Skip to content

Commit

Permalink
Merge model and config parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Aug 23, 2023
1 parent 38e0887 commit 066f78d
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 61 deletions.
5 changes: 3 additions & 2 deletions dist/docs/guide/usage/add_feature_pack.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ The Galleon feature packs may provide different capabilities using https://docs.
NOTE: Using `--layers` parameter overwrites the default configuration defined by some feature packs.
If the feature pack changes server configuration files, the user may also choose which server configuration should be affected using `--model` and `--config`
parameters. If those parameters are not provided, the layer configuration will use default values. Most Wildfly feature packs provide only a single model (standalone) and the default configuration file of standalone.xml.
If the feature pack changes server configuration files, the user may also choose which server configuration should be affected using `--config` parameter. If not provided, the layer configuration will use default values. Most Wildfly feature packs provide only a single model (standalone) and the default configuration file of standalone.xml.
NOTE: If the affected configuration file has been modified by the user, that file will not be modified. Instead, a new configuration file with suffix `.glnew` will be created with the changes.
Expand All @@ -57,6 +56,8 @@ $ prospero feature-pack add \
--dir wildfly
```
If the feature pack provides multiple configuration model, the configuration name can be prefixed with model name e.g. `--config standalone/standalone.xml`
#### 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setUp() throws IOException {

@Test
public void addFeaturePack() throws Exception {
final Path channelsFile = MetadataTestUtils.prepareChannel("manifests/wildfly-27.0.1.Final-channel.yaml");
final Path channelsFile = MetadataTestUtils.prepareChannel("manifests/wildfly-28.0.0.Final-manifest.yaml");
final Path modulePath = Path.of("modules", "com", "mysql", "jdbc");

System.out.println("Installing wildfly");
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>11</source>
<target>11</target>
<testSource>11</testSource>
<testTarget>11</testTarget>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,5 @@ private Commands() {
public static final String ACCEPT_AGREEMENTS = "--accept-license-agreements";

public static final String LAYERS = "--layers";
public static final String MODEL = "--model";
public static final String CONFIG = "--config";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.wildfly.prospero.cli.commands;

import org.jboss.galleon.config.ConfigId;
import org.wildfly.channel.Repository;
import org.wildfly.prospero.actions.FeaturesAddAction;
import org.wildfly.prospero.api.MavenOptions;
Expand Down Expand Up @@ -50,9 +51,6 @@ public static class AddCommand extends AbstractMavenCommand {
@CommandLine.Option(names = CliConstants.LAYERS, split = ",")
private Set<String> layers;

@CommandLine.Option(names = CliConstants.MODEL)
private String model;

@CommandLine.Option(names = CliConstants.CONFIG)
private String config;

Expand Down Expand Up @@ -95,7 +93,7 @@ public Integer call() throws Exception {
}

try {
featuresAddAction.addFeaturePack(fpl, layers == null ? Collections.emptySet() : layers, model, config);
featuresAddAction.addFeaturePack(fpl, layers == null ? Collections.emptySet() : layers, parseConfigName());
} catch (FeaturesAddAction.LayerNotFoundException e) {
if (!e.getSupportedLayers().isEmpty()) {
console.error(CliMessages.MESSAGES.layerNotSupported(fpl, e.getLayers(), e.getSupportedLayers()));
Expand All @@ -116,6 +114,22 @@ public Integer call() throws Exception {

return ReturnCodes.SUCCESS;
}

private ConfigId parseConfigName() {
if (config == null) {
return null;
}
int i = config.indexOf("/");
if (i < 0) {
return new ConfigId(null, config.trim());
}

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());
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class FeaturesCommandTest extends AbstractMavenCommandTest {
@Captor
private ArgumentCaptor<MavenOptions> mavenOptions;

@Captor
private ArgumentCaptor<ConfigId> configNameCaptor;

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

Expand Down Expand Up @@ -104,14 +107,11 @@ public void passArgumentsToFeaturesAddAction_OnlyFpl() throws Exception {

final ArgumentCaptor<String> fplCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<Set<String>> layersCaptor = ArgumentCaptor.forClass(Set.class);
final ArgumentCaptor<String> modelCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> configNameCaptor = ArgumentCaptor.forClass(String.class);
verify(featuresAddAction).addFeaturePack(fplCaptor.capture(), layersCaptor.capture(),
modelCaptor.capture(), configNameCaptor.capture());
configNameCaptor.capture());

assertEquals(fplCaptor.getValue(), "test:test");
assertEquals(Collections.emptySet(), layersCaptor.getValue());
assertEquals(modelCaptor.getValue(), null);
assertEquals(configNameCaptor.getValue(), null);
}

Expand All @@ -125,30 +125,53 @@ public void passArgumentsToFeaturesAddAction_LayersAreSplit() throws Exception {

final ArgumentCaptor<Set<String>> layersCaptor = ArgumentCaptor.forClass(Set.class);
verify(featuresAddAction).addFeaturePack(any(), layersCaptor.capture(),
any(), any());
any());

assertEquals(Set.of("layer1", "layer2"), layersCaptor.getValue());
}

@Test
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/");
assertEquals(ReturnCodes.SUCCESS, exitCode);

verify(featuresAddAction).addFeaturePack(any(), any(),
configNameCaptor.capture());

assertEquals(new ConfigId("test", null), configNameCaptor.getValue());
}

@Test
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");
assertEquals(ReturnCodes.SUCCESS, exitCode);

verify(featuresAddAction).addFeaturePack(any(), any(),
configNameCaptor.capture());

assertEquals(new ConfigId(null, "test"), configNameCaptor.getValue());
}

@Test
public void passArgumentsToFeaturesAddAction_AllParameters() throws Exception {
int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD,
CliConstants.DIR, installationDir.toString(),
CliConstants.FPL, "test:test",
CliConstants.LAYERS, "layer1",
CliConstants.CONFIG, "config",
CliConstants.MODEL, "model");
CliConstants.CONFIG, "model/config");
assertEquals(ReturnCodes.SUCCESS, exitCode);

final ArgumentCaptor<Set<String>> layersCaptor = ArgumentCaptor.forClass(Set.class);
final ArgumentCaptor<String> modelCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> configNameCaptor = ArgumentCaptor.forClass(String.class);
verify(featuresAddAction).addFeaturePack(any(), layersCaptor.capture(),
modelCaptor.capture(), configNameCaptor.capture());
verify(featuresAddAction).addFeaturePack(any(), layersCaptor.capture(), configNameCaptor.capture());

assertEquals(Set.of("layer1"), layersCaptor.getValue());
assertEquals("config", configNameCaptor.getValue());
assertEquals("model", modelCaptor.getValue());
assertEquals(new ConfigId("model", "config"), configNameCaptor.getValue());
}

@Test
Expand All @@ -160,8 +183,7 @@ public void nonExistingFeaturePack_CausesError() throws Exception {
CliConstants.DIR, installationDir.toString(),
CliConstants.FPL, "test:idontexist",
CliConstants.LAYERS, "layer1",
CliConstants.CONFIG, "config",
CliConstants.MODEL, "model");
CliConstants.CONFIG, "model/config");
assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode);
assertThat(getErrorOutput())
.contains(CliMessages.MESSAGES.featurePackNotFound("test:idontexist"));
Expand All @@ -178,8 +200,7 @@ public void unableToResolveFeaturePack_CausesError() throws Exception {
CliConstants.DIR, installationDir.toString(),
CliConstants.FPL, "test:idontexist",
CliConstants.LAYERS, "layer1",
CliConstants.CONFIG, "config",
CliConstants.MODEL, "model");
CliConstants.CONFIG, "model/config");
assertEquals(ReturnCodes.PROCESSING_ERROR, exitCode);
assertThat(getErrorOutput())
.contains("Unable to resolve artifacts:")
Expand Down Expand Up @@ -209,7 +230,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, null);
.when(featuresAddAction).addFeaturePack("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",
Expand All @@ -223,7 +244,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, null);
.when(featuresAddAction).addFeaturePack("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",
Expand All @@ -238,10 +259,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(), "idontexist", null);
.when(featuresAddAction).addFeaturePack("org.test:test", Collections.emptySet(),
new ConfigId("idontexist", "test"));
int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD,
CliConstants.DIR, installationDir.toString(),
CliConstants.MODEL, "idontexist",
CliConstants.CONFIG, "idontexist/test",
CliConstants.FPL, "org.test:test");
assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode);
assertThat(getErrorOutput())
Expand All @@ -252,11 +274,11 @@ 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(), "test", "idontexist");
.when(featuresAddAction).addFeaturePack("org.test:test", Collections.emptySet(),
new ConfigId("test", "idontexist"));
int exitCode = commandLine.execute(CliConstants.Commands.FEATURE_PACKS, CliConstants.Commands.ADD,
CliConstants.DIR, installationDir.toString(),
CliConstants.MODEL, "test",
CliConstants.CONFIG, "idontexist",
CliConstants.CONFIG, "test/idontexist",
CliConstants.FPL, "org.test:test");
assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode);
assertThat(getErrorOutput())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public FeaturesAddAction(MavenOptions mavenOptions, Path installDir, List<Reposi
*
* @param featurePackCoord - maven {@code groupId:artifactId} coordinates of the feature pack to install
* @param layers - set of layer names to be provisioned
* @param model - used to select layer model, if the feature pack provides multiple models
* @param configName - name of the configuration file to generate if supported
* @param configName - {@code ConfigId} of the configuration file to generate if supported
*
* @throws ProvisioningException - if unable to provision the server
* @throws ModelNotDefinedException - if requested model is not provided by the feature pack
Expand All @@ -114,7 +113,7 @@ public FeaturesAddAction(MavenOptions mavenOptions, Path installDir, List<Reposi
* @throws InvalidUpdateCandidateException - if the folder at {@code updateDir} is not a valid update
* @throws MetadataException - if unable to read or write the installation of update metadata
*/
public void addFeaturePack(String featurePackCoord, Set<String> layers, String model, String configName)
public void addFeaturePack(String featurePackCoord, Set<String> layers, ConfigId configName)
throws ProvisioningException, OperationException {
Objects.requireNonNull(layers);
if (featurePackCoord == null || featurePackCoord.isEmpty()) {
Expand Down Expand Up @@ -142,18 +141,18 @@ public void addFeaturePack(String featurePackCoord, Set<String> layers, String m
}
}

selectedModel = getSelectedModel(model, allLayers);
selectedModel = getSelectedModel(configName == null?null:configName.getModel(), allLayers);

verifyLayerAvailable(layers, selectedModel, allLayers);

if (configName == null) {
if (configName == null || configName.getName() == null) {
if (selectedModel == null) {
selectedConfig = null;
} else {
selectedConfig = selectedModel + ".xml";
}
} else {
selectedConfig = configName;
selectedConfig = configName.getName();
}

if (ProsperoLogger.ROOT_LOGGER.isDebugEnabled()) {
Expand Down
Loading

0 comments on commit 066f78d

Please sign in to comment.