Fix for empty component home variable
Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/daf555c3 Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/daf555c3 Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/daf555c3 Branch: refs/heads/feature/zookeeper-config Commit: daf555c3803739f228ab7d0ac628bc36a9224901 Parents: 2fbd08f Author: Imesha Sudasingha <[email protected]> Authored: Fri Jul 14 23:01:01 2017 +0530 Committer: Imesha Sudasingha <[email protected]> Committed: Fri Jul 14 23:01:01 2017 +0530 ---------------------------------------------------------------------- .../main/java/org/apache/oodt/config/Component.java | 4 ++-- .../distributed/DistributedConfigurationManager.java | 1 + .../oodt/config/distributed/utils/FilePathUtils.java | 6 ++++-- .../DistributedConfigurationManagerTest.java | 15 +++++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/daf555c3/config/src/main/java/org/apache/oodt/config/Component.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/oodt/config/Component.java b/config/src/main/java/org/apache/oodt/config/Component.java index 2c7123e..e2ea223 100644 --- a/config/src/main/java/org/apache/oodt/config/Component.java +++ b/config/src/main/java/org/apache/oodt/config/Component.java @@ -24,8 +24,8 @@ package org.apache.oodt.config; * @author Imesha Sudasingha */ public enum Component { - FILE_MANAGER("filemgr", "FILEMGR_HOME"), - RESOURCE_MANAGER("resmgr", "RESMGR_HOME"); + FILE_MANAGER("filemgr", "OODT_FILEMGR_HOME"), + RESOURCE_MANAGER("resmgr", "OODT_RESMGR_HOME"); /** Shorthand name of the component. Will be used when creating ZNodes in zookeeper */ String name; http://git-wip-us.apache.org/repos/asf/oodt/blob/daf555c3/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationManager.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationManager.java b/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationManager.java index 530416d..da96913 100644 --- a/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationManager.java +++ b/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationManager.java @@ -143,6 +143,7 @@ public class DistributedConfigurationManager extends ConfigurationManager { String localFilePath = zNodePaths.getLocalPropertiesFilePath(propertiesFileZNodePath); localFilePath = FilePathUtils.fixForComponentHome(component, localFilePath); + logger.debug("Storing configuration in file: {}", localFilePath); FileUtils.writeByteArrayToFile(new File(localFilePath), bytes); logger.info("Properties file from ZNode at {} saved to {}", propertiesFileZNodePath, localFilePath); } http://git-wip-us.apache.org/repos/asf/oodt/blob/daf555c3/config/src/main/java/org/apache/oodt/config/distributed/utils/FilePathUtils.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/oodt/config/distributed/utils/FilePathUtils.java b/config/src/main/java/org/apache/oodt/config/distributed/utils/FilePathUtils.java index 12fcff5..5b242c2 100644 --- a/config/src/main/java/org/apache/oodt/config/distributed/utils/FilePathUtils.java +++ b/config/src/main/java/org/apache/oodt/config/distributed/utils/FilePathUtils.java @@ -18,6 +18,7 @@ package org.apache.oodt.config.distributed.utils; import org.apache.oodt.config.Component; +import org.apache.oodt.config.Constants.ZPaths; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,11 +34,12 @@ public class FilePathUtils { public static String fixForComponentHome(Component component, String suffixPath) { String prefix = System.getenv().get(component.getHome()); StringBuilder path = new StringBuilder(); - if (prefix != null) { + if (prefix != null && !prefix.trim().isEmpty()) { + prefix = prefix.trim(); logger.debug("Found prefix {}:{} for suffixPath: {}", component.getHome(), prefix, suffixPath); path.append(prefix.endsWith(SEPARATOR) ? prefix : prefix + SEPARATOR); } - path.append(suffixPath.startsWith(SEPARATOR) ? suffixPath.substring(1) : suffixPath); + path.append(suffixPath.startsWith(ZPaths.SEPARATOR) ? suffixPath.substring(ZPaths.SEPARATOR.length()) : suffixPath); logger.debug("Fixed path for {} is {}", suffixPath, path.toString()); return path.toString(); } http://git-wip-us.apache.org/repos/asf/oodt/blob/daf555c3/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java ---------------------------------------------------------------------- diff --git a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java index fde20f8..d03f11a 100644 --- a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java +++ b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java @@ -88,16 +88,18 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf Assert.assertEquals(properties.getProperty(key), System.getProperty(key)); } - String fileName = FilePathUtils.fixForComponentHome(publisher.getComponent(), entry.getValue()); - fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(1) : fileName; + String fileName = entry.getValue(); + fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(SEPARATOR.length()) : fileName; + fileName = FilePathUtils.fixForComponentHome(publisher.getComponent(), fileName); File downloadedFile = new File(fileName); Assert.assertTrue(downloadedFile.exists()); } // Checking for configuration files for (Map.Entry<String, String> entry : publisher.getConfigFiles().entrySet()) { - String fileName = FilePathUtils.fixForComponentHome(publisher.getComponent(), entry.getValue()); - fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(1) : fileName; + String fileName = entry.getValue(); + fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(SEPARATOR.length()) : fileName; + fileName = FilePathUtils.fixForComponentHome(publisher.getComponent(), fileName); File file = new File(fileName); Assert.assertTrue(file.exists()); } @@ -117,8 +119,9 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf String fileName = entry.getValue(); fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(1) : fileName; - String confDir = System.getenv(publisher.getComponent().getHome()) != null ? - System.getenv(publisher.getComponent().getHome()) + SEPARATOR + fileName.split(SEPARATOR)[0] : fileName.split(SEPARATOR)[0]; + String prefixPath = System.getenv(publisher.getComponent().getHome()); + String confDir = prefixPath != null && !prefixPath.trim().isEmpty() ? + prefixPath.trim() + SEPARATOR + fileName.split(SEPARATOR)[0] : fileName.split(SEPARATOR)[0]; File dir = new File(confDir); FileUtils.deleteDirectory(dir);
