You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/03/05 02:27:16 UTC

git commit: https://issues.apache.org/jira/browse/AIRAVATA-1046

Repository: airavata
Updated Branches:
  refs/heads/master 893156a89 -> edd26be83


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/edd26be8
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/edd26be8
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/edd26be8

Branch: refs/heads/master
Commit: edd26be83e91048e103b222a07dd1c84b6a87f40
Parents: 893156a
Author: Saminda Wijeratne <sa...@gmail.com>
Authored: Tue Mar 4 20:26:59 2014 -0500
Committer: Saminda Wijeratne <sa...@gmail.com>
Committed: Tue Mar 4 20:26:59 2014 -0500

----------------------------------------------------------------------
 .../airavata/api/server/AiravataAPIServer.java  |  84 ++++++++--
 .../api/server/util/RegistryInitUtil.java       |  15 ++
 .../orchestrator/server/OrchestratorServer.java |  73 +++++++--
 modules/server/pom.xml                          |  52 +-----
 .../org/apache/airavata/server/ServerMain.java  | 164 ++++++-------------
 pom.xml                                         |   2 +-
 6 files changed, 207 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/edd26be8/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 886b2f7..68bdd03 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
@@ -27,6 +27,7 @@ import org.apache.airavata.api.error.AiravataSystemException;
 import org.apache.airavata.api.server.handler.AiravataServerHandler;
 import org.apache.airavata.api.server.util.RegistryInitUtil;
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.IServer;
 import org.apache.thrift.server.TServer;
 import org.apache.thrift.server.TSimpleServer;
 import org.apache.thrift.transport.TServerSocket;
@@ -35,38 +36,99 @@ import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class AiravataAPIServer {
+public class AiravataAPIServer implements IServer{
 
     private final static Logger logger = LoggerFactory.getLogger(AiravataAPIServer.class);
 
     //FIXME: Read the port from airavata-server.config file
     private static final int THRIFT_SERVER_PORT = 8930;
+    private ServerStatus status;
 
+	private TSimpleServer server;
 
-    public static void StartAiravataServer(Airavata.Processor<AiravataServerHandler> mockAiravataServer) throws AiravataSystemException {
+	public AiravataAPIServer() {
+		setStatus(ServerStatus.STOPPED);
+	}
+	
+    public void StartAiravataServer(Airavata.Processor<AiravataServerHandler> mockAiravataServer) throws AiravataSystemException {
         try {
             AiravataUtils.setExecutionAsServer();
             RegistryInitUtil.initializeDB();
             TServerTransport serverTransport = new TServerSocket(THRIFT_SERVER_PORT);
-            TServer server = new TSimpleServer(
+            server = new TSimpleServer(
                     new TServer.Args(serverTransport).processor(mockAiravataServer));
             logger.info("Starting Airavata Mock Airavata Server on Port " + THRIFT_SERVER_PORT);
             logger.info("Listening to Airavata Clients ....");
-            server.serve();
+            new Thread() {
+				public void run() {
+					server.serve();
+					RegistryInitUtil.stopDerbyInServerMode();
+				}
+			}.start();
+			setStatus(ServerStatus.STARTED);
         } catch (TTransportException e) {
             logger.error(e.getMessage());
+            setStatus(ServerStatus.FAILED);
+            RegistryInitUtil.stopDerbyInServerMode();
             throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
         }
     }
 
     public static void main(String[] args) {
-        Airavata.Processor<AiravataServerHandler> mockAiravataServer =
-                new Airavata.Processor<AiravataServerHandler>(new AiravataServerHandler());
-        try {
-            StartAiravataServer(mockAiravataServer);
-        } catch (AiravataSystemException e) {
-            e.printStackTrace();
-        }
+    	try {
+			AiravataAPIServer server = new AiravataAPIServer();
+			server.start();
+//			System.out.println(server.getStatus()+":"+server.getStatus().getTime());
+//			Thread.sleep(3000);
+//			server.stop();
+//			System.out.println(server.getStatus()+":"+server.getStatus().getTime());
+//			Thread.sleep(3000);
+//			server.start();
+//			System.out.println(server.getStatus()+":"+server.getStatus().getTime());
+//			Thread.sleep(3000);
+//			server.stop();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
     }
 
+	@Override
+	public void start() throws Exception {
+		setStatus(ServerStatus.STARTING);
+		Airavata.Processor<AiravataServerHandler> mockAiravataServer =
+                new Airavata.Processor<AiravataServerHandler>(new AiravataServerHandler());
+    	StartAiravataServer(mockAiravataServer);
+	}
+
+	@Override
+	public void stop() throws Exception {
+		if (server.isServing()){
+			server.stop();
+			setStatus(ServerStatus.STOPPED);
+			logger.info("Airavata API Server Stopped.");
+		}
+		
+	}
+
+	@Override
+	public void restart() throws Exception {
+		stop();
+		start();
+	}
+
+	@Override
+	public void configure() throws Exception {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public ServerStatus getStatus() throws Exception {
+		return status;
+	}
+	
+	private void setStatus(ServerStatus stat){
+		status=stat;
+		status.updateTime();
+	}
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/edd26be8/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/RegistryInitUtil.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/RegistryInitUtil.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/RegistryInitUtil.java
index 5d45e3c..2cb9c78 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/RegistryInitUtil.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/util/RegistryInitUtil.java
@@ -157,6 +157,21 @@ public class RegistryInitUtil {
                     "specified port is available");
         }
     }
+    
+    public static void stopDerbyInServerMode() {
+        try {
+            System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "false");
+            if (server!=null){
+            	server.shutdown();
+            }
+        } catch (IOException e) {
+            logger.error("Unable to start Apache derby in the server mode! Check whether " +
+                    "specified port is available");
+        } catch (Exception e) {
+            logger.error("Unable to start Apache derby in the server mode! Check whether " +
+                    "specified port is available");
+        }
+    }
 
     public static int getPort(String jdbcURL){
         try{

http://git-wip-us.apache.org/repos/asf/airavata/blob/edd26be8/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 fba9c05..a333bcf 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
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.orchestrator.server;
 
+import org.apache.airavata.common.utils.IServer;
 import org.apache.airavata.orchestrator.cpi.OrchestratorService;
 import org.apache.thrift.server.TServer;
 import org.apache.thrift.server.TSimpleServer;
@@ -30,39 +31,87 @@ import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class OrchestratorServer {
+public class OrchestratorServer implements IServer{
 
     private final static Logger logger = LoggerFactory.getLogger(OrchestratorServer.class);
 
     //FIXME: Read the port from airavata-server.config file
     private static final int ORCHESTRATOT_SERVER_PORT = 8940;
+    private ServerStatus status;
 
-    public static final String TESTARGUMENTTOHANDLER = "testing";
+	private TSimpleServer server;
 
+    public static final String TESTARGUMENTTOHANDLER = "testing";
+	public OrchestratorServer() {
+		setStatus(ServerStatus.STOPPED);
+	}
 
-    public static void StartOrchestratorServer(OrchestratorService.Processor<OrchestratorServerHandler> orchestratorServerHandlerProcessor)
+    public void StartOrchestratorServer(OrchestratorService.Processor<OrchestratorServerHandler> orchestratorServerHandlerProcessor)
             throws Exception {
         try {
             TServerTransport serverTransport = new TServerSocket(ORCHESTRATOT_SERVER_PORT);
-            TServer server = new TSimpleServer(
+            server = new TSimpleServer(
                     new TServer.Args(serverTransport).processor(orchestratorServerHandlerProcessor));
             logger.info("Starting Orchestrator Server on Port " + ORCHESTRATOT_SERVER_PORT);
             logger.info("Listening to Orchestrator Clients ....");
-            server.serve();
+            new Thread() {
+				public void run() {
+					server.serve();
+				}
+			}.start();
+			setStatus(ServerStatus.STARTED);
         } catch (TTransportException e) {
             logger.error(e.getMessage());
+            setStatus(ServerStatus.FAILED);
         }
     }
 
     public static void main(String[] args) {
-        OrchestratorService.Processor<OrchestratorServerHandler> orchestratorServerHandlerProcessor =
-                new OrchestratorService.Processor<OrchestratorServerHandler>(new OrchestratorServerHandler());
-        try {
-            StartOrchestratorServer(orchestratorServerHandlerProcessor);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    	try {
+			new OrchestratorServer().start();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
     }
 
+	@Override
+	public void start() throws Exception {
+		setStatus(ServerStatus.STARTING);
+		OrchestratorService.Processor<OrchestratorServerHandler> mockAiravataServer =
+                new OrchestratorService.Processor<OrchestratorServerHandler>(new OrchestratorServerHandler());
+		StartOrchestratorServer(mockAiravataServer);
+	}
+
+	@Override
+	public void stop() throws Exception {
+		if (server.isServing()){
+			server.stop();
+			setStatus(ServerStatus.STOPPED);
+			logger.info("Orchestrator Server Stopped.");
+		}
+		
+	}
+
+	@Override
+	public void restart() throws Exception {
+		stop();
+		start();
+	}
+
+	@Override
+	public void configure() throws Exception {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public ServerStatus getStatus() throws Exception {
+		return status;
+	}
+	
+	private void setStatus(ServerStatus stat){
+		status=stat;
+		status.updateTime();
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/edd26be8/modules/server/pom.xml
----------------------------------------------------------------------
diff --git a/modules/server/pom.xml b/modules/server/pom.xml
index 6356da1..a2cfdee 100644
--- a/modules/server/pom.xml
+++ b/modules/server/pom.xml
@@ -17,32 +17,11 @@
     </parent>
 
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>airavata-embedded-tomcat</artifactId>
-    <name>Airavata Embedded Tomcat Implementation</name>
-    <description>Module for starting embedded tomcat</description>
+    <artifactId>airavata-standalone-server</artifactId>
+    <name>Airavata Standalone Server</name>
+    <description>Module Containing Classes which start the Airavata Standalone Server</description>
     <dependencies>
         <dependency>
-            <groupId>org.apache.tomcat.embed</groupId>
-            <artifactId>tomcat-embed-core</artifactId>
-            <version>7.0.22</version>
-        </dependency>
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>javax.servlet-api</artifactId>
-            <version>3.0.1</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat.embed</groupId>
-            <artifactId>tomcat-embed-logging-juli</artifactId>
-            <version>7.0.22</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat.embed</groupId>
-            <artifactId>tomcat-embed-jasper</artifactId>
-            <version>7.0.22</version>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
@@ -61,30 +40,15 @@
             <artifactId>airavata-common-utils</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat</groupId>
-            <artifactId>tomcat-jasper</artifactId>
-            <version>7.0.22</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat</groupId>
-            <artifactId>tomcat-jasper-el</artifactId>
-            <version>7.0.22</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tomcat</groupId>
-            <artifactId>tomcat-jsp-api</artifactId>
-            <version>7.0.22</version>
-        </dependency>
-        <dependency>
+		<dependency>
             <groupId>org.apache.airavata</groupId>
-            <artifactId>airavata-rest-mappings</artifactId>
+            <artifactId>airavata-orchestrator-service</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.ebaysf.web</groupId>
-            <artifactId>cors-filter</artifactId>
-            <version>${ebay.cors.filter}</version>
+            <groupId>org.apache.airavata</groupId>
+            <artifactId>airavata-api-server</artifactId>
+            <version>${project.version}</version>
         </dependency>
     </dependencies>
     

http://git-wip-us.apache.org/repos/asf/airavata/blob/edd26be8/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 a855c30..fc79645 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
@@ -17,128 +17,62 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 package org.apache.airavata.server;
 
-import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 
-import org.apache.airavata.common.utils.AiravataUtils;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.catalina.Wrapper;
-import org.apache.catalina.core.StandardContext;
-import org.apache.catalina.deploy.FilterDef;
-import org.apache.catalina.deploy.FilterMap;
-import org.apache.catalina.startup.Tomcat;
+import org.apache.airavata.api.server.AiravataAPIServer;
+import org.apache.airavata.common.utils.IServer;
+import org.apache.airavata.orchestrator.server.OrchestratorServer;
 
 public class ServerMain {
+	private static List<IServer> servers;
 
-    private Tomcat embedded = null;
-    /**
-     * Default Constructor
-     */
-    public ServerMain() {
-    }
+	static {
+		servers = new ArrayList<IServer>();
+		servers.add(new AiravataAPIServer());
+		servers.add(new OrchestratorServer());
+	}
 
+	public static void main(String args[]) {
+		new Thread() {
+			public void run() {
+				startAllServers();
+			}
+		}.start();
+		Runtime.getRuntime().addShutdownHook(new Thread() {
+			public void run() {
+				stopAllServers();
+			}
+		});
+		try {
+			while (true) {
+				Thread.sleep(10000);
+			}
+		} catch (InterruptedException e) {
+			stopAllServers();
+		}
+	}
 
-    /**
-     * This method Starts the Tomcat server.
-     */
-    public void startTomcat() throws Exception {
-        AiravataUtils.setExecutionAsServer();
-        String protocol = ServerSettings.isEnableHttps() ? "https" : "http";
-        BetterTomcat tomcat = new BetterTomcat(Integer.parseInt(ServerSettings.getTomcatPort(protocol)));
-        tomcat.addContext("/airavata-server", System.getenv("AIRAVATA_HOME"));
-        Wrapper axis2Servlet = tomcat.addServlet("/airavata-server", "AxisServlet", "org.apache.axis2.transport.http.AxisServlet");
-        axis2Servlet.addMapping("/servlet/AxisServlet");
-        axis2Servlet.addMapping("*.jws");
-        axis2Servlet.addMapping("/services/*");
-        axis2Servlet.addInitParameter("axis2.repository.path",System.getenv("AIRAVATA_HOME") + File.separator + "repository");
-        axis2Servlet.addInitParameter("axis2.xml.path", System.getenv("AIRAVATA_HOME") +
-                File.separator + "bin" + File.separator + "axis2.xml");
-        axis2Servlet.setLoadOnStartup(1);
+	private static void stopAllServers() {
+		for (IServer server : servers) {
+			try {
+				server.stop();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
 
-        StandardContext context = (StandardContext)tomcat.getTomcat().addContext("/airavata", System.getenv("AIRAVATA_HOME"));
-        Wrapper experimentServlet = tomcat.addServlet("/airavata", "Airavata Experiment Service", "com.sun.jersey.spi.container.servlet.ServletContainer");
-        experimentServlet.addInitParameter("com.sun.jersey.config.property.packages", "org.apache.airavata.services.experiment;org.codehaus.jackson.jaxrs");
-        experimentServlet.setLoadOnStartup(1);
-        
-        Wrapper configurationServlet = tomcat.addServlet("/airavata", "Airavata Server Configuration Service", "com.sun.jersey.spi.container.servlet.ServletContainer");
-        configurationServlet.addInitParameter("com.sun.jersey.config.property.packages", "org.apache.airavata.services.server;org.codehaus.jackson.jaxrs");
-        configurationServlet.setLoadOnStartup(1);
-        
-        Wrapper registryServlet = tomcat.addServlet("/airavata", "Airavata Registry Service", "com.sun.jersey.spi.container.servlet.ServletContainer");
-        registryServlet.addInitParameter("com.sun.jersey.config.property.packages", "org.apache.airavata.services.registry.rest;org.codehaus.jackson.jaxrs");
-        registryServlet.setLoadOnStartup(1);
-        
-        FilterDef corsFilter = new FilterDef();
-        corsFilter.setFilterName("CORS Filter");
-        corsFilter.setFilterClass("org.ebaysf.web.cors.CORSFilter");
-        corsFilter.addInitParameter("cors.allowed.origins","*");
-        corsFilter.addInitParameter("cors.allowed.methods","GET,POST,HEAD,PUT,OPTIONS");
-        corsFilter.addInitParameter("cors.allowed.headers","Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization");
-        corsFilter.addInitParameter("cors.exposed.headers","");
-        corsFilter.addInitParameter("cors.preflight.maxage","1800");
-        corsFilter.addInitParameter("cors.support.credentials","true");
-        corsFilter.addInitParameter("cors.logging.enabled","false");
-        corsFilter.addInitParameter("cors.request.decorate","true");
-        context.addFilterDef(corsFilter);
-
-        FilterDef filter1definition = new FilterDef();
-        filter1definition.setFilterName("AuthenticationFilter");
-        filter1definition.setFilterClass("org.apache.airavata.services.registry.rest.security.HttpAuthenticatorFilter");
-        filter1definition.addInitParameter("authenticatorConfigurations","authenticators.xml");
-        context.addFilterDef(filter1definition);
-        
-        FilterMap corsFilterMapping = new FilterMap();
-        corsFilterMapping.setFilterName("CORS Filter");
-        corsFilterMapping.addURLPattern("/user-store/*");
-        corsFilterMapping.addURLPattern("/services/registry/*");
-        corsFilterMapping.addURLPattern("/services/server/*");
-        corsFilterMapping.addURLPattern("/services/experiment/*");
-        context.addFilterMap(corsFilterMapping);
-
-        FilterMap filter1mapping = new FilterMap();
-        filter1mapping.setFilterName("AuthenticationFilter");
-        filter1mapping.addURLPattern("/user-store/*");
-        filter1mapping.addURLPattern("/services/registry/*");
-        filter1mapping.addURLPattern("/services/server/*");
-        filter1mapping.addURLPattern("/services/experiment/*");
-        context.addFilterMap(filter1mapping);
-        registryServlet.addMapping("/services/registry/*");
-        configurationServlet.addMapping("/services/server/*");
-        experimentServlet.addMapping("/services/experiment/*");
-        context.addApplicationListener("org.apache.airavata.rest.mappings.utils.RegistryListener");
-
-        tomcat.start();
-    }
-
-    /**
-     * This method Stops the Tomcat server.
-     */
-    public void stopTomcat() throws Exception {
-        // Stop the embedded server
-        embedded.stop();
-    }
-
-
-    public static void main(String args[]) {
-        try {
-            new Thread(){
-                public void run(){
-                    ServerMain tomcat = new ServerMain();
-                    try {
-                        tomcat.startTomcat();
-                    } catch (Exception e) {
-                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-                    }
-                }
-            }.start();
-           while(true){
-               Thread.sleep(10000);
-           }
-        } catch (Exception e) {
-
-            e.printStackTrace();
-        }
-    }
+	private static void startAllServers() {
+		for (IServer server : servers) {
+			try {
+				server.start();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/edd26be8/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a2c3adb..a02cb37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -452,7 +452,7 @@
                 <module>modules/airavata-client</module>
                 <module>modules/security</module>
                 <module>modules/credential-store</module>
-                <module>modules/rest</module>
+                <!--module>modules/rest</module-->
                 <module>modules/orchestrator</module>
                 <module>tools</module>
                 <module>samples</module>