Search in sources :

Example 1 with ValueInjectionService

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

the class AbstractDataSourceAdd method firstRuntimeStep.

void firstRuntimeStep(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString();
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final boolean jta = JTA.resolveModelAttribute(context, operation).asBoolean();
    // The STATISTICS_ENABLED.resolveModelAttribute(context, model) call should remain as it serves to validate that any
    final String dsName = context.getCurrentAddressValue();
    // expression in the model can be resolved to a correct value.
    @SuppressWarnings("unused") final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    final CapabilityServiceSupport support = context.getCapabilityServiceSupport();
    final ServiceTarget serviceTarget = context.getServiceTarget();
    ModelNode node = DATASOURCE_DRIVER.resolveModelAttribute(context, model);
    final String driverName = node.asString();
    final ServiceName driverServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_"));
    ValueInjectionService<Driver> driverDemanderService = new ValueInjectionService<Driver>();
    final ServiceName driverDemanderServiceName = ServiceName.JBOSS.append("driver-demander").append(jndiName);
    final ServiceBuilder<?> driverDemanderBuilder = serviceTarget.addService(driverDemanderServiceName, driverDemanderService).addDependency(driverServiceName, Driver.class, driverDemanderService.getInjector());
    driverDemanderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    AbstractDataSourceService dataSourceService = createDataSourceService(dsName, jndiName);
    final ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
    final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.getServiceName(bindInfo);
    final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class);
    final ServiceBuilder<?> dataSourceServiceBuilder = Services.addServerExecutorDependency(serviceTarget.addService(dataSourceServiceName, dataSourceService), dataSourceService.getExecutorServiceInjector()).addAliases(dataSourceServiceNameAlias).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, dataSourceService.getManagementRepositoryInjector()).addDependency(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE, DriverRegistry.class, dataSourceService.getDriverRegistryInjector());
    dataSourceServiceBuilder.requires(ConnectorServices.IDLE_REMOVER_SERVICE);
    dataSourceServiceBuilder.requires(ConnectorServices.CONNECTION_VALIDATOR_SERVICE);
    dataSourceServiceBuilder.addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, dataSourceService.getMdrInjector());
    dataSourceServiceBuilder.requires(support.getCapabilityServiceName(NamingService.CAPABILITY_NAME));
    if (jta) {
        dataSourceServiceBuilder.addDependency(support.getCapabilityServiceName(ConnectorServices.TRANSACTION_INTEGRATION_CAPABILITY_NAME), TransactionIntegration.class, dataSourceService.getTransactionIntegrationInjector());
        dataSourceServiceBuilder.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector());
        dataSourceServiceBuilder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(DEFAULT_NAME));
        dataSourceServiceBuilder.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector());
    } else {
        dataSourceServiceBuilder.addDependency(ConnectorServices.NON_JTA_DS_RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, dataSourceService.getRaRepositoryInjector()).addDependency(ConnectorServices.NON_TX_CCM_SERVICE, CachedConnectionManager.class, dataSourceService.getCcmInjector());
    }
    // Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources
    if (registration.isAllowsOverride()) {
        registration.registerOverrideModel(dsName, DataSourcesSubsystemProviders.OVERRIDE_DS_DESC);
    }
    startConfigAndAddDependency(dataSourceServiceBuilder, dataSourceService, dsName, serviceTarget, operation);
    dataSourceServiceBuilder.addDependency(driverServiceName, Driver.class, dataSourceService.getDriverInjector());
    // If the authentication context is defined, add the capability
    boolean requireLegacySecurity = false;
    if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(AUTHENTICATION_CONTEXT.getName())) {
            dataSourceServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT.resolveModelAttribute(context, model).asString(), AuthenticationContext.class), AuthenticationContext.class, dataSourceService.getAuthenticationContext());
        }
    } else {
        String secDomain = SECURITY_DOMAIN.resolveModelAttribute(context, model).asStringOrNull();
        requireLegacySecurity = (secDomain != null && secDomain.length() > 0);
    }
    if (isXa()) {
        if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
            if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName())) {
                dataSourceServiceBuilder.addDependency(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, RECOVERY_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, model).asString(), AuthenticationContext.class), AuthenticationContext.class, dataSourceService.getRecoveryAuthenticationContext());
            }
        } else if (!requireLegacySecurity) {
            String secDomain = RECOVERY_SECURITY_DOMAIN.resolveModelAttribute(context, model).asStringOrNull();
            requireLegacySecurity = (secDomain != null && secDomain.length() > 0);
        }
    }
    if (requireLegacySecurity) {
        context.setRollbackOnly();
        throw SUBSYSTEM_RA_LOGGER.legacySecurityNotAvailable(dsName);
    }
    ModelNode credentialReference = Constants.CREDENTIAL_REFERENCE.resolveModelAttribute(context, model);
    if (credentialReference.isDefined()) {
        dataSourceService.getCredentialSourceSupplierInjector().inject(CredentialReference.getCredentialSourceSupplier(context, Constants.CREDENTIAL_REFERENCE, model, dataSourceServiceBuilder));
    }
    ModelNode recoveryCredentialReference = Constants.RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, model);
    if (recoveryCredentialReference.isDefined()) {
        dataSourceService.getRecoveryCredentialSourceSupplierInjector().inject(CredentialReference.getCredentialSourceSupplier(context, Constants.RECOVERY_CREDENTIAL_REFERENCE, model, dataSourceServiceBuilder));
    }
    dataSourceServiceBuilder.setInitialMode(ServiceController.Mode.NEVER);
    dataSourceServiceBuilder.install();
    driverDemanderBuilder.install();
}
Also used : AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) ValueInjectionService(org.jboss.msc.service.ValueInjectionService) ServiceTarget(org.jboss.msc.service.ServiceTarget) Driver(java.sql.Driver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) ServiceName(org.jboss.msc.service.ServiceName) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) ModelNode(org.jboss.dmr.ModelNode) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 2 with ValueInjectionService

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

the class EJB3SubsystemDefaultPoolWriteHandler method updatePoolService.

void updatePoolService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final ModelNode poolName = poolAttribute.resolveModelAttribute(context, model);
    ServiceName poolConfigServiceName = context.getCapabilityServiceName(this.poolConfigCapabilityName, PoolConfig.class);
    final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    ServiceController<?> existingDefaultPoolConfigService = serviceRegistry.getService(poolConfigServiceName);
    // if a default MDB pool is already installed, then remove it first
    if (existingDefaultPoolConfigService != null) {
        context.removeService(existingDefaultPoolConfigService);
    }
    if (poolName.isDefined()) {
        // now install default pool config service which points to an existing pool config service
        final ValueInjectionService<PoolConfig> newDefaultPoolConfigService = new ValueInjectionService<PoolConfig>();
        ServiceName poolConfigDependencyServiceName = context.getCapabilityServiceName(STRICT_MAX_POOL_CONFIG_CAPABILITY_NAME, PoolConfig.class, poolName.asString());
        ServiceController<?> newController = context.getServiceTarget().addService(poolConfigServiceName, newDefaultPoolConfigService).addDependency(poolConfigDependencyServiceName, PoolConfig.class, newDefaultPoolConfigService.getInjector()).install();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ValueInjectionService(org.jboss.msc.service.ValueInjectionService) PoolConfig(org.jboss.as.ejb3.component.pool.PoolConfig) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with ValueInjectionService

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

the class EJBRemoteInvocationPassByValueWriteHandler method updateDefaultLocalEJBReceiverService.

void updateDefaultLocalEJBReceiverService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final ModelNode passByValueModel = this.attributeDefinition.resolveModelAttribute(context, model);
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName localTransportProviderServiceName;
    if (passByValueModel.isDefined()) {
        final boolean passByValue = passByValueModel.asBoolean(true);
        if (passByValue) {
            localTransportProviderServiceName = LocalTransportProvider.BY_VALUE_SERVICE_NAME;
        } else {
            localTransportProviderServiceName = LocalTransportProvider.BY_REFERENCE_SERVICE_NAME;
        }
    } else {
        localTransportProviderServiceName = LocalTransportProvider.BY_VALUE_SERVICE_NAME;
    }
    // uninstall the existing default local Jakarta Enterprise Beans receiver service
    final ServiceController<?> existingDefaultLocalEJBReceiverServiceController = registry.getService(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME);
    if (existingDefaultLocalEJBReceiverServiceController != null) {
        context.removeService(existingDefaultLocalEJBReceiverServiceController);
    }
    final ServiceTarget serviceTarget = context.getServiceTarget();
    // now install the new default local Jakarta Enterprise Beans receiver service which points to an existing Local Jakarta Enterprise Beans receiver service
    final ValueInjectionService<LocalTransportProvider> newDefaultLocalTransportProviderService = new ValueInjectionService<LocalTransportProvider>();
    final ServiceBuilder<LocalTransportProvider> defaultLocalEJBReceiverServiceBuilder = serviceTarget.addService(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, newDefaultLocalTransportProviderService);
    defaultLocalEJBReceiverServiceBuilder.addDependency(localTransportProviderServiceName, LocalTransportProvider.class, newDefaultLocalTransportProviderService.getInjector());
    // install the service
    defaultLocalEJBReceiverServiceBuilder.install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) LocalTransportProvider(org.jboss.as.ejb3.remote.LocalTransportProvider) ValueInjectionService(org.jboss.msc.service.ValueInjectionService) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ModelNode (org.jboss.dmr.ModelNode)3 ServiceName (org.jboss.msc.service.ServiceName)3 ValueInjectionService (org.jboss.msc.service.ValueInjectionService)3 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 Driver (java.sql.Driver)1 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)1 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)1 PoolConfig (org.jboss.as.ejb3.component.pool.PoolConfig)1 LocalTransportProvider (org.jboss.as.ejb3.remote.LocalTransportProvider)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 ManagementRepository (org.jboss.jca.core.api.management.ManagementRepository)1 ResourceAdapterRepository (org.jboss.jca.core.spi.rar.ResourceAdapterRepository)1 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)1