Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4B75211436 for ; Tue, 29 Jul 2014 17:30:35 +0000 (UTC) Received: (qmail 22399 invoked by uid 500); 29 Jul 2014 17:30:35 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 22361 invoked by uid 500); 29 Jul 2014 17:30:35 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 22350 invoked by uid 99); 29 Jul 2014 17:30:35 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jul 2014 17:30:35 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B91BE8217D4; Tue, 29 Jul 2014 17:30:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lahiru@apache.org To: commits@airavata.apache.org Message-Id: <9d22579642c64e6daf8d2b6241304e1a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: adding zk in embedded mode Date: Tue, 29 Jul 2014 17:30:34 +0000 (UTC) Repository: airavata Updated Branches: refs/heads/master 1a2411d2e -> aef99c061 adding zk in embedded mode Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/aef99c06 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/aef99c06 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/aef99c06 Branch: refs/heads/master Commit: aef99c061ec1b2f61f3d99f27182a43897f2ec2e Parents: 1a2411d Author: lahiru Authored: Tue Jul 29 13:30:18 2014 -0400 Committer: lahiru Committed: Tue Jul 29 13:30:18 2014 -0400 ---------------------------------------------------------------------- .../client/samples/CreateLaunchExperiment.java | 4 +- .../airavata/common/utils/ServerSettings.java | 4 + .../main/resources/airavata-server.properties | 2 +- .../server/src/main/resources/zoo.cfg | 5 + .../server/src/main/assembly/bin-assembly.xml | 1 + .../airavata/gfac/server/GfacServerHandler.java | 75 ++- .../gfac/ssh/security/TokenizedSSHAuthInfo.java | 2 +- .../gfac/services/impl/CredentialStoreTest.java | 36 +- modules/gfac/pom.xml | 1 + .../integration-tests/tomcat-distribution.iml | 656 ------------------- modules/server/pom.xml | 7 +- .../org/apache/airavata/server/ServerMain.java | 91 ++- 12 files changed, 161 insertions(+), 723 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java index 8d006ef..f00dc31 100644 --- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java +++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java @@ -82,10 +82,10 @@ public class CreateLaunchExperiment { //// final String expId = createExperimentForSSHHost(airavata); //// final String expId = createExperimentForTrestles(client); //// final String expId = createExperimentForStampede(client); -// final String expId = createExperimentForLocalHost(client); + final String expId = createExperimentForLocalHost(client); // final String expId = createExperimentForLonestar(airavata); // final String expId = createExperimentWRFTrestles(client); - final String expId = createExperimentForBR2(client); +// final String expId = createExperimentForBR2(client); // final String expId = createExperimentForBR2Amber(client); // final String expId = createExperimentWRFStampede(client); // final String expId = createExperimentForStampedeAmber(client); http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java ---------------------------------------------------------------------- diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java index 71e1437..93f3bc3 100644 --- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java +++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ServerSettings.java @@ -48,6 +48,7 @@ public class ServerSettings extends ApplicationSettings{ private static final String TOMCAT_PORT = "port"; private static final String SERVER_CONTEXT_ROOT="server.context-root"; + public static final String EMBEDDED_ZK = "embedded.zk"; private static String tomcatPort=null; private static final String CREDENTIAL_STORE_DB_URL ="credential.store.jdbc.url"; @@ -218,4 +219,7 @@ public class ServerSettings extends ApplicationSettings{ public static String[] getActivityListeners() throws ApplicationSettingsException { return getSetting(ACTIVITY_LISTENERS).split(","); } + public static boolean isEmbeddedZK() { + return Boolean.parseBoolean(getSetting(EMBEDDED_ZK, "true")); + } } http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/configuration/server/src/main/resources/airavata-server.properties ---------------------------------------------------------------------- diff --git a/modules/configuration/server/src/main/resources/airavata-server.properties b/modules/configuration/server/src/main/resources/airavata-server.properties index fbde207..743372d 100644 --- a/modules/configuration/server/src/main/resources/airavata-server.properties +++ b/modules/configuration/server/src/main/resources/airavata-server.properties @@ -247,7 +247,7 @@ gfac.server.port=8950 orchestrator.server.min.threads=50 ##----------------------------- Zookeeper Server Configurations ----------------------### - +embedded.zk=true zookeeper.server.host=localhost zookeeper.server.port=2181 airavata-server=/api-server http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/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 new file mode 100644 index 0000000..5a9ebe9 --- /dev/null +++ b/modules/configuration/server/src/main/resources/zoo.cfg @@ -0,0 +1,5 @@ +tickTime=2000 +initLimit=10 +syncLimit=5 +dataDir=data +clientPort=2181 http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/distribution/server/src/main/assembly/bin-assembly.xml ---------------------------------------------------------------------- diff --git a/modules/distribution/server/src/main/assembly/bin-assembly.xml b/modules/distribution/server/src/main/assembly/bin-assembly.xml index 75f941d..e84d7b9 100644 --- a/modules/distribution/server/src/main/assembly/bin-assembly.xml +++ b/modules/distribution/server/src/main/assembly/bin-assembly.xml @@ -106,6 +106,7 @@ bin airavata-server.properties + zoo.cfg registry.properties log4j.properties host.xml http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java ---------------------------------------------------------------------- diff --git a/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java b/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java index 6f3247c..b098120 100644 --- a/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java +++ b/modules/gfac/airavata-gfac-service/src/main/java/org/apache/airavata/gfac/server/GfacServerHandler.java @@ -73,47 +73,26 @@ public class GfacServerHandler implements GfacService.Iface, Watcher{ private MonitorPublisher publisher; + private String gfacServer; + + private String gfacExperiments; + + private String airavataServerHostPort; public GfacServerHandler() { // registering with zk try { String zkhostPort = AiravataZKUtils.getZKhostPort(); - String airavataServerHostPort = ServerSettings.getSetting(Constants.GFAC_SERVER_HOST) + airavataServerHostPort = ServerSettings.getSetting(Constants.GFAC_SERVER_HOST) + ":" + ServerSettings.getSetting(Constants.GFAC_SERVER_PORT); try { zk = new ZooKeeper(zkhostPort, 6000, this); // no watcher is required, this will only use to store some data - String gfacServer = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NODE,"/gfac-server"); - String gfacExperiments = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_EXPERIMENT_NODE,"/gfac-experiments"); + gfacServer = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NODE,"/gfac-server"); + gfacExperiments = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_EXPERIMENT_NODE,"/gfac-experiments"); synchronized(mutex){ mutex.wait(); // waiting for the syncConnected event } - Stat zkStat = zk.exists(gfacServer, false); - if (zkStat == null) { - zk.create(gfacServer, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - } - String instanceId = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NAME); - String instantNode = gfacServer + File.separator + instanceId; - zkStat = zk.exists(instantNode, false); - if (zkStat == null) { - zk.create(instantNode, - airavataServerHostPort.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.EPHEMERAL); // other component will watch these childeren creation deletion to monitor the status of the node - } - zkStat = zk.exists(gfacExperiments, false); - if (zkStat == null) { - zk.create(gfacExperiments, - airavataServerHostPort.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - } - zkStat = zk.exists(gfacExperiments + File.separator + instanceId, false); - if (zkStat == null) { - zk.create(gfacExperiments + File.separator + instanceId, - airavataServerHostPort.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, - CreateMode.PERSISTENT); - }else{ - logger.error(" Zookeeper is inconsistent state !!!!!"); - } + storeServerConfig(); logger.info("Finished starting ZK: " + zk); } catch (IOException e) { e.printStackTrace(); @@ -137,9 +116,40 @@ public class GfacServerHandler implements GfacService.Iface, Watcher{ } } + private void storeServerConfig() throws KeeperException, InterruptedException, ApplicationSettingsException { + Stat zkStat = zk.exists(gfacServer, false); + if (zkStat == null) { + zk.create(gfacServer, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + String instanceId = ServerSettings.getSetting(Constants.ZOOKEEPER_GFAC_SERVER_NAME); + String instantNode = gfacServer + File.separator + instanceId; + zkStat = zk.exists(instantNode, false); + if (zkStat == null) { + zk.create(instantNode, + airavataServerHostPort.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.EPHEMERAL); // other component will watch these childeren creation deletion to monitor the status of the node + } + zkStat = zk.exists(gfacExperiments, false); + if (zkStat == null) { + zk.create(gfacExperiments, + airavataServerHostPort.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + } + zkStat = zk.exists(gfacExperiments + File.separator + instanceId, false); + if (zkStat == null) { + zk.create(gfacExperiments + File.separator + instanceId, + airavataServerHostPort.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, + CreateMode.PERSISTENT); + }else{ + logger.error(" Zookeeper is inconsistent state !!!!!"); + } + } + synchronized public void process(WatchedEvent watchedEvent) { synchronized (mutex) { Event.KeeperState state = watchedEvent.getState(); + logger.info(state.name()); if (state == Event.KeeperState.SyncConnected) { mutex.notify(); connected = true; @@ -147,10 +157,15 @@ public class GfacServerHandler implements GfacService.Iface, Watcher{ state == Event.KeeperState.Disconnected){ try { zk = new ZooKeeper(AiravataZKUtils.getZKhostPort(),6000,this); + storeServerConfig(); } catch (IOException e) { e.printStackTrace(); } catch (ApplicationSettingsException e) { e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (KeeperException e) { + e.printStackTrace(); } } } http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/security/TokenizedSSHAuthInfo.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/security/TokenizedSSHAuthInfo.java b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/security/TokenizedSSHAuthInfo.java index afa43f5..9e3fc58 100644 --- a/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/security/TokenizedSSHAuthInfo.java +++ b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/security/TokenizedSSHAuthInfo.java @@ -84,7 +84,7 @@ public class TokenizedSSHAuthInfo implements SSHPublicKeyFileAuthentication { gssCredentials = getCredentialsFromStore(); } catch (Exception e) { log.error("An exception occurred while retrieving credentials from the credential store. " + - "Will continue with my proxy user name and password. Provided TokenId:" + requestData.getTokenId(), e); + "Will continue with my proxy user name and password. Provided TokenId:" + requestData.getTokenId() + e.getMessage(), e); } if (gssCredentials == null) { http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/CredentialStoreTest.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/CredentialStoreTest.java b/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/CredentialStoreTest.java index 5398885..8b3653a 100644 --- a/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/CredentialStoreTest.java +++ b/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/CredentialStoreTest.java @@ -65,46 +65,36 @@ public class CredentialStoreTest { System.setProperty("myproxy.username", "ogce"); System.setProperty("myproxy.password", "OpenGwy14"); System.setProperty("trusted.cert.location", "/Users/lahirugunathilake/Downloads/certificates"); - System.setProperty("credential.store.jdbc.url","jdbc:mysql://gw85.iu.xsede.org:3306/airavata_pga_prod"); - System.setProperty("credential.store.jdbc.user","pgaAiravataUser"); - System.setProperty("credential.store.jdbc.password","pgaAiravataPWD"); + System.setProperty("credential.store.jdbc.url","jdbc:mysql://gw85.iu.xsede.org:3306/airavata_gta_prod"); + System.setProperty("credential.store.jdbc.user","gtaAiravataUser"); + System.setProperty("credential.store.jdbc.password","gtaAiravataPWD"); System.setProperty("credential.store.jdbc.driver","com.mysql.jdbc.Driver"); - try { - AiravataRegistry2 registry = AiravataRegistryFactory.getRegistry(new Gateway("default"), - new AiravataUser("admin")); + UUID uuid = UUID.randomUUID(); System.out.println("TokenId: " + uuid.toString()); - String publicKey = registry.createCredential("default",uuid.toString(),"lginnali" ); - System.out.println("Public-Key: " +publicKey); - String tokenId = uuid.toString(); -// String tokenId = "2c308fa9-99f8-4baa-92e4-d062e311483c"; - CredentialReader credentialReader = new CredentialReaderImpl(new DBUtil("jdbc:mysql://gw85.iu.xsede.org:3306/airavata_pga_prod", - "pgaAiravataUser", "pgaAiravataPWD", "com.mysql.jdbc.Driver")); +// String publicKey = registry.createCredential("default",uuid.toString(),"lginnali" ); +// System.out.println("Public-Key: " +publicKey); +// String tokenId = uuid.toString(); + String tokenId = "2c308fa9-99f8-4baa-92e4-d062e311483c"; + CredentialReader credentialReader = new CredentialReaderImpl(new DBUtil("jdbc:mysql://gw85.iu.xsede.org:3306/airavata_gta_prod", + "ptaAiravataUser", "ptaAiravataPWD", "com.mysql.jdbc.Driver")); RequestData requestData = new RequestData(); - requestData.setMyProxyUserName("lginnali"); + requestData.setMyProxyUserName("cgateway"); requestData.setTokenId(tokenId); requestData.setGatewayId("default"); TokenizedSSHAuthInfo tokenizedSSHAuthInfo = new TokenizedSSHAuthInfo(credentialReader, requestData); SSHCredential credentials = tokenizedSSHAuthInfo.getCredentials(); - ServerInfo serverInfo = new ServerInfo("lginnali", "bigred2.uits.iu.edu"); + ServerInfo serverInfo = new ServerInfo("cgateway", "bigred2.uits.iu.edu"); PBSCluster pbsCluster = new PBSCluster(serverInfo, tokenizedSSHAuthInfo, CommonUtils.getPBSJobManager("/opt/torque/bin/")); Assert.assertNotNull(pbsCluster); return; - } catch (RegAccessorInvalidException e) { - e.printStackTrace(); - } catch (RegAccessorInstantiateException e) { - e.printStackTrace(); - } catch (RegException e) { - e.printStackTrace(); - } catch (AiravataConfigurationException e) { - e.printStackTrace(); - } + } @Test http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/gfac/pom.xml ---------------------------------------------------------------------- diff --git a/modules/gfac/pom.xml b/modules/gfac/pom.xml index 9454661..ed3e27d 100644 --- a/modules/gfac/pom.xml +++ b/modules/gfac/pom.xml @@ -17,6 +17,7 @@ ../../pom.xml + 4.0.0 gfac pom http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/integration-tests/tomcat-distribution.iml ---------------------------------------------------------------------- diff --git a/modules/integration-tests/tomcat-distribution.iml b/modules/integration-tests/tomcat-distribution.iml deleted file mode 100644 index 55aff36..0000000 --- a/modules/integration-tests/tomcat-distribution.iml +++ /dev/null @@ -1,656 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/modules/server/pom.xml ---------------------------------------------------------------------- diff --git a/modules/server/pom.xml b/modules/server/pom.xml index dba1472..c09d6ec 100644 --- a/modules/server/pom.xml +++ b/modules/server/pom.xml @@ -50,10 +50,15 @@ airavata-api-server ${project.version} - + org.apache.airavata airavata-server-configuration ${project.version} + + org.apache.zookeeper + zookeeper + 3.4.0 + http://git-wip-us.apache.org/repos/asf/airavata/blob/aef99c06/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 1f14e8d..03787af 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 @@ -24,6 +24,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; +import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -36,6 +37,11 @@ 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; @@ -50,6 +56,7 @@ public class ServerMain { private static boolean systemShutDown=false; private static String STOP_COMMAND_STR = "stop"; + private static ServerCnxnFactory cnxnFactory; // private static boolean shutdownHookCalledBefore=false; static{ servers = new ArrayList(); @@ -118,16 +125,79 @@ public class ServerMain { // if (true){ // return; // } - - AiravataUtils.setExecutionAsServer(); - CommandLineParameters commandLineParameters = StringUtil.getCommandLineParser(args); - if (commandLineParameters.getArguments().contains(STOP_COMMAND_STR)){ - performServerStopRequest(commandLineParameters); - }else{ - performServerStart(args); + + AiravataUtils.setExecutionAsServer(); + CommandLineParameters commandLineParameters = StringUtil.getCommandLineParser(args); + 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 ..."); + } + 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) { setServerStarted(); logger.info("Airavata server instance starting..."); @@ -182,7 +252,10 @@ public class ServerMain { }else{ logger.error("Server"+(serverPID==-1? "":" instance "+serverPID)+" is not running!!!"); } - } + if (ServerSettings.isEmbeddedZK()) { + cnxnFactory.shutdown(); + } + } @SuppressWarnings("resource") private static void requestStop() throws IOException {