Search in sources :

Example 56 with OperationStepHandler

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

the class ServerAdd method populateModel.

@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    super.populateModel(context, operation, resource);
    if (SECURITY_ENABLED.resolveModelAttribute(context, operation).asBoolean()) {
        context.addStep(SecurityDomainCheckHandler.INSTANCE, OperationContext.Stage.MODEL);
    }
    handleCredentialReferenceUpdate(context, resource.getModel().get(CREDENTIAL_REFERENCE.getName()), CREDENTIAL_REFERENCE.getName());
    // add an operation to create all the messaging paths resources that have not been already been created
    // prior to adding the ActiveMQ server
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final ModelNode model = Resource.Tools.readModel(resource);
            for (String path : PathDefinition.PATHS.keySet()) {
                if (!model.get(ModelDescriptionConstants.PATH).hasDefined(path)) {
                    PathAddress pathAddress = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.PATH, path));
                    context.createResource(pathAddress);
                }
            }
        }
    }, OperationContext.Stage.MODEL);
    context.addStep((operationContext, model) -> {
        // check that if journal-datasource is defined, no other attributes related to file-system journal are set.
        if (ServerDefinition.JOURNAL_DATASOURCE.resolveModelAttribute(context, model).isDefined()) {
            checkNoAttributesIsDefined(ServerDefinition.JOURNAL_DATASOURCE.getName(), operationContext.getCurrentAddress(), model, ServerDefinition.JOURNAL_TYPE, ServerDefinition.JOURNAL_BUFFER_TIMEOUT, ServerDefinition.JOURNAL_BUFFER_SIZE, ServerDefinition.JOURNAL_SYNC_TRANSACTIONAL, ServerDefinition.JOURNAL_SYNC_NON_TRANSACTIONAL, ServerDefinition.LOG_JOURNAL_WRITE_RATE, ServerDefinition.JOURNAL_FILE_SIZE, ServerDefinition.JOURNAL_MIN_FILES, ServerDefinition.JOURNAL_POOL_FILES, ServerDefinition.JOURNAL_FILE_OPEN_TIMEOUT, ServerDefinition.JOURNAL_COMPACT_PERCENTAGE, ServerDefinition.JOURNAL_COMPACT_MIN_FILES, ServerDefinition.JOURNAL_MAX_IO, ServerDefinition.CREATE_BINDINGS_DIR, ServerDefinition.CREATE_JOURNAL_DIR);
        }
    }, OperationContext.Stage.MODEL);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ModelNode(org.jboss.dmr.ModelNode)

Example 57 with OperationStepHandler

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

the class ManagementHelper method checkNoOtherSibling.

static OperationStepHandler checkNoOtherSibling(final String childType) {
    return new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            PathAddress parentAddress = context.getCurrentAddress().getParent();
            Resource parent = context.readResourceFromRoot(parentAddress, false);
            Set<String> children = parent.getChildrenNames(childType);
            if (children.size() > 1) {
                throw MessagingLogger.ROOT_LOGGER.onlyOneChildIsAllowed(childType, children);
            }
        }
    };
}
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) ModelNode(org.jboss.dmr.ModelNode)

Example 58 with OperationStepHandler

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

the class AbstractUpdateJndiHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    JNDI_BINDING.validateOperation(operation);
    final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
    final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
    if (addOperation) {
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
            }
        }
        entries.add(jndiName);
    } else {
        ModelNode updatedEntries = new ModelNode();
        boolean updated = false;
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                if (entries.asList().size() == 1) {
                    throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
                }
                updated = true;
            } else {
                updatedEntries.add(entry);
            }
        }
        if (!updated) {
            throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
        }
        context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
    }
    if (context.isNormalServer()) {
        if (rollbackOperationIfServerNotActive(context, operation)) {
            return;
        }
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
                final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
                final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
                final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
                if (jmsServerService != null) {
                    JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                    if (jmsServerManager == null) {
                        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
                        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
                    }
                    try {
                        if (addOperation) {
                            addJndiName(jmsServerManager, resourceName, jndiName);
                        } else {
                            removeJndiName(jmsServerManager, resourceName, jndiName);
                        }
                    } catch (Exception e) {
                        context.getFailureDescription().set(e.getLocalizedMessage());
                    }
                }
                if (!context.hasFailureDescription()) {
                    context.getResult();
                }
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                        if (jmsServerService != null) {
                            JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                            try {
                                if (addOperation) {
                                    removeJndiName(jmsServerManager, resourceName, jndiName);
                                } else {
                                    addJndiName(jmsServerManager, resourceName, jndiName);
                                }
                            } catch (Exception e) {
                                context.getFailureDescription().set(e.getLocalizedMessage());
                            }
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 59 with OperationStepHandler

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

the class TranslatedOperationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress targetAddress = converter.convert(context, operation);
    ModelNode op = operation.clone();
    op.get(OP_ADDR).set(targetAddress.toModelNode());
    String operationName = op.require(OP).asString();
    OperationStepHandler operationHandler = context.getRootResourceRegistration().getOperationHandler(targetAddress, operationName);
    context.addStep(op, operationHandler, context.getCurrentStage(), true);
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 60 with OperationStepHandler

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

the class MetricsSubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    super.performBoottime(context, operation, model);
    List<String> exposedSubsystems = MetricsSubsystemDefinition.EXPOSED_SUBSYSTEMS.unwrap(context, model);
    boolean exposeAnySubsystem = exposedSubsystems.remove("*");
    String prefix = MetricsSubsystemDefinition.PREFIX.resolveModelAttribute(context, model).asStringOrNull();
    boolean securityEnabled = MetricsSubsystemDefinition.SECURITY_ENABLED.resolveModelAttribute(context, model).asBoolean();
    WildFlyMetricRegistryService.install(context);
    MetricsCollectorService.install(context);
    MetricsContextService.install(context, securityEnabled);
    // handles that instead.
    if (!context.getCapabilityServiceSupport().hasCapability(MetricsSubsystemDefinition.METRICS_SCAN_CAPABILITY)) {
        context.addStep(new AbstractDeploymentChainStep() {

            public void execute(DeploymentProcessorTarget processorTarget) {
                processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, INSTALL, POST_MODULE_METRICS, new DeploymentMetricProcessor(exposeAnySubsystem, exposedSubsystems, prefix));
            }
        }, RUNTIME);
        // delay the registration of the metrics in the VERIFY stage so that all resources
        // created during the RUNTIME phase will have been registered in the MRR.
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext operationContext, ModelNode modelNode) {
                ServiceController<?> serviceController = context.getServiceRegistry(false).getService(WILDFLY_COLLECTOR);
                MetricCollector metricCollector = MetricCollector.class.cast(serviceController.getValue());
                ServiceController<?> wildflyRegistryController = context.getServiceRegistry(false).getService(METRICS_REGISTRY_RUNTIME_CAPABILITY.getCapabilityServiceName());
                WildFlyMetricRegistry metricRegistry = WildFlyMetricRegistry.class.cast(wildflyRegistryController.getValue());
                ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
                Resource rootResource = context.readResourceFromRoot(EMPTY_ADDRESS);
                MetricRegistration registration = new MetricRegistration(metricRegistry);
                metricCollector.collectResourceMetrics(rootResource, rootResourceRegistration, Function.identity(), exposeAnySubsystem, exposedSubsystems, prefix, registration);
            }
        }, VERIFY);
    }
    LOGGER.activatingSubsystem();
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) DeploymentMetricProcessor(org.wildfly.extension.metrics.deployment.DeploymentMetricProcessor) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) ServiceController(org.jboss.msc.service.ServiceController) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode)

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