Search in sources :

Example 46 with OperationContext

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

the class SAMLResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
            if (serviceController != null) {
                SAMLService service = serviceController.getValue();
                ModelNode samlNode;
                if (!rollback) {
                    samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    samlNode = rc.getModel();
                }
                service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) SAMLService(org.wildfly.extension.picketlink.federation.service.SAMLService)

Example 47 with OperationContext

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

the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
            if (serviceController != null) {
                KeyStoreProviderService service = serviceController.getValue();
                ModelNode keyStoreProviderNode;
                if (!rollback) {
                    keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    keyStoreProviderNode = rc.getModel();
                }
                ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
                String relativeTo = null;
                if (relativeToNode.isDefined()) {
                    relativeTo = relativeToNode.asString();
                }
                String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
                service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) KeyStoreProviderService(org.wildfly.extension.picketlink.federation.service.KeyStoreProviderService)

Example 48 with OperationContext

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

the class HandlerAddHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    context.addStep(new AlternativeAttributeValidationStepHandler(new SimpleAttributeDefinition[] { HandlerResourceDefinition.CLASS_NAME, HandlerResourceDefinition.CODE }), OperationContext.Stage.MODEL);
    context.addStep(new UniqueTypeValidationStepHandler(ModelElement.COMMON_HANDLER) {

        @Override
        protected String getType(OperationContext context, ModelNode model) throws OperationFailedException {
            return getHandlerType(context, model);
        }
    }, OperationContext.Stage.MODEL);
    super.execute(context, operation);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) UniqueTypeValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.UniqueTypeValidationStepHandler) ModelNode(org.jboss.dmr.ModelNode) AlternativeAttributeValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.AlternativeAttributeValidationStepHandler)

Example 49 with OperationContext

use of org.jboss.as.controller.OperationContext 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 50 with OperationContext

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

the class ReadAttributeTranslationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    ModelNode targetOperation = Operations.createReadAttributeOperation(context.getCurrentAddress(), this.targetAttribute);
    String targetName = this.targetAttribute.getName();
    // If attribute has no read handler, synthesize one
    Optional.ofNullable(context.getResourceRegistration().getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetName).getReadHandler()).orElse((ctx, op) -> {
        ModelNode model = ctx.readResource(PathAddress.EMPTY_ADDRESS).getModel();
        ModelNode result = ctx.getResult();
        if (model.hasDefined(targetName)) {
            result.set(model.get(targetName));
        } else if (Operations.isIncludeDefaults(op)) {
            result.set(this.targetAttribute.getDefinition().getDefaultValue());
        }
    }).execute(context, targetOperation);
    ModelNode result = context.getResult();
    result.set(this.translator.translate(context, result));
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)67 ModelNode (org.jboss.dmr.ModelNode)67 OperationFailedException (org.jboss.as.controller.OperationFailedException)51 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)40 PathAddress (org.jboss.as.controller.PathAddress)34 ServiceController (org.jboss.msc.service.ServiceController)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)17 Resource (org.jboss.as.controller.registry.Resource)16 ServiceName (org.jboss.msc.service.ServiceName)13 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)11 ServiceTarget (org.jboss.msc.service.ServiceTarget)11 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)9 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 EnumSet (java.util.EnumSet)7 Map (java.util.Map)7 PathElement (org.jboss.as.controller.PathElement)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 ArrayList (java.util.ArrayList)6