Skip to content

Commit

Permalink
Merge pull request #7497 from pferraro/master
Browse files Browse the repository at this point in the history
WFLY-4654 JGroups transport type can't be set
  • Loading branch information
n1hility committed Jun 12, 2015
2 parents 8f94c77 + 3eb10c3 commit 597d175
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package org.jboss.as.clustering.controller.transform;

import java.util.Arrays;

import org.jboss.as.clustering.controller.Operations;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathAddress;
Expand All @@ -37,9 +39,13 @@
public class SimpleAddOperationTransformer implements org.jboss.as.controller.transform.OperationTransformer {

private final OperationTransformer transformer;
private final AttributeDefinition[] attributes;
private final Iterable<AttributeDefinition> attributes;

public SimpleAddOperationTransformer(PathAddressTransformer transformer, AttributeDefinition... attributes) {
this(transformer, Arrays.asList(attributes));
}

public SimpleAddOperationTransformer(final PathAddressTransformer transformer, AttributeDefinition... attributes) {
public SimpleAddOperationTransformer(final PathAddressTransformer transformer, Iterable<AttributeDefinition> attributes) {
this.transformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
Expand All @@ -50,6 +56,10 @@ public ModelNode transformOperation(ModelNode operation) {
}

public SimpleAddOperationTransformer(OperationTransformer transformer, AttributeDefinition... attributes) {
this(transformer, Arrays.asList(attributes));
}

public SimpleAddOperationTransformer(OperationTransformer transformer, Iterable<AttributeDefinition> attributes) {
this.transformer = transformer;
this.attributes = attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
* /subsystem=jgroups/stack=X/transport=TRANSPORT/property=Z
* /subsystem=jgroups/stack=X/protocol=Y/property=Z
*
* This resource is deprecated - replaced by a map attribute of the transport/protocol.
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
@Deprecated
public class PropertyResourceDefinition extends SimpleResourceDefinition {

static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.jboss.as.clustering.controller.validation.ModuleIdentifierValidator;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
Expand All @@ -53,6 +55,7 @@
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;

/**
Expand All @@ -72,7 +75,6 @@ static PathElement pathElement(String name) {
static final SimpleAttributeDefinition TYPE = new SimpleAttributeDefinitionBuilder(ModelKeys.TYPE, ModelType.STRING, true)
.setXmlName(Attribute.TYPE.getLocalName())
.setAllowExpression(false)
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion())
.build();

Expand All @@ -97,7 +99,7 @@ static PathElement pathElement(String name) {
.setDefaultValue(new ModelNode().setEmptyList())
.build();

static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] { TYPE, MODULE, SOCKET_BINDING, PROPERTIES };
static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] { MODULE, SOCKET_BINDING, PROPERTIES };

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
Expand Down Expand Up @@ -198,7 +200,11 @@ protected ResourceCreator getResourceCreator() {
}

ProtocolResourceDefinition(OperationStepHandler addHandler) {
super(WILDCARD_PATH, new JGroupsResourceDescriptionResolver(ModelKeys.PROTOCOL), addHandler, new ReloadRequiredRemoveStepHandler());
this(WILDCARD_PATH, addHandler);
}

ProtocolResourceDefinition(PathElement path, OperationStepHandler addHandler) {
super(path, new JGroupsResourceDescriptionResolver(path.getKey()), addHandler, new ReloadRequiredRemoveStepHandler());
}

@Override
Expand All @@ -213,6 +219,33 @@ public void registerAttributes(ManagementResourceRegistration registration) {
for (AttributeDefinition attr : ATTRIBUTES) {
registration.registerReadWriteAttribute(attr, null, writeHandler);
}

OperationStepHandler typeReadHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.getResult().set(context.getCurrentAddressValue());
}
};
OperationStepHandler typeWriteHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
// Issue remove operation for old resource address
// Followed by add operation for new resource address
String type = Operations.getAttributeValue(operation).asString();
PathAddress address = context.getCurrentAddress();
PathAddress newAddress = address.getParent().append(PathElement.pathElement(address.getLastElement().getKey(), type));

ModelNode addOperation = Util.createAddOperation(newAddress);
for (Property property : context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel().asPropertyList()) {
addOperation.get(property.getName()).set(property.getValue());
}
context.addStep(addOperation, context.getRootResourceRegistration().getOperationHandler(newAddress, ModelDescriptionConstants.ADD), context.getCurrentStage(), true);

ModelNode removeOperation = Util.createRemoveOperation(address);
context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, ModelDescriptionConstants.REMOVE), context.getCurrentStage(), true);
}
};
registration.registerReadWriteAttribute(TYPE, typeReadHandler, typeWriteHandler);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Collections;
import java.util.List;

import org.jboss.as.clustering.controller.ReloadRequiredAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.ObjectListAttributeDefinition;
Expand All @@ -36,7 +35,6 @@
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
Expand All @@ -48,7 +46,6 @@
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property;

/**
* Resource description for the addressable resource /subsystem=jgroups/stack=X
Expand Down Expand Up @@ -143,44 +140,30 @@ protected void populateModel(OperationContext context, ModelNode operation, Reso

if (transport != null) {
String type = ProtocolResourceDefinition.TYPE.resolveModelAttribute(context, transport).asString();
PathAddress transportAddress = address.append(TransportResourceDefinition.pathElement(type));
PathElement transportPath = TransportResourceDefinition.pathElement(type);
PathAddress transportAddress = address.append(transportPath);
ModelNode transportOperation = Util.createAddOperation(transportAddress);
for (AttributeDefinition attribute : TransportResourceDefinition.ATTRIBUTES) {
String name = attribute.getName();
if (transport.hasDefined(name)) {
transportOperation.get(name).set(transport.get(name));
}
}
context.addStep(transportOperation, new ReloadRequiredAddStepHandler(TransportResourceDefinition.ATTRIBUTES), OperationContext.Stage.MODEL);

if (transport.hasDefined(ProtocolResourceDefinition.PROPERTIES.getName())) {
for (Property property : operation.get(ProtocolResourceDefinition.PROPERTIES.getName()).asPropertyList()) {
ModelNode propertyOperation = Util.createAddOperation(transportAddress.append(property.getName()));
propertyOperation.set(PropertyResourceDefinition.VALUE.getName()).set(property.getValue());
context.addStep(propertyOperation, new ReloadRequiredAddStepHandler(PropertyResourceDefinition.VALUE), OperationContext.Stage.MODEL);
}
}
context.addStep(transportOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(transportPath), ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL);
}
if (!protocols.isEmpty()) {
for (ModelNode protocol : protocols) {
String type = ProtocolResourceDefinition.TYPE.resolveModelAttribute(context, protocol).asString();
PathAddress protocolAddress = address.append(ProtocolResourceDefinition.pathElement(type));
PathElement protocolPath = ProtocolResourceDefinition.pathElement(type);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
for (AttributeDefinition attribute : ProtocolResourceDefinition.ATTRIBUTES) {
String name = attribute.getName();
if (protocol.hasDefined(name)) {
protocolOperation.get(name).set(protocol.get(name));
}
}
context.addStep(protocolOperation, new ReloadRequiredAddStepHandler(ProtocolResourceDefinition.ATTRIBUTES), OperationContext.Stage.MODEL);

if (protocol.hasDefined(ProtocolResourceDefinition.PROPERTIES.getName())) {
for (Property property : operation.get(ProtocolResourceDefinition.PROPERTIES.getName()).asPropertyList()) {
ModelNode propertyOperation = Util.createAddOperation(protocolAddress.append(property.getName()));
propertyOperation.set(PropertyResourceDefinition.VALUE.getName()).set(property.getValue());
context.addStep(propertyOperation, new ReloadRequiredAddStepHandler(PropertyResourceDefinition.VALUE), OperationContext.Stage.MODEL);
}
}
context.addStep(protocolOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL);
}
}
}
Expand All @@ -199,22 +182,16 @@ protected void populateModel(OperationContext context, ModelNode operation, Reso
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress();
String protocol = operation.require(ProtocolResourceDefinition.TYPE.getName()).asString();
PathAddress protocolAddress = address.append(ProtocolResourceDefinition.pathElement(protocol));
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
for (AttributeDefinition attribute : ProtocolResourceDefinition.ATTRIBUTES) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
protocolOperation.get(name).set(operation.get(name));
}
}
context.addStep(protocolOperation, new ReloadRequiredAddStepHandler(ProtocolResourceDefinition.ATTRIBUTES), OperationContext.Stage.MODEL);
if (operation.hasDefined(ProtocolResourceDefinition.PROPERTIES.getName())) {
for (Property property : operation.get(ProtocolResourceDefinition.PROPERTIES.getName()).asPropertyList()) {
ModelNode addPropertyOperation = Util.createAddOperation(protocolAddress.append(PropertyResourceDefinition.pathElement(property.getName())));
addPropertyOperation.get(PropertyResourceDefinition.VALUE.getName()).set(property.getValue());
context.addStep(addPropertyOperation, new ReloadRequiredAddStepHandler(PropertyResourceDefinition.VALUE), OperationContext.Stage.MODEL);
}
}
context.addStep(protocolOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL);
}
};
registration.registerOperationHandler(legacyAddProtocolOperation, legacyAddProtocolHandler);
Expand All @@ -229,9 +206,10 @@ public void execute(OperationContext context, ModelNode operation) {
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress();
String protocol = operation.require(ProtocolResourceDefinition.TYPE.getName()).asString();
PathAddress protocolAddress = address.append(ProtocolResourceDefinition.pathElement(protocol));
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode removeOperation = Util.createRemoveOperation(protocolAddress);
context.addStep(removeOperation, ReloadRequiredRemoveStepHandler.INSTANCE, context.getCurrentStage());
context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
}
};
registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

package org.jboss.as.clustering.jgroups.subsystem;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import org.jboss.as.clustering.controller.ReloadRequiredAddStepHandler;
import org.jboss.as.clustering.controller.transform.DefaultValueAttributeConverter;
import org.jboss.as.clustering.controller.transform.PathAddressTransformer;
Expand All @@ -37,11 +41,9 @@
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.AttributeAccess;
Expand All @@ -55,7 +57,7 @@
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
public class TransportResourceDefinition extends SimpleResourceDefinition {
public class TransportResourceDefinition extends ProtocolResourceDefinition {

static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);

Expand Down Expand Up @@ -127,11 +129,15 @@ static PathElement pathElement(String name) {
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.build();

// the list of attributes used by the transport resource
static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] {
ProtocolResourceDefinition.TYPE, ProtocolResourceDefinition.MODULE, SHARED, ProtocolResourceDefinition.SOCKET_BINDING, DIAGNOSTICS_SOCKET_BINDING,
ProtocolResourceDefinition.PROPERTIES, DEFAULT_EXECUTOR, OOB_EXECUTOR, TIMER_EXECUTOR, THREAD_FACTORY, SITE, RACK, MACHINE
static final AttributeDefinition[] TRANSPORT_ATTRIBUTES = new AttributeDefinition[] {
SHARED, DIAGNOSTICS_SOCKET_BINDING, DEFAULT_EXECUTOR, OOB_EXECUTOR, TIMER_EXECUTOR, THREAD_FACTORY, SITE, RACK, MACHINE
};
// the list of attributes used by the transport resource
static final Collection<AttributeDefinition> ATTRIBUTES = new ArrayList<>(TRANSPORT_ATTRIBUTES.length + ProtocolResourceDefinition.ATTRIBUTES.length);
static {
Collections.addAll(ATTRIBUTES, TRANSPORT_ATTRIBUTES);
Collections.addAll(ATTRIBUTES, ProtocolResourceDefinition.ATTRIBUTES);
}

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
Expand Down Expand Up @@ -169,13 +175,15 @@ public PathAddress transform(PathAddress address) {
};

TransportResourceDefinition() {
super(WILDCARD_PATH, new JGroupsResourceDescriptionResolver(ModelKeys.TRANSPORT), new ReloadRequiredAddStepHandler(ATTRIBUTES), ReloadRequiredRemoveStepHandler.INSTANCE);
super(WILDCARD_PATH, new ReloadRequiredAddStepHandler(ATTRIBUTES));
}

@Override
public void registerAttributes(ManagementResourceRegistration registration) {
final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
for (AttributeDefinition attr : ATTRIBUTES) {
super.registerAttributes(registration);

OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(TRANSPORT_ATTRIBUTES);
for (AttributeDefinition attr : TRANSPORT_ATTRIBUTES) {
if (attr.isDeprecated()) {
registration.registerReadWriteAttribute(attr, null, new ThreadsAttributesWriteHandler(attr));
} else {
Expand All @@ -186,7 +194,7 @@ public void registerAttributes(ManagementResourceRegistration registration) {

@Override
public void registerChildren(ManagementResourceRegistration registration) {
registration.registerSubModel(new PropertyResourceDefinition());
super.registerChildren(registration);

for (ThreadPoolResourceDefinition pool : ThreadPoolResourceDefinition.values()) {
registration.registerSubModel(pool);
Expand Down

0 comments on commit 597d175

Please sign in to comment.