Skip to content

Commit

Permalink
[WFCORE-6728] Don't create new ServerEnvironment and Bootstrap.Config…
Browse files Browse the repository at this point in the history
…uration instances
  • Loading branch information
kabir committed Mar 21, 2024
1 parent 2363b2e commit 88afdd5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 124 deletions.
1 change: 0 additions & 1 deletion cli/src/main/java/org/jboss/as/cli/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public class Util {
public static final String RELEASE_CODENAME = "release-codename";
public static final String RELEASE_VERSION = "release-version";
public static final String RELOAD = "reload";
public static final String RELOAD_ENHANCED = "reload-enhanced";
public static final String REMOVE = "remove";
public static final String REPLY_PROPERTIES = "reply-properties";
public static final String REQUEST_PROPERTIES = "request-properties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.jboss.as.controller;

import org.jboss.as.version.Stability;

/**
* Provides control over the server's current {@link RunningMode}.
*
Expand All @@ -20,11 +18,6 @@ public class RunningModeControl {
private volatile String newBootFileName;
private volatile Boolean suspend;


// Temporary experiment for the testsuite
@Deprecated
private volatile Stability reloadedStability;

public RunningModeControl(final RunningMode initialMode) {
this.runningMode = initialMode;
}
Expand Down Expand Up @@ -89,21 +82,4 @@ public void setNewBootFileName(String newBootFileName) {
this.newBootFileName = newBootFileName;
}

/**
* Gets the stability of the reloaded server.
*
* @return the stability of the reloaded server
*/
public Stability getReloadedStability() {
return reloadedStability;
}

/**
* Sets the stability of the reloaded server.
*
* @param reloadedStability the stability of the reloaded server
*/
public void setReloadedStability(Stability reloadedStability) {
this.reloadedStability = reloadedStability;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
final class ApplicationServerService implements Service<AsyncFuture<ServiceContainer>> {

private final List<ServiceActivator> extraServices;
private volatile Bootstrap.Configuration configuration;
private final Bootstrap.Configuration configuration;
private final RunningModeControl runningModeControl;
private final ControlledProcessState processState;
private final SuspendController suspendController;
Expand All @@ -78,14 +78,7 @@ public synchronized void start(final StartContext context) throws StartException

//Moved to AbstractControllerService.start()
//processState.setStarting();
final Bootstrap.Configuration configuration;
Bootstrap.Configuration recalculatedConfiguration = this.configuration.recalculateForReload(runningModeControl);
if (recalculatedConfiguration != this.configuration) {
this.configuration = recalculatedConfiguration;
configuration = recalculatedConfiguration;
} else {
configuration = this.configuration;
}
final Bootstrap.Configuration configuration = this.configuration;
final ServerEnvironment serverEnvironment = configuration.getServerEnvironment();
final ProductConfig config = serverEnvironment.getProductConfig();
final String prettyVersion = config.getPrettyVersionString();
Expand Down
37 changes: 2 additions & 35 deletions server/src/main/java/org/jboss/as/server/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;

import javax.xml.namespace.QName;

Expand All @@ -24,7 +23,6 @@
import org.jboss.as.server.controller.git.GitConfigurationPersister;
import org.jboss.as.controller.persistence.XmlConfigurationPersister;
import org.jboss.as.server.parsing.StandaloneXml;
import org.jboss.as.version.Stability;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.service.ServiceActivator;
Expand Down Expand Up @@ -81,23 +79,21 @@ final class Configuration {
private final DelegatingConfigurableAuthorizer authorizer;
private final ManagementSecurityIdentitySupplier securityIdentitySupplier;

// Used to update the stability in the supplier cached by the ExtensionRegistry
private final AtomicReference<Stability> stabilityReference;
private ModuleLoader moduleLoader = Module.getBootModuleLoader();
private ConfigurationPersisterFactory configurationPersisterFactory;
private long startTime;


public Configuration(final ServerEnvironment serverEnvironment) {
assert serverEnvironment != null : "serverEnvironment is null";
this.serverEnvironment = serverEnvironment;
this.runningModeControl = serverEnvironment.getRunningModeControl();
this.auditLogger = serverEnvironment.createAuditLogger();
this.authorizer = new DelegatingConfigurableAuthorizer();
this.securityIdentitySupplier = new ManagementSecurityIdentitySupplier();
this.stabilityReference = new AtomicReference<>(serverEnvironment.getStability());
this.extensionRegistry = ExtensionRegistry.builder(serverEnvironment.getLaunchType().getProcessType())
.withRunningModeControl(this.runningModeControl)
.withStabilitySupplier(stabilityReference::get)
.withStabilitySupplier(serverEnvironment::getStability)
.withAuditLogger(this.auditLogger)
.withAuthorizer(this.authorizer)
.withSecurityIdentitySupplier(this.securityIdentitySupplier)
Expand All @@ -106,25 +102,6 @@ public Configuration(final ServerEnvironment serverEnvironment) {
this.startTime = serverEnvironment.getStartTime();
}

private Configuration(final Configuration original, ServerEnvironment serverEnvironment) {
// Updating the server environment here, will update the value
this.serverEnvironment = serverEnvironment;
this.extensionRegistry = original.extensionRegistry;
this.runningModeControl = original.runningModeControl;
this.capabilityRegistry = original.capabilityRegistry;
this.auditLogger = original.auditLogger;
this.authorizer = original.authorizer;
this.securityIdentitySupplier = original.securityIdentitySupplier;

// The extension registry caches the stability supplier so update its value here
this.stabilityReference = original.stabilityReference;
this.stabilityReference.set(this.serverEnvironment.getStability());

this.moduleLoader = original.moduleLoader;
this.configurationPersisterFactory = original.configurationPersisterFactory;
this.startTime = original.startTime;
}

/**
* Get the server environment.
*
Expand Down Expand Up @@ -260,16 +237,6 @@ public synchronized void setConfigurationPersisterFactory(final ConfigurationPer
public long getStartTime() {
return startTime;
}

Configuration recalculateForReload(RunningModeControl runningModeControl) {
if (runningModeControl.isReloaded()) {
ServerEnvironment recalculatedServerEnvironment = serverEnvironment.recalculateForReload(runningModeControl);
if (recalculatedServerEnvironment != serverEnvironment) {
return new Configuration(this, recalculatedServerEnvironment);
}
}
return this;
}
}

/** A factory for the {@link ExtensibleConfigurationPersister} to be used by this server */
Expand Down
70 changes: 19 additions & 51 deletions server/src/main/java/org/jboss/as/server/ServerEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public ProcessType getProcessType() {
private final boolean startSuspended;
private final boolean startGracefully;
private final GitRepository repository;
private final Stability stability;
private volatile Stability stability;

public ServerEnvironment(final String hostControllerName, final Properties props, final Map<String, String> env, final String serverConfig,
final ConfigurationFile.InteractionPolicy configInteractionPolicy, final LaunchType launchType,
Expand Down Expand Up @@ -523,9 +523,7 @@ public ServerEnvironment(final String hostControllerName, final Properties props
}

this.stability = getEnumProperty(props, ProcessEnvironment.STABILITY, productConfig.getDefaultStability());
if (!productConfig.getStabilitySet().contains(this.stability)) {
throw ServerLogger.ROOT_LOGGER.unsupportedStability(this.stability, productConfig.getProductName());
}
checkStabilityIsValidForInstallation(productConfig, this.stability);
}
boolean allowExecutor = true;
String maxThreads = WildFlySecurityManager.getPropertyPrivileged(BOOTSTRAP_MAX_THREADS, null);
Expand Down Expand Up @@ -589,41 +587,6 @@ public ServerEnvironment(final String hostControllerName, final Properties props
}
}

private ServerEnvironment(ServerEnvironment original, Stability stability) {
this.primordialProperties = original.primordialProperties;
this.providedProperties = original.providedProperties;
this.processNameSet = original.processNameSet;
this.launchType = original.launchType;
this.hostControllerName = original.hostControllerName;
this.qualifiedHostName = original.qualifiedHostName;
this.hostName = original.hostName;
this.serverName = original.serverName;
this.nodeName = original.nodeName;
this.javaExtDirs = original.javaExtDirs;
this.homeDir = original.homeDir;
this.serverBaseDir = original.serverBaseDir;
this.serverConfigurationDir = original.serverConfigurationDir;
this.serverConfigurationFile = original.serverConfigurationFile;
this.serverLogDir = original.serverLogDir;
this.controllerTempDir = original.controllerTempDir;
this.serverDataDir = original.serverDataDir;
this.serverContentDir = original.serverContentDir;
this.serverTempDir = original.serverTempDir;
this.domainBaseDir = original.domainBaseDir;
this.domainConfigurationDir = original.domainConfigurationDir;
this.standalone = original.standalone;
this.allowModelControllerExecutor = original.allowModelControllerExecutor;
this.initialRunningMode = original.initialRunningMode;
this.productConfig = original.productConfig;
this.runningModeControl = original.runningModeControl;
this.serverUUID = original.serverUUID;
this.startTime = original.startTime;
this.startSuspended = original.startSuspended;
this.startGracefully = original.startGracefully;
this.repository = original.repository;
this.stability = stability;
}

private Set<String> listIgnoredFiles(String defaultServerConfig) {
Set<String> ignored = new LinkedHashSet<>();
setIgnored(ignored, serverDataDir.toPath(), true, false);
Expand Down Expand Up @@ -1205,6 +1168,23 @@ protected void systemPropertyUpdated(String propertyName, String propertyValue)
}
}


public void checkStabilityIsValidForInstallation(Stability stability) {
checkStabilityIsValidForInstallation(productConfig, stability);
}

private void checkStabilityIsValidForInstallation(ProductConfig productConfig, Stability stability) {
if (!productConfig.getStabilitySet().contains(stability)) {
throw ServerLogger.ROOT_LOGGER.unsupportedStability(this.stability, productConfig.getProductName());
}
}

// TODO Figure out how to make this package protected
public void setStability(Stability stability) {
WildFlySecurityManager.setPropertyPrivileged(ProcessEnvironment.STABILITY, stability.toString());
this.stability = stability;
}

/**
* Get a File from configuration.
*
Expand Down Expand Up @@ -1277,16 +1257,4 @@ private File[] getFilesFromProperty(final String name, final Properties props) {
ManagedAuditLogger createAuditLogger() {
return new ManagedAuditLoggerImpl(getProductConfig().resolveVersion(), true);
}

ServerEnvironment recalculateForReload(RunningModeControl runningModeControl) {
if (runningModeControl.isReloaded()) {
Stability stability = runningModeControl.getReloadedStability() != null ? runningModeControl.getReloadedStability() : this.stability;
if (stability != this.stability) {
System.setProperty(ProcessEnvironment.STABILITY, stability.toString());

return new ServerEnvironment(this, stability);
}
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ protected ProcessReloadHandler.ReloadContext<RunningModeControl> initializeReloa
if (additionalAttributes.contains(ModelDescriptionConstants.STABILITY) && operation.hasDefined(ModelDescriptionConstants.STABILITY)) {
String val = STABILITY.resolveModelAttribute(context, operation).asString();
stability = Stability.fromString(val);
environment.checkStabilityIsValidForInstallation(stability);
} else {
stability = null;
}
Expand Down Expand Up @@ -164,15 +165,15 @@ public void reloadInitiated(RunningModeControl runningModeControl) {

@Override
public void doReload(RunningModeControl runningModeControl) {
// If no stability is specified, use the current stability
Stability reloadedStability = stability == null ? environment.getStability() : stability;

runningModeControl.setRunningMode(finalAdminOnly ? RunningMode.ADMIN_ONLY : RunningMode.NORMAL);
runningModeControl.setReloaded();
runningModeControl.setReloadedStability(reloadedStability);
runningModeControl.setUseCurrentConfig(useCurrentConfig);
runningModeControl.setNewBootFileName(serverConfig);
runningModeControl.setSuspend(finalSuspend);

if (stability != null) {
environment.setStability(stability);
}
}
};
}
Expand Down

0 comments on commit 88afdd5

Please sign in to comment.