Skip to content

Commit

Permalink
[WFCORE-6661] More accurate, resettable start time calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Mar 28, 2024
1 parent d0d5a88 commit 378dad0
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.DelegatingModelControllerClient;
import org.jboss.as.server.Bootstrap;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.server.Main;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerService;
Expand Down Expand Up @@ -147,7 +148,8 @@ public void exit(int status) {
});

// Determine the ServerEnvironment
ServerEnvironment serverEnvironment = Main.determineEnvironment(cmdargs, systemProps, systemEnv, ServerEnvironment.LaunchType.STANDALONE, startTime).getServerEnvironment();
ServerEnvironment serverEnvironment = Main.determineEnvironment(cmdargs, systemProps, systemEnv,
ServerEnvironment.LaunchType.STANDALONE, ElapsedTime.startingFromJvmStart()).getServerEnvironment();
if (serverEnvironment == null) {
// Nothing to do
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.wildfly.core.embedded.logging.EmbeddedLogger;

/**
* A {@link Context} that wraps other contexts and invokes them in the order they are {@link #add(Context) added}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
class ChainedContext implements Context {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.wildfly.core.embedded.logging.EmbeddedLogger;

/**
* Represents a configuration for the embedded server.
* Represents a configuration for creating an {@link EmbeddedManagedProcess}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.wildfly.core.embedded;

/**
* A context used to activate and restore the environment for embedded containers.
* A context used to activate and restore the environment for an {@link EmbeddedManagedProcess}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.DelegatingModelControllerClient;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.host.controller.DomainModelControllerService;
import org.jboss.as.host.controller.HostControllerEnvironment;
import org.jboss.as.host.controller.Main;
Expand Down Expand Up @@ -234,12 +235,12 @@ public void propertyChange(PropertyChangeEvent evt) {

@Override
public void start() throws EmbeddedProcessStartException {
ElapsedTime elapsedTime = ElapsedTime.startingFromNow();
ClassLoader tccl = SecurityActions.getTccl();
try {
SecurityActions.setTccl(embeddedModuleCL);
EmbeddedHostControllerBootstrap hostControllerBootstrap = null;
try {
final long startTime = System.currentTimeMillis();
// Take control of server use of System.exit
SystemExiter.initialize(new SystemExiter.Exiter() {
@Override
Expand All @@ -249,7 +250,7 @@ public void exit(int status) {
});

// Determine the HostControllerEnvironment
HostControllerEnvironment environment = createHostControllerEnvironment(jbossHomeDir, cmdargs, startTime);
HostControllerEnvironment environment = createHostControllerEnvironment(jbossHomeDir, cmdargs, elapsedTime);

FutureServiceContainer futureContainer = new FutureServiceContainer();
final byte[] authBytes = new byte[16];
Expand Down Expand Up @@ -400,7 +401,8 @@ private void exit() {
SystemExiter.initialize(SystemExiter.Exiter.DEFAULT);
}

private static HostControllerEnvironment createHostControllerEnvironment(File jbossHome, String[] cmdargs, long startTime) {
private static HostControllerEnvironment createHostControllerEnvironment(File jbossHome, String[] cmdargs,
ElapsedTime elapsedTime) {
SecurityActions.setPropertyPrivileged(HostControllerEnvironment.HOME_DIR, jbossHome.getAbsolutePath());

List<String> cmds = new ArrayList<String>(Arrays.asList(cmdargs));
Expand All @@ -427,7 +429,7 @@ private static HostControllerEnvironment createHostControllerEnvironment(File jb
if (value != null)
cmds.add("-D" + prop + "=" + value);
}
return Main.determineEnvironment(cmds.toArray(new String[cmds.size()]), startTime, ProcessType.EMBEDDED_HOST_CONTROLLER).getHostControllerEnvironment();
return Main.determineEnvironment(cmds.toArray(new String[cmds.size()]), elapsedTime, ProcessType.EMBEDDED_HOST_CONTROLLER).getHostControllerEnvironment();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,22 @@ public static StandaloneServer createStandaloneServer(final Configuration config

setupVfsModule(moduleLoader);

// Load the Embedded Server Module
// Load the org.wildfly.embedded module using the ModuleLoader from the Configuration
//
// Note that, depending on the Configuration, the classes in this module may be of a different
// version from those with the same name included in the archive that provides this
// EmbeddedProcessFactory class. The module must provide a factory class whose name matches SERVER_FACTORY
// that provides a 'create' method with the same parameter types as the one provided by the same class
// in this class's artifact, and that returns an object that provides methods with the same signatures
// as those in the EmbeddedManagedProcess interface included in this class's artifact.
final Module embeddedModule;
try {
embeddedModule = moduleLoader.loadModule(MODULE_ID_EMBEDDED);
} catch (final ModuleLoadException mle) {
throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_EMBEDDED, moduleLoader);
}

// Load the Embedded Server Factory via the modular environment
// Load the EmbeddedStandaloneServerFactory via the modular environment.
final ModuleClassLoader embeddedModuleCL = embeddedModule.getClassLoader();
final Class<?> embeddedServerFactoryClass;
final Class<?> standaloneServerClass;
Expand Down Expand Up @@ -238,15 +245,22 @@ public static HostController createHostController(final Configuration configurat

setupVfsModule(moduleLoader);

// Load the Embedded Server Module
// Load the org.wildfly.embedded module using the ModuleLoader from the Configuration
//
// Note that, depending on the Configuration, the classes in this module may be of a different
// version from those with the same name included in the archive that provides this
// EmbeddedProcessFactory class. The module must provide a factory class whose name matches HOST_FACTORY
// that provides a 'create' method with the same parameter types as the one provided by the same class
// in this class's artifact, and that returns an object that provides methods with the same signatures
// as those in the EmbeddedManagedProcess interface included in this class's artifact.
final Module embeddedModule;
try {
embeddedModule = moduleLoader.loadModule(MODULE_ID_EMBEDDED);
} catch (final ModuleLoadException mle) {
throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_EMBEDDED, moduleLoader);
}

// Load the Embedded Server Factory via the modular environment
// Load the EmbeddedHostControllerFactory via the modular environment
final ModuleClassLoader embeddedModuleCL = embeddedModule.getClassLoader();
final Class<?> embeddedHostControllerFactoryClass;
final Class<?> hostControllerClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.DelegatingModelControllerClient;
import org.jboss.as.server.Bootstrap;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.server.Main;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerService;
Expand Down Expand Up @@ -239,6 +240,7 @@ public ModelControllerClient getDelegate() {

@Override
public void start() throws EmbeddedProcessStartException {
ElapsedTime elapsedTime = ElapsedTime.startingFromNow();
ClassLoader tccl = SecurityActions.getTccl();
try {
SecurityActions.setTccl(embeddedModuleCL);
Expand All @@ -255,7 +257,8 @@ public void exit(int status) {
});

// Determine the ServerEnvironment
ServerEnvironment serverEnvironment = Main.determineEnvironment(cmdargs, systemProps, systemEnv, ServerEnvironment.LaunchType.EMBEDDED, startTime).getServerEnvironment();
ServerEnvironment serverEnvironment = Main.determineEnvironment(cmdargs, systemProps, systemEnv,
ServerEnvironment.LaunchType.EMBEDDED, elapsedTime).getServerEnvironment();
if (serverEnvironment == null) {
// Nothing to do
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jboss.as.host.controller;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
import static org.jboss.as.server.ElapsedTime.startingFromNow;

import java.io.File;
import java.io.IOException;
Expand All @@ -24,6 +25,7 @@
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.controller.operations.common.ProcessEnvironment;
import org.jboss.as.controller.persistence.ConfigurationFile;
import org.jboss.as.host.controller.logging.HostControllerLogger;
Expand Down Expand Up @@ -245,7 +247,7 @@ public class HostControllerEnvironment extends ProcessEnvironment {
private final HostRunningModeControl runningModeControl;
private final boolean securityManagerEnabled;
private final UUID hostControllerUUID;
private final long startTime;
private final ElapsedTime elapsedTime;
private final ProcessType processType;

/** Only for test cases */
Expand All @@ -255,14 +257,14 @@ public HostControllerEnvironment(Map<String, String> hostSystemProperties, boole
String initialHostConfig, RunningMode initialRunningMode, boolean backupDomainFiles, boolean useCachedDc, ProductConfig productConfig) {
this(hostSystemProperties, isRestart, modulePath, processControllerAddress, processControllerPort, hostControllerAddress, hostControllerPort, defaultJVM,
domainConfig, initialDomainConfig, hostConfig, initialHostConfig, initialRunningMode, backupDomainFiles, useCachedDc, productConfig, false,
System.currentTimeMillis(), ProcessType.HOST_CONTROLLER, ConfigurationFile.InteractionPolicy.STANDARD, ConfigurationFile.InteractionPolicy.STANDARD);
startingFromNow(), ProcessType.HOST_CONTROLLER, ConfigurationFile.InteractionPolicy.STANDARD, ConfigurationFile.InteractionPolicy.STANDARD);
}

public HostControllerEnvironment(Map<String, String> hostSystemProperties, boolean isRestart, String modulePath,
InetAddress processControllerAddress, Integer processControllerPort, InetAddress hostControllerAddress,
Integer hostControllerPort, String defaultJVM, String domainConfig, String initialDomainConfig, String hostConfig,
String initialHostConfig, RunningMode initialRunningMode, boolean backupDomainFiles, boolean useCachedDc,
ProductConfig productConfig, boolean securityManagerEnabled, long startTime, ProcessType processType,
ProductConfig productConfig, boolean securityManagerEnabled, ElapsedTime elapsedTime, ProcessType processType,
ConfigurationFile.InteractionPolicy hostConfigInteractionPolicy, ConfigurationFile.InteractionPolicy domainConfigInteractionPolicy) {

this.hostSystemProperties = Collections.unmodifiableMap(Assert.checkNotNullParam("hostSystemProperties", hostSystemProperties));
Expand All @@ -277,7 +279,7 @@ public HostControllerEnvironment(Map<String, String> hostSystemProperties, boole
this.hostControllerPort = hostControllerPort;
this.isRestart = isRestart;
this.modulePath = modulePath;
this.startTime = startTime;
this.elapsedTime = elapsedTime;
this.initialRunningMode = initialRunningMode;
this.runningModeControl = new HostRunningModeControl(initialRunningMode, RestartMode.SERVERS);
this.domainConfigInteractionPolicy = domainConfigInteractionPolicy;
Expand Down Expand Up @@ -781,7 +783,7 @@ public String getHostControllerName() {
* @return the time, in ms since the epoch
*/
public long getStartTime() {
return startTime;
return elapsedTime.getStartTime();
}

@Override
Expand Down Expand Up @@ -867,6 +869,15 @@ boolean isSecurityManagerEnabled() {
return securityManagerEnabled;
}

/**
* Gets this Host Controller's {@link ElapsedTime} tracker.
*
* @return the elapsed time tracker. Will not be {@code null}.
*/
ElapsedTime getElapsedTime() {
return elapsedTime;
}

/**
* Get a File from configuration.
* @param name the name of the property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jboss.as.remoting.HttpListenerRegistryService;
import org.jboss.as.remoting.management.ManagementRemotingServices;
import org.jboss.as.server.BootstrapListener;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.server.FutureServiceContainer;
import org.jboss.as.server.Services;
import org.jboss.as.server.logging.ServerLogger;
Expand Down Expand Up @@ -78,16 +79,17 @@ public JBossThreadFactory run() {
private final ControlledProcessState processState;
private final String authCode;
private final CapabilityRegistry capabilityRegistry;
private final ElapsedTime elapsedTime;
private volatile FutureServiceContainer futureContainer;
private volatile long startTime;
private volatile boolean everStopped;

public HostControllerService(final HostControllerEnvironment environment, final HostRunningModeControl runningModeControl,
final String authCode, final ControlledProcessState processState, FutureServiceContainer futureContainer) {
this.environment = environment;
this.runningModeControl = runningModeControl;
this.authCode = authCode;
this.processState = processState;
this.startTime = environment.getStartTime();
this.elapsedTime = environment.getElapsedTime();
this.futureContainer = futureContainer;
this.capabilityRegistry = new CapabilityRegistry(false);
}
Expand All @@ -99,8 +101,10 @@ public HostControllerService(final HostControllerEnvironment environment, final

@Override
public void start(StartContext context) throws StartException {
//Moved to AbstractControllerService.start()
// processState.setStarting();

// If this is a reload, track start time independently of the overall process elapsed time
ElapsedTime startupTime = everStopped ? elapsedTime.checkpoint() : elapsedTime;

final ProductConfig config = environment.getProductConfig();
final String prettyVersion = config.getPrettyVersionString();
final String banner = environment.getStability() == org.jboss.as.version.Stability.EXPERIMENTAL ? config.getBanner() : "";
Expand Down Expand Up @@ -149,14 +153,7 @@ public void start(StartContext context) throws StartException {

final ServiceContainer serviceContainer = myController.getServiceContainer();

long startTime = this.startTime;
if (startTime == -1) {
startTime = System.currentTimeMillis();
} else {
this.startTime = -1;
}

final BootstrapListener bootstrapListener = new BootstrapListener(serviceContainer, startTime, serviceTarget, futureContainer, prettyVersion + " (Host Controller)", environment.getDomainTempDir());
final BootstrapListener bootstrapListener = new BootstrapListener(serviceContainer, startupTime, serviceTarget, futureContainer, prettyVersion + " (Host Controller)", environment.getDomainTempDir());
bootstrapListener.getStabilityMonitor().addController(myController);

// The first default services are registered before the bootstrap operations are executed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.jboss.as.host.controller;

import static org.jboss.as.server.ElapsedTime.startingFromJvmStart;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,6 +26,7 @@
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.interfaces.InetAddressUtil;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.controller.operations.common.ProcessEnvironment;
import org.jboss.as.controller.persistence.ConfigurationFile;
import org.jboss.as.host.controller.logging.HostControllerLogger;
Expand Down Expand Up @@ -124,9 +127,8 @@ public static HostControllerBootstrap create(String[] args, final String authCod

private HostControllerBootstrap boot(String[] args, final String authCode) {
try {
// TODO make this settable via an embedding process
final long startTime = Module.getStartTime();
final HostControllerEnvironmentWrapper hostControllerEnvironmentWrapper = determineEnvironment(args, startTime);
final HostControllerEnvironmentWrapper hostControllerEnvironmentWrapper =
determineEnvironment(args, startingFromJvmStart(), ProcessType.HOST_CONTROLLER);
if (hostControllerEnvironmentWrapper.getHostControllerEnvironment() == null) {
usage(hostControllerEnvironmentWrapper.getProductConfig()); // In case there was an error determining the environment print the usage
if (hostControllerEnvironmentWrapper.getHostControllerEnvironmentStatus() == HostControllerEnvironmentWrapper.HostControllerEnvironmentStatus.ERROR) {
Expand Down Expand Up @@ -188,11 +190,9 @@ private static void usage(ProductConfig productConfig) {
CommandLineArgumentUsageImpl.printUsage(productConfig, STDOUT);
}

public static HostControllerEnvironmentWrapper determineEnvironment(String[] args, long startTime) {
return determineEnvironment(args, startTime, ProcessType.HOST_CONTROLLER);
}

public static HostControllerEnvironmentWrapper determineEnvironment(String[] args, long startTime, ProcessType processType) {
public static HostControllerEnvironmentWrapper determineEnvironment(String[] args,
ElapsedTime elapsedTime,
ProcessType processType) {
Integer pmPort = null;
InetAddress pmAddress = null;
final PCSocketConfig pcSocketConfig = new PCSocketConfig();
Expand Down Expand Up @@ -477,7 +477,7 @@ public static HostControllerEnvironmentWrapper determineEnvironment(String[] arg
return new HostControllerEnvironmentWrapper(new HostControllerEnvironment(hostSystemProperties, isRestart, modulePath,
pmAddress, pmPort, pcSocketConfig.getBindAddress(), pcSocketConfig.getBindPort(), defaultJVM, domainConfig,
initialDomainConfig, hostConfig, initialHostConfig, initialRunningMode, backupDomainFiles, cachedDc,
productConfig, securityManagerEnabled, startTime, processType, hostConfigInteractionPolicy, domainConfigInteractionPolicy));
productConfig, securityManagerEnabled, elapsedTime, processType, hostConfigInteractionPolicy, domainConfigInteractionPolicy));
}

private static boolean isJavaSecurityManagerConfigured(final Map<String, String> props) {
Expand Down
Loading

0 comments on commit 378dad0

Please sign in to comment.