Search in sources :

Example 46 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class InfinispanCacheDeploymentListener method startCache.

@Override
public Wrapper startCache(Classification classification, Properties properties) throws Exception {
    String cache_type = properties.getProperty(CACHE_TYPE);
    String container = properties.getProperty(CONTAINER);
    // TODO Figure out how to access CapabilityServiceSupport from here
    ServiceName containerServiceName = ServiceName.parse(InfinispanRequirement.CONTAINER.resolve(container));
    EmbeddedCacheManager embeddedCacheManager;
    ServiceName serviceName;
    if (CACHE_PRIVATE.equals(cache_type)) {
        // need a private cache for non-jpa application use
        String name = properties.getProperty(NAME);
        serviceName = ServiceName.JBOSS.append(DEFAULT_CACHE_CONTAINER, (name != null) ? name : UUID.randomUUID().toString());
        ServiceContainer target = currentServiceContainer();
        // Create a mock service that represents this session factory instance
        ServiceBuilder<EmbeddedCacheManager> builder = new AliasServiceBuilder<>(serviceName, containerServiceName, EmbeddedCacheManager.class).build(target).setInitialMode(ServiceController.Mode.ACTIVE);
        embeddedCacheManager = ServiceContainerHelper.getValue(builder.install());
    } else {
        // need a shared cache for jpa applications
        serviceName = containerServiceName;
        ServiceRegistry registry = currentServiceContainer();
        embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).getValue();
    }
    return new CacheWrapper(embeddedCacheManager, serviceName);
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) CurrentServiceContainer(org.jboss.as.server.CurrentServiceContainer) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder)

Example 47 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class SAMLResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
            if (serviceController != null) {
                SAMLService service = serviceController.getValue();
                ModelNode samlNode;
                if (!rollback) {
                    samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    samlNode = rc.getModel();
                }
                service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) SAMLService(org.wildfly.extension.picketlink.federation.service.SAMLService)

Example 48 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class EntityProviderService method getService.

public static EntityProviderService getService(OperationContext context, String alias) {
    // We assume the mgmt ops that trigger IdentityProviderAddHandler or ServiceProviderAddHandler
    // run before the OperationStepHandler that triggers deploy. If not, that's a user mistake.
    // Since those handlers run first, we can count on MSC having services *registered* even
    // though we cannot count on them being *started*.
    ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
    ServiceController<EntityProviderService> service = (ServiceController<EntityProviderService>) serviceRegistry.getService(IdentityProviderService.createServiceName(alias));
    if (service == null) {
        service = (ServiceController<EntityProviderService>) serviceRegistry.getService(ServiceProviderService.createServiceName(alias));
    }
    if (service == null) {
        return null;
    }
    return service.getValue();
}
Also used : ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 49 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
            if (serviceController != null) {
                KeyStoreProviderService service = serviceController.getValue();
                ModelNode keyStoreProviderNode;
                if (!rollback) {
                    keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    keyStoreProviderNode = rc.getModel();
                }
                ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
                String relativeTo = null;
                if (relativeToNode.isDefined()) {
                    relativeTo = relativeToNode.asString();
                }
                String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
                service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) KeyStoreProviderService(org.wildfly.extension.picketlink.federation.service.KeyStoreProviderService)

Example 50 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project teiid by teiid.

the class EngineStatistics method updateServices.

static void updateServices(OperationContext context, RuntimeVDB vdb, String dsName, ReplaceResult rr) {
    if (rr.isNew) {
        VDBDeployer.addDataSourceListener(context.getServiceTarget(), new VDBKey(vdb.getVdb().getName(), vdb.getVdb().getVersion()), dsName);
    }
    if (rr.removedDs != null) {
        final ServiceRegistry registry = context.getServiceRegistry(true);
        ServiceName serviceName;
        try {
            serviceName = TeiidServiceNames.dsListenerServiceName(vdb.getVdb().getName(), vdb.getVdb().getVersion(), rr.removedDs);
        } catch (InvalidServiceNameException e) {
            // the old isn't valid
            return;
        }
        final ServiceController<?> controller = registry.getService(serviceName);
        if (controller != null) {
            context.removeService(serviceName);
        }
    }
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) InvalidServiceNameException(org.teiid.jboss.TeiidServiceNames.InvalidServiceNameException)

Aggregations

ServiceRegistry (org.jboss.msc.service.ServiceRegistry)74 ServiceName (org.jboss.msc.service.ServiceName)51 ModelNode (org.jboss.dmr.ModelNode)22 PathAddress (org.jboss.as.controller.PathAddress)15 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 OperationFailedException (org.jboss.as.controller.OperationFailedException)13 ServiceController (org.jboss.msc.service.ServiceController)12 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)8 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)8 OperationContext (org.jboss.as.controller.OperationContext)6 Resource (org.jboss.as.controller.registry.Resource)6 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)4 PathElement (org.jboss.as.controller.PathElement)4 DefaultAccessTimeoutService (org.jboss.as.ejb3.component.DefaultAccessTimeoutService)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ArrayList (java.util.ArrayList)2 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)2 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)2