Search in sources :

Example 81 with AttributeDefinition

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

the class JacORBSubsystemAdd method populateModel.

@Override
protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    for (AttributeDefinition attr : attributes) {
        attr.validateAndSet(operation, model);
    }
    ConfigValidator.validateConfig(context, TransformUtils.transformModel(model));
    final boolean adminOnly = context.getRunningMode() == RunningMode.ADMIN_ONLY;
    final boolean hostController = context.getProcessType().equals(ProcessType.HOST_CONTROLLER);
    // valid
    if (adminOnly || !hostController) {
        final List<String> unsupportedProperites = TransformUtils.validateDeprecatedProperites(model);
        if (!unsupportedProperites.isEmpty()) {
            if (adminOnly) {
                final String warning = JacORBLogger.ROOT_LOGGER.cannotEmulatePropertiesWarning(unsupportedProperites);
                JacORBLogger.ROOT_LOGGER.warn(warning);
            } else {
                throw JacORBLogger.ROOT_LOGGER.cannotEmulateProperties(unsupportedProperites);
            }
        }
    }
}
Also used : AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 82 with AttributeDefinition

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

the class AlternativeAttributeCheckHandler method checkAlternativeAttribute.

private void checkAlternativeAttribute(OperationContext context, String attributeName, boolean alternativeMustBeSet) throws OperationFailedException {
    if (attributeDefinitions.containsKey(attributeName)) {
        AttributeDefinition attr = attributeDefinitions.get(attributeName);
        final Resource resource = context.readResource(EMPTY_ADDRESS);
        if (alternativeMustBeSet) {
            if (!attr.hasAlternative(resource.getModel())) {
                throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.undefineAttributeWithoutAlternative(attributeName));
            }
        } else {
            if (attr.hasAlternative(resource.getModel())) {
                throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.altAttributeAlreadyDefined(attributeName));
            }
        }
    }
}
Also used : Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 83 with AttributeDefinition

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

the class WebSubsystemParser method writeContent.

/**
 * {@inheritDoc}
 */
@Override
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);
    ModelNode node = context.getModelNode();
    WebDefinition.DEFAULT_VIRTUAL_SERVER.marshallAsAttribute(node, true, writer);
    WebDefinition.INSTANCE_ID.marshallAsAttribute(node, false, writer);
    WebDefinition.NATIVE.marshallAsAttribute(node, true, writer);
    WebDefinition.DEFAULT_SESSION_TIMEOUT.marshallAsAttribute(node, false, writer);
    if (node.hasDefined(CONFIGURATION)) {
        writeContainerConfig(writer, node.get(CONFIGURATION));
    }
    if (node.hasDefined(CONNECTOR)) {
        for (final Property connector : node.get(CONNECTOR).asPropertyList()) {
            final ModelNode config = connector.getValue();
            writer.writeStartElement(Element.CONNECTOR.getLocalName());
            writer.writeAttribute(NAME, connector.getName());
            List<AttributeDefinition> connectorAttributes = new ArrayList<>(Arrays.asList(WebConnectorDefinition.CONNECTOR_ATTRIBUTES));
            if (config.hasDefined(Constants.PROXY_BINDING)) {
                connectorAttributes.remove(WebConnectorDefinition.PROXY_PORT);
                connectorAttributes.remove(WebConnectorDefinition.PROXY_NAME);
            } else {
                connectorAttributes.remove(WebConnectorDefinition.PROXY_BINDING);
            }
            if (config.hasDefined(Constants.REDIRECT_BINDING)) {
                connectorAttributes.remove(WebConnectorDefinition.REDIRECT_PORT);
            } else {
                connectorAttributes.remove(WebConnectorDefinition.REDIRECT_BINDING);
            }
            for (AttributeDefinition attr : connectorAttributes) {
                if (attr instanceof SimpleAttributeDefinition) {
                    ((SimpleAttributeDefinition) attr).marshallAsAttribute(config, true, writer);
                }
            }
            if (config.get(SSL_PATH.getKey(), SSL_PATH.getValue()).isDefined()) {
                ModelNode sslConfig = config.get(SSL_PATH.getKey(), SSL_PATH.getValue());
                writer.writeStartElement(Element.SSL.getLocalName());
                WebSSLDefinition.NAME.marshallAsAttribute(sslConfig, writer);
                for (SimpleAttributeDefinition attr : WebSSLDefinition.SSL_ATTRIBUTES) {
                    attr.marshallAsAttribute(sslConfig, false, writer);
                }
                writer.writeEndElement();
            }
            if (config.hasDefined(VIRTUAL_SERVER)) {
                for (final ModelNode virtualServer : config.get(VIRTUAL_SERVER).asList()) {
                    writer.writeEmptyElement(VIRTUAL_SERVER);
                    writer.writeAttribute(NAME, virtualServer.asString());
                }
            }
            writer.writeEndElement();
        }
    }
    if (node.hasDefined(VIRTUAL_SERVER)) {
        for (final Property host : node.get(VIRTUAL_SERVER).asPropertyList()) {
            final ModelNode config = host.getValue();
            writer.writeStartElement(Element.VIRTUAL_SERVER.getLocalName());
            writer.writeAttribute(NAME, host.getName());
            WebVirtualHostDefinition.ENABLE_WELCOME_ROOT.marshallAsAttribute(config, true, writer);
            WebVirtualHostDefinition.DEFAULT_WEB_MODULE.marshallAsAttribute(config, true, writer);
            if (config.hasDefined(ALIAS)) {
                for (final ModelNode alias : config.get(ALIAS).asList()) {
                    writer.writeEmptyElement(ALIAS);
                    writer.writeAttribute(NAME, alias.asString());
                }
            }
            if (config.get(ACCESS_LOG_PATH.getKey(), ACCESS_LOG_PATH.getValue()).isDefined()) {
                ModelNode accessLog = config.get(ACCESS_LOG_PATH.getKey(), ACCESS_LOG_PATH.getValue());
                writer.writeStartElement(Element.ACCESS_LOG.getLocalName());
                for (SimpleAttributeDefinition attr : WebAccessLogDefinition.ACCESS_LOG_ATTRIBUTES) {
                    attr.marshallAsAttribute(accessLog, false, writer);
                }
                if (accessLog.get(DIRECTORY_PATH.getKey(), DIRECTORY_PATH.getValue()).isDefined()) {
                    ModelNode directory = accessLog.get(DIRECTORY_PATH.getKey(), DIRECTORY_PATH.getValue());
                    String name = Element.DIRECTORY.getLocalName();
                    boolean startwritten = false;
                    startwritten = writeAttribute(writer, WebAccessLogDirectoryDefinition.PATH, directory, startwritten, name);
                    startwritten = writeAttribute(writer, WebAccessLogDirectoryDefinition.RELATIVE_TO, directory, startwritten, name);
                    if (startwritten) {
                        writer.writeEndElement();
                    }
                }
                writer.writeEndElement();
            }
            if (config.hasDefined(REWRITE)) {
                for (final ModelNode rewritenode : config.get(REWRITE).asList()) {
                    Property prop = rewritenode.asProperty();
                    ModelNode rewrite = prop.getValue();
                    writer.writeStartElement(REWRITE);
                    writer.writeAttribute(NAME, prop.getName());
                    WebReWriteDefinition.PATTERN.marshallAsAttribute(rewrite, false, writer);
                    WebReWriteDefinition.SUBSTITUTION.marshallAsAttribute(rewrite, false, writer);
                    WebReWriteDefinition.FLAGS.marshallAsAttribute(rewrite, false, writer);
                    if (rewrite.hasDefined(CONDITION)) {
                        for (final ModelNode conditionnode : rewrite.get(CONDITION).asList()) {
                            Property conditionProp = conditionnode.asProperty();
                            ModelNode condition = conditionProp.getValue();
                            writer.writeStartElement(CONDITION);
                            writer.writeAttribute(NAME, conditionProp.getName());
                            WebReWriteConditionDefinition.TEST.marshallAsAttribute(condition, false, writer);
                            WebReWriteConditionDefinition.PATTERN.marshallAsAttribute(condition, false, writer);
                            WebReWriteConditionDefinition.FLAGS.marshallAsAttribute(condition, false, writer);
                            writer.writeEndElement();
                        }
                    }
                    writer.writeEndElement();
                }
            }
            if (config.get(SSO_PATH.getKey(), SSO_PATH.getValue()).isDefined()) {
                final ModelNode sso;
                sso = config.get(SSO_PATH.getKey(), SSO_PATH.getValue());
                writer.writeStartElement(SSO);
                for (SimpleAttributeDefinition attr : WebSSODefinition.SSO_ATTRIBUTES) {
                    attr.marshallAsAttribute(sso, false, writer);
                }
                writer.writeEndElement();
            }
            // End of the VIRTUAL_SERVER
            writer.writeEndElement();
        }
        if (node.hasDefined(VALVE)) {
            for (final Property valve : node.get(VALVE).asPropertyList()) {
                final ModelNode config = valve.getValue();
                writer.writeStartElement(Element.VALVE.getLocalName());
                writer.writeAttribute(NAME, valve.getName());
                for (AttributeDefinition attr : WebValveDefinition.ATTRIBUTES) {
                    if (attr instanceof SimpleAttributeDefinition) {
                        ((SimpleAttributeDefinition) attr).marshallAsAttribute(config, false, writer);
                    }
                }
                if (config.hasDefined(PARAM)) {
                    for (final Property entry : config.get(PARAM).asPropertyList()) {
                        writer.writeEmptyElement(Element.PARAM.getLocalName());
                        writer.writeAttribute(Attribute.PARAM_NAME.getLocalName(), entry.getName());
                        writer.writeAttribute(Attribute.PARAM_VALUE.getLocalName(), entry.getValue().asString());
                    }
                }
                writer.writeEndElement();
            }
        }
    }
    writer.writeEndElement();
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 84 with AttributeDefinition

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

the class JMSBridgeDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration registry) {
    ReloadRequiredWriteAttributeHandler reloadRequiredWriteAttributeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
    CredentialReferenceWriteAttributeHandler credentialReferenceWriteAttributeHandler = new CredentialReferenceWriteAttributeHandler(SOURCE_CREDENTIAL_REFERENCE, TARGET_CREDENTIAL_REFERENCE);
    for (AttributeDefinition attr : ATTRIBUTES) {
        if (attr.equals(SOURCE_CREDENTIAL_REFERENCE) || attr.equals(TARGET_CREDENTIAL_REFERENCE)) {
            registry.registerReadWriteAttribute(attr, null, credentialReferenceWriteAttributeHandler);
        } else {
            registry.registerReadWriteAttribute(attr, null, reloadRequiredWriteAttributeHandler);
        }
    }
    for (AttributeDefinition attr : READONLY_ATTRIBUTES) {
        registry.registerReadOnlyAttribute(attr, JMSBridgeHandler.INSTANCE);
    }
    for (AttributeDefinition attr : METRICS) {
        registry.registerMetric(attr, JMSBridgeHandler.READ_ONLY_INSTANCE);
    }
}
Also used : CredentialReferenceWriteAttributeHandler(org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler) 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 85 with AttributeDefinition

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

the class PooledConnectionFactoryDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration registry) {
    Collection<AttributeDefinition> definitions = getAttributes();
    ReloadRequiredWriteAttributeHandler reloadRequiredWriteAttributeHandler = new ReloadRequiredWriteAttributeHandler(definitions);
    CredentialReferenceWriteAttributeHandler credentialReferenceWriteAttributeHandler = new CredentialReferenceWriteAttributeHandler(CREDENTIAL_REFERENCE);
    for (AttributeDefinition attr : definitions) {
        if (!attr.getFlags().contains(AttributeAccess.Flag.STORAGE_RUNTIME)) {
            if (deployed) {
                registry.registerReadOnlyAttribute(attr, PooledConnectionFactoryConfigurationRuntimeHandler.INSTANCE);
            } else {
                if (attr.equals(CREDENTIAL_REFERENCE)) {
                    registry.registerReadWriteAttribute(attr, null, credentialReferenceWriteAttributeHandler);
                } else {
                    registry.registerReadWriteAttribute(attr, null, reloadRequiredWriteAttributeHandler);
                }
            }
        }
    }
}
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) SimpleMapAttributeDefinition(org.jboss.as.controller.SimpleMapAttributeDefinition) PrimitiveListAttributeDefinition(org.jboss.as.controller.PrimitiveListAttributeDefinition) SimpleListAttributeDefinition(org.jboss.as.controller.SimpleListAttributeDefinition) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Aggregations

AttributeDefinition (org.jboss.as.controller.AttributeDefinition)102 ModelNode (org.jboss.dmr.ModelNode)48 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)40 PathAddress (org.jboss.as.controller.PathAddress)17 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)16 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 OperationContext (org.jboss.as.controller.OperationContext)13 Resource (org.jboss.as.controller.registry.Resource)12 Property (org.jboss.dmr.Property)12 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)9 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)9 StringListAttributeDefinition (org.jboss.as.controller.StringListAttributeDefinition)9 OperationFailedException (org.jboss.as.controller.OperationFailedException)8 ArrayList (java.util.ArrayList)7 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)6 Map (java.util.Map)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5