@Override public synchronized DriverDeploymentInfo getDriverDeploymentInfo(String uuid) throws Exception { try { DriverDeploymentInfo deploymentInfo = driverProvider.getDeploymentInfo(uuid); if (deploymentInfo != null && driverDeploymentCache.get(deploymentInfo) != null) { DriverDeploymentInfo updatedInfo = new DriverDeploymentInfo(deploymentInfo.getDeploymentId(), deploymentInfo.getDriverDeploymentId(), deploymentInfo.isManaged(), deploymentInfo.getUuid(), deploymentInfo.getDriverClass()); updatedInfo.getDependants().addAll(driverDeploymentCache.get(deploymentInfo).getDependants()); deploymentInfo = updatedInfo; } return deploymentInfo; } catch (Exception e) { logger.error("It was not possible to read the deploymentInfo for driver: " + uuid); throw e; } }
@Override public DriverDeploymentInfo resync(DriverDef driverDef, DriverDeploymentInfo deploymentInfo) throws Exception { String deploymentId = DeploymentIdGenerator.generateDeploymentId(driverDef); DriverDeploymentInfo currentDeploymentInfo = findDeploymentInfo(deploymentId, driverDef); DriverDeploymentInfo result = new DriverDeploymentInfo(deploymentId, currentDeploymentInfo.getDriverDeploymentId(), true, driverDef.getUuid(), driverDef.getDriverClass()); managedDrivers.put(result.getDeploymentId(), result); return result; }
/** * Deploys a driver definition on the Wildfly server. * @param driverDef A driver definition to be deployed. * @return The deployment information for the just deployed driver. * @throws Exception exceptions may be thrown if was not possible to deploy the driver. */ public DriverDeploymentInfo deploy(final DriverDef driverDef) throws Exception { 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); } String deploymentId = DeploymentIdGenerator.generateDeploymentId(driverDef); driverMgmtClient.deploy(deploymentId, uri); DriverDeploymentInfo generatedDeploymentInfo = findDeploymentInfo(deploymentId, driverDef); DriverDeploymentInfo deploymentInfo = new DriverDeploymentInfo(deploymentId, generatedDeploymentInfo.getDeploymentId(), true, driverDef.getUuid(), driverDef.getDriverClass()); managedDrivers.put(deploymentInfo.getDeploymentId(), deploymentInfo); return deploymentInfo; }
/** * Gets the deployment information about a driver definition. * @param uuid the driver definition identifier. * @return the deployment information for the driver definition of null if the driver wasn't deployed. * @throws Exception exceptions may be thrown if e.g. communication with the Wildfly server fails, etc. */ @Override public DriverDeploymentInfo getDeploymentInfo(final String uuid) throws Exception { String deploymentId = DeploymentIdGenerator.generateDeploymentId(uuid); DriverDeploymentInfo result; if ((result = managedDrivers.get(deploymentId)) == null) { for (DriverDeploymentInfo deploymentInfo : getDeploymentsInfo()) { if (uuid.equals(deploymentInfo.getUuid())) { result = deploymentInfo; break; } } } return result; }
/** * Gets the deployment information for all the drivers currently deployed on the Wildfly server. * @return a list with the deployment information for all the drivers. * @throws Exception exceptions may be thrown if e.g. communication with the Wildfly server fails, etc. */ public List< DriverDeploymentInfo > getDeploymentsInfo() throws Exception { List< DriverDeploymentInfo > deploymentsInfo = new ArrayList<>(); DriverDeploymentInfo deploymentInfo; String uuid; boolean managed; for (WildflyDriverDef internalDef : driverMgmtClient.getDeployedDrivers()) { try { uuid = DeploymentIdGenerator.extractUuid(internalDef.getDriverName()); } catch (Exception e) { uuid = internalDef.getDriverName(); } managed = managedDrivers.containsKey(internalDef.getDriverName()); deploymentInfo = new DriverDeploymentInfo(internalDef.getDriverName(), internalDef.getDriverName(), managed, uuid, internalDef.getDriverClass()); deploymentsInfo.add(deploymentInfo); } return deploymentsInfo; }
@Override public void undeploy(final DriverDeploymentInfo deploymentInfo) throws Exception { driverMgmtClient.undeploy(deploymentInfo.getDeploymentId()); managedDrivers.remove(deploymentInfo.getDeploymentId()); }
/** * 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); }
@Test public void testDeployDriver( ) throws Exception { // the driver is deployed deployDriver( driverDef1 ); // then the deployment info should be returned. DriverDeploymentInfo deploymentInfo = driverProvider.getDeploymentInfo( driverDef1.getUuid( ) ); assertNotNull( deploymentInfo ); assertTrue( deploymentInfo.isManaged( ) ); }
@Override public void callback( DriverDeploymentInfo deploymentInfo ) { if ( deploymentInfo != null && deploymentInfo.hasDependants( ) ) { popupsUtil.showYesNoPopup( CommonConstants.INSTANCE.Warning( ), editorHelper.getMessage( onDependantsMessageKey ), yesCommand, CommonConstants.INSTANCE.YES( ), ButtonType.WARNING, noCommand, CommonConstants.INSTANCE.NO( ), ButtonType.DEFAULT ); } else { defaultCommand.execute( ); } } } ).getDriverDeploymentInfo( getContent( ).getDef( ).getUuid( ) );
@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(); }
private DriverDeploymentInfo findDeploymentInfo(String deploymentId, DriverDef driverDef) throws Exception { for (DriverDeploymentInfo deploymentInfo : getDeploymentsInfo()) { if (deploymentInfo.getDeploymentId().equals(deploymentId) || deploymentInfo.getDeploymentId().startsWith(deploymentId + "_" + driverDef.getDriverClass())) { return deploymentInfo; } } return null; }