Search in sources :

Example 86 with OperationFailedException

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

the class ReadAttributeTranslationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    ModelNode targetOperation = Operations.createReadAttributeOperation(context.getCurrentAddress(), this.targetAttribute);
    String targetName = this.targetAttribute.getName();
    // If attribute has no read handler, synthesize one
    Optional.ofNullable(context.getResourceRegistration().getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetName).getReadHandler()).orElse((ctx, op) -> {
        ModelNode model = ctx.readResource(PathAddress.EMPTY_ADDRESS).getModel();
        ModelNode result = ctx.getResult();
        if (model.hasDefined(targetName)) {
            result.set(model.get(targetName));
        } else if (Operations.isIncludeDefaults(op)) {
            result.set(this.targetAttribute.getDefinition().getDefaultValue());
        }
    }).execute(context, targetOperation);
    ModelNode result = context.getResult();
    result.set(this.translator.translate(context, result));
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) ModelNode(org.jboss.dmr.ModelNode)

Example 87 with OperationFailedException

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

the class MappingModuleDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    super.registerAddOperation(resourceRegistration, new AbstractAddStepHandler() {

        @Override
        protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
            for (AttributeDefinition attr : getAttributes()) {
                attr.validateAndSet(operation, model);
            }
        }
    }, OperationEntry.Flag.RESTART_NONE);
}
Also used : AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 88 with OperationFailedException

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

the class SecurityDomainAdd method processKeyStore.

private void processKeyStore(OperationContext context, ModelNode node, String name, KeyStoreConfig config) throws OperationFailedException {
    final ModelNode value = peek(node, name, PASSWORD);
    final ModelNode type = peek(node, name, TYPE);
    final ModelNode url = peek(node, name, URL);
    final ModelNode provider = peek(node, name, PROVIDER);
    final ModelNode providerArgument = peek(node, name, PROVIDER_ARGUMENT);
    if (value != null) {
        try {
            config.setKeyStorePassword(context.resolveExpressions(value).asString());
        } catch (Exception e) {
            throw SecurityLogger.ROOT_LOGGER.runtimeException(e);
        }
    }
    if (type != null) {
        config.setKeyStoreType(context.resolveExpressions(type).asString());
    }
    if (url != null) {
        try {
            config.setKeyStoreURL(context.resolveExpressions(url).asString());
        } catch (Exception e) {
            throw SecurityLogger.ROOT_LOGGER.runtimeException(e);
        }
    }
    if (provider != null) {
        config.setKeyStoreProvider(context.resolveExpressions(provider).asString());
    }
    if (providerArgument != null) {
        config.setKeyStoreProviderArgument(context.resolveExpressions(providerArgument).asString());
    }
}
Also used : ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException) IOException(java.io.IOException)

Example 89 with OperationFailedException

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

the class AbstractTimerManagementTestCase method triggerTimer.

protected void triggerTimer() throws Exception {
    final PathAddress address = getTimerAddress();
    final ModelNode operation = Util.createOperation("trigger", address);
    final ModelNode outcome = this.managementClient.getControllerClient().execute(operation);
    if (!Operations.isSuccessfulOutcome(outcome)) {
        throw new OperationFailedException(operation);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 90 with OperationFailedException

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

the class AbstractTimerManagementTestCase method getTimerDetails.

protected ModelNode getTimerDetails() throws Exception {
    final PathAddress address = getTimerAddress();
    final ModelNode operation = Util.createOperation("read-resource", address);
    operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(Boolean.toString(true));
    final ModelNode result = this.managementClient.getControllerClient().execute(operation);
    if (!Operations.isSuccessfulOutcome(result)) {
        throw new OperationFailedException(result.asString());
    }
    return result.get(ModelDescriptionConstants.RESULT);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

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