From c0d8ddc373f9ad879637e60bf9b08ba8ecb80f7a Mon Sep 17 00:00:00 2001 From: Bartosz Spyrko-Smietanko Date: Thu, 31 Aug 2023 17:37:29 +0100 Subject: [PATCH] Split up default-config and layer config arguments --- dist/docs/guide/usage/add_feature_pack.adoc | 2 + .../prospero/cli/commands/CliConstants.java | 1 + .../cli/commands/FeaturesCommand.java | 39 ++++-- .../main/resources/UsageMessages.properties | 3 + .../cli/commands/FeaturesCommandTest.java | 70 ++++++---- .../org/wildfly/prospero/ProsperoLogger.java | 4 +- .../prospero/actions/FeaturesAddAction.java | 125 ++++++++++++++---- .../actions/FeaturesAddActionTest.java | 42 +++--- 8 files changed, 206 insertions(+), 80 deletions(-) diff --git a/dist/docs/guide/usage/add_feature_pack.adoc b/dist/docs/guide/usage/add_feature_pack.adoc index bb82a9def..1a31649ce 100644 --- a/dist/docs/guide/usage/add_feature_pack.adoc +++ b/dist/docs/guide/usage/add_feature_pack.adoc @@ -58,6 +58,8 @@ $ prospero feature-pack add \ If the feature pack provides multiple configuration model, the configuration name can be prefixed with model name e.g. `--config standalone/standalone.xml` +Some feature packs provide a set of "default" configurations that will be included when installing the feature pack without `--layers` option. This list can be modified using `--default-config` parameter selecting which default configurations should be provisioned. + #### Offline installation Similarly to other operations, `feature-pack add` can be executed in an offline mode. To do so, users should provide local repositories with all required artifacts (both for base server and the new feature) using `--repositories` parameter. diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java index 3e5c181e5..6fe8695e3 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java @@ -102,4 +102,5 @@ private Commands() { public static final String LAYERS = "--layers"; public static final String CONFIG = "--config"; + public static final String DEFAULT_CONFIG = "--default-config"; } diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/FeaturesCommand.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/FeaturesCommand.java index b370640dd..c5f3ddec9 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/FeaturesCommand.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/FeaturesCommand.java @@ -29,9 +29,10 @@ import picocli.CommandLine; import java.nio.file.Path; -import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static org.wildfly.prospero.cli.commands.CliConstants.Commands.FEATURE_PACKS_ALIAS; @@ -47,11 +48,25 @@ public static class AddCommand extends AbstractMavenCommand { required = true) private String fpl; - @CommandLine.Option(names = CliConstants.LAYERS, split = ",") - private Set layers; - @CommandLine.Option(names = CliConstants.CONFIG) - private String config; + private static class LayersOptions { + @CommandLine.Option(names = CliConstants.LAYERS, split = ",", required = true) + private Set layers; + + @CommandLine.Option(names = CliConstants.CONFIG) + private String config; + } + + private static class ConfigOptions { + + @CommandLine.ArgGroup(exclusive = false) + private LayersOptions layersOptions = new LayersOptions(); + @CommandLine.Option(names = CliConstants.DEFAULT_CONFIG, split = ",") + private final Set defaultConfig = new HashSet<>(); + } + + @CommandLine.ArgGroup + private final ConfigOptions configOptions = new ConfigOptions(); @CommandLine.Option(names = {CliConstants.Y, CliConstants.YES}) boolean skipConfirmation; @@ -92,7 +107,12 @@ public Integer call() throws Exception { } try { - featuresAddAction.addFeaturePack(fpl, layers == null ? Collections.emptySet() : layers, parseConfigName()); + if (configOptions.layersOptions.layers == null) { + final Set configurations = configOptions.defaultConfig.stream().map(AddCommand::parseConfigName).collect(Collectors.toSet()); + featuresAddAction.addFeaturePack(fpl, configurations); + } else { + featuresAddAction.addFeaturePackWithLayers(fpl, configOptions.layersOptions.layers, parseConfigName(configOptions.layersOptions.config)); + } } catch (FeaturesAddAction.LayerNotFoundException e) { if (!e.getSupportedLayers().isEmpty()) { console.error(CliMessages.MESSAGES.layerNotSupported(fpl, e.getLayers(), e.getSupportedLayers())); @@ -114,7 +134,7 @@ public Integer call() throws Exception { return ReturnCodes.SUCCESS; } - private ConfigId parseConfigName() { + private static ConfigId parseConfigName(String config) { if (config == null) { return null; } @@ -123,15 +143,16 @@ private ConfigId parseConfigName() { return new ConfigId(null, config.trim()); } - if (i == config.length() -1) { + if (i == config.length() - 1) { return new ConfigId(config.substring(0, i).trim(), null); } else { - return new ConfigId(config.substring(0, i).trim(), config.substring(i+1).trim()); + return new ConfigId(config.substring(0, i).trim(), config.substring(i + 1).trim()); } } } + public FeaturesCommand(CliConsole console, ActionFactory actionFactory) { super(console, actionFactory, CliConstants.Commands.FEATURE_PACKS, List.of(new AddCommand(console, actionFactory))); } diff --git a/prospero-cli/src/main/resources/UsageMessages.properties b/prospero-cli/src/main/resources/UsageMessages.properties index 5456bfaa2..0594fb901 100644 --- a/prospero-cli/src/main/resources/UsageMessages.properties +++ b/prospero-cli/src/main/resources/UsageMessages.properties @@ -105,6 +105,9 @@ ${prospero.dist.name}.feature-pack.add.usage.header = Installs a new feature pac ${prospero.dist.name}.feature-pack.add.layers = Feature Pack layers selected for installation. Specify multiple layers separated by commas. ${prospero.dist.name}.feature-pack.add.config = Configuration file that the Feature Pack changes will be applied to. \ If not specified, defaults to the @|bold .xml|@ (e.g. standalone.xml). +${prospero.dist.name}.feature-pack.add.default-config = Selects which pre-defined configurations will be installed. \ + If not defined uses default configurations defined in the feature pack \ + Cannot be combined with --layers option. ${prospero.dist.name}.feature-pack.add.model = Configuration model (standalone or domain) that the Feature Pack changes should be applied to. \ If not specified, defaults to the model selected by the chosen layer. diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/FeaturesCommandTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/FeaturesCommandTest.java index 43cd38249..3df1f5385 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/FeaturesCommandTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/FeaturesCommandTest.java @@ -62,6 +62,8 @@ public class FeaturesCommandTest extends AbstractMavenCommandTest { @Captor private ArgumentCaptor configNameCaptor; + @Captor + private ArgumentCaptor> defaultConfigNamesCaptor; @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); @@ -106,13 +108,10 @@ public void passArgumentsToFeaturesAddAction_OnlyFpl() throws Exception { assertEquals(ReturnCodes.SUCCESS, exitCode); final ArgumentCaptor fplCaptor = ArgumentCaptor.forClass(String.class); - final ArgumentCaptor> layersCaptor = ArgumentCaptor.forClass(Set.class); - verify(featuresAddAction).addFeaturePack(fplCaptor.capture(), layersCaptor.capture(), - configNameCaptor.capture()); + verify(featuresAddAction).addFeaturePack(fplCaptor.capture(), defaultConfigNamesCaptor.capture()); assertEquals(fplCaptor.getValue(), "test:test"); - assertEquals(Collections.emptySet(), layersCaptor.getValue()); - assertEquals(configNameCaptor.getValue(), null); + assertEquals(defaultConfigNamesCaptor.getValue(), Collections.emptySet()); } @Test @@ -124,7 +123,7 @@ public void passArgumentsToFeaturesAddAction_LayersAreSplit() throws Exception { assertEquals(ReturnCodes.SUCCESS, exitCode); final ArgumentCaptor> layersCaptor = ArgumentCaptor.forClass(Set.class); - verify(featuresAddAction).addFeaturePack(any(), layersCaptor.capture(), + verify(featuresAddAction).addFeaturePackWithLayers(any(), layersCaptor.capture(), any()); assertEquals(Set.of("layer1", "layer2"), layersCaptor.getValue()); @@ -135,13 +134,14 @@ public void passArgumentsToFeaturesAddAction_ModuleOnlyConfig() throws Exception int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, CliConstants.DIR, installationDir.toString(), CliConstants.FPL, "test:test", - CliConstants.CONFIG, "test/"); + CliConstants.DEFAULT_CONFIG, "test/"); assertEquals(ReturnCodes.SUCCESS, exitCode); - verify(featuresAddAction).addFeaturePack(any(), any(), - configNameCaptor.capture()); + verify(featuresAddAction).addFeaturePack(any(), + defaultConfigNamesCaptor.capture()); - assertEquals(new ConfigId("test", null), configNameCaptor.getValue()); + assertThat(defaultConfigNamesCaptor.getValue()) + .contains(new ConfigId("test", null)); } @Test @@ -149,13 +149,14 @@ public void passArgumentsToFeaturesAddAction_NameOnlyConfig() throws Exception { int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, CliConstants.DIR, installationDir.toString(), CliConstants.FPL, "test:test", - CliConstants.CONFIG, "test"); + CliConstants.DEFAULT_CONFIG, "test"); assertEquals(ReturnCodes.SUCCESS, exitCode); - verify(featuresAddAction).addFeaturePack(any(), any(), - configNameCaptor.capture()); + verify(featuresAddAction).addFeaturePack(any(), + defaultConfigNamesCaptor.capture()); - assertEquals(new ConfigId(null, "test"), configNameCaptor.getValue()); + assertThat(defaultConfigNamesCaptor.getValue()) + .contains(new ConfigId(null, "test")); } @Test @@ -168,7 +169,7 @@ public void passArgumentsToFeaturesAddAction_AllParameters() throws Exception { assertEquals(ReturnCodes.SUCCESS, exitCode); final ArgumentCaptor> layersCaptor = ArgumentCaptor.forClass(Set.class); - verify(featuresAddAction).addFeaturePack(any(), layersCaptor.capture(), configNameCaptor.capture()); + verify(featuresAddAction).addFeaturePackWithLayers(any(), layersCaptor.capture(), configNameCaptor.capture()); assertEquals(Set.of("layer1"), layersCaptor.getValue()); assertEquals(new ConfigId("model", "config"), configNameCaptor.getValue()); @@ -230,7 +231,7 @@ public void fplWithTreePartsFails() throws Exception { @Test public void nonExistingLayersShowsError() throws Exception { doThrow(new FeaturesAddAction.LayerNotFoundException("foo", Set.of("idontexist"), Set.of("layer1", "layer2"))) - .when(featuresAddAction).addFeaturePack("org.test:test", Set.of("idontexist"), null); + .when(featuresAddAction).addFeaturePackWithLayers("org.test:test", Set.of("idontexist"), null); int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, CliConstants.DIR, installationDir.toString(), CliConstants.LAYERS, "idontexist", @@ -244,7 +245,7 @@ public void nonExistingLayersShowsError() throws Exception { @Test public void nonExistingLayersShowsErrorNoAvailableLayers() throws Exception { doThrow(new FeaturesAddAction.LayerNotFoundException("foo", Set.of("idontexist"), Collections.emptySet())) - .when(featuresAddAction).addFeaturePack("org.test:test", Set.of("idontexist"), null); + .when(featuresAddAction).addFeaturePackWithLayers("org.test:test", Set.of("idontexist"), null); int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, CliConstants.DIR, installationDir.toString(), CliConstants.LAYERS, "idontexist", @@ -259,11 +260,11 @@ public void nonExistingLayersShowsErrorNoAvailableLayers() throws Exception { @Test public void nonExistingModelShowsError() throws Exception { doThrow(new FeaturesAddAction.ModelNotDefinedException("test", "idontexist", Set.of("model1", "model2"))) - .when(featuresAddAction).addFeaturePack("org.test:test", Collections.emptySet(), - new ConfigId("idontexist", "test")); + .when(featuresAddAction).addFeaturePack("org.test:test", + Set.of(new ConfigId("idontexist", "test"))); int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, CliConstants.DIR, installationDir.toString(), - CliConstants.CONFIG, "idontexist/test", + CliConstants.DEFAULT_CONFIG, "idontexist/test", CliConstants.FPL, "org.test:test"); assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode); assertThat(getErrorOutput()) @@ -274,17 +275,40 @@ public void nonExistingModelShowsError() throws Exception { @Test public void nonExistingConfigurationShowsError() throws Exception { doThrow(new FeaturesAddAction.ConfigurationNotFoundException("test", new ConfigId("test", "idontexist"))) - .when(featuresAddAction).addFeaturePack("org.test:test", Collections.emptySet(), - new ConfigId("test", "idontexist")); + .when(featuresAddAction).addFeaturePack("org.test:test", + Set.of(new ConfigId("test", "idontexist"))); int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, CliConstants.DIR, installationDir.toString(), - CliConstants.CONFIG, "test/idontexist", + CliConstants.DEFAULT_CONFIG, "test/idontexist", CliConstants.FPL, "org.test:test"); assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode); assertThat(getErrorOutput()) .contains("The feature pack `org.test:test` does not provide requested configuration `test/idontexist`."); } + @Test + public void configRequiresLayer() throws Exception { + int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, + CliConstants.DIR, installationDir.toString(), + CliConstants.CONFIG, "test/idontexist", + CliConstants.FPL, "org.test:test"); + assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode); + assertThat(getErrorOutput()) + .contains("Missing required argument(s): --layers"); + } + + @Test + public void layersExcludeDefaultConfig() throws Exception { + int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD, + CliConstants.DIR, installationDir.toString(), + CliConstants.DEFAULT_CONFIG, "test/idontexist", + CliConstants.LAYERS, "layer1", + CliConstants.FPL, "org.test:test"); + assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode); + assertThat(getErrorOutput()) + .contains("are mutually exclusive (specify only one)"); + } + @Override protected ActionFactory createActionFactory() { return actionFactory; diff --git a/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java b/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java index 787215583..2cf9bf95c 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java @@ -342,8 +342,8 @@ public interface ProsperoLogger extends BasicLogger { FeaturesAddAction.FeaturePackAlreadyInstalledException featurePackAlreadyInstalled(FeaturePackLocation fpl); @LogMessage(level = Logger.Level.DEBUG) - @Message(id = 258, value = "Adding a feature pack [%s] with configId [%s:%s] and layers [%s]") - void addingFeaturePack(FeaturePackLocation fpl, String selectedConfig, String selectedModel, String layers); + @Message(id = 258, value = "Adding a feature pack [%s] with configuration %s and layers [%s]") + void addingFeaturePack(FeaturePackLocation fpl, String configuration, String layers); @Message(id = 259, value = "Requested configuration %s/%s is not available in the feature packs.") String galleonConfigNotFound(String model, String name); diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/FeaturesAddAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/FeaturesAddAction.java index f0e08b27c..828a2f8ce 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/actions/FeaturesAddAction.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/FeaturesAddAction.java @@ -98,6 +98,60 @@ public FeaturesAddAction(MavenOptions mavenOptions, Path installDir, List defaultConfigNames) + throws ProvisioningException, OperationException { + verifyFeaturePackCoord(featurePackCoord); + Objects.requireNonNull(defaultConfigNames); + + FeaturePackLocation fpl = FeaturePackLocationParser.resolveFpl(featurePackCoord); + + if (ProsperoLogger.ROOT_LOGGER.isTraceEnabled()) { + ProsperoLogger.ROOT_LOGGER.trace("Adding feature pack " + fpl); + } + + final Map> allLayers = getAllLayers(fpl); + + if (ProsperoLogger.ROOT_LOGGER.isTraceEnabled()) { + ProsperoLogger.ROOT_LOGGER.trace("Found layers"); + for (String key : allLayers.keySet()) { + ProsperoLogger.ROOT_LOGGER.trace(key + ": " + StringUtils.join(allLayers.get(key))); + } + } + + final Set selectedConfigs = new HashSet<>(); + for (ConfigId defaultConfigName : defaultConfigNames) { + final String selectedModel = getSelectedModel(defaultConfigName==null?null:defaultConfigName.getModel(), allLayers); + + final String selectedConfig = getSelectedConfig(defaultConfigName, selectedModel); + if (selectedConfig != null) { + selectedConfigs.add(new ConfigId(selectedModel, selectedConfig)); + } + } + + if (ProsperoLogger.ROOT_LOGGER.isDebugEnabled()) { + ProsperoLogger.ROOT_LOGGER.addingFeaturePack(fpl, StringUtils.join(selectedConfigs, ","), ""); + } + + + final ProvisioningConfig newConfig = buildProvisioningConfig(Collections.emptySet(), fpl, selectedConfigs); + + install(newConfig); + } + /** * performs feature pack installation. The added feature pack can be customized by specifying layers and configuration model name. * In order to install a feature pack, a server is re-provisioned and changes are applied to existing server. @@ -113,15 +167,13 @@ public FeaturesAddAction(MavenOptions mavenOptions, Path installDir, List layers, ConfigId configName) + public void addFeaturePackWithLayers(String featurePackCoord, Set layers, ConfigId configName) throws ProvisioningException, OperationException { Objects.requireNonNull(layers); - if (featurePackCoord == null || featurePackCoord.isEmpty()) { - throw new IllegalArgumentException("The feature pack coordinate cannot be null"); - } - if (featurePackCoord.split(":").length != 2) { - throw new IllegalArgumentException("The feature pack coordinate has to consist of :"); + if (layers.isEmpty() && configName != null) { + throw new IllegalArgumentException("The layers have to be selected if configName is not empty"); } + verifyFeaturePackCoord(featurePackCoord); FeaturePackLocation fpl = FeaturePackLocationParser.resolveFpl(featurePackCoord); @@ -129,9 +181,6 @@ public void addFeaturePack(String featurePackCoord, Set layers, ConfigId ProsperoLogger.ROOT_LOGGER.trace("Adding feature pack " + fpl); } - final String selectedConfig; - final String selectedModel; - final Map> allLayers = getAllLayers(fpl); if (ProsperoLogger.ROOT_LOGGER.isTraceEnabled()) { @@ -141,26 +190,43 @@ public void addFeaturePack(String featurePackCoord, Set layers, ConfigId } } - selectedModel = getSelectedModel(configName == null?null:configName.getModel(), allLayers); + final String selectedModel = getSelectedModel(configName == null?null:configName.getModel(), allLayers); verifyLayerAvailable(layers, selectedModel, allLayers); - if (configName == null || configName.getName() == null) { + final String selectedConfig = getSelectedConfig(configName, selectedModel); + + if (ProsperoLogger.ROOT_LOGGER.isDebugEnabled()) { + ProsperoLogger.ROOT_LOGGER.addingFeaturePack(fpl, selectedConfig + ":" + selectedModel, StringUtils.join(layers)); + } + + final ProvisioningConfig newConfig = buildProvisioningConfig(layers, fpl, selectedConfig==null?Collections.emptySet():Set.of(new ConfigId(selectedModel, selectedConfig))); + + install(newConfig); + } + + private static String getSelectedConfig(ConfigId defaultConfigName, String selectedModel) { + if (defaultConfigName == null || defaultConfigName.getName() == null) { if (selectedModel == null) { - selectedConfig = null; + return null; } else { - selectedConfig = selectedModel + ".xml"; + return selectedModel + ".xml"; } } else { - selectedConfig = configName.getName(); + return defaultConfigName.getName(); } + } - if (ProsperoLogger.ROOT_LOGGER.isDebugEnabled()) { - ProsperoLogger.ROOT_LOGGER.addingFeaturePack(fpl, selectedConfig, selectedModel, StringUtils.join(layers)); + private static void verifyFeaturePackCoord(String featurePackCoord) { + if (featurePackCoord == null || featurePackCoord.isEmpty()) { + throw new IllegalArgumentException("The feature pack coordinate cannot be null"); } + if (featurePackCoord.split(":").length != 2) { + throw new IllegalArgumentException("The feature pack coordinate has to consist of :"); + } + } - final ProvisioningConfig newConfig = buildProvisioningConfig(layers, fpl, selectedConfig, selectedModel); - + private void install(ProvisioningConfig newConfig) throws ProvisioningException, OperationException { final Path candidate; try { candidate = Files.createTempDirectory("prospero-candidate").toAbsolutePath(); @@ -226,8 +292,11 @@ public boolean isFeaturePackAvailable(String featurePackCoord) throws OperationE return true; } - private ProvisioningConfig buildProvisioningConfig(Set layers, FeaturePackLocation fpl, String selectedConfig, String selectedModel) + private ProvisioningConfig buildProvisioningConfig(Set layers, FeaturePackLocation fpl, Set selectedConfigs) throws ProvisioningException, OperationException { + if (!layers.isEmpty() && selectedConfigs.size() > 1) { + throw new IllegalArgumentException("Only one config can be selected when selecting layers"); + } try (GalleonEnvironment galleonEnv = getGalleonEnv(installDir); ProvisioningManager pm = galleonEnv.getProvisioningManager()) { @@ -236,13 +305,19 @@ private ProvisioningConfig buildProvisioningConfig(Set layers, FeaturePa final FeaturePackConfig.Builder fpBuilder = buildFeaturePackConfig(fpl, existingConfig, builder); - if (selectedConfig != null) { + if (!selectedConfigs.isEmpty()) { fpBuilder.setInheritConfigs(false); - if (!layers.isEmpty()) { - final ConfigModel.Builder configBuilder = buildLayerConfig(layers, selectedConfig, selectedModel, existingConfig, builder); - builder.addConfig(configBuilder.build()); - } else { - fpBuilder.includeDefaultConfig(selectedModel, selectedConfig); + } + + for (ConfigId selectedConfig : selectedConfigs) { + if (selectedConfig != null) { + fpBuilder.setInheritConfigs(false); + if (!layers.isEmpty()) { + final ConfigModel.Builder configBuilder = buildLayerConfig(layers, selectedConfig.getName(), selectedConfig.getModel(), existingConfig, builder); + builder.addConfig(configBuilder.build()); + } else { + fpBuilder.includeDefaultConfig(selectedConfig.getModel(), selectedConfig.getName()); + } } } diff --git a/prospero-common/src/test/java/org/wildfly/prospero/actions/FeaturesAddActionTest.java b/prospero-common/src/test/java/org/wildfly/prospero/actions/FeaturesAddActionTest.java index 9ea01213e..d14a22fc8 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/actions/FeaturesAddActionTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/actions/FeaturesAddActionTest.java @@ -196,7 +196,7 @@ public void layerNotAvailable_throwsException() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - assertThatThrownBy(()-> getFeaturesAddAction().addFeaturePack("org.test:added-pack", + assertThatThrownBy(()-> getFeaturesAddAction().addFeaturePackWithLayers("org.test:added-pack", Set.of("idontexist"), NO_CONFIG)) .isInstanceOf(FeaturesAddAction.LayerNotFoundException.class) .hasFieldOrPropertyWithValue("layers", Set.of("idontexist")) @@ -219,7 +219,7 @@ public void noLayersInTheFeaturePacks_provisionsNoConfigs() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - getFeaturesAddAction().addFeaturePack("org.test:added-pack", Collections.emptySet(), NO_CONFIG); + getFeaturesAddAction().addFeaturePack("org.test:added-pack", Collections.emptySet()); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), @@ -244,7 +244,7 @@ public void noLayersInTheFeaturePackWithRequriedLayer_throwsException() throws E // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - assertThatThrownBy(()-> getFeaturesAddAction().addFeaturePack("org.test:added-pack", + assertThatThrownBy(()-> getFeaturesAddAction().addFeaturePackWithLayers("org.test:added-pack", Set.of("idontexist"), NO_CONFIG)) .isInstanceOf(FeaturesAddAction.LayerNotFoundException.class) .hasFieldOrPropertyWithValue("layers", Set.of("idontexist")); @@ -274,7 +274,7 @@ public void requestedLayerAddsItsConfig() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - getFeaturesAddAction().addFeaturePack("org.test:added-pack", Set.of("layer1"), NO_CONFIG); + getFeaturesAddAction().addFeaturePackWithLayers("org.test:added-pack", Set.of("layer1"), NO_CONFIG); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), @@ -310,7 +310,7 @@ public void selectedConfigOverridesDefaultWithRequestedLayer() throws Exception // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - getFeaturesAddAction().addFeaturePack("org.test:added-pack", Set.of("layer1"), + getFeaturesAddAction().addFeaturePackWithLayers("org.test:added-pack", Set.of("layer1"), new ConfigId(null, "test.xml")); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); @@ -357,7 +357,7 @@ public void addFeaturePackAlreadyInstalledAsDependency() throws Exception { .build()); mockInstallationData(installDir, "org.test:base-pack:1.0.0", "org.test:added-pack:1.0.0"); - getFeaturesAddAction().addFeaturePack("org.test:added-pack", Set.of("layer2"), new ConfigId(null, "test.xml")); + getFeaturesAddAction().addFeaturePackWithLayers("org.test:added-pack", Set.of("layer2"), new ConfigId(null, "test.xml")); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), @@ -414,7 +414,7 @@ public void installingLayerOverridesExcludesLayer() throws Exception { .build()); mockInstallationData(installDir, "org.test:base-pack:1.0.0"); - getFeaturesAddAction().addFeaturePack("org.test:added-pack", Set.of("layer2"), new ConfigId(null, "test.xml")); + getFeaturesAddAction().addFeaturePackWithLayers("org.test:added-pack", Set.of("layer2"), new ConfigId(null, "test.xml")); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), @@ -458,7 +458,7 @@ public void multipleModelsDefinedInLayersWithoutSelectedModel_throwError() throw installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack( - "org.test:added-pack", Collections.emptySet(), new ConfigId(null, "test"))) + "org.test:added-pack", Set.of(new ConfigId(null, "test")))) .isInstanceOf(FeaturesAddAction.ModelNotDefinedException.class); } @@ -478,7 +478,7 @@ public void selectedModelIsNotDefinedInFeaturePack_throwError() throws Exception installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack( - "org.test:added-pack", Collections.emptySet(), new ConfigId("model2", null))) + "org.test:added-pack", Set.of(new ConfigId("model2", null)))) .isInstanceOf(FeaturesAddAction.ModelNotDefinedException.class) .hasFieldOrPropertyWithValue("model", "model2"); @@ -507,7 +507,7 @@ public void selectedModelOverridesTheDefault() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - getFeaturesAddAction().addFeaturePack( + getFeaturesAddAction().addFeaturePackWithLayers( "org.test:added-pack", Set.of("layer1"), new ConfigId("model2", null)); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), @@ -533,8 +533,8 @@ public void featurePacksWithoutLayersCanBeInstalled() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - getFeaturesAddAction().addFeaturePack( - "org.test:added-pack", Collections.emptySet(), null); + getFeaturesAddAction().addFeaturePackWithLayers( + "org.test:added-pack", Set.of(), NO_CONFIG); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), provisioningConfigArgumentCaptor.capture()); @@ -549,21 +549,21 @@ public void featurePacksWithoutLayersCanBeInstalled() throws Exception { @Test public void invalidFeatureNameThrowsException() throws Exception { mockInstallationData(installDir); - assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack(null, Collections.emptySet(), NO_CONFIG)) + assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack(null, Collections.emptySet())) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The feature pack coordinate cannot be null"); assertThatThrownBy(()->getFeaturesAddAction().isFeaturePackAvailable(null)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The feature pack coordinate cannot be null"); - assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack("only_group", Collections.emptySet(), NO_CONFIG)) + assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack("only_group", Collections.emptySet())) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The feature pack coordinate has to consist of :"); assertThatThrownBy(()->getFeaturesAddAction().isFeaturePackAvailable("only_group")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The feature pack coordinate has to consist of :"); - assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack("too:many:parts", Collections.emptySet(), NO_CONFIG)) + assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack("too:many:parts", Collections.emptySet())) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The feature pack coordinate has to consist of :"); assertThatThrownBy(()->getFeaturesAddAction().isFeaturePackAvailable("too:many:parts")) @@ -587,7 +587,7 @@ public void existingFeaturePackCannotBeInstalled() throws Exception { installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack( - "org.test:base-pack", Collections.emptySet(), NO_CONFIG)) + "org.test:base-pack", Collections.emptySet())) .isInstanceOf(FeaturesAddAction.FeaturePackAlreadyInstalledException.class); } @@ -606,7 +606,7 @@ public void installDefaultPackagesIfNoLayersAreSpecified() throws Exception { installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); getFeaturesAddAction().addFeaturePack( - "org.test:added-pack", Collections.emptySet(), NO_CONFIG); + "org.test:added-pack", Collections.emptySet()); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), provisioningConfigArgumentCaptor.capture()); @@ -654,7 +654,7 @@ public void installSelectedConfigsIfNoLayersAreSpecified() throws Exception { installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); getFeaturesAddAction().addFeaturePack( - "org.test:added-pack", Collections.emptySet(), new ConfigId("model1", "config2")); + "org.test:added-pack", Set.of(new ConfigId("model1", "config2"))); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), provisioningConfigArgumentCaptor.capture()); @@ -707,7 +707,7 @@ public void installSelectedConfigsIfLayersAreSpecified() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - getFeaturesAddAction().addFeaturePack( + getFeaturesAddAction().addFeaturePackWithLayers( "org.test:added-pack", Set.of("layer1"), NO_CONFIG); final ArgumentCaptor provisioningConfigArgumentCaptor = ArgumentCaptor.forClass(ProvisioningConfig.class); verify(prepareCandidateAction).buildCandidate(any(), any(), eq(ApplyCandidateAction.Type.FEATURE_ADD), @@ -745,7 +745,7 @@ public void nonExistingConfigNameThrowsException() throws Exception { // install installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); - assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack( + assertThatThrownBy(()->getFeaturesAddAction().addFeaturePackWithLayers( "org.test:added-pack", Set.of("layer1"), new ConfigId("model1", "idontexist"))) .isInstanceOf(FeaturesAddAction.ConfigurationNotFoundException.class) .hasFieldOrPropertyWithValue("model", "model1") @@ -774,7 +774,7 @@ public void nonExistingConfigNameWithoutLayersThrowsException() throws Exception installFeaturePack(installDir, "org.test:base-pack:1.0.0:zip"); assertThatThrownBy(()->getFeaturesAddAction().addFeaturePack( - "org.test:added-pack", Collections.emptySet(), new ConfigId("model1", "idontexist"))) + "org.test:added-pack", Set.of(new ConfigId("model1", "idontexist")))) .isInstanceOf(FeaturesAddAction.ConfigurationNotFoundException.class) .hasFieldOrPropertyWithValue("model", "model1") .hasFieldOrPropertyWithValue("name", "idontexist");