Search in sources :

Example 61 with Resource

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;
}
Also used : ProtocolConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolConfiguration) PathElement(org.jboss.as.controller.PathElement) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) TransportConfiguration(org.wildfly.clustering.jgroups.spi.TransportConfiguration)

Example 62 with Resource

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();
            }
        }
    });
}
Also used : BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) GroupAliasBuilderProvider(org.wildfly.clustering.spi.GroupAliasBuilderProvider) ServiceTarget(org.jboss.msc.service.ServiceTarget) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 63 with Resource

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);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ServiceName(org.jboss.msc.service.ServiceName) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 64 with Resource

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);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 65 with Resource

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;
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4