Skip to content

Commit

Permalink
[WFCORE-6728] Setup tasks to reload to a server stability level
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir committed Mar 21, 2024
1 parent ada7a1d commit 189129f
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.Set;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_OPERATION_DESCRIPTION_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_OPERATION_NAMES_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELOAD_ENHANCED;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STABILITY;
Expand All @@ -57,15 +59,23 @@ public StabilityServerSetupTasks(Stability desiredStability) {

@Override
public void setup(ManagementClient managementClient) throws Exception {
// Make sure the desired stability level is one of the ones supported by the server
Set<Stability> supportedStabilityLevels = getSupportedStabilityLevels();
Assume.assumeTrue(
String.format("%s is not a supported stability level", desiredStability, supportedStabilityLevels),
supportedStabilityLevels.contains(desiredStability));

// Check the reload-enhanced operation exists in the current stability level
Assume.assumeTrue(
"The reload-enhanced operation is not registered at this stability level",
checkReloadEnhancedOperationIsAvailable(managementClient));

// Check the reload-enhanced operation exists in the stability level we want to load to so that
// we can reload back to the current one
Stability reloadOpStability = getReloadEnhancedOperationStabilityLevel(managementClient);
Assume.assumeTrue(desiredStability.enables(reloadOpStability));

// All good, let's do it!
reloadToDesiredStability(managementClient.getControllerClient(), desiredStability);
}

Expand All @@ -85,6 +95,15 @@ private boolean checkReloadEnhancedOperationIsAvailable(ManagementClient managem
return false;
}

private Stability getReloadEnhancedOperationStabilityLevel(ManagementClient managementClient) throws Exception {
ModelNode op = Util.createOperation(READ_OPERATION_DESCRIPTION_OPERATION, PathAddress.EMPTY_ADDRESS);
op.get(NAME).set(RELOAD_ENHANCED);

ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
String stability = result.get(STABILITY).asString();
return Stability.fromString(stability);

}
private Set<Stability> getSupportedStabilityLevels() {
// TODO WFCORE-6731 - see https://github.com/wildfly/wildfly-core/pull/5895#discussion_r1520489808
// This information will be available in a management operation, For now just return a hardcoded set
Expand All @@ -98,8 +117,6 @@ private Stability reloadToDesiredStability(ModelControllerClient client, Stabili
originalStability = currentStability;
}

// The stability parameter for the reload opration is only registered below the default level
Assume.assumeFalse("Can't reload to a different stability when server stability level is default", currentStability == Stability.DEFAULT && stability != Stability.DEFAULT);

if (currentStability == stability) {
return originalStability;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.wildfly.core.test.standalone.stability;

import jakarta.inject.Inject;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.core.testrunner.ManagementClient;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STABILITY;
import static org.jboss.as.server.controller.descriptions.ServerDescriptionConstants.SERVER_ENVIRONMENT;

public abstract class AbstractStabilityServerSetupTaskTest {
private final Stability desiredStability;

@Inject
private ManagementClient managementClient;

public AbstractStabilityServerSetupTaskTest(Stability desiredStability) {
this.desiredStability = desiredStability;
}

@Test
public void testStabilityMatchesSetupTask() throws Exception {
ModelNode op = Util.getReadAttributeOperation(PathAddress.pathAddress(CORE_SERVICE, SERVER_ENVIRONMENT), STABILITY);
ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
Stability stability = Stability.fromString(result.asString());
Assert.assertEquals(desiredStability, stability);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.wildfly.core.test.standalone.stability;

import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.core.testrunner.ServerSetup;
import org.wildfly.core.testrunner.WildFlyRunner;
import org.wildfly.test.stability.StabilityServerSetupTasks;

@ServerSetup(StabilityServerSetupTasks.Community.class)
@RunWith(WildFlyRunner.class)
public class StabilityCommunityServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityCommunityServerSetupTestCase() {
super(Stability.COMMUNITY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.wildfly.core.test.standalone.stability;

import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.core.testrunner.ServerSetup;
import org.wildfly.core.testrunner.WildFlyRunner;
import org.wildfly.test.stability.StabilityServerSetupTasks;

@ServerSetup(StabilityServerSetupTasks.Default.class)
@RunWith(WildFlyRunner.class)
public class StabilityDefaultServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityDefaultServerSetupTestCase() {
super(Stability.DEFAULT);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.wildfly.core.test.standalone.stability;

import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.core.testrunner.ServerSetup;
import org.wildfly.core.testrunner.WildFlyRunner;
import org.wildfly.test.stability.StabilityServerSetupTasks;

@ServerSetup(StabilityServerSetupTasks.Experimental.class)
@RunWith(WildFlyRunner.class)
public class StabilityExperimentalServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityExperimentalServerSetupTestCase() {
super(Stability.EXPERIMENTAL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.wildfly.core.test.standalone.stability;

import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.core.testrunner.ServerSetup;
import org.wildfly.core.testrunner.WildFlyRunner;
import org.wildfly.test.stability.StabilityServerSetupTasks;

@ServerSetup(StabilityServerSetupTasks.Preview.class)
@RunWith(WildFlyRunner.class)
public class StabilityPreviewServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityPreviewServerSetupTestCase() {
super(Stability.PREVIEW);
}
}

0 comments on commit 189129f

Please sign in to comment.