org.jboss.msc.service.ServiceController Java Examples

The following examples show how to use org.jboss.msc.service.ServiceController. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JBossSubsystemXMLTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testInstallSubsystemXmlPlatformPlugins() throws Exception {
  String subsystemXml = FileUtils.readFile(SUBSYSTEM_WITH_PROCESS_ENGINES_ELEMENT_ONLY);

  KernelServices services = createKernelServicesBuilder(null)
      .setSubsystemXml(subsystemXml)
      .build();

  ServiceContainer container = services.getContainer();
  ServiceController<?> serviceController = container.getService(PLATFORM_BPM_PLATFORM_PLUGINS_SERVICE_NAME);
  assertNotNull(serviceController);
  Object platformPlugins = serviceController.getValue();
  assertNotNull(platformPlugins);
  assertTrue(platformPlugins instanceof BpmPlatformPlugins);
  List<BpmPlatformPlugin> plugins = ((BpmPlatformPlugins) platformPlugins).getPlugins();
  assertEquals(1, plugins.size());
  assertTrue(plugins.get(0) instanceof ExampleBpmPlatformPlugin);
}
 
Example #2
Source File: MBeanServerService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ServiceController<?> addService(final OperationContext context, final String resolvedDomainName, final String expressionsDomainName, final boolean legacyWithProperPropertyFormat,
                                              final boolean coreMBeanSensitivity,
                                              final ManagedAuditLogger auditLoggerInfo,
                                              final JmxAuthorizer authorizer,
                                              final Supplier<SecurityIdentity> securityIdentitySupplier,
                                              final JmxEffect jmxEffect,
                                              final ProcessType processType, final boolean isMasterHc) {
    final MBeanServerService service = new MBeanServerService(resolvedDomainName, expressionsDomainName, legacyWithProperPropertyFormat,
            coreMBeanSensitivity, auditLoggerInfo, authorizer, securityIdentitySupplier, jmxEffect, processType, isMasterHc);
    final ServiceName modelControllerName = processType.isHostController() ?
            DOMAIN_CONTROLLER_NAME : Services.JBOSS_SERVER_CONTROLLER;
    return context.getServiceTarget().addService(MBeanServerService.SERVICE_NAME, service)
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .addDependency(modelControllerName, ModelController.class, service.modelControllerValue)
        .addDependency(context.getCapabilityServiceName("org.wildfly.management.notification-handler-registry", null), NotificationHandlerRegistry.class, service.notificationRegistryValue)
        .addDependency(ManagementModelIntegration.SERVICE_NAME, ManagementModelIntegration.ManagementModelProvider.class, service.managementModelProviderValue)
        .addAliases(LEGACY_MBEAN_SERVER_NAME)
            .install();
}
 
Example #3
Source File: JobAcquisitionAdd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {

  String acquisitionName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();

  MscRuntimeContainerJobExecutor mscRuntimeContainerJobExecutor = new MscRuntimeContainerJobExecutor();

  if (model.hasDefined(SubsystemAttributeDefinitons.PROPERTIES.getName())) {
    List<Property> properties = SubsystemAttributeDefinitons.PROPERTIES.resolveModelAttribute(context, model).asPropertyList();
    for (Property property : properties) {
      PropertyHelper.applyProperty(mscRuntimeContainerJobExecutor, property.getName(), property.getValue().asString());
    }
  }

  // start new service for job executor
  ServiceController<RuntimeContainerJobExecutor> serviceController = context.getServiceTarget().addService(ServiceNames.forMscRuntimeContainerJobExecutorService(acquisitionName), mscRuntimeContainerJobExecutor)
    .addDependency(ServiceNames.forMscRuntimeContainerDelegate())
    .addDependency(ServiceNames.forMscExecutorService())
    .setInitialMode(Mode.ACTIVE)
    .install();
}
 
Example #4
Source File: CamelContextAdd.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {

    String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CONTEXT).asString();
    String propValue = CamelContextResource.VALUE.resolveModelAttribute(context, model).asString();
    subsystemState.putContextDefinition(propName, propValue.trim());

    ServiceController<?> container = context.getServiceRegistry(false).getService(CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME);
    if (container != null) {
        CamelContextRegistryService serviceRegistry = CamelContextRegistryService.class.cast(container.getService());
        CamelContextRegistry camelContextRegistry = serviceRegistry.getValue();
        if (camelContextRegistry != null) {
            if (camelContextRegistry.getCamelContext(propName) == null) {
                serviceRegistry.createCamelContext(propName, propValue);
            }
        }
    }
}
 
Example #5
Source File: ModelControllerImplUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testGoodServiceTxRollback() throws Exception {
    ModelNode result = controller.execute(getOperation("good-service", "attr1", 5), null, RollbackTransactionControl.INSTANCE, null);
    // Store response data for later assertions after we check more critical stuff

    ServiceController<?> sc = container.getService(ServiceName.JBOSS.append("good-service"));
    if (sc != null) {
        assertEquals(ServiceController.Mode.REMOVE, sc.getMode());
    }
    notificationHandler.validate(2);

    // Confirm model was unchanged
    ModelNode result2 = controller.execute(getOperation("good", "attr1", 1), null, null, null);
    assertEquals(SUCCESS, result2.get(OUTCOME).asString());
    assertEquals(1, result2.get(RESULT).asInt());

    // Assert the first response was as expected
    assertEquals(FAILED, result.get(OUTCOME).asString());   // TODO success may be valid???
    assertTrue(result.get(ROLLED_BACK).asBoolean());
    notificationHandler.validate(0);
}
 
Example #6
Source File: BufferPoolResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final ModelNode bufferSizeModel = BUFFER_SIZE.resolveModelAttribute(context, model);
    final ModelNode bufferPerSliceModel = BUFFER_PER_SLICE.resolveModelAttribute(context, model);
    final ModelNode directModel = DIRECT_BUFFERS.resolveModelAttribute(context, model);

    final int bufferSize = bufferSizeModel.isDefined() ? bufferSizeModel.asInt() : defaultBufferSize;
    final int bufferPerSlice = bufferPerSliceModel.isDefined() ? bufferPerSliceModel.asInt() : defaultBuffersPerRegion;
    final boolean direct = directModel.isDefined() ? directModel.asBoolean() : defaultDirectBuffers;

    CapabilityServiceBuilder<?> builder = context.getCapabilityServiceTarget().addCapability(IO_POOL_RUNTIME_CAPABILITY);
    final Consumer<Pool<ByteBuffer>> byteBufferConsumer = builder.provides(IO_POOL_RUNTIME_CAPABILITY);
    builder.setInstance(new BufferPoolService(byteBufferConsumer, bufferSize, bufferPerSlice, direct));
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    builder.install();

    builder = context.getCapabilityServiceTarget().addCapability(IO_BYTE_BUFFER_POOL_RUNTIME_CAPABILITY);
    final Consumer<ByteBufferPool> poolConsumer = builder.provides(IO_BYTE_BUFFER_POOL_RUNTIME_CAPABILITY);
    final Supplier<Pool> poolSupplier = builder.requiresCapability(IO_POOL_RUNTIME_CAPABILITY.getDynamicName(address), Pool.class);
    builder.setInstance(new ByteBufferPoolService(poolConsumer, poolSupplier));
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    builder.install();
}
 
Example #7
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void deployServletProcessApplication(ServletProcessApplication processApplication) {

  ClassLoader contextClassloader = ClassLoaderUtil.getContextClassloader();
  String moduleName = ((ModuleClassLoader)contextClassloader).getModule().getIdentifier().toString();

  ServiceName serviceName = ServiceNames.forNoViewProcessApplicationStartService(moduleName);
  ServiceName paModuleService = ServiceNames.forProcessApplicationModuleService(moduleName);

  if(serviceContainer.getService(serviceName) == null) {

    ServiceController<ServiceTarget> requiredService = (ServiceController<ServiceTarget>) serviceContainer.getRequiredService(paModuleService);

    NoViewProcessApplicationStartService service = new NoViewProcessApplicationStartService(processApplication.getReference());
    requiredService.getValue()
      .addService(serviceName, service)
      .setInitialMode(Mode.ACTIVE)
      .install();

  }
}
 
Example #8
Source File: CompositeOperationHandlerUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
    public void testGoodServiceNestedCompositeTxRollback() throws Exception {
        ModelNode step1 = getOperation("good", "attr1", 2);
        ModelNode step2 = getOperation("good", "attr2", 1);
        ModelNode comp1 = getCompositeOperation(null, step1, step2);
        ModelNode step3 = getOperation("good", "attr1", 20);
        ModelNode step4 = getOperation("good-service", "attr2", 10);
        ModelNode comp2 = getCompositeOperation(null, step3, step4);
        ModelNode op = getCompositeOperation(null, comp1, comp2);
//        System.out.println(op);
        ModelNode result = controller.execute(op, null, ModelControllerImplUnitTestCase.RollbackTransactionControl.INSTANCE, null);
        System.out.println(result);
        Assert.assertEquals("failed", result.get("outcome").asString());
        assertTrue(result.hasDefined(FAILURE_DESCRIPTION));

        assertTrue(sharedState.get());

        ServiceController<?> sc = container.getService(ServiceName.JBOSS.append("bad-service"));
        if (sc != null) {
            Assert.assertEquals(ServiceController.Mode.REMOVE, sc.getMode());
        }

        Assert.assertEquals(1, controller.execute(getOperation("good", "attr1", 3), null, null, null).get("result").asInt());
        Assert.assertEquals(2, controller.execute(getOperation("good", "attr2", 3), null, null, null).get("result").asInt());
    }
 
Example #9
Source File: TopologyManagerActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
    ServiceTarget target = context.getServiceTarget();

    TopologyManager.INSTANCE.setServiceTarget(target);

    target.addService(SERVICE_NAME, new ValueService<>(new ImmediateValue<>(TopologyManager.INSTANCE)))
            .install();

    BinderService binderService = new BinderService(Topology.JNDI_NAME, null, true);

    target.addService(ContextNames.buildServiceName(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, Topology.JNDI_NAME), binderService)
            .addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
            .addInjection(binderService.getManagedObjectInjector(), new ImmediateManagedReferenceFactory(TopologyManager.INSTANCE))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();

}
 
Example #10
Source File: CamelEndpointDeploymentSchedulerProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = deploymentUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }
    List<DeploymentUnit> subDeployments = deploymentUnit
            .getAttachmentList(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS);
    if (subDeployments != null && !subDeployments.isEmpty()) {
        /* do not install CamelEndpointDeploymentSchedulerService for ears */
        return;
    }

    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ServiceController<CamelEndpointDeploymentSchedulerService> serviceController = CamelEndpointDeploymentSchedulerService
            .addService(deploymentUnit.getServiceName(), deploymentUnit.getName(), serviceTarget);
    phaseContext.addDeploymentDependency(serviceController.getName(),
            CamelConstants.CAMEL_ENDPOINT_DEPLOYMENT_SCHEDULER_REGISTRY_KEY);
}
 
Example #11
Source File: ModelControllerImplUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testGoodService() throws Exception {
    ModelNode result = controller.execute(getOperation("good-service", "attr1", 5), null, null, null);
    System.out.println(result);
    assertEquals("success", result.get("outcome").asString());
    assertEquals(1, result.get("result").asInt());

    ServiceController<?> sc = container.getService(ServiceName.JBOSS.append("good-service"));
    assertNotNull(sc);
    assertEquals(ServiceController.State.UP, sc.getState());
    notificationHandler.validate(1);

    result = controller.execute(getOperation("good", "attr1", 1), null, null, null);
    assertEquals("success", result.get("outcome").asString());
    assertEquals(5, result.get("result").asInt());
    notificationHandler.validate(0);
}
 
Example #12
Source File: SubsystemAdd.java    From gmlc with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model,
                            ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
    throws OperationFailedException {

  ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

  GmlcService service = GmlcService.INSTANCE;
  service.setModel(fullModel);

  ServiceName name = GmlcService.getServiceName();
  ServiceController<GmlcService> controller = context.getServiceTarget()
      .addService(name, service)
      .addDependency(PathManagerService.SERVICE_NAME, PathManager.class, service.getPathManagerInjector())
      .addDependency(MBeanServerService.SERVICE_NAME, MBeanServer.class, service.getMbeanServer())
      .addDependency(SS7ExtensionService.getServiceName(), SS7ServiceInterface.class, service.getSS7Service())
      .addListener(verificationHandler)
      .setInitialMode(ServiceController.Mode.ACTIVE)
      .install();
  newControllers.add(controller);

}
 
Example #13
Source File: CredentialStoreResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    ServiceName credentialStoreServiceName = CREDENTIAL_STORE_UTIL.serviceName(operation);
    ServiceController<?> credentialStoreServiceController = context.getServiceRegistry(writeAccess).getRequiredService(credentialStoreServiceName);
    State serviceState;
    if ((serviceState = credentialStoreServiceController.getState()) != State.UP) {
        if (serviceMustBeUp) {
            try {
                // give it another chance to wait at most 500 mill-seconds
                credentialStoreServiceController.awaitValue(500, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | IllegalStateException | TimeoutException e) {
                throw ROOT_LOGGER.requiredServiceNotUp(credentialStoreServiceName, credentialStoreServiceController.getState());
            }
        }
        serviceState = credentialStoreServiceController.getState();
        if (serviceState != State.UP) {
            if (serviceMustBeUp) {
                throw ROOT_LOGGER.requiredServiceNotUp(credentialStoreServiceName, serviceState);
            }
            return;
        }
    }
    CredentialStoreService service = (CredentialStoreService) credentialStoreServiceController.getService();
    performRuntime(context.getResult(), context, operation, service);
}
 
Example #14
Source File: MscRuntimeContainerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void unregisterProcessEngine(ProcessEngine processEngine) {

  if(processEngine == null) {
    throw new ProcessEngineException("Cannot unregister process engine with Msc Runtime Container: process engine is 'null'");
  }

  ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());

  // remove the service asynchronously
  ServiceController<ProcessEngine> service = (ServiceController<ProcessEngine>) serviceContainer.getService(serviceName);
  if(service != null && service.getService() instanceof MscManagedProcessEngine) {
    service.setMode(Mode.REMOVE);
  }

}
 
Example #15
Source File: BoundedQueueThreadPoolWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected ServiceController<?> getService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    ServiceName serviceName = null;
    ServiceController<?> controller = null;
    if(capability != null) {
        serviceName = capability.getCapabilityServiceName(context.getCurrentAddress());
        controller = context.getServiceRegistry(true).getService(serviceName);
        if(controller != null) {
            return controller;
        }
    }
    if (serviceNameBase != null) {
        serviceName = serviceNameBase.append(name);
        controller = context.getServiceRegistry(true).getService(serviceName);
    }
    if(controller == null) {
        throw ThreadsLogger.ROOT_LOGGER.boundedQueueThreadPoolServiceNotFound(serviceName);
    }
    return controller;
}
 
Example #16
Source File: FilteringKeyStoreDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    for (AttributeDefinition current : CONFIG_ATTRIBUTES) {
        resourceRegistration.registerReadWriteAttribute(current, null, WRITE);
    }

    if (isServerOrHostController(resourceRegistration)) {
        resourceRegistration.registerReadOnlyAttribute(STATE, new ElytronRuntimeOnlyHandler() {

            @Override
            protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
                ServiceName keyStoreName = FILTERING_KEY_STORE_UTIL.serviceName(operation);
                ServiceController<?> serviceController = context.getServiceRegistry(false).getRequiredService(keyStoreName);

                populateResponse(context.getResult(), serviceController);
            }

        });
    }
}
 
Example #17
Source File: ModelControllerImplUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testBadService() throws Exception {
    ModelNode result = controller.execute(getOperation("bad-service", "attr1", 5, "good"), null, null, null);
    assertEquals(FAILED, result.get(OUTCOME).asString());
    assertTrue(result.hasDefined(FAILURE_DESCRIPTION));

    ServiceController<?> sc = container.getService(ServiceName.JBOSS.append("bad-service"));
    if (sc != null) {
        assertEquals(ServiceController.Mode.REMOVE, sc.getMode());
    }
    notificationHandler.validate(2);

    // Confirm model was unchanged
    result = controller.execute(getOperation("good", "attr1", 1), null, null, null);
    assertEquals("success", result.get("outcome").asString());
    assertEquals(1, result.get("result").asInt());
    notificationHandler.validate(0);
}
 
Example #18
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void removeService(final ServiceController<?> controller) throws UnsupportedOperationException {

    readOnly = false;

    assert isControllingThread();

    if (!isRuntimeChangeAllowed()) {
        throw ControllerLogger.ROOT_LOGGER.serviceRemovalRuntimeOperationsOnly();
    }
    authorize(false, WRITE_RUNTIME);
    ensureWriteLockForRuntime();
    if (controller != null) {
        doRemove(controller);
    }
}
 
Example #19
Source File: BindingRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    String name = context.getCurrentAddressValue();
    ServiceName svcName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    ServiceController.State state = controller == null ? null : controller.getState();
    if (!context.isResourceServiceRestartAllowed() || (state == ServiceController.State.UP)) {
        context.reloadRequired();
    } else {
        context.removeService(svcName);
    }
}
 
Example #20
Source File: NamingContextAssociationHandler.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private ServiceController<?> removeBinderService(String name) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
    ServiceController<?> controller = serviceRegistry.getService(bindInfo.getBinderServiceName());
    if (controller != null) {
        controller.setMode(Mode.REMOVE);
    }
    return controller;
}
 
Example #21
Source File: RemoteDomainConnectionService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static Future<MasterDomainControllerClient> install(final ServiceTarget serviceTarget,
                                                    final ModelController controller,
                                                    final ExtensionRegistry extensionRegistry,
                                                    final LocalHostControllerInfo localHostControllerInfo,
                                                    final ServiceName authenticationContext,
                                                    final String securityRealm,
                                                    final RemoteFileRepository remoteFileRepository,
                                                    final ContentRepository contentRepository,
                                                    final IgnoredDomainResourceRegistry ignoredDomainResourceRegistry,
                                                    final HostControllerRegistrationHandler.OperationExecutor operationExecutor,
                                                    final DomainController domainController,
                                                    final HostControllerEnvironment hostControllerEnvironment,
                                                    final ExecutorService executor,
                                                    final RunningMode currentRunningMode,
                                                    final Map<String, ProxyController> serverProxies,
                                                    final AtomicBoolean domainConfigAvailable) {
    RemoteDomainConnectionService service = new RemoteDomainConnectionService(controller, extensionRegistry, localHostControllerInfo,
            remoteFileRepository, contentRepository,
            ignoredDomainResourceRegistry, operationExecutor, domainController,
            hostControllerEnvironment, executor, currentRunningMode, serverProxies, domainConfigAvailable);
    ServiceBuilder<MasterDomainControllerClient> builder = serviceTarget.addService(MasterDomainControllerClient.SERVICE_NAME, service)
            .addDependency(ManagementRemotingServices.MANAGEMENT_ENDPOINT, Endpoint.class, service.endpointInjector)
            .addDependency(ServerInventoryService.SERVICE_NAME, ServerInventory.class, service.serverInventoryInjector)
            .addDependency(HostControllerService.HC_SCHEDULED_EXECUTOR_SERVICE_NAME, ScheduledExecutorService.class, service.scheduledExecutorInjector)
            .setInitialMode(ServiceController.Mode.ACTIVE);

    if (authenticationContext != null) {
        builder.addDependency(authenticationContext, AuthenticationContext.class, service.authenticationContextInjector);
    }
    if (securityRealm != null) {
        SecurityRealm.ServiceUtil.addDependency(builder, service.securityRealmInjector, securityRealm);
    }

    builder.install();
    return service.futureClient;
}
 
Example #22
Source File: AbstractOperationContext.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tracks a service whose mode is changing for subsequent verification of service stability.
 * @param service the service
 */
void serviceModeChanged(ServiceController<?> service) {
    // This should not be used for removals
    assert service.getMode() != ServiceController.Mode.REMOVE;

    if (!executed) {
        if (addedServices == null || !addedServices.contains(service.getName())) {
            getServiceVerificationHelper().getMonitor().addController(service);
        } // else we already handled this when it was added

    } // else this is rollback stuff we ignore
}
 
Example #23
Source File: WildflyHTTPServerEngine.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public void addServant(URL nurl, UndertowHTTPHandler handler) {
    try {
        final URI uri = nurl.toURI();
        LOG.debug("Adding CXF servant for URI {}", uri);
        final ServiceName serviceName = CamelEndpointDeploymentSchedulerService.deploymentSchedulerServiceName(handler.getHTTPDestination().getClassLoader());
        ServiceController<?> serviceControler = CurrentServiceContainer.getServiceContainer().getRequiredService(serviceName);
        CamelEndpointDeploymentSchedulerService deploymentSchedulerService = (CamelEndpointDeploymentSchedulerService) serviceControler.getValue();
        deploymentSchedulerService.schedule(uri, handler.getHTTPDestination());
        synchronized (uriServiceNameMap) {
            uriServiceNameMap.put(uri, serviceName);
        }
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: SpecifiedInterfaceAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model, String name, ParsedInterfaceCriteria criteria) {
    context.getCapabilityServiceTarget().addCapability(InterfaceResourceDefinition.INTERFACE_CAPABILITY.fromBaseCapability(name))
        .setInstance(createInterfaceService(name, criteria))
        .addAliases(NetworkInterfaceService.JBOSS_NETWORK_INTERFACE.append(name))
        .setInitialMode(ServiceController.Mode.ON_DEMAND)
        .install();
}
 
Example #25
Source File: CamelUndertowHostService.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static ServiceController<UndertowHost> addService(ServiceTarget serviceTarget, RuntimeState runtimeState) {
    CamelUndertowHostService service = new CamelUndertowHostService(runtimeState);
    ServiceBuilder<UndertowHost> builder = serviceTarget.addService(SERVICE_NAME, service);
    builder.addDependency(UndertowService.UNDERTOW, UndertowService.class, service.injectedUndertowService);
    builder.addDependency(SocketBinding.JBOSS_BINDING_NAME.append("http"), SocketBinding.class, service.injectedHttpSocketBinding);
    builder.addDependency(UndertowService.virtualHostName("default-server", "default-host"), Host.class, service.injectedDefaultHost);
    return builder.install();
}
 
Example #26
Source File: AdvancedModifiableKeyStoreDecorator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static AcmeAccount getAcmeAccount(OperationContext context, String certificateAuthorityAccountName, boolean staging) throws OperationFailedException {
    ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    RuntimeCapability<Void> runtimeCapability = CERTIFICATE_AUTHORITY_ACCOUNT_RUNTIME_CAPABILITY.fromBaseCapability(certificateAuthorityAccountName);
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName();

    ServiceController<AcmeAccount> serviceContainer = getRequiredService(serviceRegistry, serviceName, AcmeAccount.class);
    ServiceController.State serviceState = serviceContainer.getState();
    if (serviceState != ServiceController.State.UP) {
        throw ROOT_LOGGER.requiredServiceNotUp(serviceName, serviceState);
    }
    AcmeAccount acmeAccount = serviceContainer.getService().getValue();
    return resetAcmeAccount(acmeAccount, staging);
}
 
Example #27
Source File: AuthenticationFactoryDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String[] getAvailableSaslMechanisms(OperationContext context) {
    RuntimeCapability<Void> runtimeCapability = SASL_AUTHENTICATION_FACTORY_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName securityDomainSaslConfigurationName = runtimeCapability.getCapabilityServiceName(SaslAuthenticationFactory.class);

    ServiceController<SaslAuthenticationFactory> serviceContainer = getRequiredService(context.getServiceRegistry(false), securityDomainSaslConfigurationName, SaslAuthenticationFactory.class);
    if (serviceContainer.getState() != State.UP) {
        return null;
    }

    Collection<String> mechanismNames = serviceContainer.getValue().getMechanismNames();
    return  mechanismNames.toArray(new String[mechanismNames.size()]);
}
 
Example #28
Source File: LdapConnectionWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Config updateLdapConnectionService(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    String name = address.getLastElement().getValue();
    ServiceName svcName = LdapConnectionManagerService.ServiceUtil.createServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    if (controller != null) {
        // Just set the new values on the existing service
        LdapConnectionManagerService service = LdapConnectionManagerService.class.cast(controller.getValue());
        return LdapConnectionAddHandler.updateRuntime(context, model, service);
    } else {
        // Nothing to do
        return null;
    }
}
 
Example #29
Source File: TestHostCapableExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    resourceRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
    resourceRegistration.registerOperationHandler(TEST_OP, new OperationStepHandler() {
        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            ServiceController<?> sc = context.getServiceRegistry(false).getService(createServiceName(context.getCurrentAddress()));
            context.getResult().set(sc != null);
        }
    });
}
 
Example #30
Source File: OtherServicesSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test that paths got added properly
 */
@Test
public void testPath() throws Exception {
    ((OtherServicesSubsystemExtension)getMainExtension()).setAddHandler(SubsystemAddWithPathUserService.INSTANCE);

    //Parse the subsystem xml and install into the controller
    String subsystemXml =
            "<subsystem xmlns=\"" + SimpleSubsystemExtension.NAMESPACE + "\">" +
            "</subsystem>";
    KernelServices services = createKernelServicesBuilder(new PathInit())
            .setSubsystemXml(subsystemXml)
            .build();

    //Read the whole model and make sure it looks as expected
    ModelNode model = services.readWholeModel();
    Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(OtherServicesSubsystemExtension.SUBSYSTEM_NAME));

    ModelNode path = model.require(PATH);
    Assert.assertEquals(2, path.asList().size());
    Assert.assertEquals("p1", path.require("p1").require("name").asString());
    Assert.assertEquals(new File(".").getAbsolutePath(), path.require("p1").require("path").asString());
    Assert.assertFalse(path.get("p1", "relative-to").isDefined());
    Assert.assertEquals("p2", path.require("p2").require("name").asString());
    Assert.assertEquals("target", path.require("p2").require("path").asString());
    Assert.assertEquals("p1", path.require("p2").require("relative-to").asString());

    ServiceController<?> controller = services.getContainer().getService(PathUserService.NAME);
    Assert.assertNotNull(controller);
    PathUserService service = (PathUserService)controller.getValue();
    Assert.assertEquals(new File(".", "target").getAbsolutePath(), service.pathValue.getValue());
}