Search in sources :

Example 11 with DataSourceDeploymentInfo

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;
}
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 DataSourceDeploymentInfo

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

Example 13 with DataSourceDeploymentInfo

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);
}
Also used : DriverDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo) WildflyDataSourceDef(org.kie.workbench.common.screens.datasource.management.backend.integration.wildfly.WildflyDataSourceDef) DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo)

Example 14 with DataSourceDeploymentInfo

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

Example 15 with DataSourceDeploymentInfo

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());
}
Also used : DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) DataSourceProviderBaseTest(org.kie.workbench.common.screens.datasource.management.backend.core.DataSourceProviderBaseTest) Test(org.junit.Test)

Aggregations

DataSourceDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo)21 Test (org.junit.Test)7 DriverDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo)4 SQLException (java.sql.SQLException)3 DataSourceDef (org.kie.workbench.common.screens.datasource.management.model.DataSourceDef)3 Before (org.junit.Before)2 DataSource (org.kie.workbench.common.screens.datasource.management.backend.core.DataSource)2 WildflyDataSourceDef (org.kie.workbench.common.screens.datasource.management.backend.integration.wildfly.WildflyDataSourceDef)2 DataSourceDefInfo (org.kie.workbench.common.screens.datasource.management.model.DataSourceDefInfo)2 DriverDef (org.kie.workbench.common.screens.datasource.management.model.DriverDef)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)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 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)1 DataColumn (org.dashbuilder.dataset.DataColumn)1 DataSet (org.dashbuilder.dataset.DataSet)1