Search in sources :

Example 56 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class JcaWorkManagerDefinition method registerSubModels.

static void registerSubModels(ManagementResourceRegistration resourceRegistration, boolean runtimeOnly) {
    final BoundedQueueThreadPoolAdd shortRunningThreadPoolAdd = new BoundedQueueThreadPoolAdd(false, 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(false, runtimeOnly, WORKMANAGER_SHORT_RUNNING, ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING), CommonAttributes.BOUNDED_QUEUE_THREAD_POOL, shortRunningThreadPoolAdd, ReloadRequiredRemoveStepHandler.INSTANCE));
    final BoundedQueueThreadPoolAdd longRunningThreadPoolAdd = new BoundedQueueThreadPoolAdd(false, 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(false, runtimeOnly, WORKMANAGER_LONG_RUNNING, ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING), CommonAttributes.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 57 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class AOConfigPropertyAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException {
    final String configPropertyValue = CONFIG_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString();
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String archiveName = path.getElement(path.size() - 3).getValue();
    final String aoName = path.getElement(path.size() - 2).getValue();
    final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue();
    ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, aoName, configPropertyName);
    ServiceName aoServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, archiveName, aoName);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final AOConfigPropertiesService service = new AOConfigPropertiesService(configPropertyName, configPropertyValue);
    serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(aoServiceName, ModifiableAdminObject.class, service.getAOInjector()).install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModelNode(org.jboss.dmr.ModelNode)

Example 58 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class AdminObjectAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String raName = context.getCurrentAddress().getParent().getLastElement().getValue();
    final String archiveOrModuleName;
    ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1)).getModel();
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
    if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (raModel.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
    } else {
        archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
    }
    final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
    final ModifiableAdminObject adminObjectValue;
    try {
        adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName);
    } catch (ValidateException e) {
        throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage())));
    }
    ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
    ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final AdminObjectService service = new AdminObjectService(adminObjectValue);
    serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()).install();
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    AdminObjectStatisticsService adminObjectStatisticsService = new AdminObjectStatisticsService(context.getResourceRegistrationForUpdate(), poolName, statsEnabled);
    ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), adminObjectStatisticsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), adminObjectStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, adminObjectStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource aoResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peAO, aoResource);
}
Also used : ValidateException(org.jboss.jca.common.api.validator.ValidateException) AdminObjectStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 59 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class CommonIronJacamarParser method parseConnectionDefinitions_4_0.

/**
     * parse a single connection-definition tag
     *
     * @param reader the reader
     * @throws javax.xml.stream.XMLStreamException
     *                         XMLStreamException
     * @throws ParserException ParserException
     * @throws org.jboss.jca.common.api.validator.ValidateException
     *                         ValidateException
     */
protected void parseConnectionDefinitions_4_0(final XMLExtendedStreamReader reader, final Map<String, ModelNode> map, final Map<String, HashMap<String, ModelNode>> configMap, final boolean isXa) throws XMLStreamException, ParserException, ValidateException {
    final ModelNode connectionDefinitionNode = new ModelNode();
    connectionDefinitionNode.get(OP).set(ADD);
    String poolName = null;
    String jndiName = null;
    int attributeSize = reader.getAttributeCount();
    boolean poolDefined = Boolean.FALSE;
    for (int i = 0; i < attributeSize; i++) {
        ConnectionDefinition.Attribute attribute = ConnectionDefinition.Attribute.forName(reader.getAttributeLocalName(i));
        String value = reader.getAttributeValue(i);
        switch(attribute) {
            case ENABLED:
                {
                    ENABLED.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case CONNECTABLE:
                {
                    CONNECTABLE.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case TRACKING:
                {
                    TRACKING.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case JNDI_NAME:
                {
                    jndiName = value;
                    JNDINAME.parseAndSetParameter(jndiName, connectionDefinitionNode, reader);
                    break;
                }
            case POOL_NAME:
                {
                    poolName = value;
                    break;
                }
            case USE_JAVA_CONTEXT:
                {
                    USE_JAVA_CONTEXT.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case USE_CCM:
                {
                    USE_CCM.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case SHARABLE:
                {
                    SHARABLE.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case ENLISTMENT:
                {
                    ENLISTMENT.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case CLASS_NAME:
                {
                    CLASS_NAME.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case MCP:
                {
                    MCP.parseAndSetParameter(value, connectionDefinitionNode, reader);
                    break;
                }
            case ENLISTMENT_TRACE:
                ENLISTMENT_TRACE.parseAndSetParameter(value, connectionDefinitionNode, reader);
                break;
            default:
                throw ParseUtils.unexpectedAttribute(reader, i);
        }
    }
    if (poolName == null || poolName.trim().equals("")) {
        if (jndiName != null && jndiName.trim().length() != 0) {
            if (jndiName.contains("/")) {
                poolName = jndiName.substring(jndiName.lastIndexOf("/") + 1);
            } else {
                poolName = jndiName.substring(jndiName.lastIndexOf(":") + 1);
            }
        } else {
            throw ParseUtils.missingRequired(reader, EnumSet.of(ConnectionDefinition.Attribute.JNDI_NAME));
        }
    }
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case END_ELEMENT:
                {
                    if (Activation.Tag.forName(reader.getLocalName()) == Activation.Tag.CONNECTION_DEFINITION) {
                        map.put(poolName, connectionDefinitionNode);
                        return;
                    } else {
                        if (ConnectionDefinition.Tag.forName(reader.getLocalName()) == ConnectionDefinition.Tag.UNKNOWN) {
                            throw ParseUtils.unexpectedEndElement(reader);
                        }
                    }
                    break;
                }
            case START_ELEMENT:
                {
                    switch(ConnectionDefinition.Tag.forName(reader.getLocalName())) {
                        case CONFIG_PROPERTY:
                            {
                                if (!configMap.containsKey(poolName)) {
                                    configMap.put(poolName, new HashMap<String, ModelNode>(0));
                                }
                                parseConfigProperties(reader, configMap.get(poolName));
                                break;
                            }
                        case SECURITY:
                            {
                                parseSecuritySettings(reader, connectionDefinitionNode);
                                break;
                            }
                        case TIMEOUT:
                            {
                                parseTimeOut(reader, isXa, connectionDefinitionNode);
                                break;
                            }
                        case VALIDATION:
                            {
                                parseValidation(reader, connectionDefinitionNode);
                                break;
                            }
                        case XA_POOL:
                            {
                                if (!isXa) {
                                    throw ParseUtils.unexpectedElement(reader);
                                }
                                if (poolDefined) {
                                    throw new ParserException(bundle.multiplePools());
                                }
                                parseXaPool(reader, connectionDefinitionNode);
                                poolDefined = true;
                                break;
                            }
                        case POOL:
                            {
                                if (isXa) {
                                    throw ParseUtils.unexpectedElement(reader);
                                }
                                if (poolDefined) {
                                    throw new ParserException(bundle.multiplePools());
                                }
                                parsePool(reader, connectionDefinitionNode);
                                poolDefined = true;
                                break;
                            }
                        case RECOVERY:
                            {
                                parseRecovery(reader, connectionDefinitionNode);
                                break;
                            }
                        default:
                            throw ParseUtils.unexpectedElement(reader);
                    }
                    break;
                }
        }
    }
    throw ParseUtils.unexpectedEndElement(reader);
}
Also used : ParserException(org.jboss.as.connector.util.ParserException) ConnectionDefinition(org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 60 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class AbstractComplexSubsystemTestCase method getModel.

public ModelNode getModel(String resourceFileName, boolean checkMarshalledXML, String archiveName) throws Exception {
    String xml = readResource(resourceFileName);
    KernelServices services = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT).setSubsystemXml(xml).build();
    ModelNode model = services.readWholeModel();
    // Marshal the xml to see that it is the same as before
    String marshalled = services.getPersistedSubsystemXml();
    if (checkMarshalledXML)
        Assert.assertEquals(normalizeXML(xml), normalizeXML(marshalled));
    services = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT).setSubsystemXml(marshalled).build();
    // Check that the model looks the same
    ModelNode modelReloaded = services.readWholeModel();
    compare(model, modelReloaded);
    assertRemoveSubsystemResources(services);
    return model;
}
Also used : KernelServices(org.jboss.as.subsystem.test.KernelServices) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)1634 PathAddress (org.jboss.as.controller.PathAddress)351 Test (org.junit.Test)344 KernelServices (org.jboss.as.subsystem.test.KernelServices)102 Property (org.jboss.dmr.Property)92 OperationFailedException (org.jboss.as.controller.OperationFailedException)89 OperationContext (org.jboss.as.controller.OperationContext)68 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)68 ArrayList (java.util.ArrayList)58 Resource (org.jboss.as.controller.registry.Resource)54 PathElement (org.jboss.as.controller.PathElement)53 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)52 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)50 IOException (java.io.IOException)49 ServiceName (org.jboss.msc.service.ServiceName)49 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)47 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)44 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)42 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)42 Map (java.util.Map)38