Skip to content

Commit

Permalink
enable to override DBMSConfigurator props using JRE -D arguments; pre…
Browse files Browse the repository at this point in the history
…fix props with KL_
  • Loading branch information
pgdurand committed Oct 30, 2020
1 parent 9e92600 commit 2f1337e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 53 deletions.
15 changes: 7 additions & 8 deletions src/bzh/plealog/dbmirror/ui/LocalDBPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
import com.plealog.genericapp.api.EZEnvironment;
import com.plealog.genericapp.api.file.EZFileManager;

import bzh.plealog.dbmirror.fetcher.DBServerConfig;
import bzh.plealog.dbmirror.fetcher.PFTPLoaderDescriptor;
import bzh.plealog.dbmirror.fetcher.PLocalLoader;
Expand All @@ -90,7 +95,6 @@
import bzh.plealog.dbmirror.ui.resources.DBMSMessages;
import bzh.plealog.dbmirror.util.Utils;
import bzh.plealog.dbmirror.util.conf.DBMSAbstractConfig;
import bzh.plealog.dbmirror.util.conf.DBMSConfigurator;
import bzh.plealog.dbmirror.util.conf.DBMirrorConfig;
import bzh.plealog.dbmirror.util.descriptor.DBDescriptor;
import bzh.plealog.dbmirror.util.descriptor.DBDescriptorUtils;
Expand All @@ -103,11 +107,6 @@
import bzh.plealog.dbmirror.util.sequence.SequenceValidatorTaxon;
import bzh.plealog.dbmirror.util.sequence.TaxonMatcherHelper;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
import com.plealog.genericapp.api.EZEnvironment;
import com.plealog.genericapp.api.file.EZFileManager;

/**
* This class implements a panel enabling a user to use the KDMS Lucene Indexer
* system given a set of data files.
Expand Down Expand Up @@ -1351,15 +1350,15 @@ public void actionPerformed(ActionEvent e) {
// In case of a previous filter, takes the filtered files

final File current = new File(file);
foundFiles = new File(DBMSConfigurator.TMP_FILTER_DIRECTORY)
foundFiles = new File(DBMSAbstractConfig.getWorkingFilterPath())
.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return current.getName().equalsIgnoreCase(name);
}
});
if ((foundFiles != null) && (foundFiles.length == 1)) {
databankFiles.add(new File(DBMSConfigurator.TMP_FILTER_DIRECTORY,
databankFiles.add(new File(DBMSAbstractConfig.getWorkingFilterPath(),
foundFiles[0]));

} else {
Expand Down
65 changes: 29 additions & 36 deletions src/bzh/plealog/dbmirror/util/conf/DBMSAbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class DBMSAbstractConfig {
private static String _logAppFileName;
private static String _logAppFile;
private static String _workingTmpPath;
private static String _filterWorkingTmpPath;
private static String _externalBinPath;
private static String _confPath;
private static String _startDate;
Expand Down Expand Up @@ -87,15 +88,15 @@ public class DBMSAbstractConfig {
public static final String CONF_PATH_NAME = "conf";
public static final String EXT_PATH_NAME = "external";
public static final String BIN_PATH_NAME = "bin";
private static final String APP_HOME_PROP_KEY = "KL_HOME";
private static final String APP_WORKING_DIR_PROP_KEY = "KL_WORKING_DIR";
private static final String APP_CONF_DIR_PROP_KEY = "KL_CONF_DIR";
public static final String APP_DEBUG_MODE_PROP_KEY = "KL_DEBUG";
private static final String APP_LOG_FILE_PROP_KEY = "KL_LOG_FILE";
private static final String LCL_MIRROR_PROP_KEY = "MIRROR_HOME";
public static final String APP_KEY_PREFIX = "KL_";
private static final String APP_HOME_PROP_KEY = APP_KEY_PREFIX+"HOME";
private static final String APP_WORKING_DIR_PROP_KEY = APP_KEY_PREFIX+"WORKING_DIR";
private static final String APP_CONF_DIR_PROP_KEY = APP_KEY_PREFIX+"CONF_DIR";
public static final String APP_DEBUG_MODE_PROP_KEY = APP_KEY_PREFIX+"DEBUG";
private static final String APP_LOG_FILE_PROP_KEY = APP_KEY_PREFIX+"LOG_FILE";
private static final String USER_DIR_PROP_KEY = "user.dir";

private static final String DEF_DB_PATH = "biobanks";
private static final String DEF_DB_PATH = "beedeem_banks_repository";

// file containing the DB_XREFs definition
public static final String DB_XREF_CONF_FILE = "dbxrefsForFasta.config";
Expand Down Expand Up @@ -167,7 +168,7 @@ public static String getLocalMirrorPath() {

if (_localMirrorPath != null)
return _localMirrorPath;
String path = pruneQuotes(System.getProperty(LCL_MIRROR_PROP_KEY));
String path = pruneQuotes(System.getProperty(APP_KEY_PREFIX+DBMSConfigurator.MIRROR_PATH));
if (path != null) {
_localMirrorPath = path;
} else {
Expand Down Expand Up @@ -278,11 +279,27 @@ public static String getWorkingPath() {
return _workingTmpPath;
}

public static void setWorkingPath(String path) {
_workingTmpPath = Utils.terminatePath(path);
LOGGER.debug("working path: " + _workingTmpPath);
public static String getWorkingFilterPath() {
if (_filterWorkingTmpPath != null)
return _filterWorkingTmpPath;
_filterWorkingTmpPath = Utils.terminatePath(getWorkingPath()+"filter");
File f = new File(_filterWorkingTmpPath);
if (!f.exists()) {
f.mkdirs();
} else {
try {
FileUtils.cleanDirectory(f);
} catch (IOException e) {
// do not throw exception for this
LoggerCentral.warn(
LOGGER,
"Unable to manage the tmp filter directory in '"
+ _filterWorkingTmpPath + "' : "
+ e.getMessage());
}
}
return _filterWorkingTmpPath;
}

/**
* Returns the path pointing to external binaries. The path specifically
* points to the OS localized dir (linux, windows or macos).
Expand Down Expand Up @@ -501,31 +518,7 @@ public static void initializeConfigurator(String kdmsConfFile) {
LoggerCentral.info(LOGGER, "*** START APPLICATION *** " + new Date());
LoggerCentral.info(LOGGER, "Configuration:");
_configurator.dumpContent(LOGGER);

// manage the tmp filter directory
try {
DBMSConfigurator.TMP_FILTER_DIRECTORY = DBMSExecNativeCommand
.formatNativePath(
(Utils.terminatePath(DBMSAbstractConfig.getLocalMirrorPath()) + "tmp")
.replace(File.separatorChar, '|'), false, false).replace(
'|', File.separatorChar);
File tmpFilterDirectory = new File(
DBMSConfigurator.TMP_FILTER_DIRECTORY);
if (!tmpFilterDirectory.exists()) {
tmpFilterDirectory.mkdirs();
} else {
FileUtils.cleanDirectory(tmpFilterDirectory);
}
} catch (IOException e) {
// do not throw exception for this
LoggerCentral.warn(
LOGGER,
"Unable to manage the tmp filter directory in '"
+ DBMSConfigurator.TMP_FILTER_DIRECTORY + "' : "
+ e.getMessage());
}
}

}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/bzh/plealog/dbmirror/util/conf/DBMSConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ public static enum LUCENE_LK_VALUES {LK_DEFAULT, LK_NATIVE, LK_SIMPLE};
LONG_FILE_NAME, FDB_PRG_NAME, FDB_PATH_NAME, UI_SHOW_PATH, COPY_WORKERS,
FASTA_VOLSIZE, LUCENE_FS, LUCENE_LOCK, ASPERA_KEY, ASPERA_BIN};

public static String TMP_FILTER_DIRECTORY = Utils
.terminatePath(DBMSAbstractConfig
.getLocalMirrorPath())
+ "tmp";

public DBMSConfigurator() {
try {
_pConfig = new PropertiesConfiguration();
Expand Down Expand Up @@ -153,7 +148,9 @@ public void load(String path, boolean listenReload) throws IOException {
* @see java.util.Properties#getProperty(java.lang.String)
*/
public String getProperty(String key) {
return _pConfig.getString(key);
//this was added to enable overriding config file properties using java -D arguments.
String value = DBMSAbstractConfig.pruneQuotes(System.getProperty(DBMSAbstractConfig.APP_KEY_PREFIX+key));
return value !=null ? value : _pConfig.getString(key);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.apache.commons.logging.Log;

import bzh.plealog.dbmirror.util.Utils;
import bzh.plealog.dbmirror.util.conf.DBMSConfigurator;
import bzh.plealog.dbmirror.util.conf.DBMSAbstractConfig;
import bzh.plealog.dbmirror.util.descriptor.DatabankFormat;
import bzh.plealog.dbmirror.util.log.LoggerCentral;

Expand Down Expand Up @@ -108,7 +108,7 @@ public void abortProcess() {
public SequenceFileManager(String sequenceFilepath,
DatabankFormat databankFormat, Log logger, JProgressBar progressBar)
throws IOException {
setTmpFileDirectory(DBMSConfigurator.TMP_FILTER_DIRECTORY);
setTmpFileDirectory(DBMSAbstractConfig.getWorkingFilterPath());
this.sequenceFile = new File(sequenceFilepath);
this.databankFormat = databankFormat;
this.progressBar = progressBar;
Expand Down Expand Up @@ -142,7 +142,7 @@ public SequenceFileManager(String sequenceFilepath,
*/
public SequenceFileManager(BufferedReader reader, BufferedWriter writer,
DatabankFormat databankFormat, Log logger) {
setTmpFileDirectory(DBMSConfigurator.TMP_FILTER_DIRECTORY);
setTmpFileDirectory(DBMSAbstractConfig.getWorkingFilterPath());
this.databankFormat = databankFormat;
this.logger = logger;
this.validators = new ArrayList<ISequenceValidator>();
Expand Down

0 comments on commit 2f1337e

Please sign in to comment.