Search in sources :

Example 21 with Resource

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

the class LogStoreProbeHandler method probeTransactions.

private Resource probeTransactions(MBeanServer mbs, boolean exposeAllLogs) throws OperationFailedException {
    try {
        ObjectName on = new ObjectName(osMBeanName);
        mbs.setAttribute(on, new javax.management.Attribute("ExposeAllRecordsAsMBeans", Boolean.valueOf(exposeAllLogs)));
        mbs.invoke(on, "probe", null, null);
        Set<ObjectInstance> transactions = mbs.queryMBeans(new ObjectName(osMBeanName + ",*"), null);
        final Resource resource = Resource.Factory.create();
        addTransactions(resource, transactions, mbs);
        return resource;
    } catch (JMException e) {
        throw new OperationFailedException("Transaction discovery error: ", e);
    } catch (IOException e) {
        throw new OperationFailedException("Transaction discovery error: ", e);
    }
}
Also used : ObjectInstance(javax.management.ObjectInstance) Resource(org.jboss.as.controller.registry.Resource) JMException(javax.management.JMException) OperationFailedException(org.jboss.as.controller.OperationFailedException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Example 22 with Resource

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

the class LogStoreTransactionDeleteHandler method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    MBeanServer mbs = TransactionExtension.getMBeanServer(context);
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    try {
        final ObjectName on = LogStoreResource.getObjectName(resource);
        //  Invoke operation
        Object res = mbs.invoke(on, "remove", null, null);
        try {
            // validate that the MBean was removed:
            mbs.getObjectInstance(on);
            String reason = res != null ? res.toString() : LOG_DELETE_FAILURE_MESSAGE;
            throw new OperationFailedException(reason);
        } catch (InstanceNotFoundException e) {
            // success, the MBean was deleted
            final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
            final PathElement element = address.getLastElement();
            logStoreResource.removeChild(element);
        }
    } catch (OperationFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new OperationFailedException(e.getMessage());
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : PathElement(org.jboss.as.controller.PathElement) InstanceNotFoundException(javax.management.InstanceNotFoundException) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 23 with Resource

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

the class RelayConfigurationBuilder method configure.

@Override
public Builder<RelayConfiguration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.siteName = SITE.resolveModelAttribute(context, model).asString();
    PathAddress address = context.getCurrentAddress();
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    this.sites = resource.getChildren(RemoteSiteResourceDefinition.WILDCARD_PATH.getKey()).stream().map(entry -> new InjectedValueDependency<>(new RemoteSiteServiceNameProvider(address, entry.getPathElement()), RemoteSiteConfiguration.class)).collect(Collectors.toList());
    return super.configure(context, model);
}
Also used : RemoteSiteConfiguration(org.wildfly.clustering.jgroups.spi.RemoteSiteConfiguration) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 24 with Resource

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

the class ProtocolResourceRegistrationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {

        @Override
        public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
            return Collections.emptyMap();
        }

        @Override
        public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
            StandardResourceDescriptionResolver resolver = new JGroupsResourceDescriptionResolver();
            String description = resolver.getChildTypeDescription(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), locale, resolver.getResourceBundle(locale));
            ModelNode result = new ModelNode();
            result.get(ModelDescriptionConstants.DESCRIPTION).set(description);
            return Collections.singletonMap(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), result);
        }
    };
    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    String stack = STACK.resolveModelAttribute(context, resource.getModel()).asString();
    ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate().registerOverrideModel(context.getCurrentAddressValue(), provider);
    PathAddress stackAddress = context.getCurrentAddress().getParent().append(StackResourceDefinition.pathElement(stack));
    Resource stackResource = context.readResourceFromRoot(stackAddress, false);
    for (String name : stackResource.getChildrenNames(TransportResourceDefinition.WILDCARD_PATH.getKey())) {
        PathAddress transportAddress = stackAddress.append(TransportResourceDefinition.pathElement(name));
        ModelNode transport = context.readResourceFromRoot(transportAddress, false).getModel();
        String moduleName = MODULE.resolveModelAttribute(context, transport).asString();
        Class<? extends Protocol> transportClass = findProtocolClass(context, name, moduleName);
        registration.registerSubModel(this.createProtocolResourceDefinition(name, transportClass));
        resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
    }
    for (String name : stackResource.getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
        Resource protocolResource = context.readResourceFromRoot(stackAddress.append(ProtocolResourceDefinition.pathElement(name)), false);
        String moduleName = MODULE.resolveModelAttribute(context, protocolResource.getModel()).asString();
        Class<? extends Protocol> protocolClass = findProtocolClass(context, name, moduleName);
        registration.registerSubModel(this.createProtocolResourceDefinition(name, protocolClass));
        resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
    }
    if (stackResource.hasChild(RelayResourceDefinition.PATH)) {
        registration.registerSubModel(this.createProtocolResourceDefinition(RelayConfiguration.PROTOCOL_NAME, RELAY2.class));
        resource.registerChild(ProtocolResourceDefinition.pathElement(RelayConfiguration.PROTOCOL_NAME), PlaceholderResource.INSTANCE);
    }
}
Also used : Locale(java.util.Locale) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) PlaceholderResource(org.jboss.as.controller.registry.PlaceholderResource) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) RELAY2(org.jgroups.protocols.relay.RELAY2)

Example 25 with Resource

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

the class TransactionResourceDefinition method buildTransformation.

@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH, RequiredChildResourceDiscardPolicy.NEVER) : parent.addChildResource(PATH);
    List<org.jboss.as.controller.transform.OperationTransformer> addOperationTransformers = new LinkedList<>();
    List<org.jboss.as.controller.transform.OperationTransformer> removeOperationTransformers = new LinkedList<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> readAttributeTransformers = new HashMap<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> writeAttributeTransformers = new HashMap<>();
    Map<String, org.jboss.as.controller.transform.OperationTransformer> undefineAttributeTransformers = new HashMap<>();
    if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
        // Convert BATCH -> NONE, and include write-attribute:name=batching
        OperationTransformer addTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                if (operation.hasDefined(Attribute.MODE.getName())) {
                    ModelNode mode = operation.get(Attribute.MODE.getName());
                    if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
                        mode.set(TransactionMode.NONE.name());
                        PathAddress address = Operations.getPathAddress(operation);
                        return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(true)));
                    }
                }
                return operation;
            }
        };
        addOperationTransformers.add(new SimpleOperationTransformer(addTransformer));
        // Additionally include undefine-attribute:name=batching
        OperationTransformer removeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
            }
        };
        removeOperationTransformers.add(new SimpleOperationTransformer(removeTransformer));
        // If read-attribute:name=batching is true, return BATCH, otherwise use result from read-attribute:name=mode
        OperationTransformer readAttributeOperationTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(Operations.createReadAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING), operation);
            }
        };
        OperationResultTransformer readAttributeResultTransformer = new OperationResultTransformer() {

            @Override
            public ModelNode transformResult(ModelNode result) {
                ModelNode readBatchingResult = result.get(0);
                return readBatchingResult.asBoolean() ? new ModelNode(TransactionMode.BATCH.name()) : result.get(1);
            }
        };
        readAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(readAttributeOperationTransformer, readAttributeResultTransformer));
        // Convert BATCH -> NONE, and include write-attribute:name=batching
        OperationTransformer writeAttributeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                ModelNode mode = Operations.getAttributeValue(operation);
                boolean batching = (mode.isDefined() && (mode.getType() == ModelType.STRING)) ? (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH) : false;
                if (batching) {
                    mode.set(TransactionMode.NONE.name());
                }
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(batching)));
            }
        };
        writeAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(writeAttributeTransformer));
        // Include undefine-attribute:name=batching
        OperationTransformer undefineAttributeTransformer = new OperationTransformer() {

            @Override
            public ModelNode transformOperation(ModelNode operation) {
                PathAddress address = Operations.getPathAddress(operation);
                return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
            }
        };
        undefineAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(undefineAttributeTransformer));
        // Convert BATCH -> NONE
        ResourceTransformer modeTransformer = new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                ModelNode model = resource.getModel();
                if (model.hasDefined(Attribute.MODE.getName())) {
                    ModelNode value = model.get(Attribute.MODE.getName());
                    if ((value.getType() == ModelType.STRING) && (TransactionMode.valueOf(value.asString()) == TransactionMode.BATCH)) {
                        value.set(TransactionMode.NONE.name());
                    }
                }
                context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
            }
        };
        builder.setCustomResourceTransformer(modeTransformer);
        // change default value of stop-timeout attribute
        builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.STOP_TIMEOUT.getDefinition()), Attribute.STOP_TIMEOUT.getDefinition());
    }
    buildOperationTransformation(builder, ModelDescriptionConstants.ADD, addOperationTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.REMOVE, removeOperationTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION, readAttributeTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION, writeAttributeTransformers);
    buildOperationTransformation(builder, ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION, undefineAttributeTransformers);
}
Also used : OperationResultTransformer(org.jboss.as.controller.transform.OperationResultTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) AttributeOperationTransformer(org.jboss.as.clustering.controller.transform.AttributeOperationTransformer) OperationTransformer(org.jboss.as.clustering.controller.transform.OperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) HashMap(java.util.HashMap) Resource(org.jboss.as.controller.registry.Resource) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) ModelNode(org.jboss.dmr.ModelNode) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer)

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