Search in sources :

Example 1 with OperationTransformer

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();
}
Also used : OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker)

Example 2 with OperationTransformer

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);
}
Also used : OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) LinkedList(java.util.LinkedList)

Example 3 with OperationTransformer

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);
}
Also used : OperationTransformer(org.jboss.as.controller.transform.OperationTransformer)

Example 4 with OperationTransformer

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));
    }
}
Also used : SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationTransformer (org.jboss.as.controller.transform.OperationTransformer)4 PathAddress (org.jboss.as.controller.PathAddress)3 ModelNode (org.jboss.dmr.ModelNode)3 LinkedList (java.util.LinkedList)2 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)2 ArrayList (java.util.ArrayList)1 ChainedOperationTransformer (org.jboss.as.clustering.controller.transform.ChainedOperationTransformer)1 LegacyPropertyAddOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer)1 LegacyPropertyMapGetOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer)1 LegacyPropertyResourceTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer)1 LegacyPropertyWriteOperationTransformer (org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)1 SimpleDescribeOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer)1 SimpleOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleOperationTransformer)1 SimplePathOperationTransformer (org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer)1 SimpleReadAttributeOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer)1 SimpleRemoveOperationTransformer (org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 Resource (org.jboss.as.controller.registry.Resource)1 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)1 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)1