use of org.kie.workbench.common.screens.datasource.management.model.DriverDef 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.DriverDef in project kie-wb-common by kiegroup.
the class DataSourceDefQueryServiceImpl method createDriverInfo.
private DriverDefInfo createDriverInfo(final org.uberfire.java.nio.file.Path path) {
String content = ioService.readAllString(path);
DriverDef driverDef = DriverDefSerializer.deserialize(content);
DriverDeploymentInfo deploymentInfo = null;
try {
deploymentInfo = runtimeManager.getDriverDeploymentInfo(driverDef.getUuid());
} catch (Exception e) {
logger.warn("It was not possible to read deployment info when building DriverDefInfo for driver: " + driverDef.getUuid(), e);
}
return new DriverDefInfo(driverDef.getUuid(), driverDef.getName(), Paths.convert(path), deploymentInfo);
}
use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.
the class DriverDefDeployerImpl method deployDef.
@Override
protected void deployDef(DriverDefInfo defInfo) {
try {
logger.debug("Deploying driver def: " + defInfo);
String source = ioService.readAllString(Paths.convert(defInfo.getPath()));
DriverDef driverDef = DriverDefSerializer.deserialize(source);
runtimeManager.deployDriver(driverDef, DeploymentOptions.createOrResync());
defRegistry.setEntry(defInfo.getPath(), driverDef);
logger.debug("Driver was successfully deployed");
} catch (Exception e) {
logger.error("Driver deployment failed, defInfo: " + defInfo, e);
}
}
use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.
the class DefaultDriverInitializerTest method createDrivers.
private List<DriverDef> createDrivers(String prefix, int count) {
List<DriverDef> driverDefs = new ArrayList<>();
DriverDef driverDef;
for (int i = 0; i < count; i++) {
driverDef = new DriverDef();
driverDef.setUuid(prefix + "uuid" + i);
driverDef.setName(prefix + "name" + i);
driverDef.setDriverClass(prefix + "driverClass" + i);
driverDef.setGroupId(prefix + "groupId" + i);
driverDef.setArtifactId(prefix + "artifactId" + i);
driverDef.setVersion(prefix + "version" + i);
driverDefs.add(driverDef);
}
return driverDefs;
}
use of org.kie.workbench.common.screens.datasource.management.model.DriverDef in project kie-wb-common by kiegroup.
the class DriverProviderBaseTest method setup.
public void setup() throws Exception {
driverDef1 = new DriverDef();
driverDef1.setUuid(DRIVER1_UUID);
driverDef1.setName(DRIVER1_NAME);
driverDef1.setDriverClass(DRIVER1_CLASS);
driverDef1.setArtifactId(ARTIFACT_ID);
driverDef1.setGroupId(GROUP_ID);
driverDef1.setVersion(VERSION);
driver1Uri = new URI("file:///maven_dir/driver1_file.jar");
when(artifactResolver.resolve(driverDef1.getGroupId(), driverDef1.getArtifactId(), driverDef1.getVersion())).thenReturn(driver1Uri);
}
Aggregations