Skip to content

Commit

Permalink
[WFCORE-6771]: Fixing several small issues with the YAML extension.
Browse files Browse the repository at this point in the history
* adding WARNING traces
* adding warning if YAML is adding an existing resource without any attribute
* failing if unexisting attribute is used
* better error messages
* ignoring removal of unexisting resource
* warning about ignoring unexisting resource delete operation
* Fixing how we apply YAML configuration on reload
* Adding configuration for YAML file size.
* Adding tests for yaml

Jira: https://issues.redhat.com/browse/WFCORE-6771

Signed-off-by: Emmanuel Hugonnet <[email protected]>
  • Loading branch information
ehsavoie committed Apr 5, 2024
1 parent d0d5a88 commit fdd4171
Show file tree
Hide file tree
Showing 42 changed files with 1,032 additions and 271 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())) {
if (configExtension != null && configExtension.shouldProcessOperations(runningModeControl)) {
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,20 @@ public void setSuspend(Boolean suspend) {
this.suspend = suspend;
}

/**
* Indicates if the configuration extension should be applied after reloading.
* This should occur on a reload if no changes were applied (thus stored) or after the changes made
* by a boot cli script.
* @return true if we should apply the configuration extension - false otherwise.
*/
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 @@ -3682,7 +3682,7 @@ OperationFailedRuntimeException capabilityAlreadyRegisteredInContext(String capa
IllegalArgumentException noResourceForUndefiningAttribute(String attribute, String address);

@LogMessage(level = WARN)
@Message(id = 490, value = "You have defined a resource for address %s without any attributes, doing nothing")
@Message(id = 490, value = "A YAML resource has been defined for the address %s without any attribute. No actions will be taken.")
void noAttributeSetForAddress(String address);

@LogMessage(level = WARN)
Expand Down Expand Up @@ -3744,7 +3744,7 @@ OperationFailedRuntimeException capabilityAlreadyRegisteredInContext(String capa
@Message(id = 501, value = "An invalid UUID string '%s' was found at '%s'. A new value will be generated.")
void uuidNotValid(String corruptedUuid, String path);

@Message(id = 502, value = "No child resource called %s could be found at address %s'.")
@Message(id = 502, value = "No child resource called '%s' could be found at address '%s'.")
IllegalArgumentException noChildResource(String name, String address);

@Message(id = 503, value = "Failed to publish configuration, because the remote name %s is not valid.")
Expand All @@ -3759,4 +3759,27 @@ OperationFailedRuntimeException capabilityAlreadyRegisteredInContext(String capa
@LogMessage(level = WARN)
@Message(id = 506, value = "Extension %s from module %s is not enabled by the current stability level")
void unstableExtension(String extensionName, String moduleName);

@Message(id = 507, value = "Unsuported deployment yaml file %s with attributes %s")
IllegalArgumentException unsupportedDeployment(String deployment, Set<String> attributes);

@Message(id = 508, value = "The yaml element '%s' and its sub-elements are ignored.")
String ignoreYamlElement(String element);

@Message(id = NONE, value = " Thus ignoring element '%s'.")
String ignoreYamlSubElement(String element);

@Message(id = 509, value = "No attribute called '%s' is defined at address '%s'.")
IllegalArgumentException noAttributeDefined(String name, String address);

@Message(id = 510, value = "No operation %s can be executed for attribute called '%s' is defined at address '%s'.")
IllegalArgumentException illegalOperationForAttribute(String operationName, String attribute, String address);

@LogMessage(level = WARN)
@Message(id = 511, value = "No value is defined for attribute '%s' at address '%s'.")
void noAttributeValueDefined(String name, String address);

@LogMessage(level = WARN)
@Message(id = 512, value = "No resource exists at address '%s'. Ignoring the remove opreation.")
void removingUnexistingResource(String address);
}
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 @@ -8,7 +8,7 @@
import java.nio.file.Path;
import java.util.List;
import org.jboss.as.controller.ParsedBootOp;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.RunningModeControl;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;

/**
Expand Down Expand Up @@ -44,10 +44,10 @@ public interface ConfigurationExtension {

/**
* Checks if the configuration extension should process the supplemental configurations.
* @param mode: the running mode of the server.
* @param runningModeControl: the running mode control of the server.
* @return true if the configuration extension should process operations - false otherwise.
*/
boolean shouldProcessOperations(RunningMode mode);
boolean shouldProcessOperations(RunningModeControl runningModeControl);

/**
* Process the already defined boot operations to update them with the supplemnetal configurations.
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;
}

}
Loading

0 comments on commit fdd4171

Please sign in to comment.