Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9B0CF2004F1 for ; Wed, 30 Aug 2017 18:39:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 99A511697F9; Wed, 30 Aug 2017 16:39:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 404071697EF for ; Wed, 30 Aug 2017 18:39:33 +0200 (CEST) Received: (qmail 5057 invoked by uid 500); 30 Aug 2017 16:39:32 -0000 Mailing-List: contact commits-help@oodt.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@oodt.apache.org Delivered-To: mailing list commits@oodt.apache.org Received: (qmail 3722 invoked by uid 99); 30 Aug 2017 16:39:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Aug 2017 16:39:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 33F03F5579; Wed, 30 Aug 2017 16:39:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mattmann@apache.org To: commits@oodt.apache.org Date: Wed, 30 Aug 2017 16:39:54 -0000 Message-Id: <01977c0cba174c3eb19e49cea49b145c@git.apache.org> In-Reply-To: <602f1c7b278843318b280f88fc5fbb83@git.apache.org> References: <602f1c7b278843318b280f88fc5fbb83@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [25/52] [abbrv] oodt git commit: fix for presence of component home environment variables in tests archived-at: Wed, 30 Aug 2017 16:39:35 -0000 fix for presence of component home environment variables in tests Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/2fbd08f0 Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/2fbd08f0 Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/2fbd08f0 Branch: refs/heads/master Commit: 2fbd08f0d4aa9cced62f286ef7a1dd29536ace16 Parents: 22a1e59 Author: Imesha Sudasingha Authored: Fri Jul 14 21:23:54 2017 +0530 Committer: Imesha Sudasingha Committed: Fri Jul 14 21:23:54 2017 +0530 ---------------------------------------------------------------------- .../DistributedConfigurationManager.java | 15 ++---- .../config/distributed/utils/FilePathUtils.java | 53 ++++++++++++++++++++ config/src/main/resources/etc/log4j.xml | 2 +- .../DistributedConfigurationManagerTest.java | 18 +++++-- 4 files changed, 71 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/2fbd08f0/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 6572270..530416d 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 @@ -24,6 +24,7 @@ import org.apache.oodt.config.ConfigurationManager; import org.apache.oodt.config.Constants; import org.apache.oodt.config.Constants.Properties; import org.apache.oodt.config.distributed.utils.CuratorUtils; +import org.apache.oodt.config.distributed.utils.FilePathUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,7 +142,7 @@ public class DistributedConfigurationManager extends ConfigurationManager { logger.info("Properties loaded from ZNode at : {}", propertiesFileZNodePath); String localFilePath = zNodePaths.getLocalPropertiesFilePath(propertiesFileZNodePath); - localFilePath = fixForComponentHome(localFilePath); + localFilePath = FilePathUtils.fixForComponentHome(component, localFilePath); FileUtils.writeByteArrayToFile(new File(localFilePath), bytes); logger.info("Properties file from ZNode at {} saved to {}", propertiesFileZNodePath, localFilePath); } @@ -167,22 +168,12 @@ public class DistributedConfigurationManager extends ConfigurationManager { byte[] bytes = client.getData().forPath(configFileZNodePath); String localFilePath = zNodePaths.getLocalConfigFilePath(configFileZNodePath); - localFilePath = fixForComponentHome(localFilePath); + localFilePath = FilePathUtils.fixForComponentHome(component, localFilePath); FileUtils.writeByteArrayToFile(new File(localFilePath), bytes); logger.info("Config file from ZNode at {} saved to {}", configFileZNodePath, localFilePath); } } - private String fixForComponentHome(String suffixPath) { - String prefix = System.getenv().get(component.getHome()); - StringBuilder path = new StringBuilder(); - if (prefix != null) { - path.append(prefix.endsWith(SEPARATOR) ? prefix : prefix + SEPARATOR); - } - path.append(suffixPath.startsWith(SEPARATOR) ? suffixPath.substring(1) : suffixPath); - return path.toString(); - } - public Component getComponent() { return component; } http://git-wip-us.apache.org/repos/asf/oodt/blob/2fbd08f0/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 new file mode 100644 index 0000000..12fcff5 --- /dev/null +++ b/config/src/main/java/org/apache/oodt/config/distributed/utils/FilePathUtils.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oodt.config.distributed.utils; + +import org.apache.oodt.config.Component; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.oodt.config.Constants.SEPARATOR; + +public class FilePathUtils { + + private static final Logger logger = LoggerFactory.getLogger(FilePathUtils.class); + + private FilePathUtils() { + } + + public static String fixForComponentHome(Component component, String suffixPath) { + String prefix = System.getenv().get(component.getHome()); + StringBuilder path = new StringBuilder(); + if (prefix != null) { + 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); + logger.debug("Fixed path for {} is {}", suffixPath, path.toString()); + return path.toString(); + } + + public static String unfixForComponentHome(Component component, String path) { + String prefix = System.getenv().get(component.getHome()); + if (prefix != null && path.startsWith(prefix)) { + return path.substring(prefix.length() + SEPARATOR.length()); + } + + return path; + } +} http://git-wip-us.apache.org/repos/asf/oodt/blob/2fbd08f0/config/src/main/resources/etc/log4j.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/etc/log4j.xml b/config/src/main/resources/etc/log4j.xml index 0421de2..1b3dbdf 100644 --- a/config/src/main/resources/etc/log4j.xml +++ b/config/src/main/resources/etc/log4j.xml @@ -27,7 +27,7 @@ - + http://git-wip-us.apache.org/repos/asf/oodt/blob/2fbd08f0/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 1d8c716..fde20f8 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 @@ -20,6 +20,7 @@ package org.apache.oodt.config.distributed; import org.apache.commons.io.FileUtils; import org.apache.oodt.config.ConfigurationManager; import org.apache.oodt.config.distributed.cli.DistributedConfigurationPublisher; +import org.apache.oodt.config.distributed.utils.FilePathUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -31,9 +32,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import static org.apache.oodt.config.Constants.CONFIG_PUBLISHER_XML; import static org.apache.oodt.config.Constants.SEPARATOR; @@ -85,7 +88,7 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf Assert.assertEquals(properties.getProperty(key), System.getProperty(key)); } - String fileName = entry.getValue(); + String fileName = FilePathUtils.fixForComponentHome(publisher.getComponent(), entry.getValue()); fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(1) : fileName; File downloadedFile = new File(fileName); Assert.assertTrue(downloadedFile.exists()); @@ -93,7 +96,7 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf // Checking for configuration files for (Map.Entry entry : publisher.getConfigFiles().entrySet()) { - String fileName = entry.getValue(); + String fileName = FilePathUtils.fixForComponentHome(publisher.getComponent(), entry.getValue()); fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(1) : fileName; File file = new File(fileName); Assert.assertTrue(file.exists()); @@ -106,10 +109,17 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf for (DistributedConfigurationPublisher publisher : publishers) { publisher.destroy(); - for (Map.Entry entry : publisher.getConfigFiles().entrySet()) { + // deleting all locally created conf file directories + Set> files = new HashSet<>(publisher.getConfigFiles().entrySet()); + files.addAll(publisher.getPropertiesFiles().entrySet()); + + for (Map.Entry entry : files) { String fileName = entry.getValue(); fileName = fileName.startsWith(SEPARATOR) ? fileName.substring(1) : fileName; - String confDir = fileName.split(SEPARATOR)[0]; + + String confDir = System.getenv(publisher.getComponent().getHome()) != null ? + System.getenv(publisher.getComponent().getHome()) + SEPARATOR + fileName.split(SEPARATOR)[0] : fileName.split(SEPARATOR)[0]; + File dir = new File(confDir); FileUtils.deleteDirectory(dir); }