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/08 17:11:13 UTC
[1/2] git commit: support overriding server settings via commandline
args https://issues.apache.org/jira/browse/AIRAVATA-1047
Repository: airavata
Updated Branches:
refs/heads/master afcd6e381 -> 708f6a483
support overriding server settings via commandline args https://issues.apache.org/jira/browse/AIRAVATA-1047
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/e54c7d05
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/e54c7d05
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/e54c7d05
Branch: refs/heads/master
Commit: e54c7d058150c86559c323f5248212570d6a3d45
Parents: 856da92
Author: Saminda Wijeratne <sa...@gmail.com>
Authored: Sat Mar 8 11:08:23 2014 -0500
Committer: Saminda Wijeratne <sa...@gmail.com>
Committed: Sat Mar 8 11:10:34 2014 -0500
----------------------------------------------------------------------
.../airavata/api/server/AiravataAPIServer.java | 2 +-
modules/commons/utils/pom.xml | 6 +-
.../common/utils/ApplicationSettings.java | 62 +++-
.../apache/airavata/server/BetterTomcat.java | 312 -------------------
.../airavata/server/BetterTomcatException.java | 40 ---
.../org/apache/airavata/server/ServerMain.java | 40 ++-
6 files changed, 90 insertions(+), 372 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/e54c7d05/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 ff51c0b..f3f9388 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
@@ -59,7 +59,7 @@ public class AiravataAPIServer implements IServer{
TServerTransport serverTransport = new TServerSocket(serverPort);
server = new TSimpleServer(
new TServer.Args(serverTransport).processor(mockAiravataServer));
- logger.info("Starting Airavata Mock Airavata Server on Port " + serverPort);
+ logger.info("Starting Airavata API Server on Port " + serverPort);
logger.info("Listening to Airavata Clients ....");
new Thread() {
public void run() {
http://git-wip-us.apache.org/repos/asf/airavata/blob/e54c7d05/modules/commons/utils/pom.xml
----------------------------------------------------------------------
diff --git a/modules/commons/utils/pom.xml b/modules/commons/utils/pom.xml
index ac0706f..7add7eb 100644
--- a/modules/commons/utils/pom.xml
+++ b/modules/commons/utils/pom.xml
@@ -96,7 +96,11 @@
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.22</version>
</dependency>
-
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
http://git-wip-us.apache.org/repos/asf/airavata/blob/e54c7d05/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
index c20dc32..715c7d2 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
@@ -22,10 +22,15 @@
package org.apache.airavata.common.utils;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.HashMap;
import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -34,6 +39,12 @@ import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.exception.ApplicationSettingsLoadException;
import org.apache.airavata.common.exception.ApplicationSettingsStoreException;
import org.apache.airavata.common.exception.UnspecifiedApplicationSettingsException;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -228,7 +239,54 @@ public abstract class ApplicationSettings {
return properties;
}
- public static void mergeSettings(Properties properties){
- properties.putAll(properties);
+ public static void mergeSettings(Map<String,String> props){
+ properties.putAll(props);
}
+
+ public static void mergeSettings(InputStream stream) throws IOException{
+ Properties tmpProp = new Properties();
+ tmpProp.load(stream);
+ properties.putAll(tmpProp);
+ }
+
+ public static void mergeSettingsCommandLineArgs(String[] args){
+ properties.putAll(parseCommandLineOptions(args));
+ }
+
+ private static Options deriveCommandLineOptions(String[] args){
+ Options options = new Options();
+ for (String arg : args) {
+ if (arg.startsWith("--")){
+ arg=arg.substring(2);
+ int pos = arg.indexOf('=');
+ String opt = pos == -1 ? arg : arg.substring(0, pos);
+ options.addOption(opt, true, "");
+ }
+ }
+ return options;
+ }
+
+ private static Map<String, String> parseCommandLineOptions(String[] args) {
+ Map<String,String> commandLineOptions=new HashMap<String,String>();
+ CommandLineParser parser = new DynamicOptionPosixParser();
+ try {
+ CommandLine cmdLine = parser.parse(deriveCommandLineOptions(args), args);
+ for (Option s : cmdLine.getOptions()) {
+ commandLineOptions.put(s.getOpt(), s.getValue());
+ }
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ return commandLineOptions;
+ }
+
+ private static class DynamicOptionPosixParser extends PosixParser{
+ @Override
+ protected void processOption(String arg0, @SuppressWarnings("rawtypes") ListIterator arg1)
+ throws ParseException {
+ if (getOptions().hasOption(arg0)){
+ super.processOption(arg0, arg1);
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/e54c7d05/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java b/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java
deleted file mode 100644
index ca30172..0000000
--- a/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed 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.airavata.server;
-
-
-import org.apache.catalina.*;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.core.StandardHost;
-import org.apache.catalina.startup.Embedded;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
-import org.apache.tomcat.util.IntrospectionUtils;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * This is an improvement to Embedded Tomcat. The objective is to provide a cleaner API for
- * embedders.
- */
-@SuppressWarnings("unused")
-public class BetterTomcat {
- private Tomcat tomcat = new Tomcat();
- private static Map<String, Connector> connectors = new HashMap<String, Connector>();
- private boolean unpackWars = true;
-
- public BetterTomcat() {
- // Override the default Tomcat connector. Otherwise a Connector on 8080 will be started
- tomcat.setConnector(new Connector(Protocol.HTTP_11.getProtocolName()));
-// setDefaultHost("defaultHost");
-// setBaseDir(".");
- }
-
- public BetterTomcat(int port) {
- this();
- addConnector(Protocol.HTTP_11, null, port);
- }
-
- /**
- * Indicates whether WAR files should be unpacked or not
- *
- * @param unpackWars true - unpackWars
- */
- public void setUnpackWars(boolean unpackWars) {
- this.unpackWars = unpackWars;
- }
-
- /**
- * Start the server.
- *
- * @throws LifecycleException If an irrecoverable error occurs while starting
- */
- public void start() throws LifecycleException {
- tomcat.start();
- }
-
- /**
- * Stop the server.
- *
- * @throws LifecycleException If an irrecoverable error occurs while stopping
- */
- public void stop() throws LifecycleException {
- tomcat.stop();
- }
-
- public Host getHost() {
- Host host = tomcat.getHost();
- ((StandardHost) host).setUnpackWARs(unpackWars);
- return host;
- }
-
- /**
- * Add a webapp using normal WEB-INF/web.xml if found.
- *
- * @param contextPath The context of the webapp, e.g., /foo
- * @param webappFilePath The file path of the webapp. Can be the path to a WAR file or a
- * directory,
- * e.g.,
- * 1. /home/azeez/bettertomcat/foo.war
- * 2. /home/azeez/bettertomcat/foo
- * @return new Context The Context of the deployed webapp
- * @throws BetterTomcatException If webapp deployment fails
- */
- public Context addWebapp(String contextPath,
- String webappFilePath) throws BetterTomcatException {
-
- Context context;
- try {
- context = tomcat.addWebapp(contextPath, webappFilePath);
- if (context.getState().equals(LifecycleState.STOPPED)) {
- throw new BetterTomcatException("Webapp " + context + " failed to deploy");
- }
- if (!unpackWars) {
- context.addParameter("antiJARLocking", "false");
- context.addParameter("antiResourceLocking", "false");
- }
- return context;
- } catch (ServletException e) {
- throw new BetterTomcatException("Webapp failed to deploy", e);
- }
- }
-
- /**
- * Add a webapp to a particular Host
- *
- * @param host The Host to which this webapp is added to
- * @param contextPath The context of the webapp, e.g., /foo
- * @param webappFilePath The file path of the webapp. Can be the path to a WAR file or a
- * directory,
- * e.g.,
- * 1. /home/azeez/bettertomcat/foo.war
- * 2. /home/azeez/bettertomcat/foo
- * @return new Context The Context of the deployed webapp
- */
- public Context addWebapp(Host host, String contextPath, String webappFilePath) {
- return tomcat.addWebapp(host, contextPath, webappFilePath);
- }
-
- /**
- * Add a context - programmatic mode, no web.xml used.
- * <p/>
- * API calls equivalent with web.xml:
- * <p/>
- * context-param
- * ctx.addParameter("name", "value");
- * <p/>
- * <p/>
- * error-page
- * ErrorPage ep = new ErrorPage();
- * ep.setErrorCode(500);
- * ep.setLocation("/error.html");
- * ctx.addErrorPage(ep);
- * <p/>
- * ctx.addMimeMapping("ext", "type");
- * <p/>
- * Note: If you reload the Context, all your configuration will be lost. If
- * you need reload support, consider using a LifecycleListener to provide
- * your configuration.
- * <p/>
- *
- * @param contextPath The context of the webapp. "" for root context.
- * @param baseDir base dir for the context, for static files. Must exist,
- * relative to the server home
- * @return new Context The Context of the deployed webapp
- */
- public Context addContext(String contextPath, String baseDir) {
- return tomcat.addContext(contextPath, baseDir);
- }
-
- public Context addContext(Host host, String contextPath, String dir) {
- return tomcat.addContext(host, contextPath, dir);
- }
-
- /**
- * Equivalent with
- * <servlet><servlet-name><servlet-class>.
- * <p/>
- * In general it is better/faster to use the method that takes a
- * Servlet as param - this one can be used if the servlet is not
- * commonly used, and want to avoid loading all deps.
- * ( for example: jsp servlet )
- * <p/>
- * You can customize the returned servlet, ex:
- * <p/>
- * wrapper.addInitParameter("name", "value");
- *
- * @param contextPath Context to add Servlet to
- * @param servletName Servlet name (used in mappings)
- * @param servletClass The class to be used for the Servlet
- * @return The wrapper for the servlet
- */
- public Wrapper addServlet(String contextPath,
- String servletName,
- String servletClass) {
- return tomcat.addServlet(contextPath, servletName, servletClass);
- }
-
- /**
- * Add an existing Servlet to the context with no class.forName or
- * initialisation.
- *
- * @param contextPath Context to add Servlet to
- * @param servletName Servlet name (used in mappings)
- * @param servlet The Servlet to add
- * @return The wrapper for the servlet
- */
- public Wrapper addServlet(String contextPath,
- String servletName,
- Servlet servlet) {
- return tomcat.addServlet(contextPath, servletName, servlet);
- }
-
- /**
- * Enables JNDI naming which is disabled by default. Server must implement
- * {@link org.apache.catalina.Lifecycle} in order for the
- * {@link org.apache.catalina.core.NamingContextListener} to be used.
- */
- public void enableNaming() {
- tomcat.enableNaming();
- }
-
- public Connector addConnector(int port) {
- return addConnector(Protocol.HTTP_11, null, port);
- }
-
- /**
- * Get a Tomcat Connector. If a connector with the Tomcat connector does not exist, create a new
- * one.
- *
- * @param protocol The protocol of the connector.
- * @param address The IP address of the network interface to which this connector should bind
- * to. Specify this as null if the connector should bind to all network interfaces.
- * @param port The port on which this connector has to be run
- * @return The Tomcat connector
- */
- public Connector addConnector(Protocol protocol, String address, int port) {
- Connector connector = connectors.get(protocol + "-" + address + "-" + port);
- if (connector == null) {
- connector = new Connector(protocol.getProtocolClass());
- if (address != null) {
- IntrospectionUtils.setProperty(connector, "address", address);
- }
- connector.setPort(port);
- connector.setEnableLookups(true);
- connector.setProperty("bindOnInit", "false");
- if (protocol.equals(Protocol.HTTPS_11) || protocol.equals(Protocol.HTTPS_11_NIO)) {
- connector.setSecure(true);
- connector.setAttribute("SSLEnabled", "true");
- connector.setScheme("https");
- }
- tomcat.getService().addConnector(connector);
- }
- return connector;
- }
-
- public void setClientAuth(Connector connector, String clientAuth) {
- ((AbstractHttp11JsseProtocol)connector.getProtocolHandler()).setClientAuth(clientAuth);
- }
-
- public Connector getConnector(Protocol protocol, String address, int port) {
- return addConnector(protocol, address, port);
- }
-
- public void setBaseDir(String baseDir) {
- tomcat.setBaseDir(baseDir);
- }
-
- public void setDefaultHost(String defaultHostName) {
- tomcat.setHostname(defaultHostName);
- tomcat.getEngine().setDefaultHost(defaultHostName);
- }
-
- public void setDefaultRealm(Realm realm) {
- tomcat.setDefaultRealm(realm);
- }
-
- /**
- * The valid protocol types
- */
- @SuppressWarnings("unused")
- public static enum Protocol {
- HTTP_11("HTTP/1.1", "HTTP/1.1"),
- HTTPS_11("HTTPS/1.1", "HTTP/1.1"),
- HTTP_11_NIO("HTTP/1.1/NIO", "org.apache.coyote.http11.Http11NioProtocol"),
- HTTPS_11_NIO("HTTPS/1.1/NIO", "org.apache.coyote.http11.Http11NioProtocol"),
- HTTP_11_APR("HTTP/1.1/APR","org.apache.coyote.http11.Http11AprProtocol"),
- HTTPS_11_APR("HTTPS/1.1/APR", "org.apache.coyote.http11.Http11AprProtocol"),
- MEMORY("memory", "org.apache.coyote.memory.MemoryProtocolHandler"),
- AJP("ajp", "org.apache.coyote.ajp.AjpProtocol");
-
- private String protocolName;
- private String protocolClass;
-
- Protocol(String protocolName, String protocolClass) {
- this.protocolName = protocolName;
- this.protocolClass = protocolClass;
- }
-
- public String getProtocolName() {
- return protocolName;
- }
-
- public String getProtocolClass() {
- return protocolClass;
- }
- }
-
- /**
- * Returns the wrapped Tomcat instance. This should be used only when advanced functionality
- * is required
- *
- * @return The Tomcat instance which can be used by advanced users who wish to gain more control
- */
- public Tomcat getTomcat() {
- return tomcat;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/e54c7d05/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java b/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java
deleted file mode 100644
index 5c5439a..0000000
--- a/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.airavata.server;
-
-
-/**
- * BetterTomcatException
- */
-public class BetterTomcatException extends Exception {
- public BetterTomcatException() {
- super();
- }
-
- public BetterTomcatException(String message) {
- super(message);
- }
-
- public BetterTomcatException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public BetterTomcatException(Throwable cause) {
- super(cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/e54c7d05/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 69a0034..3e8d18b 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
@@ -26,11 +26,15 @@ import java.util.List;
import org.apache.airavata.common.exception.ApplicationSettingsException;
import org.apache.airavata.common.utils.IServer;
import org.apache.airavata.common.utils.ServerSettings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ServerMain {
private static List<IServer> servers;
private static final String SERVERS_KEY="servers";
- static {
+ private final static Logger logger = LoggerFactory.getLogger(ServerMain.class);
+
+ private static void loadServers() {
servers = new ArrayList<IServer>();
try {
String serversString = ServerSettings.getSetting(SERVERS_KEY);
@@ -38,28 +42,31 @@ public class ServerMain {
String[] serversList = serversString.split(",");
for (String serverString : serversList) {
String serverClassName = ServerSettings.getSetting(serverString);
- Class<?> classInstance = ServerMain.class
- .getClassLoader().loadClass(
- serverClassName);
- servers.add((IServer)classInstance.newInstance());
+ Class<?> classInstance;
+ try {
+ classInstance = ServerMain.class
+ .getClassLoader().loadClass(
+ serverClassName);
+ servers.add((IServer)classInstance.newInstance());
+ } catch (ClassNotFoundException e) {
+ logger.error("Error while initiating locating server implementation \""+serverString+"\"!!!",e);
+ } catch (InstantiationException e) {
+ logger.error("Error while initiating server instance \""+serverString+"\"!!!",e);
+ } catch (IllegalAccessException e) {
+ logger.error("Error while initiating server instance \""+serverString+"\"!!!",e);
+ } catch (ClassCastException e){
+ logger.error("Invalid server \""+serverString+"\"!!!",e);
+ }
}
}
} catch (ApplicationSettingsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("Error while retrieving server list!!!",e);
}
}
public static void main(String args[]) {
+ ServerSettings.mergeSettingsCommandLineArgs(args);
+ loadServers();
new Thread() {
public void run() {
startAllServers();
@@ -99,4 +106,5 @@ public class ServerMain {
}
}
}
+
}
\ No newline at end of file
[2/2] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/airavata
Posted by sa...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/airavata
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/708f6a48
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/708f6a48
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/708f6a48
Branch: refs/heads/master
Commit: 708f6a48381ae0cef9de1728bcf0740fa2853b24
Parents: e54c7d0 afcd6e3
Author: Saminda Wijeratne <sa...@gmail.com>
Authored: Sat Mar 8 11:10:53 2014 -0500
Committer: Saminda Wijeratne <sa...@gmail.com>
Committed: Sat Mar 8 11:10:53 2014 -0500
----------------------------------------------------------------------
.../client/samples/CreateLaunchExperiment.java | 72 +++++++++--
.../airavata/client/tools/DocumentCreator.java | 119 ++++++++++++++++++-
2 files changed, 180 insertions(+), 11 deletions(-)
----------------------------------------------------------------------