-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFCORE-6728] Make the stability setup tasks take/restore snapshots o…
…f the server config Otherwise, if we were working on a lower stability level, and made changes to the model, those could be stored with s schema from a lower stability level, meaning the reload back to the default community level will fail since it will contain xml elements from a namespace we can't handle
- Loading branch information
Showing
9 changed files
with
188 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
testsuite/shared/src/main/java/org/wildfly/test/snapshot/ServerSnapshot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.test.snapshot; | ||
|
||
import org.jboss.as.controller.client.helpers.ClientConstants; | ||
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; | ||
import org.jboss.as.test.integration.management.util.ServerReload; | ||
import org.jboss.as.version.Stability; | ||
import org.jboss.dmr.ModelNode; | ||
import org.wildfly.core.testrunner.ManagementClient; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
public class ServerSnapshot { | ||
public static AutoCloseable takeSnapshot(ManagementClient client) { | ||
return takeSnapshot(client, null); | ||
} | ||
/** | ||
* Takes a snapshot of the current state of the server. | ||
* | ||
* Returns a AutoCloseable that can be used to restore the server state | ||
* @param client The client | ||
* @param reloadToStability the stability the AutoCloseable should reload to | ||
* @return A closeable that can be used to restore the server | ||
*/ | ||
public static AutoCloseable takeSnapshot(ManagementClient client, Stability reloadToStability) { | ||
try { | ||
ModelNode node = new ModelNode(); | ||
node.get(ModelDescriptionConstants.OP).set("take-snapshot"); | ||
ModelNode result = client.getControllerClient().execute(node); | ||
if (!"success".equals(result.get(ClientConstants.OUTCOME).asString())) { | ||
fail("Reload operation didn't finish successfully: " + result.asString()); | ||
} | ||
String snapshot = result.get(ModelDescriptionConstants.RESULT).asString(); | ||
final String fileName = snapshot.contains(File.separator) ? snapshot.substring(snapshot.lastIndexOf(File.separator) + 1) : snapshot; | ||
return new AutoCloseable() { | ||
@Override | ||
public void close() throws Exception { | ||
ServerReload.Parameters parameters = new ServerReload.Parameters(); | ||
parameters.setServerConfig(fileName); | ||
if (reloadToStability != null) { | ||
parameters.setStability(reloadToStability); | ||
} | ||
ServerReload.executeReloadAndWaitForCompletion(client.getControllerClient(), parameters); | ||
|
||
ModelNode node = new ModelNode(); | ||
node.get(ModelDescriptionConstants.OP).set("write-config"); | ||
ModelNode result = client.getControllerClient().execute(node); | ||
if (!"success".equals(result.get(ClientConstants.OUTCOME).asString())) { | ||
fail("Failed to write config after restoring from snapshot " + result.asString()); | ||
} | ||
} | ||
}; | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to take snapshot", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters