use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class JChannelFactoryBuilder method configure.
@Override
public Builder<ChannelFactory> configure(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
Optional<PathElement> transport = resource.getChildren(TransportResourceDefinition.WILDCARD_PATH.getKey()).stream().map(Resource.ResourceEntry::getPathElement).findFirst();
if (!transport.isPresent()) {
throw JGroupsLogger.ROOT_LOGGER.transportNotDefined(this.getName());
}
this.transport = new InjectedValueDependency<>(new SingletonProtocolServiceNameProvider(address, transport.get()), TransportConfiguration.class);
this.protocols = resource.getChildren(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).stream().map(entry -> new InjectedValueDependency<>(new ProtocolServiceNameProvider(address, entry.getPathElement()), ProtocolConfiguration.class)).collect(Collectors.toList());
this.relay = resource.hasChild(RelayResourceDefinition.PATH) ? new InjectedValueDependency<>(new SingletonProtocolServiceNameProvider(address, RelayResourceDefinition.PATH), RelayConfiguration.class) : null;
return this;
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class JGroupsSubsystemServiceHandler method installServices.
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
ROOT_LOGGER.activatingSubsystem(Version.printVersion());
ServiceTarget target = context.getServiceTarget();
PathAddress address = context.getCurrentAddress();
// In this case, the Infinispan subsystem may have already registered default group capabilities
if (context.getProcessType().isServer() && !context.isBooting()) {
Resource rootResource = context.readResourceFromRoot(address.getParent());
if (rootResource.hasChild(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan"))) {
// Following restart, default group services will be installed by this handler, rather than the infinispan subsystem handler
context.addStep((ctx, operation) -> {
ctx.reloadRequired();
ctx.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
}, OperationContext.Stage.RUNTIME);
return;
}
}
new ProtocolDefaultsBuilder().build(target).install();
ModelNodes.optionalString(DEFAULT_CHANNEL.resolveModelAttribute(context, model)).ifPresent(defaultChannel -> {
CAPABILITIES.entrySet().forEach(entry -> new AliasServiceBuilder<>(entry.getValue().getServiceName(address), entry.getKey().getServiceName(context, defaultChannel), entry.getKey().getType()).build(target).install());
if (!defaultChannel.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) {
new BinderServiceBuilder<>(JGroupsBindingFactory.createChannelBinding(JndiNameFactory.DEFAULT_LOCAL_NAME), JGroupsRequirement.CHANNEL.getServiceName(context, defaultChannel), JGroupsRequirement.CHANNEL.getType()).build(target).install();
new BinderServiceBuilder<>(JGroupsBindingFactory.createChannelFactoryBinding(JndiNameFactory.DEFAULT_LOCAL_NAME), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, defaultChannel), JGroupsRequirement.CHANNEL_FACTORY.getType()).build(target).install();
}
for (GroupAliasBuilderProvider provider : ServiceLoader.load(GroupAliasBuilderProvider.class, GroupAliasBuilderProvider.class.getClassLoader())) {
for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), null, defaultChannel)) {
builder.configure(context).build(target).install();
}
}
});
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class ServerRemove method performRemove.
@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
// add a runtime step to remove services related to broadcast-group/discovery-group that are started
// when the server is added.
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String serverName = context.getCurrentAddressValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(serverName);
for (final Resource.ResourceEntry broadcastGroup : resource.getChildren(CommonAttributes.BROADCAST_GROUP)) {
context.removeService(GroupBindingService.getBroadcastBaseServiceName(serviceName).append(broadcastGroup.getName()));
}
for (final Resource.ResourceEntry divertGroup : resource.getChildren(CommonAttributes.DISCOVERY_GROUP)) {
context.removeService(GroupBindingService.getDiscoveryBaseServiceName(serviceName).append(divertGroup.getName()));
}
}
}, OperationContext.Stage.RUNTIME);
super.performRemove(context, operation, model);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class AddressSettingsValidator method validateModel.
/**
* Validate that an updated address-settings still has resources bound corresponding
* to expiry-address and dead-letter-address (if they are defined).
*/
static void validateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
String addressSetting = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
PathAddress address = pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
Resource activeMQServer = context.readResourceFromRoot(MessagingServices.getActiveMQServerPathAddress(address), true);
checkExpiryAddress(context, resource.getModel(), activeMQServer, addressSetting);
checkDeadLetterAddress(context, resource.getModel(), activeMQServer, addressSetting);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class QueueDefinition method forwardToRuntimeQueue.
/**
* [AS7-5850] Core queues created with ActiveMQ API does not create WildFly resources
*
* For backwards compatibility if an operation is invoked on a queue that has no corresponding resources,
* we forward the operation to the corresponding runtime-queue resource (which *does* exist).
*
* @return true if the operation is forwarded to the corresponding runtime-queue resource, false else.
*/
static boolean forwardToRuntimeQueue(OperationContext context, ModelNode operation, OperationStepHandler handler) {
PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
// do not forward if the current operation is for a runtime-queue already:
if (RUNTIME_QUEUE.equals(address.getLastElement().getKey())) {
return false;
}
String queueName = address.getLastElement().getValue();
PathAddress activeMQPathAddress = MessagingServices.getActiveMQServerPathAddress(address);
Resource serverResource = context.readResourceFromRoot(activeMQPathAddress);
boolean hasChild = serverResource.hasChild(address.getLastElement());
if (hasChild) {
return false;
} else {
// there is no registered queue resource, forward to the runtime-queue address instead
ModelNode forwardOperation = operation.clone();
forwardOperation.get(ModelDescriptionConstants.OP_ADDR).set(activeMQPathAddress.append(RUNTIME_QUEUE, queueName).toModelNode());
context.addStep(forwardOperation, handler, OperationContext.Stage.RUNTIME, true);
return true;
}
}
Aggregations