Skip to content

Commit

Permalink
[WFCORE-6541] Patch high level command should be completely disabled …
Browse files Browse the repository at this point in the history
…in standalone mode

Jira issue: https://issues.redhat.com/browse/WFCORE-6541
  • Loading branch information
yersan committed Oct 5, 2023
1 parent fec6a97 commit f540ce9
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public void complete(CLICompleterInvocation completerInvocation) {
mainCommand = cmd.command.get(0);
}

// The "patch" command is only activated in domain mode to patch remote legacy Host Controllers from a Domain
// Controller. See PatchCommand#PatchCommandActivator.
// Therefore, we allow the Help command to show the help for "patch" only if the client is running under domain
// mode context.
// For standalone mode or when the CLI is disconnected, the help for the "patch" command is no longer available
// because the "patch" command deactivated under this context.
if ("patch".equals(mainCommand) && !completerInvocation.getCommandContext().isDomainMode()) {
return;
}

// Special case for operations.
String buff = completerInvocation.getGivenCompleteValue();
if (OperationCommandContainer.isOperation(buff)) {
Expand Down Expand Up @@ -98,9 +108,14 @@ public void complete(CLICompleterInvocation completerInvocation) {
return;
}

List<String> allExposed = new ArrayList<>(cmd.aeshRegistry.getAllCommandNames());
List<String> candidates = new ArrayList<>();
if (mainCommand == null) {
List<String> allExposed = new ArrayList<>(cmd.aeshRegistry.getAllCommandNames());

// complete to "patch" is only available in Domain Mode.
if (!completerInvocation.getCommandContext().isDomainMode()) {
allExposed.remove("patch");
}
if (completerInvocation.getCommandContext().getModelControllerClient() != null) {
allExposed.add("/");
allExposed.add(":");
Expand Down Expand Up @@ -178,6 +193,16 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm
}
}

// The "patch" command is only activated in domain mode to patch remote legacy Host Controllers from a Domain
// Controller. See PatchCommand#PatchCommandActivator.
// Therefore, we allow the Help command to show the help for "patch" only if the client is running under domain
// mode context.
// For standalone mode or when the CLI is disconnected, the help for the "patch" command is no longer available
// because the "patch" command deactivated under this context.
if ("patch".equals(mainCommand) && !ctx.isDomainMode()) {
throw new CommandException("The command is not available in the current context.");
}

// An operation?
if (OperationCommandContainer.isOperation(mainCommand)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @author [email protected]
*/
@CommandDefinition(name = "apply", description = "")
@CommandDefinition(name = "apply", description = "", activator = PatchCommand.PatchCommandActivator.class)
public class PatchApply extends PatchOverrideCommand {

// Argument comes first, aesh behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm
}

/**
* Hides the high level patch commands on a standalone installation only.
* Activates the high level patch command only under Domain Mode context.
*
* Since the introduction of Prospero as the tool to patch, the "patch" command only makes sense in domain
* mode to patch legacy host controllers that do not use Prospero. For example, in mixed domains where you
* need to patch a remote secondary host, which only understands "patch", using the Domain Controller.
* Only in such a case, we activate the "patch" command.
*/
public static class PatchCommandActivator extends AbstractCommandActivator {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author [email protected]
*/
@CommandDefinition(name = "history", description = "")
@CommandDefinition(name = "history", description = "", activator = PatchCommand.PatchCommandActivator.class)
public class PatchHistory extends AbstractDistributionCommand {

@Option(name = "patch-stream", hasValue = true, required = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author [email protected]
*/
@CommandDefinition(name = "info", description = "")
@CommandDefinition(name = "info", description = "", activator = PatchCommand.PatchCommandActivator.class)
public class PatchInfo extends AbstractDistributionCommand {

public static class NoStreamsActivator extends AbstractRejectOptionActivator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @author [email protected]
*/
@CommandDefinition(name = "inspect", description = "")
@CommandDefinition(name = "inspect", description = "", activator = PatchCommand.PatchCommandActivator.class)
public class PatchInspect implements Command<CLICommandInvocation> {

// Argument comes first, aesh behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class PatchRollbackActivator extends AbstractCommandActivator {

@Override
public boolean isActivated(ParsedCommand command) {
if (!getCommandContext().isDomainMode()) return false;

try {
AbstractDistributionCommand cmd = (AbstractDistributionCommand) command.command();
return !getPatches(getCommandContext(), cmd, cmd.getPatchStream(), cmd.getHost()).isEmpty();
Expand Down
5 changes: 5 additions & 0 deletions testsuite/domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-installation-manager</artifactId>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-patching</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,57 @@ public void helpWithDeploymentTest() {
}
}

/**
* Checks CLI completion for "help pat" command
*/
@Test
public void helpCompletePatchTest() {
for (List<String> candidates : getCandidatesLists("help pat", true, -1)) {
assertTrue(candidates.toString(), candidates.contains("patch"));
}
}

/**
* Checks CLI completion for "help " command
*/
@Test
public void helpHasPatch() {
for (List<String> candidates : getCandidatesLists("help ", true, -1)) {
assertTrue(candidates.toString(), candidates.contains("patch"));
}
}

/**
* Checks CLI completion for "patch" command
*/
@Test
public void patchTest() {
for (List<String> candidates : getCandidatesLists("patch", true, -1)) {
assertTrue(candidates.toString(), candidates.contains("patch"));
}
}

/**
* Checks CLI completion for "pat" command
*/
@Test
public void patchCompleteTest() {
for (List<String> candidates : getCandidatesLists("pat", true, -1)) {
assertTrue(candidates.toString(), candidates.contains("patch"));
}
}

/**
* Checks CLI completion for "patch in" command
*/
@Test
public void patchInfoCompleteTest() {
for (List<String> candidates : getCandidatesLists("patch in", true, -1)) {
assertTrue(candidates.toString(), candidates.contains("info"));
}
}


@Test
public void testPropertiesNoValue() throws Exception {
CommandContext ctx = CLITestUtil.getCommandContext(testSupport,
Expand Down
5 changes: 5 additions & 0 deletions testsuite/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron-x500-cert</artifactId>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-patching</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,57 @@ public void helpWithDeploymentTest() {
}
}

/**
* Checks CLI completion for "help pat" command
*/
@Test
public void helpDoNotCompletePatchTest() {
for (List<String> candidates : getCandidatesLists("help pat", true)) {
assertFalse(candidates.toString(), candidates.contains("patch"));
}
}

/**
* Checks CLI completion for "help " command
*/
@Test
public void helpDoNotHavePatch() {
for (List<String> candidates : getCandidatesLists("help ", true)) {
assertFalse(candidates.toString(), candidates.contains("patch"));
}
}

/**
* Checks CLI completion for "patch" command
*/
@Test
public void patchTest() {
for (List<String> candidates : getCandidatesLists("patch", true)) {
assertTrue(candidates.toString(), candidates.isEmpty());
}
}

/**
* Checks CLI completion for "pat" command
*/
@Test
public void patchDoNotCompleteTest() {
for (List<String> candidates : getCandidatesLists("pat", true)) {
assertTrue(candidates.toString(), candidates.isEmpty());
}
}


/**
* Checks CLI completion for "patch in" command
*/
@Test
public void patchInfoDoNotCompleteTest() {
for (List<String> candidates : getCandidatesLists("patch in", true)) {
assertTrue(candidates.toString(), candidates.isEmpty());
}
}

@Test
public void deployTest() {
String cmd = "deploy";
Expand Down

0 comments on commit f540ce9

Please sign in to comment.