Skip to content

Commit

Permalink
icewind: re-use existing JNDI DataSource(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Aug 23, 2023
1 parent 7aa5805 commit 7429f78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion icewind/VERSION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## deployable containers have a semantic and build tag
# semantic version tag: major.minor[.patch]
# build version tag: timestamp
VER=0.9.4
VER=0.9.5
TAGS="${VER} ${VER}-$(date --utc +"%Y%m%dT%H%M%S")"
unset VER
20 changes: 16 additions & 4 deletions icewind/src/main/java/org/opencadc/icewind/DeletionHarvester.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import java.util.ListIterator;
import java.util.Map;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.log4j.Logger;

/**
Expand Down Expand Up @@ -139,12 +140,23 @@ private void init() {
this.repoClient = new RepoClient(src.getResourceID(), 1);

// destination
final String destDS = "jdbc/DeletionHarvester";

Map<String, Object> destConfig = getConfigDAO(dest);
ConnectionConfig destConnectionConfig = new ConnectionConfig(null, null,
dest.getUsername(), dest.getPassword(), HarvesterResource.POSTGRESQL_DRIVER, dest.getJdbcUrl());
final String destDS = "jdbc/destObsHarvest";
try {
DBUtil.createJNDIDataSource(destDS, destConnectionConfig);
DataSource cur = null;
try {
cur = DBUtil.findJNDIDataSource(destDS);
} catch (NamingException notInitialized) {
log.debug("JNDI not initialized yet... OK");
}
if (cur == null) {
ConnectionConfig destConnectionConfig = new ConnectionConfig(null, null,
dest.getUsername(), dest.getPassword(), HarvesterResource.POSTGRESQL_DRIVER, dest.getJdbcUrl());
DBUtil.createJNDIDataSource(destDS, destConnectionConfig);
} else {
log.debug("found DataSource: " + destDS + " -- re-using");
}
} catch (NamingException e) {
throw new IllegalStateException(String.format("Error creating destination JNDI datasource for %s reason: %s",
dest, e.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,25 @@ private void init(int nthreads) {
this.srcObservationService = new RepoClient(src.getResourceID(), nthreads);

// dest is always a database
final String destDS = "jdbc/ObservationHarvester";
Map<String, Object> destConfig = getConfigDAO(dest);
ConnectionConfig destConnectionConfig = new ConnectionConfig(null, null,
dest.getUsername(), dest.getPassword(), HarvesterResource.POSTGRESQL_DRIVER, dest.getJdbcUrl());
final String destDS = "jdbc/obsHarvestDest";
try {
DBUtil.createJNDIDataSource(destDS, destConnectionConfig);
DataSource cur = null;
try {
cur = DBUtil.findJNDIDataSource(destDS);
} catch (NamingException notInitialized) {
log.debug("JNDI not initialized yet... OK");
}
if (cur == null) {
ConnectionConfig destConnectionConfig = new ConnectionConfig(null, null,
dest.getUsername(), dest.getPassword(), HarvesterResource.POSTGRESQL_DRIVER, dest.getJdbcUrl());
DBUtil.createJNDIDataSource(destDS, destConnectionConfig);
} else {
log.debug("found DataSource: " + destDS + " -- re-using");
}
} catch (NamingException e) {
throw new IllegalStateException(String.format("Error creating destination JNDI datasource for %s reason: %s",
dest, e.getMessage()));
dest, e.getMessage()), e);
}
destConfig.put("jndiDataSourceName", destDS);
destConfig.put("basePublisherID", basePublisherID.toASCIIString());
Expand Down

0 comments on commit 7429f78

Please sign in to comment.