Search in sources :

Example 11 with DriverDef

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;
}
Also used : URLConnectionFactory(org.kie.workbench.common.screens.datasource.management.util.URLConnectionFactory) PoolingDataSource(org.apache.commons.dbcp2.PoolingDataSource) Properties(java.util.Properties) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) URI(java.net.URI) DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) SQLException(java.sql.SQLException) ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) URLConnectionFactory(org.kie.workbench.common.screens.datasource.management.util.URLConnectionFactory) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 12 with DriverDef

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);
}
Also used : DriverDefInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDefInfo) DriverDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef)

Example 13 with DriverDef

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);
    }
}
Also used : DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef)

Example 14 with DriverDef

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;
}
Also used : ArrayList(java.util.ArrayList) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef)

Example 15 with DriverDef

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);
}
Also used : DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef) URI(java.net.URI)

Aggregations

DriverDef (org.kie.workbench.common.screens.datasource.management.model.DriverDef)18 Before (org.junit.Before)6 URI (java.net.URI)4 Properties (java.util.Properties)3 DriverDefEditorContent (org.kie.workbench.common.screens.datasource.management.model.DriverDefEditorContent)3 URLConnectionFactory (org.kie.workbench.common.screens.datasource.management.util.URLConnectionFactory)3 ArrayList (java.util.ArrayList)2 ClientValidationServiceMock (org.kie.workbench.common.screens.datasource.management.client.util.ClientValidationServiceMock)2 DataSourceDef (org.kie.workbench.common.screens.datasource.management.model.DataSourceDef)2 DataSourceDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo)2 DriverDefInfo (org.kie.workbench.common.screens.datasource.management.model.DriverDefInfo)2 DriverDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo)2 URL (java.net.URL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)1 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)1 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)1 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)1