@Override protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); ModelNode model = resource.getModel(); // The super implementation assumes that the capability name is a simple extension of the base name - we do not. // Only register capabilities when allowed by the associated predicate for (Map.Entry<Capability, Predicate<ModelNode>> entry : this.descriptor.getCapabilities().entrySet()) { if (entry.getValue().test(model)) { context.registerCapability(entry.getKey().resolve(address)); } } ImmutableManagementResourceRegistration registration = context.getResourceRegistration(); for (String attributeName : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { AttributeDefinition attribute = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName).getAttributeDefinition(); if (attribute.hasCapabilityRequirements()) { attribute.addCapabilityRequirements(context, resource, model.get(attributeName)); } } for (CapabilityReferenceRecorder recorder : context.getResourceRegistration().getRequirements()) { recorder.addCapabilityRequirements(context, resource, null); } }
ModelNode writeAttributeOperation = Operations.createWriteAttributeOperation(targetAddress, targetAttribute, 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); 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)) { definition.validateAndSet(operation, model);
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress currentAddress = context.getCurrentAddress(); PathAddress targetAddress = this.translation.getPathAddressTransformation().apply(currentAddress); Attribute targetAttribute = this.translation.getTargetAttribute(); ModelNode targetOperation = Operations.createReadAttributeOperation(targetAddress, targetAttribute); ImmutableManagementResourceRegistration targetRegistration = this.translation.getResourceRegistrationTransformation().apply(context.getResourceRegistration()); OperationStepHandler readAttributeHandler = targetRegistration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getReadHandler(); OperationStepHandler readTranslatedAttributeHandler = new ReadTranslatedAttributeStepHandler(readAttributeHandler, targetAttribute, this.translation.getReadTranslator()); // If targetOperation applies to the current resource, we can execute in the current step if (targetAddress == currentAddress) { readTranslatedAttributeHandler.execute(context, targetOperation); } else { context.addStep(targetOperation, readTranslatedAttributeHandler, context.getCurrentStage(), true); } }
private boolean isAddableAttribute(String attrName, ImmutableManagementResourceRegistration resourceRegistration) { AttributeAccess attributeAccess = resourceRegistration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attrName); if (attributeAccess == null) { return false; } if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION && attributeAccess.getAccessType() == AttributeAccess.AccessType.READ_WRITE) { AttributeDefinition ad = attributeAccess.getAttributeDefinition(); if (ad == null) { return false; } if (ad.isRequired() || ad.isNullSignificant()) { // must be set, presence of a default means not setting is the same as setting, // or the AD is specifically configured that null is significant return true; } } return false; }
for (final String attributeName : attributeNames) { final AttributeAccess access = registry.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); final AttributeDefinition ad = access.getAttributeDefinition(); 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); addReadAttributeStep(context, address, defaults, resolve, localFilteredData, registry, nag, responseMap);
if ((aliases || !access.getFlags().contains(AttributeAccess.Flag.ALIAS)) && (queryRuntime || access.getStorageType() == AttributeAccess.Storage.CONFIGURATION)) { Map<String, ModelNode> responseMap = access.getAccessType() == AttributeAccess.AccessType.METRIC ? metrics : otherAttributes;
throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownAttribute(attributeName)); assert attributeAccess.getAttributeDefinition() != null; if (attributeAccess.getReadHandler() == null) { resolveAttribute(context, attributeAccess.getAttributeDefinition(), attributeExpression, defaults, useEnhancedSyntax); } else { OperationStepHandler handler = attributeAccess.getReadHandler(); ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(handler.getClass()); try { if (attributeAccess.getAccessType() == AttributeAccess.AccessType.METRIC) { if (!context.getResult().isDefined() && !includeUndefinedMetricValue) { ModelNode undefinedMetricValue = attributeAccess.getAttributeDefinition().getUndefinedMetricValue(); if (undefinedMetricValue != null) { context.getResult().set(undefinedMetricValue); if (AttributeAccess.Storage.CONFIGURATION == attributeAccess.getStorageType()) { ModelNode resolved = EnhancedSyntaxSupport.resolveEnhancedSyntax(remainingExpression, context.getResult(), attributeAccess.getAttributeDefinition()); context.getResult().set(resolved); } else { assert AttributeAccess.Storage.RUNTIME == attributeAccess.getStorageType(); attributeAccess.getAttributeDefinition()); context.getResult().set(resolved); }, OperationContext.Stage.RUNTIME);
for (final String attributeName : attributeNames) { final AttributeAccess access = registry.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); if (access == null || access.getFlags().contains(AttributeAccess.Flag.ALIAS) && !aliases) { continue; } else { final AttributeAccess.Storage storage = access.getStorageType(); final AttributeAccess.AccessType type = access.getAccessType(); final OperationStepHandler handler = access.getReadHandler(); if (handler != null) {
for (String attr : attributeNames) { AttributeAccess attributeAccess = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attr); if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION) { AttributeDefinition def = attributeAccess.getAttributeDefinition(); if (def != null) { if (!def.isResourceOnly()){
if (attributeAccess == null) { 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 { if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION) { ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); currentValue = model.has(attributeName) ? model.get(attributeName) : new ModelNode(); if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION && !registry.isRuntimeOnly()) { OperationStepHandler writeHandler = attributeAccess.getWriteHandler(); ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(writeHandler.getClass()); try { assert attributeAccess.getStorageType() == AttributeAccess.Storage.RUNTIME;
if (access.getStorageType() == AttributeAccess.Storage.CONFIGURATION) { boolean hasCurrent = current.add.hasDefined(attribute); boolean hasRemote = remote.add.hasDefined(attribute); if (access.getAccessType() == AttributeAccess.AccessType.READ_WRITE) { } else if (access.getAccessType() == AttributeAccess.AccessType.READ_ONLY) { ModelNode currentValue = hasCurrent ? current.add.get(attribute) : new ModelNode(); ModelNode removeValue = hasRemote ? remote.add.get(attribute) : new ModelNode();
private void doExecuteInternal(OperationContext context, ModelNode operation, AttributeAccess attributeAccess, String attributeName, ModelNode currentValue, boolean useEnhancedSyntax, String attributeExpression) throws OperationFailedException { if (useEnhancedSyntax){ if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION) { operation = getEnhancedSyntaxResolvedOperation(operation, currentValue, attributeName, attributeExpression); } else { assert attributeAccess.getStorageType() == AttributeAccess.Storage.RUNTIME; // Resolution must be postponed to RUNTIME stage for Storage.RUNTIME attributes. final ModelNode originalOperation = operation; // final vars so they can be accessed from lambda final ModelNode resolvedOperation = operation.clone(); operation = resolvedOperation; context.addStep((context1, operation1) -> { ModelNode resolved = getEnhancedSyntaxResolvedOperation(originalOperation, currentValue, attributeName, attributeExpression); resolvedOperation.get(ModelDescriptionConstants.NAME).set(resolved.get(ModelDescriptionConstants.NAME)); resolvedOperation.get(ModelDescriptionConstants.VALUE).set(resolved.get(ModelDescriptionConstants.VALUE)); }, OperationContext.Stage.RUNTIME); } } OperationStepHandler writeHandler = attributeAccess.getWriteHandler(); ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(writeHandler.getClass()); try { writeHandler.execute(context, operation); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl); } } private void emitAttributeValueWrittenNotification(OperationContext context, PathAddress address, String attributeName, ModelNode oldValue, ModelNode newValue) {
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { nameValidator.validate(operation); final String attributeName = operation.require(GlobalOperationHandlers.NAME.getName()).asString(); final AttributeAccess attributeAccess = context.getResourceRegistration().getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); if (attributeAccess == null) { 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 { OperationStepHandler handler = attributeAccess.getWriteHandler(); ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(handler.getClass()); try { handler.execute(context, operation); } finally { SecurityActions.setThreadContextClassLoader(oldTccl); } } } }
/** * Get the storage type. * * @return the storage type */ public AttributeAccess.Storage getStorageType() { return attributeAccess == null ? null : attributeAccess.getStorageType(); }
/** * Get the access type. * * @return the access type */ public AttributeAccess.AccessType getAccessType() { return attributeAccess == null ? null : attributeAccess.getAccessType(); }
@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 public void registerReadOnlyAttribute(final String attributeName, final OperationStepHandler readHandler, AttributeAccess.Storage storage) { AttributeAccess aa = new AttributeAccess(AttributeAccess.AccessType.READ_ONLY, storage, readHandler, null, null, null); if (attributesUpdater.putIfAbsent(this, attributeName, aa) != null) { throw alreadyRegistered("attribute", attributeName); } }
/** * Gets the flags associated with this attribute. * @return the flags. Will not return {@code null} */ public Set<AttributeAccess.Flag> getFlags() { if (attributeAccess == null) { return Collections.emptySet(); } return attributeAccess.getFlags(); }
private boolean isAddableAttribute(String attrName, ImmutableManagementResourceRegistration resourceRegistration) { AttributeAccess attributeAccess = resourceRegistration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attrName); if (attributeAccess == null) { return false; } if (attributeAccess.getStorageType() == AttributeAccess.Storage.CONFIGURATION && attributeAccess.getAccessType() == AttributeAccess.AccessType.READ_WRITE) { AttributeDefinition ad = attributeAccess.getAttributeDefinition(); if (ad == null) { return false; } if (ad.isRequired() || ad.isNullSignificant()) { // must be set, presence of a default means not setting is the same as setting, // or the AD is specifically configured that null is significant return true; } } return false; }
for (final String attributeName : attributeNames) { final AttributeAccess access = registry.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); final AttributeDefinition ad = access.getAttributeDefinition(); 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); addReadAttributeStep(context, address, defaults, resolve, localFilteredData, registry, nag, responseMap);