Skip to content

Commit

Permalink
make PatchingOperations and commands unavailable on WildFly 29+
Browse files Browse the repository at this point in the history
Patching has been removed
* https://issues.redhat.com/browse/WFCORE-6206
* https://issues.redhat.com/browse/WFCORE-6541

The "patch" command should be only functional in Domain Mode since it still needs to be used to patch secondary hosts running on legacy versions from a Domain Controller.
  • Loading branch information
simkam authored and jbliznak committed Sep 9, 2024
1 parent 44dfcbb commit 2d35741
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wildfly.extras.creaper.commands.patching;

import org.wildfly.extras.creaper.core.CommandFailedException;
import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.CliException;
import org.wildfly.extras.creaper.core.online.OnlineCommand;
import org.wildfly.extras.creaper.core.online.OnlineCommandContext;
Expand Down Expand Up @@ -31,6 +32,11 @@ private ApplyPatch(Builder builder) {

@Override
public void apply(OnlineCommandContext ctx) throws CliException, CommandFailedException, IOException {
if (ctx.options.isStandalone && ctx.version.greaterThan(ServerVersion.VERSION_21_0_0)) {
// https://issues.redhat.com/browse/WFCORE-6206
throw new AssertionError("Patching has been removed in WildFly 29.");
}

StringBuilder cmd = new StringBuilder("patch apply " + patchPath);
if (ctx.options.isDomain) {
cmd.append(" --host=");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wildfly.extras.creaper.commands.patching;

import org.jboss.dmr.ModelNode;
import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.ModelNodeResult;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import org.wildfly.extras.creaper.core.online.operations.Address;
Expand All @@ -13,10 +14,12 @@
import java.util.List;

public final class PatchingOperations {
private final OnlineManagementClient client;
private final Operations ops;
private final Address patchingAddress;

public PatchingOperations(OnlineManagementClient client) {
this.client = client;
this.ops = new Operations(client);
this.patchingAddress = Address.coreService("patching");
}
Expand All @@ -25,6 +28,7 @@ public PatchingOperations(OnlineManagementClient client) {
* @return list of history entries of all patches that have been applied; never {@code null}
*/
public List<PatchHistoryEntry> getHistory() throws IOException {
checkServerVersionIsSupported();
List<ModelNode> asList = ops.invoke("show-history", patchingAddress).listValue();
List<PatchHistoryEntry> entries = new ArrayList<PatchHistoryEntry>(asList.size());

Expand Down Expand Up @@ -59,6 +63,7 @@ public PatchHistoryEntry getHistoryEntry(String patchId) throws IOException {
* @return information about current patch state as a {@code PatchInfo} object; never {@code null}
*/
public PatchInfo getPatchInfo() throws IOException {
checkServerVersionIsSupported();
ModelNodeResult modelNodeResult = ops.readResource(patchingAddress, ReadResourceOption.RECURSIVE,
ReadResourceOption.INCLUDE_RUNTIME);
modelNodeResult.assertDefinedValue();
Expand All @@ -80,6 +85,7 @@ public PatchInfo getPatchInfo() throws IOException {
* @throws IOException when IO error occurs
*/
public String getCumulativePatchId() throws IOException {
checkServerVersionIsSupported();
return ops.readAttribute(patchingAddress, "cumulative-patch-id").stringValue(null);
}

Expand All @@ -89,6 +95,7 @@ public String getCumulativePatchId() throws IOException {
* @throws IOException when IO error occurs
*/
public String getCurrentServerVersion() throws IOException {
checkServerVersionIsSupported();
return ops.readAttribute(patchingAddress, "version").stringValue(null);
}

Expand All @@ -97,6 +104,7 @@ public String getCurrentServerVersion() throws IOException {
* @throws IOException when IO error occurs
*/
public List<String> getPatchesIds() throws IOException {
checkServerVersionIsSupported();
return ops.readAttribute(patchingAddress, "patches").stringListValue(Collections.<String>emptyList());
}

Expand Down Expand Up @@ -235,4 +243,15 @@ public String toString() {
return "PatchHistoryEntry {patchId='" + patchId + "\', type='" + type + "\', appliedAt='" + appliedAt + "\'}";
}
}

private void checkServerVersionIsSupported() {
try {
if (client.version().greaterThan(ServerVersion.VERSION_21_0_0)) {
// https://issues.redhat.com/browse/WFCORE-6206
throw new AssertionError("Patching subsystem has been removed in WildFly 29.");
}
} catch (IOException ioe) {
throw new IllegalStateException(ioe);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wildfly.extras.creaper.commands.patching;

import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.OnlineCommand;
import org.wildfly.extras.creaper.core.online.OnlineCommandContext;
import org.wildfly.extras.creaper.core.online.operations.Address;
Expand Down Expand Up @@ -31,6 +32,10 @@ private RollbackLastPatch(Builder builder) {

@Override
public void apply(OnlineCommandContext ctx) throws IOException {
if (ctx.version.greaterThan(ServerVersion.VERSION_21_0_0)) {
// https://issues.redhat.com/browse/WFCORE-6206
throw new AssertionError("Patching has been removed in WildFly 29.");
}
Operations ops = new Operations(ctx.client);
ops.invoke("rollback-last", Address.coreService("patching"), Values.empty()
.andOptional("reset-configuration", resetConfiguration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wildfly.extras.creaper.commands.patching;

import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.OnlineCommand;
import org.wildfly.extras.creaper.core.online.OnlineCommandContext;
import org.wildfly.extras.creaper.core.online.operations.Address;
Expand Down Expand Up @@ -35,6 +36,10 @@ private RollbackPatch(Builder builder) {

@Override
public void apply(OnlineCommandContext ctx) throws IOException {
if (ctx.version.greaterThan(ServerVersion.VERSION_21_0_0)) {
// https://issues.redhat.com/browse/WFCORE-6206
throw new AssertionError("Patching has been removed in WildFly 29.");
}
Operations ops = new Operations(ctx.client);
ops.invoke("rollback", Address.coreService("patching"), Values.empty()
.andOptional("patch-id", patchId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Assume;
import org.wildfly.extras.creaper.core.CommandFailedException;
import org.wildfly.extras.creaper.core.ManagementClient;
import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.ModelNodeResult;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import org.wildfly.extras.creaper.core.online.OnlineOptions;
Expand Down Expand Up @@ -62,6 +64,8 @@ public void startServer() {
@Test
@InSequence(2)
public void applyPatch() throws Exception {
checkServerVersionIsSupported();

File patchZip = tmp.newFile("test-patch.zip");

String serverName = "WildFly";
Expand Down Expand Up @@ -93,7 +97,9 @@ public void applyPatch() throws Exception {

@Test
@InSequence(3)
public void restartServerAfterPatchApply() throws TimeoutException, InterruptedException {
public void restartServerAfterPatchApply() throws TimeoutException, InterruptedException, IOException {
checkServerVersionIsSupported();

controller.stop(ManualTests.ARQUILLIAN_CONTAINER);
controller.start(ManualTests.ARQUILLIAN_CONTAINER);
client.reconnect(10);
Expand All @@ -102,18 +108,24 @@ public void restartServerAfterPatchApply() throws TimeoutException, InterruptedE
@Test
@InSequence(4)
public void assertPatchInstalled() throws IOException {
checkServerVersionIsSupported();

assertTrue(patching.isPatchInstalled("test-patch"));
}

@Test
@InSequence(5)
public void rollbackPatch() throws CommandFailedException {
public void rollbackPatch() throws CommandFailedException, IOException {
checkServerVersionIsSupported();

client.apply(new RollbackPatch.Builder("test-patch").resetConfiguration(false).build());
}

@Test
@InSequence(6)
public void restartServerAfterPatchRollback() throws TimeoutException, InterruptedException {
public void restartServerAfterPatchRollback() throws TimeoutException, InterruptedException, IOException {
checkServerVersionIsSupported();

controller.stop(ManualTests.ARQUILLIAN_CONTAINER);
controller.start(ManualTests.ARQUILLIAN_CONTAINER);
client.reconnect(10);
Expand All @@ -122,6 +134,8 @@ public void restartServerAfterPatchRollback() throws TimeoutException, Interrupt
@Test
@InSequence(7)
public void assertPatchNotInstalled() throws IOException {
checkServerVersionIsSupported();

assertFalse(patching.isAnyPatchInstalled());
}

Expand All @@ -135,4 +149,13 @@ public void stopServer() {
public void tearDown() throws IOException {
client.close();
}

private void checkServerVersionIsSupported() throws IOException {
// check version is supported
ServerVersion serverVersion
= client.version();
// https://issues.redhat.com/browse/WFCORE-6206
Assume.assumeFalse("Patching has been removed in WildFly 29.",
serverVersion.greaterThan(ServerVersion.VERSION_21_0_0));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.wildfly.extras.creaper.commands.patching;

import org.jboss.arquillian.junit.Arquillian;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.wildfly.extras.creaper.core.CommandFailedException;
import org.wildfly.extras.creaper.core.ManagementClient;
import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import org.wildfly.extras.creaper.core.online.OnlineOptions;
import org.junit.After;
Expand All @@ -16,6 +19,16 @@
public class ApplyRollbackNonexistingPatchTest {
private OnlineManagementClient client;

@BeforeClass
public static void checkServerVersionIsSupported() throws Exception {
// check version is supported
ServerVersion serverVersion
= ManagementClient.online(OnlineOptions.standalone().localDefault().build()).version();
// https://issues.redhat.com/browse/WFCORE-6206
Assume.assumeFalse("Patching subsystem has been removed in WildFly 29.",
serverVersion.greaterThan(ServerVersion.VERSION_21_0_0));
}

@Before
public void connect() throws IOException {
client = ManagementClient.online(OnlineOptions.standalone().localDefault().build());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.wildfly.extras.creaper.commands.patching;

import org.jboss.arquillian.junit.Arquillian;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.wildfly.extras.creaper.core.ManagementClient;
import org.wildfly.extras.creaper.core.ServerVersion;
import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
import org.wildfly.extras.creaper.core.online.OnlineOptions;
import org.junit.After;
Expand All @@ -22,6 +25,16 @@ public class PatchingOperationsTest {
private OnlineManagementClient client;
private PatchingOperations patchingOps;

@BeforeClass
public static void checkServerVersionIsSupported() throws Exception {
// check version is supported
ServerVersion serverVersion
= ManagementClient.online(OnlineOptions.standalone().localDefault().build()).version();
// https://issues.redhat.com/browse/WFCORE-6206
Assume.assumeFalse("Patching subsystem has been removed in WildFly 29.",
serverVersion.greaterThan(ServerVersion.VERSION_21_0_0));
}

@Before
public void connect() throws IOException {
client = ManagementClient.online(OnlineOptions.standalone().localDefault().build());
Expand Down

0 comments on commit 2d35741

Please sign in to comment.