/** * Gets the deployment information about a data source definition. * @param uuid the data source definition identifier. * @return the deployment information for the data source definition of null if no data source has been created * with the given uuid. * @throws Exception exceptions may be thrown if e.g. communication with the Wildfly server fails, etc. */ public DataSourceDeploymentInfo getDeploymentInfo(final String uuid) throws Exception { for (DataSourceDeploymentInfo deploymentInfo : getDeploymentsInfo()) { if (uuid.equals(deploymentInfo.getUuid())) { return deploymentInfo; } } return null; }
@Override public void undeploy(final DataSourceDeploymentInfo deploymentInfo) throws Exception { DataSourceDeploymentInfo currentDeploymentInfo = getDeploymentInfo(deploymentInfo.getUuid()); if (currentDeploymentInfo == null) { throw new Exception("DataSource: " + deploymentInfo.getUuid() + " is not deployed"); } dataSourceMgmtClient.deleteDataSource(currentDeploymentInfo.getDeploymentId()); managedDataSources.remove(currentDeploymentInfo.getDeploymentId()); }
@Before public void setUp() throws Exception { dataSetDefCaptor = ArgumentCaptor.forClass(DataSetDef.class); when(dataSourceRuntimeManager.getDataSourceDeploymentInfo(DATASOURCE_UUID)).thenReturn(dataSourceDeploymentInfo); when(dataSourceDeploymentInfo.getUuid()).thenReturn(DATASOURCE_UUID); when(databaseMetadataService.getMetadata(DATASOURCE_UUID, false, false)).thenReturn(databaseMetadata); dataManagementService = new DataManagementServiceImpl(dataSourceRuntimeManager, databaseMetadataService, dataSetDefRegistry, dataSetManager); }
@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."); } }
@Before public void setup() { setupChangeHandler(); when(serviceHelper.getDefRegistry()).thenReturn(defRegistry); when(moduleService.resolveModule(path)).thenReturn(module); when(sessionInfo.getId()).thenReturn(SESSION_ID); when(sessionInfo.getIdentity()).thenReturn(identity); when(identity.getIdentifier()).thenReturn(IDENTIFIER); dataSourceDef = new DataSourceDef(); dataSourceDef.setUuid("uuid"); dataSourceDef.setName("dataSourceName"); dataSourceDef.setConnectionURL("connectionURL"); dataSourceDef.setUser("user"); dataSourceDef.setPassword("password"); driverDef = new DriverDef(); driverDef.setUuid("uuid"); driverDef.setName("driverName"); driverDef.setDriverClass(TestDriver.class.getName()); driverDef.setGroupId("groupId"); driverDef.setArtifactId("artifactId"); driverDef.setVersion("version"); when(registeredDataSourceDef.getUuid()).thenReturn("registeredDataSourceUuid"); when(registeredDataSourceDeploymentInfo.getUuid()).thenReturn("registeredDataSourceUuid"); when(originalDataSourceDef.getUuid()).thenReturn("originalDataSourceUuid"); when(originalDatasourceDeploymentInfo.getUuid()).thenReturn("originalDataSourceUuid"); when(registeredDriverDef.getUuid()).thenReturn("registeredDriverDefUuid"); when(registeredDriverDeploymentInfo.getUuid()).thenReturn("registeredDriverDefUuid"); when(originalDriverDef.getUuid()).thenReturn("originalDriverDefUuid"); when(originalDriverDeploymentInfo.getUuid()).thenReturn("originalDriverDefUuid"); }
.dataSetName(buildDataSetName(schema, table)) .dataSourceUuid(deploymentInfo.getUuid()) .schema(schema) .table(buildDataSetTableName(dataSourceUuid,
@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 ); }