Search in sources :

Example 1 with ProcessType

use of org.jboss.as.controller.ProcessType 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 as first
            LinkedHashMap<PathAddress, ModelNode> orderedMigrationOperations = new LinkedHashMap<>();
            removeWebSubsystem(orderedMigrationOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER, pathAddress(operation.get(ADDRESS)));
            orderedMigrationOperations.putAll(sortedMigrationOperations);
            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)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)1 PathAddress (org.jboss.as.controller.PathAddress)1 ProcessType (org.jboss.as.controller.ProcessType)1 ModelNode (org.jboss.dmr.ModelNode)1