@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String attributeName = operation.require(NAME).asString(); // Don't require VALUE. Let the validator decide if it's bothered by an undefined value ModelNode newValue = operation.hasDefined(VALUE) ? operation.get(VALUE) : new ModelNode(); final ModelNode resolvedValue = newValue.resolve(); switch (attributeName) { case ModelDescriptionConstants.STATISTICS_ENABLED: { stats.setEnabled(resolvedValue.asBoolean()); break; } } }
private GetInstalledDriverOperationHandler() { validator.registerValidator(DRIVER_NAME.getName(), new StringLengthValidator(1)); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String attributeName = operation.require(NAME).asString(); final ModelNode newValue = operation.hasDefined(VALUE) ? operation.get(VALUE) : new ModelNode(); final ModelNode submodel = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); final AttributeDefinition attributeDefinition = ATTRIBUTES.get(attributeName); if (attributeDefinition != null) { final ModelNode syntheticOp = new ModelNode(); syntheticOp.get(attributeName).set(newValue); attributeDefinition.validateAndSet(syntheticOp, submodel); } else { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownAttribute(attributeName)); } if (updateRuntime) { // Require a reload context.reloadRequired(); } // Verify the model in a later step context.addStep(VERIFY_HANDLER, OperationContext.Stage.MODEL); OperationContext.RollbackHandler rollbackHandler = updateRuntime ? OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER : OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER; context.completeStep(rollbackHandler); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String attributeName = operation.require(NAME).asString(); ModelNode newValue = operation.hasDefined(VALUE) ? operation.get(VALUE) : new ModelNode(); validateUnresolvedValue(attributeName, newValue); final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode submodel = resource.getModel(); final ModelNode currentValue = submodel.get(attributeName).clone(); final ModelNode syntheticOp = new ModelNode(); syntheticOp.get(attributeName).set(newValue); attributeDefinition.validateAndSet(syntheticOp, submodel); newValue = submodel.get(attributeName); } else { context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { context.stepCompleted();
validator.validate(operation); final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString(); String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR))); ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName); ActiveMQServer server = ActiveMQServer.class.cast(service.getValue()); ManagementService managementService = server.getManagementService(); if (CommonAttributes.MESSAGE_COUNT.getName().equals(attributeName)) { try { context.getResult().set(control.getMessageCount()); } catch (RuntimeException e) { throw e; throw new RuntimeException(e); } else if (CommonAttributes.DELIVERING_COUNT.getName().equals(attributeName)) { context.getResult().set(getDeliveringCount(control, managementService)); } else if (CommonAttributes.MESSAGES_ADDED.getName().equals(attributeName)) { context.getResult().set(getMessagesAdded(control, managementService)); } else if (DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
@Override void doExecute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); final String opName = operation.require(OP).asString(); final ModelNode opAddr = operation.get(OP_ADDR); final PathAddress address = PathAddress.pathAddress(opAddr); final int recursiveDepth = operation.get(ModelDescriptionConstants.RECURSIVE_DEPTH).asInt(0); final boolean recursive = recursiveDepth > 0 ? true : operation.get(ModelDescriptionConstants.RECURSIVE).asBoolean(false); context.addStep(assemblyHandler, queryRuntime ? OperationContext.Stage.VERIFY : OperationContext.Stage.IMMEDIATE, queryRuntime); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); final ModelNode model = resource.getModel(); if (model.isDefined()) { context.addStep(rrRsp, rrOp, rrHandler, OperationContext.Stage.IMMEDIATE); attributeOperation.get(OP_ADDR).set(opAddr); attributeOperation.get(OP).set(READ_ATTRIBUTE_OPERATION); attributeOperation.get(GlobalOperationHandlers.NAME.getName()).set(attributeName); final ModelNode attrResponse = new ModelNode();
/** * An attribute write handler which performs special processing for ALIAS attributes. * * @param context the operation context * @param operation the operation being executed * @throws org.jboss.as.controller.OperationFailedException */ @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String newAlias = operation.require(NAME).asString(); final ModelNode submodel = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); final ModelNode currentValue = submodel.get(CacheContainerResource.ALIASES.getName()).clone(); ModelNode newValue = addNewAliasToList(currentValue, newAlias) ; // now set the new ALIAS attribute final ModelNode syntheticOp = new ModelNode(); syntheticOp.get(CacheContainerResource.ALIASES.getName()).set(newValue); CacheContainerResource.ALIASES.validateAndSet(syntheticOp, submodel); // since we modified the model, set reload required if (requiresRuntime(context)) { context.addStep((context1, operation1) -> { context1.reloadRequired(); context1.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER); }, OperationContext.Stage.RUNTIME); } }
@Override protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String path = address.getLastElement().getValue(); final String name = address.getElement(address.size() - 2).getValue(); final ModelNode content = operation.get(CONTENT); final byte[] hash; if (content.hasDefined(HASH)) { managedContentValidator.validate(content); hash = content.require(HASH).asBytes(); addFromHash(hash, name, path, context); slave.get(CONTENT).get(HASH).set(hash); List<DomainOperationTransformer> transformers = context.getAttachment(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSFORMERS); if(transformers == null) { context.attach(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSFORMERS, transformers = new ArrayList<DomainOperationTransformer>()); modified.get(CONTENT).set(hash); for (AttributeDefinition attr : ContentDefinition.attributes()) { attr.validateAndSet(modified, resource.getModel());
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String attributeName = operation.require(NAME.getName()).asString(); final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); if (registry == null) { throw new OperationFailedException(ControllerMessages.MESSAGES.noSuchResourceType(PathAddress.pathAddress(operation.get(OP_ADDR)))); throw new OperationFailedException(new ModelNode().set(MESSAGES.unknownAttribute(attributeName))); } else if (attributeAccess.getAccessType() != AttributeAccess.AccessType.READ_WRITE) { throw new OperationFailedException(new ModelNode().set(MESSAGES.attributeNotWritable(attributeName))); } else { ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); currentValue = model.has(attributeName) ? model.get(attributeName) : new ModelNode(); } else { currentValue = new ModelNode(); AuthorizationResult authorizationResult = context.authorize(operation, attributeName, currentValue); if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) { throw ControllerMessages.MESSAGES.unauthorized(operation.require(OP).asString(), PathAddress.pathAddress(operation.get(OP_ADDR)), authorizationResult.getExplanation()); readAttributeOperation.get(NAME.getName()).set(attributeName); ReadAttributeHandler readAttributeHandler = new ReadAttributeHandler(null, null);
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String childType = operation.require(GlobalOperationHandlers.CHILD_TYPE.getName()).asString(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); Map<String, Set<String>> childAddresses = GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, childType); Set<String> childNames = childAddresses.get(childType); if (childNames == null) { throw new OperationFailedException(new ModelNode().set(MESSAGES.unknownChildType(childType))); context.addStep(assemblyHandler, OperationContext.Stage.IMMEDIATE); final PathAddress childAddress = PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(childType, key)); final OperationStepHandler handler = context.getResourceRegistration().getOperationHandler(childAddress, READ_RESOURCE_OPERATION); if (handler == null) { throw new OperationFailedException(new ModelNode().set(MESSAGES.noOperationHandler())); final ModelNode rrRsp = new ModelNode();
@Override void doExecute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); final String attributeName = operation.require(GlobalOperationHandlers.NAME.getName()).asString(); final boolean defaults = operation.get(GlobalOperationHandlers.INCLUDE_DEFAULTS.getName()).asBoolean(true); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); final AttributeAccess attributeAccess = registry.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); final Set<String> children = context.getResourceRegistration().getChildNames(PathAddress.EMPTY_ADDRESS); if (children.contains(attributeName)) { throw new OperationFailedException(new ModelNode().set(MESSAGES.attributeRegisteredOnResource(attributeName, operation.get(OP_ADDR)))); } else { final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); final ModelNode subModel = resource.getModel(); if (subModel.hasDefined(attributeName)) { final ModelNode result = subModel.get(attributeName); context.getResult(); // this initializes the "result" to ModelType.UNDEFINED } else { throw new OperationFailedException(new ModelNode().set(MESSAGES.unknownAttribute(attributeName))); } else if (attributeAccess.getReadHandler() == null) { final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); final ModelNode subModel = resource.getModel(); if (subModel.hasDefined(attributeName) || !defaults) {
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String childType = operation.require(GlobalOperationHandlers.CHILD_TYPE.getName()).asString(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); Map<String, Set<String>> childAddresses = GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, childType); Set<String> childNames = childAddresses.get(childType); if (childNames == null) { throw new OperationFailedException(new ModelNode().set(MESSAGES.unknownChildType(childType))); } // Sort the result childNames = new TreeSet<String>(childNames); ModelNode result = context.getResult(); result.setEmptyList(); for (String childName : childNames) { result.add(childName); } context.stepCompleted(); } }
private void doExecuteInternal(OperationContext context, ModelNode operation, boolean ignoreMissingResource) throws OperationFailedException { validator.validate(operation); final String opName = operation.require(OP).asString(); final PathAddress address = context.getCurrentAddress(); final boolean queryRuntime = operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).asBoolean(false); final boolean proxies = operation.get(ModelDescriptionConstants.PROXIES).asBoolean(false); final boolean aliases = operation.get(ModelDescriptionConstants.INCLUDE_ALIASES).asBoolean(false); final boolean includeUndefinedMetricValues = operation.get(ModelDescriptionConstants.INCLUDE_UNDEFINED_METRIC_VALUES).asBoolean(false); final boolean attributesOnly = operation.get(ModelDescriptionConstants.ATTRIBUTES_ONLY).asBoolean(false); final boolean resolve = RESOLVE.resolveModelAttribute(context, operation).asBoolean(); context.addStep(assemblyHandler, queryRuntime ? OperationContext.Stage.VERIFY : OperationContext.Stage.MODEL, true); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); PathAddress absoluteChildAddr = address.append(childPE); PathAddress relativeAddr = PathAddress.pathAddress(childPE);
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); String name = operation.require(NAME).asString(); String toReplace = operation.require(TO_REPLACE).asString(); try { domainDeployment = context.getRootResource().requireChild(deploymentPath); } catch (Exception e) { throw operationFailed(String.format("No deployment with name %s found", name)); final ModelNode deployment = domainDeployment.getModel(); for (ModelNode content : deployment.require(CONTENT).asList()) { if ((content.hasDefined(HASH))) { final Resource serverGroup = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); if (! serverGroup.hasChild(replacePath)) { throw operationFailed(String.format("No deployment with name %s found", toReplace)); final Resource replaceResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS.append(replacePath)); if(! serverGroup.hasChild(deploymentPath)) { final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS.append(deploymentPath)); final ModelNode deployNode = resource.getModel(); deployNode.set(deployment); // Get the information from the domain deployment
private void doExecuteInternal(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); String attributeName = GlobalOperationAttributes.NAME.resolveModelAttribute(context, operation).asString(); final boolean defaults = GlobalOperationAttributes.INCLUDE_DEFAULTS.resolveModelAttribute(context,operation).asBoolean(); final boolean includeUndefinedMetricValue = GlobalOperationAttributes.INCLUDE_UNDEFINED_METRIC_VALUES.resolveModelAttribute(context, operation).asBoolean(); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); final boolean useEnhancedSyntax = containsEnhancedSyntax(attributeName, registry); String attributeExpression = attributeName; throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownAttribute(attributeName)); if (!context.getResult().isDefined() && !includeUndefinedMetricValue) { ModelNode undefinedMetricValue = attributeAccess.getAttributeDefinition().getUndefinedMetricValue(); if (undefinedMetricValue != null) { context.getResult().set(undefinedMetricValue);
validator.validate(operation); final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); String profile = operation.require(PROFILE).asString(); context.getRootResource().navigate(PathAddress.pathAddress(PathElement.pathElement(PROFILE, profile))); } catch (NoSuchElementException e) { throw new OperationFailedException(new ModelNode().set(String.format("Unknown %s %s", PROFILE, profile))); model.get(PROFILE).set(profile); context.getRootResource().navigate(PathAddress.pathAddress(PathElement.pathElement(SOCKET_BINDING_GROUP, socketBindingGroup))); } catch (NoSuchElementException e) { throw new OperationFailedException(new ModelNode().set(String.format("Unknown %s %s", SOCKET_BINDING_GROUP, socketBindingGroup))); model.get(SOCKET_BINDING_GROUP).set(socketBindingGroup);
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); String name = operation.require(NAME).asString(); String runtimeName = operation.hasDefined(RUNTIME_NAME) ? operation.get(RUNTIME_NAME).asString() : name; byte[] hash; final ModelNode contentItemNode = content.require(0); if (contentItemNode.hasDefined(HASH)) { managedContentValidator.validate(contentItemNode); hash = contentItemNode.require(HASH).asBytes(); if (contentRepository != null) { unmanagedContentValidator.validate(contentItemNode); final Resource root = context.readResource(PathAddress.EMPTY_ADDRESS); final PathElement deploymentPath = PathElement.pathElement(DEPLOYMENT, name); final Resource replaceNode = root.getChild(deploymentPath); if (replaceNode == null) { throw createFailureException("No deployment with name %s found", name); if(root.hasChild(PathElement.pathElement(SERVER_GROUP))) { for(final Resource.ResourceEntry serverGroupResource : root.getChildren(SERVER_GROUP)) { Resource deploymentResource = serverGroupResource.getChild(deploymentPath); removeContentAdditions(replaceNode.getModel().require(CONTENT)); context.completeStep();
@Override void doExecute(OperationContext context, ModelNode operation, FilteredData filteredData, boolean ignoreMissingResource) throws OperationFailedException { validator.validate(operation); final PathAddress address = context.getCurrentAddress(); final boolean includeRutime = operation.get(ModelDescriptionConstants.INCLUDE_RUNTIME).asBoolean(false); final boolean aliases = operation.get(ModelDescriptionConstants.INCLUDE_ALIASES).asBoolean(false); final boolean defaults = operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).asBoolean(true); final boolean resolve = RESOLVE.resolveModelAttribute(context, operation).asBoolean(); final ModelNode groupNameNode = NAME.resolveModelAttribute(context, operation); final String groupName = groupNameNode.isDefined() ? groupNameNode.asString() : null; final FilteredData localFilteredData = new FilteredData(address); context.addStep(assemblyHandler, includeRutime ? OperationContext.Stage.VERIFY : OperationContext.Stage.MODEL, true); final ImmutableManagementResourceRegistration registry = context.getResourceRegistration(); final Set<String> attributeNames = registry != null ? registry.getAttributeNames(PathAddress.EMPTY_ADDRESS) : Collections.<String>emptySet(); for (final String attributeName : attributeNames) { if ((aliases || !access.getFlags().contains(AttributeAccess.Flag.ALIAS)) && (includeRutime || access.getStorageType() == AttributeAccess.Storage.CONFIGURATION) && (groupName == null || groupName.equals(ad.getAttributeGroup()))) { Map<AttributeDefinition.NameAndGroup, GlobalOperationHandlers.AvailableResponse> responseMap = access.getAccessType() == AttributeAccess.AccessType.METRIC ? metrics : otherAttributes; AttributeDefinition.NameAndGroup nag = ad == null ? new AttributeDefinition.NameAndGroup(attributeName) : new AttributeDefinition.NameAndGroup(ad);
validator.validate(operation); PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); String name = address.getLastElement().getValue(); String runtimeName = operation.hasDefined(RUNTIME_NAME) ? operation.get(RUNTIME_NAME).asString() : name; final ModelNode contentItemNode = content.require(0); if (contentItemNode.hasDefined(HASH)) { managedContentValidator.validate(contentItemNode); hash = contentItemNode.require(HASH).asBytes(); unmanagedContentValidator.validate(contentItemNode); final Resource resource = context.createResource(PathAddress.EMPTY_ADDRESS); final ModelNode subModel = resource.getModel(); subModel.get(NAME).set(name); subModel.get(RUNTIME_NAME).set(runtimeName); subModel.get(CONTENT).set(content); context.completeStep();
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String name = operation.require(NAME).asString(); // Don't require VALUE. Let validateValue decide if it's bothered // by an undefined value final ModelNode value = operation.get(VALUE); validateValue(name, value); final ModelNode submodel = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); final ModelNode currentValue = submodel.get(name).clone(); submodel.get(name).set(value); modelChanged(context, operation, name, value, currentValue); }