Search in sources :

Example 6 with DataSourceDeploymentInfo

use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.

the class DataSourceProviderBaseTest method testLookupDataSourceForNotDeployed.

/**
 * Tests the lookup of a data source that has not been deployed.
 */
@Test
public void testLookupDataSourceForNotDeployed() throws Exception {
    setupDrivers();
    // case 1
    // emulate that the data source #1 was deployed in an earlier time.
    deployDataSource(dataSourceDef);
    // now do a lookup for data source #1
    DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid());
    // deployment info for data source #1 should exists.
    assertNotNull(deploymentInfo);
    // perform the lookup on data source #1
    DataSource dataSource = dataSourceProvider.lookupDataSource(deploymentInfo);
    // the lookup should be ok.
    assertNotNull(dataSource);
    // now un-deploy data source #1
    unDeployDataSource(deploymentInfo);
    // now a lookup for data source #1 must fail
    expectedException.expectMessage("Data source for: " + deploymentInfo + " is not deployed in current system.");
    dataSourceProvider.lookupDataSource(deploymentInfo);
    // case 2
    // invent that a valid deployment information for a non deployed (or not existing) data source.
    deploymentInfo = new DataSourceDeploymentInfo(DS3_DEPLOYMENT_ID, true, DS3_UUID, false);
    // the lookup should fail.
    expectedException.expectMessage("Data source for: " + deploymentInfo + " is not deployed in current system.");
    dataSourceProvider.lookupDataSource(deploymentInfo);
}
Also used : DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) Test(org.junit.Test)

Example 7 with DataSourceDeploymentInfo

use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.

the class DataSourceProviderBaseTest method testUnDeployDataSource.

@Test
public void testUnDeployDataSource() throws Exception {
    setupDrivers();
    // deploy the data source
    deployDataSource(dataSourceDef);
    DataSourceDeploymentInfo initialDeploymentInfo = dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid());
    // deployment info should exists
    assertNotNull(initialDeploymentInfo);
    // un-deploy the datasource
    unDeployDataSource(initialDeploymentInfo);
    // the deployment info should not exists now
    DataSourceDeploymentInfo currentDeploymentInfo = dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid());
    assertNull(currentDeploymentInfo);
    // un-deploy the non existing data source
    expectedException.expectMessage("DataSource: " + initialDeploymentInfo.getUuid() + " is not deployed");
    dataSourceProvider.undeploy(initialDeploymentInfo);
}
Also used : DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) Test(org.junit.Test)

Example 8 with DataSourceDeploymentInfo

use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.

the class DataSourceRuntimeManagerTest method setup.

@Before
public void setup() {
    when(providerFactory.getDataSourceProvider()).thenReturn(dataSourceProvider);
    when(providerFactory.getDriverProvider()).thenReturn(driverProvider);
    runtimeManager = new DataSourceRuntimeManagerMock(providerFactory);
    dataSourceDef = new DataSourceDef();
    dataSourceDef.setUuid(DS1_UUID);
    dataSourceDef.setName(DS1_NAME);
    dataSourceDef.setDriverUuid(DRIVER1_UUID);
    dataSourceDef.setConnectionURL(DS1_CONNECTION_URL);
    dataSourceDef.setUser(DS1_USER);
    dataSourceDef.setPassword(DS1_PASSWORD);
    driverDef = new DriverDef();
    driverDef.setUuid(DRIVER1_UUID);
    driverDef.setName(DRIVER1_NAME);
    driverDef.setDriverClass(DRIVER1_CLASS);
    driverDef.setArtifactId(ARTIFACT_ID);
    driverDef.setGroupId(GROUP_ID);
    driverDef.setVersion(VERSION);
    driverDeploymentInfo = new DriverDeploymentInfo();
    dataSourceDeploymentInfo = new DataSourceDeploymentInfo();
}
Also used : DriverDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DriverDeploymentInfo) DataSourceDef(org.kie.workbench.common.screens.datasource.management.model.DataSourceDef) DriverDef(org.kie.workbench.common.screens.datasource.management.model.DriverDef) DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) Before(org.junit.Before)

Example 9 with DataSourceDeploymentInfo

use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.

the class DBCPDataSourceProvider method undeploy.

@Override
public void undeploy(DataSourceDeploymentInfo deploymentInfo) throws Exception {
    DataSourceDeploymentInfo currentDeploymentInfo = deploymentInfos.get(deploymentInfo.getDeploymentId());
    if (currentDeploymentInfo == null) {
        throw new Exception("DataSource: " + deploymentInfo.getUuid() + " is not deployed");
    }
    DBCPDataSource dataSource = deploymentRegistry.remove(currentDeploymentInfo.getDeploymentId());
    if (dataSource != null) {
        try {
            dataSource.close();
        } catch (Exception e) {
            logger.warn("An error was produced during datasource close", e);
        }
    }
    deploymentRegistry.remove(currentDeploymentInfo.getDeploymentId());
    deployedDataSources.remove(currentDeploymentInfo.getDeploymentId());
    deploymentInfos.remove(currentDeploymentInfo.getDeploymentId());
}
Also used : DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) SQLException(java.sql.SQLException)

Example 10 with DataSourceDeploymentInfo

use of org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo in project kie-wb-common by kiegroup.

the class DBCPDataSourceProvider method lookupDataSource.

@Override
public DataSource lookupDataSource(DataSourceDeploymentInfo deploymentInfo) throws Exception {
    DBCPDataSource dataSource = deploymentRegistry.get(deploymentInfo.getDeploymentId());
    if (dataSource != null) {
        if (dataSource.isNew()) {
            // first access to the data source
            dataSource.setStatus(DataSourceStatus.REFERENCED);
        }
        DataSourceDeploymentInfo _deploymentInfo = deploymentInfos.get(deploymentInfo.getDeploymentId());
        if (_deploymentInfo != null) {
            DataSourceDeploymentInfo updatedDeploymentInfo = new DataSourceDeploymentInfo(deploymentInfo.getDeploymentId(), true, deploymentInfo.getUuid(), true);
            deploymentInfos.put(deploymentInfo.getDeploymentId(), updatedDeploymentInfo);
        }
        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) SQLException(java.sql.SQLException)

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