Skip to content

Commit

Permalink
[WFCORE-884] Add a capability for interfaces
Browse files Browse the repository at this point in the history
Also renames DomainModelReferenceValidator and removes its use from a few cases left over from WFCORE-833.
  • Loading branch information
bstansberry committed Aug 18, 2015
1 parent 89176da commit 17e2cca
Show file tree
Hide file tree
Showing 40 changed files with 314 additions and 207 deletions.
Expand Up @@ -43,6 +43,7 @@ public abstract class AbstractSocketBindingGroupAddHandler extends AbstractAddSt
* Create the AbstractSocketBindingGroupAddHandler
*/
protected AbstractSocketBindingGroupAddHandler() {
super(AbstractSocketBindingGroupResourceDefinition.SOCKET_BINDING_GROUP_CAPABILITY);
}

/**
Expand Down
Expand Up @@ -36,8 +36,9 @@
*/
public class InterfaceAddHandler extends AbstractAddStepHandler {


@Deprecated
public static final InterfaceAddHandler NAMED_INSTANCE = new InterfaceAddHandler(false);
@Deprecated
public static final InterfaceAddHandler SPECIFIED_INSTANCE = new InterfaceAddHandler(true);

private final boolean specified;
Expand Down
Expand Up @@ -32,6 +32,7 @@ public class InterfaceRemoveHandler extends AbstractRemoveStepHandler {

public static final String OPERATION_NAME = REMOVE;

@Deprecated
public static final InterfaceRemoveHandler INSTANCE = new InterfaceRemoveHandler();

/**
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.resource.AbstractSocketBindingGroupResourceDefinition;
import org.jboss.dmr.ModelNode;

/**
Expand All @@ -41,6 +42,7 @@ public class SocketBindingGroupRemoveHandler extends AbstractRemoveStepHandler {
* Create the AbstractSocketBindingRemoveHandler
*/
protected SocketBindingGroupRemoveHandler() {
super(AbstractSocketBindingGroupResourceDefinition.SOCKET_BINDING_GROUP_CAPABILITY);
}

protected boolean requiresRuntime(OperationContext context) {
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.access.management.AccessConstraintDefinition;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.common.ControllerResolver;
import org.jboss.as.controller.logging.ControllerLogger;
Expand All @@ -53,6 +54,10 @@
*/
public abstract class AbstractSocketBindingGroupResourceDefinition extends SimpleResourceDefinition {

public static final String SOCKET_BINDING_GROUP_CAPABILITY_NAME = "org.wildfly.domain.socket-binding-group";
public static final RuntimeCapability SOCKET_BINDING_GROUP_CAPABILITY = RuntimeCapability.Builder.of(SOCKET_BINDING_GROUP_CAPABILITY_NAME, true)
.build();

// Common attributes

public static final PathElement PATH = PathElement.pathElement(ModelDescriptionConstants.SOCKET_BINDING_GROUP);
Expand All @@ -62,10 +67,11 @@ public abstract class AbstractSocketBindingGroupResourceDefinition extends Simpl
.setValidator(new StringLengthValidator(1)).build();

public static final SimpleAttributeDefinition DEFAULT_INTERFACE = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.DEFAULT_INTERFACE, ModelType.STRING, false)
.setAllowExpression(true).setValidator(new StringLengthValidator(1, Integer.MAX_VALUE, false, true))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES).build();


.setAllowExpression(true)
.setValidator(new StringLengthValidator(1, Integer.MAX_VALUE, false, true))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setCapabilityReference("org.wildfly.network.interface", SOCKET_BINDING_GROUP_CAPABILITY)
.build();

private final List<AccessConstraintDefinition> accessConstraints;

Expand Down Expand Up @@ -119,4 +125,8 @@ public static void validateDefaultInterfaceReference(final OperationContext cont

}

@Override
public void registerCapabilities(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerCapability(SOCKET_BINDING_GROUP_CAPABILITY);
}
}
Expand Up @@ -49,6 +49,9 @@
*/
public abstract class AbstractSocketBindingResourceDefinition extends SimpleResourceDefinition {


public static final String SOCKET_BINDING_CAPABILITY_NAME = "org.wildfly.network.socket-binding";

// Common attributes

public static final PathElement PATH = PathElement.pathElement(ModelDescriptionConstants.SOCKET_BINDING);
Expand All @@ -58,8 +61,11 @@ public abstract class AbstractSocketBindingResourceDefinition extends SimpleReso
.setValidator(new StringLengthValidator(1)).build();

public static final SimpleAttributeDefinition INTERFACE = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.INTERFACE, ModelType.STRING, true)
.setAllowExpression(true).setValidator(new StringLengthValidator(1, Integer.MAX_VALUE, true, true))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES).build();
.setAllowExpression(true)
.setValidator(new StringLengthValidator(1, Integer.MAX_VALUE, true, true))
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setCapabilityReference("org.wildfly.network.interface", SOCKET_BINDING_CAPABILITY_NAME, true)
.build();

public static final SimpleAttributeDefinition PORT = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.PORT, ModelType.INT, true)
.setAllowExpression(true)
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

Expand Down Expand Up @@ -67,6 +68,9 @@
* @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a> (c) 2012 Red Hat Inc.
*/
public class InterfaceDefinition extends SimpleResourceDefinition {

public static final String INTERFACE_CAPABILITY_NAME = "org.wildfly.network.interface";

public static final String[] OTHERS = new String[]{localName(Element.INET_ADDRESS), localName(Element.LINK_LOCAL_ADDRESS),
localName(Element.LOOPBACK), localName(Element.LOOPBACK_ADDRESS), localName(Element.MULTICAST), localName(Element.NIC),
localName(Element.NIC_MATCH), localName(Element.POINT_TO_POINT), localName(Element.PUBLIC_ADDRESS), localName(Element.SITE_LOCAL_ADDRESS),
Expand Down
Expand Up @@ -34,8 +34,8 @@
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistration;
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.resource.AbstractSocketBindingGroupResourceDefinition;
import org.jboss.as.core.model.test.ModelInitializer;
import org.jboss.as.domain.controller.operations.SocketBindingGroupResourceDefinition;
import org.jboss.as.domain.controller.resources.ServerGroupResourceDefinition;

/**
Expand All @@ -52,7 +52,7 @@ public final class ServerConfigInitializers {
private static final String TEST_OTHER_SERVER_GROUP_CAPABILITY = ServerGroupResourceDefinition.SERVER_GROUP_CAPABILITY.getDynamicName("other-server-group");
private static final PathAddress TEST_OTHER_SERVER_GROUP_ADDRESS = PathAddress.pathAddress(SERVER_GROUP, "other-server-group");

private static final String TEST_FULL_HA_SOCKETS_CAPABILITY = SocketBindingGroupResourceDefinition.SOCKET_BINDING_GROUP_CAPABILITY.getDynamicName("full-ha-sockets");
private static final String TEST_FULL_HA_SOCKETS_CAPABILITY = AbstractSocketBindingGroupResourceDefinition.SOCKET_BINDING_GROUP_CAPABILITY.getDynamicName("full-ha-sockets");
private static final PathAddress TEST_FULL_HA_SOCKETS_ADDRESS = PathAddress.pathAddress(SOCKET_BINDING_GROUP, "full-ha-sockets");
private static final CapabilityContext TEST_SBG_CONTEXT = CapabilityContext.Factory.create(ProcessType.HOST_CONTROLLER, TEST_FULL_HA_SOCKETS_ADDRESS);

Expand Down
Expand Up @@ -34,10 +34,10 @@
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistration;
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.resource.AbstractSocketBindingGroupResourceDefinition;
import org.jboss.as.core.model.test.LegacyKernelServicesInitializer;
import org.jboss.as.core.model.test.ModelInitializer;
import org.jboss.as.core.model.test.ModelWriteSanitizer;
import org.jboss.as.domain.controller.operations.SocketBindingGroupResourceDefinition;
import org.jboss.as.domain.controller.resources.ProfileResourceDefinition;
import org.jboss.as.model.test.ModelFixer;
import org.jboss.dmr.ModelNode;
Expand All @@ -52,7 +52,7 @@ public class StandardServerGroupInitializers {
private static final PathAddress TEST_PROFILE_ADDRESS = PathAddress.pathAddress(PROFILE, "test");
private static final CapabilityContext TEST_PROFILE_CONTEXT = CapabilityContext.Factory.create(ProcessType.HOST_CONTROLLER, TEST_PROFILE_ADDRESS);

private static final String TEST_SBG_CAPABILITY = SocketBindingGroupResourceDefinition.SOCKET_BINDING_GROUP_CAPABILITY.getDynamicName("test-sockets");
private static final String TEST_SBG_CAPABILITY = AbstractSocketBindingGroupResourceDefinition.SOCKET_BINDING_GROUP_CAPABILITY.getDynamicName("test-sockets");
private static final PathAddress TEST_SBG_ADDRESS = PathAddress.pathAddress(SOCKET_BINDING_GROUP, "test-sockets");
private static final CapabilityContext TEST_SBG_CONTEXT = CapabilityContext.Factory.create(ProcessType.HOST_CONTROLLER, TEST_SBG_ADDRESS);

Expand Down
Expand Up @@ -30,13 +30,13 @@
import org.jboss.dmr.ModelNode;

/**
* Write attribute handler to trigger validation when something in the domain model involving references has changed
* Write attribute handler to trigger validation when something in the domain model involving includes has changed
*
* @author Kabir Khan
*/
public class DomainReferenceValidationWriteAttributeHandler extends ModelOnlyWriteAttributeHandler {
public class DomainIncludesValidationWriteAttributeHandler extends ModelOnlyWriteAttributeHandler {

public DomainReferenceValidationWriteAttributeHandler(AttributeDefinition... attributeDefinitions) {
public DomainIncludesValidationWriteAttributeHandler(AttributeDefinition... attributeDefinitions) {
super(attributeDefinitions);
}

Expand All @@ -49,7 +49,7 @@ protected void finishModelStage(OperationContext context, ModelNode operation, S
ServerOperationResolver.addToDontPropagateToServersAttachment(context, operation);
}

DomainModelReferenceValidator.addValidationStep(context, operation);
DomainModelIncludesValidator.addValidationStep(context, operation);
}

}
Expand Up @@ -22,16 +22,12 @@

package org.jboss.as.domain.controller.operations;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDES;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INTERFACE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROFILE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_DEFAULT_INTERFACE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;

Expand All @@ -49,37 +45,34 @@
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.registry.Resource.ResourceEntry;
import org.jboss.as.host.controller.logging.HostControllerLogger;
import org.jboss.dmr.ModelNode;

/**
* Handler validating that all known model references are present, that "including" resources don't involve
* cycles, and that including resources don't involve children that override the included resources.
*
* The model reference part of this is slowly being replaced with capability-based model reference validation..
* Handler validating that "including" resources don't involve cycles
* and that including resources don't involve children that override the included resources.
*
* @author Emanuel Muckenhuber
* @author Kabir Khan
*/
public class DomainModelReferenceValidator implements OperationStepHandler {
public class DomainModelIncludesValidator implements OperationStepHandler {

private static DomainModelReferenceValidator INSTANCE = new DomainModelReferenceValidator();
private static final AttachmentKey<DomainModelReferenceValidator> KEY = AttachmentKey.create(DomainModelReferenceValidator.class);
private static DomainModelIncludesValidator INSTANCE = new DomainModelIncludesValidator();
private static final AttachmentKey<DomainModelIncludesValidator> KEY = AttachmentKey.create(DomainModelIncludesValidator.class);

private DomainModelReferenceValidator() {
private DomainModelIncludesValidator() {
}

public static void addValidationStep(OperationContext context, ModelNode operation) {
assert context.getProcessType() == ProcessType.HOST_CONTROLLER : "Not a host controller";
if (!context.isBooting()) {
// This does not need to get executed on boot the domain controller service does that once booted
// by calling validateAtBoot(). Otherwise we get issues with the testsuite, which only partially sets up the model
if (context.attachIfAbsent(KEY, DomainModelReferenceValidator.INSTANCE) == null) {
context.addStep(DomainModelReferenceValidator.INSTANCE, OperationContext.Stage.MODEL);
if (context.attachIfAbsent(KEY, DomainModelIncludesValidator.INSTANCE) == null) {
context.addStep(DomainModelIncludesValidator.INSTANCE, OperationContext.Stage.MODEL);
}
}
}
Expand All @@ -89,8 +82,8 @@ public static void validateAtBoot(OperationContext context, ModelNode operation)
assert context.isBooting() : "Should only be called at boot";
assert operation.require(OP).asString().equals("validate"); //Should only be called by the domain controller service
//Only validate once
if (context.attachIfAbsent(KEY, DomainModelReferenceValidator.INSTANCE) == null) {
context.addStep(DomainModelReferenceValidator.INSTANCE, OperationContext.Stage.MODEL);
if (context.attachIfAbsent(KEY, DomainModelIncludesValidator.INSTANCE) == null) {
context.addStep(DomainModelIncludesValidator.INSTANCE, OperationContext.Stage.MODEL);
}
}

Expand All @@ -102,96 +95,13 @@ public void execute(final OperationContext context, final ModelNode operation) t

public void validate(final OperationContext context) throws OperationFailedException {

// final Set<String> serverGroups = new HashSet<>();
final Set<String> interfaces = new HashSet<String>();

final Resource domain = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
final Set<String> missingProfiles = new HashSet<>();
final Set<String> missingSocketBindingGroups = new HashSet<>();
checkProfileIncludes(domain, missingProfiles);
checkSocketBindingGroupIncludes(domain, missingSocketBindingGroups);
final String hostName = determineHostName(domain);
if (hostName != null) {
// The testsuite does not always setup the model properly
final Resource host = domain.getChild(PathElement.pathElement(HOST, hostName));
for (final Resource.ResourceEntry serverConfig : host.getChildren(SERVER_CONFIG)) {
final ModelNode model = serverConfig.getModel();
// final String group = model.require(GROUP).asString();
// if (!serverGroups.contains(group)) {
// serverGroups.add(group);
// }
if (model.hasDefined(SOCKET_BINDING_DEFAULT_INTERFACE)) {
String defaultInterface = model.get(SOCKET_BINDING_DEFAULT_INTERFACE).asString();
if (!interfaces.contains(defaultInterface)) {
interfaces.add(defaultInterface);
}
}
// BES 2015/08/07 We use capability/requirement validation for this
//processSocketBindingGroup(model, allSocketBindingGroups, missingSocketBindingGroups);
}
}

// process referenced server-groups
// BES 2015/08/07 We use capability/requirement validation for this
// for (final Resource.ResourceEntry serverGroup : domain.getChildren(SERVER_GROUP)) {
// final ModelNode model = serverGroup.getModel();
// final String profile = model.require(PROFILE).asString();
// if (!allProfiles.contains(profile)) {
// missingProfiles.add(profile);
// }
// // Process the socket-binding-group
//
// processSocketBindingGroup(model, allSocketBindingGroups, missingSocketBindingGroups);
//
// serverGroups.remove(serverGroup.getName()); // The server-group is present
// }

// process referenced interfaces
for (final Resource.ResourceEntry iface : domain.getChildren(INTERFACE)) {
interfaces.remove(iface.getName());
}
// If we are missing a server group
// BES 2015/08/07 We use capability/requirement validation for this
// if (!serverGroups.isEmpty()) {
// throw HostControllerLogger.ROOT_LOGGER.missingReferences(SERVER_GROUP, serverGroups);
// }
// We are missing a profile
// BES 2015/06/19 We use capability/requirement validation for this
// if (!missingProfiles.isEmpty()) {
// throw HostControllerLogger.ROOT_LOGGER.missingReferences(PROFILE, missingProfiles);
// }
// Process socket-binding groups
// BES 2015/08/07 We use capability/requirement validation for this
// if (!missingSocketBindingGroups.isEmpty()) {
// throw HostControllerLogger.ROOT_LOGGER.missingReferences(SOCKET_BINDING_GROUP, missingSocketBindingGroups);
// }

//We are missing an interface
if (!interfaces.isEmpty()) {
throw HostControllerLogger.ROOT_LOGGER.missingReferences(INTERFACE, interfaces);
}

}
// BES 2015/08/07 We use capability/requirement validation for this
// private void processSocketBindingGroup(final ModelNode model, final Set<String> socketBindings, final Set<String> missingSocketBindings) {
// if (model.hasDefined(SOCKET_BINDING_GROUP)) {
// final String socketBinding = model.require(SOCKET_BINDING_GROUP).asString();
// if (!socketBindings.contains(socketBinding)) {
// missingSocketBindings.add(socketBinding);
// }
// }
// }

private String determineHostName(final Resource domain) {
// This could use a better way to determine the local host name
for (final Resource.ResourceEntry entry : domain.getChildren(HOST)) {
if (entry.isProxy() || entry.isRuntime()) {
continue;
}
return entry.getName();
}
return null;
}
}

private Set<String> checkProfileIncludes(Resource domain, Set<String> missingProfiles) throws OperationFailedException {
ProfileIncludeValidator validator = new ProfileIncludeValidator();
Expand Down

0 comments on commit 17e2cca

Please sign in to comment.