Search in sources :

Example 86 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class BinaryKeyedJDBCStoreResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH) : parent.addChildResource(PATH);
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                final ModelNode model = resource.getModel();
                final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
                if (binaryTableModel != null && binaryTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.TABLE.getName()).set(binaryTableModel);
                }
                final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
                final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
                LegacyPropertyResourceTransformer.transformPropertiesToChildrenResources(properties, address, childContext);
                context.processChildren(resource);
            }
        });
    }
    BinaryTableResourceDefinition.buildTransformation(version, builder);
    JDBCStoreResourceDefinition.buildTransformation(version, builder);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext)

Example 87 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class NamingBindingResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(BINDING_TYPE).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
    resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    validateResourceModel(operation, false);
                    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
                    ModelNode model = resource.getModel();
                    for (AttributeDefinition attr : ATTRIBUTES) {
                        attr.validateAndSet(operation, model);
                    }
                    context.addStep(new OperationStepHandler() {

                        @Override
                        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                            final String name = context.getCurrentAddressValue();
                            final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
                            ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
                            if (service == null) {
                                context.reloadRequired();
                                return;
                            }
                            NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
                        }
                    }, OperationContext.Stage.RUNTIME);
                }
            }, OperationContext.Stage.MODEL);
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) BinderService(org.jboss.as.naming.service.BinderService) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 88 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class MixedKeyedJDBCStoreResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH) : parent.addChildResource(PATH);
    BinaryTableResourceDefinition.buildTransformation(version, builder);
    StringTableResourceDefinition.buildTransformation(version, builder);
    JDBCStoreResourceDefinition.buildTransformation(version, builder);
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                final ModelNode model = resource.getModel();
                final ModelNode binaryTableModel = Resource.Tools.readModel(resource.removeChild(BinaryTableResourceDefinition.PATH));
                if (binaryTableModel != null && binaryTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.BINARY_TABLE.getName()).set(binaryTableModel);
                }
                final ModelNode stringTableModel = Resource.Tools.readModel(resource.removeChild(StringTableResourceDefinition.PATH));
                if (stringTableModel != null && stringTableModel.isDefined()) {
                    model.get(DeprecatedAttribute.STRING_TABLE.getName()).set(stringTableModel);
                }
                final ModelNode properties = model.remove(StoreResourceDefinition.Attribute.PROPERTIES.getName());
                final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
                LegacyPropertyResourceTransformer.transformPropertiesToChildrenResources(properties, address, childContext);
                context.processChildren(resource);
            }
        });
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(new LegacyPropertyWriteOperationTransformer());
        }
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer)

Example 89 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class JDBCStoreResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) {
    if (InfinispanModel.VERSION_4_2_0.requiresTransformation(version) && !InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        // DATASOURCE attribute was only supported as an add operation parameter
        builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, DeprecatedAttribute.DATASOURCE.getDefinition());
    }
    if (InfinispanModel.VERSION_4_0_0.requiresTransformation(version)) {
        // Converts pool name to its JNDI name
        Converter converter = new Converter() {

            @Override
            public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) {
                if (value.isDefined()) {
                    PathAddress rootAddress = address.subAddress(0, address.size() - 4);
                    PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources"));
                    Resource subsystem = context.readResourceFromRoot(subsystemAddress);
                    String poolName = value.asString();
                    for (String type : Arrays.asList("data-source", "xa-data-source")) {
                        if (subsystem.hasChildren(type)) {
                            for (Resource.ResourceEntry entry : subsystem.getChildren(type)) {
                                if (entry.getName().equals(poolName)) {
                                    value.set(entry.getModel().get("jndi-name"));
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        };
        builder.getAttributeBuilder().addRename(Attribute.DATA_SOURCE.getName(), DeprecatedAttribute.DATASOURCE.getName()).setValueConverter(new SimpleAttributeConverter(converter), Attribute.DATA_SOURCE.getDefinition());
    }
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new LegacyPropertyAddOperationTransformer())).inheritResourceAttributeDefinitions();
    }
    if (InfinispanModel.VERSION_2_0_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.UNDEFINED, Attribute.DIALECT.getDefinition()).addRejectCheck(RejectAttributeChecker.DEFINED, Attribute.DIALECT.getDefinition()).end();
    }
    StoreResourceDefinition.buildTransformation(version, builder);
}
Also used : LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter) Converter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter.Converter) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext) SimpleAttributeConverter(org.jboss.as.clustering.controller.transform.SimpleAttributeConverter)

Example 90 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class InfinispanSubsystemInitialization method initializeExtraSubystemsAndModel.

@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry registry, Resource root, ManagementResourceRegistration registration, RuntimeCapabilityRegistry capabilityRegistry) {
    new DataSourcesExtension().initialize(registry.getExtensionContext("datasources", registration, ExtensionRegistryType.MASTER));
    Resource subsystem = Resource.Factory.create();
    root.registerChild(PathElement.pathElement(SUBSYSTEM, DataSourcesExtension.SUBSYSTEM_NAME), subsystem);
    Resource dataSource = Resource.Factory.create();
    subsystem.registerChild(PathElement.pathElement("data-source", "ExampleDS"), dataSource);
    dataSource.getModel().get("jndi-name").set("java:jboss/jdbc/store");
    super.initializeExtraSubystemsAndModel(registry, root, registration, capabilityRegistry);
}
Also used : DataSourcesExtension(org.jboss.as.connector.subsystems.datasources.DataSourcesExtension) Resource(org.jboss.as.controller.registry.Resource)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4