From 2d35741693b501f90dfc3e5d52c1f3c19eac6ae0 Mon Sep 17 00:00:00 2001 From: Martin Simka Date: Fri, 6 Sep 2024 18:06:24 +0200 Subject: [PATCH] make PatchingOperations and commands unavailable on WildFly 29+ 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. --- .../creaper/commands/patching/ApplyPatch.java | 6 ++++ .../commands/patching/PatchingOperations.java | 19 ++++++++++++ .../commands/patching/RollbackLastPatch.java | 5 ++++ .../commands/patching/RollbackPatch.java | 5 ++++ .../ApplyRollbackExistingPatchTest.java | 29 +++++++++++++++++-- .../ApplyRollbackNonexistingPatchTest.java | 13 +++++++++ .../patching/PatchingOperationsTest.java | 13 +++++++++ 7 files changed, 87 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/ApplyPatch.java b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/ApplyPatch.java index 101c5b7f..dea45314 100644 --- a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/ApplyPatch.java +++ b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/ApplyPatch.java @@ -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; @@ -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="); diff --git a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/PatchingOperations.java b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/PatchingOperations.java index a56b73be..480f43ed 100644 --- a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/PatchingOperations.java +++ b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/PatchingOperations.java @@ -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; @@ -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"); } @@ -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 getHistory() throws IOException { + checkServerVersionIsSupported(); List asList = ops.invoke("show-history", patchingAddress).listValue(); List entries = new ArrayList(asList.size()); @@ -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(); @@ -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); } @@ -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); } @@ -97,6 +104,7 @@ public String getCurrentServerVersion() throws IOException { * @throws IOException when IO error occurs */ public List getPatchesIds() throws IOException { + checkServerVersionIsSupported(); return ops.readAttribute(patchingAddress, "patches").stringListValue(Collections.emptyList()); } @@ -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); + } + } } diff --git a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackLastPatch.java b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackLastPatch.java index 3445a681..5c91c364 100644 --- a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackLastPatch.java +++ b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackLastPatch.java @@ -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; @@ -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) diff --git a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackPatch.java b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackPatch.java index 08590214..622f28c6 100644 --- a/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackPatch.java +++ b/commands/src/main/java/org/wildfly/extras/creaper/commands/patching/RollbackPatch.java @@ -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; @@ -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) diff --git a/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackExistingPatchTest.java b/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackExistingPatchTest.java index d3c987c3..0a9e2906 100644 --- a/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackExistingPatchTest.java +++ b/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackExistingPatchTest.java @@ -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; @@ -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"; @@ -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); @@ -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); @@ -122,6 +134,8 @@ public void restartServerAfterPatchRollback() throws TimeoutException, Interrupt @Test @InSequence(7) public void assertPatchNotInstalled() throws IOException { + checkServerVersionIsSupported(); + assertFalse(patching.isAnyPatchInstalled()); } @@ -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)); + } } diff --git a/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackNonexistingPatchTest.java b/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackNonexistingPatchTest.java index 197f5dff..8a285cf7 100644 --- a/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackNonexistingPatchTest.java +++ b/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/ApplyRollbackNonexistingPatchTest.java @@ -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; @@ -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()); diff --git a/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/PatchingOperationsTest.java b/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/PatchingOperationsTest.java index 691bffdf..2e4d766b 100644 --- a/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/PatchingOperationsTest.java +++ b/testsuite/standalone/src/test/java/org/wildfly/extras/creaper/commands/patching/PatchingOperationsTest.java @@ -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; @@ -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());