Search in sources :

Example 1 with OperationFailedException

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

the class WebMigrateOperation method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (!describe && context.getRunningMode() != RunningMode.ADMIN_ONLY) {
        throw WebLogger.ROOT_LOGGER.migrateOperationAllowedOnlyInAdminOnly();
    }
    final List<String> warnings = new ArrayList<>();
    // node containing the description (list of add operations) of the legacy subsystem
    final ModelNode legacyModelAddOps = new ModelNode();
    //we don't preserve order, instead we sort by address length
    final Map<PathAddress, ModelNode> sortedMigrationOperations = new TreeMap<>(new Comparator<PathAddress>() {

        @Override
        public int compare(PathAddress o1, PathAddress o2) {
            final int compare = Integer.compare(o1.size(), o2.size());
            if (compare != 0) {
                return compare;
            }
            return o1.toString().compareTo(o2.toString());
        }
    });
    // invoke an OSH to describe the legacy messaging subsystem
    describeLegacyWebResources(context, legacyModelAddOps);
    // invoke an OSH to add the messaging-activemq extension
    // FIXME: this does not work it the extension :add is added to the migrationOperations directly (https://issues.jboss.org/browse/WFCORE-323)
    addExtension(context, sortedMigrationOperations, describe, UNDERTOW_EXTENSION);
    addExtension(context, sortedMigrationOperations, describe, IO_EXTENSION);
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            addDefaultResources(sortedMigrationOperations, legacyModelAddOps, warnings);
            // transform the legacy add operations and put them in migrationOperations
            ProcessType processType = context.getCallEnvironment().getProcessType();
            boolean domainMode = processType != ProcessType.STANDALONE_SERVER && processType != ProcessType.SELF_CONTAINED;
            PathAddress baseAddres;
            if (domainMode) {
                baseAddres = pathAddress(operation.get(ADDRESS)).getParent();
            } else {
                baseAddres = pathAddress();
            }
            //create the new IO subsystem
            createIoSubsystem(context, sortedMigrationOperations, baseAddres);
            createWelcomeContentHandler(sortedMigrationOperations);
            transformResources(context, legacyModelAddOps, sortedMigrationOperations, warnings, domainMode);
            fixAddressesForDomainMode(pathAddress(operation.get(ADDRESS)), sortedMigrationOperations);
            // put the /subsystem=web:remove operation
            //we need the removes to be last, so we create a new linked hash map and add our sorted ops to it
            LinkedHashMap<PathAddress, ModelNode> orderedMigrationOperations = new LinkedHashMap<>(sortedMigrationOperations);
            removeWebSubsystem(orderedMigrationOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER, pathAddress(operation.get(ADDRESS)));
            if (describe) {
                // :describe-migration operation
                // for describe-migration operation, do nothing and return the list of operations that would
                // be executed in the composite operation
                final Collection<ModelNode> values = orderedMigrationOperations.values();
                ModelNode result = new ModelNode();
                if (!warnings.isEmpty()) {
                    ModelNode rw = new ModelNode().setEmptyList();
                    for (String warning : warnings) {
                        rw.add(warning);
                    }
                    result.get(MIGRATION_WARNINGS).set(rw);
                }
                result.get(MIGRATION_OPERATIONS).set(values);
                context.getResult().set(result);
            } else {
                // :migrate operation
                // invoke an OSH on a composite operation with all the migration operations
                final Map<PathAddress, ModelNode> migrateOpResponses = migrateSubsystems(context, orderedMigrationOperations);
                context.completeStep(new OperationContext.ResultHandler() {

                    @Override
                    public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
                        final ModelNode result = new ModelNode();
                        ModelNode rw = new ModelNode().setEmptyList();
                        for (String warning : warnings) {
                            rw.add(warning);
                        }
                        result.get(MIGRATION_WARNINGS).set(rw);
                        if (resultAction == OperationContext.ResultAction.ROLLBACK) {
                            for (Map.Entry<PathAddress, ModelNode> entry : migrateOpResponses.entrySet()) {
                                if (entry.getValue().hasDefined(FAILURE_DESCRIPTION)) {
                                    //we check for failure description, as every node has 'failed', but one
                                    //the real error has a failure description
                                    //we break when we find the first one, as there will only ever be one failure
                                    //as the op stops after the first failure
                                    ModelNode desc = new ModelNode();
                                    desc.get(OP).set(orderedMigrationOperations.get(entry.getKey()));
                                    desc.get(RESULT).set(entry.getValue());
                                    result.get(MIGRATION_ERROR).set(desc);
                                    break;
                                }
                            }
                            context.getFailureDescription().set(new ModelNode(WebLogger.ROOT_LOGGER.migrationFailed()));
                        }
                        context.getResult().set(result);
                    }
                });
            }
        }
    }, MODEL);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) ProcessType(org.jboss.as.controller.ProcessType) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 2 with OperationFailedException

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

the class MigrateOperation method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (!describe && context.getRunningMode() != RunningMode.ADMIN_ONLY) {
        throw ROOT_LOGGER.migrateOperationAllowedOnlyInAdminOnly();
    }
    boolean addLegacyEntries = ADD_LEGACY_ENTRIES.resolveModelAttribute(context, operation).asBoolean();
    final List<String> warnings = new ArrayList<>();
    // node containing the description (list of add operations) of the legacy subsystem
    final ModelNode legacyModelAddOps = new ModelNode();
    // preserve the order of insertion of the add operations for the new subsystem.
    final Map<PathAddress, ModelNode> migrationOperations = new LinkedHashMap<PathAddress, ModelNode>();
    // invoke an OSH to describe the legacy messaging subsystem
    describeLegacyMessagingResources(context, legacyModelAddOps);
    // invoke an OSH to add the messaging-activemq extension
    // FIXME: this does not work it the extension :add is added to the migrationOperations directly (https://issues.jboss.org/browse/WFCORE-323)
    addMessagingActiveMQExtension(context, migrationOperations, describe);
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            // transform the legacy add operations and put them in migrationOperations
            transformResources(context, legacyModelAddOps, migrationOperations, addLegacyEntries, warnings);
            // put the /subsystem=messaging:remove operation
            removeMessagingSubsystem(migrationOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER);
            PathAddress parentAddress = context.getCurrentAddress().getParent();
            fixAddressesForDomainMode(parentAddress, migrationOperations);
            if (describe) {
                // :describe-migration operation
                // for describe-migration operation, do nothing and return the list of operations that would
                // be executed in the composite operation
                final Collection<ModelNode> values = migrationOperations.values();
                ModelNode result = new ModelNode();
                fillWarnings(result, warnings);
                result.get(MIGRATION_OPERATIONS).set(values);
                context.getResult().set(result);
            } else {
                // :migrate operation
                // invoke an OSH on a composite operation with all the migration operations
                final Map<PathAddress, ModelNode> migrateOpResponses = migrateSubsystems(context, migrationOperations);
                context.completeStep(new OperationContext.ResultHandler() {

                    @Override
                    public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
                        final ModelNode result = new ModelNode();
                        fillWarnings(result, warnings);
                        if (resultAction == OperationContext.ResultAction.ROLLBACK) {
                            for (Map.Entry<PathAddress, ModelNode> entry : migrateOpResponses.entrySet()) {
                                if (entry.getValue().hasDefined(FAILURE_DESCRIPTION)) {
                                    //we check for failure description, as every node has 'failed', but one
                                    //the real error has a failure description
                                    //we break when we find the first one, as there will only ever be one failure
                                    //as the op stops after the first failure
                                    ModelNode desc = new ModelNode();
                                    desc.get(OP).set(migrationOperations.get(entry.getKey()));
                                    desc.get(RESULT).set(entry.getValue());
                                    result.get(MIGRATION_ERROR).set(desc);
                                    break;
                                }
                            }
                            context.getFailureDescription().set(ROOT_LOGGER.migrationFailed());
                        }
                        context.getResult().set(result);
                    }
                });
            }
        }
    }, MODEL);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedHashMap(java.util.LinkedHashMap) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with OperationFailedException

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

the class JMSTopicRemove method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final String name = context.getCurrentAddress().getLastElement().getValue();
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    JMSServerControl control = JMSServerControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_SERVER));
    if (control != null) {
        try {
            control.destroyTopic(name, true);
        } catch (Exception e) {
            throw new OperationFailedException(e);
        }
    }
    context.removeService(JMSServices.getJmsTopicBaseServiceName(serviceName).append(name));
    for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(entry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
    for (String legacyEntry : CommonAttributes.LEGACY_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(legacyEntry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
}
Also used : JMSServerControl(org.apache.activemq.artemis.api.jms.management.JMSServerControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 4 with OperationFailedException

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

the class ServerAdd method processStorageConfiguration.

private static void processStorageConfiguration(OperationContext context, ModelNode model, Configuration configuration) throws OperationFailedException {
    ModelNode journalDataSource = JOURNAL_DATASOURCE.resolveModelAttribute(context, model);
    if (!journalDataSource.isDefined()) {
        return;
    }
    DatabaseStorageConfiguration storageConfiguration = new DatabaseStorageConfiguration();
    storageConfiguration.setBindingsTableName(JOURNAL_BINDINGS_TABLE.resolveModelAttribute(context, model).asString());
    storageConfiguration.setMessageTableName(JOURNAL_MESSAGES_TABLE.resolveModelAttribute(context, model).asString());
    storageConfiguration.setLargeMessageTableName(JOURNAL_LARGE_MESSAGES_TABLE.resolveModelAttribute(context, model).asString());
    storageConfiguration.setPageStoreTableName(JOURNAL_PAGE_STORE_TABLE.resolveModelAttribute(context, model).asString());
    ModelNode databaseNode = JOURNAL_DATABASE.resolveModelAttribute(context, model);
    final String database = databaseNode.isDefined() ? databaseNode.asString() : null;
    try {
        storageConfiguration.setSqlProvider(new PropertySQLProviderFactory(database));
    } catch (IOException e) {
        throw new OperationFailedException(e);
    }
    configuration.setStoreConfiguration(storageConfiguration);
}
Also used : DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 5 with OperationFailedException

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

the class JMSQueueReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (ignoreOperationIfServerNotActive(context, operation)) {
        return;
    }
    validator.validate(operation);
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    JMSQueueControl control = getControl(context, operation);
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    if (CommonAttributes.MESSAGE_COUNT.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.getMessageCount());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.SCHEDULED_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getScheduledCount());
    } else if (CommonAttributes.CONSUMER_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getConsumerCount());
    } else if (CommonAttributes.DELIVERING_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getDeliveringCount());
    } else if (CommonAttributes.MESSAGES_ADDED.getName().equals(attributeName)) {
        context.getResult().set(control.getMessagesAdded());
    } else if (JMSQueueDefinition.QUEUE_ADDRESS.getName().equals(attributeName)) {
        context.getResult().set(control.getAddress());
    } else if (JMSQueueDefinition.EXPIRY_ADDRESS.getName().equals(attributeName)) {
        // create the result node in all cases
        ModelNode result = context.getResult();
        String expiryAddress = control.getExpiryAddress();
        if (expiryAddress != null) {
            result.set(expiryAddress);
        }
    } else if (JMSQueueDefinition.DEAD_LETTER_ADDRESS.getName().equals(attributeName)) {
        // create the result node in all cases
        ModelNode result = context.getResult();
        String dla = control.getDeadLetterAddress();
        if (dla != null) {
            result.set(dla);
        }
    } else if (CommonAttributes.PAUSED.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.isPaused());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.TEMPORARY.getName().equals(attributeName)) {
        context.getResult().set(control.isTemporary());
    } else {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
}
Also used : JMSQueueControl(org.apache.activemq.artemis.api.jms.management.JMSQueueControl) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

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