Search in sources :

Example 6 with ReloadRequiredWriteAttributeHandler

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

the class AbstractDataSourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    ReloadRequiredWriteAttributeHandler handler = new ReloadRequiredWriteAttributeHandler(getAttributes());
    for (AttributeDefinition attributeDefinition : getAttributes()) {
        OperationStepHandler writeHandler = handler;
        if (attributeDefinition == STATISTICS_ENABLED_ATTRIBUTE) {
            writeHandler = AbstractDataSourceOperations.STATISTICS_ENABLED_WRITE_OPERATION;
        }
        if (attributeDefinition == CONNECTION_FACTORY_ATTRIBUTE) {
            writeHandler = AbstractDataSourceOperations.CONNECTION_FACTORY_WRITE_OPERATION;
        }
        if (attributeDefinition == CONNECTION_POOL_ATTRIBUTE) {
            writeHandler = AbstractDataSourceOperations.CONNECTION_POOL_WRITE_OPERATION;
        }
        if (attributeDefinition == CREDENTIAL_REFERENCE) {
            writeHandler = AbstractDataSourceOperations.CREDENTIAL_REFERENCE_WRITE_OPERATION;
        }
        resourceRegistration.registerReadWriteAttribute(attributeDefinition, null, writeHandler);
    }
    // Runtime attributes
    if (resourceRegistration.getProcessType().isServer()) {
        resourceRegistration.registerReadOnlyAttribute(STATISTICS, AbstractDataSourceOperations.STATISTICS_GET_OPERATION);
    }
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) ObjectTypeAttributeDefinition(org.jboss.as.controller.ObjectTypeAttributeDefinition) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 7 with ReloadRequiredWriteAttributeHandler

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

the class ProxyConfigurationResourceDefinition method register.

@SuppressWarnings("deprecation")
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(EnumSet.complementOf(EnumSet.of(Attribute.SSL_CONTEXT))).addExtraParameters(Attribute.SSL_CONTEXT).addAttributeTranslation(DeprecatedAttribute.SIMPLE_LOAD_PROVIDER, SIMPLE_LOAD_PROVIDER_TRANSLATION).addAlias(DeprecatedAttribute.CONNECTOR, Attribute.LISTENER).addRequiredSingletonChildren(SimpleLoadProviderResourceDefinition.PATH).addCapabilities(Capability.class);
    registration.registerReadWriteAttribute(Attribute.SSL_CONTEXT.getDefinition(), null, new ReloadRequiredWriteAttributeHandler() {

        @Override
        protected void validateUpdatedModel(OperationContext context, Resource model) {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext ctx, ModelNode op) throws OperationFailedException {
                    if (model.hasChild(SSLResourceDefinition.PATH)) {
                        throw new OperationFailedException(ROOT_LOGGER.bothElytronAndLegacySslContextDefined());
                    }
                }
            }, OperationContext.Stage.MODEL);
        }
    });
    parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {

        @Override
        public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
            PathAddress rebuiltAddress = PathAddress.EMPTY_ADDRESS;
            for (PathElement pathElement : aliasAddress) {
                if (pathElement.equals(LEGACY_PATH)) {
                    try {
                        if (aliasContext.readResourceFromRoot(rebuiltAddress, false).hasChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey())) {
                            Set<Resource.ResourceEntry> children = aliasContext.readResourceFromRoot(rebuiltAddress, false).getChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey());
                            if (children.size() > 1 && !Operations.getOperationName(aliasContext.getOperation()).equals(AliasContext.RECURSIVE_GLOBAL_OP)) {
                                throw new IllegalStateException(ModClusterLogger.ROOT_LOGGER.legacyOperationsWithMultipleProxies());
                            }
                            PathAddress proxyPath = PathAddress.pathAddress(ProxyConfigurationResourceDefinition.pathElement(children.iterator().next().getName()));
                            rebuiltAddress = rebuiltAddress.append(proxyPath);
                        } else {
                            // handle :add
                            rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.pathElement("default"));
                        }
                    } catch (Resource.NoSuchResourceException ignore) {
                        // handle recursive-global-op
                        rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.WILDCARD_PATH);
                    }
                } else {
                    rebuiltAddress = rebuiltAddress.append(pathElement);
                }
            }
            return rebuiltAddress;
        }
    });
    if (registration.isRuntimeOnlyRegistrationValid()) {
        new OperationHandler<>(new ProxyOperationExecutor(this.executors), ProxyOperation.class).register(registration);
    }
    new ReloadRequiredResourceRegistration(descriptor).register(registration);
    new LegacyMetricOperationsRegistration().register(registration);
    new SimpleLoadProviderResourceDefinition().register(registration);
    new DynamicLoadProviderResourceDefinition().register(registration);
    new SSLResourceDefinition().register(registration);
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) EnumSet(java.util.EnumSet) Set(java.util.Set) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ReloadRequiredResourceRegistration(org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration) AliasEntry(org.jboss.as.controller.registry.AliasEntry) ModelNode(org.jboss.dmr.ModelNode) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 8 with ReloadRequiredWriteAttributeHandler

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

the class SecuritySubsystemRootResourceDefinition method registerAttributes.

@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
    resourceRegistration.registerReadWriteAttribute(DEEP_COPY_SUBJECT_MODE, null, new ReloadRequiredWriteAttributeHandler(DEEP_COPY_SUBJECT_MODE));
    resourceRegistration.registerReadWriteAttribute(INITIALIZE_JACC, null, new ReloadRequiredWriteAttributeHandler(INITIALIZE_JACC) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> voidHandback) throws OperationFailedException {
            // As the PolicyConfigurationFactory is a singleton, once it's initialized any changes will require a restart
            CapabilityServiceSupport capabilitySupport = context.getCapabilityServiceSupport();
            final boolean elytronJacc = capabilitySupport.hasCapability("org.wildfly.security.jacc-policy");
            if (resolvedValue.asBoolean() == true && elytronJacc) {
                throw SecurityLogger.ROOT_LOGGER.unableToEnableJaccSupport();
            }
            return super.applyUpdateToRuntime(context, operation, attributeName, resolvedValue, currentValue, voidHandback);
        }

        @Override
        protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, ModelNode newValue, ModelNode oldValue) {
            super.recordCapabilitiesAndRequirements(context, attributeDefinition, newValue, oldValue);
            boolean shouldRegister = resolveValue(context, attributeDefinition, newValue);
            boolean registered = resolveValue(context, attributeDefinition, oldValue);
            if (!shouldRegister) {
                context.deregisterCapability(JACC_CAPABILITY.getName());
            }
            if (!registered && shouldRegister) {
                context.registerCapability(JACC_CAPABILITY);
            // do not register the JACC_CAPABILITY_TOMBSTONE at this point - it will be registered on restart
            }
        }

        private boolean resolveValue(OperationContext context, AttributeDefinition attributeDefinition, ModelNode node) {
            try {
                return attributeDefinition.resolveValue(context, node).asBoolean();
            } catch (OperationFailedException e) {
                throw new IllegalStateException(e);
            }
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport)

Example 9 with ReloadRequiredWriteAttributeHandler

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

the class ApplicationSecurityDomainDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    knownApplicationSecurityDomains.clear();
    ReloadRequiredWriteAttributeHandler handler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
    for (AttributeDefinition attribute : ATTRIBUTES) {
        resourceRegistration.registerReadWriteAttribute(attribute, null, handler);
    }
    if (resourceRegistration.getProcessType().isServer()) {
        resourceRegistration.registerReadOnlyAttribute(REFERENCING_DEPLOYMENTS, new ReferencingDeploymentsHandler());
    }
}
Also used : StringListAttributeDefinition(org.jboss.as.controller.StringListAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 10 with ReloadRequiredWriteAttributeHandler

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

the class BridgeDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration registry) {
    ReloadRequiredWriteAttributeHandler reloadRequiredWriteAttributeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
    CredentialReferenceWriteAttributeHandler credentialReferenceWriteAttributeHandler = new CredentialReferenceWriteAttributeHandler(CREDENTIAL_REFERENCE);
    for (AttributeDefinition attr : ATTRIBUTES) {
        if (!attr.getFlags().contains(AttributeAccess.Flag.STORAGE_RUNTIME)) {
            if (attr.equals(CREDENTIAL_REFERENCE)) {
                registry.registerReadWriteAttribute(attr, null, credentialReferenceWriteAttributeHandler);
            } else {
                registry.registerReadWriteAttribute(attr, null, reloadRequiredWriteAttributeHandler);
            }
        }
    }
    BridgeControlHandler.INSTANCE.registerAttributes(registry);
}
Also used : CredentialReferenceWriteAttributeHandler(org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler) StringListAttributeDefinition(org.jboss.as.controller.StringListAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PrimitiveListAttributeDefinition(org.jboss.as.controller.PrimitiveListAttributeDefinition) ObjectTypeAttributeDefinition(org.jboss.as.controller.ObjectTypeAttributeDefinition) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Aggregations

ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)30 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)14 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)14 OperationContext (org.jboss.as.controller.OperationContext)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)8 ModelNode (org.jboss.dmr.ModelNode)8 OperationFailedException (org.jboss.as.controller.OperationFailedException)7 StringListAttributeDefinition (org.jboss.as.controller.StringListAttributeDefinition)6 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)5 CredentialReferenceWriteAttributeHandler (org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler)4 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)3 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)3 ReloadRequiredResourceRegistration (org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration)2 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)2 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)2 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)2 Resource (org.jboss.as.controller.registry.Resource)2 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1