@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource existing = context.readResource(PathAddress.EMPTY_ADDRESS); OperationStepHandler addHandler = context.getResourceRegistration().getSubModel(PathAddress.EMPTY_ADDRESS.append(newKeyName)).getOperationHandler(PathAddress.EMPTY_ADDRESS, "add"); ModelNode value = operation.get(VALUE); if (value.isDefined()) { List<ModelNode> modules = new ArrayList<ModelNode>(value.asList()); Collections.reverse(modules); //need to reverse it to make sure they are added in proper order for (ModelNode module : modules) { ModelNode addModuleOp = module.clone(); String code = addModuleOp.get(Constants.CODE).asString(); PathElement relativePath = PathElement.pathElement(newKeyName, code); PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)).append(relativePath); addModuleOp.get(OP_ADDR).set(address.toModelNode()); addModuleOp.get(OP).set(ADD); context.addStep(new ModelNode(), addModuleOp, addHandler, OperationContext.Stage.MODEL, true); } } //remove on the end to make sure it is executed first for (Resource.ResourceEntry entry : existing.getChildren(newKeyName)) { PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)).append(entry.getPathElement()); ModelNode removeModuleOp = Util.createRemoveOperation(address); context.addStep(new ModelNode(), removeModuleOp, new SecurityDomainReloadRemoveHandler(), OperationContext.Stage.MODEL, true); } } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { operationDeprecated(context, operation); PathAddress address = translateProxyPath(context); String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString(); PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type)); PathAddress metricPathAddress = address.append(metricPath); ModelNode metricOperation = Util.createAddOperation(metricPathAddress); OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD); for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) { String name = attribute.getName(); if (operation.hasDefined(name)) { metricOperation.get(name).set(operation.get(name)); } } context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true); } };
@SuppressWarnings("deprecation") @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress address = context.getCurrentAddress().append(BinaryTableResourceDefinition.PATH); ModelNode table = Operations.getAttributeValue(operation); for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass : Arrays.asList(BinaryTableResourceDefinition.Attribute.class, TableResourceDefinition.Attribute.class, TableResourceDefinition.DeprecatedAttribute.class)) { for (org.jboss.as.clustering.controller.Attribute attribute : attributeClass.getEnumConstants()) { ModelNode writeAttributeOperation = Operations.createWriteAttributeOperation(address, attribute, table.get(attribute.getName())); context.addStep(writeAttributeOperation, context.getResourceRegistration().getAttributeAccess(PathAddress.pathAddress(BinaryTableResourceDefinition.PATH), attribute.getName()).getWriteHandler(), context.getCurrentStage()); } } } };
@Override protected void describe(OrderedChildTypesAttachment orderedChildTypesAttachment, Resource resource, ModelNode addressModel, ModelNode result, ImmutableManagementResourceRegistration registration) { if (resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias()) return; result.add(createAddOperation(orderedChildTypesAttachment, addressModel, resource, registration.getChildAddresses(PathAddress.EMPTY_ADDRESS))); PathAddress address = PathAddress.pathAddress(addressModel); for (String type : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(type)) { PathElement path = entry.getPathElement(); ImmutableManagementResourceRegistration childRegistration = Optional.ofNullable(registration.getSubModel(PathAddress.pathAddress(path))).orElse(registration.getSubModel(PathAddress.pathAddress(PathElement.pathElement(path.getKey())))); PathAddress childAddress = address.append(path); this.describe(orderedChildTypesAttachment, entry, childAddress.toModelNode(), result, childRegistration); } } }
@Override public OperationStepHandler apply(OperationStepHandler handler) { return (context, operation) -> { if (this.legacy.test(operation)) { PathElement path = context.getCurrentAddress().getLastElement(); // This is a legacy add operation - process it using the generic handler OperationStepHandler genericHandler = context.getResourceRegistration().getParent().getOperationHandler(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD); Operations.setPathAddress(operation, context.getCurrentAddress().getParent().append(GenericProtocolResourceDefinition.pathElement(path.getValue()))); // Process this step first to preserve protocol order context.addStep(operation, genericHandler, OperationContext.Stage.MODEL, true); } else { handler.execute(context, operation); } }; } }
public static ModelNode readFullModelDescription(PathAddress address, ImmutableManagementResourceRegistration reg) { ModelNode node = new ModelNode(); node.get(ModelDescriptionConstants.MODEL_DESCRIPTION).set(reg.getModelDescription(PathAddress.EMPTY_ADDRESS).getModelDescription(Locale.getDefault())); node.get(ModelDescriptionConstants.ADDRESS).set(address.toModelNode()); for (PathElement pe : reg.getChildAddresses(PathAddress.EMPTY_ADDRESS)) { ModelNode children = node.get(ModelDescriptionConstants.CHILDREN); ImmutableManagementResourceRegistration sub = reg.getSubModel(PathAddress.pathAddress(pe)); children.add(readFullModelDescription(address.append(pe), sub)); } return node; }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource res = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS,false); Set<String> hosts = res.getChildrenNames(HOST); String hostName = hosts.iterator().next(); PathAddress address = PathAddress.pathAddress(PathElement.pathElement(HOST)); //Hacky part we are getting the handler from a real host and calling the operation on /host=* OperationEntry entry = context.getRootResourceRegistration().getOperationEntry(PathAddress.pathAddress(PathElement.pathElement(HOST, hostName)), OPERATION_NAME); ModelNode reportOperation = Util.getEmptyOperation(OPERATION_NAME, address.toModelNode()); if (operation.hasDefined(CREATE_REPORT_DEFINITION.getName())) { reportOperation.get(CREATE_REPORT_DEFINITION.getName()).set(operation.get(CREATE_REPORT_DEFINITION.getName())); if (operation.hasDefined(FILE_FORMAT_DEFINITION.getName())) { reportOperation.get(FILE_FORMAT_DEFINITION.getName()).set(operation.get(FILE_FORMAT_DEFINITION.getName())); } } if (entry != null) { OperationStepHandler osh = entry.getOperationHandler(); context.addStep(reportOperation, osh, OperationContext.Stage.MODEL); } } };
@Override public OperationStepHandler apply(OperationStepHandler handler) { return (context, operation) -> { if (operation.hasDefined(this.attribute.getName())) { // Translate deprecated table attribute into separate add table operation ModelNode addTableOperation = Util.createAddOperation(context.getCurrentAddress().append(this.path)); ModelNode parameters = operation.get(this.attribute.getName()); for (Property parameter : parameters.asPropertyList()) { addTableOperation.get(parameter.getName()).set(parameter.getValue()); } context.addStep(addTableOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(this.path), ModelDescriptionConstants.ADD), context.getCurrentStage()); } handler.execute(context, operation); }; }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { operationDeprecated(context, operation); PathAddress address = translateProxyPath(context); String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString(); PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type)); PathAddress metricPathAddress = address.append(metricPath); ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress); OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE); context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true); } };
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // If this is a legacy configuration containing a default-stack, but no default-channel, then fabricate a default channel using the default stack // This ensures that the default channel factory capability is available to the /subsystem=infinispan/cache-container=*/transport=jgroups resource, which requires them // We can drop this compatibility workaround after we drop support for model version 3.0. if (!operation.hasDefined(Attribute.DEFAULT_CHANNEL.getName()) && operation.hasDefined(Attribute.DEFAULT_STACK.getName())) { String defaultChannel = "auto"; PathAddress channelAddress = context.getCurrentAddress().append(ChannelResourceDefinition.pathElement(defaultChannel)); ModelNode channelOperation = Util.createAddOperation(channelAddress); channelOperation.get(ChannelResourceDefinition.Attribute.STACK.getName()).set(operation.get(Attribute.DEFAULT_STACK.getName())); context.addStep(channelOperation, context.getRootResourceRegistration().getOperationHandler(channelAddress, ModelDescriptionConstants.ADD), OperationContext.Stage.MODEL); operation.get(Attribute.DEFAULT_CHANNEL.getName()).set(new ModelNode(defaultChannel)); } handler.execute(context, operation); } };
definition.validateOperation(operation); PathAddress currentAddress = context.getCurrentAddress(); AttributeDefinition sourceParameter = entry.getKey(); AttributeTranslation translation = entry.getValue(); if (operation.hasDefined(sourceParameter.getName())) { ModelNode value = sourceParameter.validateOperation(operation); ModelNode targetValue = translation.getWriteTranslator().translate(context, value); if (!operation.hasDefined(targetName)) { operation.get(targetName).set(targetValue); ImmutableManagementResourceRegistration targetRegistration = translation.getResourceRegistrationTransformation().apply(context.getResourceRegistration()); OperationStepHandler writeAttributeHandler = targetRegistration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getWriteHandler(); context.addStep(writeAttributeOperation, writeAttributeHandler, OperationContext.Stage.MODEL); ModelNode model = resource.getModel(); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(); for (String attributeName : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { AttributeAccess attribute = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); AttributeDefinition definition = attribute.getAttributeDefinition(); if ((attribute.getStorageType() == AttributeAccess.Storage.CONFIGURATION) && !translations.containsKey(definition)) { addRequiredChildren(context, this.descriptor.getRequiredChildren(), (Resource parent, PathElement path) -> parent.hasChild(path)); addRequiredChildren(context, this.descriptor.getRequiredSingletonChildren(), (Resource parent, PathElement path) -> parent.hasChildren(path.getKey()));
@Override public void execute(OperationContext context, ModelNode operation) { operationDeprecated(context, operation); PathAddress address = context.getCurrentAddress(); String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString(); PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol); PathAddress protocolAddress = address.append(protocolPath); ModelNode removeOperation = Util.createRemoveOperation(protocolAddress); context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(protocolPath), ModelDescriptionConstants.REMOVE), context.getCurrentStage()); } };
private TargetAttribute createTargetAttribute(AuthorizationResponseImpl authResp, String attributeName, boolean isDefaultResponse) { ModelNode model = authResp.targetResource.getResource().getModel(); ModelNode currentValue; if (isDefaultResponse) { //Just use an empty model node to avoid using vault expressions currentValue = new ModelNode(); } else { currentValue = model.has(attributeName) ? model.get(attributeName) : new ModelNode(); } AttributeAccess attributeAccess = authResp.targetResource.getResourceRegistration().getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); return new TargetAttribute(attributeName, attributeAccess, currentValue, authResp.targetResource); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode patchingInfo = new ModelNode(); PathAddress patchingAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "patching")); OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(patchingAddress, "show-history"); if(opEntry != null) { context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress), opEntry.getOperationHandler(), OperationContext.Stage.RUNTIME); } final Path installationDir = environment.getHomeDir().toPath(); context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode result = context.getResult(); result.get(SUMMARY_DEFINITION.getName()).set(createProductNode(context, new InstallationConfiguration( environment, environment.getProductConfig(), patchingInfo, installationDir))); } }, OperationContext.Stage.RUNTIME); } }
private boolean canReadFailureDescription(OperationContext context, ModelNode bootError) { ModelNode completeOPeration = bootError.get(COMPLETE_OP); OperationEntry operationEntry = context.getRootResourceRegistration().getOperationEntry( PathAddress.pathAddress(completeOPeration.get(OP_ADDR)), completeOPeration.get(OP).asString()); Set<Action.ActionEffect> effects = getEffects(operationEntry); return context.authorize(bootError.get(COMPLETE_OP), effects).getDecision() == AuthorizationResult.Decision.PERMIT; }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // Log that this is deprecated ConnectorLogger.ROOT_LOGGER.legacyDisableEnableOperation(operation.get(OP).asString()); // Just delegate to write-attribute. ModelNode writeAttributeOp = getWriteAttributeOperation(context.getCurrentAddress(), Constants.ENABLED.getName(), enabled); OperationStepHandler writeHandler = context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION); // set the addFirst param to 'true' so the write-attribute runs before any other steps already registered; // i.e. in the logically equivalent spot in the sequence to this step context.addStep(writeAttributeOp, writeHandler, OperationContext.Stage.MODEL, true); } }
private void addOperation(OperationContext context, ModelNode op) { final PathAddress addr = PathAddress.pathAddress(op.require(OP_ADDR)); final OperationStepHandler h = context.getRootResourceRegistration().getOperationHandler(addr, op.get(OP).asString()); context.addStep(op, h, OperationContext.Stage.MODEL, true); } }
private void addOpenjdkExtension(final OperationContext context, final Map<PathAddress, ModelNode> migrateOperations) { final PathAddress extensionAddress = PathAddress.EMPTY_ADDRESS.append(OPENJDK_EXTENSION_ELEMENT); OperationEntry addEntry = context.getRootResourceRegistration().getOperationEntry(extensionAddress, ADD); final ModelNode addOperation = Util.createAddOperation(extensionAddress); if (describe) { migrateOperations.put(extensionAddress, addOperation); } else { context.addStep(context.getResult().get(extensionAddress.toString()), addOperation, addEntry.getOperationHandler(), MODEL); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); PathAddress parentAddress = address.getParent(); PathElement path = address.getLastElement(); OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD); if (parentHandler instanceof DescribedAddStepHandler) { AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor(); if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) { context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); context.addStep(operation, this, OperationContext.Stage.MODEL); return; String requiredPathKey = requiredPath.getKey(); if (requiredPath.getKey().equals(path.getKey())) { Set<String> childrenNames = context.readResourceFromRoot(parentAddress, false).getChildrenNames(requiredPathKey); if (!childrenNames.isEmpty()) { PathAddress singletonAddress = parentAddress.append(requiredPathKey, childName); context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); context.addStep(operation, this, OperationContext.Stage.MODEL);
private Object getAttribute(final ResourceAndRegistration reg, final PathAddress address, final ObjectName name, final String attribute) throws ReflectionException, AttributeNotFoundException, InstanceNotFoundException { final ImmutableManagementResourceRegistration registration = getMBeanRegistration(address, reg); final DescriptionProvider provider = registration.getModelDescription(PathAddress.EMPTY_ADDRESS); if (provider == null) { throw MESSAGES.descriptionProviderNotFound(address); } final ModelNode description = provider.getModelDescription(null); final String attributeName = findAttributeName(description.get(ATTRIBUTES), attribute); ModelNode op = new ModelNode(); op.get(OP).set(READ_ATTRIBUTE_OPERATION); op.get(OP_ADDR).set(address.toModelNode()); op.get(NAME).set(attributeName); ModelNode result = execute(op); String error = getFailureDescription(result); if (error != null) { throw new AttributeNotFoundException(error); } return converters.fromModelNode(description.require(ATTRIBUTES).require(attributeName), result.get(RESULT)); }