public static String generateJNDIName( final DataSourceDef dataSourceDef ) { return "java:jboss/kie/datasources/" + dataSourceDef.getUuid(); }
public static String generateDeploymentId( final DataSourceDef dataSourceDef ) { return generateDeploymentId( dataSourceDef.getUuid() ); }
private DataSourceDefInfo createDataSourceDefInfo(final org.uberfire.java.nio.file.Path path) { String content = ioService.readAllString(path); DataSourceDef dataSourceDef = DataSourceDefSerializer.deserialize(content); DataSourceDeploymentInfo deploymentInfo = null; try { deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); } catch (Exception e) { logger.warn("It was not possible to read deployment info when building DataSourceDefInfo for data source: " + dataSourceDef.getUuid(), e); } return new DataSourceDefInfo(dataSourceDef.getUuid(), dataSourceDef.getName(), Paths.convert(path), deploymentInfo); }
@Override public Collection<DataSourceDefInfo> findGlobalDataSources(boolean includeUnManaged) { Collection<DataSourceDefInfo> result = resolveDataSources(serviceHelper.getGlobalDataSourcesContext()); if (includeUnManaged) { Map<String, DataSourceDefInfo> managedDataSources = new HashMap<>(); for (DataSourceDefInfo dataSourceDefInfo : result) { managedDataSources.put(dataSourceDefInfo.getUuid(), dataSourceDefInfo); } try { List<DataSourceDef> allDeployments = providerFactory.getDataSourceProvider().getDeployments(); DeploymentInfo deploymentInfo; for (DataSourceDef dataSourceDef : allDeployments) { deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); if (!managedDataSources.containsKey(dataSourceDef.getUuid()) && (deploymentInfo != null && !deploymentInfo.isManaged())) { result.add(new DataSourceDefInfo(dataSourceDef.getUuid(), dataSourceDef.getName(), runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()))); } } } catch (Exception e) { logger.warn("It was not possible to read all deployed data sources. ", e); } } return result; }
private void deployDataSource(DataSourceDef dataSourceDef) throws Exception { when(dataSourceProvider.deploy(dataSourceDef)).thenReturn(dataSourceDeploymentInfo); runtimeManager.deployDataSource(dataSourceDef, DeploymentOptions.create()); when(dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid())).thenReturn(dataSourceDeploymentInfo); when(dataSourceProvider.lookupDataSource(dataSourceDeploymentInfo)).thenReturn(dataSource); }
/** * Checks current data source status prior to execute an update operation. */ protected void executeSafeUpdateCommand(String onDependantsMessageKey, Command defaultCommand, Command yesCommand, Command noCommand) { dataSourceManagerClient.call(new RemoteCallback<DataSourceDeploymentInfo>() { @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()); }
private void testLookupDataSource(boolean isDeployed) { try { if (isDeployed) { // emulates that the required driver is properly deployed. when(driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid())).thenReturn(driverDeploymentInfo); // deploy the data source. deployDataSource(dataSourceDef); // the data source should exist. DataSource dataSource = runtimeManager.lookupDataSource(dataSourceDef.getUuid()); assertNotNull(dataSource); } else { expectedException.expectMessage("Data source: " + dataSourceDef.getUuid() + " is not deployed in current system."); runtimeManager.lookupDataSource(dataSourceDef.getUuid()); } } catch (Exception e) { fail(e.getMessage()); } }
@Override public synchronized DataSourceDeploymentInfo deployDataSource(DataSourceDef dataSourceDef, DeploymentOptions options) throws Exception { try { DataSourceDeploymentInfo dataSourceDeploymentInfo = dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid()); DriverDeploymentInfo driverDeploymentInfo = driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid()); if (dataSourceDeploymentInfo != null) { if (options.isCreateOrResyncDeployment()) { dataSourceDeploymentInfo = dataSourceProvider.resync(dataSourceDef, dataSourceDeploymentInfo); } else { throw new Exception("Data source: " + dataSourceDef + " is already deployed"); } } else if (driverDeploymentInfo != null) { dataSourceDeploymentInfo = dataSourceProvider.deploy(dataSourceDef); } else { throw new Exception("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed."); } if (driverDeploymentInfo != null && driverDeploymentCache.get(driverDeploymentInfo) != null) { driverDeploymentCache.get(driverDeploymentInfo).addDependant(dataSourceDeploymentInfo); } return dataSourceDeploymentInfo; } catch (Exception e) { logger.error("Data source deployment failed for dataSourceDef: " + dataSourceDef, e); throw e; } }
/** * 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); }
result.setMessage("Data source driver: " + dataSourceDef.getUuid() + " was not found"); return result;
/** * Tests the un-deployment of a data source. */ @Test public void testUnDeployDataSource() { try { // emulates that the required driver is properly deployed. when(driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid())).thenReturn(driverDeploymentInfo); // simulate we have an already deployed data source deployDataSource(dataSourceDef); DataSourceDeploymentInfo deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); assertNotNull(deploymentInfo); runtimeManager.unDeployDataSource(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); when(dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid())).thenReturn(null); // the data source should have been un-deployed with the provider. verify(dataSourceProvider, times(1)).undeploy(dataSourceDeploymentInfo); deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); // no deployment info should exist assertNull(deploymentInfo); } catch (Exception e) { fail(e.getMessage()); } }
@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"); }
@Test public void testOnBrowseDatabase() { //open the editor with a valid content prepareLoadFileSuccessful(); //emulates the selection of the show content action from the UI editor.onShowContent(); DatabaseStructureExplorer.Settings expectedSettings = new DatabaseStructureExplorer.Settings(); expectedSettings.dataSourceUuid(content.getDef().getUuid()); expectedSettings.dataSourceName(content.getDef().getName()); //dbStructureExplorer should have been initialized with the proper datasource parameters. verify(dbStructureExplorer, times(1)).initialize(eq(expectedSettings), any(InitializeCallback.class)); }
@Override public void onShowContent() { DatabaseStructureExplorer.Settings settings = new DatabaseStructureExplorer.Settings() .dataSourceUuid(getContent().getDef().getUuid()) .dataSourceName(getContent().getDef().getName()); dbStructureExplorer.initialize(settings, new InitializeCallback() { @Override public void onInitializeError(Throwable throwable) { // do nothing, just stay showing the parameters edition. } @Override public void onInitializeSuccess() { showContent(); } }); }
/** * Tests the successful deployment of a data source. */ @Test public void testDeployDataSource( ) throws Exception { setupDrivers( ); // deploy the data source deployDataSource( dataSourceDef ); DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo( dataSourceDef.getUuid( ) ); // the data source should have been properly deployed. assertNotNull( deploymentInfo ); }
when(dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid())).thenReturn(dataSourceDeploymentInfo);
/** * Tests a data source deployment attempt in the case when the required driver is not deployed. */ @Test public void testDeployDataSourceWithMissingDriver( ) throws Exception { // an exception should have been thrown. expectedException.expectMessage( "Required driver: " + dataSourceDef.getDriverUuid( ) + " is not deployed" ); dataSourceProvider.deploy( dataSourceDef ); DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo( dataSourceDef.getUuid( ) ); assertNull( deploymentInfo ); }
@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 ); }
/** * 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 ); }
DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo( dataSourceDef.getUuid( ) );