Skip to content

Commit

Permalink
Revert "WFLY-4654 JGroups transport type can't be set"
Browse files Browse the repository at this point in the history
  • Loading branch information
n1hility committed Jun 12, 2015
1 parent 597d175 commit d4c5494
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 103 deletions.
Expand Up @@ -22,8 +22,6 @@

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 @@ -39,13 +37,9 @@
public class SimpleAddOperationTransformer implements org.jboss.as.controller.transform.OperationTransformer {

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

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

public SimpleAddOperationTransformer(final PathAddressTransformer transformer, Iterable<AttributeDefinition> attributes) {
public SimpleAddOperationTransformer(final PathAddressTransformer transformer, AttributeDefinition... attributes) {
this.transformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
Expand All @@ -56,10 +50,6 @@ 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
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
Expand Up @@ -31,8 +31,6 @@
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 @@ -55,7 +53,6 @@
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 @@ -75,6 +72,7 @@ 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 @@ -99,7 +97,7 @@ static PathElement pathElement(String name) {
.setDefaultValue(new ModelNode().setEmptyList())
.build();

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

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

ProtocolResourceDefinition(OperationStepHandler addHandler) {
this(WILDCARD_PATH, addHandler);
}

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

@Override
Expand All @@ -219,33 +213,6 @@ 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
Expand Up @@ -25,6 +25,7 @@
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 @@ -35,6 +36,7 @@
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 @@ -46,6 +48,7 @@
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 @@ -140,30 +143,44 @@ protected void populateModel(OperationContext context, ModelNode operation, Reso

if (transport != null) {
String type = ProtocolResourceDefinition.TYPE.resolveModelAttribute(context, transport).asString();
PathElement transportPath = TransportResourceDefinition.pathElement(type);
PathAddress transportAddress = address.append(transportPath);
PathAddress transportAddress = address.append(TransportResourceDefinition.pathElement(type));
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, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(transportPath), ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL);
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);
}
}
}
if (!protocols.isEmpty()) {
for (ModelNode protocol : protocols) {
String type = ProtocolResourceDefinition.TYPE.resolveModelAttribute(context, protocol).asString();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(type);
PathAddress protocolAddress = address.append(protocolPath);
PathAddress protocolAddress = address.append(ProtocolResourceDefinition.pathElement(type));
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, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL);
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);
}
}
}
}
}
Expand All @@ -182,16 +199,22 @@ 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();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
PathAddress protocolAddress = address.append(ProtocolResourceDefinition.pathElement(protocol));
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, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL);
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);
}
}
}
};
registration.registerOperationHandler(legacyAddProtocolOperation, legacyAddProtocolHandler);
Expand All @@ -206,10 +229,9 @@ 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();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
PathAddress protocolAddress = address.append(ProtocolResourceDefinition.pathElement(protocol));
ModelNode removeOperation = Util.createRemoveOperation(protocolAddress);
context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
context.addStep(removeOperation, ReloadRequiredRemoveStepHandler.INSTANCE, context.getCurrentStage());
}
};
registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
Expand Down
Expand Up @@ -22,10 +22,6 @@

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 @@ -41,9 +37,11 @@
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 @@ -57,7 +55,7 @@
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
public class TransportResourceDefinition extends ProtocolResourceDefinition {
public class TransportResourceDefinition extends SimpleResourceDefinition {

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

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

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 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 void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
Expand Down Expand Up @@ -175,15 +169,13 @@ public PathAddress transform(PathAddress address) {
};

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

@Override
public void registerAttributes(ManagementResourceRegistration registration) {
super.registerAttributes(registration);

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

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

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

0 comments on commit d4c5494

Please sign in to comment.