Repository: airavata Updated Branches: refs/heads/master 53acbbde5 -> 5b3c75f71
https://issues.apache.org/jira/browse/AIRAVATA-1046 Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/5b3c75f7 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/5b3c75f7 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/5b3c75f7 Branch: refs/heads/master Commit: 5b3c75f71d88ab70a8a80639e95e1d7ff21f8e85 Parents: 53acbbd Author: Saminda Wijeratne <[email protected]> Authored: Sun Mar 9 11:38:20 2014 -0400 Committer: Saminda Wijeratne <[email protected]> Committed: Sun Mar 9 11:38:20 2014 -0400 ---------------------------------------------------------------------- .../airavata/api/server/AiravataAPIServer.java | 15 +++++- .../apache/airavata/common/utils/IServer.java | 4 +- .../orchestrator/server/OrchestratorServer.java | 18 ++++++-- .../org/apache/airavata/server/ServerMain.java | 48 ++++++++++---------- 4 files changed, 53 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/5b3c75f7/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java index f3f9388..53f4696 100644 --- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java +++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/AiravataAPIServer.java @@ -98,6 +98,7 @@ public class AiravataAPIServer implements IServer{ @Override public void stop() throws Exception { if (server.isServing()){ + setStatus(ServerStatus.STOPING); server.stop(); } @@ -126,12 +127,22 @@ public class AiravataAPIServer implements IServer{ } @Override - public void waitForServerStart() throws Exception { + public void waitForServerToStart() throws Exception { while((getStatus()==ServerStatus.STARTING || getStatus()==ServerStatus.STARTED) && !server.isServing()){ Thread.sleep(100); } if (!(getStatus()==ServerStatus.STARTING || getStatus()==ServerStatus.STARTED)){ - throw new Exception("The server did not start!!!"); + throw new Exception("The Airavata API server did not start!!!"); + } + } + + @Override + public void waitForServerToStop() throws Exception { + while((getStatus()==ServerStatus.STOPING || getStatus()==ServerStatus.STOPPED) && server.isServing()){ + Thread.sleep(100); + } + if (!(getStatus()==ServerStatus.STOPING || getStatus()==ServerStatus.STOPPED)){ + throw new Exception("Error stopping the Airavata API server!!!"); } } } http://git-wip-us.apache.org/repos/asf/airavata/blob/5b3c75f7/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/IServer.java ---------------------------------------------------------------------- diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/IServer.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/IServer.java index 1187c98..361865f 100644 --- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/IServer.java +++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/IServer.java @@ -26,6 +26,7 @@ import java.util.Date; public interface IServer { public enum ServerStatus{ + STOPING, STOPPED, STARTING, STARTED, @@ -43,5 +44,6 @@ public interface IServer { public void restart() throws Exception; public void configure() throws Exception; public ServerStatus getStatus() throws Exception; - public void waitForServerStart() throws Exception; + public void waitForServerToStart() throws Exception; + public void waitForServerToStop() throws Exception; } http://git-wip-us.apache.org/repos/asf/airavata/blob/5b3c75f7/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java ---------------------------------------------------------------------- diff --git a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java index 0b8e676..dfff8a5 100644 --- a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java +++ b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServer.java @@ -23,7 +23,6 @@ package org.apache.airavata.orchestrator.server; import org.apache.airavata.common.utils.IServer; import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.common.utils.IServer.ServerStatus; import org.apache.airavata.orchestrator.cpi.OrchestratorService; import org.apache.airavata.orchestrator.util.Constants; import org.apache.thrift.server.TServer; @@ -88,7 +87,8 @@ public class OrchestratorServer implements IServer{ @Override public void stop() throws Exception { - if (server.isServing()){ + if (server!=null && server.isServing()){ + setStatus(ServerStatus.STOPING); server.stop(); } @@ -117,12 +117,22 @@ public class OrchestratorServer implements IServer{ } @Override - public void waitForServerStart() throws Exception { + public void waitForServerToStart() throws Exception { while((getStatus()==ServerStatus.STARTING || getStatus()==ServerStatus.STARTED) && !server.isServing()){ Thread.sleep(100); } if (!(getStatus()==ServerStatus.STARTING || getStatus()==ServerStatus.STARTED)){ - throw new Exception("The server did not start!!!"); + throw new Exception("The Orchestrator server did not start!!!"); + } + } + + @Override + public void waitForServerToStop() throws Exception { + while((getStatus()==ServerStatus.STOPING || getStatus()==ServerStatus.STOPPED) && server.isServing()){ + Thread.sleep(100); + } + if (!(getStatus()==ServerStatus.STOPING || getStatus()==ServerStatus.STOPPED)){ + throw new Exception("Error stopping the Orchestrator server!!!"); } } http://git-wip-us.apache.org/repos/asf/airavata/blob/5b3c75f7/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 3e8d18b..bc9a5dd 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 @@ -33,9 +33,13 @@ public class ServerMain { private static List<IServer> servers; private static final String SERVERS_KEY="servers"; private final static Logger logger = LoggerFactory.getLogger(ServerMain.class); - - private static void loadServers() { + private static boolean serversLoaded=false; + + static{ servers = new ArrayList<IServer>(); + } + + private static void loadServers() { try { String serversString = ServerSettings.getSetting(SERVERS_KEY); if (serversString!=null){ @@ -49,7 +53,7 @@ public class ServerMain { serverClassName); servers.add((IServer)classInstance.newInstance()); } catch (ClassNotFoundException e) { - logger.error("Error while initiating locating server implementation \""+serverString+"\"!!!",e); + logger.error("Error while locating server implementation \""+serverString+"\"!!!",e); } catch (InstantiationException e) { logger.error("Error while initiating server instance \""+serverString+"\"!!!",e); } catch (IllegalAccessException e) { @@ -62,45 +66,39 @@ public class ServerMain { } catch (ApplicationSettingsException e) { logger.error("Error while retrieving server list!!!",e); } - } - - public static void main(String args[]) { - ServerSettings.mergeSettingsCommandLineArgs(args); - loadServers(); - new Thread() { - public void run() { - startAllServers(); - } - }.start(); + serversLoaded=true; Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { stopAllServers(); } }); - try { - while (true) { - Thread.sleep(10000); - } - } catch (InterruptedException e) { - stopAllServers(); - } } - private static void stopAllServers() { - for (IServer server : servers) { + public static void main(String args[]) { + ServerSettings.mergeSettingsCommandLineArgs(args); + startAllServers(); + } + + public static void stopAllServers() { + //stopping should be done in reverse order of starting the servers + for(int i=servers.size()-1;i>=0;i--){ try { - server.stop(); + servers.get(i).stop(); + servers.get(i).waitForServerToStop(); } catch (Exception e) { e.printStackTrace(); } } } - private static void startAllServers() { + public static void startAllServers() { + if (!serversLoaded){ + loadServers(); + } for (IServer server : servers) { try { server.start(); - server.waitForServerStart(); + server.waitForServerToStart(); } catch (Exception e) { e.printStackTrace(); }
