Skip to content

Commit

Permalink
Merge pull request wildfly#7829 from emmartins/WFLY-4904
Browse files Browse the repository at this point in the history
WFLY-4904: fixes jndi based datasource service names
  • Loading branch information
stuartwdouglas committed Jul 28, 2015
2 parents edd0bb3 + 0f54e0d commit 7b2419c
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 92 deletions.
Expand Up @@ -134,6 +134,7 @@ public void getResourceValue(final ResolutionContext context, final ServiceBuild
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final String poolName = uniqueName(context, jndiName);
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final boolean securityEnabled = phaseContext.getDeploymentUnit().hasAttachment(SecurityAttachments.SECURITY_ENABLED);
try {
Expand All @@ -156,19 +157,19 @@ public void getResourceValue(final ResolutionContext context, final ServiceBuild
jndiName, false, false, Defaults.CONNECTABLE, Defaults.TRACKING, properties,
className, null, null,
xaPool, null, null);
final XaDataSourceService xds = new XaDataSourceService(jndiName, jndiName, module.getClassLoader());
final XaDataSourceService xds = new XaDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader());
xds.getDataSourceConfigInjector().inject(dataSource);
startDataSource(xds, jndiName, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, securityEnabled);
startDataSource(xds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, securityEnabled);
} else {
final DsPoolImpl commonPool = new DsPoolImpl(minPoolSize < 0 ? Defaults.MIN_POOL_SIZE : Integer.valueOf(minPoolSize),
initialPoolSize < 0 ? Defaults.INITIAL_POOL_SIZE : Integer.valueOf(initialPoolSize),
maxPoolSize < 1 ? Defaults.MAX_POOL_SIZE : Integer.valueOf(maxPoolSize),
Defaults.PREFILL, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY, Boolean.FALSE, null, null);
final ModifiableDataSource dataSource = new ModifiableDataSource(url, null, className, null, transactionIsolation(), properties,
null, dsSecurity, null, null, null, null, null, false, poolName, true, jndiName, Defaults.SPY, Defaults.USE_CCM, transactional, Defaults.CONNECTABLE, Defaults.TRACKING, commonPool, null);
final LocalDataSourceService ds = new LocalDataSourceService(jndiName, jndiName, module.getClassLoader());
final LocalDataSourceService ds = new LocalDataSourceService(bindInfo.getBinderServiceName().getCanonicalName(), bindInfo, module.getClassLoader());
ds.getDataSourceConfigInjector().inject(dataSource);
startDataSource(ds, jndiName, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, securityEnabled);
startDataSource(ds, bindInfo, eeModuleDescription, context, phaseContext.getServiceTarget(), serviceBuilder, injector, securityEnabled);
}

} catch (Exception e) {
Expand Down Expand Up @@ -211,14 +212,13 @@ private String uniqueName(ResolutionContext context, final String jndiName) {
}

private void startDataSource(final AbstractDataSourceService dataSourceService,
final String jndiName,
final ContextNames.BindInfo bindInfo,
final EEModuleDescription moduleDescription,
final ResolutionContext context,
final ServiceTarget serviceTarget,
final ServiceBuilder valueSourceServiceBuilder, final Injector<ManagedReferenceFactory> injector, boolean securityEnabled) {


final ServiceName dataSourceServiceName = AbstractDataSourceService.SERVICE_NAME_BASE.append("DataSourceDefinition", moduleDescription.getApplicationName(), moduleDescription.getModuleName(), jndiName);
final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
final ServiceBuilder<?> dataSourceServiceBuilder =
Services.addServerExecutorDependency(
serviceTarget.addService(dataSourceServiceName, dataSourceService),
Expand All @@ -239,7 +239,6 @@ private void startDataSource(final AbstractDataSourceService dataSourceService,
dataSourceService.getSubjectFactoryInjector());
}

final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), jndiName);

final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE
Expand Down
Expand Up @@ -137,7 +137,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
if (ds.isEnabled() && ds.getDriver() != null) {
try {
final String jndiName = Util.cleanJndiName(ds.getJndiName(), ds.isUseJavaContext());
LocalDataSourceService lds = new LocalDataSourceService(jndiName, jndiName);
LocalDataSourceService lds = new LocalDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName));
lds.getDataSourceConfigInjector().inject(buildDataSource(ds));
final String dsName = ds.getJndiName();
final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, false);
Expand All @@ -159,7 +159,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
if (xads.isEnabled() && xads.getDriver() != null) {
try {
String jndiName = Util.cleanJndiName(xads.getJndiName(), xads.isUseJavaContext());
XaDataSourceService xds = new XaDataSourceService(jndiName, jndiName);
XaDataSourceService xds = new XaDataSourceService(jndiName, ContextNames.bindInfoFor(jndiName));
xds.getDataSourceConfigInjector().inject(buildXaDataSource(xads));
final String dsName = xads.getJndiName();
final PathAddress addr = getDataSourceAddress(dsName, deploymentUnit, true);
Expand Down Expand Up @@ -282,8 +282,9 @@ private void startDataSource(final AbstractDataSourceService dataSourceService,
final Resource resource,
final String managementName, boolean securityEnabled) {

final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

final ServiceName dataSourceServiceName = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName);
final ServiceName dataSourceServiceName = AbstractDataSourceService.getServiceName(bindInfo);
final ServiceBuilder<?> dataSourceServiceBuilder =
Services.addServerExecutorDependency(
serviceTarget.addService(dataSourceServiceName, dataSourceService),
Expand Down Expand Up @@ -314,7 +315,7 @@ private void startDataSource(final AbstractDataSourceService dataSourceService,
DataSourceStatisticsService statsService = new DataSourceStatisticsService(registration, false );
serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService)
.addDependency(dataSourceServiceName)
.addDependency(CommonDeploymentService.SERVICE_NAME_BASE.append(jndiName), CommonDeployment.class, statsService.getCommonDeploymentInjector())
.addDependency(CommonDeploymentService.getServiceName(bindInfo), CommonDeployment.class, statsService.getCommonDeploymentInjector())
.setInitialMode(ServiceController.Mode.PASSIVE)
.install();
DataSourceStatisticsService.registerStatisticsResources(resource);
Expand All @@ -333,7 +334,6 @@ private void startDataSource(final AbstractDataSourceService dataSourceService,
referenceFactoryService).addDependency(dataSourceServiceName, javax.sql.DataSource.class,
referenceFactoryService.getDataSourceInjector());

final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
final BinderService binderService = new BinderService(bindInfo.getBindName());
final ServiceBuilder<?> binderBuilder = serviceTarget
.addService(bindInfo.getBinderServiceName(), binderService)
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.service.NamingService;
import org.jboss.as.security.service.SubjectFactoryService;
import org.jboss.as.server.Services;
Expand Down Expand Up @@ -88,6 +89,7 @@ protected void performRuntime(final OperationContext context, final ModelNode op
final ModelNode address = operation.require(OP_ADDR);
final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
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
// expression in the model can be resolved to a correct value.
Expand All @@ -114,7 +116,7 @@ protected void performRuntime(final OperationContext context, final ModelNode op
AbstractDataSourceService dataSourceService = createDataSourceService(dsName, jndiName);

final ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName);
final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.getServiceName(bindInfo);
final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class);
final ServiceBuilder<?> dataSourceServiceBuilder =
Services.addServerExecutorDependency(
Expand Down
Expand Up @@ -62,7 +62,8 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod
final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString();

final ServiceName binderServiceName = ContextNames.bindInfoFor(jndiName).getBinderServiceName();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
final ServiceName binderServiceName = bindInfo.getBinderServiceName();
final ServiceController<?> binderController = registry.getService(binderServiceName);
if (binderController != null) {
context.removeService(binderServiceName);
Expand Down Expand Up @@ -107,7 +108,7 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod
if (dataSourceController != null) {
context.removeService(dataSourceServiceName);
}
context.removeService(CommonDeploymentService.SERVICE_NAME_BASE.append(jndiName));
context.removeService(CommonDeploymentService.getServiceName(bindInfo));
context.removeService(dataSourceServiceName.append(Constants.STATISTICS));


Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.jboss.as.connector.services.driver.InstalledDriver;
import org.jboss.as.connector.services.driver.registry.DriverRegistry;
import org.jboss.as.connector.util.Injection;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory;
import org.jboss.jca.adapters.jdbc.JDBCResourceAdapter;
import org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory;
Expand Down Expand Up @@ -104,6 +105,11 @@ public abstract class AbstractDataSourceService implements Service<DataSource> {
* the dynamic name is the resource name in the model.
*/
public static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("data-source");

public static ServiceName getServiceName(ContextNames.BindInfo bindInfo) {
return SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName().getCanonicalName());
}

private static final DeployersLogger DEPLOYERS_LOGGER = Logger.getMessageLogger(DeployersLogger.class, AS7DataSourceDeployer.class.getName());
protected final InjectedValue<TransactionIntegration> transactionIntegrationValue = new InjectedValue<TransactionIntegration>();
private final InjectedValue<Driver> driverValue = new InjectedValue<Driver>();
Expand All @@ -117,7 +123,7 @@ public abstract class AbstractDataSourceService implements Service<DataSource> {


private final String dsName;
private final String jndiName;
private final ContextNames.BindInfo jndiName;

protected CommonDeployment deploymentMD;
private WildFlyDataSource sqlDataSource;
Expand All @@ -127,7 +133,7 @@ public abstract class AbstractDataSourceService implements Service<DataSource> {
*/
private final ClassLoader classLoader;

protected AbstractDataSourceService(final String dsName, final String jndiName, final ClassLoader classLoader ) {
protected AbstractDataSourceService(final String dsName, final ContextNames.BindInfo jndiName, final ClassLoader classLoader ) {
this.dsName = dsName;
this.classLoader = classLoader;
this.jndiName = jndiName;
Expand All @@ -141,13 +147,14 @@ public synchronized void start(StartContext startContext) throws StartException
if (deploymentMD.getCfs().length != 1) {
throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
}
sqlDataSource = new WildFlyDataSource((javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName);
sqlDataSource = new WildFlyDataSource((javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName());
DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD);
startContext.getController().getServiceContainer().addService(CommonDeploymentService.SERVICE_NAME_BASE.append(jndiName),cdService)
final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName);
startContext.getController().getServiceContainer().addService(cdServiceName, cdService)
// The dependency added must be the JNDI name which for subsystem resources is an alias. This service
// is also used in deployments where the capability service name is not registered for the service.
.addDependency(SERVICE_NAME_BASE.append(jndiName))
.addDependency(getServiceName(jndiName))
.setInitialMode(ServiceController.Mode.ACTIVE).install();
} catch (Throwable t) {
throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
Expand All @@ -157,8 +164,9 @@ public synchronized void start(StartContext startContext) throws StartException
protected abstract AS7DataSourceDeployer getDeployer() throws ValidateException ;

public void stop(final StopContext stopContext) {
if (stopContext.getController().getServiceContainer().getService(CommonDeploymentService.SERVICE_NAME_BASE.append(jndiName)) != null) {
stopContext.getController().getServiceContainer().getService(CommonDeploymentService.SERVICE_NAME_BASE.append(jndiName)).setMode(ServiceController.Mode.REMOVE);
final ServiceController<?> serviceController = stopContext.getController().getServiceContainer().getService(CommonDeploymentService.getServiceName(jndiName));
if (serviceController != null) {
serviceController.setMode(ServiceController.Mode.REMOVE);
}
ExecutorService executorService = executor.getValue();
Runnable r = new Runnable() {
Expand Down
Expand Up @@ -24,6 +24,7 @@

import static org.jboss.as.connector.logging.ConnectorLogger.ROOT_LOGGER;

import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.jca.deployers.common.CommonDeployment;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
Expand All @@ -33,7 +34,11 @@

public class CommonDeploymentService implements Service<CommonDeployment> {

public static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("data-source").append("common-deployment");
private static final ServiceName SERVICE_NAME_BASE = ServiceName.JBOSS.append("data-source").append("common-deployment");

public static ServiceName getServiceName(ContextNames.BindInfo bindInfo) {
return SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName().getCanonicalName());
}

private CommonDeployment value;

Expand Down
Expand Up @@ -26,6 +26,7 @@
import static org.jboss.as.connector.subsystems.datasources.Constants.DATASOURCE_PROPERTIES_ATTRIBUTES;

import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
Expand All @@ -44,7 +45,7 @@ private DataSourceAdd() {
}

protected AbstractDataSourceService createDataSourceService(final String dsName,final String jndiName) throws OperationFailedException {
return new LocalDataSourceService(dsName, jndiName);
return new LocalDataSourceService(dsName, ContextNames.bindInfoFor(jndiName));
}

@Override
Expand Down

0 comments on commit 7b2419c

Please sign in to comment.