@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."); } }
@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()); }
public DataSourceDeploymentInfo resync(DataSourceDef dataSourceDef, DataSourceDeploymentInfo deploymentInfo) throws Exception { javax.sql.DataSource dataSource = (javax.sql.DataSource) jndiLookupDataSource(deploymentInfo.getJndi()); WildlfyDataSource wfDataSource = new WildlfyDataSource(dataSource, deploymentInfo.getJndi()); managedDataSources.put(deploymentInfo.getDeploymentId(), wfDataSource); return deploymentInfo; }
/** * 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; }
/** * 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); }
@Override public String getJndi() { if (view.getSelectedRow().getDataSourceDefInfo().getDeploymentInfo() != null) { return view.getSelectedRow().getDataSourceDefInfo().getDeploymentInfo().getJndi(); } return null; }
@Override public void callback(DataSourceDeploymentInfo deploymentInfo) { if (deploymentInfo != null && deploymentInfo.wasReferenced()) { popupsUtil.showYesNoPopup(CommonConstants.INSTANCE.Warning(), editorHelper.getMessage(onDependantsMessageKey), yesCommand, CommonConstants.INSTANCE.YES(), ButtonType.WARNING, noCommand, CommonConstants.INSTANCE.NO(), ButtonType.DEFAULT); } else { defaultCommand.execute(); } } }).getDataSourceDeploymentInfo(getContent().getDef().getUuid());
/** * Tests the lookup of a previously deployed data source. */ @Test public void testLookupDataSourceForDeployed( ) throws Exception { setupDrivers( ); // emulate that the data source was deployed in an earlier time. deployDataSource( dataSourceDef ); // query the deployment information in a later time. DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo( dataSourceDef.getUuid( ) ); // the deployment information for the previously deployed data source should be available and should be a // managed data source. assertNotNull( deploymentInfo ); assertTrue( deploymentInfo.isManaged( ) ); // finally lookup the data source. DataSource dataSource = dataSourceProvider.lookupDataSource( deploymentInfo ); // the lookup must return a value. assertNotNull( dataSource ); }
@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); }
jndi = internalDef.getJndi(); deploymentInfo = new DataSourceDeploymentInfo(internalDef.getName(), managed, uuid,
@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"); }
@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(); }
.dataSetName(buildDataSetName(schema, table)) .dataSourceUuid(deploymentInfo.getUuid()) .schema(schema) .table(buildDataSetTableName(dataSourceUuid,
deploymentInfo = new DataSourceDeploymentInfo( DS3_DEPLOYMENT_ID, true, DS3_UUID, false );
@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 ); }