use of org.jboss.as.controller.OperationFailedException in project wildfly by wildfly.
the class JGroupsTransportServiceHandler method removeServices.
@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
PathAddress containerAddress = address.getParent();
String name = containerAddress.getLastElement().getValue();
for (GroupAliasBuilderProvider provider : ServiceLoader.load(GroupAliasBuilderProvider.class, GroupAliasBuilderProvider.class.getClassLoader())) {
for (ServiceNameProvider builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, null)) {
context.removeService(builder.getServiceName());
}
}
EnumSet.allOf(CacheContainerComponent.class).stream().map(component -> component.getServiceName(containerAddress)).forEach(serviceName -> context.removeService(serviceName));
}
use of org.jboss.as.controller.OperationFailedException 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.OperationFailedException in project wildfly by wildfly.
the class AbstractEJBComponentResourceDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
final AbstractEJBComponentRuntimeHandler<?> handler = componentType.getRuntimeHandler();
resourceRegistration.registerReadOnlyAttribute(COMPONENT_CLASS_NAME, handler);
resourceRegistration.registerReadOnlyAttribute(SECURITY_DOMAIN, handler);
resourceRegistration.registerReadOnlyAttribute(RUN_AS_ROLE, handler);
resourceRegistration.registerReadOnlyAttribute(DECLARED_ROLES, handler);
if (componentType.hasTimer()) {
resourceRegistration.registerReadOnlyAttribute(TimerAttributeDefinition.INSTANCE, handler);
}
if (componentType.hasPool()) {
resourceRegistration.registerReadOnlyAttribute(POOL_AVAILABLE_COUNT, handler);
resourceRegistration.registerReadOnlyAttribute(POOL_CREATE_COUNT, handler);
resourceRegistration.registerReadOnlyAttribute(POOL_NAME, handler);
resourceRegistration.registerReadOnlyAttribute(POOL_REMOVE_COUNT, handler);
resourceRegistration.registerReadOnlyAttribute(POOL_CURRENT_SIZE, handler);
resourceRegistration.registerReadWriteAttribute(POOL_MAX_SIZE, handler, handler);
}
if (componentType.equals(EJBComponentType.STATEFUL)) {
resourceRegistration.registerMetric(CACHE_SIZE, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(((StatefulSessionComponent) component).getCache().getCacheSize());
}
});
resourceRegistration.registerMetric(PASSIVATED_SIZE, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(((StatefulSessionComponent) component).getCache().getPassivatedCount());
}
});
resourceRegistration.registerMetric(TOTAL_SIZE, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(((StatefulSessionComponent) component).getCache().getTotalSize());
}
});
}
resourceRegistration.registerMetric(EXECUTION_TIME, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(component.getInvocationMetrics().getExecutionTime());
}
});
resourceRegistration.registerMetric(INVOCATIONS, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(component.getInvocationMetrics().getInvocations());
}
});
resourceRegistration.registerMetric(PEAK_CONCURRENT_INVOCATIONS, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(component.getInvocationMetrics().getPeakConcurrent());
}
});
resourceRegistration.registerMetric(WAIT_TIME, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().set(component.getInvocationMetrics().getWaitTime());
}
});
resourceRegistration.registerMetric(METHODS, new AbstractRuntimeMetricsHandler() {
@Override
protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
context.getResult().setEmptyObject();
for (final Map.Entry<String, InvocationMetrics.Values> entry : component.getInvocationMetrics().getMethods().entrySet()) {
final InvocationMetrics.Values values = entry.getValue();
final ModelNode result = new ModelNode();
result.get("execution-time").set(values.getExecutionTime());
result.get("invocations").set(values.getInvocations());
result.get("wait-time").set(values.getWaitTime());
context.getResult().get(entry.getKey()).set(result);
}
}
});
}
use of org.jboss.as.controller.OperationFailedException 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.OperationFailedException 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());
}
}
}
Aggregations