Search in sources :

Example 26 with ModelNode

use of org.jboss.dmr.ModelNode 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 27 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class MigrateOperation method fixAddressesForDomainMode.

/**
     * In domain mode, the subsystem are under /profile=XXX.
     * This method fixes the address by prepending the addresses (that start with /subsystem) with the current
     * operation parent so that is works both in standalone (parent = EMPTY_ADDRESS) and domain mode
     * (parent = /profile=XXX)
     */
private void fixAddressesForDomainMode(PathAddress parentAddress, Map<PathAddress, ModelNode> migrationOperations) {
    // in standalone mode, do nothing
    if (parentAddress.size() == 0) {
        return;
    }
    // use a linked hash map to preserve operations order
    Map<PathAddress, ModelNode> fixedMigrationOperations = new LinkedHashMap<>(migrationOperations);
    migrationOperations.clear();
    for (Map.Entry<PathAddress, ModelNode> entry : fixedMigrationOperations.entrySet()) {
        PathAddress fixedAddress = parentAddress.append(entry.getKey());
        entry.getValue().get(ADDRESS).set(fixedAddress.toModelNode());
        migrationOperations.put(fixedAddress, entry.getValue());
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class MigrateOperation method connectionFactoryIsUsingInVMConnectors.

private boolean connectionFactoryIsUsingInVMConnectors(OperationContext context, ModelNode connectionFactoryAddOp) {
    ModelNode connector = connectionFactoryAddOp.get(CONNECTOR);
    if (connector.isDefined()) {
        PathAddress connectionFactoryAddress = pathAddress(connectionFactoryAddOp.get(OP_ADDR));
        PathElement relativeLegacyServerAddress = connectionFactoryAddress.getParent().getLastElement();
        // read the server resource related to the context current address (which is the messaging subsystem address).
        Resource serverResource = context.readResource(pathAddress(relativeLegacyServerAddress), false);
        Set<String> definedInVMConnectors = serverResource.getChildrenNames("in-vm-connector");
        // legacy connector is a property list where the name is the connector and the value is undefined
        List<Property> connectorProps = connector.asPropertyList();
        for (Property connectorProp : connectorProps) {
            String connectorName = connectorProp.getName();
            if (definedInVMConnectors.contains(connectorName)) {
                return true;
            }
        }
    }
    return false;
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 29 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class MigrateOperation method describeLegacyMessagingResources.

private void describeLegacyMessagingResources(OperationContext context, ModelNode legacyModelDescription) {
    ModelNode describeLegacySubsystem = createOperation(GenericSubsystemDescribeHandler.DEFINITION, context.getCurrentAddress());
    context.addStep(legacyModelDescription, describeLegacySubsystem, GenericSubsystemDescribeHandler.INSTANCE, MODEL, true);
}
Also used : ModelNode(org.jboss.dmr.ModelNode)

Example 30 with ModelNode

use of org.jboss.dmr.ModelNode in project wildfly by wildfly.

the class MigrateOperation method addMessagingActiveMQExtension.

/**
     * It's possible that the extension is already present. In that case, this method does nothing.
     */
private void addMessagingActiveMQExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe) {
    Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
    if (root.getChildrenNames(EXTENSION).contains(MESSAGING_ACTIVEMQ_EXTENSION)) {
        // extension is already added, do nothing
        return;
    }
    PathAddress extensionAddress = pathAddress(EXTENSION, MESSAGING_ACTIVEMQ_EXTENSION);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    ModelNode addOperation = createAddOperation(extensionAddress);
    addOperation.get(MODULE).set(MESSAGING_ACTIVEMQ_MODULE);
    if (describe) {
        migrationOperations.put(extensionAddress, addOperation);
    } else {
        context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)1634 PathAddress (org.jboss.as.controller.PathAddress)351 Test (org.junit.Test)344 KernelServices (org.jboss.as.subsystem.test.KernelServices)102 Property (org.jboss.dmr.Property)92 OperationFailedException (org.jboss.as.controller.OperationFailedException)89 OperationContext (org.jboss.as.controller.OperationContext)68 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)68 ArrayList (java.util.ArrayList)58 Resource (org.jboss.as.controller.registry.Resource)54 PathElement (org.jboss.as.controller.PathElement)53 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)52 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)50 IOException (java.io.IOException)49 ServiceName (org.jboss.msc.service.ServiceName)49 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)47 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)44 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)42 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)42 Map (java.util.Map)38