use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project wildfly by wildfly.
the class AddStepHandler method populateModel.
@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
// Perform operation translation
for (OperationStepHandler translator : this.descriptor.getOperationTranslators()) {
translator.execute(context, operation);
}
// Validate extra add operation parameters
for (AttributeDefinition definition : this.descriptor.getExtraParameters()) {
definition.validateOperation(operation);
}
// Validate and apply attribute translations
Map<AttributeDefinition, AttributeTranslation> translations = this.descriptor.getAttributeTranslations();
for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : translations.entrySet()) {
AttributeDefinition alias = entry.getKey();
AttributeTranslation translation = entry.getValue();
Attribute target = translation.getTargetAttribute();
String targetName = target.getName();
if (operation.hasDefined(alias.getName()) && !operation.hasDefined(targetName)) {
ModelNode value = alias.validateOperation(operation);
ModelNode translatedValue = translation.getWriteTranslator().translate(context, value);
// Target attribute will be validated by super implementation
operation.get(targetName).set(translatedValue);
}
}
// Validate proper attributes
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)) {
definition.validateAndSet(operation, model);
}
}
// Auto-create required child resources as necessary
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()));
}
use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project wildfly by wildfly.
the class AddStepHandler method recordCapabilitiesAndRequirements.
@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
this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.registerCapability(capability.resolve(address)));
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.addCapabilityRequirements(context, model.get(attribute.getName())));
this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.addCapabilityRequirements(context, (String) null, resolver.apply(address)));
}
use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project wildfly by wildfly.
the class DefaultSubsystemDescribeHandler method describe.
@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);
}
}
}
use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project wildfly by wildfly.
the class RemoveStepHandler method performRemove.
@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
// Determine whether super impl will actually remove the resource
boolean remove = !resource.getChildTypes().stream().anyMatch(type -> resource.getChildren(type).stream().filter(entry -> !entry.isRuntime()).map(entry -> entry.getPathElement()).anyMatch(path -> resource.hasChild(path)));
if (remove) {
// We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource
PathAddress address = context.getCurrentAddress();
this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.deregisterCapability(capability.resolve(address).getName()));
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.removeCapabilityRequirements(context, model.get(attribute.getName())));
this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.removeCapabilityRequirements(context, (String) null, resolver.apply(address)));
// Remove any runtime child resources
removeRuntimeChildren(context, PathAddress.EMPTY_ADDRESS);
}
super.performRemove(context, operation, model);
if (remove) {
PathAddress address = context.getResourceRegistration().getPathAddress();
PathElement path = address.getLastElement();
// If override model was registered, unregister it
if (!path.isWildcard() && (context.getResourceRegistration().getParent().getSubModel(PathAddress.pathAddress(path.getKey(), PathElement.WILDCARD_VALUE)) != null)) {
context.getResourceRegistrationForUpdate().unregisterOverrideModel(context.getCurrentAddressValue());
}
}
}
use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project teiid by teiid.
the class TeiidAdd method deployResources.
private void deployResources(OperationContext context) throws OperationFailedException {
if (requiresRuntime(context)) {
try {
Module module = Module.forClass(getClass());
if (module == null) {
// during testing
return;
}
// $NON-NLS-1$
URL deployments = module.getExportedResource("deployments.properties");
if (deployments == null) {
// no deployments
return;
}
BufferedReader in = new BufferedReader(new InputStreamReader(deployments.openStream()));
String deployment;
while ((deployment = in.readLine()) != null) {
PathAddress deploymentAddress = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, deployment));
ModelNode op = new ModelNode();
op.get(OP).set(ADD);
op.get(OP_ADDR).set(deploymentAddress.toModelNode());
op.get(ENABLED).set(true);
// prevents writing this deployment out to standalone.xml
op.get(PERSISTENT).set(false);
URL url = module.getExportedResource(deployment);
String urlString = url.toExternalForm();
ModelNode contentItem = new ModelNode();
contentItem.get(URL).set(urlString);
op.get(CONTENT).add(contentItem);
ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
OperationStepHandler handler = rootResourceRegistration.getOperationHandler(deploymentAddress, ADD);
context.addStep(op, handler, OperationContext.Stage.MODEL);
}
in.close();
} catch (IOException e) {
throw new OperationFailedException(e.getMessage(), e);
}
}
}
Aggregations