use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class CachedConnectionManagerRemove method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
// This is an odd case where we do not actually do a remove; we just reset state to
// what it would be following parsing if the xml element does not exist.
// See discussion on PR with fix for WFLY-2640 .
ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();
for (JcaCachedConnectionManagerDefinition.CcmParameters param : JcaCachedConnectionManagerDefinition.CcmParameters.values()) {
AttributeDefinition ad = param.getAttribute();
if (param == INSTALL || param == DEBUG || param == ERROR || param == IGNORE_UNKNOWN_CONNECTIONS) {
model.get(ad.getName()).clear();
} else {
// Someone added a new param since wFLY-2640/WFLY-8141 and did not account for it above
throw new IllegalStateException();
}
}
// At the time of WFLY-2640 there were no capabilities associated with this resource,
// but if anyone adds one, part of the task is to deal with deregistration.
// So here's an assert to ensure that is considered
Set<RuntimeCapability> capabilitySet = context.getResourceRegistration().getCapabilities();
assert capabilitySet.isEmpty();
if (context.isDefaultRequiresRuntime()) {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException {
context.reloadRequired();
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext operationContext, ModelNode modelNode) {
context.revertReloadRequired();
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class CacheContainerServiceHandler method installServices.
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
String name = context.getCurrentAddressValue();
// This can happen if the ejb cache-container is added to a running server
if (context.getProcessType().isServer() && !context.isBooting() && name.equals("ejb")) {
Resource rootResource = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
PathElement ejbPath = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "ejb3");
if (rootResource.hasChild(ejbPath) && rootResource.getChild(ejbPath).hasChild(PathElement.pathElement("service", "remote"))) {
// Following restart, these services will be installed by this handler, rather than the ejb remote handler
context.addStep(new OperationStepHandler() {
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
context.reloadRequired();
context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
return;
}
}
ServiceTarget target = context.getServiceTarget();
new ModuleBuilder(CacheContainerComponent.MODULE.getServiceName(address), MODULE).configure(context, model).build(target).install();
new GlobalConfigurationBuilder(address).configure(context, model).build(target).install();
CacheContainerBuilder containerBuilder = new CacheContainerBuilder(address).configure(context, model);
containerBuilder.build(target).install();
new KeyAffinityServiceFactoryBuilder(address).build(target).install();
BinderServiceBuilder<?> bindingBuilder = new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheContainerBinding(name), containerBuilder.getServiceName(), CacheContainer.class);
ModelNodes.optionalString(JNDI_NAME.resolveModelAttribute(context, model)).map(jndiName -> ContextNames.bindInfoFor(JndiNameFactory.parse(jndiName).getAbsoluteName())).ifPresent(aliasBinding -> bindingBuilder.alias(aliasBinding));
bindingBuilder.build(target).install();
String defaultCache = containerBuilder.getDefaultCache();
if (defaultCache != null) {
DEFAULT_CAPABILITIES.entrySet().forEach(entry -> new AliasServiceBuilder<>(entry.getValue().getServiceName(address), entry.getKey().getServiceName(context, name, defaultCache), entry.getKey().getType()).build(target).install());
if (!defaultCache.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) {
new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME), DEFAULT_CAPABILITIES.get(InfinispanCacheRequirement.CACHE).getServiceName(address), Cache.class).build(target).install();
new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheConfigurationBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME), DEFAULT_CAPABILITIES.get(InfinispanCacheRequirement.CONFIGURATION).getServiceName(address), Configuration.class).build(target).install();
}
for (CacheAliasBuilderProvider provider : ServiceLoader.load(CacheAliasBuilderProvider.class, CacheAliasBuilderProvider.class.getClassLoader())) {
for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> DEFAULT_CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, null, defaultCache)) {
builder.configure(context).build(target).install();
}
}
}
}
use of org.jboss.as.controller.OperationStepHandler 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.OperationStepHandler in project wildfly by wildfly.
the class RaActivate method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
final String idName = PathAddress.pathAddress(address).getLastElement().getValue();
ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
final String archiveOrModuleName;
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();
}
if (context.isNormalServer()) {
context.addStep(new OperationStepHandler() {
public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, idName);
if (restartedServiceName == null) {
RaOperationUtil.activate(context, idName, archiveOrModuleName);
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName);
} catch (OperationFailedException e) {
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
context.stepCompleted();
}
use of org.jboss.as.controller.OperationStepHandler 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();
// domains/application attributes should only be defined when Elytron enabled is undefined or false (default value)
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), raStatsService.getBootstrapContextInjector()).addDependency(serviceName, 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