You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2017/08/30 16:39:34 UTC
[05/52] [abbrv] oodt git commit: Implemented configuration fetching
for DistributedConfigurationManager
Implemented configuration fetching for DistributedConfigurationManager
Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/5fcf2220
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/5fcf2220
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/5fcf2220
Branch: refs/heads/master
Commit: 5fcf2220125b64afba080c6c9c6c5592daae2dea
Parents: fadf149
Author: Imesha Sudasingha <im...@gmail.com>
Authored: Sat Jun 17 23:21:12 2017 +0530
Committer: Imesha Sudasingha <im...@gmail.com>
Committed: Sat Jun 17 23:21:12 2017 +0530
----------------------------------------------------------------------
README.md | 26 ++--
.../oodt/config/ConfigurationManager.java | 10 +-
.../DistributedConfigurationManager.java | 83 +++++++++-
.../DistributedConfigurationPublisher.java | 9 +-
.../oodt/config/distributed/ZNodePaths.java | 4 +
.../config/distributed/utils/CuratorUtils.java | 151 +++++++++++++++++++
.../StandaloneConfigurationManager.java | 3 +-
.../apache/oodt/config/utils/CuratorUtils.java | 126 ----------------
.../DistributedConfigurationPublisherTest.java | 4 +-
.../cas/filemgr/system/XmlRpcFileManager.java | 8 +-
10 files changed, 264 insertions(+), 160 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index de11028..76c6d49 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,4 @@
-=============================================================
- Welcome to Apache OODT <http://oodt.apache.org/>
-=============================================================
+# Welcome to Apache OODT <http://oodt.apache.org/>
OODT is a grid middleware framework used on a number of successful projects at
NASA's Jet Propulsion Laboratory/California Institute of Technology, and many
@@ -19,8 +17,7 @@ other research institutions and universities, specifically those part of the:
OODT is a Top Level project of the Apache Software Foundation
<http://www.apache.org/>.
-Getting Started
-===============
+## Getting Started
OODT is primarily written in Java, with some components available in Python.
It requires Java 5 and uses the Maven 2 <http://maven.apache.org/> build
@@ -31,8 +28,8 @@ this directory:
For the Python components, see the "agility" subdirectory.
-Contributing
-============
+## Contributing
+
To contribute a patch, follow these instructions (note that installing
[Hub](http://hub.github.com) is not strictly required, but is recommended).
@@ -53,8 +50,7 @@ To contribute a patch, follow these instructions (note that installing
```
-License (see also LICENSE.txt)
-==============================
+## License (see also LICENSE.txt)
Collective work: Copyright 2010-2012 The Apache Software Foundation.
@@ -77,8 +73,7 @@ Apache OODT includes a number of subcomponents with separate copyright
notices and license terms. Your use of these subcomponents is subject to
the terms and conditions of the licenses listed in the LICENSE.txt file.
-Export control
-==============
+## Export control
This distribution includes cryptographic software. The country in which you
currently reside may have restrictions on the import, possession, use, and/or
@@ -104,8 +99,7 @@ The following provides more details on the included cryptographic software:
encrypted PDF files. See http://www.bouncycastle.org/ for more details on
Bouncy Castle.
-Documentation
-=============
+## Documentation
You can build a local copy of the OODT documentation including JavaDocs using
the following Maven 2 command in the OODT source directory:
@@ -125,8 +119,7 @@ than likely you'll need to add to the MAVEN_OPTS environment variable in order
to set the Java heap maximum size with "-Xmx512m" or larger before attempting
to run "mvn site".
-Mailing Lists
-=============
+## Mailing Lists
Discussion about OODT takes place on the following mailing lists:
@@ -144,8 +137,7 @@ dev-subscribe@oodt...). To unsubscribe, send a message to
<LIST>-unsubscribe@oodt.apache.org. For more instructions, send a
message to <LIST>-help@oodt.apache.org.
-Issue Tracker
-=============
+## Issue Tracker
If you encounter errors in OODT or want to suggest an improvement or a new
feature, please visit the OODT issue tracker at
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/main/java/org/apache/oodt/config/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/oodt/config/ConfigurationManager.java b/config/src/main/java/org/apache/oodt/config/ConfigurationManager.java
index 1911889..d65c4ae 100644
--- a/config/src/main/java/org/apache/oodt/config/ConfigurationManager.java
+++ b/config/src/main/java/org/apache/oodt/config/ConfigurationManager.java
@@ -17,10 +17,8 @@
package org.apache.oodt.config;
-import java.io.IOException;
-
/**
- * The abstract class to define functionalities of the configuration managers.
+ * The abstract class to define functions of the configuration managers.
*
* @author Imesha Sudasingha
*/
@@ -32,5 +30,9 @@ public abstract class ConfigurationManager {
this.component = component;
}
- public abstract void loadProperties() throws IOException;
+ public abstract void loadConfiguration() throws Exception;
+
+ public String getComponent() {
+ return component;
+ }
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/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 9ab0e32..d16df7e 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
@@ -17,15 +17,20 @@
package org.apache.oodt.config.distributed;
+import org.apache.commons.io.FileUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.oodt.config.ConfigurationManager;
import org.apache.oodt.config.Constants;
import org.apache.oodt.config.Constants.Properties;
-import org.apache.oodt.config.utils.CuratorUtils;
+import org.apache.oodt.config.distributed.utils.CuratorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.apache.oodt.config.Constants.Properties.ZK_CONNECT_STRING;
@@ -41,12 +46,17 @@ public class DistributedConfigurationManager extends ConfigurationManager {
private static final Logger logger = LoggerFactory.getLogger(DistributedConfigurationManager.class);
- /** Variables required to connect to zookeeper */
+ /** Connection string required to connect to zookeeper */
private String connectString;
private CuratorFramework client;
+ /** Name of the OODT component, to which this class is providing configuration support */
+ private String componentName;
+ private ZNodePaths zNodePaths;
public DistributedConfigurationManager(String component) {
super(component);
+ this.componentName = component;
+ this.zNodePaths = new ZNodePaths(component);
if (System.getProperty(ZK_PROPERTIES_FILE) == null && System.getProperty(Constants.Properties.ZK_CONNECT_STRING) == null) {
throw new IllegalArgumentException("Zookeeper requires system properties " + ZK_PROPERTIES_FILE + " or " + ZK_CONNECT_STRING + " to be set");
@@ -96,7 +106,72 @@ public class DistributedConfigurationManager extends ConfigurationManager {
}
@Override
- public void loadProperties() {
- // todo Implement the logic with Curator
+ public void loadConfiguration() throws Exception {
+ logger.debug("Loading properties for : {}", componentName);
+ loadProperties();
+ logger.info("Properties loaded for : {}", componentName);
+
+ logger.debug("Saving configuration files for : {}", componentName);
+ saveConfigFiles();
+ logger.info("Configuration files saved for : {}", componentName);
+
+ }
+
+ /**
+ * This method will fetch <pre>.properties</pre> files stored in zookeeper and load the properties in those files
+ * to {@link System#props}.
+ *
+ * @throws Exception Zookeeper exceptions
+ */
+ private void loadProperties() throws Exception {
+ String propertiesZNodePath = zNodePaths.getPropertiesZNodePath();
+ List<String> propertiesFilesZNodePaths = CuratorUtils.getLeafZNodePaths(client, propertiesZNodePath);
+
+ if (propertiesFilesZNodePaths.contains(propertiesZNodePath)) {
+ propertiesFilesZNodePaths.remove(propertiesZNodePath);
+ }
+
+ for (String propertiesFileZNodePath : propertiesFilesZNodePaths) {
+ logger.debug("Loading properties from ZNode at : {}", propertiesFileZNodePath);
+ byte[] bytes = client.getData().forPath(propertiesFileZNodePath);
+ try (InputStream in = new ByteArrayInputStream(bytes)) {
+ System.getProperties().load(in);
+ }
+
+ logger.info("Properties loaded from ZNode at : {}", propertiesFileZNodePath);
+ }
+ }
+
+ /**
+ * Fetch and save all the configuration files from zookeeper. Local directories are created accordingly.
+ * For example, if there is a ZNode under <pre>/components/{component}/configuration/etc/mime-types.xml</pre>, it
+ * will be fetched and stored in the local path <pre>etc/mime-types.xml</pre>
+ *
+ * @throws Exception IOException or Zookeeper exception
+ */
+ private void saveConfigFiles() throws Exception {
+ String configParentZNodePath = zNodePaths.getConfigurationZNodePath();
+ List<String> configFilesZNodePaths = CuratorUtils.getLeafZNodePaths(client, configParentZNodePath);
+
+ if (configFilesZNodePaths.contains(configParentZNodePath)) {
+ configFilesZNodePaths.remove(configParentZNodePath);
+ }
+
+ for (String configFileZNodePath : configFilesZNodePaths) {
+ logger.debug("Fetching configuration file from ZNode at : {}", configFileZNodePath);
+ byte[] bytes = client.getData().forPath(configFileZNodePath);
+
+ String localFilePath = zNodePaths.getLocalConfigFilePath(configFileZNodePath);
+ FileUtils.writeByteArrayToFile(new File(localFilePath), bytes);
+ logger.info("Config file from ZNode at {} saved to {}", configFileZNodePath);
+ }
+ }
+
+ public String getComponentName() {
+ return componentName;
+ }
+
+ public ZNodePaths getzNodePaths() {
+ return zNodePaths;
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisher.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisher.java b/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisher.java
index 8970641..37b57c9 100644
--- a/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisher.java
+++ b/config/src/main/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisher.java
@@ -20,7 +20,7 @@ package org.apache.oodt.config.distributed;
import org.apache.commons.io.FileUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.oodt.config.Constants;
-import org.apache.oodt.config.utils.CuratorUtils;
+import org.apache.oodt.config.distributed.utils.CuratorUtils;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -114,6 +114,8 @@ public class DistributedConfigurationPublisher {
logger.debug("Publishing config files : {}", configFiles);
publishConfiguration(configFiles, false);
logger.info("Config files published successfully");
+
+ // TODO: 6/17/17 Verify whether the given configuration are published correctly
}
private void publishConfiguration(Map<String, String> fileMapping, boolean isProperties) throws Exception {
@@ -135,7 +137,6 @@ public class DistributedConfigurationPublisher {
String existingData = new String(bytes);
if (content.equals(existingData)) {
logger.warn("{} already exists in zookeeper at {}", entry.getKey(), entry.getValue());
- continue;
} else {
Stat stat = client.setData().forPath(zNodePath, content.getBytes());
if (stat != null) {
@@ -143,6 +144,10 @@ public class DistributedConfigurationPublisher {
}
}
} else {
+ /*
+ * Creating these ZNodes with parent 'Containers' is important since containers are automatically deleted
+ * when no child node is present under them.
+ */
client.create().creatingParentContainersIfNeeded().forPath(zNodePath, content.getBytes());
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/main/java/org/apache/oodt/config/distributed/ZNodePaths.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/oodt/config/distributed/ZNodePaths.java b/config/src/main/java/org/apache/oodt/config/distributed/ZNodePaths.java
index f390838..90fa9a5 100644
--- a/config/src/main/java/org/apache/oodt/config/distributed/ZNodePaths.java
+++ b/config/src/main/java/org/apache/oodt/config/distributed/ZNodePaths.java
@@ -77,4 +77,8 @@ public class ZNodePaths {
public String getConfigurationZNodePath(String subPath) {
return configurationZNodeRoot + (subPath.startsWith(SEPARATOR) ? subPath.substring(1) : subPath);
}
+
+ public String getLocalConfigFilePath(String zNodePath) {
+ return zNodePath.substring(configurationZNodeRoot.length());
+ }
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/main/java/org/apache/oodt/config/distributed/utils/CuratorUtils.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/oodt/config/distributed/utils/CuratorUtils.java b/config/src/main/java/org/apache/oodt/config/distributed/utils/CuratorUtils.java
new file mode 100644
index 0000000..6f9c97f
--- /dev/null
+++ b/config/src/main/java/org/apache/oodt/config/distributed/utils/CuratorUtils.java
@@ -0,0 +1,151 @@
+/*
+ * 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.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.ACLProvider;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.oodt.config.Constants;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.oodt.config.Constants.Properties.ZK_PROPERTIES_FILE;
+import static org.apache.oodt.config.Constants.ZPaths.*;
+
+public class CuratorUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(CuratorUtils.class);
+
+ private CuratorUtils() {
+ }
+
+ /**
+ * Loads zookeeper related properties from ZK_PROPERTIES_FILE.
+ *
+ * @throws IOException if properties file could not be read
+ */
+ public static void loadZookeeperProperties() throws IOException {
+ System.getProperties().load(new FileInputStream(System.getProperty(ZK_PROPERTIES_FILE)));
+ }
+
+ /**
+ * Create a ZNode in the given path if not exists, with the given data
+ *
+ * @param curatorFramework {@link CuratorFramework} client
+ * @param zNodePath the path in which the ZNode to be created
+ */
+ public static void createZNodeIfNotExists(CuratorFramework curatorFramework, String zNodePath, CreateMode mode, byte[] content) throws Exception {
+ try {
+ String path = curatorFramework.create().creatingParentsIfNeeded().withMode(mode).forPath(zNodePath, content);
+ logger.debug("Created ZNode at path : {}", path);
+ } catch (Exception e) {
+ if (e instanceof KeeperException && KeeperException.Code.NODEEXISTS.equals(((KeeperException) e).code())) {
+ // This is a desired behaviour, trying to create an already existing znode.
+ logger.debug("Attempting to create an already existing ZNode at path {} : {}", zNodePath, e);
+ } else {
+ logger.error("Error when creating ZNode for path {} : {}", zNodePath, e.getMessage());
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Gets the <code>String</code> value of the data in the given znode path
+ *
+ * @param client {@link CuratorFramework} client
+ * @param path ZNode path to be checked
+ * @return ZNode's data as a string or null
+ * @throws Exception zookeeper errors and etc
+ */
+ public static String getIfExists(CuratorFramework client, String path) throws Exception {
+ return client.checkExists().forPath(path) != null ? new String(client.getData().forPath(path)) : null;
+ }
+
+ /**
+ * Builds a {@link CuratorFramework} instance using the given connectString.
+ *
+ * @param connectString connection string to connect to zookeeper
+ * @param logger {@link Logger} instance of the calling class
+ * @return Newly created CuratorFramework instance.
+ */
+ public static CuratorFramework getCuratorFrameworkClient(String connectString, Logger logger) {
+ int connectionTimeoutMs = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "15000"));
+ int sessionTimeoutMs = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "60000"));
+ int retryInitialWaitMs = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "1000"));
+ int maxRetryCount = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "3"));
+
+ CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
+ .connectString(connectString)
+ .retryPolicy(new ExponentialBackoffRetry(retryInitialWaitMs, maxRetryCount))
+ .connectionTimeoutMs(connectionTimeoutMs)
+ .sessionTimeoutMs(sessionTimeoutMs);
+
+ /*
+ * If authorization information is available, those will be added to the client. NOTE: These auth info are
+ * for access control, therefore no authentication will happen when the client is being started. These
+ * info will only be required whenever a client is accessing an already create ZNode. For another client of
+ * another node to make use of a ZNode created by this node, it should also provide the same auth info.
+ */
+ if (System.getProperty(Constants.Properties.ZK_USERNAME) != null && System.getProperty(Constants.Properties.ZK_PASSWORD) != null) {
+ String authenticationString = System.getProperty(Constants.Properties.ZK_USERNAME) + ":" + System.getProperty(Constants.Properties.ZK_PASSWORD);
+ builder.authorization("digest", authenticationString.getBytes())
+ .aclProvider(new ACLProvider() {
+ public List<ACL> getDefaultAcl() {
+ return ZooDefs.Ids.CREATOR_ALL_ACL;
+ }
+
+ public List<ACL> getAclForPath(String path) {
+ return ZooDefs.Ids.CREATOR_ALL_ACL;
+ }
+ });
+ }
+
+ CuratorFramework client = builder.build();
+ logger.debug("CuratorFramework client built successfully with connectString: {}, sessionTimeout: {} and connectionTimeout: {}",
+ connectString, sessionTimeoutMs, connectionTimeoutMs);
+
+ return client;
+ }
+
+ public static List<String> getLeafZNodePaths(CuratorFramework client, String parentZNodePath) throws Exception {
+ List<String> leafZNodePaths = new ArrayList<>();
+
+ List<String> childNodes = client.getChildren().forPath(parentZNodePath);
+ if (childNodes != null && childNodes.size() > 0) {
+ for (String child : childNodes) {
+ String childZNodePath = parentZNodePath + SEPARATOR + child;
+ leafZNodePaths.addAll(getLeafZNodePaths(client, childZNodePath));
+ }
+ } else {
+ // Then, current ZNode path is a leaf node
+ leafZNodePaths.add(parentZNodePath);
+ }
+
+ return leafZNodePaths;
+ }
+}
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/main/java/org/apache/oodt/config/standalone/StandaloneConfigurationManager.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/oodt/config/standalone/StandaloneConfigurationManager.java b/config/src/main/java/org/apache/oodt/config/standalone/StandaloneConfigurationManager.java
index 6ecb1b7..8d932fb 100644
--- a/config/src/main/java/org/apache/oodt/config/standalone/StandaloneConfigurationManager.java
+++ b/config/src/main/java/org/apache/oodt/config/standalone/StandaloneConfigurationManager.java
@@ -23,7 +23,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -45,7 +44,7 @@ public class StandaloneConfigurationManager extends ConfigurationManager {
/** {@inheritDoc} */
@Override
- public void loadProperties() throws IOException {
+ public void loadConfiguration() throws Exception {
for (String file : propertiesFiles) {
logger.debug("Loading properties from file : {}", file);
System.getProperties().load(new FileInputStream(new File(file)));
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/main/java/org/apache/oodt/config/utils/CuratorUtils.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/oodt/config/utils/CuratorUtils.java b/config/src/main/java/org/apache/oodt/config/utils/CuratorUtils.java
deleted file mode 100644
index c73d48b..0000000
--- a/config/src/main/java/org/apache/oodt/config/utils/CuratorUtils.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.utils;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.framework.api.ACLProvider;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.oodt.config.Constants;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.data.ACL;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.List;
-
-import static org.apache.oodt.config.Constants.Properties.ZK_PROPERTIES_FILE;
-
-public class CuratorUtils {
-
- private static final Logger logger = LoggerFactory.getLogger(CuratorUtils.class);
-
- private CuratorUtils() {
- }
-
- /**
- * Loads zookeeper related properties from ZK_PROPERTIES_FILE.
- *
- * @throws IOException if properties file could not be read
- */
- public static void loadZookeeperProperties() throws IOException {
- System.getProperties().load(new FileInputStream(System.getProperty(ZK_PROPERTIES_FILE)));
- }
-
- /**
- * Create a ZNode in the given path if not exists, with the given data
- *
- * @param curatorFramework {@link CuratorFramework} client
- * @param zNodePath the path in which the ZNode to be created
- */
- public static void createZNodeIfNotExists(CuratorFramework curatorFramework, String zNodePath, CreateMode mode, byte[] content) throws Exception {
- try {
- String path = curatorFramework.create().creatingParentsIfNeeded().withMode(mode).forPath(zNodePath, content);
- logger.debug("Created ZNode at path : {}", path);
- } catch (Exception e) {
- if (e instanceof KeeperException && KeeperException.Code.NODEEXISTS.equals(((KeeperException) e).code())) {
- // This is a desired behaviour, trying to create an already existing znode.
- logger.debug("Attempting to create an already existing ZNode at path {} : {}", zNodePath, e);
- } else {
- logger.error("Error when creating ZNode for path {} : {}", zNodePath, e.getMessage());
- throw e;
- }
- }
- }
-
- /**
- * Gets the <code>String</code> value of the data in the given znode path
- *
- * @param client {@link CuratorFramework} client
- * @param path ZNode path to be checked
- * @return ZNode's data as a string or null
- * @throws Exception zookeeper errors and etc
- */
- public static String getIfExists(CuratorFramework client, String path) throws Exception {
- return client.checkExists().forPath(path) != null ? new String(client.getData().forPath(path)) : null;
- }
-
- public static CuratorFramework getCuratorFrameworkClient(String connectString, Logger logger) {
- int connectionTimeoutMs = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "15000"));
- int sessionTimeoutMs = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "60000"));
- int retryInitialWaitMs = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "1000"));
- int maxRetryCount = Integer.parseInt(System.getProperty(Constants.Properties.ZK_CONNECTION_TIMEOUT, "3"));
-
- CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
- .connectString(connectString)
- .retryPolicy(new ExponentialBackoffRetry(retryInitialWaitMs, maxRetryCount))
- .connectionTimeoutMs(connectionTimeoutMs)
- .sessionTimeoutMs(sessionTimeoutMs);
-
- /*
- * If authorization information is available, those will be added to the client. NOTE: These auth info are
- * for access control, therefore no authentication will happen when the client is being started. These
- * info will only be required whenever a client is accessing an already create ZNode. For another client of
- * another node to make use of a ZNode created by this node, it should also provide the same auth info.
- */
- if (System.getProperty(Constants.Properties.ZK_USERNAME) != null && System.getProperty(Constants.Properties.ZK_PASSWORD) != null) {
- String authenticationString = System.getProperty(Constants.Properties.ZK_USERNAME) + ":" + System.getProperty(Constants.Properties.ZK_PASSWORD);
- builder.authorization("digest", authenticationString.getBytes())
- .aclProvider(new ACLProvider() {
- public List<ACL> getDefaultAcl() {
- return ZooDefs.Ids.CREATOR_ALL_ACL;
- }
-
- public List<ACL> getAclForPath(String path) {
- return ZooDefs.Ids.CREATOR_ALL_ACL;
- }
- });
- }
-
- CuratorFramework client = builder.build();
- logger.debug("CuratorFramework client built successfully with connectString: {}, sessionTimeout: {} and connectionTimeout: {}",
- connectString, sessionTimeoutMs, connectionTimeoutMs);
-
- return client;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java
----------------------------------------------------------------------
diff --git a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java
index 2a3c903..3a0212a 100644
--- a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java
+++ b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java
@@ -95,8 +95,10 @@ public class DistributedConfigurationPublisherTest {
Assert.assertEquals(fileContent, storedContent);
}
-
}
+
+// DistributedConfigurationManager configurationManager = new DistributedConfigurationManager(Constants.Components.FILE_MANAGER);
+// configurationManager.loadConfiguration();
}
@AfterClass
http://git-wip-us.apache.org/repos/asf/oodt/blob/5fcf2220/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
index 9d7d740..261e93c 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
@@ -117,7 +117,7 @@ public class XmlRpcFileManager {
*
* @param port The web server port to run the XML Rpc server on, defaults to 1999.
*/
- public XmlRpcFileManager(int port) throws IOException {
+ public XmlRpcFileManager(int port) throws Exception {
webServerPort = port;
// start up the web server
@@ -1197,7 +1197,7 @@ public class XmlRpcFileManager {
}
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) throws Exception {
int portNum = -1;
String usage = "FileManager --portNum <port number for xml rpc service>\n";
@@ -1536,8 +1536,8 @@ public class XmlRpcFileManager {
return pMet;
}
- private void loadConfiguration() throws IOException {
- configurationManager.loadProperties();
+ private void loadConfiguration() throws Exception {
+ configurationManager.loadConfiguration();
String metaFactory, dataFactory, transferFactory;