use of org.jboss.as.controller.transform.OperationTransformer in project wildfly by wildfly.
the class JcaDistributedWorkManagerDefinition method registerTransformers300.
static void registerTransformers300(ResourceTransformationDescriptionBuilder parentBuilder) {
ResourceTransformationDescriptionBuilder builder = parentBuilder.addChildResource(PATH_DISTRIBUTED_WORK_MANAGER);
builder.addOperationTransformationOverride("add").inheritResourceAttributeDefinitions().setCustomOperationTransformer(new OperationTransformer() {
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
ModelNode copy = operation.clone();
copy.add("transport-jgroups-cluster").set(address.getLastElement().toString());
return new TransformedOperation(copy, TransformedOperation.ORIGINAL_RESULT);
}
}).end().getAttributeBuilder().setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(false, true, new ModelNode(false)), DWmParameters.ELYTRON_ENABLED.getAttribute()).addRejectCheck(RejectAttributeChecker.DEFINED, DWmParameters.ELYTRON_ENABLED.getAttribute()).end();
}
use of org.jboss.as.controller.transform.OperationTransformer in project wildfly by wildfly.
the class ChainedOperationTransformer method transformOperation.
/**
* {@inheritDoc}
*/
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode originalOperation) throws OperationFailedException {
String originalName = Operations.getName(originalOperation);
PathAddress originalAddress = Operations.getPathAddress(originalOperation);
Deque<ModelNode> preSteps = new LinkedList<>();
Deque<ModelNode> postSteps = new LinkedList<>();
ModelNode operation = originalOperation;
for (OperationTransformer transformer : this.transformers) {
operation = transformer.transformOperation(context, address, operation).getTransformedOperation();
// If the transformed operation is a composite operation, locate the modified operation and record any pre/post operations
if (this.collate && operation.get(ModelDescriptionConstants.OP).asString().equals(ModelDescriptionConstants.COMPOSITE)) {
List<ModelNode> stepList = operation.get(ModelDescriptionConstants.STEPS).asList();
ListIterator<ModelNode> steps = stepList.listIterator();
while (steps.hasNext()) {
ModelNode step = steps.next();
String operationName = Operations.getName(step);
PathAddress operationAddress = Operations.getPathAddress(step);
if (operationName.equals(originalName) && operationAddress.equals(originalAddress)) {
operation = step;
break;
}
preSteps.addLast(step);
}
steps = stepList.listIterator(stepList.size());
while (steps.hasPrevious()) {
ModelNode step = steps.previous();
String operationName = Operations.getName(step);
PathAddress operationAddress = Operations.getPathAddress(step);
if (operationName.equals(originalName) && operationAddress.equals(originalAddress)) {
break;
}
postSteps.addFirst(step);
}
}
}
if (this.collate) {
int count = preSteps.size() + postSteps.size() + 1;
// If there are any pre or post steps, we need a composite operation
if (count > 1) {
List<ModelNode> steps = new ArrayList<>(count);
steps.addAll(preSteps);
steps.add(operation);
steps.addAll(postSteps);
operation = Operations.createCompositeOperation(steps);
}
}
return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
use of org.jboss.as.controller.transform.OperationTransformer in project wildfly by wildfly.
the class AttributeOperationTransformer method transformOperation.
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
String name = Operations.getName(operation);
OperationTransformer transformer = this.transformers.get(name);
return (transformer != null) ? transformer.transformOperation(context, address, operation) : new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
}
use of org.jboss.as.controller.transform.OperationTransformer in project wildfly by wildfly.
the class TransportResourceDefinition method buildTransformation.
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
AbstractProtocolResourceDefinition.addTransformations(version, builder);
if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.SHARED.getDefinition()), Attribute.SHARED.getDefinition());
builder.setCustomResourceTransformer(new ResourceTransformer() {
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
new LegacyPropertyResourceTransformer().transformResource(context, LEGACY_ADDRESS_TRANSFORMER.transform(address), resource);
}
});
builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new org.jboss.as.clustering.controller.transform.OperationTransformer() {
@Override
public ModelNode transformOperation(final ModelNode operation) {
operation.get(ModelDescriptionConstants.OP_ADDR).set(LEGACY_ADDRESS_TRANSFORMER.transform(Operations.getPathAddress(operation)).toModelNode());
return new LegacyPropertyAddOperationTransformer().transformOperation(operation);
}
})).inheritResourceAttributeDefinitions();
builder.addOperationTransformationOverride(ModelDescriptionConstants.REMOVE).setCustomOperationTransformer(new SimpleRemoveOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
builder.addOperationTransformationOverride(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION).setCustomOperationTransformer(new SimpleReadAttributeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
builder.addOperationTransformationOverride(ModelDescriptionConstants.DESCRIBE).setCustomOperationTransformer(new SimpleDescribeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
List<OperationTransformer> getOpTransformerChain = new LinkedList<>();
getOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
getOpTransformerChain.add(new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
ChainedOperationTransformer getOpChainedTransformer = new ChainedOperationTransformer(getOpTransformerChain, false);
builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), getOpChainedTransformer);
List<OperationTransformer> writeOpTransformerChain = new LinkedList<>();
writeOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
writeOpTransformerChain.add(new LegacyPropertyWriteOperationTransformer());
ChainedOperationTransformer writeOpChainedTransformer = new ChainedOperationTransformer(writeOpTransformerChain, false);
for (String opName : Operations.getAllWriteAttributeOperationNames()) {
builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(writeOpChainedTransformer);
}
// Reject thread pool configuration, discard if undefined, support EAP 6.x slaves using deprecated attributes
builder.addChildResource(ThreadPoolResourceDefinition.WILDCARD_PATH, RequiredChildResourceDiscardPolicy.REJECT_AND_WARN);
} else {
EnumSet.allOf(ThreadPoolResourceDefinition.class).forEach(p -> p.buildTransformation(version, parent));
}
}
Aggregations