Search in sources :

Example 61 with ModelNode

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

the class ComplexResourceAdaptersSubsystemTestCase method testResourceAdapters.

@Test
public void testResourceAdapters() throws Exception {
    ModelNode model = getModel("ra.xml", "some.rar");
    if (model == null)
        return;
    // Check model..
    Properties params = ParseUtils.raCommonProperties();
    ModelNode raCommonModel = model.get("subsystem", "resource-adapters", "resource-adapter", "myRA");
    ParseUtils.checkModelParams(raCommonModel, params);
    Assert.assertEquals(raCommonModel.asString(), "A", raCommonModel.get("config-properties", "Property", "value").asString());
    Assert.assertEquals(raCommonModel.get("beanvalidationgroups").asString(), raCommonModel.get("beanvalidationgroups").asString(), "[\"Class0\",\"Class00\"]");
    params = ParseUtils.raAdminProperties();
    ModelNode raAdminModel = raCommonModel.get("admin-objects", "Pool2");
    ParseUtils.checkModelParams(raAdminModel, params);
    Assert.assertEquals(raAdminModel.asString(), "D", raAdminModel.get("config-properties", "Property", "value").asString());
    params = ParseUtils.raConnectionProperties();
    ModelNode raConnModel = raCommonModel.get("connection-definitions", "Pool1");
    ParseUtils.checkModelParams(raConnModel, params);
    Assert.assertEquals(raConnModel.asString(), "B", raConnModel.get("config-properties", "Property", "value").asString());
    Assert.assertEquals(raConnModel.asString(), "C", raConnModel.get("recovery-plugin-properties", "Property").asString());
}
Also used : ModelNode(org.jboss.dmr.ModelNode) Properties(java.util.Properties) Test(org.junit.Test)

Example 62 with ModelNode

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

the class ResourceAdapterSubsystemParser method writeRaElement.

private void writeRaElement(XMLExtendedStreamWriter streamWriter, ModelNode ra, final String name) throws XMLStreamException {
    streamWriter.writeStartElement(Activations.Tag.RESOURCE_ADAPTER.getLocalName());
    streamWriter.writeAttribute(ResourceAdapterParser.Attribute.ID.getLocalName(), name);
    STATISTICS_ENABLED.marshallAsAttribute(ra, streamWriter);
    ARCHIVE.marshallAsElement(ra, streamWriter);
    MODULE.marshallAsElement(ra, streamWriter);
    BOOTSTRAP_CONTEXT.marshallAsElement(ra, streamWriter);
    if (ra.hasDefined(BEANVALIDATION_GROUPS.getName())) {
        streamWriter.writeStartElement(Activation.Tag.BEAN_VALIDATION_GROUPS.getLocalName());
        for (ModelNode bvg : ra.get(BEANVALIDATION_GROUPS.getName()).asList()) {
            streamWriter.writeStartElement(BEANVALIDATION_GROUPS.getXmlName());
            streamWriter.writeCharacters(bvg.asString());
            streamWriter.writeEndElement();
        }
        streamWriter.writeEndElement();
    }
    TRANSACTION_SUPPORT.marshallAsElement(ra, streamWriter);
    writeNewConfigProperties(streamWriter, ra);
    TransactionSupportEnum transactionSupport = ra.hasDefined(TRANSACTION_SUPPORT.getName()) ? TransactionSupportEnum.valueOf(ra.get(TRANSACTION_SUPPORT.getName()).asString()) : null;
    boolean isXa = false;
    if (transactionSupport == TransactionSupportEnum.XATransaction) {
        isXa = true;
    }
    if (ra.hasDefined(WM_SECURITY.getName()) && ra.get(WM_SECURITY.getName()).asBoolean()) {
        streamWriter.writeStartElement(Activation.Tag.WORKMANAGER.getLocalName());
        streamWriter.writeStartElement(WorkManager.Tag.SECURITY.getLocalName());
        WM_SECURITY_MAPPING_REQUIRED.marshallAsElement(ra, streamWriter);
        WM_SECURITY_DOMAIN.marshallAsElement(ra, streamWriter);
        WM_ELYTRON_SECURITY_DOMAIN.marshallAsElement(ra, streamWriter);
        WM_SECURITY_DEFAULT_PRINCIPAL.marshallAsElement(ra, streamWriter);
        if (ra.hasDefined(WM_SECURITY_DEFAULT_GROUPS.getName())) {
            streamWriter.writeStartElement(WM_SECURITY_DEFAULT_GROUPS.getXmlName());
            for (ModelNode group : ra.get(WM_SECURITY_DEFAULT_GROUPS.getName()).asList()) {
                streamWriter.writeStartElement(WM_SECURITY_DEFAULT_GROUP.getXmlName());
                streamWriter.writeCharacters(group.asString());
                streamWriter.writeEndElement();
            }
            streamWriter.writeEndElement();
        }
        if (ra.hasDefined(WM_SECURITY_MAPPING_USERS.getName()) || ra.hasDefined(WM_SECURITY_MAPPING_GROUPS.getName())) {
            streamWriter.writeStartElement(WorkManagerSecurity.Tag.MAPPINGS.getLocalName());
            if (ra.hasDefined(WM_SECURITY_MAPPING_USERS.getName())) {
                streamWriter.writeStartElement(WorkManagerSecurity.Tag.USERS.getLocalName());
                for (ModelNode node : ra.get(WM_SECURITY_MAPPING_USERS.getName()).asList()) {
                    streamWriter.writeStartElement(WorkManagerSecurity.Tag.MAP.getLocalName());
                    WM_SECURITY_MAPPING_FROM.marshallAsAttribute(node, streamWriter);
                    WM_SECURITY_MAPPING_TO.marshallAsAttribute(node, streamWriter);
                    streamWriter.writeEndElement();
                }
                streamWriter.writeEndElement();
            }
            if (ra.hasDefined(WM_SECURITY_MAPPING_GROUPS.getName())) {
                streamWriter.writeStartElement(WorkManagerSecurity.Tag.GROUPS.getLocalName());
                for (ModelNode node : ra.get(WM_SECURITY_MAPPING_GROUPS.getName()).asList()) {
                    streamWriter.writeStartElement(WorkManagerSecurity.Tag.MAP.getLocalName());
                    WM_SECURITY_MAPPING_FROM.marshallAsAttribute(node, streamWriter);
                    WM_SECURITY_MAPPING_TO.marshallAsAttribute(node, streamWriter);
                    streamWriter.writeEndElement();
                }
                streamWriter.writeEndElement();
            }
            streamWriter.writeEndElement();
        }
        streamWriter.writeEndElement();
        streamWriter.writeEndElement();
    }
    if (ra.hasDefined(CONNECTIONDEFINITIONS_NAME)) {
        streamWriter.writeStartElement(Activation.Tag.CONNECTION_DEFINITIONS.getLocalName());
        for (Property conDef : ra.get(CONNECTIONDEFINITIONS_NAME).asPropertyList()) {
            writeConDef(streamWriter, conDef.getValue(), conDef.getName(), isXa);
        }
        streamWriter.writeEndElement();
    }
    if (ra.hasDefined(ADMIN_OBJECTS_NAME)) {
        streamWriter.writeStartElement(Activation.Tag.ADMIN_OBJECTS.getLocalName());
        for (Property adminObject : ra.get(ADMIN_OBJECTS_NAME).asPropertyList()) {
            writeAdminObject(streamWriter, adminObject.getValue(), adminObject.getName());
        }
        streamWriter.writeEndElement();
    }
    streamWriter.writeEndElement();
}
Also used : TransactionSupportEnum(org.jboss.jca.common.api.metadata.common.TransactionSupportEnum) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 63 with ModelNode

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

the class DatasourcesSubsystemTestCase method testTransformer.

/**
     * Tests transformation of model from latest version into one passed into modelVersion parameter.
     *
     * @throws Exception
     */
private void testTransformer(String subsystemXml, ModelTestControllerVersion controllerVersion, final ModelVersion modelVersion) throws Exception {
    //Use the non-runtime version of the extension which will happen on the HC
    KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT);
    KernelServices mainServices = initialKernelServices(builder, controllerVersion, modelVersion);
    List<ModelNode> ops = builder.parseXmlResource(subsystemXml);
    PathAddress subsystemAddress = PathAddress.pathAddress(DataSourcesSubsystemRootDefinition.PATH_SUBSYSTEM);
    ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, ops, new FailedOperationTransformationConfig().addFailedAttribute(subsystemAddress.append(DataSourceDefinition.PATH_DATASOURCE), new FailedOperationTransformationConfig.NewAttributesConfig(TRACKING)).addFailedAttribute(subsystemAddress.append(XaDataSourceDefinition.PATH_XA_DATASOURCE), new FailedOperationTransformationConfig.NewAttributesConfig(TRACKING)));
}
Also used : FailedOperationTransformationConfig(org.jboss.as.model.test.FailedOperationTransformationConfig) PathAddress(org.jboss.as.controller.PathAddress) KernelServices(org.jboss.as.subsystem.test.KernelServices) ModelNode(org.jboss.dmr.ModelNode) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder)

Example 64 with ModelNode

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

the class DatasourcesSubsystemTestCase method testTransformerElytronEnabled.

/**
     * Tests transformation of model from latest version into one passed into modelVersion parameter.
     *
     * @throws Exception
     */
private void testTransformerElytronEnabled(String subsystemXml, ModelTestControllerVersion controllerVersion, final ModelVersion modelVersion) throws Exception {
    //Use the non-runtime version of the extension which will happen on the HC
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization());
    KernelServices mainServices = initialKernelServices(builder, controllerVersion, modelVersion);
    List<ModelNode> ops = builder.parseXmlResource(subsystemXml);
    PathAddress subsystemAddress = PathAddress.pathAddress(DataSourcesSubsystemRootDefinition.PATH_SUBSYSTEM);
    ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, ops, new FailedOperationTransformationConfig().addFailedAttribute(subsystemAddress.append(DataSourceDefinition.PATH_DATASOURCE), new FailedOperationTransformationConfig.NewAttributesConfig(TRACKING, ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE)).addFailedAttribute(subsystemAddress.append(XaDataSourceDefinition.PATH_XA_DATASOURCE), new FailedOperationTransformationConfig.NewAttributesConfig(TRACKING, ELYTRON_ENABLED, AUTHENTICATION_CONTEXT, RECOVERY_ELYTRON_ENABLED, RECOVERY_AUTHENTICATION_CONTEXT, CREDENTIAL_REFERENCE, RECOVERY_CREDENTIAL_REFERENCE) {

        @Override
        protected boolean isAttributeWritable(String attributeName) {
            return false;
        }

        @Override
        protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) {
            if (attribute.isDefined()) {
                return true;
            } else {
                return false;
            }
        }

        @Override
        protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) {
            return new ModelNode();
        }
    }));
}
Also used : FailedOperationTransformationConfig(org.jboss.as.model.test.FailedOperationTransformationConfig) PathAddress(org.jboss.as.controller.PathAddress) KernelServices(org.jboss.as.subsystem.test.KernelServices) ModelNode(org.jboss.dmr.ModelNode) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder)

Example 65 with ModelNode

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

the class JcaSubsystemTestCase method testTransformerWF.

/**
     * Tests transformation of model from 1.2.0 version into 1.1.0 version.
     *
     * @throws Exception
     */
private void testTransformerWF(ModelTestControllerVersion controllerVersion, ModelVersion modelVersion, String xmlResourceName) throws Exception {
    // create builder for current subsystem version
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXmlResource(xmlResourceName);
    // create builder for legacy subsystem version
    builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion).addMavenResourceURL("org.wildfly:wildfly-connector:" + controllerVersion.getMavenGavVersion()).addMavenResourceURL("org.wildfly:wildfly-threads:" + controllerVersion.getMavenGavVersion()).setExtensionClassName("org.jboss.as.connector.subsystems.jca.JcaExtension").excludeFromParent(SingleClassFilter.createFilter(ConnectorLogger.class)).configureReverseControllerCheck(AdditionalInitialization.MANAGEMENT, new ModelFixer() {

        @Override
        public ModelNode fixModel(ModelNode modelNode) {
            //These two are true in the original model but get removed by the transformers, so they default to false. Set them to true
            //modelNode.get(Constants.TRACER, Constants.TRACER). add(new ModelNode(Constants.TRACER));
            //.add(Constants.TRACER);
            modelNode.get(Constants.TRACER, Constants.TRACER, TracerDefinition.TracerParameters.TRACER_ENABLED.getAttribute().getName()).set(true);
            return modelNode;
        }
    });
    KernelServices mainServices = builder.build();
    KernelServices legacyServices = mainServices.getLegacyServices(modelVersion);
    Assert.assertNotNull(legacyServices);
    assertTrue("main services did not boot", mainServices.isSuccessfulBoot());
    assertTrue(legacyServices.isSuccessfulBoot());
    checkSubsystemModelTransformation(mainServices, modelVersion);
}
Also used : KernelServices(org.jboss.as.subsystem.test.KernelServices) ModelFixer(org.jboss.as.model.test.ModelFixer) ModelNode(org.jboss.dmr.ModelNode) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder)

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