@Override default ServiceName getServiceName(PathAddress address) { return this.resolve(address).getCapabilityServiceName(); } }
@Override default RuntimeCapability<?> resolve(PathAddress address) { return this.getCapability().resolve(address); }
protected String getDependentName(OperationContext context) { return this.capability.resolve(context.getCurrentAddress()).getName(); }
@Override protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attribute, ModelNode newValue, ModelNode oldValue) { Map<Capability, Predicate<ModelNode>> capabilities = this.descriptor.getCapabilities(); if (!capabilities.isEmpty()) { PathAddress address = context.getCurrentAddress(); // newValue is already applied to the model ModelNode newModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode oldModel = newModel.clone(); oldModel.get(attribute.getName()).set(oldValue); for (Map.Entry<Capability, Predicate<ModelNode>> entry : capabilities.entrySet()) { Capability capability = entry.getKey(); Predicate<ModelNode> predicate = entry.getValue(); boolean registered = predicate.test(oldModel); boolean shouldRegister = predicate.test(newModel); if (!registered && shouldRegister) { // Attribute change enables capability registration context.registerCapability(capability.resolve(address)); } else if (registered && !shouldRegister) { // Attribute change disables capability registration context.deregisterCapability(capability.resolve(address).getName()); } } } super.recordCapabilitiesAndRequirements(context, attribute, newValue, oldValue); }
@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); } }
@Override protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); if (removeInCurrentStep(resource)) { // We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource PathAddress address = context.getCurrentAddress(); for (Map.Entry<Capability, Predicate<ModelNode>> entry : this.descriptor.getCapabilities().entrySet()) { if (entry.getValue().test(model)) { context.deregisterCapability(entry.getKey().resolve(address).getName()); } } 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.removeCapabilityRequirements(context, resource, model.get(attributeName)); } } for (CapabilityReferenceRecorder recorder : registration.getRequirements()) { recorder.removeCapabilityRequirements(context, resource, null); } if (this.requiresRuntime(context)) { for (RuntimeResourceRegistration runtimeRegistration : this.descriptor.getRuntimeResourceRegistrations()) { runtimeRegistration.unregister(context); } } } super.performRemove(context, operation, model); }
@Override default ServiceName getServiceName(PathAddress address) { return this.resolve(address).getCapabilityServiceName(); } }
@Override default RuntimeCapability<?> resolve(PathAddress address) { return this.getCapability().resolve(address); }
protected String getDependentName(OperationContext context) { return this.capability.resolve(context.getCurrentAddress()).getName(); }
@Override protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attribute, ModelNode newValue, ModelNode oldValue) { Map<Capability, Predicate<ModelNode>> capabilities = this.descriptor.getCapabilities(); if (!capabilities.isEmpty()) { PathAddress address = context.getCurrentAddress(); // newValue is already applied to the model ModelNode newModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode oldModel = newModel.clone(); oldModel.get(attribute.getName()).set(oldValue); for (Map.Entry<Capability, Predicate<ModelNode>> entry : capabilities.entrySet()) { Capability capability = entry.getKey(); Predicate<ModelNode> predicate = entry.getValue(); boolean registered = predicate.test(oldModel); boolean shouldRegister = predicate.test(newModel); if (!registered && shouldRegister) { // Attribute change enables capability registration context.registerCapability(capability.resolve(address)); } else if (registered && !shouldRegister) { // Attribute change disables capability registration context.deregisterCapability(capability.resolve(address).getName()); } } } super.recordCapabilitiesAndRequirements(context, attribute, newValue, oldValue); }
@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); } }
@Override protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); if (removeInCurrentStep(resource)) { // We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource PathAddress address = context.getCurrentAddress(); for (Map.Entry<Capability, Predicate<ModelNode>> entry : this.descriptor.getCapabilities().entrySet()) { if (entry.getValue().test(model)) { context.deregisterCapability(entry.getKey().resolve(address).getName()); } } 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.removeCapabilityRequirements(context, resource, model.get(attributeName)); } } for (CapabilityReferenceRecorder recorder : registration.getRequirements()) { recorder.removeCapabilityRequirements(context, resource, null); } if (this.requiresRuntime(context)) { for (RuntimeResourceRegistration runtimeRegistration : this.descriptor.getRuntimeResourceRegistrations()) { runtimeRegistration.unregister(context); } } } super.performRemove(context, operation, model); }