Java Code Examples for org.jboss.as.controller.OperationContext#createResource()

The following examples show how to use org.jboss.as.controller.OperationContext#createResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoleMappingAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS);
    PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String roleName = address.getLastElement().getValue();

    if (authorizerConfiguration.getStandardRoles().contains(roleName) == false) {
        if (domainMode) {
            ScopedRoleRequiredHandler.addOperation(context, roleName);
        } else {
            // Standalone mode so no scoped roles so if it is not a standard role it is invalid.
            throw DomainManagementLogger.ROOT_LOGGER.invalidRoleName(roleName);
        }
    }

    ModelNode model = resource.getModel();
    RoleMappingResourceDefinition.INCLUDE_ALL.validateAndSet(operation, model);

    registerRuntimeAdd(context, roleName.toUpperCase(Locale.ENGLISH));
}
 
Example 2
Source File: HostDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void initModelServices(final OperationContext context, final PathAddress hostAddress, final Resource rootResource) {
    // Create the management resources
    Resource management = context.createResource(hostAddress.append(PathElement.pathElement(CORE_SERVICE, MANAGEMENT)));
    if (modelControllerResource != null) {
        management.registerChild(PathElement.pathElement(SERVICE, MANAGEMENT_OPERATIONS), modelControllerResource);
    }

    //Create the empty host-environment resource
    context.addResource(hostAddress.append(PathElement.pathElement(CORE_SERVICE, HOST_ENVIRONMENT)), PlaceholderResource.INSTANCE);

    //Create the empty module-loading resource
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.MODULE_LOADING), PlaceholderResource.INSTANCE);

    //Create the empty capability registry resource
    rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.CAPABILITY_REGISTRY), PlaceholderResource.INSTANCE);

    // Wire in the platform mbean resources. We're bypassing the context.createResource API here because
    // we want to use our own resource type. But it's ok as the createResource calls above have taken the lock
    rootResource.registerChild(PlatformMBeanConstants.ROOT_PATH, new RootPlatformMBeanResource());
    // Wire in the ignored-resources resource
    Resource.ResourceEntry ignoredRoot = ignoredDomainResourceRegistry.getRootResource();
    rootResource.registerChild(ignoredRoot.getPathElement(), ignoredRoot);

    // Create the empty discovery options resource
    context.addResource(hostAddress.append(PathElement.pathElement(CORE_SERVICE, DISCOVERY_OPTIONS)), new DiscoveryOptionsResource());
}
 
Example 3
Source File: ApplyExtensionsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Resource getResource(PathAddress resourceAddress, Resource rootResource, OperationContext context) {
    if(resourceAddress.size() == 0) {
        return rootResource;
    }
    Resource temp = rootResource;
    int idx = 0;
    for(PathElement element : resourceAddress) {
        temp = temp.getChild(element);
        if(temp == null) {
            if (idx == 0) {
                String type = element.getKey();
                if (type.equals(EXTENSION)) {
                    // Needs a specialized resource type
                    temp = new ExtensionResource(element.getValue(), extensionRegistry);
                    context.addResource(resourceAddress, temp);
                }
            }
            if (temp == null) {
                temp = context.createResource(resourceAddress);
            }
            break;
        }
        idx++;
    }
    return temp;
}
 
Example 4
Source File: DeploymentReplaceHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    for (AttributeDefinition def : DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.values()) {
        def.validateOperation(operation);
    }
    String name = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(NAME).resolveModelAttribute(context, operation).asString();
    String toReplace = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(TO_REPLACE).resolveModelAttribute(context, operation).asString();

    if (name.equals(toReplace)) {
        throw ServerLogger.ROOT_LOGGER.cannotReplaceDeployment(OPERATION_NAME, NAME, TO_REPLACE,
                DeploymentRedeployHandler.OPERATION_NAME, DeploymentFullReplaceHandler.OPERATION_NAME);
    }

    final PathElement deployPath = PathElement.pathElement(DEPLOYMENT, name);
    final PathElement replacePath = PathElement.pathElement(DEPLOYMENT, toReplace);

    final Resource root = context.readResource(PathAddress.EMPTY_ADDRESS, false);
    if (! root.hasChild(replacePath)) {
        throw ServerLogger.ROOT_LOGGER.noSuchDeployment(toReplace);
    }

    final ModelNode replaceNode = context.readResourceForUpdate(PathAddress.pathAddress(replacePath)).getModel();
    final String replacedName = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, replaceNode).asString();

    ModelNode deployNode;
    String runtimeName;
    if (!root.hasChild(deployPath)) {
        if (!operation.hasDefined(CONTENT)) {
            throw ServerLogger.ROOT_LOGGER.noSuchDeployment(name);
        }
        // else -- the HostController handles a server group replace-deployment like an add, so we do too

        final ModelNode content = operation.require(CONTENT);
        // TODO: JBAS-9020: for the moment overlays are not supported, so there is a single content item
        final ModelNode contentItemNode = content.require(0);
        if (contentItemNode.hasDefined(HASH)) {
            byte[] hash = contentItemNode.require(HASH).asBytes();
            addFromHash(ModelContentReference.fromDeploymentName(name, hash));
        } else {
        }
        runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : replacedName;

        // Create the resource
        final Resource deployResource = context.createResource(PathAddress.pathAddress(deployPath));
        deployNode = deployResource.getModel();
        deployNode.get(RUNTIME_NAME).set(runtimeName);

        //TODO Assumes this can only be set by client
        deployNode.get(ModelDescriptionConstants.PERSISTENT).set(true);

        deployNode.get(CONTENT).set(content);

    } else {
        deployNode = context.readResourceForUpdate(PathAddress.pathAddress(deployPath)).getModel();
        if (ENABLED.resolveModelAttribute(context, deployNode).asBoolean()) {
            throw ServerLogger.ROOT_LOGGER.deploymentAlreadyStarted(toReplace);
        }
        runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : deployNode.require(RUNTIME_NAME).asString();
        deployNode.get(RUNTIME_NAME).set(runtimeName);
    }

    deployNode.get(ENABLED.getName()).set(true);
    replaceNode.get(ENABLED.getName()).set(false);

    final DeploymentHandlerUtil.ContentItem[] contents = getContents(deployNode.require(CONTENT));
    DeploymentHandlerUtil.replace(context, replaceNode, runtimeName, name, replacedName, vaultReader, contents);
}