use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.
the class DBCPDataSourceProvider method deploy.
@Override
public DataSourceDeploymentInfo deploy(DataSourceDef dataSourceDef) throws Exception {
DriverDef driverDef = null;
for (DriverDef _driverDef : driverProvider.getDeployments()) {
if (_driverDef.getUuid().equals(dataSourceDef.getDriverUuid())) {
driverDef = _driverDef;
break;
}
}
if (driverDef == null) {
throw new Exception("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed");
}
final URI uri = artifactResolver.resolve(driverDef.getGroupId(), driverDef.getArtifactId(), driverDef.getVersion());
if (uri == null) {
throw new Exception("Unable to get driver library artifact for driver: " + driverDef);
}
final Properties properties = new Properties();
properties.setProperty("user", dataSourceDef.getUser());
properties.setProperty("password", dataSourceDef.getPassword());
final URLConnectionFactory urlConnectionFactory = buildConnectionFactory(uri, driverDef.getDriverClass(), dataSourceDef.getConnectionURL(), properties);
// Connection Factory that the pool will use for creating connections.
ConnectionFactory connectionFactory = new DBCPConnectionFactory(urlConnectionFactory);
// Poolable connection factory
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
// The pool to be used by the ConnectionFactory
ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
// Set the factory's pool property to the owning pool
poolableConnectionFactory.setPool(connectionPool);
// Finally create DataSource
PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);
DataSourceDeploymentInfo deploymentInfo = new DataSourceDeploymentInfo(dataSourceDef.getUuid(), true, dataSourceDef.getUuid(), false);
deploymentRegistry.put(deploymentInfo.getDeploymentId(), new DBCPDataSource(dataSource));
deploymentInfos.put(deploymentInfo.getDeploymentId(), deploymentInfo);
deployedDataSources.put(deploymentInfo.getDeploymentId(), dataSourceDef);
return deploymentInfo;
}
use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.
the class WildflyDataSourceProvider method lookupDataSource.
@Override
public DataSource lookupDataSource(DataSourceDeploymentInfo deploymentInfo) throws Exception {
WildlfyDataSource dataSource = managedDataSources.get(deploymentInfo.getDeploymentId());
if (dataSource == null) {
dataSource = unManagedDataSources.get(deploymentInfo.getDeploymentId());
}
if (dataSource == null) {
DataSourceDeploymentInfo refreshedDeploymentInfo = getDeploymentInfo(deploymentInfo.getUuid());
if (refreshedDeploymentInfo != null && refreshedDeploymentInfo.getJndi() != null) {
javax.sql.DataSource sqlDataSource = (javax.sql.DataSource) jndiLookupDataSource(refreshedDeploymentInfo.getJndi());
if (sqlDataSource != null) {
dataSource = new WildlfyDataSource(sqlDataSource, refreshedDeploymentInfo.getJndi());
unManagedDataSources.put(deploymentInfo.getDeploymentId(), dataSource);
return dataSource;
}
}
}
if (dataSource != null) {
if (dataSource.isNew()) {
// first access to the data source
dataSource.setStatus(DataSourceStatus.REFERENCED);
}
return dataSource;
} else {
throw new Exception("Data source for: " + deploymentInfo + " is not deployed in current system.");
}
}
use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.
the class WildflyDataSourceProvider method deploy.
/**
* Creates a data source in the Wildfly server.
* @param dataSourceDef Data source definition to be created.
* @param jndi jndi name to be use the Wildly server to bound the data source in the jndi context.
* @return returns the deployment information for the created data source.
* @throws Exception exceptions may be thrown if the data source couldn't be created.
*/
private DataSourceDeploymentInfo deploy(final DataSourceDef dataSourceDef, final String jndi, String deploymentId) throws Exception {
DriverDeploymentInfo driverDeploymentInfo = driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid());
if (driverDeploymentInfo == null) {
throw new Exception("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed.");
}
WildflyDataSourceDef wfDataSourceDef = buildWFDataSource(deploymentId, jndi, dataSourceDef, driverDeploymentInfo.getDriverDeploymentId());
dataSourceMgmtClient.createDataSource(wfDataSourceDef);
return new DataSourceDeploymentInfo(deploymentId, true, dataSourceDef.getUuid(), jndi, false);
}
use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.
the class WildflyDataSourceProvider method getDeploymentsInfo.
/**
* Gets the deployment information for all the data sources currently defined on the Wildfly server.
* @return a list with the deployment information for all the data sources.
* @throws Exception exceptions may be thrown if e.g. communication with the Wildfly server fails, etc.
*/
public List<DataSourceDeploymentInfo> getDeploymentsInfo() throws Exception {
List<WildflyDataSourceDef> dataSources = dataSourceMgmtClient.getDataSources();
List<DataSourceDeploymentInfo> result = new ArrayList<>();
DataSourceDeploymentInfo deploymentInfo;
String uuid;
WildlfyDataSource managedDataSource;
boolean managed;
String jndi;
for (WildflyDataSourceDef internalDef : dataSources) {
try {
uuid = DeploymentIdGenerator.extractUuid(internalDef.getName());
} catch (Exception e) {
uuid = internalDef.getName();
}
managedDataSource = managedDataSources.get(internalDef.getName());
if (managedDataSource != null) {
managed = true;
jndi = managedDataSource.getExternalJndi();
} else {
managed = false;
jndi = internalDef.getJndi();
}
deploymentInfo = new DataSourceDeploymentInfo(internalDef.getName(), managed, uuid, jndi, wasReferenced(internalDef.getName()));
result.add(deploymentInfo);
}
return result;
}
use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.
the class WildflyDataSourceProviderTest method testDataSourceResync.
/**
* Tests the resync of a data source.
*/
@Test
public void testDataSourceResync() throws Exception {
when(managementClient.getDataSources()).thenReturn(wfDataSources);
when(dataSourceDeploymentInfo.getJndi()).thenReturn(DS1_JNID);
when(dataSourceDeploymentInfo.getDeploymentId()).thenReturn(DS1_DEPLOYMENT_ID);
DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo(DS1_UUID);
// the data source deployment info should exist, but it's not managed.
assertNotNull(deploymentInfo);
assertFalse(deploymentInfo.isManaged());
dataSourceProvider.resync(dataSourceDef, dataSourceDeploymentInfo);
deploymentInfo = dataSourceProvider.getDeploymentInfo(DS1_UUID);
// after the resync the data source should have been tagged as managed.
assertNotNull(deploymentInfo);
assertTrue(deploymentInfo.isManaged());
}
Aggregations