Search in sources :

Example 11 with ModelNode

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

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

the class WebMigrateOperation method migrateSso.

private void migrateSso(Map<PathAddress, ModelNode> newAddOperations, ModelNode newAddOp, PathAddress address, List<String> warnings) {
    PathAddress newAddress = pathAddress(UndertowExtension.SUBSYSTEM_PATH, DEFAULT_SERVER_PATH, pathElement(Constants.HOST, address.getElement(address.size() - 2).getValue()), UndertowExtension.PATH_SSO);
    ModelNode add = createAddOperation(newAddress);
    add.get(Constants.DOMAIN).set(newAddOp.get(WebSSODefinition.DOMAIN.getName()).clone());
    add.get(Constants.HTTP_ONLY).set(newAddOp.get(WebSSODefinition.HTTP_ONLY.getName()).clone());
    if (newAddOp.hasDefined(WebSSODefinition.CACHE_CONTAINER.getName())) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSODefinition.CACHE_CONTAINER.getName(), pathAddress(newAddOp.get(ADDRESS))));
    }
    if (newAddOp.hasDefined(WebSSODefinition.REAUTHENTICATE.getName())) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSODefinition.REAUTHENTICATE.getName(), pathAddress(newAddOp.get(ADDRESS))));
    }
    if (newAddOp.hasDefined(WebSSODefinition.CACHE_NAME.getName())) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSODefinition.CACHE_NAME.getName(), pathAddress(newAddOp.get(ADDRESS))));
    }
    newAddOperations.put(newAddress, add);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 13 with ModelNode

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

the class WebMigrateOperation method migrateConnector.

private void migrateConnector(OperationContext context, Map<PathAddress, ModelNode> newAddOperations, ModelNode newAddOp, PathAddress address, ModelNode legacyModelAddOps, List<String> warnings, boolean domainMode) throws OperationFailedException {
    String protocol = newAddOp.get(WebConnectorDefinition.PROTOCOL.getName()).asString();
    String scheme = null;
    if (newAddOp.hasDefined(WebConnectorDefinition.SCHEME.getName())) {
        scheme = newAddOp.get(WebConnectorDefinition.SCHEME.getName()).asString();
    }
    final PathAddress newAddress;
    final ModelNode addConnector;
    switch(protocol) {
        case "org.apache.coyote.http11.Http11Protocol":
        case "org.apache.coyote.http11.Http11NioProtocol":
        case "org.apache.coyote.http11.Http11AprProtocol":
        case "HTTP/1.1":
            if (scheme == null || scheme.equals("http")) {
                newAddress = pathAddress(UndertowExtension.SUBSYSTEM_PATH, DEFAULT_SERVER_PATH, pathElement(Constants.HTTP_LISTENER, address.getLastElement().getValue()));
                addConnector = createAddOperation(newAddress);
            } else if (scheme.equals("https")) {
                newAddress = pathAddress(UndertowExtension.SUBSYSTEM_PATH, DEFAULT_SERVER_PATH, pathElement(Constants.HTTPS_LISTENER, address.getLastElement().getValue()));
                addConnector = createAddOperation(newAddress);
                SSLInformation sslInfo = createSecurityRealm(context, newAddOperations, legacyModelAddOps, newAddress.getLastElement().getValue(), warnings, domainMode);
                if (sslInfo == null) {
                    throw WebLogger.ROOT_LOGGER.noSslConfig();
                } else {
                    addConnector.get(Constants.SECURITY_REALM).set(sslInfo.realmName);
                    ModelNode verify = sslInfo.verifyClient;
                    if (verify.isDefined()) {
                        if (verify.getType() == ModelType.EXPRESSION) {
                            warnings.add(WebLogger.ROOT_LOGGER.couldNotTranslateVerifyClientExpression(verify.toString()));
                            addConnector.get(Constants.VERIFY_CLIENT).set(verify);
                        } else {
                            String translated = translateVerifyClient(verify.asString(), warnings);
                            if (translated != null) {
                                addConnector.get(Constants.VERIFY_CLIENT).set(translated);
                            }
                        }
                    }
                    addConnector.get(Constants.SSL_SESSION_CACHE_SIZE).set(sslInfo.sessionCacheSize);
                    addConnector.get(Constants.SSL_SESSION_TIMEOUT).set(sslInfo.sessionTimeout);
                    addConnector.get(Constants.ENABLED_PROTOCOLS).set(sslInfo.sslProtocol);
                    addConnector.get(Constants.ENABLED_CIPHER_SUITES).set(sslInfo.cipherSuites);
                }
            } else {
                newAddress = null;
                addConnector = null;
            }
            break;
        case "org.apache.coyote.ajp.AjpAprProtocol":
        case "org.apache.coyote.ajp.AjpProtocol":
        case "AJP/1.3":
            newAddress = pathAddress(UndertowExtension.SUBSYSTEM_PATH, DEFAULT_SERVER_PATH, pathElement(Constants.AJP_LISTENER, address.getLastElement().getValue()));
            addConnector = createAddOperation(newAddress);
            addConnector.get(Constants.SCHEME).set(newAddOp.get(Constants.SCHEME));
            break;
        default:
            newAddress = null;
            addConnector = null;
    }
    if (newAddress == null) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(newAddOp));
        return;
    }
    addConnector.get(Constants.SOCKET_BINDING).set(newAddOp.get(SOCKET_BINDING));
    addConnector.get(Constants.SECURE).set(newAddOp.get(WebConnectorDefinition.SECURE.getName()));
    addConnector.get(Constants.REDIRECT_SOCKET).set(newAddOp.get(WebConnectorDefinition.REDIRECT_BINDING.getName()));
    addConnector.get(Constants.ENABLED).set(newAddOp.get(WebConnectorDefinition.ENABLED.getName()));
    addConnector.get(Constants.RESOLVE_PEER_ADDRESS).set(newAddOp.get(WebConnectorDefinition.ENABLE_LOOKUPS.getName()));
    addConnector.get(Constants.MAX_POST_SIZE).set(newAddOp.get(WebConnectorDefinition.MAX_POST_SIZE.getName()));
    addConnector.get(Constants.REDIRECT_SOCKET).set(newAddOp.get(WebConnectorDefinition.REDIRECT_BINDING.getName()));
    addConnector.get(Constants.MAX_CONNECTIONS).set(newAddOp.get(WebConnectorDefinition.MAX_CONNECTIONS.getName()));
    addConnector.get(Constants.MAX_BUFFERED_REQUEST_SIZE).set(newAddOp.get(WebConnectorDefinition.MAX_SAVE_POST_SIZE.getName()));
    addConnector.get(Constants.SECURE).set(newAddOp.get(WebConnectorDefinition.SECURE.getName()));
    if (newAddOp.hasDefined(WebConnectorDefinition.REDIRECT_PORT.getName())) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebConnectorDefinition.REDIRECT_PORT.getName(), pathAddress(newAddOp.get(ADDRESS))));
    }
    if (newAddOp.hasDefined(WebConnectorDefinition.PROXY_BINDING.getName())) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebConnectorDefinition.PROXY_BINDING.getName(), pathAddress(newAddOp.get(ADDRESS))));
    }
    if (newAddOp.hasDefined(WebConnectorDefinition.EXECUTOR.getName())) {
        //TODO: migrate executor to worker
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebConnectorDefinition.EXECUTOR.getName(), pathAddress(newAddOp.get(ADDRESS))));
    }
    newAddOperations.put(pathAddress(newAddOp.get(OP_ADDR)), addConnector);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 14 with ModelNode

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

the class WebMigrateOperation method createSecurityRealm.

/**
     * Creates the security realm
     *
     * @param context
     * @param migrationOperations
     * @return
     */
private SSLInformation createSecurityRealm(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, ModelNode legacyModelAddOps, String connector, List<String> warnings, boolean domainMode) {
    ModelNode legacyAddOp = findResource(pathAddress(WebExtension.SUBSYSTEM_PATH, pathElement(WebExtension.CONNECTOR_PATH.getKey(), connector), pathElement("configuration", "ssl")), legacyModelAddOps);
    if (legacyAddOp == null) {
        return null;
    }
    //we have SSL
    //read all the info from the SSL definition
    ModelNode keyAlias = legacyAddOp.get(WebSSLDefinition.KEY_ALIAS.getName());
    ModelNode password = legacyAddOp.get(WebSSLDefinition.PASSWORD.getName());
    ModelNode certificateKeyFile = legacyAddOp.get(WebSSLDefinition.CERTIFICATE_KEY_FILE.getName());
    ModelNode cipherSuite = legacyAddOp.get(WebSSLDefinition.CIPHER_SUITE.getName());
    ModelNode protocol = legacyAddOp.get(WebSSLDefinition.PROTOCOL.getName());
    ModelNode verifyClient = legacyAddOp.get(WebSSLDefinition.VERIFY_CLIENT.getName());
    ModelNode verifyDepth = legacyAddOp.get(WebSSLDefinition.VERIFY_DEPTH.getName());
    ModelNode certificateFile = legacyAddOp.get(WebSSLDefinition.CERTIFICATE_FILE.getName());
    ModelNode caCertificateFile = legacyAddOp.get(WebSSLDefinition.CA_CERTIFICATE_FILE.getName());
    ModelNode caCertificatePassword = legacyAddOp.get(WebSSLDefinition.CA_CERTIFICATE_PASSWORD.getName());
    ModelNode csRevocationURL = legacyAddOp.get(WebSSLDefinition.CA_REVOCATION_URL.getName());
    ModelNode trustStoreType = legacyAddOp.get(WebSSLDefinition.TRUSTSTORE_TYPE.getName());
    ModelNode keystoreType = legacyAddOp.get(WebSSLDefinition.KEYSTORE_TYPE.getName());
    ModelNode sessionCacheSize = legacyAddOp.get(WebSSLDefinition.SESSION_CACHE_SIZE.getName());
    ModelNode sessionTimeout = legacyAddOp.get(WebSSLDefinition.SESSION_TIMEOUT.getName());
    ModelNode sslProvider = legacyAddOp.get(WebSSLDefinition.SSL_PROTOCOL.getName());
    if (verifyDepth.isDefined()) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.VERIFY_DEPTH.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
    }
    if (certificateFile.isDefined()) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.CERTIFICATE_FILE.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
    }
    if (sslProvider.isDefined()) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.SSL_PROTOCOL.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
    }
    if (csRevocationURL.isDefined()) {
        warnings.add(WebLogger.ROOT_LOGGER.couldNotMigrateResource(WebSSLDefinition.CA_REVOCATION_URL.getName(), pathAddress(legacyAddOp.get(ADDRESS))));
    }
    String realmName;
    PathAddress managementCoreService;
    if (domainMode) {
        Set<String> hosts = new HashSet<>();
        Resource hostResource = context.readResourceFromRoot(pathAddress(), false);
        hosts.addAll(hostResource.getChildrenNames(HOST));
        //now we need to find a unique name
        //in domain mode different profiles could have different SSL configurations
        //but the realms are not scoped to a profile
        //if we hard coded a name migration would fail when migrating domains with multiple profiles
        int counter = 1;
        realmName = REALM_NAME + counter;
        while (true) {
            boolean hostOk = true;
            for (String host : hosts) {
                Resource root = context.readResourceFromRoot(pathAddress(pathElement(HOST, host), pathElement(CORE_SERVICE, MANAGEMENT)), false);
                if (root.getChildrenNames(SECURITY_REALM).contains(realmName)) {
                    counter++;
                    realmName = REALM_NAME + counter;
                    hostOk = false;
                    break;
                }
            }
            if (hostOk) {
                break;
            }
        }
        for (String host : hosts) {
            createHostSSLConfig(realmName, migrationOperations, keyAlias, password, certificateKeyFile, protocol, caCertificateFile, caCertificatePassword, trustStoreType, keystoreType, pathAddress(pathElement(HOST, host), pathElement(CORE_SERVICE, MANAGEMENT)));
        }
    } else {
        managementCoreService = pathAddress(CORE_SERVICE, MANAGEMENT);
        //now we need to find a unique name
        //in domain mode different profiles could have different SSL configurations
        //but the realms are not scoped to a profile
        //if we hard coded a name migration would fail when migrating domains with multiple profiles
        int counter = 1;
        realmName = REALM_NAME + counter;
        boolean ok = false;
        do {
            Resource root = context.readResourceFromRoot(managementCoreService, false);
            if (root.getChildrenNames(SECURITY_REALM).contains(realmName)) {
                counter++;
                realmName = REALM_NAME + counter;
            } else {
                ok = true;
            }
        } while (!ok);
        //we have a unique realm name
        createHostSSLConfig(realmName, migrationOperations, keyAlias, password, certificateKeyFile, protocol, caCertificateFile, caCertificatePassword, trustStoreType, keystoreType, managementCoreService);
    }
    return new SSLInformation(realmName, verifyClient, sessionCacheSize, sessionTimeout, protocol, cipherSuite);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 15 with ModelNode

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

the class WebMigrateOperation method addExtension.

/**
     * It's possible that the extension is already present. In that case, this method does nothing.
     */
private void addExtension(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, boolean describe, String extension) {
    Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
    if (root.getChildrenNames(EXTENSION).contains(extension)) {
        // extension is already added, do nothing
        return;
    }
    PathAddress extensionAddress = pathAddress(EXTENSION, extension);
    OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD);
    ModelNode addOperation = createAddOperation(extensionAddress);
    addOperation.get(MODULE).set(extension);
    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