airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject git commit: fixing test cases with embedded zk integration
Date Sat, 02 Aug 2014 02:39:38 GMT
Repository: airavata
Updated Branches:
  refs/heads/master f65c5a8a6 -> 7d07911c9


fixing test cases with embedded zk integration


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/7d07911c
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/7d07911c
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/7d07911c

Branch: refs/heads/master
Commit: 7d07911c9d1389ac957067dc5314580382dbe1ad
Parents: f65c5a8
Author: lahiru <lahiru@apache.org>
Authored: Sat Aug 2 02:41:12 2014 +0530
Committer: lahiru <lahiru@apache.org>
Committed: Sat Aug 2 02:41:12 2014 +0530

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   |  4 +-
 .../airavata/common/utils/AiravataZKUtils.java  | 82 +++++++++++++++++++-
 .../server/src/main/resources/zoo.cfg           |  2 +-
 .../gfac/client/GfacClientFactoryTest.java      | 16 ++++
 .../src/test/resources/zoo.cfg                  |  5 ++
 .../core/monitor/GfacInternalStatusUpdator.java |  3 +-
 .../util/OrchestratorRecoveryHandler.java       |  4 +-
 .../client/OrchestratorClientFactoryTest.java   |  8 ++
 .../src/test/resources/zoo.cfg                  |  5 ++
 .../core/impl/GFACServiceJobSubmitter.java      |  4 +-
 .../org/apache/airavata/server/ServerMain.java  | 72 +----------------
 11 files changed, 126 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index 90f4857..f75944c 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -48,6 +48,7 @@ import org.apache.airavata.api.airavataAPIConstants;
 import org.apache.airavata.api.server.util.DataModelUtils;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.AiravataZKUtils;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription;
 import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule;
@@ -125,8 +126,7 @@ public class AiravataServerHandler implements Airavata.Iface, Watcher
{
 
     public AiravataServerHandler() {
         try {
-            String zkhostPort = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_HOST)
-                    + ":" + ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_PORT);
+            String zkhostPort = AiravataZKUtils.getZKhostPort();
             String airavataServerHostPort = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.API_SERVER_HOST)
                                 + ":" + ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.API_SERVER_PORT);
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataZKUtils.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataZKUtils.java
b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataZKUtils.java
index 1426e67..4347bd2 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataZKUtils.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/AiravataZKUtils.java
@@ -26,11 +26,22 @@ import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.URL;
 import java.util.List;
 
 public class AiravataZKUtils {
+    private final static Logger logger = LoggerFactory.getLogger(AiravataZKUtils.class);
+
     public static final String ZK_EXPERIMENT_STATE_NODE = "state";
 
     public static String getExpZnodePath(String experimentId, String taskId) throws ApplicationSettingsException
{
@@ -48,8 +59,8 @@ public class AiravataZKUtils {
     }
 
     public static String getZKhostPort() throws ApplicationSettingsException {
-        return ServerSettings.getSetting(Constants.ZOOKEEPER_SERVER_HOST)
-                + ":" + ServerSettings.getSetting(Constants.ZOOKEEPER_SERVER_PORT);
+        return ServerSettings.getSetting(Constants.ZOOKEEPER_SERVER_HOST,"localhost")
+                + ":" + ServerSettings.getSetting(Constants.ZOOKEEPER_SERVER_PORT,"2181");
     }
 
     public static String getExpStatePath(String experimentId, String taskId) throws ApplicationSettingsException
{
@@ -86,4 +97,71 @@ public class AiravataZKUtils {
         String gfacServer = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_EXPERIMENT_NODE,
"/gfac-experiments");
         return zk.getChildren(gfacServer, null);
     }
+
+    public static void runZKFromConfig(ServerConfig config,ServerCnxnFactory cnxnFactory)
throws IOException {
+        AiravataZKUtils.logger.info("Starting Zookeeper server...");
+        FileTxnSnapLog txnLog = null;
+        try {
+            // Note that this thread isn't going to be doing anything else,
+            // so rather than spawning another thread, we will just call
+            // run() in this thread.
+            // create a file logger url from the command line args
+            ZooKeeperServer zkServer = new ZooKeeperServer();
+
+            txnLog = new FileTxnSnapLog(new File(config.getDataDir()), new File(
+                    config.getDataDir()));
+            zkServer.setTxnLogFactory(txnLog);
+            zkServer.setTickTime(config.getTickTime());
+            zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
+            zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
+            cnxnFactory = ServerCnxnFactory.createFactory();
+            cnxnFactory.configure(config.getClientPortAddress(),
+                    config.getMaxClientCnxns());
+            cnxnFactory.startup(zkServer);
+            cnxnFactory.join();
+            if (zkServer.isRunning()) {
+                zkServer.shutdown();
+            }
+        } catch (InterruptedException e) {
+            // warn, but generally this is ok
+            AiravataZKUtils.logger.warn("Server interrupted", e);
+            System.exit(1);
+        } finally {
+            if (txnLog != null) {
+                txnLog.close();
+            }
+        }
+    }
+
+    public static void startEmbeddedZK(ServerCnxnFactory cnxnFactory) {
+        if (ServerSettings.isEmbeddedZK()) {
+            ServerConfig serverConfig = new ServerConfig();
+            URL resource = AiravataZKUtils.class.getClassLoader().getResource("zoo.cfg");
+            if (resource == null) {
+                logger.error("There is no zoo.cfg file in the classpath... Failed to start
Zookeeper Server");
+                System.exit(1);
+            }
+            try {
+                serverConfig.parse(resource.getPath());
+            } catch (QuorumPeerConfig.ConfigException e) {
+                logger.error("Error while starting embedded Zookeeper", e);
+                System.exit(2);
+            }
+
+            final ServerConfig fServerConfig = serverConfig;
+            final ServerCnxnFactory fserverCnxnFactory = cnxnFactory;
+            (new Thread() {
+                public void run() {
+                    try {
+                        AiravataZKUtils.runZKFromConfig(fServerConfig,fserverCnxnFactory);
+                    } catch (IOException e) {
+                        logger.error("Error while starting embedded Zookeeper", e);
+                        System.exit(3);
+                    }
+                }
+            }).start();
+        }else{
+            logger.info("Skipping Zookeeper embedded startup ...");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/configuration/server/src/main/resources/zoo.cfg
----------------------------------------------------------------------
diff --git a/modules/configuration/server/src/main/resources/zoo.cfg b/modules/configuration/server/src/main/resources/zoo.cfg
index 5a9ebe9..d65a3bc 100644
--- a/modules/configuration/server/src/main/resources/zoo.cfg
+++ b/modules/configuration/server/src/main/resources/zoo.cfg
@@ -2,4 +2,4 @@ tickTime=2000
 initLimit=10
 syncLimit=5
 dataDir=data
-clientPort=2181
+clientPort=2181
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
----------------------------------------------------------------------
diff --git a/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
b/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
index 8d64046..b7a8104 100644
--- a/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
+++ b/modules/gfac/airavata-gfac-service/src/test/java/org/apache/airavata/gfac/client/GfacClientFactoryTest.java
@@ -27,26 +27,39 @@ import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
 import org.apache.airavata.client.tools.DocumentCreator;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.AiravataZKUtils;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.gfac.client.util.Initialize;
 import org.apache.airavata.gfac.cpi.GfacService;
 import org.apache.airavata.gfac.server.GfacServer;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.Registry;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URL;
 
 public class GfacClientFactoryTest {
+    private final static Logger logger = LoggerFactory.getLogger(GfacClientFactoryTest.class);
     private DocumentCreator documentCreator;
     private GfacService.Client gfacClient;
     private Registry registry;
     private int NUM_CONCURRENT_REQUESTS = 1;
     Initialize initialize;
     GfacServer service;
+    private static ServerCnxnFactory cnxnFactory;
+
     @Test
     public void setUp() {
     	AiravataUtils.setExecutionAsServer();
         initialize = new Initialize("registry-derby.sql");
         initialize.initializeDB();
+        AiravataZKUtils.startEmbeddedZK(cnxnFactory);
         try {
             service = (new GfacServer());
             service.start();
@@ -60,6 +73,7 @@ public class GfacClientFactoryTest {
 
         try {
             service.stop();
+            cnxnFactory.shutdown();
         } catch (Exception e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
         }
@@ -83,4 +97,6 @@ public class GfacClientFactoryTest {
     private void storeDescriptors() {
 
     }
+
+
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/gfac/airavata-gfac-service/src/test/resources/zoo.cfg
----------------------------------------------------------------------
diff --git a/modules/gfac/airavata-gfac-service/src/test/resources/zoo.cfg b/modules/gfac/airavata-gfac-service/src/test/resources/zoo.cfg
new file mode 100644
index 0000000..d65a3bc
--- /dev/null
+++ b/modules/gfac/airavata-gfac-service/src/test/resources/zoo.cfg
@@ -0,0 +1,5 @@
+tickTime=2000
+initLimit=10
+syncLimit=5
+dataDir=data
+clientPort=2181
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/monitor/GfacInternalStatusUpdator.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/monitor/GfacInternalStatusUpdator.java
b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/monitor/GfacInternalStatusUpdator.java
index 870ba26..dcef46f 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/monitor/GfacInternalStatusUpdator.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/monitor/GfacInternalStatusUpdator.java
@@ -57,8 +57,7 @@ public class GfacInternalStatusUpdator implements AbstractActivityListener,
Watc
         Stat exists = null;
         try {
             if (!zk.getState().isConnected()) {
-                String zkhostPort = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_HOST)
-                        + ":" + ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_PORT);
+                String zkhostPort = AiravataZKUtils.getZKhostPort();
                 zk = new ZooKeeper(zkhostPort, 6000, this);
                 synchronized (mutex){
                     mutex.wait();

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorRecoveryHandler.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorRecoveryHandler.java
b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorRecoveryHandler.java
index 4d8b7c4..5f3c263 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorRecoveryHandler.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorRecoveryHandler.java
@@ -21,6 +21,7 @@
 package org.apache.airavata.orchestrator.util;
 
 import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataZKUtils;
 import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.orchestrator.core.exception.OrchestratorException;
@@ -67,8 +68,7 @@ public class OrchestratorRecoveryHandler implements Watcher {
      * @throws InterruptedException
      */
     public void recover() throws OrchestratorException, ApplicationSettingsException, IOException,
KeeperException, InterruptedException {
-        String zkhostPort = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_HOST)
-                + ":" + ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_PORT);
+        String zkhostPort = AiravataZKUtils.getZKhostPort();
         zk = new ZooKeeper(zkhostPort, 6000, this);
         synchronized (mutex) {
             mutex.wait();

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
index 67b72f2..26eab03 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
@@ -27,12 +27,15 @@ import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
 import org.apache.airavata.client.tools.DocumentCreator;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.AiravataZKUtils;
+import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.orchestrator.client.util.Initialize;
 import org.apache.airavata.orchestrator.cpi.OrchestratorService;
 import org.apache.airavata.orchestrator.server.OrchestratorServer;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.Registry;
+import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.junit.Test;
 
 public class OrchestratorClientFactoryTest {
@@ -42,11 +45,16 @@ public class OrchestratorClientFactoryTest {
     private int NUM_CONCURRENT_REQUESTS = 1;
     Initialize initialize;
     OrchestratorServer service;
+    private static ServerCnxnFactory cnxnFactory;
+
     @Test
     public void setUp() {
     	AiravataUtils.setExecutionAsServer();
         initialize = new Initialize("registry-derby.sql");
         initialize.initializeDB();
+        System.setProperty(Constants.ZOOKEEPER_SERVER_PORT,"2185");
+        AiravataZKUtils.startEmbeddedZK(cnxnFactory);
+
         try {
             service = (new OrchestratorServer());
             service.start();

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/orchestrator/airavata-orchestrator-service/src/test/resources/zoo.cfg
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/test/resources/zoo.cfg
b/modules/orchestrator/airavata-orchestrator-service/src/test/resources/zoo.cfg
new file mode 100644
index 0000000..393de1d
--- /dev/null
+++ b/modules/orchestrator/airavata-orchestrator-service/src/test/resources/zoo.cfg
@@ -0,0 +1,5 @@
+tickTime=2000
+initLimit=10
+syncLimit=5
+dataDir=data
+clientPort=2185
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
index 7bc3c56..9f4eea8 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Random;
 
 import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataZKUtils;
 import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.gfac.core.utils.GFacUtils;
@@ -75,8 +76,7 @@ public class GFACServiceJobSubmitter implements JobSubmitter, Watcher {
         ZooKeeper zk = orchestratorContext.getZk();
         try {
             if (zk==null || !zk.getState().isConnected()) {
-                String zkhostPort = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_HOST)
-                        + ":" + ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ZOOKEEPER_SERVER_PORT);
+                String zkhostPort = AiravataZKUtils.getZKhostPort();
                 zk = new ZooKeeper(zkhostPort, 6000, this);
                 synchronized (mutex) {
                     mutex.wait();

http://git-wip-us.apache.org/repos/asf/airavata/blob/7d07911c/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
index 03787af..6aca971 100644
--- a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
+++ b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
@@ -29,18 +29,13 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.*;
 import org.apache.airavata.common.utils.ApplicationSettings.ShutdownStrategy;
-import org.apache.airavata.common.utils.IServer;
 import org.apache.airavata.common.utils.IServer.ServerStatus;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.common.utils.StringUtil;
 import org.apache.airavata.common.utils.StringUtil.CommandLineParameters;
 import org.apache.commons.cli.ParseException;
 import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -131,74 +126,15 @@ public class ServerMain {
         if (commandLineParameters.getArguments().contains(STOP_COMMAND_STR)){
             performServerStopRequest(commandLineParameters);
         }else{
-            if (ServerSettings.isEmbeddedZK()) {
-                ServerConfig serverConfig = new ServerConfig();
-                URL resource = ServerMain.class.getClassLoader().getResource("zoo.cfg");
-                if (resource == null) {
-                    logger.error("There is no zoo.cfg file in the classpath... Failed to
start Zookeeper Server");
-                    System.exit(1);
-                }
-                try {
-                    serverConfig.parse(resource.getPath());
-                } catch (QuorumPeerConfig.ConfigException e) {
-                    logger.error("Error while starting embedded Zookeeper", e);
-                    System.exit(2);
-                }
-
-                final ServerConfig fServerConfig = serverConfig;
-                (new Thread() {
-                    public void run() {
-                        try {
-                            runZKFromConfig(fServerConfig);
-                        } catch (IOException e) {
-                            logger.error("Error while starting embedded Zookeeper", e);
-                            System.exit(3);
-                        }
-                    }
-                }).start();
-            }else{
-                logger.info("Skipping Zookeeper embedded startup ...");
-            }
+            AiravataZKUtils.startEmbeddedZK(cnxnFactory);
             performServerStart(args);
 		}
 
     }
 
-    private static void runZKFromConfig(ServerConfig config) throws IOException {
-        logger.info("Starting Zookeeper server...");
-        FileTxnSnapLog txnLog = null;
-        try {
-            // Note that this thread isn't going to be doing anything else,
-            // so rather than spawning another thread, we will just call
-            // run() in this thread.
-            // create a file logger url from the command line args
-            ZooKeeperServer zkServer = new ZooKeeperServer();
 
-            txnLog = new FileTxnSnapLog(new File(config.getDataDir()), new File(
-                    config.getDataDir()));
-            zkServer.setTxnLogFactory(txnLog);
-            zkServer.setTickTime(config.getTickTime());
-            zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
-            zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
-            cnxnFactory = ServerCnxnFactory.createFactory();
-            cnxnFactory.configure(config.getClientPortAddress(),
-                    config.getMaxClientCnxns());
-            cnxnFactory.startup(zkServer);
-            cnxnFactory.join();
-            if (zkServer.isRunning()) {
-                zkServer.shutdown();
-            }
-        } catch (InterruptedException e) {
-            // warn, but generally this is ok
-            logger.warn("Server interrupted", e);
-            System.exit(1);
-        } finally {
-            if (txnLog != null) {
-                txnLog.close();
-            }
-        }
-    }
-	private static void performServerStart(String[] args) {
+
+    private static void performServerStart(String[] args) {
 		setServerStarted();
 		logger.info("Airavata server instance starting...");
 		ServerSettings.mergeSettingsCommandLineArgs(args);


Mime
View raw message