Skip to content

Commit

Permalink
[WFCORE-6503]: Fixing the reloading issue
Browse files Browse the repository at this point in the history
Signed-off-by: Emmanuel Hugonnet <[email protected]>
  • Loading branch information
ehsavoie committed Mar 20, 2024
1 parent 27e93b3 commit ed19e2f
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ boolean boot(final List<ModelNode> bootList, final OperationMessageHandler handl
headers, handler, null, managementModel.get(), control, processState, auditLogger,
bootingFlag.get(), true, hostServerGroupTracker, null, notificationSupport, true,
extraValidationStepHandler, partialModel, securityIdentitySupplier);
if (configExtension != null && configExtension.shouldProcessOperations(runningModeControl.getRunningMode()) && !runningModeControl.isReloaded()) {
if (configExtension != null && configExtension.shouldProcessOperations(runningModeControl.getRunningMode()) && (!runningModeControl.isReloaded() || runningModeControl.isApplyConfigurationExtension())) {
configExtension.processOperations(managementModel.get().getRootResourceRegistration(), bootOperations.postExtensionOps);
}
for (ParsedBootOp parsedOp : bootOperations.postExtensionOps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class RunningModeControl {
private volatile boolean useCurrentConfig;
private volatile String newBootFileName;
private volatile Boolean suspend;
private volatile boolean applyConfigurationExtension;

public RunningModeControl(final RunningMode initialMode) {
this.runningMode = initialMode;
Expand Down Expand Up @@ -58,6 +59,14 @@ public void setSuspend(Boolean suspend) {
this.suspend = suspend;
}

public boolean isApplyConfigurationExtension() {
return applyConfigurationExtension;
}

public void setApplyConfigurationExtension(boolean applyConfigurationExtension) {
this.applyConfigurationExtension = applyConfigurationExtension;
}

/**
* Get the new boot file name. For a standalone server this will be the location of the server configuration
* (i.e. the standalone.xml variety). For a host controller this will be the location of the host configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private static boolean isSuppressLoad(ConfigurationFile configurationFile, boole
return initialEmpty && !reload;
}

@Override
public void registerAdditionalRootElement(final QName anotherRoot, final XMLElementReader<List<ModelNode>> parser){
super.registerAdditionalRootElement(anotherRoot, parser);
}
Expand All @@ -93,13 +94,16 @@ public boolean isPersisting() {
public PersistenceResource store(final ModelNode model, Set<PathAddress> affectedAddresses) throws ConfigurationPersistenceException {
if(!successfulBoot.get()) {
return new PersistenceResource() {
@Override
public void commit() {
}

@Override
public void rollback() {
}
};
}
this.stored = true;
return new ConfigurationFilePersistenceResource(model, configurationFile, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ default boolean isPersisting() {
return true;
}

/**
* Gets whether a call persist to persistent storage has been successfully completed.
* <p>
* The default implementation always returns {@code false}
*
* @return {@code true} if a call to {@link #store(ModelNode, Set)} will return an object that actually writes
*/
default boolean hasStored() {
return false;
}

/**
* Persist the given configuration model if {@link #isPersisting()} would return {@code true}, otherwise
* return a no-op {@link PersistenceResource}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public List<ModelNode> load() {
return Collections.emptyList();
}

@Override
public boolean hasStored() {
return false;
}

private static class NullPersistenceResource implements ConfigurationPersister.PersistenceResource {

private static final NullPersistenceResource INSTANCE = new NullPersistenceResource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class XmlConfigurationPersister extends AbstractConfigurationPersister {
private final XMLElementReader<List<ModelNode>> rootParser;
private final Map<QName, XMLElementReader<List<ModelNode>>> additionalParsers;
private final boolean suppressLoad;
protected volatile boolean stored = false;

/**
* Construct a new instance.
Expand Down Expand Up @@ -84,6 +85,7 @@ public void registerAdditionalRootElement(final QName anotherRoot, final XMLElem
/** {@inheritDoc} */
@Override
public PersistenceResource store(final ModelNode model, Set<PathAddress> affectedAddresses) throws ConfigurationPersistenceException {
stored = true;
return new FilePersistenceResource(model, fileName, this);
}

Expand Down Expand Up @@ -157,4 +159,9 @@ protected void successfulBoot(File file) throws ConfigurationPersistenceExceptio

}

@Override
public boolean hasStored() {
return isPersisting() && stored;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class StringConfigurationPersister extends AbstractConfigurationPersister
private final List<ModelNode> bootOperations;
private final boolean persistXml;
volatile String marshalled;
private volatile boolean stored = false;

public StringConfigurationPersister(List<ModelNode> bootOperations, XMLElementWriter<ModelMarshallingContext> rootDeparser, boolean persistXml) {
super(rootDeparser);
Expand All @@ -40,6 +41,7 @@ public PersistenceResource store(ModelNode model, Set<PathAddress> affectedAddre
if (!persistXml) {
return new NullConfigurationPersister().store(model, affectedAddresses);
}
stored = true;
return new StringPersistenceResource(model, this);
}

Expand All @@ -56,6 +58,11 @@ public String getMarshalled() {
return marshalled;
}

@Override
public boolean hasStored() {
return isPersisting() && stored;
}

private class StringPersistenceResource implements PersistenceResource {
private byte[] bytes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void registerOperations(ManagementResourceRegistration resourceRegistrati
resourceRegistration.registerOperationHandler(ServerDomainProcessShutdownHandler.DOMAIN_DEFINITION, new ServerDomainProcessShutdownHandler());

} else {
final ServerProcessReloadHandler reloadHandler = new ServerProcessReloadHandler(Services.JBOSS_AS, runningModeControl, processState, serverEnvironment);
final ServerProcessReloadHandler reloadHandler = new ServerProcessReloadHandler(Services.JBOSS_AS, runningModeControl, processState, serverEnvironment, extensibleConfigurationPersister);
resourceRegistration.registerOperationHandler(ServerProcessReloadHandler.DEFINITION, reloadHandler, false);

resourceRegistration.registerOperationHandler(ServerSuspendHandler.DEFINITION, ServerSuspendHandler.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ServerDomainProcessReloadHandler extends ServerProcessReloadHandler
public ServerDomainProcessReloadHandler(ServiceName rootService, RunningModeControl runningModeControl, ControlledProcessState processState,
final DomainServerCommunicationServices.OperationIDUpdater operationIDUpdater,
final ServerEnvironment serverEnvironment) {
super(rootService, runningModeControl, processState, serverEnvironment);
super(rootService, runningModeControl, processState, serverEnvironment, null);
this.operationIDUpdater = operationIDUpdater;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.jboss.as.server.operations;


import java.util.Locale;

import org.jboss.as.controller.AttributeDefinition;
Expand All @@ -20,6 +21,7 @@
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.ProcessReloadHandler;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.persistence.ExtensibleConfigurationPersister;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.controller.descriptions.ServerDescriptions;
import org.jboss.as.server.logging.ServerLogger;
Expand Down Expand Up @@ -59,10 +61,12 @@ public class ServerProcessReloadHandler extends ProcessReloadHandler<RunningMode
.build();

private final ServerEnvironment environment;
private ExtensibleConfigurationPersister extensibleConfigurationPersister;
public ServerProcessReloadHandler(ServiceName rootService, RunningModeControl runningModeControl,
ControlledProcessState processState, ServerEnvironment environment) {
ControlledProcessState processState, ServerEnvironment environment, ExtensibleConfigurationPersister extensibleConfigurationPersister) {
super(rootService, runningModeControl, processState);
this.environment = environment;
this.extensibleConfigurationPersister = extensibleConfigurationPersister;
}

@Override
Expand Down Expand Up @@ -91,6 +95,8 @@ protected ProcessReloadHandler.ReloadContext<RunningModeControl> initializeReloa
}
final boolean finalSuspend = suspend;
final boolean finalAdminOnly = adminOnly;
final boolean applyConfigurationExtension = !(context.isNormalServer() || finalAdminOnly) ||
(extensibleConfigurationPersister != null && !extensibleConfigurationPersister.hasStored());

final String serverConfig = unmanaged && operation.hasDefined(SERVER_CONFIG.getName()) ? SERVER_CONFIG.resolveModelAttribute(context, operation).asString() : null;

Expand All @@ -113,6 +119,7 @@ public void doReload(RunningModeControl runningModeControl) {
runningModeControl.setUseCurrentConfig(useCurrentConfig);
runningModeControl.setNewBootFileName(serverConfig);
runningModeControl.setSuspend(finalSuspend);
runningModeControl.setApplyConfigurationExtension(applyConfigurationExtension);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void testFailedDeploymentYaml() throws URISyntaxException, Exception {
} catch (RuntimeException ex) {
Assert.assertFalse(container.isStarted());
try (final BufferedReader reader = Files.newBufferedReader(basedir.resolve("log").resolve("server.log"), StandardCharsets.UTF_8)) {
Assert.assertTrue(reader.lines().anyMatch(line -> line.contains("WFLYCTL0505: Unsuported deployment yaml file hello.jar with attributes [empty]")));
Assert.assertTrue(reader.lines().anyMatch(line -> line.contains("WFLYCTL0507: Unsuported deployment yaml file hello.jar with attributes [empty]")));
}
} finally {
container.stop();
Expand Down

0 comments on commit ed19e2f

Please sign in to comment.