Search in sources :

Example 66 with OperationStepHandler

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

the class BatchSubsystemDefinition method registerAttributes.

@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL, SECURITY_DOMAIN);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_JOB_REPOSITORY, null, writeHandler);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_THREAD_POOL, null, writeHandler);
    resourceRegistration.registerReadWriteAttribute(SECURITY_DOMAIN, null, writeHandler);
    resourceRegistration.registerReadWriteAttribute(RESTART_JOBS_ON_RESUME, null, new AbstractWriteAttributeHandler<Boolean>(RESTART_JOBS_ON_RESUME) {

        @Override
        protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<Boolean> handbackHolder) throws OperationFailedException {
            setValue(context, resolvedValue);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode valueToRestore, final ModelNode valueToRevert, final Boolean handback) throws OperationFailedException {
            setValue(context, valueToRestore);
        }

        private void setValue(final OperationContext context, final ModelNode value) {
            final BatchConfigurationService service = (BatchConfigurationService) context.getServiceRegistry(true).getService(context.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName(), BatchConfiguration.class)).getService();
            service.setRestartOnResume(value.asBoolean());
        }
    });
}
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) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 67 with OperationStepHandler

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

the class StorePropertyResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            operationDeprecated(context, operation);
            context.createResource(PathAddress.EMPTY_ADDRESS);
            String name = context.getCurrentAddressValue();
            String value = operation.get(VALUE.getName()).asString();
            PathAddress storeAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapPutOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, name, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    this.registerAddOperation(registration, addHandler);
    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 storeAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapRemoveOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, name);
            context.addStep(putOperation, MapOperations.MAP_REMOVE_HANDLER, context.getCurrentStage());
        }
    };
    this.registerRemoveOperation(registration, removeHandler);
    OperationStepHandler readHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            operationDeprecated(context, operation);
            PathAddress storeAddress = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            ModelNode getOperation = Operations.createMapGetOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, key);
            context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
        }
    };
    OperationStepHandler writeHandler = new OperationStepHandler() {

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

Example 68 with OperationStepHandler

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

the class DataSourceEnableDisable method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    // Log that this is deprecated
    ConnectorLogger.ROOT_LOGGER.legacyDisableEnableOperation(operation.get(OP).asString());
    // Just delegate to write-attribute.
    ModelNode writeAttributeOp = getWriteAttributeOperation(context.getCurrentAddress(), Constants.ENABLED.getName(), enabled);
    OperationStepHandler writeHandler = context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION);
    // set the addFirst param to 'true' so the write-attribute runs before any other steps already registered;
    // i.e. in the logically equivalent spot in the sequence to this step
    context.addStep(writeAttributeOp, writeHandler, OperationContext.Stage.MODEL, true);
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 69 with OperationStepHandler

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

the class PoolOperations method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String jndiName;
    ModelNode model;
    if (!address.getElement(0).getKey().equals(ModelDescriptionConstants.DEPLOYMENT) && (model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()).isDefined()) {
        jndiName = Util.getJndiName(context, model);
        if (isDisabledDatasource(context, address, model)) {
            throw ConnectorLogger.ROOT_LOGGER.datasourceIsDisabled(jndiName);
        }
    } else {
        jndiName = address.getLastElement().getValue();
    }
    final Object[] parameters = getParameters(context, operation);
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final ServiceController<?> managementRepoService = context.getServiceRegistry(disallowMonitor).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
                if (managementRepoService != null) {
                    ModelNode operationResult = null;
                    try {
                        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
                        final List<Pool> pools = matcher.match(jndiName, repository);
                        if (pools.isEmpty()) {
                            throw ConnectorLogger.ROOT_LOGGER.failedToMatchPool(jndiName);
                        }
                        for (Pool pool : pools) {
                            operationResult = invokeCommandOn(pool, parameters);
                        }
                    } catch (Exception e) {
                        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToInvokeOperation(e.getLocalizedMessage()));
                    }
                    if (operationResult != null) {
                        context.getResult().set(operationResult);
                    }
                }
                context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ResourceException(javax.resource.ResourceException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.jboss.jca.core.api.connectionmanager.pool.Pool) ModelNode(org.jboss.dmr.ModelNode)

Example 70 with OperationStepHandler

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

the class AbstractDataSourceAdd method performRuntime.

@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    // domains should only be defined when Elytron enabled is undefined or false (default value)
    if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()) && !ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        throw SUBSYSTEM_DATASOURCES_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
    } else if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && model.hasDefined(SECURITY_DOMAIN.getName())) {
        throw SUBSYSTEM_DATASOURCES_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
    }
    final boolean enabled = ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (enabled) {
        firstRuntimeStep(context, operation, model);
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException {
                secondRuntimeStep(context, operation, context.getResourceRegistrationForUpdate(), model, isXa());
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
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

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