Search in sources :

Example 11 with OperationContext

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

the class IdentityConfigurationRemoveStepHandler method updateModel.

@Override
protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress partitionManagerAddress = getParentAddress(context.getCurrentAddress());
    Resource partitionManagerResource = context.readResourceFromRoot(partitionManagerAddress);
    checkIfLastConfiguration(partitionManagerResource);
    ModelNode originalParentModel = Resource.Tools.readModel(partitionManagerResource);
    super.updateModel(context, operation);
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            PartitionManagerRemoveHandler.INSTANCE.removeIdentityStoreServices(context, originalParentModel, partitionManagerAddress.getLastElement().getValue(), context.getCurrentAddressValue());
            context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 12 with OperationContext

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

the class StackResourceDefinition method register.

@SuppressWarnings("deprecation")
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(Attribute.class).addExtraParameters(TRANSPORT, PROTOCOLS).addCapabilities(Capability.class).setAddOperationTransformation(new AddOperationTransformation());
    ResourceServiceHandler handler = new StackServiceHandler(this.serviceConfiguratorFactory);
    new SimpleResourceRegistration(descriptor, handler).register(registration);
    OperationDefinition legacyAddProtocolOperation = new SimpleOperationDefinitionBuilder("add-protocol", this.getResourceDescriptionResolver()).setParameters(MulticastProtocolResourceDefinition.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) {
            operationDeprecated(context, 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(protocolPath), 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, true);
        }
    };
    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) {
            operationDeprecated(context, 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(protocolPath), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
    if (registration.isRuntimeOnlyRegistrationValid()) {
        new StackOperationHandler().register(registration);
    }
    new TransportRegistration(this.serviceConfiguratorFactory).register(registration);
    new ProtocolRegistration(this.serviceConfiguratorFactory).register(registration);
    new RelayResourceDefinition(this.serviceConfiguratorFactory).register(registration);
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) UnaryRequirementCapability(org.jboss.as.clustering.controller.UnaryRequirementCapability) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationEntry(org.jboss.as.controller.registry.OperationEntry) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ObjectListAttributeDefinition(org.jboss.as.controller.ObjectListAttributeDefinition) ObjectTypeAttributeDefinition(org.jboss.as.controller.ObjectTypeAttributeDefinition) ManagementResourceRegistration(org.jboss.as.clustering.controller.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 13 with OperationContext

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

the class PropertyResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    // Delegate add of property to "properties" attribute of parent protocol
    AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            operationDeprecated(context, operation);
            context.addResource(PathAddress.EMPTY_ADDRESS, PlaceholderResource.INSTANCE);
            String name = context.getCurrentAddressValue();
            String value = operation.get(VALUE.getName()).asString();
            PathAddress protocolAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapPutOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, this.getResourceDescriptionResolver()).addParameter(VALUE).withFlag(OperationEntry.Flag.RESTART_NONE).build(), LEGACY_PROTOCOL_OPERATION_TRANSFORMATION.apply(addHandler));
    // Delegate remove of property to "properties" attribute of parent protocol
    AbstractRemoveStepHandler removeHandler = new AbstractRemoveStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            operationDeprecated(context, operation);
            context.removeResource(PathAddress.EMPTY_ADDRESS);
            String name = context.getCurrentAddressValue();
            PathAddress protocolAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapRemoveOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name);
            context.addStep(putOperation, MapOperations.MAP_REMOVE_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.REMOVE, this.getResourceDescriptionResolver()).withFlag(OperationEntry.Flag.RESTART_RESOURCE_SERVICES).build(), LEGACY_PROTOCOL_OPERATION_TRANSFORMATION.apply(removeHandler));
    // Delegate read of property value to "properties" attribute of parent protocol
    OperationStepHandler readHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            operationDeprecated(context, operation);
            PathAddress protocolAddress = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            ModelNode getOperation = Operations.createMapGetOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key);
            context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
        }
    };
    // Delegate write of property value to "properties" attribute of parent protocol
    OperationStepHandler writeHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            operationDeprecated(context, operation);
            PathAddress protocolAddress = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            String value = Operations.getAttributeValue(operation).asString();
            ModelNode putOperation = Operations.createMapPutOperation(protocolAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerReadWriteAttribute(VALUE, LEGACY_PROTOCOL_OPERATION_TRANSFORMATION.apply(readHandler), LEGACY_PROTOCOL_OPERATION_TRANSFORMATION.apply(writeHandler));
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) AbstractRemoveStepHandler(org.jboss.as.controller.AbstractRemoveStepHandler)

Example 14 with OperationContext

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

the class TransportResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = super.register(parent);
    new WriteAttributeStepHandler(new WriteThreadingAttributeStepHandlerDescriptor()) {

        @Override
        protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException {
            // Add a new step to validate instead of doing it directly in this method.
            // This allows a composite op to change both attributes and then the
            // validation occurs after both have done their work.
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    ModelNode conf = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
                    // TODO doesn't cover the admin-only modes
                    if (context.getProcessType().isServer()) {
                        for (ThreadingAttribute attribute : EnumSet.allOf(ThreadingAttribute.class)) {
                            if (conf.hasDefined(attribute.getName())) {
                                // That is not supported.
                                throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.threadsAttributesUsedInRuntime());
                            }
                        }
                    }
                }
            }, OperationContext.Stage.MODEL);
        }
    }.register(registration);
    if (registration.getPathAddress().getLastElement().isWildcard()) {
        for (ThreadPoolResourceDefinition pool : EnumSet.allOf(ThreadPoolResourceDefinition.class)) {
            pool.register(registration);
        }
        parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {

            @Override
            public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
                PathAddress target = this.getTargetAddress();
                List<PathElement> result = new ArrayList<>(aliasAddress.size());
                for (int i = 0; i < aliasAddress.size(); ++i) {
                    PathElement element = aliasAddress.getElement(i);
                    if (i == target.size() - 1) {
                        final ModelNode operation = aliasContext.getOperation();
                        final String stackName;
                        if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) {
                            stackName = operation.get("type").asString();
                        } else {
                            Resource root = null;
                            try {
                                root = aliasContext.readResourceFromRoot(PathAddress.pathAddress(result));
                            } catch (Resource.NoSuchResourceException ignored) {
                            }
                            if (root == null) {
                                stackName = "*";
                            } else {
                                Set<String> names = root.getChildrenNames("transport");
                                if (names.size() > 1) {
                                    throw new AssertionError("There should be at most one child");
                                } else if (names.size() == 0) {
                                    stackName = "*";
                                } else {
                                    stackName = names.iterator().next();
                                }
                            }
                        }
                        result.add(PathElement.pathElement("transport", stackName));
                    } else if (i < target.size()) {
                        PathElement targetElement = target.getElement(i);
                        result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement);
                    } else {
                        result.add(element);
                    }
                }
                return PathAddress.pathAddress(result);
            }
        });
    }
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) EnumSet(java.util.EnumSet) Set(java.util.Set) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) WriteAttributeStepHandler(org.jboss.as.clustering.controller.WriteAttributeStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) List(java.util.List) AliasEntry(org.jboss.as.controller.registry.AliasEntry) ModelNode(org.jboss.dmr.ModelNode)

Example 15 with OperationContext

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

the class RaAdd method performRuntime.

@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    // TODO WFLY-15231 -- this logic is using the wrong attributes, so it's currently doing nothing
    if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    // do the same for recovery security attributes
    if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    // Compensating is remove
    final String name = context.getCurrentAddressValue();
    final String archiveOrModuleName;
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
        RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
        RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
        if (context.isBooting()) {
            context.addStep(new OperationStepHandler() {

                public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
                    // Next lines activate configuration on module deployed rar
                    // in case there is 2 different resource-adapter config using same module deployed rar
                    // a Deployment sercivice could be already present and need a restart to consider also this
                    // newly added configuration
                    ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                    if (restartedServiceName == null) {
                        RaOperationUtil.activate(context, name, archiveOrModuleName);
                    }
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            try {
                                RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                            } catch (OperationFailedException e) {
                            }
                        }
                    });
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
    ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, raStatsService.getBootstrapContextInjector()).addDependency(serviceName, Object.class, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peStats, statsResource);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ResourceAdapterStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ResourceAdapterStatisticsService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)67 ModelNode (org.jboss.dmr.ModelNode)66 OperationFailedException (org.jboss.as.controller.OperationFailedException)51 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)45 PathAddress (org.jboss.as.controller.PathAddress)25 Resource (org.jboss.as.controller.registry.Resource)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)15 ServiceController (org.jboss.msc.service.ServiceController)13 ServiceName (org.jboss.msc.service.ServiceName)12 ArrayList (java.util.ArrayList)8 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)8 List (java.util.List)7 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)7 Map (java.util.Map)6 Collection (java.util.Collection)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)5 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)5 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5