Search in sources :

Example 1 with Resource

use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.

the class WebMigrateOperation method createIoSubsystem.

/**
     * We need to create the IO subsystem, if it does not already exist
     */
private void createIoSubsystem(OperationContext context, Map<PathAddress, ModelNode> migrationOperations, PathAddress baseAddress) {
    Resource root = context.readResourceFromRoot(baseAddress, false);
    if (root.getChildrenNames(SUBSYSTEM).contains(IOExtension.SUBSYSTEM_NAME)) {
        // subsystem is already added, do nothing
        return;
    }
    //these addresses will be fixed later, no need to use the base address
    PathAddress address = pathAddress(pathElement(SUBSYSTEM, IOExtension.SUBSYSTEM_NAME));
    migrationOperations.put(address, createAddOperation(address));
    address = pathAddress(pathElement(SUBSYSTEM, IOExtension.SUBSYSTEM_NAME), pathElement("worker", "default"));
    migrationOperations.put(address, createAddOperation(address));
    address = pathAddress(pathElement(SUBSYSTEM, IOExtension.SUBSYSTEM_NAME), pathElement("buffer-pool", "default"));
    migrationOperations.put(address, createAddOperation(address));
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 2 with Resource

use of org.jboss.as.controller.registry.Resource 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 3 with Resource

use of org.jboss.as.controller.registry.Resource 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)

Example 4 with Resource

use of org.jboss.as.controller.registry.Resource 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 5 with Resource

use of org.jboss.as.controller.registry.Resource 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

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4