Java Code Examples for org.jboss.as.controller.OperationContext#readResourceForUpdate()
The following examples show how to use
org.jboss.as.controller.OperationContext#readResourceForUpdate() .
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: HandlerOperations.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final String handlerName = operation.get(HANDLER_NAME.getName()).asString(); // Create a new handler list for the model boolean found = false; final List<ModelNode> handlers = model.get(SUBHANDLERS.getName()).asList(); final List<ModelNode> newHandlers = new ArrayList<>(handlers.size()); for (ModelNode handler : handlers) { if (handlerName.equals(handler.asString())) { HANDLER.removeCapabilityRequirements(context, resource, handler); found = true; } else { newHandlers.add(handler); } } if (found) { model.get(SUBHANDLERS.getName()).set(newHandlers); } }
Example 2
Source File: LoggerOperations.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final String handlerName = operation.get(HANDLER_NAME.getName()).asString(); // Create a new handler list for the model boolean found = false; final List<ModelNode> handlers = model.get(HANDLERS.getName()).asList(); final List<ModelNode> newHandlers = new ArrayList<>(handlers.size()); for (ModelNode handler : handlers) { if (handlerName.equals(handler.asString())) { HANDLER.removeCapabilityRequirements(context, resource, handler); found = true; } else { newHandlers.add(handler); } } if (found) { model.get(HANDLERS.getName()).set(newHandlers); } }
Example 3
Source File: LoggingOperations.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Updates the model based on the operation. * * @param context the operation context * @param operation the operation being executed * @param model the model to update * * @throws OperationFailedException if a processing error occurs */ public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode submodel = resource.getModel(); for (AttributeDefinition attribute : attributes) { final String attributeName = attribute.getName(); final ModelNode currentValue = submodel.get(attributeName).clone(); // Filter attribute needs to be converted to filter spec if (CommonAttributes.FILTER.equals(attribute)) { final ModelNode filter = CommonAttributes.FILTER.validateOperation(operation); if (filter.isDefined()) { final String value = Filters.filterToFilterSpec(filter); model.get(LoggerAttributes.FILTER_SPEC.getName()).set(value.isEmpty() ? new ModelNode() : new ModelNode(value)); } } else { // Only update the model for attributes that are defined in the operation if (operation.has(attribute.getName())) { attribute.validateAndSet(operation, model); } } final ModelNode newValue = model.get(attributeName).clone(); recordCapabilitiesAndRequirements(context, resource, attribute, newValue, currentValue); } }
Example 4
Source File: JVMOptionRemoveHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); // the attribute allow expressions but it is *not* resolved. This enables to remove a jvm option // which was added with an expression. If the expression was resolved it would not be found in the JVM_OPTIONS list final ModelNode option = JVM_OPTION.validateOperation(operation); if (model.hasDefined(JvmAttributes.JVM_OPTIONS)) { final ModelNode values = model.get(JvmAttributes.JVM_OPTIONS).clone(); model.get(JvmAttributes.JVM_OPTIONS).setEmptyList(); for (ModelNode value : values.asList()) { if (!value.equals(option)) { model.get(JvmAttributes.JVM_OPTIONS).add(value); } } } }
Example 5
Source File: JVMOptionAddHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); final ModelNode option = JVM_OPTION.validateOperation(operation); ModelNode jvmOptions = model.get(JvmAttributes.JVM_OPTIONS); if (jvmOptions.isDefined()) { for (ModelNode optionNode : jvmOptions.asList()) { if (optionNode.equals(option)) { throw HostControllerLogger.ROOT_LOGGER.jvmOptionAlreadyExists(option.asString()); } } } model.get(JvmAttributes.JVM_OPTIONS).add(option); }
Example 6
Source File: JmxFacadeRbacEnabledTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (readOnly) { context.readResource(PathAddress.EMPTY_ADDRESS); } else { context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); } }
Example 7
Source File: HandlerOperations.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode handlerName = operation.get(HANDLER_NAME.getName()); // Get the current handlers, add the handler and set the model value final ModelNode handlers = model.get(SUBHANDLERS.getName()).clone(); if (!handlers.isDefined()) { handlers.setEmptyList(); } handlers.add(handlerName); SUBHANDLERS.getValidator().validateParameter(SUBHANDLERS.getName(), handlers); model.get(SUBHANDLERS.getName()).add(handlerName); HANDLER.addCapabilityRequirements(context, resource, handlerName); }
Example 8
Source File: LoggerOperations.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void updateModel(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode handlerName = operation.get(HANDLER_NAME.getName()); // Get the current handlers, add the handler and set the model value final ModelNode handlers = model.get(HANDLERS.getName()).clone(); if (!handlers.isDefined()) { handlers.setEmptyList(); } handlers.add(handlerName); HANDLERS.getValidator().validateParameter(HANDLERS.getName(), handlers); model.get(HANDLERS.getName()).add(handlerName); HANDLER.addCapabilityRequirements(context, resource, handlerName); }
Example 9
Source File: RemotingEndpointAdd.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected Resource createResource(OperationContext context) { // If the resource is already there, just use it // We do this because RemotingSubsystemAdd/WorkerThreadPoolVsEndpointHandler will end up adding a resource if // one isn't added in the same op. So if a user adds one in a separate op, we're forgiving about it. // Mostly we do this to allow transformers tests to pass which call ModelTestUtils.checkFailedTransformedBootOperations // which calls this OSH in a separate op from the one that calls RemotingSubystemAdd try { return context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); } catch (Resource.NoSuchResourceException ignored) { // } return super.createResource(context); }
Example 10
Source File: ManagedDMRContentStoreHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final byte[] oldHash = ManagedDMRContentResourceDefinition.HASH.validateOperation(operation).asBytes(); final byte[] currentHash = resource.getModel().get(ManagedDMRContentResourceDefinition.HASH.getName()).asBytes(); if (!Arrays.equals(oldHash, currentHash)) { throw ManagedDMRContentLogger.ROOT_LOGGER.invalidHash(HashUtil.bytesToHexString(oldHash), PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)), HashUtil.bytesToHexString(currentHash)); } ModelNode model = new ModelNode(); contentAttribute.validateAndSet(operation, model); // IMPORTANT: Use writeModel, as this is what causes the content to be flushed to the content repo! resource.writeModel(model); }
Example 11
Source File: ManagedDMRContentWriteAttributeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode model = new ModelNode(); ModelNode synthOp = new ModelNode(); synthOp.get(contentAttribute.getName()).set(operation.get(ModelDescriptionConstants.VALUE)); contentAttribute.validateAndSet(synthOp, model); final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); // IMPORTANT: Use writeModel, as this is what causes the content to be flushed to the content repo! resource.writeModel(model); }
Example 12
Source File: DeploymentDeployHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); ModelNode model = resource.getModel(); model.get(ENABLED.getName()).set(true); final ModelNode opAddr = operation.get(OP_ADDR); PathAddress address = PathAddress.pathAddress(opAddr); final String name = address.getLastElement().getValue(); final String runtimeName = RUNTIME_NAME.resolveModelAttribute(context, model).asString(); final DeploymentHandlerUtil.ContentItem[] contents = getContents(CONTENT_RESOURCE_ALL.resolveModelAttribute(context, model)); DeploymentHandlerUtil.deploy(context, operation, runtimeName, name, vaultReader, contents); DeploymentUtils.enableAttribute(model); }
Example 13
Source File: LocalDomainControllerRemoveHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); model.get(DOMAIN_CONTROLLER).setEmptyObject(); }
Example 14
Source File: SyncModelOperationHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
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 15
Source File: WriteConfigHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); }