Skip to content

Commit

Permalink
Merge pull request #5903 from michpetrov/wfcore-4868
Browse files Browse the repository at this point in the history
WFCORE-4868: implement aliases for standalone configuration files
  • Loading branch information
darranl committed Mar 25, 2024
2 parents 8f02f22 + 2ba2d9a commit bca245b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
27 changes: 25 additions & 2 deletions server/src/main/java/org/jboss/as/server/ServerEnvironment.java
Expand Up @@ -499,7 +499,10 @@ public ServerEnvironment(final String hostControllerName, final Properties props
} else {
repository = null;
}
serverConfigurationFile = standalone ? new ConfigurationFile(serverConfigurationDir, defaultServerConfig, serverConfig, configInteractionPolicy, repository != null, serverTempDir, configurationExtension) : null;

this.stability = getEnumProperty(props, ProcessEnvironment.STABILITY, productConfig.getDefaultStability());
final String translatedConfig = translateFileAlias(serverConfig, stability);
serverConfigurationFile = standalone ? new ConfigurationFile(serverConfigurationDir, defaultServerConfig, translatedConfig, configInteractionPolicy, repository != null, serverTempDir, configurationExtension) : null;
// Adds a system property to indicate whether or not the server configuration should be persisted
@SuppressWarnings("deprecation")
final String propertyKey = JBOSS_PERSIST_SERVER_CONFIG;
Expand All @@ -525,7 +528,6 @@ public ServerEnvironment(final String hostControllerName, final Properties props
this.domainConfigurationDir = null;
}

this.stability = getEnumProperty(props, ProcessEnvironment.STABILITY, productConfig.getDefaultStability());
if (!productConfig.getStabilitySet().contains(this.stability)) {
throw ServerLogger.ROOT_LOGGER.unsupportedStability(this.stability, productConfig.getProductName());
}
Expand Down Expand Up @@ -1266,4 +1268,25 @@ private File[] getFilesFromProperty(final String name, final Properties props) {
ManagedAuditLogger createAuditLogger() {
return new ManagedAuditLoggerImpl(getProductConfig().resolveVersion(), true);
}

public static String translateFileAlias(String alias, Stability stability) {
if (!stability.enables(Stability.COMMUNITY) || alias == null) {
return alias;
}
switch (alias) {
case "full":
case "ha":
case "full-ha":
case "load-balancer":
case "microprofile":
case "microprofile-ha":
break;
case "fha": alias = "full-ha"; break;
case "lb": alias = "load-balancer"; break;
case "mp": alias = "microprofile"; break;
case "mpha": alias = "microprofile-ha"; break;
default: return alias;
}
return "standalone-" + alias + ".xml";
}
}
Expand Up @@ -91,4 +91,42 @@ public void testUUIDLifeCycle() throws IOException {
assertThat(uuids.get(0), is(not(uuid)));
Files.delete(uuidPath);
}

@Test
public void testAliasFunctionality() throws IOException {
Properties props = new Properties();
Path standaloneDir = homeDir.resolve("standalone");
Files.createDirectories(standaloneDir.resolve("configuration"));
Files.createFile(standaloneDir.resolve("configuration").resolve("standalone.xml"));
Files.createFile(standaloneDir.resolve("configuration").resolve("standalone-load-balancer.xml"));
Files.createFile(standaloneDir.resolve("configuration").resolve("custom.xml"));
props.put(HOME_DIR, homeDir.toAbsolutePath().toString());

// default stability = COMMUNITY
ProductConfig productConfig = ProductConfig.fromFilesystemSlot(null, "", props);

ServerEnvironment serverEnvironment = createServerEnvironment(props, null, productConfig);
assertThat(serverEnvironment.getServerConfigurationFile().getBootFile().getName(), is("standalone.xml"));

serverEnvironment = createServerEnvironment(props, "lb", productConfig);
assertThat(serverEnvironment.getServerConfigurationFile().getBootFile().getName(), is("standalone-load-balancer.xml"));

serverEnvironment = createServerEnvironment(props, "custom.xml", productConfig);
assertThat(serverEnvironment.getServerConfigurationFile().getBootFile().getName(), is("custom.xml"));
}

@Test(expected = IllegalStateException.class)
public void testAliasNotWorkingInDefaultStability() {
Properties props = new Properties();
props.put(HOME_DIR, homeDir.toAbsolutePath().toString());

// default stability = DEFAULT
ProductConfig productConfig = new ProductConfig(null, null, null);
createServerEnvironment(props, "lb", productConfig);
}

private ServerEnvironment createServerEnvironment(Properties props, String serverConfig, ProductConfig productConfig) {
return new ServerEnvironment(null, props, System.getenv(), serverConfig,
ConfigurationFile.InteractionPolicy.READ_ONLY, ServerEnvironment.LaunchType.STANDALONE, RunningMode.NORMAL, productConfig, false);
}
}

0 comments on commit bca245b

Please sign in to comment.