Search in sources :

Example 41 with ServiceController

use of org.jboss.msc.service.ServiceController 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 42 with ServiceController

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

the class WritableServiceBasedNamingStoreTestCase method setup.

@Before
public void setup() throws Exception {
    container = ServiceContainer.Factory.create();
    installOwnerService(OWNER_FOO);
    installOwnerService(OWNER_BAR);
    final CountDownLatch latch2 = new CountDownLatch(1);
    final NamingStoreService namingStoreService = new NamingStoreService();
    container.addService(ContextNames.JAVA_CONTEXT_SERVICE_NAME, namingStoreService).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<NamingStore>() {

        public void transition(ServiceController<? extends NamingStore> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        latch2.countDown();
                        break;
                    }
                case STARTING_to_START_FAILED:
                    {
                        latch2.countDown();
                        fail("Did not install store service - " + controller.getStartException().getMessage());
                        break;
                    }
                default:
                    break;
            }
        }
    }).install();
    latch2.await(10, TimeUnit.SECONDS);
    store = (WritableServiceBasedNamingStore) namingStoreService.getValue();
}
Also used : NamingStoreService(org.jboss.as.naming.service.NamingStoreService) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 43 with ServiceController

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

the class WritableServiceBasedNamingStoreTestCase method installOwnerService.

private void installOwnerService(ServiceName owner) throws InterruptedException {
    final CountDownLatch latch1 = new CountDownLatch(1);
    container.addService(JndiNamingDependencyProcessor.serviceName(owner), new RuntimeBindReleaseService()).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<Object>() {

        public void transition(ServiceController<?> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        latch1.countDown();
                        break;
                    }
                case STARTING_to_START_FAILED:
                    {
                        latch1.countDown();
                        fail("Did not install store service - " + controller.getStartException().getMessage());
                        break;
                    }
                default:
                    break;
            }
        }
    }).install();
    latch1.await(10, TimeUnit.SECONDS);
}
Also used : AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService)

Example 44 with ServiceController

use of org.jboss.msc.service.ServiceController 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 45 with ServiceController

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

the class CacheFactoryAdd method installRuntimeServices.

Collection<ServiceController<?>> installRuntimeServices(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler) throws OperationFailedException {
    final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
    ModelNode passivationStoreModel = CacheFactoryResourceDefinition.PASSIVATION_STORE.resolveModelAttribute(context, model);
    String passivationStore = passivationStoreModel.isDefined() ? passivationStoreModel.asString() : null;
    final Collection<String> unwrappedAliasValues = CacheFactoryResourceDefinition.ALIASES.unwrap(context, model);
    final Set<String> aliases = unwrappedAliasValues != null ? new HashSet<>(unwrappedAliasValues) : Collections.<String>emptySet();
    ServiceTarget target = context.getServiceTarget();
    ServiceBuilder<?> builder = buildCacheFactoryBuilder(target, name, passivationStore);
    for (String alias : aliases) {
        builder.addAliases(CacheFactoryBuilderService.getServiceName(alias));
    }
    if (verificationHandler != null) {
        builder.addListener(verificationHandler);
    }
    return Collections.<ServiceController<?>>singleton(builder.install());
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ServiceController (org.jboss.msc.service.ServiceController)52 ServiceName (org.jboss.msc.service.ServiceName)20 ModelNode (org.jboss.dmr.ModelNode)17 OperationFailedException (org.jboss.as.controller.OperationFailedException)15 OperationContext (org.jboss.as.controller.OperationContext)12 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 BinderService (org.jboss.as.naming.service.BinderService)9 PathAddress (org.jboss.as.controller.PathAddress)8 ContextNames (org.jboss.as.naming.deployment.ContextNames)8 HttpHandler (io.undertow.server.HttpHandler)7 PathHandler (io.undertow.server.handlers.PathHandler)7 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)7 FilterService (org.wildfly.extension.undertow.filters.FilterService)7 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)6 ArrayList (java.util.ArrayList)5 Resource (org.jboss.as.controller.registry.Resource)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)5 AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)5 List (java.util.List)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4