Search in sources :

Example 71 with OperationStepHandler

use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.

the class RaRemove method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final ModelNode opAddr = operation.require(OP_ADDR);
    final String idName = PathAddress.pathAddress(opAddr).getLastElement().getValue();
    final boolean isModule;
    // Compensating is add
    final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
    final String archiveOrModuleName;
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        isModule = false;
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        isModule = true;
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr);
    if (model.hasDefined(RESOURCEADAPTERS_NAME)) {
        for (ModelNode raNode : model.get(RESOURCEADAPTERS_NAME).asList()) {
            ModelNode raCompensatingNode = raNode.clone();
            compensating.get(RESOURCEADAPTERS_NAME).add(raCompensatingNode);
        }
    }
    context.removeResource(PathAddress.EMPTY_ADDRESS);
    context.deregisterCapability(Capabilities.RESOURCE_ADAPTER_CAPABILITY.getDynamicName(context.getCurrentAddress()));
    if (context.isDefaultRequiresRuntime()) {
        context.addStep(new OperationStepHandler() {

            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final boolean wasActive;
                wasActive = RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName);
                if (wasActive && !context.isResourceServiceRestartAllowed()) {
                    context.reloadRequired();
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            context.revertReloadRequired();
                        }
                    });
                    return;
                }
                ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, idName);
                ServiceController<?> serviceController = context.getServiceRegistry(false).getService(raServiceName);
                final ModifiableResourceAdapter resourceAdapter;
                if (serviceController != null) {
                    resourceAdapter = (ModifiableResourceAdapter) serviceController.getValue();
                } else {
                    resourceAdapter = null;
                }
                final List<ServiceName> serviceNameList = context.getServiceRegistry(false).getServiceNames();
                for (ServiceName name : serviceNameList) {
                    if (raServiceName.isParentOf(name)) {
                        context.removeService(name);
                    }
                }
                if (model.get(MODULE.getName()).isDefined()) {
                    // ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(model.get(MODULE.getName()).asString(),raId);
                    // context.removeService(deploymentServiceName);
                    ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(idName);
                    context.removeService(deployerServiceName);
                    ServiceName inactiveServiceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(idName);
                    context.removeService(inactiveServiceName);
                }
                context.removeService(raServiceName);
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                        if (resourceAdapter != null) {
                            List<ServiceController<?>> newControllers = new LinkedList<ServiceController<?>>();
                            if (model.get(ARCHIVE.getName()).isDefined()) {
                                RaOperationUtil.installRaServices(context, idName, resourceAdapter, newControllers);
                            } else {
                                try {
                                    RaOperationUtil.installRaServicesAndDeployFromModule(context, idName, resourceAdapter, archiveOrModuleName, newControllers);
                                } catch (OperationFailedException e) {
                                }
                            }
                            try {
                                if (wasActive) {
                                    RaOperationUtil.activate(context, idName, archiveOrModuleName);
                                }
                            } catch (OperationFailedException e) {
                            }
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedList(java.util.LinkedList) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) LinkedList(java.util.LinkedList) ModelNode(org.jboss.dmr.ModelNode)

Example 72 with OperationStepHandler

use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.

the class SSLResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addExtraParameters(Attribute.class);
    for (Attribute attribute : Attribute.values()) {
        registration.registerReadWriteAttribute(attribute.getDefinition(), null, new ReloadRequiredWriteAttributeHandler() {

            @Override
            protected void validateUpdatedModel(OperationContext context, Resource model) {
                context.addStep(new OperationStepHandler() {

                    @Override
                    public void execute(OperationContext ctx, ModelNode op) throws OperationFailedException {
                        final ModelNode conf = ctx.readResourceFromRoot(ctx.getCurrentAddress().getParent(), false).getModel();
                        if (conf.hasDefined(ProxyConfigurationResourceDefinition.Attribute.SSL_CONTEXT.getName())) {
                            throw new OperationFailedException(ROOT_LOGGER.bothElytronAndLegacySslContextDefined());
                        }
                    }
                }, OperationContext.Stage.MODEL);
            }
        });
    }
    new ReloadRequiredResourceRegistration(descriptor).register(registration);
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ReloadRequiredResourceRegistration(org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 73 with OperationStepHandler

use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.

the class LegacyMetricOperationsRegistration method register.

public void register(ManagementResourceRegistration registration) {
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-metric(type=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:add(...)
    OperationDefinition legacyAddMetricOperation = new SimpleOperationDefinitionBuilder("add-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyAddMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
            OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
            for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                String name = attribute.getName();
                if (operation.hasDefined(name)) {
                    metricOperation.get(name).set(operation.get(name));
                }
            }
            context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyAddMetricOperation, legacyAddMetricHandler);
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-metric(type=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:remove()
    OperationDefinition legacyRemoveMetricOperation = new SimpleOperationDefinitionBuilder("remove-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyRemoveMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
            OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
            context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyRemoveMetricOperation, legacyRemoveMetricHandler);
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-custom-metric(class=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:add(...)
    OperationDefinition legacyAddCustomMetricOperation = new SimpleOperationDefinitionBuilder("add-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyAddCustomMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
            OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
            for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                String name = attribute.getName();
                if (operation.hasDefined(name)) {
                    metricOperation.get(name).set(operation.get(name));
                }
            }
            context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyAddCustomMetricOperation, legacyAddCustomMetricHandler);
    // Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-custom-metric(class=...) operation
    // -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:remove()
    OperationDefinition legacyRemoveCustomMetricOperation = new SimpleOperationDefinitionBuilder("remove-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
    OperationStepHandler legacyRemoveCustomMetricHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            operationDeprecated(context, operation);
            PathAddress address = translateProxyPath(context);
            String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
            PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
            PathAddress metricPathAddress = address.append(metricPath);
            ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
            OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
            context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
        }
    };
    registration.registerOperationHandler(legacyRemoveCustomMetricOperation, legacyRemoveCustomMetricHandler);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) OperationDefinition(org.jboss.as.controller.OperationDefinition)

Example 74 with OperationStepHandler

use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.

the class NamingBindingResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(SimpleAttributeDefinitionBuilder.create(BINDING_TYPE).setValidator(new EnumValidator<>(BindingType.class, EnumSet.complementOf(EnumSet.of(BindingType.EXTERNAL_CONTEXT)))).build()).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
    resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
                    ModelNode model = resource.getModel();
                    for (AttributeDefinition attr : ATTRIBUTES) {
                        attr.validateAndSet(operation, model);
                    }
                    context.addStep(NamingBindingResourceDefinition.VALIDATE_RESOURCE_MODEL_OPERATION_STEP_HANDLER, OperationContext.Stage.MODEL);
                    context.addStep(new OperationStepHandler() {

                        @Override
                        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                            final String name = context.getCurrentAddressValue();
                            final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
                            ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
                            if (service == null) {
                                context.reloadRequired();
                                return;
                            }
                            NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
                        }
                    }, OperationContext.Stage.RUNTIME);
                }
            }, OperationContext.Stage.MODEL);
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) BinderService(org.jboss.as.naming.service.BinderService) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 75 with OperationStepHandler

use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.

the class LoginModuleResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    OperationStepHandler writeHandler = new ModelOnlyWriteAttributeHandler(ATTRIBUTES);
    for (AttributeDefinition attribute : ATTRIBUTES) {
        resourceRegistration.registerReadWriteAttribute(attribute, null, writeHandler);
    }
}
Also used : ModelOnlyWriteAttributeHandler(org.jboss.as.controller.ModelOnlyWriteAttributeHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Aggregations

OperationStepHandler (org.jboss.as.controller.OperationStepHandler)76 ModelNode (org.jboss.dmr.ModelNode)57 OperationContext (org.jboss.as.controller.OperationContext)45 OperationFailedException (org.jboss.as.controller.OperationFailedException)40 PathAddress (org.jboss.as.controller.PathAddress)31 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)23 Resource (org.jboss.as.controller.registry.Resource)19 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)17 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 PathElement (org.jboss.as.controller.PathElement)9 ServiceController (org.jboss.msc.service.ServiceController)8 ServiceName (org.jboss.msc.service.ServiceName)8 Map (java.util.Map)7 ImmutableManagementResourceRegistration (org.jboss.as.controller.registry.ImmutableManagementResourceRegistration)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)5 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ManagementResourceRegistration (org.jboss.as.clustering.controller.ManagementResourceRegistration)4