use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class TransportResourceDefinition method register.
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = super.register(parent);
new WriteAttributeStepHandler(new WriteThreadingAttributeStepHandlerDescriptor()) {
@Override
protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException {
// Add a new step to validate instead of doing it directly in this method.
// This allows a composite op to change both attributes and then the
// validation occurs after both have done their work.
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode conf = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
// TODO doesn't cover the admin-only modes
if (context.getProcessType().isServer()) {
for (ThreadingAttribute attribute : EnumSet.allOf(ThreadingAttribute.class)) {
if (conf.hasDefined(attribute.getName())) {
// That is not supported.
throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.threadsAttributesUsedInRuntime());
}
}
}
}
}, OperationContext.Stage.MODEL);
}
}.register(registration);
if (registration.getPathAddress().getLastElement().isWildcard()) {
for (ThreadPoolResourceDefinition pool : EnumSet.allOf(ThreadPoolResourceDefinition.class)) {
pool.register(registration);
}
parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {
@Override
public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
PathAddress target = this.getTargetAddress();
List<PathElement> result = new ArrayList<>(aliasAddress.size());
for (int i = 0; i < aliasAddress.size(); ++i) {
PathElement element = aliasAddress.getElement(i);
if (i == target.size() - 1) {
final ModelNode operation = aliasContext.getOperation();
final String stackName;
if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) {
stackName = operation.get("type").asString();
} else {
Resource root = null;
try {
root = aliasContext.readResourceFromRoot(PathAddress.pathAddress(result));
} catch (Resource.NoSuchResourceException ignored) {
}
if (root == null) {
stackName = "*";
} else {
Set<String> names = root.getChildrenNames("transport");
if (names.size() > 1) {
throw new AssertionError("There should be at most one child");
} else if (names.size() == 0) {
stackName = "*";
} else {
stackName = names.iterator().next();
}
}
}
result.add(PathElement.pathElement("transport", stackName));
} else if (i < target.size()) {
PathElement targetElement = target.getElement(i);
result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement);
} else {
result.add(element);
}
}
return PathAddress.pathAddress(result);
}
});
}
return registration;
}
use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class AddStepHandler method populateModel.
@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
// Validate extra add operation parameters
for (AttributeDefinition definition : this.descriptor.getExtraParameters()) {
definition.validateOperation(operation);
}
PathAddress currentAddress = context.getCurrentAddress();
// Validate and apply attribute translations
Map<AttributeDefinition, AttributeTranslation> translations = this.descriptor.getAttributeTranslations();
for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : translations.entrySet()) {
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);
Attribute targetAttribute = translation.getTargetAttribute();
PathAddress targetAddress = translation.getPathAddressTransformation().apply(currentAddress);
// Otherwise, we need a separate write-attribute operation
if (targetAddress == currentAddress) {
String targetName = targetAttribute.getName();
if (!operation.hasDefined(targetName)) {
operation.get(targetName).set(targetValue);
}
} else {
ModelNode writeAttributeOperation = Operations.createWriteAttributeOperation(targetAddress, targetAttribute, targetValue);
ImmutableManagementResourceRegistration registration = (currentAddress == targetAddress) ? context.getResourceRegistration() : context.getRootResourceRegistration().getSubModel(targetAddress);
if (registration == null) {
throw new OperationFailedException(ControllerLogger.MGMT_OP_LOGGER.noSuchResourceType(targetAddress));
}
OperationStepHandler writeAttributeHandler = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getWriteHandler();
context.addStep(writeAttributeOperation, writeAttributeHandler, OperationContext.Stage.MODEL);
}
}
}
// 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)) {
OperationStepHandler writeHandler = this.descriptor.getCustomAttributes().get(definition);
if (writeHandler != null) {
// If attribute has custom handling, perform a separate write-attribute operation
ModelNode writeAttributeOperation = Util.getWriteAttributeOperation(currentAddress, definition.getName(), definition.validateOperation(operation));
context.addStep(writeAttributeOperation, writeHandler, OperationContext.Stage.MODEL);
} else {
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()));
// Don't leave model undefined
if (!model.isDefined()) {
model.setEmptyObject();
}
}
use of org.jboss.as.controller.PathElement 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.PathElement in project wildfly by wildfly.
the class JobOperationStepHandler method getServiceName.
private static ServiceName getServiceName(final OperationContext context) {
final PathAddress address = context.getCurrentAddress();
String deploymentName = null;
String subdeploymentName = null;
for (PathElement element : address) {
if (ModelDescriptionConstants.DEPLOYMENT.equals(element.getKey())) {
deploymentName = getRuntimeName(context, element);
} else if (ModelDescriptionConstants.SUBDEPLOYMENT.endsWith(element.getKey())) {
subdeploymentName = element.getValue();
}
}
if (deploymentName == null) {
throw BatchLogger.LOGGER.couldNotFindDeploymentName(address.toString());
}
if (subdeploymentName == null) {
return BatchServiceNames.jobOperatorServiceName(deploymentName);
}
return BatchServiceNames.jobOperatorServiceName(deploymentName, subdeploymentName);
}
use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class RaAdd method performRuntime.
@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
// TODO WFLY-15231 -- this logic is using the wrong attributes, so it's currently doing nothing
if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
if (model.hasDefined(SECURITY_DOMAIN.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
else if (model.hasDefined(APPLICATION.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
} else {
if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
}
// do the same for recovery security attributes
if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
} else {
if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
}
// Compensating is remove
final String name = context.getCurrentAddressValue();
final String archiveOrModuleName;
final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
}
if (model.get(ARCHIVE.getName()).isDefined()) {
archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
} else {
archiveOrModuleName = model.get(MODULE.getName()).asString();
}
ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
if (model.get(ARCHIVE.getName()).isDefined()) {
RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
} else {
RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
if (context.isBooting()) {
context.addStep(new OperationStepHandler() {
public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
// Next lines activate configuration on module deployed rar
// in case there is 2 different resource-adapter config using same module deployed rar
// a Deployment sercivice could be already present and need a restart to consider also this
// newly added configuration
ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
if (restartedServiceName == null) {
RaOperationUtil.activate(context, name, archiveOrModuleName);
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
} catch (OperationFailedException e) {
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
Activation raxml = (Activation) RaxmlController.getValue();
ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
String bootStrapCtxName = DEFAULT_NAME;
if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
bootStrapCtxName = raxml.getBootstrapContext();
}
ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, raStatsService.getBootstrapContextInjector()).addDependency(serviceName, Object.class, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
resource.registerChild(peStats, statsResource);
}
Aggregations