You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2013/01/02 20:55:59 UTC
svn commit: r1427983 [4/4] - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src: main/ main/java/
main/java/org/ main/java/org/apache/ main/java/org/apache/uima/
main/java/org/apache/uima/ducc/ main/java/org/apache/uima/ducc/ws/
main/java/org/apache/ui...
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebJobSpecificationProperties.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebJobSpecificationProperties.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebJobSpecificationProperties.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebJobSpecificationProperties.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.server;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.uima.ducc.cli.DuccUiConstants;
+import org.apache.uima.ducc.transport.event.cli.JobSpecificationProperties;
+
+
+@SuppressWarnings("serial")
+public class DuccWebJobSpecificationProperties extends JobSpecificationProperties {
+
+ private static int inputSize = 30;
+
+ private static String help(String helptext) {
+ return "<img title=\""+helptext+"\" src=\"images/qmark.png\"/>";
+ }
+
+ private static String genInput(String key, String initialValue) {
+ if(initialValue == null) {
+ return "<input type=\"text\" size=\""+inputSize+"\" id=\""+key+"\" />";
+ }
+ else {
+ return "<input type=\"text\" size=\""+inputSize+"\" id=\""+key+"\" value=\""+initialValue+"\"/>";
+ }
+ }
+
+ private static String genSelect(String key, String initialValue, String[] possibleValues) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("<select id=\""+key+"\">");
+ for (int i=0;i<possibleValues.length;i++) {
+ String selected = "";
+ if(initialValue != null) {
+ if(initialValue.equals(possibleValues[i])) {
+ selected = " selected=\"selected\"";
+ }
+ }
+ sb.append("<option"+selected+">"+possibleValues[i]+"</option>");
+ }
+ sb.append("</select>");
+ return sb.toString();
+ }
+
+ private static String entry(String description, String key, String label, String initialValue, String[] possibleValues, String color, String hover) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("<tr>");
+ sb.append("<td>");
+ sb.append(help(description));
+ sb.append("<td>");
+ if(possibleValues == null) {
+ sb.append(genInput(key,initialValue));
+ }
+ else {
+ sb.append(genSelect(key,initialValue,possibleValues));
+ }
+ sb.append("<td align=\"left\">");
+ sb.append("<span title=\""+hover+"\" style=\"color: "+color+"\">*</span>");
+ sb.append("<span title=\""+hover+"\" >"+label+"</span>");
+ return sb.toString();
+ }
+
+ private static String entry(String description, String key, String label, String initialValue, String[] possibleValues) {
+ return entry(description, key, label, initialValue, possibleValues, "white", "");
+ }
+
+ private static String descriptionWithExample(String description, String exampleText) {
+ return description+" Example: "+exampleText;
+ }
+
+ private static String presetValue(String cookieValue, String defaultValue) {
+ String retVal = null;
+ if(cookieValue != null) {
+ retVal = cookieValue;
+ }
+ else if(defaultValue != null) {
+ retVal = defaultValue;
+ }
+ return retVal;
+ }
+
+ public static String getHtmlForm(HttpServletRequest request, DuccWebSchedulerClasses schedulerClasses)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("<fieldset>");
+ sb.append("<legend>");
+ sb.append("Job");
+ sb.append("<table>");
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_description,DuccUiConstants.exmp_description),
+ key_description,
+ DuccUiConstants.labl_description,
+ null,
+ null
+ ));
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_jvm,DuccUiConstants.exmp_jvm),
+ key_jvm,
+ DuccUiConstants.labl_jvm,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_jvm)),DuccUiConstants.dval_jvm),
+ null
+ ));
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_scheduling_class,DuccUiConstants.exmp_scheduling_class),
+ key_scheduling_class,
+ DuccUiConstants.labl_scheduling_class,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_scheduling_class)),DuccUiConstants.dval_scheduling_class),
+ schedulerClasses.getJobClasses()
+ ));
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_log_directory,DuccUiConstants.exmp_log_directory),
+ key_log_directory,
+ DuccUiConstants.labl_log_directory,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_log_directory)),DuccUiConstants.dval_log_directory),
+ null
+ ));
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_working_directory,DuccUiConstants.exmp_working_directory),
+ key_working_directory,
+ DuccUiConstants.labl_working_directory,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_working_directory)),DuccUiConstants.dval_working_directory),
+ null
+ ));
+
+ sb.append("</table>");
+ sb.append("</legend>");
+ sb.append("</fieldset>");
+
+ sb.append("<fieldset>");
+ sb.append("<legend>");
+ sb.append("Driver");
+ sb.append("<table>");
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_driver_jvm_args,DuccUiConstants.exmp_driver_jvm_args),
+ key_driver_jvm_args,
+ DuccUiConstants.labl_driver_jvm_args,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_driver_classpath,
+ key_driver_classpath,
+ DuccUiConstants.labl_driver_classpath,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_driver_environment,
+ key_driver_environment,
+ DuccUiConstants.labl_driver_environment,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_driver_memory_size,
+ key_driver_memory_size,
+ DuccUiConstants.labl_driver_memory_size,
+ null,
+ null
+ ));
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_driver_descriptor_CR,DuccUiConstants.exmp_driver_descriptor_CR),
+ key_driver_descriptor_CR,
+ DuccUiConstants.labl_driver_descriptor_CR,
+ null,
+ null,
+ "red",
+ "CR is required."
+ ));
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_driver_descriptor_CR_overrides,DuccUiConstants.exmp_driver_descriptor_CR_overrides),
+ key_driver_descriptor_CR_overrides,
+ DuccUiConstants.labl_driver_descriptor_CR_overrides,
+ null,
+ null
+ ));
+
+ sb.append("</table>");
+ sb.append("</legend>");
+ sb.append("</fieldset>");
+
+ sb.append("<fieldset>");
+ sb.append("<legend>");
+ sb.append("Process");
+ sb.append("<table>");
+
+ sb.append(entry(descriptionWithExample(DuccUiConstants.desc_process_jvm_args,DuccUiConstants.exmp_process_jvm_args),
+ key_process_jvm_args,
+ DuccUiConstants.labl_process_jvm_args,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_classpath,
+ key_process_classpath,
+ DuccUiConstants.labl_process_classpath,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_environment,
+ key_process_environment,
+ DuccUiConstants.labl_process_environment,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_memory_size,
+ key_process_memory_size,
+ DuccUiConstants.labl_process_memory_size,
+ null,
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_descriptor_CM,
+ key_process_descriptor_CM,
+ DuccUiConstants.labl_process_descriptor_CM,
+ null,
+ null,
+ "orange",
+ "At least one of { CM, AE, CC } is required."
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_descriptor_AE,
+ key_process_descriptor_AE,
+ DuccUiConstants.labl_process_descriptor_AE,
+ null,
+ null,
+ "orange",
+ "At least one of { CM, AE, CC } is required."
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_descriptor_CC,
+ key_process_descriptor_CC,
+ DuccUiConstants.labl_process_descriptor_CC,
+ null,
+ null,
+ "orange",
+ "At least one of { CM, AE, CC } is required."
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_deployments_max,
+ key_process_deployments_max,
+ DuccUiConstants.labl_process_deployments_max,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_process_deployments_max)),DuccUiConstants.dval_process_deployments_max),
+ null
+ ));
+ /*
+ sb.append(entry(DuccUiConstants.desc_process_deployments_min,
+ key_process_deployments_min,
+ DuccUiConstants.labl_process_deployments_min,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_process_deployments_min)),DuccUiConstants.dval_process_deployments_min),
+ null
+ ));
+ */
+ sb.append(entry(DuccUiConstants.desc_process_thread_count,
+ key_process_thread_count,
+ DuccUiConstants.labl_process_thread_count,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_process_thread_count)),DuccUiConstants.dval_process_thread_count),
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_get_meta_time_max,
+ key_process_get_meta_time_max,
+ DuccUiConstants.labl_process_get_meta_time_max,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_process_get_meta_time_max)),DuccUiConstants.dval_process_get_meta_time_max),
+ null
+ ));
+ sb.append(entry(DuccUiConstants.desc_process_per_item_time_max,
+ key_process_per_item_time_max,
+ DuccUiConstants.labl_process_per_item_time_max,
+ presetValue(DuccWebUtil.getCookieOrNull(request,DuccWebUtil.getCookieKey(DuccUiConstants.name_process_per_item_time_max)),DuccUiConstants.dval_process_per_item_time_max),
+ null
+ ));
+
+ sb.append("</table>");
+ sb.append("</legend>");
+ sb.append("</fieldset>");
+
+ return sb.toString();
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebJobSpecificationProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebProperties.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebProperties.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebProperties.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebProperties.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.server;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+public class DuccWebProperties {
+
+ static Properties properties = new Properties();
+
+ public static String key_MaxRecordsJobs = "MaxRecordsJobs";
+ public static String key_MaxRecordsReservations = "MaxRecordsReservations";
+
+ static {
+ properties.setProperty(key_MaxRecordsJobs, "12");
+ properties.setProperty(key_MaxRecordsReservations, "5");
+ }
+
+ public static Properties instance() {
+ return (Properties)properties.clone();
+ }
+
+ private static String dir_home = System.getenv("DUCC_HOME");
+ private static String dir_resources = "resources";
+ private static String ducc_properties_filename = dir_home+File.separator+dir_resources+File.separator+"ducc.properties";
+
+ public static Properties get() {
+ Properties properties = new Properties();
+ try {
+ File file = new File(ducc_properties_filename);
+ FileInputStream fis;
+ fis = new FileInputStream(file);
+ properties.load(fis);
+ fis.close();
+ }
+ catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ return properties;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebSchedulerClasses.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebSchedulerClasses.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebSchedulerClasses.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebSchedulerClasses.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.server;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.uima.ducc.common.utils.DuccProperties;
+
+
+public class DuccWebSchedulerClasses {
+
+ private String fileName;
+
+ public DuccWebSchedulerClasses(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public DuccProperties getClasses() {
+ DuccProperties properties = new DuccProperties();
+ try {
+ File file = new File(fileName);
+ FileInputStream fis = new FileInputStream(file);
+ properties.load(fis);
+ fis.close();
+ }
+ catch(IOException e) {
+ e.printStackTrace();
+ }
+ return properties;
+ }
+
+ public String getProperty(Properties properties, String name) {
+ String retVal = "";
+ String property = properties.getProperty(name);
+ if(property != null) {
+ retVal = property.trim();
+ }
+ return retVal;
+ }
+
+ public String[] getReserveClasses() {
+ ArrayList<String> classList = new ArrayList<String>();
+ Properties properties = getClasses();
+ String class_set = properties.getProperty("scheduling.class_set");
+ class_set.trim();
+ if(class_set != null) {
+ String[] class_array = StringUtils.split(class_set);
+ for(int i=0; i<class_array.length; i++) {
+ String class_name = class_array[i].trim();
+ String policy = getProperty(properties,"scheduling.class."+class_name+".policy");
+ if(policy.equals(DuccConstants.FIXED_SHARE)) {
+ classList.add(class_name);
+ }
+ else if(policy.equals(DuccConstants.RESERVE) && !class_name.equals(DuccConstants.JobDriver)) {
+ classList.add(class_name);
+ }
+ }
+ }
+ String[] retVal = classList.toArray(new String[0]);
+ return retVal;
+ }
+
+ public String[] getJobClasses() {
+ ArrayList<String> classList = new ArrayList<String>();
+ Properties properties = getClasses();
+ String class_set = properties.getProperty("scheduling.class_set");
+ class_set.trim();
+ if(class_set != null) {
+ String[] class_array = StringUtils.split(class_set);
+ for(int i=0; i<class_array.length; i++) {
+ String class_name = class_array[i].trim();
+ String policy = getProperty(properties,"scheduling.class."+class_name+".policy");
+ if(policy.equals(DuccConstants.FAIR_SHARE)) {
+ classList.add(class_name);
+ }
+ }
+ }
+ String[] retVal = classList.toArray(new String[0]);
+ return retVal;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebSchedulerClasses.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.server;
+
+import java.io.File;
+
+import org.apache.jasper.servlet.JspServlet;
+import org.apache.uima.ducc.common.config.CommonConfiguration;
+import org.apache.uima.ducc.common.internationalization.Messages;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.eclipse.jetty.http.ssl.SslContextFactory;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
+import org.eclipse.jetty.servlet.DefaultServlet;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+
+public class DuccWebServer {
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(DuccWebServer.class.getName());
+ private static Messages messages = Messages.getInstance();
+
+ /**
+ * DUCC_WEB should be set as an environment variable. This is the webserver's
+ * base directory where it will find web pages to serve from sub-directory root,
+ * and SSL data in sub-directory etc.
+ */
+ private String ducc_web =".";
+
+ /**
+ * The default port can be overridden in ducc.proerties file, for example:
+ * ducc.ws.port = 41233
+ */
+ private int port = 42133;
+ private String ipaddress = null;
+
+ /**
+ * To support https, do the following:
+ *
+ * 1. use 'keytool -keystore keystore -alias jetty -genkey -keyalg RSA -validity 10000' to create
+ * keystore in ducc_web/etc directory
+ * 2. in ducc.properties set SSL port, for example:
+ * ducc.ws.port.ssl = 42155
+ * 3. in ducc.properties set SSL password, for example:
+ * ducc.ws.port.ssl.pw = quackquack
+ *
+ * Note: if SSL port is not set in ducc.properties, the webserver will not create
+ * the SSL connection, and thus secure communications will be unsupported.
+ */
+ private int portSsl = -1;
+ private String portSslPw = "quackquack";
+ private String rootDir = "?";
+
+ //
+
+ private Server server;
+
+ private CommonConfiguration commonConfiguration;
+
+ public DuccWebServer(CommonConfiguration commonConfiguration) {
+ this.commonConfiguration = commonConfiguration;
+ init();
+ }
+
+ public String getJdHostUser() {
+ return commonConfiguration.jdHostUser;
+ }
+
+ /**
+ * The DUCC cluster name can be set in the ducc.properties file, for example:
+ * ducc.cluster.name=Watson!
+ */
+ public String getClusterName() {
+ return commonConfiguration.clusterName;
+ }
+
+ /**
+ * The DUCC class definition file can be set in the ducc.properties file, for example:
+ * ducc.rm.class.definitions = blade.classes
+ */
+ public String getClassDefinitionFile() {
+ return commonConfiguration.classDefinitionFile;
+ }
+
+ public int getPortSsl() {
+ return portSsl;
+ }
+
+ public String getRootDir() {
+ return rootDir;
+ }
+
+ private void init() {
+ String methodName = "init";
+ logger.trace(methodName, null, messages.fetch("enter"));
+ logger.info(methodName, null, messages.fetchLabel("cluster name")+getClusterName());
+ logger.info(methodName, null, messages.fetchLabel("class definition file")+getClassDefinitionFile());
+ if(commonConfiguration.wsIpAddress != null) {
+ this.ipaddress = commonConfiguration.wsIpAddress;
+ logger.info(methodName, null, messages.fetchLabel("IP Address")+ipaddress);
+ }
+ if(commonConfiguration.wsPort != null) {
+ this.port = Integer.parseInt(commonConfiguration.wsPort);
+ logger.info(methodName, null, messages.fetchLabel("port")+port);
+ }
+ if(commonConfiguration.wsPortSsl != null) {
+ this.portSsl = Integer.parseInt(commonConfiguration.wsPortSsl);
+ logger.info(methodName, null, messages.fetchLabel("SSL port")+portSsl);
+ if(commonConfiguration.wsPortSslPw != null) {
+ this.portSslPw = commonConfiguration.wsPortSslPw;
+ logger.debug(methodName, null, messages.fetchLabel("SSL pw")+portSslPw);
+ }
+ }
+ String ducc_web_property = System.getProperty("DUCC_WEB");
+ String ducc_web_env = System.getenv("DUCC_WEB");
+ if(ducc_web_property != null) {
+ ducc_web = ducc_web_property;
+ logger.info(methodName, null, messages.fetchLabel("DUCC_WEB")+ducc_web);
+ }
+ else if(ducc_web_env != null) {
+ ducc_web = ducc_web_env;
+ logger.info(methodName, null, messages.fetchLabel("DUCC_WEB (default)")+ducc_web);
+ }
+ server = new Server();
+ SelectChannelConnector connector0 = new SelectChannelConnector();
+ connector0.setPort(port);
+ if(ipaddress != null) {
+ connector0.setHost(ipaddress);
+ }
+ if(portSsl < 0) {
+ server.setConnectors(new Connector[]{ connector0 });
+ }
+ else {
+ SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();
+ ssl_connector.setPort(portSsl);
+ if(ipaddress != null) {
+ ssl_connector.setHost(ipaddress);
+ }
+ SslContextFactory cf = ssl_connector.getSslContextFactory();
+ cf.setKeyStore(ducc_web + File.separator+"etc"+File.separator+"keystore");
+ cf.setKeyStorePassword(portSslPw);
+ server.setConnectors(new Connector[]{ connector0, ssl_connector });
+ }
+ //
+ ServletContextHandler jspHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ jspHandler.setContextPath("/");
+ jspHandler.setResourceBase("root");
+ jspHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
+ jspHandler.addServlet(DefaultServlet.class, "/");
+ ServletHolder jsp = jspHandler.addServlet(JspServlet.class, "*.jsp");
+ jsp.setInitParameter("classpath", jspHandler.getClassPath());
+ //
+ ResourceHandler resourceHandler = new ResourceHandler();
+ resourceHandler.setDirectoriesListed(true);
+ resourceHandler.setWelcomeFiles(new String[]{ "index.html" });
+ rootDir = ducc_web+File.separator+"root";
+ resourceHandler.setResourceBase(rootDir);
+ HandlerList handlers = new HandlerList();
+ DuccHandler duccHandler = new DuccHandler(this);
+ handlers.setHandlers(new Handler[] { duccHandler, jspHandler, resourceHandler, new DefaultHandler() });
+ server.setHandler(handlers);
+ logger.trace(methodName, null, messages.fetch("exit"));
+ }
+
+ public void start() throws Exception {
+ server.start();
+ }
+
+ public void join() throws Exception {
+ server.join();
+ }
+
+ public void stop() throws Exception {
+ server.stop();
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebUtil.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebUtil.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebUtil.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.server;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.uima.ducc.common.internationalization.Messages;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+
+
+public class DuccWebUtil {
+
+ private static DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(DuccWebUtil.class.getName());
+ private static Messages messages = Messages.getInstance();
+
+ public static final String cookieUri = "/";
+
+ private static final String join = ":";
+
+ private static final String application = "ducc";
+
+ public static final String cookieUser = application+join+"user";
+ public static final String cookieSession = application+join+"session";
+
+ private static final String jobs = "jobs";
+ private static final String reservations = "reservations";
+ private static final String services = "services";
+
+ private static final String max = "max";
+ private static final String users = "users";
+ private static final String qualifier = "qualifier";
+
+ public static final String cookieJobsMax = application+join+jobs+max;
+ public static final String cookieJobsUsers = application+join+jobs+users;
+ public static final String cookieJobsUsersQualifier = application+join+jobs+users+qualifier;
+ public static final String cookieReservationsMax = application+join+reservations+max;
+ public static final String cookieReservationsUsers = application+join+reservations+users;
+ public static final String cookieReservationsUsersQualifier = application+join+reservations+users+qualifier;
+ public static final String cookieServicesMax = application+join+services+max;
+ public static final String cookieServicesUsers = application+join+services+users;
+ public static final String cookieServicesUsersQualifier = application+join+services+users+qualifier;
+
+ protected static final String getCookieKey(String name) {
+ return application+join+"name";
+ }
+
+ protected static String getCookie(String defaultValue, HttpServletRequest request, String name) {
+ String methodName = "getCookie";
+ String retVal = defaultValue;
+ Cookie[] cookies = request.getCookies();
+ if(cookies != null) {
+ for(int i=0; i < cookies.length; i++) {
+ Cookie cookie = cookies[i];
+ if(cookie != null) {
+ String cookieName = cookie.getName();
+ if(cookieName != null) {
+ if(cookieName.equals(name)) {
+ retVal = cookie.getValue();
+ break;
+ }
+ }
+ }
+ }
+ }
+ duccLogger.debug(methodName, null, messages.fetchLabel("name")+name+" "+messages.fetchLabel("value")+retVal);
+ return retVal;
+ }
+
+ protected static String getCookie(HttpServletRequest request, String name) {
+ return getCookie("",request,name);
+ }
+
+ protected static String getCookieOrNull(HttpServletRequest request, String name) {
+ return getCookie(null,request,name);
+ }
+
+ protected static void putCookie(HttpServletResponse response, String name, String value) {
+ String methodName = "putCookie";
+ Cookie cookie = new Cookie(name, value);
+ cookie.setPath(cookieUri);
+ response.addCookie(cookie);
+ duccLogger.debug(methodName, null, messages.fetchLabel("name")+name+" "+messages.fetchLabel("value")+value);
+ }
+
+ protected static void expireCookie(HttpServletResponse response, String name, String value) {
+ String methodName = "expireCookie";
+ Cookie cookie = new Cookie(name, value);
+ cookie.setMaxAge(0);
+ response.addCookie(cookie);
+ duccLogger.debug(methodName, null, messages.fetchLabel("name")+name+" "+messages.fetchLabel("value")+value);
+ }
+
+ /*
+ @Deprecated
+ protected String getUserHome(String userName) throws IOException{
+ return new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(new String[]{"sh", "-c", "echo ~" + userName}).getInputStream())).readLine();
+ }
+ */
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Ip.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Ip.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Ip.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Ip.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.types;
+
+public class Ip {
+
+ private String ip;
+
+ public Ip(String ip) {
+ this.ip = ip;
+ }
+
+ @Override
+ public String toString() {
+ return this.ip;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Ip.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/NodeId.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/NodeId.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/NodeId.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/NodeId.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.types;
+
+public class NodeId {
+
+ private String machine;
+
+ public NodeId(String machine) {
+ this.machine = machine;
+ }
+
+ @Override
+ public String toString() {
+ return this.machine;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/NodeId.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Pid.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Pid.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Pid.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Pid.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.types;
+
+public class Pid {
+
+ private String pid;
+
+ public Pid(String pid) {
+ this.pid = pid;
+ }
+
+ @Override
+ public String toString() {
+ return this.pid;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/Pid.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/UserId.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/UserId.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/UserId.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/UserId.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.types;
+
+public class UserId {
+
+ private String user;
+
+ public UserId(String user) {
+ this.user = user;
+ }
+
+ @Override
+ public String toString() {
+ return this.user;
+ }
+
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/types/UserId.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/DatedNodeMetricsUpdateDuccEvent.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/DatedNodeMetricsUpdateDuccEvent.java?rev=1427983&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/DatedNodeMetricsUpdateDuccEvent.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/DatedNodeMetricsUpdateDuccEvent.java Wed Jan 2 19:55:58 2013
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.uima.ducc.ws.utils;
+
+import java.io.Serializable;
+
+import org.apache.uima.ducc.transport.event.NodeMetricsUpdateDuccEvent;
+
+
+@SuppressWarnings("serial")
+public class DatedNodeMetricsUpdateDuccEvent implements Serializable {
+
+ private NodeMetricsUpdateDuccEvent nodeMetricsUpdateDuccEvent = null;
+ private long millis = -1;
+
+ public DatedNodeMetricsUpdateDuccEvent(NodeMetricsUpdateDuccEvent nodeMetricsUpdateDuccEvent) {
+ this.nodeMetricsUpdateDuccEvent = nodeMetricsUpdateDuccEvent;
+ this.millis = System.currentTimeMillis();
+ }
+
+ public NodeMetricsUpdateDuccEvent getNodeMetricsUpdateDuccEvent() {
+ return nodeMetricsUpdateDuccEvent;
+ }
+
+ public long getMillis() {
+ return millis;
+ }
+
+ public long getElapsed() {
+ return System.currentTimeMillis() - getMillis();
+ }
+
+ public boolean isExpired(long millis) {
+ return getElapsed() > millis;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/DatedNodeMetricsUpdateDuccEvent.java
------------------------------------------------------------------------------
svn:eol-style = native