From 5dab05dba1542eba6fb14c97580b0976ed987506 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Thu, 21 Dec 2023 13:26:28 +0000 Subject: [PATCH 1/2] [WFCORE-6649] Deprecate --no-resol-local-cache and replace it with --use-default-local-cache Jira issue: https://issues.redhat.com/browse/WFCORE-6649 --- .../instmgr/AbstractInstMgrUpdateHandler.java | 19 ++- .../core/instmgr/InstMgrConstants.java | 1 + .../instmgr/InstMgrListUpdatesHandler.java | 19 ++- .../instmgr/InstMgrOperationStepHandler.java | 2 +- .../instmgr/InstMgrPrepareRevertHandler.java | 18 ++- .../instmgr/InstMgrPrepareUpdateHandler.java | 20 ++- .../instmgr/cli/AbstractInstMgrCommand.java | 16 ++ .../core/instmgr/cli/ListUpdatesAction.java | 26 ++- .../core/instmgr/cli/PrepareUpdateAction.java | 27 +++- .../core/instmgr/cli/RevertCommand.java | 25 ++- .../core/instmgr/cli/UpdateCommand.java | 17 +- .../core/instmgr/logging/InstMgrLogger.java | 8 + .../core/instmgr/LocalDescriptions.properties | 6 + .../instmgr/cli/command_resources.properties | 10 +- .../core/instmgr/InstMgrResourceTestCase.java | 152 ++++++++++++++++++ ...nstallationManagerIntegrationTestCase.java | 91 +++++++++-- 16 files changed, 408 insertions(+), 49 deletions(-) diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/AbstractInstMgrUpdateHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/AbstractInstMgrUpdateHandler.java index 6df652866d9..846c30d10e1 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/AbstractInstMgrUpdateHandler.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/AbstractInstMgrUpdateHandler.java @@ -17,6 +17,7 @@ import java.util.List; import org.jboss.as.controller.AttributeDefinition; +import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.ObjectTypeAttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; @@ -63,16 +64,28 @@ abstract class AbstractInstMgrUpdateHandler extends InstMgrOperationStepHandler .addArbitraryDescriptor(FILESYSTEM_PATH, ModelNode.TRUE) .setMinSize(1) .setRequired(false) - .setAlternatives(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE) + .setAlternatives(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE, InstMgrConstants.USE_DEFAULT_LOCAL_CACHE) .build(); + /** + * @deprecated Use USE_DEFAULT_LOCAL_CACHE instead. + */ + @Deprecated(forRemoval = true) protected static final AttributeDefinition NO_RESOLVE_LOCAL_CACHE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE, ModelType.BOOLEAN) .setStorageRuntime() .setRuntimeServiceNotRequired() - .setDefaultValue(ModelNode.FALSE) .setRequired(false) .setStorageRuntime() - .setAlternatives(InstMgrConstants.LOCAL_CACHE) + .setAlternatives(InstMgrConstants.LOCAL_CACHE, InstMgrConstants.USE_DEFAULT_LOCAL_CACHE) + .setDeprecated(ModelVersion.create(24)) + .build(); + + protected static final AttributeDefinition USE_DEFAULT_LOCAL_CACHE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE, ModelType.BOOLEAN) + .setStorageRuntime() + .setRuntimeServiceNotRequired() + .setRequired(false) + .setStorageRuntime() + .setAlternatives(InstMgrConstants.LOCAL_CACHE, InstMgrConstants.NO_RESOLVE_LOCAL_CACHE) .build(); AbstractInstMgrUpdateHandler(InstMgrService imService, InstallationManagerFactory imf) { diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java index 96476cb0ea4..2abebd93f1f 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java @@ -53,6 +53,7 @@ public interface InstMgrConstants { String MAVEN_REPO_FILE = "maven-repo-file"; String MAVEN_REPO_FILES = "maven-repo-files"; String NO_RESOLVE_LOCAL_CACHE = "no-resolve-local-cache"; + String USE_DEFAULT_LOCAL_CACHE = "use-default-local-cache"; String OFFLINE = "offline"; String REPOSITORIES = "repositories"; String REPOSITORY = "repository"; diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrListUpdatesHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrListUpdatesHandler.java index 4544a846e9d..efaf649265b 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrListUpdatesHandler.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrListUpdatesHandler.java @@ -59,6 +59,7 @@ public class InstMgrListUpdatesHandler extends AbstractInstMgrUpdateHandler { .addParameter(REPOSITORIES) .addParameter(LOCAL_CACHE) .addParameter(NO_RESOLVE_LOCAL_CACHE) + .addParameter(USE_DEFAULT_LOCAL_CACHE) .addParameter(MAVEN_REPO_FILES) .withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY) .setRuntimeOnly() @@ -72,12 +73,21 @@ public InstMgrListUpdatesHandler(InstMgrService imService, InstallationManagerFa public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean offline = OFFLINE.resolveModelAttribute(context, operation).asBoolean(false); final String pathLocalRepo = LOCAL_CACHE.resolveModelAttribute(context, operation).asStringOrNull(); - final boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBoolean(false); + final Boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull(); + final Boolean useDefaultLocalCache = USE_DEFAULT_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull(); final Path localRepository = pathLocalRepo != null ? Path.of(pathLocalRepo) : null; final List mavenRepoFileIndexes = MAVEN_REPO_FILES.resolveModelAttribute(context, operation).asListOrEmpty(); final List repositoriesMn = REPOSITORIES.resolveModelAttribute(context, operation).asListOrEmpty(); - if (pathLocalRepo != null && noResolveLocalCache) { + if (noResolveLocalCache != null && useDefaultLocalCache !=null) { + throw InstMgrLogger.ROOT_LOGGER.noResolveLocalCacheWithUseDefaultLocalCache(); + } + + if (pathLocalRepo != null && useDefaultLocalCache != null && useDefaultLocalCache) { + throw InstMgrLogger.ROOT_LOGGER.localCacheWithUseDefaultLocalCache(); + } + + if (pathLocalRepo != null && noResolveLocalCache !=null && noResolveLocalCache) { throw InstMgrLogger.ROOT_LOGGER.localCacheWithNoResolveLocalCache(); } @@ -91,7 +101,10 @@ public void execute(OperationContext context, ModelNode operation) throws Operat context.acquireControllerLock(); try { final Path homeDir = imService.getHomeDir(); - final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCache, offline); + boolean noResolveLocalCacheResult = noResolveLocalCache != null + ? noResolveLocalCache + : useDefaultLocalCache == null ? localRepository == null : (!useDefaultLocalCache && localRepository == null); + final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCacheResult, offline); final InstallationManager im = imf.create(homeDir, mavenOptions); final Path listUpdatesWorkDir = imService.createTempDir("list-updates-"); diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrOperationStepHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrOperationStepHandler.java index c1deb0ae4f8..5d7ecf4d0e3 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrOperationStepHandler.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrOperationStepHandler.java @@ -101,7 +101,7 @@ protected Path getUploadedMvnRepoRoot(Path source) throws Exception, ZipExceptio List entries = content .filter(e -> e.toFile().isDirectory() && e.getFileName().toString().equals(InstMgrConstants.MAVEN_REPO_DIR_NAME_IN_ZIP_FILES)) .collect(Collectors.toList()); - if (entries.isEmpty() || entries.size() != 1) { + if (entries.size() != 1) { throw InstMgrLogger.ROOT_LOGGER.invalidZipEntry(InstMgrConstants.MAVEN_REPO_DIR_NAME_IN_ZIP_FILES); } diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareRevertHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareRevertHandler.java index 22a567f15c9..eaffed1b9bc 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareRevertHandler.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareRevertHandler.java @@ -80,13 +80,22 @@ public class InstMgrPrepareRevertHandler extends AbstractInstMgrUpdateHandler { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean offline = OFFLINE.resolveModelAttribute(context, operation).asBoolean(false); final String pathLocalRepo = LOCAL_CACHE.resolveModelAttribute(context, operation).asStringOrNull(); - final boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBoolean(false); + final Boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull(); + final Boolean useDefaultLocalCache = USE_DEFAULT_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull(); final Path localRepository = pathLocalRepo != null ? Path.of(pathLocalRepo) : null; final List mavenRepoFileIndexes = MAVEN_REPO_FILES.resolveModelAttribute(context, operation).asListOrEmpty(); final List repositoriesMn = REPOSITORIES.resolveModelAttribute(context, operation).asListOrEmpty(); final String revision = REVISION.resolveModelAttribute(context, operation).asString(); - if (pathLocalRepo != null && noResolveLocalCache) { + if (noResolveLocalCache != null && useDefaultLocalCache !=null) { + throw InstMgrLogger.ROOT_LOGGER.noResolveLocalCacheWithUseDefaultLocalCache(); + } + + if (pathLocalRepo != null && useDefaultLocalCache != null && useDefaultLocalCache) { + throw InstMgrLogger.ROOT_LOGGER.localCacheWithUseDefaultLocalCache(); + } + + if (pathLocalRepo != null && noResolveLocalCache != null && noResolveLocalCache) { throw InstMgrLogger.ROOT_LOGGER.localCacheWithNoResolveLocalCache(); } @@ -106,7 +115,10 @@ public void execute(OperationContext context, ModelNode operation) throws Operat imService.beginCandidateServer(); addCompleteStep(context, imService, null); final Path homeDir = imService.getHomeDir(); - final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCache, offline); + boolean noResolveLocalCacheResult = noResolveLocalCache != null + ? noResolveLocalCache + : useDefaultLocalCache == null ? localRepository == null : (!useDefaultLocalCache && localRepository == null); + final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCacheResult, offline); final InstallationManager im = imf.create(homeDir, mavenOptions); final List repositories = new ArrayList<>(); diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareUpdateHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareUpdateHandler.java index 1e39aab6942..ee1aad22d4f 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareUpdateHandler.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrPrepareUpdateHandler.java @@ -69,6 +69,7 @@ public class InstMgrPrepareUpdateHandler extends AbstractInstMgrUpdateHandler { .addParameter(REPOSITORIES) .addParameter(LOCAL_CACHE) .addParameter(NO_RESOLVE_LOCAL_CACHE) + .addParameter(USE_DEFAULT_LOCAL_CACHE) .addParameter(MAVEN_REPO_FILES) .addParameter(LIST_UPDATES_WORK_DIR) .withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY) @@ -83,13 +84,22 @@ public class InstMgrPrepareUpdateHandler extends AbstractInstMgrUpdateHandler { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean offline = OFFLINE.resolveModelAttribute(context, operation).asBoolean(false); final String pathLocalRepo = LOCAL_CACHE.resolveModelAttribute(context, operation).asStringOrNull(); - final boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBoolean(false); + final Boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull(); + final Boolean useDefaultLocalCache = USE_DEFAULT_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull(); final Path localRepository = pathLocalRepo != null ? Path.of(pathLocalRepo) : null; final List mavenRepoFileIndexes = MAVEN_REPO_FILES.resolveModelAttribute(context, operation).asListOrEmpty(); final List repositoriesMn = REPOSITORIES.resolveModelAttribute(context, operation).asListOrEmpty(); final String listUpdatesWorkDir = LIST_UPDATES_WORK_DIR.resolveModelAttribute(context, operation).asStringOrNull(); - if (pathLocalRepo != null && noResolveLocalCache) { + if (noResolveLocalCache != null && useDefaultLocalCache != null) { + throw InstMgrLogger.ROOT_LOGGER.noResolveLocalCacheWithUseDefaultLocalCache(); + } + + if (pathLocalRepo != null && useDefaultLocalCache != null && useDefaultLocalCache) { + throw InstMgrLogger.ROOT_LOGGER.localCacheWithUseDefaultLocalCache(); + } + + if (pathLocalRepo != null && noResolveLocalCache!= null && noResolveLocalCache) { throw InstMgrLogger.ROOT_LOGGER.localCacheWithNoResolveLocalCache(); } @@ -114,7 +124,11 @@ public void execute(OperationContext context, ModelNode operation) throws Operat addCompleteStep(context, imService, null); final Path homeDir = imService.getHomeDir(); - final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCache, offline); + + boolean noResolveLocalCacheResult = noResolveLocalCache != null + ? noResolveLocalCache + : useDefaultLocalCache == null ? localRepository == null : (!useDefaultLocalCache && localRepository == null); + final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCacheResult, offline); final InstallationManager im = imf.create(homeDir, mavenOptions); final List repositories = new ArrayList<>(); diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/AbstractInstMgrCommand.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/AbstractInstMgrCommand.java index 656f7ba9fb8..578f77b9aeb 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/AbstractInstMgrCommand.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/AbstractInstMgrCommand.java @@ -10,6 +10,8 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST; import static org.wildfly.core.instmgr.cli.UpdateCommand.CONFIRM_OPTION; import static org.wildfly.core.instmgr.cli.UpdateCommand.DRY_RUN_OPTION; +import static org.wildfly.core.instmgr.cli.UpdateCommand.NO_RESOLVE_LOCAL_CACHE_OPTION; +import static org.wildfly.core.instmgr.cli.UpdateCommand.USE_DEFAULT_LOCAL_CACHE_OPTION; import java.io.IOException; import java.net.MalformedURLException; @@ -45,6 +47,8 @@ @CommandDefinition(name = "abstract-inst-mgr-cmd", description = "", activator = InstMgrActivator.class) public abstract class AbstractInstMgrCommand implements Command { static final PathElement CORE_SERVICE_INSTALLER = PathElement.pathElement(CORE_SERVICE, InstMgrGroupCommand.COMMAND_NAME); + static final String NO_RESOLVE_LOCAL_CACHE_OPTION= "no-resolve-local-cache"; + static final String USE_DEFAULT_LOCAL_CACHE_OPTION = "use-default-local-cache"; @Option(name = "host", completer = AbstractInstMgrCommand.HostsCompleter.class, activator = AbstractInstMgrCommand.HostsActivator.class) protected String host; @@ -121,6 +125,18 @@ public ConfirmActivator() { } } + public static class UseDefaultLocalCacheActivator extends AbstractRejectOptionActivator { + public UseDefaultLocalCacheActivator() { + super(NO_RESOLVE_LOCAL_CACHE_OPTION); + } + } + + public static class NoResolveLocalCacheActivator extends AbstractRejectOptionActivator { + public NoResolveLocalCacheActivator() { + super(USE_DEFAULT_LOCAL_CACHE_OPTION); + } + } + public static class HostsCompleter implements OptionCompleter { @Override public void complete(CLICompleterInvocation completerInvocation) { diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/ListUpdatesAction.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/ListUpdatesAction.java index 35fa39ac453..29a367fa96d 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/ListUpdatesAction.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/ListUpdatesAction.java @@ -24,7 +24,8 @@ public class ListUpdatesAction extends AbstractInstMgrCommand { private final List mavenRepoFiles; private final List repositories; private final Path localCache; - private final boolean noResolveLocalCache; + private final Boolean noResolveLocalCache; + private final Boolean useDefaultLocalCache; private final boolean offline; private final ModelNode headers; @@ -35,6 +36,7 @@ public ListUpdatesAction(Builder builder) { this.noResolveLocalCache = builder.noResolveLocalCache; this.offline = builder.offline; this.headers = builder.headers; + this.useDefaultLocalCache = builder.useDefaultLocalCache; } @Override @@ -59,7 +61,14 @@ protected Operation buildOperation() throws CommandException { op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.normalize().toAbsolutePath().toString()); } - op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache); + if (useDefaultLocalCache != null) { + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(useDefaultLocalCache); + } + + if (noResolveLocalCache != null) { + op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache); + } + op.get(InstMgrConstants.OFFLINE).set(offline); if (this.headers != null && headers.isDefined()) { @@ -76,12 +85,12 @@ public static class Builder { private List repositories; private Path localCache; - private boolean noResolveLocalCache; + private Boolean noResolveLocalCache; + private Boolean useDefaultLocalCache; public Builder() { this.repositories = new ArrayList<>(); this.offline = false; - this.noResolveLocalCache = false; this.mavenRepoFiles = new ArrayList<>(); } @@ -94,7 +103,7 @@ public Builder setMavenRepoFiles(List mavenRepoFiles) { public Builder setRepositories(List repositories) { if (repositories != null) { - this.repositories = new ArrayList<>(repositories); + this.repositories.addAll(repositories); } return this; } @@ -106,11 +115,16 @@ public Builder setLocalCache(File localCache) { return this; } - public Builder setNoResolveLocalCache(boolean noResolveLocalCache) { + public Builder setNoResolveLocalCache(Boolean noResolveLocalCache) { this.noResolveLocalCache = noResolveLocalCache; return this; } + public Builder setUseDefaultLocalCache(Boolean useDefaultLocalCache) { + this.useDefaultLocalCache = useDefaultLocalCache; + return this; + } + public Builder setOffline(boolean offline) { this.offline = offline; return this; diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/PrepareUpdateAction.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/PrepareUpdateAction.java index 0a1af5466ac..9dc61a4c655 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/PrepareUpdateAction.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/PrepareUpdateAction.java @@ -25,7 +25,8 @@ public class PrepareUpdateAction extends AbstractInstMgrCommand { private final List mavenRepoFiles; private final List repositories; private final Path localCache; - private final boolean noResolveLocalCache; + private final Boolean noResolveLocalCache; + private final Boolean useDefaultLocalCache; private final Path listUpdatesWorkDir; @@ -38,6 +39,7 @@ public PrepareUpdateAction(Builder builder) { this.repositories = builder.repositories; this.localCache = builder.localCache; this.noResolveLocalCache = builder.noResolveLocalCache; + this.useDefaultLocalCache = builder.useDefaultLocalCache; this.listUpdatesWorkDir = builder.listUpdatesWorkDir; this.offline = builder.offline; this.headers = builder.headers; @@ -65,7 +67,14 @@ protected Operation buildOperation() throws CommandException { op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.normalize().toAbsolutePath().toString()); } - op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache); + if (noResolveLocalCache != null) { + op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache); + } + + if (useDefaultLocalCache != null) { + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(useDefaultLocalCache); + } + op.get(InstMgrConstants.OFFLINE).set(offline); if (listUpdatesWorkDir != null) { @@ -86,13 +95,12 @@ public static class Builder { private List repositories; private Path localCache; - private boolean noResolveLocalCache; + private Boolean noResolveLocalCache; + private Boolean useDefaultLocalCache; private Path listUpdatesWorkDir; public Builder() { this.repositories = new ArrayList<>(); - this.offline = false; - this.noResolveLocalCache = false; this.mavenRepoFiles = new ArrayList<>(); } @@ -103,7 +111,7 @@ public Builder setMavenRepoFiles(Set mavenRepoFiles) { public Builder setRepositories(List repositories) { if (repositories != null) { - this.repositories = new ArrayList<>(repositories); + this.repositories.addAll(repositories); } return this; } @@ -115,11 +123,16 @@ public Builder setLocalCache(File localCache) { return this; } - public Builder setNoResolveLocalCache(boolean noResolveLocalCache) { + public Builder setNoResolveLocalCache(Boolean noResolveLocalCache) { this.noResolveLocalCache = noResolveLocalCache; return this; } + public Builder setUseDefaultLocalCache(Boolean useDefaultLocalCache) { + this.useDefaultLocalCache = useDefaultLocalCache; + return this; + } + public Builder setOffline(boolean offline) { this.offline = offline; return this; diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/RevertCommand.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/RevertCommand.java index 9b2dd743f9f..c67f0a98edc 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/RevertCommand.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/RevertCommand.java @@ -19,6 +19,7 @@ import org.jboss.as.cli.Util; import org.jboss.as.cli.impl.aesh.cmd.HeadersCompleter; import org.jboss.as.cli.impl.aesh.cmd.HeadersConverter; +import org.jboss.as.cli.operation.ParsedCommandLine; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.Operation; import org.jboss.as.controller.client.OperationBuilder; @@ -33,8 +34,10 @@ public class RevertCommand extends AbstractInstMgrCommand { private List repositories; @Option(name = "local-cache") private File localCache; - @Option(name = "no-resolve-local-cache", hasValue = false) + @Option(name = NO_RESOLVE_LOCAL_CACHE_OPTION, hasValue = false, activator = AbstractInstMgrCommand.NoResolveLocalCacheActivator.class) private boolean noResolveLocalCache; + @Option(name = USE_DEFAULT_LOCAL_CACHE_OPTION, hasValue = false, activator = AbstractInstMgrCommand.UseDefaultLocalCacheActivator.class) + private boolean useDefaultLocalCache; @Option(name = "offline", hasValue = false) private boolean offline; @OptionList(name = "maven-repo-files") @@ -45,6 +48,9 @@ public class RevertCommand extends AbstractInstMgrCommand { @Option(converter = HeadersConverter.class, completer = HeadersCompleter.class) public ModelNode headers; + private Boolean optNoResolveLocalCache; + private Boolean optUseDefaultLocalCache; + @Override public CommandResult execute(CLICommandInvocation commandInvocation) throws CommandException, InterruptedException { final CommandContext ctx = commandInvocation.getCommandContext(); @@ -54,6 +60,14 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm return CommandResult.FAILURE; } + ParsedCommandLine cmdParser = ctx.getParsedCommandLine(); + optNoResolveLocalCache = cmdParser.hasProperty("--" + NO_RESOLVE_LOCAL_CACHE_OPTION) ? noResolveLocalCache : null; + optUseDefaultLocalCache = cmdParser.hasProperty("--" + USE_DEFAULT_LOCAL_CACHE_OPTION) ? useDefaultLocalCache : null; + + if (optNoResolveLocalCache != null && optUseDefaultLocalCache != null) { + throw new CommandException(String.format("%s and %s cannot be used at the same time.", NO_RESOLVE_LOCAL_CACHE_OPTION, USE_DEFAULT_LOCAL_CACHE_OPTION)); + } + commandInvocation.println("\nThe new installation is being prepared ...\n"); this.executeOp(ctx, this.host); ctx.printLine("The candidate server has been generated. To apply it, restart the server with 'shutdown --perform-installation' command."); @@ -83,7 +97,14 @@ protected Operation buildOperation() throws CommandException { op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toPath().normalize().toAbsolutePath().toString()); } - op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache); + if (optNoResolveLocalCache != null) { + op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache); + } + + if (optUseDefaultLocalCache != null) { + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(useDefaultLocalCache); + } + op.get(InstMgrConstants.OFFLINE).set(offline); if (revision != null) { diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/UpdateCommand.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/UpdateCommand.java index 8939a7ef211..52ebf8993db 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/UpdateCommand.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/UpdateCommand.java @@ -20,6 +20,7 @@ import org.jboss.as.cli.Util; import org.jboss.as.cli.impl.aesh.cmd.HeadersCompleter; import org.jboss.as.cli.impl.aesh.cmd.HeadersConverter; +import org.jboss.as.cli.operation.ParsedCommandLine; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.Operation; import org.jboss.dmr.ModelNode; @@ -38,8 +39,10 @@ public class UpdateCommand extends AbstractInstMgrCommand { private List repositories; @Option(name = "local-cache") private File localCache; - @Option(name = "no-resolve-local-cache", hasValue = false) + @Option(name = NO_RESOLVE_LOCAL_CACHE_OPTION, hasValue = false, activator = AbstractInstMgrCommand.NoResolveLocalCacheActivator.class, defaultValue = "true") private boolean noResolveLocalCache; + @Option(name = USE_DEFAULT_LOCAL_CACHE_OPTION, hasValue = false, activator = AbstractInstMgrCommand.UseDefaultLocalCacheActivator.class) + private boolean useDefaultLocalCache; @Option(name = "offline", hasValue = false) private boolean offline; @OptionList(name = "maven-repo-files") @@ -61,8 +64,13 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm throw new CommandException(String.format("%s and %s cannot be used at the same time.", CONFIRM_OPTION, DRY_RUN_OPTION)); } + ParsedCommandLine cmdParser = ctx.getParsedCommandLine(); + final Boolean optNoResolveLocalCache = cmdParser.hasProperty("--" + NO_RESOLVE_LOCAL_CACHE_OPTION) ? noResolveLocalCache : null; + final Boolean optUseDefaultLocalCache = cmdParser.hasProperty("--" + USE_DEFAULT_LOCAL_CACHE_OPTION) ? useDefaultLocalCache : null; + ListUpdatesAction.Builder listUpdatesCmdBuilder = new ListUpdatesAction.Builder() - .setNoResolveLocalCache(noResolveLocalCache) + .setNoResolveLocalCache(optNoResolveLocalCache) + .setUseDefaultLocalCache(optUseDefaultLocalCache) .setLocalCache(localCache) .setRepositories(repositories) .setMavenRepoFiles(mavenRepoFiles) @@ -119,7 +127,8 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm commandInvocation.println("\nThe new installation is being prepared ...\n"); // trigger an prepare-update PrepareUpdateAction.Builder prepareUpdateActionBuilder = new PrepareUpdateAction.Builder() - .setNoResolveLocalCache(noResolveLocalCache) + .setNoResolveLocalCache(optNoResolveLocalCache) + .setUseDefaultLocalCache(optUseDefaultLocalCache) .setLocalCache(localCache) .setRepositories(repositories) .setOffline(offline) @@ -146,7 +155,7 @@ private void printListUpdatesResult(CLICommandInvocation commandInvocation, List int maxLength = 0; for (ModelNode artifactChange : changesMn) { String channelName = artifactChange.get(InstMgrConstants.HISTORY_DETAILED_ARTIFACT_NAME).asString(); - maxLength = maxLength < channelName.length() ? channelName.length() : maxLength; + maxLength = Math.max(maxLength, channelName.length()); } maxLength += 1; diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/logging/InstMgrLogger.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/logging/InstMgrLogger.java index 262fc3265cd..bffbfa58009 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/logging/InstMgrLogger.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/logging/InstMgrLogger.java @@ -81,6 +81,12 @@ public interface InstMgrLogger extends BasicLogger { @Message(id = 20, value = "No custom patches installed found for the specified manifest maven coordinates: '%s'") OperationFailedException noCustomPatchFound(String manifestGA); + @Message(id = 21, value = "You cannot use the 'local-cache' option when the 'use-default-local-cache' option is enabled.") + OperationFailedException localCacheWithUseDefaultLocalCache(); + + @Message(id = 22, value = "'no-resolve-local-cache' and 'use-default-local-cache' are mutually exclusive (specify only one).") + OperationFailedException noResolveLocalCacheWithUseDefaultLocalCache(); + //////////////////////////////////////////////// // Messages without IDs @@ -89,4 +95,6 @@ public interface InstMgrLogger extends BasicLogger { @Message(id = Message.NONE, value = "The structure of directories and files in the .zip file is invalid. The '%s' directory cannot be found as a second-level entry in the extracted .zip file.") ZipException invalidZipEntry(String directory); + + } diff --git a/installation-manager/src/main/resources/org/wildfly/core/instmgr/LocalDescriptions.properties b/installation-manager/src/main/resources/org/wildfly/core/instmgr/LocalDescriptions.properties index c2b65ac3c70..4b6c3af1692 100644 --- a/installation-manager/src/main/resources/org/wildfly/core/instmgr/LocalDescriptions.properties +++ b/installation-manager/src/main/resources/org/wildfly/core/instmgr/LocalDescriptions.properties @@ -26,6 +26,8 @@ installation-manager.list-updates.offline=Perform installation from local or fil installation-manager.list-updates.repositories=Remote Maven repositories that contain the artifacts required to install the application server (multiple repositories are separated by commas). These repositories will override any other configured repositories in all channels for this operation only. Valid values are either URLs or ID::URL pairs. installation-manager.list-updates.local-cache=Path to the local Maven repository cache. It overrides the default Maven repository at ~/.m2/repository. installation-manager.list-updates.no-resolve-local-cache=Perform the operation without resolving or installing artifacts from/into local maven cache. +installation-manager.list-updates.no-resolve-local-cache.deprecated=Use use-default-local-cache instead. +installation-manager.list-updates.use-default-local-cache=Enable caching and resolving artifacts from the default local Maven repository. installation-manager.list-updates.maven-repo-file=The index of the Maven Repository Zip file stream attached to the current operation. The Maven Repository Zip file contains the necessary artifacts to provide the server candidate with the most recently available updates. installation-manager.list-updates.maven-repo-files=The indexes of the Maven Repository Zip file streams attached to the current operation. The Maven Repository Zip file contains the necessary artifacts to provide the server candidate with the most recently available updates. @@ -35,6 +37,8 @@ installation-manager.prepare-updates.offline=Perform installation from local or installation-manager.prepare-updates.repositories=Remote Maven repositories that contain the artifacts required to install the application server. Specify multiple repositories separated by commas. These repositories will override any other configured repositories in all channels for this operation only. Valid values are either URLs or ID::URL pairs. installation-manager.prepare-updates.local-cache=Path to the local Maven repository cache. It overrides the default Maven repository at ~/.m2/repository. installation-manager.prepare-updates.no-resolve-local-cache=Perform the operation without resolving or installing artifacts from/into local maven cache. +installation-manager.prepare-updates.no-resolve-local-cache.deprecated=Use use-default-local-cache instead. +installation-manager.prepare-updates.use-default-local-cache=Enable caching and resolving artifacts from the default local Maven repository. installation-manager.prepare-updates.maven-repo-file=The index of the Maven Repository Zip file stream attached to the current operation. The Maven Repository Zip file contains the necessary artifacts to provide the server candidate with the most recently available updates. installation-manager.prepare-updates.maven-repo-files=The indexes of the Maven Repository Zip file streams attached to the current operation. The Maven Repository Zip file contains the necessary artifacts to provide the server candidate with the most recently available updates. installation-manager.prepare-updates.work-dir=Directory name relative to the file system of the target server, that contains the Maven repository which provides a server candidate with the most recently available updates. @@ -46,6 +50,8 @@ installation-manager.prepare-revert.offline=Perform installation from local or f installation-manager.prepare-revert.repositories=Remote Maven repositories that contain the artifacts required to install the application server (multiple repositories are separated by commas). These repositories will override any other configured repositories in all channels for this operation only. Valid values are either URLs or ID::URL pairs. installation-manager.prepare-revert.local-cache=Path to the local Maven repository cache. It overrides the default Maven repository at ~/.m2/repository. installation-manager.prepare-revert.no-resolve-local-cache=Perform the operation without resolving or installing artifacts from/into local maven cache. +installation-manager.prepare-revert.no-resolve-local-cache.deprecated=Use use-default-local-cache instead. +installation-manager.prepare-revert.use-default-local-cache=Enable caching and resolving artifacts from the default local Maven repository. installation-manager.prepare-revert.maven-repo-file=The index of the Maven Repository Zip file stream attached to the current operation. The Maven Repository Zip file contains the necessary artifacts to provide the server candidate with the most recently available updates. installation-manager.prepare-revert.maven-repo-files=The indexes of the Maven Repository Zip file streams attached to the current operation. The Maven Repository Zip file contains the necessary artifacts to provide the server candidate with the most recently available updates. diff --git a/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties b/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties index 2655103e378..1f51f133bb4 100644 --- a/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties +++ b/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties @@ -103,7 +103,10 @@ installer.revert.option.local-cache.description=\ system of the remote machine to which the JBoss CLI is connected. installer.revert.option.no-resolve-local-cache.description=\ - Perform the operation without resolving or installing artifacts from/into the local maven cache. + Deprecated, use 'use-default-local-cache' instead. Perform the operation without resolving or installing artifacts from/into the local maven cache. + +installer.revert.option.use-default-local-cache.description=\ + Enable caching and resolving artifacts from the default local Maven repository. installer.revert.option.offline.description=\ Perform installation from local or file-system Maven repositories only. @@ -157,7 +160,10 @@ installer.update.option.local-cache.description=\ system of the remote machine to which the JBoss CLI is connected. installer.update.option.no-resolve-local-cache.description=\ - Perform the operation without resolving or installing artifacts from/into the local maven cache. + Deprecated, use 'use-default-local-cache' instead. Perform the operation without resolving or installing artifacts from/into the local maven cache. + +installer.update.option.use-default-local-cache.description=\ + Enable caching and resolving artifacts from the default local Maven repository. installer.update.option.offline.description=\ Perform installation from local or file-system Maven repositories only. diff --git a/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java b/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java index 9166a8fda83..7e65046d51d 100644 --- a/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java +++ b/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java @@ -502,6 +502,28 @@ public void testListMavenOptions() throws Exception { Assert.assertEquals(MavenOptions.LOCAL_MAVEN_REPO, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.OFFLINE).set(true); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(false); + + response = executeForResult(op); + verifyListUpdatesResult(response, false); + + Assert.assertTrue(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertNull(TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + + + op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.OFFLINE).set(false); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + + response = executeForResult(op); + verifyListUpdatesResult(response, false); + + Assert.assertFalse(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertEquals(MavenOptions.LOCAL_MAVEN_REPO, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + + Path localCache = Paths.get("one").resolve("two").toAbsolutePath(); op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); @@ -540,6 +562,31 @@ public void listUpdatesCannotUseLocalCacheWithNoResolveLocalCache() throws Opera ); } + @Test + public void listUpdatesCannotUseLocalCacheWithUseDefaultLocalCache() throws OperationFailedException { + PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); + Path localCache = Paths.get("dummy").resolve("something"); + ModelNode op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); + + ModelNode failed = executeCheckForFailure(op); + String expectedCode = "WFLYIM0021:"; + Assert.assertTrue( + getCauseLogFailure(failed.get(FAILURE_DESCRIPTION).asString(), expectedCode), + failed.get(FAILURE_DESCRIPTION).asString().startsWith(expectedCode) + ); + + op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(false); + op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); + + executeForResult(op); + + Assert.assertFalse(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertEquals(localCache, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + } + @Test public void listUpdatesCannotUseMavenRepoFileWithRepositories() { PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); @@ -561,6 +608,30 @@ public void listUpdatesCannotUseMavenRepoFileWithRepositories() { ); } + @Test + public void listUpdatesCannotUseNoResolveLocalCacheWithUseDefaultLocalCache() throws OperationFailedException { + PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); + ModelNode op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(true); + + ModelNode failed = executeCheckForFailure(op); + String expectedCode = "WFLYIM0022:"; + Assert.assertTrue( + getCauseLogFailure(failed.get(FAILURE_DESCRIPTION).asString(), expectedCode), + failed.get(FAILURE_DESCRIPTION).asString().startsWith(expectedCode) + ); + + op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + + executeForResult(op); + + op = Util.createEmptyOperation(InstMgrListUpdatesHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(true); + + executeForResult(op); + } @Test public void listUpdatesWithRepositories() throws OperationFailedException, IOException, URISyntaxException { PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); @@ -739,6 +810,34 @@ public void prepareUpdatesMavenOptions() throws OperationFailedException, IOExce Assert.assertEquals(MavenOptions.LOCAL_MAVEN_REPO, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + // Clean it to be able to prepare another + op = Util.createEmptyOperation(InstMgrCleanHandler.OPERATION_NAME, pathElements); + executeForResult(op); + + op = Util.createEmptyOperation(InstMgrPrepareUpdateHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.OFFLINE).set(true); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(false); + + response = executeForResult(op); + Assert.assertEquals(instMgrService.getPreparedServerDir().toString(), response.asString()); + Assert.assertTrue(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertNull(TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + + // Clean it to be able to prepare another + op = Util.createEmptyOperation(InstMgrCleanHandler.OPERATION_NAME, pathElements); + executeForResult(op); + + + op = Util.createEmptyOperation(InstMgrPrepareUpdateHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.OFFLINE).set(false); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + + response = executeForResult(op); + Assert.assertEquals(instMgrService.getPreparedServerDir().toString(), response.asString()); + Assert.assertFalse(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertEquals(MavenOptions.LOCAL_MAVEN_REPO, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + + // Clean it to be able to prepare another op = Util.createEmptyOperation(InstMgrCleanHandler.OPERATION_NAME, pathElements); executeForResult(op); @@ -784,6 +883,31 @@ public void prepareUpdatesCannotUseLocalCacheWithNoResolveLocalCache() throws Op ); } + @Test + public void prepareUpdatesCannotUseLocalCacheWithUseDefaultLocalCache() throws OperationFailedException { + PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); + Path localCache = Paths.get("dummy").resolve("something"); + ModelNode op = Util.createEmptyOperation(InstMgrPrepareUpdateHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); + + ModelNode failed = executeCheckForFailure(op); + String expectedCode = "WFLYIM0021:"; + Assert.assertTrue( + getCauseLogFailure(failed.get(FAILURE_DESCRIPTION).asString(), expectedCode), + failed.get(FAILURE_DESCRIPTION).asString().startsWith(expectedCode) + ); + + op = Util.createEmptyOperation(InstMgrPrepareUpdateHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(false); + op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); + + executeForResult(op); + + Assert.assertFalse(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertEquals(localCache, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + } + @Test public void prepareUpdatesCannotUseMavenRepoFileWithRepositories() { PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); @@ -999,6 +1123,34 @@ public void prepareUpdatesSimple() throws OperationFailedException, IOException } } + @Test + public void prepareRevertCannotUseLocalCacheWithUseDefaultLocalCache() throws OperationFailedException { + PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); + Path localCache = Paths.get("dummy").resolve("something"); + ModelNode op = Util.createEmptyOperation(InstMgrPrepareRevertHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.REVISION).set("aaaabbbb"); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(true); + op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); + + ModelNode failed = executeCheckForFailure(op); + String expectedCode = "WFLYIM0021:"; + Assert.assertTrue( + getCauseLogFailure(failed.get(FAILURE_DESCRIPTION).asString(), expectedCode), + failed.get(FAILURE_DESCRIPTION).asString().startsWith(expectedCode) + ); + + op = Util.createEmptyOperation(InstMgrPrepareRevertHandler.OPERATION_NAME, pathElements); + op.get(InstMgrConstants.REVISION).set("aaaabbbb"); + op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(false); + op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.toString()); + + executeForResult(op); + + Assert.assertFalse(TestInstallationManagerFactory.mavenOptions.isOffline()); + Assert.assertEquals(localCache, TestInstallationManagerFactory.mavenOptions.getLocalRepository()); + } + + @Test public void prepareRevertCannotUseLocalCacheWithNoResolveLocalCache() throws OperationFailedException { PathAddress pathElements = PathAddress.pathAddress(CORE_SERVICE, InstMgrConstants.TOOL_NAME); diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerIntegrationTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerIntegrationTestCase.java index 5adf518eae5..162797f0134 100644 --- a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerIntegrationTestCase.java +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerIntegrationTestCase.java @@ -24,6 +24,8 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -399,7 +401,7 @@ public void updateWithConfirm() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir,p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -413,7 +415,7 @@ public void updateWithConfirmRepositories() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -428,7 +430,28 @@ public void updateWithConfirmLocalCache() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + } + + @Test + public void updateLocalCacheWithUseDefaultLocalCache() { + String host = "primary"; + + AssertionError exception = assertThrows(AssertionError.class, () -> { + cli.sendLine("installer update --local-cache=" + TARGET_DIR + " --use-default-local-cache --host=" + host); + }); + + String expectedMessage = "WFLYIM0021:"; + String actualMessage = exception.getMessage(); + Assert.assertTrue(getCauseLogFailure(actualMessage, expectedMessage), actualMessage.contains(expectedMessage)); + + exception = assertThrows(AssertionError.class, () -> { + cli.sendLine("installer update --local-cache=" + TARGET_DIR + " --use-default-local-cache --host=" + host); + }); + + expectedMessage = "WFLYIM0021:"; + actualMessage = exception.getMessage(); + Assert.assertTrue(getCauseLogFailure(actualMessage, expectedMessage), actualMessage.contains(expectedMessage)); } @Test @@ -483,7 +506,7 @@ public void verifyUpdatePrepareDirWasCreated(String host, String output) throws Assert.assertTrue(Files.exists(expectedPreparedServerDir) && Files.isDirectory(expectedPreparedServerDir)); Assert.assertTrue(expectedPreparedServerDir + " does not contain the expected file marker", - Files.list(expectedPreparedServerDir).allMatch(p -> expectedPreparedServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(expectedPreparedServerDir, p -> expectedPreparedServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @@ -534,7 +557,7 @@ public void updateUsingBlockingTimeout() throws IOException { Assert.assertTrue(Files.exists(secondaryPrepareServerDir) && Files.isDirectory(secondaryPrepareServerDir)); Assert.assertTrue(secondaryPrepareServerDir + " does not contain the expected file marker", - Files.list(secondaryPrepareServerDir).allMatch(p -> secondaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(secondaryPrepareServerDir, p -> secondaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -566,7 +589,7 @@ public void revertWithMavenZipFile() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -585,7 +608,7 @@ public void revertWithMultipleMavenZipFiles() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -599,6 +622,17 @@ public void revertWithNoResolveLocalMavenCache() throws IOException { Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } + @Test + public void revertWithUseDefaultLocalCache() throws IOException { + String host = "primary"; + + assertTrue(cli.sendLine("installer revert --revision=dummy --use-default-local-cache --host=" + host, false)); + + Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); + Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + } + @Test public void revertWithLocalCacheMavenCache() throws IOException { String host = "primary"; @@ -607,7 +641,28 @@ public void revertWithLocalCacheMavenCache() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + } + + @Test + public void revertLocalCacheWithUseDefaultLocalCache() { + String host = "primary"; + + AssertionError exception = assertThrows(AssertionError.class, () -> { + cli.sendLine("installer revert --revision=dummy --local-cache=" + TARGET_DIR + " --use-default-local-cache --host=" + host); + }); + + String expectedMessage = "WFLYIM0021:"; + String actualMessage = exception.getMessage(); + Assert.assertTrue(getCauseLogFailure(actualMessage, expectedMessage), actualMessage.contains(expectedMessage)); + + exception = assertThrows(AssertionError.class, () -> { + cli.sendLine("installer revert --revision=dummy --local-cache=" + TARGET_DIR + " --use-default-local-cache=true --host=" + host); + }); + + expectedMessage = "WFLYIM0021:"; + actualMessage = exception.getMessage(); + Assert.assertTrue(getCauseLogFailure(actualMessage, expectedMessage), actualMessage.contains(expectedMessage)); } @Test @@ -618,7 +673,7 @@ public void revertWithOffline() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -629,7 +684,7 @@ public void revertWithHeaders() throws IOException { Assert.assertTrue(Files.exists(secondaryPrepareServerDir) && Files.isDirectory(secondaryPrepareServerDir)); Assert.assertTrue(secondaryPrepareServerDir + " does not contain the expected file marker", - Files.list(secondaryPrepareServerDir).allMatch(p -> secondaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(secondaryPrepareServerDir, p -> secondaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -640,7 +695,7 @@ public void revertWithRepositories() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -651,7 +706,7 @@ public void simpleRevert() throws IOException { Assert.assertTrue(Files.exists(primaryPrepareServerDir) && Files.isDirectory(primaryPrepareServerDir)); Assert.assertTrue(primaryPrepareServerDir + " does not contain the expected file marker", - Files.list(primaryPrepareServerDir).allMatch(p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); + directoryOnlyContains(primaryPrepareServerDir, p -> primaryPrepareServerDir.relativize(p).toString().startsWith("server-prepare-marker-"))); } @Test @@ -724,7 +779,7 @@ public void uploadAndRemoveMultipleCustomPatches() throws IOException { final Path customPatchMavenRepo = hostCustomPatchDir_2.resolve(InstMgrConstants.MAVEN_REPO_DIR_NAME_IN_ZIP_FILES); Assert.assertTrue(Files.exists(customPatchMavenRepo) && Files.isDirectory(customPatchMavenRepo)); Assert.assertTrue(hostCustomPatchDir_2 + " does not contain the expected maven repository", - Files.list(customPatchMavenRepo).allMatch(p -> customPatchMavenRepo.relativize(p).toString().equals("artifact-two"))); + directoryOnlyContains(customPatchMavenRepo, p -> customPatchMavenRepo.relativize(p).toString().equals("artifact-two"))); // remove the patch 2 removeCustomPatch(patchManifestGA_2, host, hostCustomPatchDir_2); @@ -737,7 +792,7 @@ public void createAndUploadCustomPatch(String customPatchManifest, String host, // verify the patch doesn't exist yet final Path customPatchMavenRepo = hostCustomPatchDir.resolve(InstMgrConstants.MAVEN_REPO_DIR_NAME_IN_ZIP_FILES); - Assert.assertTrue(!Files.exists(customPatchMavenRepo)); + Assert.assertFalse(Files.exists(customPatchMavenRepo)); Assert.assertTrue( cli.sendLine("installer upload-custom-patch --custom-patch-file=" + target + " --manifest=" + customPatchManifest + " --host=" + host, false)); @@ -745,7 +800,7 @@ public void createAndUploadCustomPatch(String customPatchManifest, String host, Assert.assertTrue(cli.sendLine("installer clean --host=" + host, false)); Assert.assertTrue(Files.exists(customPatchMavenRepo) && Files.isDirectory(customPatchMavenRepo)); Assert.assertTrue(hostCustomPatchDir + " does not contain the expected artifact included in the custom patch Zip file", - Files.list(customPatchMavenRepo).allMatch(p -> customPatchMavenRepo.relativize(p).toString().equals(expectedArtifact))); + directoryOnlyContains(customPatchMavenRepo, p -> customPatchMavenRepo.relativize(p).toString().equals(expectedArtifact))); } public void removeCustomPatch(String customPatchManifest, String host, Path hostCustomPatchDir) { @@ -792,4 +847,10 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr public String getCauseLogFailure(String description, String expectedLogCode) { return "Unexpected Error Code. Got " + description + " It was expected: " + expectedLogCode; } + + public boolean directoryOnlyContains(Path directory, Predicate match) throws IOException { + try (Stream stream = Files.list(directory)) { + return stream.allMatch(match); + } + } } From ae34f5bca7aa4d1a55bd462b0c92c11844251723 Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Thu, 21 Dec 2023 13:29:25 +0000 Subject: [PATCH 2/2] [WFCORE-6653] Missing maven-repo-files description on the help of management CLI installer command Jira issue: https://issues.redhat.com/browse/WFCORE-6653 --- .../wildfly/core/instmgr/cli/command_resources.properties | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties b/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties index 1f51f133bb4..f339861ac3f 100644 --- a/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties +++ b/installation-manager/src/main/resources/org/wildfly/core/instmgr/cli/command_resources.properties @@ -111,8 +111,8 @@ installer.revert.option.use-default-local-cache.description=\ installer.revert.option.offline.description=\ Perform installation from local or file-system Maven repositories only. -installer.revert.option.maven-repo-file.description=\ - The location of the local Maven repository zip File. The file contains the necessary artifacts to prepare the server candidate we want to apply. +installer.revert.option.maven-repo-files.description=\ + Comma separated list of individual Maven repository zip Files that contain the necessary artifacts to prepare the server candidate we want to apply. installer.revert.option.revision.description=\ Hash of an installation state of the previous version. The base server will be reverted to this installation state. @@ -172,6 +172,8 @@ installer.update.option.headers.description=\ Any operation headers. Depending on the target environment, preparing a server could take time because all the required artifacts need to be downloaded to provision \ the server candidate. You can use the operation headers to increase the default blocking timeout which is 300 seconds. +installer.update.option.maven-repo-files.description=\ + Comma separated list of individual Maven repository zip Files that contain the necessary artifacts to prepare the server candidate we want to apply. # UPLOAD CUSTOM PATCHES installer.upload-custom-patch.description=\