Search in sources :

Example 21 with OperationContext

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

the class CachedConnectionManagerRemove method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    // This is an odd case where we do not actually do a remove; we just reset state to
    // what it would be following parsing if the xml element does not exist.
    // See discussion on PR with fix for WFLY-2640 .
    ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();
    for (JcaCachedConnectionManagerDefinition.CcmParameters param : JcaCachedConnectionManagerDefinition.CcmParameters.values()) {
        AttributeDefinition ad = param.getAttribute();
        if (param == INSTALL || param == DEBUG || param == ERROR || param == IGNORE_UNKNOWN_CONNECTIONS) {
            model.get(ad.getName()).clear();
        } else {
            // Someone added a new param since wFLY-2640/WFLY-8141 and did not account for it above
            throw new IllegalStateException();
        }
    }
    // At the time of WFLY-2640 there were no capabilities associated with this resource,
    // but if anyone adds one, part of the task is to deal with deregistration.
    // So here's an assert to ensure that is considered
    Set<RuntimeCapability> capabilitySet = context.getResourceRegistration().getCapabilities();
    assert capabilitySet.isEmpty();
    if (context.isDefaultRequiresRuntime()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException {
                context.reloadRequired();
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext operationContext, ModelNode modelNode) {
                        context.revertReloadRequired();
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) RuntimeCapability(org.jboss.as.controller.capability.RuntimeCapability) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 22 with OperationContext

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

the class JcaWorkManagerDefinition method registerSubModels.

static void registerSubModels(ManagementResourceRegistration resourceRegistration, boolean runtimeOnly) {
    final BoundedQueueThreadPoolAdd shortRunningThreadPoolAdd = new BoundedQueueThreadPoolAdd(true, ThreadsServices.STANDARD_THREAD_FACTORY_RESOLVER, ThreadsServices.STANDARD_HANDOFF_EXECUTOR_RESOLVER, ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING)) {

        @Override
        protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
            super.populateModel(context, operation, resource);
            context.addStep(new OperationStepHandler() {

                public void execute(OperationContext oc, ModelNode op) throws OperationFailedException {
                    checkThreadPool(oc, op, WORKMANAGER_SHORT_RUNNING);
                }
            }, MODEL);
        }
    };
    resourceRegistration.registerSubModel(new JCAThreadPoolResourceDefinition(true, runtimeOnly, WORKMANAGER_SHORT_RUNNING, ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING), CommonAttributes.BLOCKING_BOUNDED_QUEUE_THREAD_POOL, shortRunningThreadPoolAdd, ReloadRequiredRemoveStepHandler.INSTANCE));
    final BoundedQueueThreadPoolAdd longRunningThreadPoolAdd = new BoundedQueueThreadPoolAdd(true, ThreadsServices.STANDARD_THREAD_FACTORY_RESOLVER, ThreadsServices.STANDARD_HANDOFF_EXECUTOR_RESOLVER, ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING)) {

        @Override
        protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
            super.populateModel(context, operation, resource);
            context.addStep(new OperationStepHandler() {

                public void execute(OperationContext oc, ModelNode op) throws OperationFailedException {
                    checkThreadPool(oc, op, WORKMANAGER_LONG_RUNNING);
                }
            }, MODEL);
        }
    };
    resourceRegistration.registerSubModel(new JCAThreadPoolResourceDefinition(true, runtimeOnly, WORKMANAGER_LONG_RUNNING, ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING), CommonAttributes.BLOCKING_BOUNDED_QUEUE_THREAD_POOL, longRunningThreadPoolAdd, new BoundedQueueThreadPoolRemove(longRunningThreadPoolAdd)));
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) BoundedQueueThreadPoolRemove(org.jboss.as.threads.BoundedQueueThreadPoolRemove) BoundedQueueThreadPoolAdd(org.jboss.as.threads.BoundedQueueThreadPoolAdd) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ReadResourceNameOperationStepHandler(org.jboss.as.controller.ReadResourceNameOperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 23 with OperationContext

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

the class AbstractEJBComponentResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    final AbstractEJBComponentRuntimeHandler<?> handler = componentType.getRuntimeHandler();
    resourceRegistration.registerReadOnlyAttribute(COMPONENT_CLASS_NAME, handler);
    resourceRegistration.registerReadOnlyAttribute(SECURITY_DOMAIN, handler);
    resourceRegistration.registerReadOnlyAttribute(RUN_AS_ROLE, handler);
    resourceRegistration.registerReadOnlyAttribute(DECLARED_ROLES, handler);
    resourceRegistration.registerReadOnlyAttribute(TRANSACTION_TYPE, handler);
    if (!componentType.equals(EJBComponentType.MESSAGE_DRIVEN)) {
        resourceRegistration.registerReadOnlyAttribute(JNDI_NAMES, handler);
        resourceRegistration.registerReadOnlyAttribute(BUSINESS_LOCAL, handler);
        resourceRegistration.registerReadOnlyAttribute(BUSINESS_REMOTE, handler);
        resourceRegistration.registerReadOnlyAttribute(ASYNC_METHODS, handler);
    }
    if (componentType.hasTimer()) {
        resourceRegistration.registerReadOnlyAttribute(TimerAttributeDefinition.INSTANCE, handler);
        resourceRegistration.registerReadOnlyAttribute(TIMEOUT_METHOD, handler);
    }
    if (componentType.hasPool()) {
        resourceRegistration.registerReadOnlyAttribute(POOL_AVAILABLE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_CREATE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_NAME, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_REMOVE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_CURRENT_SIZE, handler);
        resourceRegistration.registerReadWriteAttribute(POOL_MAX_SIZE, handler, handler);
    }
    if (componentType.equals(EJBComponentType.STATEFUL)) {
        resourceRegistration.registerMetric(CACHE_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getCacheSize());
            }
        });
        resourceRegistration.registerMetric(PASSIVATED_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getPassivatedCount());
            }
        });
        resourceRegistration.registerMetric(TOTAL_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getTotalSize());
            }
        });
    }
    resourceRegistration.registerMetric(EXECUTION_TIME, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getExecutionTime());
        }
    });
    resourceRegistration.registerMetric(INVOCATIONS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getInvocations());
        }
    });
    resourceRegistration.registerMetric(PEAK_CONCURRENT_INVOCATIONS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getPeakConcurrent());
        }
    });
    resourceRegistration.registerMetric(WAIT_TIME, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().set(component.getInvocationMetrics().getWaitTime());
        }
    });
    resourceRegistration.registerMetric(METHODS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) {
            context.getResult().setEmptyObject();
            for (final Map.Entry<String, InvocationMetrics.Values> entry : component.getInvocationMetrics().getMethods().entrySet()) {
                final InvocationMetrics.Values values = entry.getValue();
                final ModelNode result = new ModelNode();
                result.get("execution-time").set(values.getExecutionTime());
                result.get("invocations").set(values.getInvocations());
                result.get("wait-time").set(values.getWaitTime());
                context.getResult().get(entry.getKey()).set(result);
            }
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InvocationMetrics(org.jboss.as.ejb3.component.invocationmetrics.InvocationMetrics) ModelNode(org.jboss.dmr.ModelNode) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Example 24 with OperationContext

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

the class MigrateOperation method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (!describe && context.getRunningMode() != RunningMode.ADMIN_ONLY) {
        throw ROOT_LOGGER.migrateOperationAllowedOnlyInAdminOnly();
    }
    boolean addLegacyEntries = ADD_LEGACY_ENTRIES.resolveModelAttribute(context, operation).asBoolean();
    final List<String> warnings = new ArrayList<>();
    // node containing the description (list of add operations) of the legacy subsystem
    final ModelNode legacyModelAddOps = new ModelNode();
    // preserve the order of insertion of the add operations for the new subsystem.
    final Map<PathAddress, ModelNode> migrationOperations = new LinkedHashMap<PathAddress, ModelNode>();
    // invoke an OSH to describe the legacy messaging subsystem
    describeLegacyMessagingResources(context, legacyModelAddOps);
    // invoke an OSH to add the messaging-activemq extension
    // FIXME: this does not work it the extension :add is added to the migrationOperations directly (https://issues.jboss.org/browse/WFCORE-323)
    addMessagingActiveMQExtension(context, migrationOperations, describe);
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            // transform the legacy add operations and put them in migrationOperations
            transformResources(context, legacyModelAddOps, migrationOperations, addLegacyEntries, warnings);
            // put the /subsystem=messaging:remove operation
            removeMessagingSubsystem(migrationOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER);
            PathAddress parentAddress = context.getCurrentAddress().getParent();
            fixAddressesForDomainMode(parentAddress, migrationOperations);
            if (describe) {
                // :describe-migration operation
                // for describe-migration operation, do nothing and return the list of operations that would
                // be executed in the composite operation
                final Collection<ModelNode> values = migrationOperations.values();
                ModelNode result = new ModelNode();
                fillWarnings(result, warnings);
                result.get(MIGRATION_OPERATIONS).set(values);
                context.getResult().set(result);
            } else {
                // :migrate operation
                // invoke an OSH on a composite operation with all the migration operations
                final Map<PathAddress, ModelNode> migrateOpResponses = migrateSubsystems(context, migrationOperations);
                context.completeStep(new OperationContext.ResultHandler() {

                    @Override
                    public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
                        final ModelNode result = new ModelNode();
                        fillWarnings(result, warnings);
                        if (resultAction == OperationContext.ResultAction.ROLLBACK) {
                            for (Map.Entry<PathAddress, ModelNode> entry : migrateOpResponses.entrySet()) {
                                if (entry.getValue().hasDefined(FAILURE_DESCRIPTION)) {
                                    // we check for failure description, as every node has 'failed', but one
                                    // the real error has a failure description
                                    // we break when we find the first one, as there will only ever be one failure
                                    // as the op stops after the first failure
                                    ModelNode desc = new ModelNode();
                                    desc.get(OP).set(migrationOperations.get(entry.getKey()));
                                    desc.get(RESULT).set(entry.getValue());
                                    result.get(MIGRATION_ERROR).set(desc);
                                    break;
                                }
                            }
                            context.getFailureDescription().set(ROOT_LOGGER.migrationFailed());
                        }
                        context.getResult().set(result);
                    }
                });
            }
        }
    }, MODEL);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedHashMap(java.util.LinkedHashMap) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with OperationContext

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

the class SocketBroadcastGroupAdd method populateModel.

@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    super.populateModel(context, operation, resource);
    final ModelNode connectorRefs = resource.getModel().require(CONNECTOR_REFS.getName());
    if (connectorRefs.isDefined()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                validateConnectors(context, operation, connectorRefs);
            }
        }, OperationContext.Stage.MODEL);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) 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