Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFGP-264] Start WF processes at a configurable stability level when … #277

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class FeatureSpecGenerator implements ForkCallback {
private Path systemProps;
private Path standaloneSpecsFile;
private Path domainSpecsFile;
private String mimimumStability;

String getBranchId(String spec, int dots) {
int i = 0;
Expand Down Expand Up @@ -138,12 +139,14 @@ void increaseSpecCount() {
public FeatureSpecGenerator() {
}

public FeatureSpecGenerator(String installation, Path outputDir, Map<String, Path> inheritedSpecs, boolean fork, boolean debug) {
public FeatureSpecGenerator(String installation, Path outputDir, Map<String, Path> inheritedSpecs,
String mimimumStability, boolean fork, boolean debug) {
this.installation = installation;
this.outputDir = outputDir;
this.fork = fork;
this.debug = debug;
this.inheritedSpecs = inheritedSpecs;
this.mimimumStability = mimimumStability;
}

public int generateSpecs() throws ProvisioningException {
Expand Down Expand Up @@ -180,20 +183,21 @@ private void doGenerate() throws ProvisioningException {
final ModelNode standaloneFeatures;
ModelNode domainRoots = null;
if(fork) {
ForkedEmbeddedUtil.fork(this, getStoredSystemProps(), installation, getStandaloneSpecsFile().toString(), getDomainSpecsFile().toString());
String minStab = mimimumStability == null ? "" : mimimumStability;
ForkedEmbeddedUtil.fork(this, getStoredSystemProps(), installation, getStandaloneSpecsFile().toString(), getDomainSpecsFile().toString(), minStab);
standaloneFeatures = readSpecsFile(getStandaloneSpecsFile());
if(Files.exists(Paths.get(installation).resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
domainRoots = readSpecsFile(getDomainSpecsFile());
}
} else {
final Path home = Paths.get(installation);
if(Files.exists(home.resolve(WfConstants.STANDALONE).resolve(WfConstants.CONFIGURATION))) {
standaloneFeatures = readFeatureSpecs(createStandaloneServer(installation));
standaloneFeatures = readFeatureSpecs(createStandaloneServer(installation, mimimumStability));
} else {
throw new ProvisioningException("The installation does not include standalone configuration");
}
if(Files.exists(home.resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
domainRoots = readFeatureSpecs(createEmbeddedHc(installation));
domainRoots = readFeatureSpecs(createEmbeddedHc(installation, mimimumStability));
}
}

Expand Down Expand Up @@ -226,16 +230,17 @@ private void doGenerate() throws ProvisioningException {

@Override
public void forkedForEmbedded(String... args) throws ConfigGeneratorException {
if(args.length != 3) {
if(args.length != 3 && args.length != 4) {
final StringBuilder buf = new StringBuilder();
StringUtils.append(buf, Arrays.asList(args));
throw new IllegalArgumentException("Expected 3 arguments but got " + Arrays.asList(args));
throw new IllegalArgumentException("Expected 3-4 arguments but got " + Arrays.asList(args));
}
try {
ModelNode result = readFeatureSpecs(createStandaloneServer(args[0]));
String mimimumStability = args.length == 4 ? args[3] : null;
ModelNode result = readFeatureSpecs(createStandaloneServer(args[0], mimimumStability));
writeSpecsFile(Paths.get(args[1]), result);
if (Files.exists(Paths.get(args[0]).resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
result = readFeatureSpecs(createEmbeddedHc(args[0]));
result = readFeatureSpecs(createEmbeddedHc(args[0], mimimumStability));
writeSpecsFile(Paths.get(args[2]), result);
}
} catch (ProvisioningException e) {
Expand Down Expand Up @@ -297,12 +302,21 @@ protected FeatureSpec getInheritedSpec(String name) throws ProvisioningException
return spec;
}

private static EmbeddedManagedProcess createStandaloneServer(String jbossHome) {
return EmbeddedProcessFactory.createStandaloneServer(jbossHome, null, null, new String[] {"--admin-only"});
private static EmbeddedManagedProcess createStandaloneServer(String jbossHome, String minimumStability) {
String[] cmdArgs = getCmdArgs(minimumStability);
return EmbeddedProcessFactory.createStandaloneServer(jbossHome, null, null, cmdArgs);
}

private static EmbeddedManagedProcess createEmbeddedHc(String jbossHome) {
return EmbeddedProcessFactory.createHostController(jbossHome, null, null, new String[] {"--admin-only"});
private static EmbeddedManagedProcess createEmbeddedHc(String jbossHome, String minimumStability) {
String[] cmdArgs = getCmdArgs(minimumStability);
return EmbeddedProcessFactory.createHostController(jbossHome, null, null, cmdArgs);
}

private static String[] getCmdArgs(String mimimumStability) {
if (mimimumStability != null && !mimimumStability.isEmpty()) {
return new String[] {"--admin-only", "--stability=" + mimimumStability};
}
return new String[] {"--admin-only"};
}

private static ModelNode readFeatureSpecs(final EmbeddedManagedProcess server) throws ProvisioningException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class FeatureSpecGeneratorInvoker {
private Set<String> domainExtensions = Collections.emptySet();
private Set<String> hostExtensions = Collections.emptySet();
private List<Path> layersConfs = Collections.emptyList();
private String minimumStability;

private WildFlyPackageTasksParser tasksParser;
private ProvisioningLayoutFactory layoutFactory;
Expand All @@ -138,6 +139,7 @@ public class FeatureSpecGeneratorInvoker {
this.forkEmbedded = mojo.forkEmbedded;
this.wildflyHome = mojo.wildflyHome.toPath();
this.moduleTemplatesDir = mojo.moduleTemplatesDir.toPath();
this.minimumStability = mojo.minimumStability;
this.log = mojo.getLog();
}

Expand Down Expand Up @@ -252,8 +254,7 @@ private int doExecute() throws MojoExecutionException, MojoFailureException, Mav
}
final Class<?> specGenCls = (newCl == null ? originalCl : newCl).loadClass("org.wildfly.galleon.plugin.featurespec.generator.FeatureSpecGenerator");
final Method specGenMethod = specGenCls.getMethod("generateSpecs");
return (int) specGenMethod.invoke(specGenCls.getConstructor(String.class, Path.class, Map.class, boolean.class, boolean.class)
.newInstance(wildflyHome.toString(), featureSpecsOutput.toPath(), inheritedFeatureSpecs, forkEmbedded, log.isDebugEnabled()));
return (int) specGenMethod.invoke(getFeaturePackGenerator(specGenCls));
} catch(InvocationTargetException e) {
throw new MojoExecutionException("Feature spec generator failed", e.getCause());
} catch (Throwable e) {
Expand Down Expand Up @@ -719,4 +720,20 @@ private void debug(String format, Object... args) {
log.debug(String.format(format, args));
}
}

private Object getFeaturePackGenerator(Class<?> specGenCls) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
debug("Creating a feature spec generator for stability %s using %s", minimumStability, specGenCls);
try {
return specGenCls.getConstructor(String.class, Path.class, Map.class, String.class, boolean.class, boolean.class)
.newInstance(wildflyHome.toString(), featureSpecsOutput.toPath(), inheritedFeatureSpecs, minimumStability, forkEmbedded, log.isDebugEnabled());
} catch (NoSuchMethodException e) {
if (minimumStability != null && !minimumStability.isEmpty()) {
return specGenCls.getConstructor(String.class, Path.class, Map.class, boolean.class, boolean.class)
.newInstance(wildflyHome.toString(), featureSpecsOutput.toPath(), inheritedFeatureSpecs, forkEmbedded, log.isDebugEnabled());
} else {
// We've been configured to use a stability but the generator class does not support it
throw e;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ public boolean accept(Path path) {
@Parameter(alias = "feature-specs-output", defaultValue = "${project.build.directory}/resources/features", required = true)
protected File featureSpecsOutput;

/**
* The minimum stability level of the WildFly processes used to generate feature specs.
* Set this if you need to generate feature specs for features with a lower stability level
* than the default level of the WildFly process being used for feature-spec generation.
*/
@Parameter(alias = "minimum-stability", required = false)
protected String minimumStability;

private WildFlyFeaturePackBuild buildConfig;
private Map<String, PackageSpec.Builder> extendedPackages = Collections.emptyMap();

Expand Down