Search in sources :

Example 1 with OperationEntry

use of org.jboss.as.controller.registry.OperationEntry in project wildfly by wildfly.

the class WebMigrateOperation method addExtension.

/**
     * It's possible that the extension is already present. In that case, this method does nothing.
     */
private void addExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe, String extension) {
    Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
    if (root.getChildrenNames(EXTENSION).contains(extension)) {
        // extension is already added, do nothing
        return;
    }
    PathAddress extensionAddress = pathAddress(EXTENSION, extension);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    ModelNode addOperation = createAddOperation(extensionAddress);
    addOperation.get(MODULE).set(extension);
    if (describe) {
        migrationOperations.put(extensionAddress, addOperation);
    } else {
        context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with OperationEntry

use of org.jboss.as.controller.registry.OperationEntry in project wildfly by wildfly.

the class MigrateOperation method addMessagingActiveMQExtension.

/**
     * It's possible that the extension is already present. In that case, this method does nothing.
     */
private void addMessagingActiveMQExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe) {
    Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
    if (root.getChildrenNames(EXTENSION).contains(MESSAGING_ACTIVEMQ_EXTENSION)) {
        // extension is already added, do nothing
        return;
    }
    PathAddress extensionAddress = pathAddress(EXTENSION, MESSAGING_ACTIVEMQ_EXTENSION);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    ModelNode addOperation = createAddOperation(extensionAddress);
    addOperation.get(MODULE).set(MESSAGING_ACTIVEMQ_MODULE);
    if (describe) {
        migrationOperations.put(extensionAddress, addOperation);
    } else {
        context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with OperationEntry

use of org.jboss.as.controller.registry.OperationEntry in project wildfly by wildfly.

the class StackResourceDefinition method register.

@SuppressWarnings("deprecation")
@Override
public void register(ManagementResourceRegistration parentRegistration) {
    ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addExtraParameters(TRANSPORT, PROTOCOLS).addCapabilities(Capability.class).addOperationTranslator(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            if (operation.hasDefined(TRANSPORT.getName())) {
                PathAddress address = context.getCurrentAddress();
                ModelNode transport = operation.get(TRANSPORT.getName());
                String type = AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.resolveModelAttribute(context, transport).asString();
                PathElement transportPath = TransportResourceDefinition.pathElement(type);
                PathAddress transportAddress = address.append(transportPath);
                ModelNode transportOperation = Util.createAddOperation(transportAddress);
                OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(TransportResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
                for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                    String name = attribute.getName();
                    if (transport.hasDefined(name)) {
                        transportOperation.get(name).set(transport.get(name));
                    }
                }
                context.addStep(transportOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
            }
        }
    }).addOperationTranslator(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            if (operation.hasDefined(PROTOCOLS.getName())) {
                PathAddress address = context.getCurrentAddress();
                for (ModelNode protocol : operation.get(PROTOCOLS.getName()).asList()) {
                    String type = AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.resolveModelAttribute(context, protocol).asString();
                    PathElement protocolPath = ProtocolResourceDefinition.pathElement(type);
                    PathAddress protocolAddress = address.append(protocolPath);
                    ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
                    OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
                    for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                        String name = attribute.getName();
                        if (protocol.hasDefined(name)) {
                            protocolOperation.get(name).set(protocol.get(name));
                        }
                    }
                    context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
                }
            }
        }
    });
    ResourceServiceHandler handler = new StackServiceHandler(this.builderFactory);
    new SimpleResourceRegistration(descriptor, handler).register(registration);
    OperationDefinition legacyAddProtocolOperation = new SimpleOperationDefinitionBuilder("add-protocol", this.getResourceDescriptionResolver()).setParameters(SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING.getDefinition()).addParameter(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).addParameter(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
    // Transform legacy /subsystem=jgroups/stack=*:add-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:add()
    OperationStepHandler legacyAddProtocolHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress();
            String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
            PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
            PathAddress protocolAddress = address.append(protocolPath);
            ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
            OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
            for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                String name = attribute.getName();
                if (operation.hasDefined(name)) {
                    protocolOperation.get(name).set(operation.get(name));
                }
            }
            context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
        }
    };
    registration.registerOperationHandler(legacyAddProtocolOperation, legacyAddProtocolHandler);
    OperationDefinition legacyRemoveProtocolOperation = new SimpleOperationDefinitionBuilder("remove-protocol", this.getResourceDescriptionResolver()).setParameters(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
    // Transform legacy /subsystem=jgroups/stack=*:remove-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:remove()
    OperationStepHandler legacyRemoveProtocolHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress();
            String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
            PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
            PathAddress protocolAddress = address.append(protocolPath);
            ModelNode removeOperation = Util.createRemoveOperation(protocolAddress);
            context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
    if (this.allowRuntimeOnlyRegistration) {
        new OperationHandler<>(new StackOperationExecutor(), StackOperation.class).register(registration);
    }
    new TransportRegistration(this.builderFactory).register(registration);
    new ProtocolRegistration(this.builderFactory).register(registration);
    new RelayResourceDefinition(this.builderFactory).register(registration);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationEntry(org.jboss.as.controller.registry.OperationEntry) OperationFailedException(org.jboss.as.controller.OperationFailedException) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ObjectListAttributeDefinition(org.jboss.as.controller.ObjectListAttributeDefinition) ObjectTypeAttributeDefinition(org.jboss.as.controller.ObjectTypeAttributeDefinition) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) OperationDefinition(org.jboss.as.controller.OperationDefinition) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 4 with OperationEntry

use of org.jboss.as.controller.registry.OperationEntry in project wildfly by wildfly.

the class MigrateOperation method addOpenjdkExtension.

private void addOpenjdkExtension(final OperationContext context, final Map<PathAddress, ModelNode> migrateOperations) {
    final PathAddress extensionAddress = PathAddress.EMPTY_ADDRESS.append(OPENJDK_EXTENSION_ELEMENT);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    final ModelNode addOperation = Util.createAddOperation(extensionAddress);
    if (describe) {
        migrateOperations.put(extensionAddress, addOperation);
    } else {
        context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)4 OperationEntry (org.jboss.as.controller.registry.OperationEntry)4 ModelNode (org.jboss.dmr.ModelNode)4 Resource (org.jboss.as.controller.registry.Resource)2 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)1 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)1 SimpleResourceRegistration (org.jboss.as.clustering.controller.SimpleResourceRegistration)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 ObjectListAttributeDefinition (org.jboss.as.controller.ObjectListAttributeDefinition)1 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationDefinition (org.jboss.as.controller.OperationDefinition)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)1 PathElement (org.jboss.as.controller.PathElement)1 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)1 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)1