Search in sources :

Example 31 with ServiceController

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

the class AbstractUpdateJndiHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    JNDI_BINDING.validateOperation(operation);
    final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
    final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
    if (addOperation) {
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
            }
        }
        entries.add(jndiName);
    } else {
        ModelNode updatedEntries = new ModelNode();
        boolean updated = false;
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                if (entries.asList().size() == 1) {
                    throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
                }
                updated = true;
            } else {
                updatedEntries.add(entry);
            }
        }
        if (!updated) {
            throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
        }
        context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
    }
    if (context.isNormalServer()) {
        if (rollbackOperationIfServerNotActive(context, operation)) {
            return;
        }
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
                final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
                final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
                final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
                if (jmsServerService != null) {
                    JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                    if (jmsServerManager == null) {
                        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
                        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
                    }
                    try {
                        if (addOperation) {
                            addJndiName(jmsServerManager, resourceName, jndiName);
                        } else {
                            removeJndiName(jmsServerManager, resourceName, jndiName);
                        }
                    } catch (Exception e) {
                        context.getFailureDescription().set(e.getLocalizedMessage());
                    }
                }
                if (!context.hasFailureDescription()) {
                    context.getResult();
                }
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                        if (jmsServerService != null) {
                            JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                            try {
                                if (addOperation) {
                                    removeJndiName(jmsServerManager, resourceName, jndiName);
                                } else {
                                    addJndiName(jmsServerManager, resourceName, jndiName);
                                }
                            } catch (Exception e) {
                                context.getFailureDescription().set(e.getLocalizedMessage());
                            }
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 32 with ServiceController

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

the class StackOperationExecutor method execute.

@Override
public ModelNode execute(OperationContext context, Operation<ChannelFactory> operation) throws OperationFailedException {
    String stackName = context.getCurrentAddressValue();
    ServiceRegistry registry = context.getServiceRegistry(false);
    ServiceName serviceName = JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stackName);
    try {
        ServiceController<ChannelFactory> controller = ServiceContainerHelper.getService(registry, serviceName);
        ServiceController.Mode mode = controller.getMode();
        controller.setMode(ServiceController.Mode.ACTIVE);
        try {
            return operation.execute(controller.awaitValue());
        } finally {
            controller.setMode(mode);
        }
    } catch (InterruptedException e) {
        throw new OperationFailedException(e.getLocalizedMessage(), e);
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 33 with ServiceController

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

the class JMSDestinationDefinitionInjectionSource method inject.

private <D extends Destination> void inject(ServiceBuilder<?> serviceBuilder, Injector<ManagedReferenceFactory> injector, Service<D> destinationService) {
    final ContextListAndJndiViewManagedReferenceFactory referenceFactoryService = new MessagingJMSDestinationManagedReferenceFactory(destinationService);
    serviceBuilder.addInjection(injector, referenceFactoryService).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        ROOT_LOGGER.boundJndiName(jndiName);
                        break;
                    }
                case START_REQUESTED_to_DOWN:
                    {
                        ROOT_LOGGER.unboundJndiName(jndiName);
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        ROOT_LOGGER.debugf("Removed messaging object [%s]", jndiName);
                        break;
                    }
            }
        }
    });
}
Also used : ServiceController(org.jboss.msc.service.ServiceController) ContextListAndJndiViewManagedReferenceFactory(org.jboss.as.naming.ContextListAndJndiViewManagedReferenceFactory)

Example 34 with ServiceController

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

the class WeldStartService method start.

@Override
public void start(final StartContext context) throws StartException {
    /*
         * Weld service restarts are not supported. Therefore, if we detect that Weld is being restarted we
         * trigger restart of the entire deployment.
         */
    if (runOnce.get()) {
        ServiceController<?> controller = context.getController().getServiceContainer().getService(deploymentServiceName);
        controller.addListener(new AbstractServiceListener<Object>() {

            @Override
            public void transition(final ServiceController<?> controller, final ServiceController.Transition transition) {
                if (transition.getAfter().equals(ServiceController.Substate.DOWN)) {
                    controller.setMode(Mode.ACTIVE);
                    controller.removeListener(this);
                }
            }
        });
        controller.setMode(Mode.NEVER);
        return;
    }
    runOnce.set(true);
    ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        for (SetupAction action : setupActions) {
            action.setup(null);
        }
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
        bootstrap.getValue().getBootstrap().startInitialization();
        bootstrap.getValue().getBootstrap().deployBeans();
        bootstrap.getValue().getBootstrap().validateBeans();
        bootstrap.getValue().getBootstrap().endInitialization();
    } finally {
        for (SetupAction action : setupActions) {
            try {
                action.teardown(null);
            } catch (Exception e) {
                WeldLogger.DEPLOYMENT_LOGGER.exceptionClearingThreadState(e);
            }
        }
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
Also used : ServiceController(org.jboss.msc.service.ServiceController) SetupAction(org.jboss.as.server.deployment.SetupAction) StartException(org.jboss.msc.service.StartException)

Example 35 with ServiceController

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

the class AdministeredObjectDefinitionInjectionSource method getResourceValue.

public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    String raId = resourceAdapter;
    if (resourceAdapter.startsWith("#")) {
        raId = deploymentUnit.getParent().getName() + raId;
    }
    String deployerServiceName = raId;
    if (!raId.endsWith(".rar")) {
        deployerServiceName = deployerServiceName + ".rar";
        raId = deployerServiceName;
    }
    SUBSYSTEM_RA_LOGGER.debugf("@AdministeredObjectDefinition: %s for %s binding to %s ", className, resourceAdapter, jndiName);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
    DirectAdminObjectActivatorService service = new DirectAdminObjectActivatorService(jndiName, className, resourceAdapter, raId, properties, module, bindInfo);
    ServiceName serviceName = DirectAdminObjectActivatorService.SERVICE_NAME_BASE.append(jndiName);
    phaseContext.getServiceTarget().addService(serviceName, service).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, service.getMdrInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(deployerServiceName)).setInitialMode(ServiceController.Mode.ACTIVE).install();
    serviceBuilder.addDependency(AdminObjectReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName()), ManagedReferenceFactory.class, injector);
    serviceBuilder.addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.adminObjectAnnotation(jndiName);
                        break;
                    }
                case STOPPING_to_DOWN:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.unboundJca("AdminObject", jndiName);
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        DEPLOYMENT_CONNECTOR_LOGGER.debugf("Removed JCA AdminObject [%s]", jndiName);
                    }
            }
        }
    });
}
Also used : DirectAdminObjectActivatorService(org.jboss.as.connector.services.resourceadapters.DirectAdminObjectActivatorService) AS7MetadataRepository(org.jboss.as.connector.services.mdr.AS7MetadataRepository) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ContextNames(org.jboss.as.naming.deployment.ContextNames)

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