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

The following examples show how to use org.jboss.as.controller.OperationContext#getRootResourceRegistration() . 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: ReadTransformedResourceOperation.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode transformReadResourceResult(final OperationContext context, ModelNode original, String subsystem) throws OperationFailedException {
    ModelNode rootData = original.get(ModelDescriptionConstants.RESULT);

    Map<PathAddress, ModelVersion> subsystemVersions = new HashMap<>();
    subsystemVersions.put(PathAddress.EMPTY_ADDRESS.append(ModelDescriptionConstants.SUBSYSTEM, subsystem), subsystemModelVersion);

    final TransformationTarget target = TransformationTargetImpl.create(null, transformerRegistry, coreModelVersion,
            subsystemVersions, TransformationTarget.TransformationTargetType.SERVER);
    final Transformers transformers = Transformers.Factory.create(target);

    final ImmutableManagementResourceRegistration rr = context.getRootResourceRegistration();
    Resource root = TransformationUtils.modelToResource(rr, rootData, true);
    Transformers.TransformationInputs transformationInputs = Transformers.TransformationInputs.getOrCreate(context);
    Resource transformed = transformers.transformRootResource(transformationInputs, root);

    return Resource.Tools.readModel(transformed);
}
 
Example 2
Source File: Transformers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new {@code TransformationInputs} from the given operation context.
 * @param context  the operation context. Cannot be {@code null}
 */
public TransformationInputs(OperationContext context) {
    this.originalModel = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true);
    this.registration = context.getRootResourceRegistration();
    this.processType = context.getProcessType();
    this.runningMode = context.getRunningMode();
    this.transformerOperationAttachment = context.getAttachment(TransformerOperationAttachment.KEY);
}
 
Example 3
Source File: OperationRouting.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static OperationRouting determineRouting(OperationContext context, ModelNode operation,
                                         final LocalHostControllerInfo localHostControllerInfo, Set<String> hostNames) throws OperationFailedException {
    final ImmutableManagementResourceRegistration rootRegistration = context.getRootResourceRegistration();
    return determineRouting(operation, localHostControllerInfo, rootRegistration, hostNames, false);
}
 
Example 4
Source File: SyncModelOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
        // In case we want to automatically ignore extensions we would need to add them before describing the operations
        // This is also required for resolving the corresponding OperationStepHandler here
//        final ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
//        for (String extension : missingExtensions) {
//            final PathElement element = PathElement.pathElement(EXTENSION, extension);
//            if (ignoredResourceRegistry.isResourceExcluded(PathAddress.pathAddress(element))) {
//                continue;
//            }
//            context.addResource(PathAddress.pathAddress(element), new ExtensionResource(extension, extensionRegistry));
//            initializeExtension(extension, registration);
//        }
        // There should be no missing extensions for now, unless they are manually ignored
        if (!missingExtensions.isEmpty()) {
            throw DomainControllerLogger.HOST_CONTROLLER_LOGGER.missingExtensions(missingExtensions);
        }

        final ModelNode readOp = new ModelNode();
        readOp.get(OP).set(ReadMasterDomainOperationsHandler.OPERATION_NAME);
        readOp.get(OP_ADDR).setEmptyList();

        // Describe the operations based on the remote model
        final ReadMasterDomainOperationsHandler readOperationsHandler = new ReadMasterDomainOperationsHandler();
        final HostControllerRegistrationHandler.OperationExecutor operationExecutor = parameters.getOperationExecutor();
        final ModelNode result = operationExecutor.executeReadOnly(readOp, remoteModel, readOperationsHandler, ModelController.OperationTransactionControl.COMMIT);
        if (result.hasDefined(FAILURE_DESCRIPTION)) {
            context.getFailureDescription().set(result.get(FAILURE_DESCRIPTION));
            return;
        }

        final List<ModelNode> remoteOperations = result.get(RESULT).asList();

        // Create the node models based on the operations
        final Node currentRoot = new Node(null, PathAddress.EMPTY_ADDRESS);
        final Node remoteRoot = new Node(null, PathAddress.EMPTY_ADDRESS);

        // Process the local and remote operations
        process(currentRoot, localOperations, localOrderedChildTypes);
        process(remoteRoot, remoteOperations, readOperationsHandler.getOrderedChildTypes());

        // Compare the nodes and create the operations to sync the model
        //final List<ModelNode> operations = new ArrayList<>();
        OrderedOperationsCollection operations = new OrderedOperationsCollection(context);
        processAttributes(currentRoot, remoteRoot, operations, context.getRootResourceRegistration());
        processChildren(currentRoot, remoteRoot, operations, context.getRootResourceRegistration());

        //Process root domain attributes manually as those are read-only
        if(context.getCurrentAddress().size() == 0) {
            Resource rootResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
            ModelNode rootModel = rootResource.getModel().clone();
            ModelNode remoteRootModel = remoteModel.getModel();
            for (String attributeName : ROOT_ATTRIBUTES) {
                if ((remoteRootModel.hasDefined(attributeName))) {
                    rootModel.get(attributeName).set(remoteRootModel.get(attributeName));
                }
            }
            rootResource.writeModel(rootModel);
        }

        // Reverse, since we are adding the steps on top of the queue
        final List<ModelNode> ops = operations.getReverseList();

        for (final ModelNode op : ops) {

            final String operationName = op.require(OP).asString();
            final PathAddress address = PathAddress.pathAddress(op.require(OP_ADDR));
            if (parameters.getIgnoredResourceRegistry().isResourceExcluded(address)) {
                continue;
            }
            // Ignore all extension:add operations, since we've added them before
//            if (address.size() == 1 && EXTENSION.equals(address.getElement(0).getKey()) && ADD.equals(operationName)) {
//                continue;
//            }

            final ImmutableManagementResourceRegistration rootRegistration = context.getRootResourceRegistration();
            final OperationStepHandler stepHandler = rootRegistration.getOperationHandler(address, operationName);
            if(stepHandler != null) {
                context.addStep(op, stepHandler, OperationContext.Stage.MODEL, true);
            } else {
                final ImmutableManagementResourceRegistration child = rootRegistration.getSubModel(address);
                if (child == null) {
                    context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noSuchResourceType(address));
                } else {
                    context.getFailureDescription().set(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(operationName, address));
                }
            }

        }

        if (!context.isBooting() && operations.getAllOps().size() > 0 && parameters.isFullModelTransfer()) {
            //Only do this is if it is a full model transfer as a result of a _reconnect_ to the DC.
            //When fetching missing configuration while connected, the servers will get put into reload-required as a
            // result of changing the server-group, profile or the socket-binding-group
            context.addStep(new SyncServerStateOperationHandler(parameters, operations.getAllOps()),
                    OperationContext.Stage.MODEL,
                    true);
        }
    }
 
Example 5
Source File: MultistepUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static OpData getOpData(OperationContext context, ModelNode subOperation, ModelNode response, PathAddress stepAddress,
                                OperationHandlerResolver handlerResolver, boolean rejectPrivateOperations,
                                boolean allowDeferredResolution,
                                boolean requireReResolution) throws OperationFailedException {
    ImmutableManagementResourceRegistration registry = context.getRootResourceRegistration();
    String stepOpName = subOperation.require(OP).asString();
    OperationDefinition operationDefinition;
    OperationStepHandler osh;
    OperationEntry operationEntry = registry.getOperationEntry(stepAddress, stepOpName);
    ControllerLogger.MGMT_OP_LOGGER.tracef("Getting OpDate for op %s at %s with deferred resolution %s", stepOpName, stepAddress, allowDeferredResolution);
    if (operationEntry == null) {
        ImmutableManagementResourceRegistration child = registry.getSubModel(stepAddress);
        if (child == null) {
            if (allowDeferredResolution && isSubsystem(stepAddress)) {
                // No MRR now but perhaps there will be later when this op actually executes.
                // So set things up to try then.
                ControllerLogger.MGMT_OP_LOGGER.tracef("Deferred resolution for op %s at %s", stepOpName, stepAddress);
                osh = new DeferredResolutionHandler(subOperation, response, stepAddress, handlerResolver, rejectPrivateOperations);
                // Supply a dummy definition. For no well thought out reason I'm using the original op name
                // and thus a dynamic op definition. Probably could be an OD constant with a fixed arbitary name
                // like "deferred-op-resolution"
                operationDefinition = SimpleOperationDefinitionBuilder.of(stepOpName, NonResolvingResourceDescriptionResolver.INSTANCE).build();
            } else {
                ControllerLogger.MGMT_OP_LOGGER.tracef("No resource registration for op %s at %s", stepOpName, stepAddress);
                throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noSuchResourceType(stepAddress));
            }
        } else {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(stepOpName, stepAddress));
        }
    } else {
        if (operationEntry.getType() == OperationEntry.EntryType.PRIVATE
                && (rejectPrivateOperations
                    || (subOperation.hasDefined(OPERATION_HEADERS, CALLER_TYPE)
                    && USER.equals(subOperation.get(OPERATION_HEADERS, CALLER_TYPE).asString())))) {
            // Not allowed; respond as if there is no such operation
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.noHandlerForOperation(stepOpName, stepAddress));
        }
        operationDefinition = operationEntry.getOperationDefinition();
        if (requireReResolution && isSubsystem(stepAddress)) {
            // A previous step will remove an extension before this subsystem step runs.
            // Get the currently registered handler before executing for real

            ControllerLogger.MGMT_OP_LOGGER.tracef("Re-resolution for op %s at %s", stepOpName, stepAddress);
            osh = new DeferredResolutionHandler(subOperation, response, stepAddress, handlerResolver, rejectPrivateOperations);
        } else {
            osh = handlerResolver.getOperationStepHandler(stepOpName, stepAddress, subOperation, operationEntry);
        }
    }

    // If this step is adding or removing an extension, subsequent steps need to deal with the possibility
    // that MRRs are coming/going. So track that. If we're already tracking, keep doing it.
    boolean allowDeferred = allowDeferredResolution || (ADD.equals(stepOpName) && isExtensionAddress(stepAddress));
    boolean requireReRes = requireReResolution || (REMOVE.equals(stepOpName) && isExtensionAddress(stepAddress));

    return new OpData(subOperation, operationDefinition, osh, response, allowDeferred, requireReRes);
}
 
Example 6
Source File: KeycloakSubsystemRemoveHandler.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private OperationStepHandler getRemoveHandler(OperationContext context, PathAddress address) {
    ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
    return rootResourceRegistration.getOperationHandler(address, REMOVE);
}
 
Example 7
Source File: ServerUtil.java    From keycloak with Apache License 2.0 4 votes vote down vote up
static OperationStepHandler getHandler(OperationContext context, PathAddress address, String opName) {
    ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
    return rootResourceRegistration.getOperationHandler(address, opName);
}