Search in sources :

Example 66 with OperationFailedException

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

the class TransportResourceDefinition method buildTransformation.

static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    AbstractProtocolResourceDefinition.addTransformations(version, builder);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.SHARED.getDefinition()), Attribute.SHARED.getDefinition());
        builder.setCustomResourceTransformer(new ResourceTransformer() {

            @Override
            public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
                new LegacyPropertyResourceTransformer().transformResource(context, LEGACY_ADDRESS_TRANSFORMER.transform(address), resource);
            }
        });
        builder.addOperationTransformationOverride(ModelDescriptionConstants.ADD).setCustomOperationTransformer(new SimpleOperationTransformer(new org.jboss.as.clustering.controller.transform.OperationTransformer() {

            @Override
            public ModelNode transformOperation(final ModelNode operation) {
                operation.get(ModelDescriptionConstants.OP_ADDR).set(LEGACY_ADDRESS_TRANSFORMER.transform(Operations.getPathAddress(operation)).toModelNode());
                return new LegacyPropertyAddOperationTransformer().transformOperation(operation);
            }
        })).inheritResourceAttributeDefinitions();
        builder.addOperationTransformationOverride(ModelDescriptionConstants.REMOVE).setCustomOperationTransformer(new SimpleRemoveOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        builder.addOperationTransformationOverride(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION).setCustomOperationTransformer(new SimpleReadAttributeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        builder.addOperationTransformationOverride(ModelDescriptionConstants.DESCRIBE).setCustomOperationTransformer(new SimpleDescribeOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        List<OperationTransformer> getOpTransformerChain = new LinkedList<>();
        getOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        getOpTransformerChain.add(new SimpleOperationTransformer(new LegacyPropertyMapGetOperationTransformer()));
        ChainedOperationTransformer getOpChainedTransformer = new ChainedOperationTransformer(getOpTransformerChain, false);
        builder.addRawOperationTransformationOverride(MapOperations.MAP_GET_DEFINITION.getName(), getOpChainedTransformer);
        List<OperationTransformer> writeOpTransformerChain = new LinkedList<>();
        writeOpTransformerChain.add(new SimplePathOperationTransformer(LEGACY_ADDRESS_TRANSFORMER));
        writeOpTransformerChain.add(new LegacyPropertyWriteOperationTransformer());
        ChainedOperationTransformer writeOpChainedTransformer = new ChainedOperationTransformer(writeOpTransformerChain, false);
        for (String opName : Operations.getAllWriteAttributeOperationNames()) {
            builder.addOperationTransformationOverride(opName).inheritResourceAttributeDefinitions().setCustomOperationTransformer(writeOpChainedTransformer);
        }
        // Reject thread pool configuration, discard if undefined, support EAP 6.x slaves using deprecated attributes
        builder.addChildResource(ThreadPoolResourceDefinition.WILDCARD_PATH, RequiredChildResourceDiscardPolicy.REJECT_AND_WARN);
    } else {
        EnumSet.allOf(ThreadPoolResourceDefinition.class).forEach(p -> p.buildTransformation(version, parent));
    }
}
Also used : SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) OperationTransformer(org.jboss.as.controller.transform.OperationTransformer) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) LegacyPropertyAddOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyAddOperationTransformer) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) LegacyPropertyWriteOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyWriteOperationTransformer) SimpleRemoveOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleRemoveOperationTransformer) LegacyPropertyMapGetOperationTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyMapGetOperationTransformer) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) SimplePathOperationTransformer(org.jboss.as.clustering.controller.transform.SimplePathOperationTransformer) SimpleReadAttributeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleReadAttributeOperationTransformer) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleDescribeOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleDescribeOperationTransformer) ResourceTransformationContext(org.jboss.as.controller.transform.ResourceTransformationContext) LinkedList(java.util.LinkedList) ChainedOperationTransformer(org.jboss.as.clustering.controller.transform.ChainedOperationTransformer) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) DefaultValueAttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter.DefaultValueAttributeConverter) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ResourceTransformer(org.jboss.as.controller.transform.ResourceTransformer) LegacyPropertyResourceTransformer(org.jboss.as.clustering.controller.transform.LegacyPropertyResourceTransformer) ModelNode(org.jboss.dmr.ModelNode)

Example 67 with OperationFailedException

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

the class StackOperationExecutor method execute.

@Override
public ModelNode execute(OperationContext context, Operation<ChannelFactory> operation) throws OperationFailedException {
    String stackName = context.getCurrentAddressValue();
    ServiceRegistry registry = context.getServiceRegistry(false);
    ServiceName serviceName = JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stackName);
    try {
        ServiceController<ChannelFactory> controller = ServiceContainerHelper.getService(registry, serviceName);
        ServiceController.Mode mode = controller.getMode();
        controller.setMode(ServiceController.Mode.ACTIVE);
        try {
            return operation.execute(controller.awaitValue());
        } finally {
            controller.setMode(mode);
        }
    } catch (InterruptedException e) {
        throw new OperationFailedException(e.getLocalizedMessage(), e);
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 68 with OperationFailedException

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

the class ProtocolMetricsHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    String name = Operations.getAttributeName(operation);
    try {
        Protocol protocol = this.locator.findProtocol(context);
        if (protocol != null) {
            Attribute attribute = getAttribute(protocol.getClass(), name);
            if (attribute != null) {
                FieldType type = FieldType.valueOf(attribute.getType());
                try {
                    ModelNode result = new ModelNode();
                    Object value = attribute.read(protocol);
                    if (value != null) {
                        type.setValue(result, value);
                    }
                    context.getResult().set(result);
                } catch (Exception e) {
                    context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.privilegedAccessExceptionForAttribute(name));
                }
            } else {
                context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
            }
        }
    } catch (ClassNotFoundException | ModuleLoadException e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    } finally {
        context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ManagedAttribute(org.jgroups.annotations.ManagedAttribute) AccessibleObject(java.lang.reflect.AccessibleObject) Protocol(org.jgroups.stack.Protocol) ModelNode(org.jboss.dmr.ModelNode) PrivilegedActionException(java.security.PrivilegedActionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException)

Example 69 with OperationFailedException

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

the class EEJndiViewExtension method handleModule.

private void handleModule(final JndiViewExtensionContext context, final DeploymentUnit deploymentUnit, final ModelNode modulesNode, final ServiceRegistry serviceRegistry) throws OperationFailedException {
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    // If it isn't an EE module, just return
    if (moduleDescription == null) {
        return;
    }
    final String appName = moduleDescription.getApplicationName();
    final String moduleName = moduleDescription.getModuleName();
    final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName());
    final ServiceName moduleContextName = ContextNames.contextServiceNameOfModule(appName, moduleName);
    final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName);
    if (moduleContextController != null) {
        final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue());
        try {
            context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null));
        } catch (NamingException e) {
            throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:module", appName, moduleName)));
        }
        final Collection<ComponentDescription> componentDescriptions = moduleDescription.getComponentDescriptions();
        for (ComponentDescription componentDescription : componentDescriptions) {
            final String componentName = componentDescription.getComponentName();
            final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName);
            final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName);
            if (compContextController != null) {
                final ModelNode componentNode = moduleNode.get("components").get(componentName);
                final NamingStore compStore = NamingStore.class.cast(compContextController.getValue());
                try {
                    context.addEntries(componentNode.get("java:comp"), new NamingContext(compStore, null));
                } catch (NamingException e) {
                    throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:comp", appName, moduleName, componentName)));
                }
            }
        }
    }
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) NamingException(javax.naming.NamingException) ModelNode(org.jboss.dmr.ModelNode) NamingContext(org.jboss.as.naming.NamingContext)

Example 70 with OperationFailedException

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

the class ImportJournalOperation method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != NORMAL) {
        throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("import-journal", NORMAL);
    }
    String file = FILE.resolveModelAttribute(context, operation).asString();
    final XmlDataImporter importer = new XmlDataImporter();
    TransportConfiguration transportConfiguration = createInVMTransportConfiguration(context);
    try (InputStream is = new FileInputStream(new File(file));
        ServerLocator serverLocator = ActiveMQClient.createServerLocator(false, transportConfiguration);
        ClientSessionFactory sf = serverLocator.createSessionFactory()) {
        ClientSession session = sf.createSession();
        importer.process(is, session);
    } catch (Exception e) {
        throw new OperationFailedException(e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) OperationFailedException(org.jboss.as.controller.OperationFailedException) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) File(java.io.File) FileInputStream(java.io.FileInputStream) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) OperationFailedException(org.jboss.as.controller.OperationFailedException) XmlDataImporter(org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter)

Aggregations

OperationFailedException (org.jboss.as.controller.OperationFailedException)113 ModelNode (org.jboss.dmr.ModelNode)86 PathAddress (org.jboss.as.controller.PathAddress)51 OperationContext (org.jboss.as.controller.OperationContext)49 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)34 ServiceName (org.jboss.msc.service.ServiceName)33 Resource (org.jboss.as.controller.registry.Resource)26 ServiceController (org.jboss.msc.service.ServiceController)19 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 PathElement (org.jboss.as.controller.PathElement)13 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 IOException (java.io.IOException)11 Map (java.util.Map)11 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)11 ArrayList (java.util.ArrayList)9 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)9 ContextNames (org.jboss.as.naming.deployment.ContextNames)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 List (java.util.List)6 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)6