Skip to content

Commit

Permalink
[WFCORE-893] Add a default io subsystem to profiles using a legacy re…
Browse files Browse the repository at this point in the history
…moting config
  • Loading branch information
bstansberry committed Aug 23, 2015
1 parent 81f588d commit 7378b87
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 30 deletions.
Expand Up @@ -25,6 +25,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -314,14 +315,25 @@ TransformerRegistry getTransformersRegistry() {
protected boolean boot(List<ModelNode> bootOperations, boolean rollbackOnRuntimeFailure) throws ConfigurationPersistenceException {
try {
preBoot(bootOperations, rollbackOnRuntimeFailure);
OperationValidator validator = new OperationValidator(rootRegistration);

// See what we need to validate, but defer doing it to after super.boot to allow
// initModel to run first and given tests a chance to set things up
List<ModelNode> validationList = new ArrayList<>();
for (ModelNode op : bootOperations) {
ModelNode toValidate = validateOpsFilter.adjustForValidation(op.clone());
if (toValidate != null) {
validator.validateOperation(toValidate);
validationList.add(toValidate);
}
}

bootSuccess = super.boot(persister.getBootOperations(), rollbackOnRuntimeFailure);

// Ok, now we can validate
OperationValidator validator = new OperationValidator(rootRegistration);
for (ModelNode op : validationList) {
validator.validateOperation(op);
}

return bootSuccess;
} catch (Exception e) {
error = e;
Expand Down
Expand Up @@ -46,13 +46,23 @@ public class ModelTestOperationValidatorFilter implements Serializable {
private final List<OperationEntry> entries;

private ModelTestOperationValidatorFilter(List<OperationEntry> entries) {
this.entries = entries;
this.entries = createStandardEntries(entries);
validateNone = false;
}

private ModelTestOperationValidatorFilter(boolean validateNone) {
this.validateNone = validateNone;
entries = null;
entries = validateNone ? null : createStandardEntries(null);
}

private static List<OperationEntry> createStandardEntries(List<OperationEntry> provided) {
if (provided == null) {
provided = new ArrayList<>();
}
// Don't check the private internal op that deregisters itself before we get a chance to validate it
OperationEntry oe = new OperationEntry(PathAddress.EMPTY_ADDRESS, "boottime-controller-initializer-step", Action.NOCHECK, null);
provided.add(oe);
return provided;
}

public static ModelTestOperationValidatorFilter createValidateNone() {
Expand Down Expand Up @@ -82,19 +92,13 @@ public ModelNode adjustForValidation(ModelNode op) {
String name = op.get(OP).asString();

for (OperationEntry entry : entries) {
if (nameMatch(name, entry)) {
if (entry.address.size() == address.size()) {
for (int i = 0 ; i < address.size() ; i++) {
if (pathElementMatch(address.getElement(i), entry.address.getElement(i))) {
if (entry.action == Action.NOCHECK) {
return null;
} else if (entry.action == Action.RESOLVE){
op = op.resolve();
} else if (entry.operationFixer != null){
op = entry.operationFixer.fixOperation(op);
}
}
}
if (nameMatch(name, entry) && addressMatch(address, entry)) {
if (entry.action == Action.NOCHECK) {
return null;
} else if (entry.action == Action.RESOLVE){
op = op.resolve();
} else if (entry.operationFixer != null){
op = entry.operationFixer.fixOperation(op);
}
}
}
Expand All @@ -108,6 +112,19 @@ private boolean nameMatch(String opName, OperationEntry entry) {
return opName.equals(entry.name);
}

private boolean addressMatch(PathAddress opAddr, OperationEntry entry) {
boolean match = entry.address.size() == opAddr.size();
if (match) {
for (int i = 0; i < opAddr.size(); i++) {
if (!pathElementMatch(opAddr.getElement(i), entry.address.getElement(i))) {
match = false;
break;
}
}
}
return match;
}

private boolean pathElementMatch(PathElement element, PathElement operationEntryElement) {
if (operationEntryElement.getKey().equals("*")) {
} else if (!operationEntryElement.getKey().equals(element.getKey())) {
Expand Down
Expand Up @@ -22,18 +22,29 @@

package org.jboss.as.remoting;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MODULE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;

import java.util.List;
import java.util.Map;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.access.constraint.SensitivityClassification;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.parsing.ProfileParsingCompletionHandler;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.OperationTransformer;
import org.jboss.as.controller.transform.ResourceTransformer;
Expand All @@ -42,6 +53,7 @@
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;
import org.jboss.as.remoting.logging.RemotingLogger;
import org.jboss.dmr.ModelNode;

/**
Expand Down Expand Up @@ -76,6 +88,8 @@ static ResourceDescriptionResolver getResourceDescriptionResolver(final String k
private static final ModelVersion VERSION_1_3 = ModelVersion.create(1, 3);
private static final ModelVersion VERSION_2_1 = ModelVersion.create(2, 1);

private static final String IO_EXTENSION_MODULE = "org.wildfly.extension.io";

@Override
public void initialize(ExtensionContext context) {

Expand Down Expand Up @@ -173,6 +187,69 @@ public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.REMOTING_1_2.getUriString(), RemotingSubsystem12Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.REMOTING_2_0.getUriString(), RemotingSubsystem20Parser.INSTANCE);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.REMOTING_3_0.getUriString(), RemotingSubsystem30Parser.INSTANCE);

context.setProfileParsingCompletionHandler(new IOCompletionHandler());
}

private static class IOCompletionHandler implements ProfileParsingCompletionHandler {

@Override
public void handleProfileParsingCompletion(Map<String, List<ModelNode>> profileBootOperations, List<ModelNode> otherBootOperations) {

// If the namespace used for our subsystem predates the introduction of the IO subsystem,
// check if the profile includes io and if not add it

String legacyNS = null;
List<ModelNode> legacyRemotingOps = null;
for (Namespace ns : Namespace.values()) {
String nsString = ns.getUriString();
if (nsString != null && nsString.startsWith("urn:jboss:domain:remoting:1.")) {
legacyRemotingOps = profileBootOperations.get(nsString);
if (legacyRemotingOps != null) {
legacyNS = nsString;
break;
}
}
}

if (legacyRemotingOps != null) {
boolean foundIO = false;
for (String ns : profileBootOperations.keySet()) {
if (ns.startsWith("urn:jboss:domain:io:")) {
foundIO = true;
break;
}
}

if (!foundIO) {
// legacy Remoting subsystem and no io subsystem, add it

// See if we need to add the extension as well
boolean hasIoExtension = false;
for (ModelNode op : otherBootOperations) {
PathAddress pa = PathAddress.pathAddress(op.get(OP_ADDR));
if (pa.size() == 1 && EXTENSION.equals(pa.getElement(0).getKey())
&& IO_EXTENSION_MODULE.equals(pa.getElement(0).getValue())) {
hasIoExtension = true;
break;
}
}

if (!hasIoExtension) {
final ModelNode addIoExtensionOp = Util.createAddOperation(PathAddress.pathAddress(EXTENSION, IO_EXTENSION_MODULE));
addIoExtensionOp.get(MODULE).set(IO_EXTENSION_MODULE);
otherBootOperations.add(addIoExtensionOp);
}

PathAddress subsystemAddress = PathAddress.pathAddress(SUBSYSTEM, "io");
legacyRemotingOps.add(Util.createAddOperation(subsystemAddress));
legacyRemotingOps.add(Util.createAddOperation(subsystemAddress.append("worker", "default")));
legacyRemotingOps.add(Util.createAddOperation(subsystemAddress.append("buffer-pool", "default")));

RemotingLogger.ROOT_LOGGER.addingIOSubsystem(legacyNS);
}
}
}
}

}
Expand Up @@ -124,4 +124,9 @@ public interface RemotingLogger extends BasicLogger {

@Message(id = 23, value = "Only one of '%s' configuration or '%s' configuration is allowed")
String workerThreadsEndpointConfigurationChoiceRequired(String workerThreads, String endpoint);

@LogMessage(level = INFO)
@Message(id = 24, value = "The remoting subsystem is present but no io subsystem was found. An io subsystem " +
"was not required when remoting schema '%s' was current but now is, so a default subsystem is being added.")
void addingIOSubsystem(String legacyNS);
}

0 comments on commit 7378b87

Please sign in to comment.