You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2012/05/23 04:29:06 UTC
svn commit: r1341732 [2/3] - in
/incubator/airavata/sandbox/workflow-monitoring-util: ./ conf/ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/airavata/ src/main/java/org/apache/airavata/tools/
src/ma...
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConfigurationParamsReader.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConfigurationParamsReader.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConfigurationParamsReader.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConfigurationParamsReader.java Wed May 23 02:29:03 2012
@@ -0,0 +1,940 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.db;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import xsul.MLogger;
+
+public class ConfigurationParamsReader implements Configuration {
+
+ private final static MLogger log = MLogger.getLogger();
+
+ public final String FILE_SEPARATOR = "/";
+
+ public final String DELIMITER = ",";
+
+ private final int INITIAL_LIST_SIZE = 3;
+
+ private String basePath = null;
+
+ private ArrayList keysList = new ArrayList();
+
+ protected Configuration defaults = null;
+
+ protected Hashtable store = new Hashtable();
+
+ public ConfigurationParamsReader() {
+ }
+
+ public ConfigurationParamsReader(String file) {
+ try {
+ load(file);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ log.info(ioe.getMessage());
+ }
+ }
+
+ public ConfigurationParamsReader(Configuration defaults) {
+ this.defaults = defaults;
+ }
+
+ /**
+ * Load the properties from the given file
+ *
+ * @param file
+ * The properties file to load
+ * @throws IOException
+ */
+ public void load(String file) throws IOException {
+ load(this.getClass().getClassLoader().getResourceAsStream(file));
+ }
+
+ /**
+ * Load the properties from the given input stream.
+ *
+ * @param input
+ * An InputStream on the properties file
+ * @throws IOException
+ */
+ public void load(InputStream input) throws IOException {
+ load(input, null);
+ }
+
+ /**
+ * Load the properties from the given input stream and using the specified
+ * encoding.
+ *
+ * @param input
+ * An InputStream.
+ * @param enc
+ * An encoding.
+ * @exception IOException
+ */
+ public synchronized void load(InputStream input, String enc)
+ throws IOException {
+
+ LineNumberReader reader = null;
+
+ if (enc != null) {
+ try {
+ reader = new LineNumberReader(new InputStreamReader(input, enc));
+ } catch (UnsupportedEncodingException e) {
+ // Get one with the default encoding...
+ }
+ }
+ if (reader == null) {
+ reader = new LineNumberReader(new InputStreamReader(input));
+ }
+
+ StringBuffer sb = new StringBuffer();
+ while (true) {
+
+ String line = reader.readLine();
+ if (line == null) {
+ break; // EOF
+ }
+
+ line = line.trim();
+ if (line.startsWith("#")) {
+ continue;
+
+ } else if (line.equals("")) {
+ continue;
+
+ } else if (line.endsWith("\\")) {
+ sb.append(line.substring(0, line.length() - 1));
+ continue;
+
+ } else {
+ line = sb.append(line).toString();
+ sb = new StringBuffer();
+
+ int equalIndex = line.indexOf('=');
+ /**
+ * fix commons.configuration bug
+ *
+ * @see BasePropertiesConfiguration#load we not only make sure
+ * there is an equal sign, but also there is something
+ * after the equal sign
+ */
+ if (equalIndex > 0 && (equalIndex + 1) < line.length()) {
+ String key = line.substring(0, equalIndex).trim();
+ String value = line.substring(equalIndex + 1).trim();
+
+ addProperty(key, value);
+
+ }
+ }
+ }
+ }
+
+ /**
+ * @param The
+ * file name with which to get InputStream
+ * @return An InputStream
+ * @throws IOException
+ */
+ public InputStream getPropertyStream(String resourceName)
+ throws IOException {
+
+ InputStream resource = null;
+ File file = null;
+
+ if (resourceName.startsWith(FILE_SEPARATOR)) {
+ // an absolute path
+ file = new File(resourceName);
+ log.info("configuration: load " + resourceName);
+ } else if (basePath == null || basePath.equals("")) {
+
+ file = new File(resourceName);
+ String canonName = file.getCanonicalPath();
+ file = new File(canonName);
+ log.info("configuration: load " + canonName);
+ } else {
+ StringBuffer fileName = new StringBuffer();
+
+ if (!basePath.endsWith(FILE_SEPARATOR)) {
+ basePath = basePath + FILE_SEPARATOR;
+ }
+ fileName.append(basePath).append(resourceName);
+ file = new File(fileName.toString());
+ String canonName = file.getCanonicalPath();
+ file = new File(canonName);
+ log.info("configuration: load " + canonName);
+ }
+
+ if (file == null || !file.exists()) {
+ throw new FileNotFoundException("File not exists " + resourceName);
+
+ } else if (!file.canRead()) {
+ throw new IOException("File " + resourceName
+ + " exists but could not be read.");
+
+ } else {
+ resource = new FileInputStream(file);
+ }
+
+ return resource;
+ }
+
+ /**
+ * @see Configuration
+ */
+ public void addProperty(String key, Object token) {
+
+ List tokenAdd = null;
+
+ if (token instanceof String) {
+ tokenAdd = processString((String) token);
+
+ } else if (token instanceof Collection) {
+
+ for (Iterator it = ((Collection) token).iterator(); it.hasNext();) {
+ addProperty(key, it.next());
+ }
+ return;
+
+ } else {
+ tokenAdd = new Vector(1);
+ tokenAdd.add(token);
+ }
+
+ Object o = store.get(key);
+ if (o instanceof Vector) {
+ for (Iterator it = tokenAdd.iterator(); it.hasNext();) {
+ ((Vector) o).add(it.next());
+ }
+
+ } else {
+ Vector v = new Vector();
+ if (o != null) {
+ v.add(o);
+ }
+ for (Iterator it = tokenAdd.iterator(); it.hasNext();) {
+ v.add(it.next());
+ }
+
+ if (o == null && v.size() == 1) {
+ addPropertyDirect(key, v.get(0));
+
+ } else {
+ addPropertyDirect(key, v);
+ }
+ }
+ }
+
+ /**
+ * @param token
+ * A String token
+ * @return A List of Strings
+ */
+ protected List processString(String token) {
+ List l = new ArrayList(INITIAL_LIST_SIZE);
+
+ if (token.indexOf(DELIMITER) > 0) {
+ StringTokenizer tokenizer = new StringTokenizer(token, DELIMITER);
+
+ while (tokenizer.hasMoreTokens()) {
+ String value = tokenizer.nextToken();
+ /**
+ * fix commons.configuration bug
+ *
+ * @see PropertiesConfiguration#processString() more trim() call
+ * allows both comma "," AND whitespace between values
+ */
+ l.add(value.trim());
+ }
+ } else {
+ l.add(token);
+ }
+
+ return l;
+ }
+
+ /**
+ * @param key
+ * key to use for mapping
+ * @param obj
+ * object to store
+ */
+ protected void addPropertyDirect(String key, Object obj) {
+
+ if (!store.containsKey(key)) {
+ keysList.add(key);
+ }
+
+ store.put(key, obj);
+ }
+
+ /**
+ * Map <code> true </code>, <code> on </code>, <code> yes </code> to true;
+ * <code> false </code>, <code> off </code>, <code> no </code> to false.
+ *
+ * @param value
+ * The value to test for boolean state.
+ * @return String of true, false or null
+ */
+ public String testBoolean(String value) {
+
+ String val = value.toLowerCase();
+
+ if (val.equals("true") || val.equals("on") || val.equals("yes")) {
+ return "true";
+
+ } else if (val.equals("false") || val.equals("off") || val.equals("no")) {
+ return "false";
+
+ } else {
+ return null;
+ }
+
+ }
+
+ /**
+ *
+ * @see Configuration
+ */
+ public Configuration subset(String prefix) {
+
+ Configuration pc = new ConfigurationParamsReader();
+ Iterator keys = this.getKeys();
+ boolean valid = false;
+
+ while (keys.hasNext()) {
+ Object key = keys.next();
+
+ if (key instanceof String && ((String) key).startsWith(prefix)) {
+ if (!valid) {
+ valid = true;
+ }
+
+ String newKey = null;
+ if (((String) key).length() == prefix.length()) {
+ newKey = prefix;
+
+ } else {
+ newKey = ((String) key).substring(prefix.length() + 1);
+ }
+
+ Object value = store.get(key);
+ ((ConfigurationParamsReader) pc).addPropertyDirect(newKey,
+ value);
+
+ }
+ }
+
+ if (valid) {
+ return pc;
+ } else {
+ return null;
+ }
+
+ }
+
+ /**
+ * @see Configuration#isEmpty
+ */
+ public boolean isEmpty() {
+ return store.isEmpty();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public boolean containsKey(String key) {
+ return store.containsKey(key);
+ }
+
+ /**
+ * @see Configuration
+ */
+ public void setProperty(String key, Object value) {
+ clearProperty(key);
+ addProperty(key, value);
+ }
+
+ /**
+ * @see Configuration
+ */
+ public void clearProperty(String key) {
+
+ if (containsKey(key)) {
+ for (int i = 0; i < keysList.size(); i++) {
+ if (((String) keysList.get(i)).equals(key)) {
+ keysList.remove(i);
+ break;
+ }
+ }
+ store.remove(key);
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Iterator getKeys() {
+ return keysList.iterator();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Iterator getKeys(String prefix) {
+ Iterator keys = getKeys();
+ ArrayList matchingKeys = new ArrayList();
+
+ while (keys.hasNext()) {
+ Object key = keys.next();
+
+ if (key instanceof String && ((String) key).startsWith(prefix)) {
+ matchingKeys.add(key);
+ }
+ }
+ return matchingKeys.iterator();
+ }
+
+ /**
+ * Returns all the properties that have been read from the specified
+ * configuration file
+ */
+ public Properties getProperties(Properties _defaults) {
+ Properties props = new Properties(_defaults);
+
+ Enumeration e = store.keys();
+ while (e.hasMoreElements()) {
+ String _key = (String) e.nextElement();
+ String _value = store.get(_key).toString();
+ props.setProperty(_key, _value);
+ }
+ return props;
+
+ }
+
+ /**
+ * @see Configuration
+ * @see #getProperties(String, Properties)
+ */
+ public Properties getProperties(String key) {
+ return getProperties(key, null);
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Properties getProperties(String key, Properties defaults) {
+
+ String[] tokens = getStringArray(key);
+
+ /*
+ * Each token is of the form 'key=value'.
+ */
+ Properties props = (defaults == null ? new Properties()
+ : new Properties(defaults));
+
+ for (int i = 0; i < tokens.length; i++) {
+ String token = tokens[i];
+ int equalIndex = token.indexOf('=');
+ if (equalIndex > 0) {
+ String pkey = token.substring(0, equalIndex).trim();
+ String pvalue = token.substring(equalIndex + 1).trim();
+ props.put(pkey, pvalue);
+ } else if (tokens.length == 1 && token.equals("")) {
+ // Semantically equivalent to an empty Properties
+ // object.
+ break;
+ } else {
+ throw new IllegalArgumentException('\'' + token
+ + "' does not contain an equals sign");
+ }
+ }
+ return props;
+ }
+
+ /**
+ * @see Configuration
+ */
+ public String getProperty(String key) {
+
+ Object o = store.get(key);
+
+ if (o == null) {
+ if (defaults != null) {
+ o = defaults.getProperty(key);
+ }
+ }
+ return o.toString();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public boolean getBoolean(String key) {
+ Boolean b = getBoolean(key, (Boolean) null);
+ if (b != null) {
+ return b.booleanValue();
+
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + "' doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public boolean getBoolean(String key, boolean defaultValue) {
+ return getBoolean(key, new Boolean(defaultValue)).booleanValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Boolean getBoolean(String key, Boolean defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Boolean) {
+ return (Boolean) value;
+ } else if (value instanceof String) {
+ String s = testBoolean((String) value);
+ Boolean b = new Boolean(s);
+ return b;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getBoolean(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Boolean object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public byte getByte(String key) {
+ Byte b = getByte(key, null);
+ if (b != null) {
+ return b.byteValue();
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + " doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public byte getByte(String key, byte defaultValue) {
+ return getByte(key, new Byte(defaultValue)).byteValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Byte getByte(String key, Byte defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Byte) {
+ return (Byte) value;
+ } else if (value instanceof String) {
+ Byte b = new Byte((String) value);
+ return b;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getByte(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Byte object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public double getDouble(String key) {
+ Double d = getDouble(key, null);
+ if (d != null) {
+ return d.doubleValue();
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + "' doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public double getDouble(String key, double defaultValue) {
+ return getDouble(key, new Double(defaultValue)).doubleValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Double getDouble(String key, Double defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Double) {
+ return (Double) value;
+ } else if (value instanceof String) {
+ Double d = new Double((String) value);
+ return d;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getDouble(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Double object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public float getFloat(String key) {
+ Float f = getFloat(key, null);
+ if (f != null) {
+ return f.floatValue();
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + "' doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public float getFloat(String key, float defaultValue) {
+ return getFloat(key, new Float(defaultValue)).floatValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Float getFloat(String key, Float defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Float) {
+ return (Float) value;
+ } else if (value instanceof String) {
+ Float f = new Float((String) value);
+ return f;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getFloat(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Float object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public int getInt(String key) {
+ Integer i = getInteger(key, null);
+ if (i != null) {
+ return i.intValue();
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + "' doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public int getInt(String key, int defaultValue) {
+ Integer i = getInteger(key, null);
+
+ if (i == null) {
+ return defaultValue;
+ }
+
+ return i.intValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Integer getInteger(String key, Integer defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Integer) {
+ return (Integer) value;
+ } else if (value instanceof String) {
+ Integer i = new Integer((String) value);
+ return i;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getInteger(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Integer object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public long getLong(String key) {
+ Long l = getLong(key, null);
+ if (l != null) {
+ return l.longValue();
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + "' doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public long getLong(String key, long defaultValue) {
+ return getLong(key, new Long(defaultValue)).longValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Long getLong(String key, Long defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Long) {
+ return (Long) value;
+ } else if (value instanceof String) {
+ Long l = new Long((String) value);
+ return l;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getLong(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Long object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public short getShort(String key) {
+ Short s = getShort(key, null);
+ if (s != null) {
+ return s.shortValue();
+ } else {
+ throw new NoSuchElementException('\'' + key
+ + "' doesn't map to an existing object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public short getShort(String key, short defaultValue) {
+ return getShort(key, new Short(defaultValue)).shortValue();
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Short getShort(String key, Short defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof Short) {
+ return (Short) value;
+ } else if (value instanceof String) {
+ Short s = new Short((String) value);
+ return s;
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getShort(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Short object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public String getString(String key) {
+ return getString(key, null);
+ }
+
+ /**
+ * @see Configuration
+ */
+ public String getString(String key, String defaultValue) {
+ Object value = resolveVectorStore(key);
+
+ if (value instanceof String) {
+ return (String) value;
+
+ } else if (value == null) {
+ if (defaults != null) {
+ return defaults.getString(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a String object");
+ }
+ }
+
+ /**
+ * @see Configuration
+ */
+ public String[] getStringArray(String key) {
+ Object value = store.get(key);
+
+ String[] tokens;
+
+ if (value instanceof String) {
+ tokens = new String[1];
+ tokens[0] = (String) value;
+
+ } else if (value instanceof Vector) {
+ tokens = new String[((Vector) value).size()];
+
+ for (int i = 0; i < tokens.length; i++) {
+
+ tokens[i] = (String) ((Vector) value).get(i);
+ }
+
+ } else if (value == null) {
+ if (defaults != null) {
+ tokens = defaults.getStringArray(key);
+ } else {
+ tokens = new String[0];
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a String/Vector object");
+ }
+ return tokens;
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Vector getVector(String key) {
+ return getVector(key, null);
+ }
+
+ /**
+ * @see Configuration
+ */
+ public Vector getVector(String key, Vector defaultValue) {
+ Object value = store.get(key);
+ Vector v = null;
+
+ if (value instanceof String) {
+ v = new Vector(1);
+ v.addElement((String) value);
+
+ } else if (value == null) {
+ if (defaults != null) {
+ v = defaults.getVector(key, defaultValue);
+ } else {
+ v = ((defaultValue == null) ? new Vector() : defaultValue);
+ }
+ } else {
+ throw new ClassCastException('\'' + key
+ + "' doesn't map to a Vector object: " + value + ", a "
+ + value.getClass().getName());
+ }
+ return v;
+ }
+
+ /**
+ *
+ */
+ public String getBasePath() {
+ return this.basePath;
+ }
+
+ /**
+ *
+ */
+ public void setBasePath(String path) {
+ this.basePath = path;
+ }
+
+ /**
+ * Returns an object from the store described by the key. If the value is a
+ * Vector object, replace it with the first object in the container
+ *
+ * @param key
+ * The property key.
+ *
+ * @return value Value, transparently resolving a possible Vector
+ * dependency.
+ */
+ private Object resolveVectorStore(String key) {
+ Object value = store.get(key);
+ if (value != null && value instanceof Vector) {
+ value = ((Vector) value).get(0);
+ }
+ return value;
+ }
+
+}
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConnectionPool.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConnectionPool.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConnectionPool.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/ConnectionPool.java Wed May 23 02:29:03 2012
@@ -0,0 +1,338 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.db;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.sql.DataSource;
+
+public class ConnectionPool implements Runnable {
+ private long MAX_IDLE_TIME = 5 * 60 * 1000; // 5 minutes
+ private String driver, url, username, password, jdbcUrl;
+
+ private int initialConnections, maxConnections;
+
+ private boolean waitIfBusy;
+
+ private Vector availableConnections, busyConnections;
+
+ private boolean connectionPending = false;
+
+ private HashMap lastAccessTimeRecord = new HashMap();
+
+ private String urlType = "";
+
+ private DataSource datasource;
+
+ private boolean autoCommit = true;
+
+ private int transactionIsolation = Connection.TRANSACTION_NONE;
+
+ public ConnectionPool(String driver, String url, String username, String password, int initialConnections,
+ int maxConnections, boolean waitIfBusy) throws SQLException {
+ this(initialConnections, maxConnections, waitIfBusy);
+ this.driver = driver;
+ this.url = url;
+ this.username = username;
+ this.password = password;
+ urlType = "speratedURL";
+ createConnectionPool();
+ }
+
+ public ConnectionPool(String driver, String jdbcUrl, int initialConnections, int maxConnections,
+ boolean waitIfBusy, boolean autoCommit, int transactionIsolation) throws SQLException {
+ this(initialConnections, maxConnections, waitIfBusy);
+ this.driver = driver;
+ this.jdbcUrl = jdbcUrl;
+ urlType = "simpleURL";
+ this.autoCommit = autoCommit;
+ this.transactionIsolation = transactionIsolation;
+ createConnectionPool();
+ }
+
+ public ConnectionPool(String driver, String jdbcUrl, int initialConnections, int maxConnections, boolean waitIfBusy)
+ throws SQLException {
+ this(initialConnections, maxConnections, waitIfBusy);
+ this.driver = driver;
+ this.jdbcUrl = jdbcUrl;
+ urlType = "simpleURL";
+ createConnectionPool();
+ }
+
+ public ConnectionPool(DataSource dataSource, int initialConnections, int maxConnections, boolean waitIfBusy)
+ throws SQLException {
+ this(initialConnections, maxConnections, waitIfBusy);
+ urlType = "dataSource";
+ this.datasource = dataSource;
+ createConnectionPool();
+ }
+
+ protected ConnectionPool(int initialConnections, int maxConnections, boolean waitIfBusy) throws SQLException {
+ this.initialConnections = initialConnections;
+ this.maxConnections = maxConnections;
+ this.waitIfBusy = waitIfBusy;
+ if (initialConnections > maxConnections) {
+ initialConnections = maxConnections;
+ }
+ availableConnections = new Vector(initialConnections);
+ busyConnections = new Vector();
+ CleanUpThread cleanUpThread = new CleanUpThread();
+ new Thread(cleanUpThread).start();
+ }
+
+ private void createConnectionPool() throws SQLException {
+ for (int i = 0; i < initialConnections; i++) {
+ availableConnections.addElement(makeNewConnection());
+ }
+ }
+
+ public synchronized Connection getConnection() throws SQLException {
+ if (!availableConnections.isEmpty()) {
+ Connection existingConnection = (Connection) availableConnections.lastElement();
+ int lastIndex = availableConnections.size() - 1;
+ // System.out.println("ConnectionNo="+lastIndex);
+ availableConnections.removeElementAt(lastIndex);
+
+ long lastAccess = ((Long) lastAccessTimeRecord.get(existingConnection)).longValue();
+ // If connection on available list is closed (e.g.,
+ // it timed out), then remove it from available list
+ // and repeat the process of obtaining a connection.
+ // Also wake up threads that were waiting for a
+ // connection because maxConnection limit was reached.
+ if (existingConnection.isClosed()) {
+ notifyAll(); // Freed up a spot for anybody waiting
+ Connection connection = getConnection();
+ setTimeStamp(connection);
+ return (connection);
+ } else {
+ busyConnections.addElement(existingConnection);
+ setTimeStamp(existingConnection);
+ return existingConnection;
+ }
+ } else {
+ // Three possible cases:
+ // 1) You haven't reached maxConnections limit. So
+ // establish one in the background if there isn't
+ // already one pending, then wait for
+ // the next available connection (whether or not
+ // it was the newly established one).
+ // 2) You reached maxConnections limit and waitIfBusy
+ // flag is false. Throw SQLException in such a case.
+ // 3) You reached maxConnections limit and waitIfBusy
+ // flag is true. Then do the same thing as in second
+ // part of step 1: wait for next available connection.
+ if ((totalConnections() < maxConnections) && !connectionPending) {
+ makeBackgroundConnection();
+ } else if (!waitIfBusy) {
+ throw new SQLException("Connection limit reached");
+ }
+ // Wait for either a new connection to be established
+ // (if you called makeBackgroundConnection) or for
+ // an existing connection to be freed up.
+ try {
+ wait();
+ } catch (InterruptedException ie) {
+ }
+ // Someone freed up a connection, so try again.
+ Connection connection = getConnection();
+ setTimeStamp(connection);
+ return connection;
+ }
+ }
+
+ // You can't just make a new connection in the foreground
+ // when none are available, since this can take several
+ // seconds with a slow network connection. Instead,
+ // start a thread that establishes a new connection,
+ // then wait. You get woken up either when the new connection
+ // is established or if someone finishes with an existing
+ // connection.
+ private void makeBackgroundConnection() {
+ connectionPending = true;
+ try {
+ Thread connectThread = new Thread(this);
+ connectThread.start();
+ } catch (OutOfMemoryError oome) {
+ // Give up on new connection
+ }
+ }
+
+ public void run() {
+ try {
+ Connection connection = makeNewConnection();
+ synchronized (this) {
+ availableConnections.addElement(connection);
+ connectionPending = false;
+ notifyAll();
+ }
+ } catch (Exception e) { // SQLException or OutOfMemory
+ // Give up on new connection and wait for existing one
+ // to free up.
+ }
+ }
+
+ // This explicitly makes a new connection. Called in
+ // the foreground when initializing the ConnectionPool,
+ // and called in the background when running.
+ private Connection makeNewConnection() throws SQLException {
+ try {
+ // Load database driver if not already loaded
+ Class.forName(driver);
+ Connection connection;
+ // Establish network connection to database
+ if (urlType.equals("speratedURL")) {
+ connection = DriverManager.getConnection(url, username, password);
+ } else if (urlType.equals("simpleURL")) {
+ connection = DriverManager.getConnection(jdbcUrl);
+ } else { // if(urlType.equals("dataSource")){
+ connection = datasource.getConnection();
+
+ }
+ connection.setTransactionIsolation(this.transactionIsolation);
+ connection.setAutoCommit(this.autoCommit);
+ setTimeStamp(connection);
+ return connection;
+ } catch (ClassNotFoundException cnfe) {
+ // Simplify try/catch blocks of people using this by
+ // throwing only one exception type.
+ throw new SQLException("Can't find class for driver: " + driver);
+ }
+ }
+
+ private void setTimeStamp(Connection connection) {
+ lastAccessTimeRecord.put(connection, Long.valueOf(System.currentTimeMillis()));
+ }
+
+ // The database connection cannot be left idle for too long, otherwise TCP connection will be broken.
+ /**
+ * From http://forums.mysql.com/read.php?39,28450,57460#msg-57460 Okay, then it looks like wait_timeout on the
+ * server is killing your connection (it is set to 8 hours of idle time by default). Either set that value higher on
+ * your server, or configure your connection pool to not hold connections idle that long (I prefer the latter). Most
+ * folks I know that run MySQL with a connection pool in high-load production environments only let connections sit
+ * idle for a matter of minutes, since it only takes a few milliseconds to open a connection, and the longer one
+ * sits idle the more chance it will go "bad" because of a network hiccup or the MySQL server being restarted.
+ *
+ * @throws SQLException
+ */
+ private boolean isConnectionStale(Connection connection) throws SQLException {
+ long currentTime = System.currentTimeMillis();
+ long lastAccess = ((Long) lastAccessTimeRecord.get(connection)).longValue();
+ if (currentTime - lastAccess > MAX_IDLE_TIME) {
+ // connection.close();
+ // System.out.println("*************JDBC Connection Stale!");
+ return true;
+ } else
+ return false;
+ }
+
+ private void closeStaleConnections() throws SQLException {
+ // close idle connections
+ Iterator iter = availableConnections.iterator();
+ while (iter.hasNext()) {
+ Connection existingConnection = (Connection) iter.next();
+ if (isConnectionStale(existingConnection)) {
+ existingConnection.close();
+ iter.remove();
+ }
+ }
+ // close busy connections that have been checked out for too long.
+ // This should not happen sinc ethis means program has bug for not releasing connections .
+ iter = busyConnections.iterator();
+ while (iter.hasNext()) {
+ Connection busyConnection = (Connection) iter.next();
+ if (isConnectionStale(busyConnection)) {
+ iter.remove();
+ busyConnection.close();
+ System.out
+ .println("****Connection has checked out too long. Forced release. Check the program for unReleased connection.");
+ }
+ }
+ }
+
+ public synchronized void free(Connection connection) {
+ busyConnections.removeElement(connection);
+ availableConnections.addElement(connection);
+ // Wake up threads that are waiting for a connection
+ notifyAll();
+ }
+
+ public synchronized int totalConnections() {
+ return (availableConnections.size() + busyConnections.size());
+ }
+
+ /**
+ * Close all the connections. Use with caution: be sure no connections are in use before calling. Note that you are
+ * not <I>required</I> to call this when done with a ConnectionPool, since connections are guaranteed to be closed
+ * when garbage collected. But this method gives more control regarding when the connections are closed.
+ */
+ public synchronized void closeAllConnections() {
+ closeConnections(availableConnections);
+ availableConnections = new Vector();
+ closeConnections(busyConnections);
+ busyConnections = new Vector();
+ lastAccessTimeRecord.clear();
+ }
+
+ private void closeConnections(Vector connections) {
+ try {
+ for (int i = 0; i < connections.size(); i++) {
+ Connection connection = (Connection) connections.elementAt(i);
+ if (!connection.isClosed()) {
+ connection.close();
+ }
+ }
+ } catch (SQLException sqle) {
+ // Ignore errors; garbage collect anyhow
+ }
+ }
+
+ public synchronized String toString() {
+ String info = "ConnectionPool(" + url + "," + username + ")" + ", available=" + availableConnections.size()
+ + ", busy=" + busyConnections.size() + ", max=" + maxConnections;
+ return (info);
+ }
+
+ class CleanUpThread implements Runnable {
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(MAX_IDLE_TIME);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try {
+ closeStaleConnections();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/DBConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/DBConstants.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/DBConstants.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/DBConstants.java Wed May 23 02:29:03 2012
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.db;
+
+public abstract class DBConstants {
+
+ /****************************************************************
+ * Summary Table Information *
+ ****************************************************************/
+ public static final String T_SUMMARY_NAME = "summary";
+ public static final String T_SUMMARY_WORKFLOW_ID = "workflowid";
+ public static final String T_SUMMARY_TEMPLATE_ID = "templateid";
+ public static final String T_SUMMARY_STATUS = "status";
+ public static final String T_SUMMARY_END_TIME = "endTime";
+ public static final String T_SUMMARY_START_TIME = "startTime";
+ public static final String T_SUMMARY_USERNAME = "username";
+
+ /****************************************************************
+ * Faults Table Information *
+ ****************************************************************/
+ public static final String T_FAULTS_NAME = "faults";
+ public static final String T_FAULTS_ID = "id";
+ public static final String T_FAULTS_XML = "xml";
+ public static final String T_FAULTS_WORKFLOW_ID = "workflowid";
+
+}
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/JdbcStorage.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/JdbcStorage.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/JdbcStorage.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/db/JdbcStorage.java Wed May 23 02:29:03 2012
@@ -0,0 +1,142 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.db;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class JdbcStorage {
+ private ConfigurationParamsReader config;
+
+ // private String jdbcUrl=
+ // "jdbc:mysql://156.56.104.175:3306/wsnt?user=root";
+ private String jdbcUrl = null;;
+
+ private PreparedStatement stmt = null;
+
+ private ResultSet rs = null;
+
+ private ResultSetMetaData rsmd = null;
+
+ // private Connection conn = null;
+ private ConnectionPool connectionPool;
+
+ private String jdbcDriver;
+
+ public JdbcStorage(String fileName, boolean enableTransactions) {
+ config = new ConfigurationParamsReader(fileName);
+ jdbcUrl = config.getProperty("jdbcUrl");
+ jdbcDriver = config.getProperty("jdbcDriver");
+
+ try {
+ if (enableTransactions) {
+ connectionPool = new ConnectionPool(jdbcDriver, jdbcUrl, 10, 50, true, false,
+ Connection.TRANSACTION_SERIALIZABLE);
+ } else {
+ connectionPool = new ConnectionPool(jdbcDriver, jdbcUrl, 10, 50, true);
+ }
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ throw new RuntimeException("Failed to create database connection poll.", e);
+ }
+ }
+
+ public JdbcStorage(String fileName) {
+ this(fileName, false);
+
+ }
+
+ public Connection connect() throws SQLException {
+
+ Connection conn = connectionPool.getConnection();
+ return conn;
+ }
+
+ public void closeConnection(Connection conn) throws java.sql.SQLException {
+
+ connectionPool.free(conn);
+ }
+
+ public int update(String query) throws java.sql.SQLException {
+ int result = 0;
+ // connect();
+ Connection conn = connectionPool.getConnection();
+ stmt = conn.prepareStatement(query);
+ result = stmt.executeUpdate();
+ stmt.close();
+ connectionPool.free(conn);
+
+ return result;
+ }
+
+ /**
+ * This method is provided so that yo can have better control over the statement. For example: You can use
+ * stmt.setString to convert quotation mark automatically in an INSERT statement
+ */
+ public int insert(PreparedStatement stmt) throws java.sql.SQLException {
+ int rows = 0;
+
+ rows = stmt.executeUpdate();
+ stmt.close();
+ return rows;
+ }
+
+ public int insert(String query) throws java.sql.SQLException {
+ int rows = 0;
+
+ Connection conn = connectionPool.getConnection();
+ stmt = conn.prepareStatement(query);
+ rows = stmt.executeUpdate();
+ stmt.close();
+ connectionPool.free(conn);
+
+ return rows;
+ }
+
+ public ResultSet query(String query) throws SQLException {
+ Connection conn = connectionPool.getConnection();
+ // Create a scrollable ResultSet so that I can use rs.last() to get
+ // total number of rows without using another COUNT in SQL query
+ Statement lstmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ ResultSet rs = lstmt.executeQuery(query);
+ connectionPool.free(conn);
+ return rs;
+ }
+
+ public int countRow(String tableName, String columnName) throws java.sql.SQLException {
+ String query = new String("SELECT COUNT(" + columnName + ") FROM " + tableName);
+ Connection conn = connectionPool.getConnection();
+ stmt = conn.prepareStatement(query);
+ rs = stmt.executeQuery();
+ rs.next();
+ int count = rs.getInt(1);
+ stmt.close();
+ connectionPool.free(conn);
+ return count;
+ }
+
+}
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowStartedStatusHandler.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowStartedStatusHandler.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowStartedStatusHandler.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowStartedStatusHandler.java Wed May 23 02:29:03 2012
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.status;
+
+import org.apache.airavata.tools.workflow.monitoring.Server;
+import org.apache.airavata.tools.workflow.monitoring.ServerContext;
+import org.apache.airavata.tools.workflow.monitoring.SummeryDB;
+import org.apache.airavata.tools.workflow.monitoring.Util;
+
+import wsmg.NotificationHandler;
+import xsul.MLogger;
+
+public class WorkflowStartedStatusHandler implements NotificationHandler {
+
+ private static MLogger log = MLogger.getLogger();
+
+ private ServerContext context;;
+
+ private SummeryDB summeryTbl;
+
+ public WorkflowStartedStatusHandler(ServerContext context) {
+ this.context = context;
+ this.summeryTbl = new SummeryDB(context.getDatabase());
+ }
+
+ public void handleNotification(String message) {
+
+ String workflowID = Util.getInitialID(message);
+ if (null != workflowID) {
+ log.finest("Adding workflowStarted entry " + message);
+ this.context.removeWorkflow(workflowID);
+ this.summeryTbl.insert(workflowID, null, Util.getDN(message));
+ }else{
+ log.warning("Got null for workflow started"+message);
+ }
+
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowTerminatedHandler.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowTerminatedHandler.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowTerminatedHandler.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/main/java/org/apache/airavata/tools/workflow/monitoring/status/WorkflowTerminatedHandler.java Wed May 23 02:29:03 2012
@@ -0,0 +1,61 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.status;
+
+import org.apache.airavata.tools.workflow.monitoring.Server;
+import org.apache.airavata.tools.workflow.monitoring.ServerContext;
+import org.apache.airavata.tools.workflow.monitoring.StatusConstants;
+import org.apache.airavata.tools.workflow.monitoring.SummeryDB;
+import org.apache.airavata.tools.workflow.monitoring.Util;
+import org.apache.airavata.tools.workflow.monitoring.db.JdbcStorage;
+
+import sun.security.acl.WorldGroupImpl;
+import wsmg.NotificationHandler;
+import xsul.MLogger;
+
+public class WorkflowTerminatedHandler implements NotificationHandler, StatusConstants {
+
+ private static MLogger log = MLogger.getLogger();
+
+ private ServerContext context;
+
+ private SummeryDB summeryTbl;
+
+ public WorkflowTerminatedHandler(ServerContext context) {
+ this.context = context;
+ this.summeryTbl = new SummeryDB(context.getDatabase());
+ }
+
+ public void handleNotification(String message) {
+
+ String workflowID = Util.getWorkflowID(message, Server.WORKFLOW_TERMINATED, "serviceID");
+ if (workflowID != null) {
+ this.summeryTbl.edit(workflowID, STATUS_SUCCESSFUL);
+ this.context.removeWorkflow(workflowID);
+ log.finest("Adding Finished entry " + message);
+ } else {
+ log.warning("goat a null workflowid for terminated handler" + message);
+ }
+
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/DatabseTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/DatabseTest.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/DatabseTest.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/DatabseTest.java Wed May 23 02:29:03 2012
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.test;
+
+import org.apache.airavata.tools.workflow.monitoring.Server;
+import org.apache.airavata.tools.workflow.monitoring.SummeryDB;
+import org.apache.airavata.tools.workflow.monitoring.db.JdbcStorage;
+import junit.framework.TestCase;
+
+public class DatabseTest extends TestCase {
+
+ public void testDatabaseInsert() {
+ // new FaultMessagesDB(new JdbcStorage(Server.DB_CONFIG_NAME, true)).insert(PublishSendingFaultTest.workflowID,
+ // PublishSendingFaultTest.message);
+ SummeryDB summeryDB = new SummeryDB(new JdbcStorage(Server.DB_CONFIG_NAME, true));
+ summeryDB.insert("testid", null, null);
+ summeryDB.edit("testid", "TERMINATED");
+ }
+}
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/MonitorTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/MonitorTest.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/MonitorTest.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/MonitorTest.java Wed May 23 02:29:03 2012
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.test;
+
+import wsmg.WseClientAPI;
+import org.apache.airavata.tools.workflow.monitoring.Server;
+import junit.framework.TestCase;
+
+public class MonitorTest extends TestCase {
+
+ public static final String brokerurl = "http://127.0.0.1:8888";
+ public static String message = "<wor:monitorWorkflow "
+ + "xmlns:wor=\"http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking\">"
+ + "<wor:notificationSource " + "wor:serviceID=\"urn:qname:http://www.extreme.indiana.edu/lead:WCS\""
+ + "wor:workflowID=\"tag:gpel.leadproject.org,2006:6BD/WRFForecastWithADASInitializedData/instance7155555\""
+ + "wor:workflowTimestep=\"18\" wor:workflowNodeID=\"WCS\" />"
+ + "<wor:monitoringDuration>12</wor:monitoringDuration>" + "<wor:emailTo>cherath@indiana.edu</wor:emailTo>"
+ + "<wor:timestamp>2007-01-20T10:53:28-05:00</wor:timestamp>" + "</wor:monitorWorkflow>";
+
+ public void testMonitor() {
+ // Server.main(null);
+ WseClientAPI client = new WseClientAPI();
+ client.publish(brokerurl, Server.monitoringTopic, message);
+ }
+
+}
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/PublishSendingFaultTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/PublishSendingFaultTest.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/PublishSendingFaultTest.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/PublishSendingFaultTest.java Wed May 23 02:29:03 2012
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.test;
+
+import org.apache.airavata.tools.workflow.monitoring.Server;
+import wsmg.WseClientAPI;
+import junit.framework.TestCase;
+
+public class PublishSendingFaultTest extends TestCase {
+
+ public static String workflowID = "tag:gpel.leadproject.org,2006:6BD/WRFForecastWithADASInitializedData/instance71";
+
+ public static String message = "<wor:sendingFault "
+ + "xmlns:wor=\"http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking\">"
+ + "<wor:notificationSource"
+ + " wor:serviceID=\"urn:qname:http://www.extreme.indiana.edu/lead:WRF_Forecasting_Model_Service\""
+ + " wor:workflowID=\"tag:gpel.leadproject.org,2006:71N/TestCISimpleEchoWorkflow/instance36\""
+ + " wor:workflowTimestep=\"18\"" + " wor:workflowNodeID=\"WRF_Forecasting_Model_Service\" />" +
+
+ "</wor:sendingFault>";
+
+ public void testPublish() {
+ WseClientAPI client = new WseClientAPI();
+ client.publish(MonitorTest.brokerurl, "anytopic-since-we-use-xpath", message);
+ }
+
+}
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowIDParsingTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowIDParsingTest.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowIDParsingTest.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowIDParsingTest.java Wed May 23 02:29:03 2012
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.test;
+
+import org.apache.airavata.tools.workflow.monitoring.Server;
+import org.apache.airavata.tools.workflow.monitoring.Util;
+import junit.framework.TestCase;
+
+public class WorkflowIDParsingTest extends TestCase {
+
+ public static String TEST_ENVELOP = "<S:Envelope " + "xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ + "<S:Body>" + PublishSendingFaultTest.message + "</S:Body>" + "</S:Envelope>";
+
+ public void testPasringWOrkflowID() {
+ assertEquals(PublishSendingFaultTest.workflowID,
+ Util.getWorkflowID(TEST_ENVELOP, Server.SENDING_FAULT, "workflowID"));
+ }
+}
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowLifeCycleTest.java
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowLifeCycleTest.java?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowLifeCycleTest.java (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/src/test/java/org/apache/airavata/tools/workflow/monitoring/test/WorkflowLifeCycleTest.java Wed May 23 02:29:03 2012
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.airavata.tools.workflow.monitoring.test;
+
+import wsmg.WseClientAPI;
+import junit.framework.TestCase;
+
+public class WorkflowLifeCycleTest extends TestCase {
+
+ private String worklowTerminated = "<wor:workflowTerminated xmlns:wor='http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking'><wor:notificationSource wor:serviceID='tag:gpel.leadproject.org,2006:71N/TestCISimpleEchoWorkflow/instance36'/><wor:timestamp>2007-02-05T00:21:33-05:00</wor:timestamp></wor:workflowTerminated>";
+ private String worklowStarted = "<wor:workflowInitialized xmlns:wor='http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking'><wor:notificationSource wor:serviceID='tag:gpel.leadproject.org,2006:71N/TestCISimpleEchoWorkflow/instance36'/><wor:timestamp>2007-02-04T23:57:20-05:00</wor:timestamp></wor:workflowInitialized>";
+
+ public void testStartWorkflow() {
+ WseClientAPI client = new WseClientAPI();
+ client.publish(MonitorTest.brokerurl, "anytopic-since-we-use-xpath", worklowStarted);
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/web/META-INF/context.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/web/META-INF/context.xml?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/web/META-INF/context.xml (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/web/META-INF/context.xml Wed May 23 02:29:03 2012
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context path="/">
+</Context>
Added: incubator/airavata/sandbox/workflow-monitoring-util/web/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/web/WEB-INF/web.xml?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/web/WEB-INF/web.xml (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/web/WEB-INF/web.xml Wed May 23 02:29:03 2012
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
+
+</web-app>
Added: incubator/airavata/sandbox/workflow-monitoring-util/web/build.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/web/build.xml?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/web/build.xml (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/web/build.xml Wed May 23 02:29:03 2012
@@ -0,0 +1,84 @@
+<?xml version="1.0"?>
+
+<project name="project" default="war">
+ <description>
+ description
+ </description>
+ <property name="lib.dir" value="../lib"/>
+ <property name="build.dir" value="./build"/>
+ <property name="src.dir" value="./src"/>
+ <property name="build.dest" value="${build.dir}/classes"/>
+ <property name="build.lib" value="./build/lib"/>
+
+ <path id="classpath">
+
+ <fileset dir="${lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="../build/lib">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <target name="clean">
+ <delete dir="${build.dir}"/>
+ </target>
+ <target name="setenv">
+ <mkdir dir="${build.lib}"/>
+ <mkdir dir="${build.dest}"/>
+ </target>
+
+ <target name="compile" depends="setenv">
+ <javac srcdir="${src.dir}" destdir="${build.dest}" debug="${debug}" deprecation="${deprecation}"
+ classpathref="classpath">
+
+ </javac>
+ </target>
+ <target name="war" depends="compile">
+ <mkdir dir="${build.dir}/XWorkflows"/>
+ <mkdir dir="${build.dir}/XWorkflows/WEB-INF"/>
+ <mkdir dir="${build.dir}/XWorkflows/WEB-INF/classes"/>
+ <mkdir dir="${build.dir}/XWorkflows/WEB-INF/lib"/>
+ <mkdir dir="${build.dir}/XWorkflows/jsp"/>
+ <copy todir="${build.dir}/XWorkflows">
+ <fileset dir="resources"/>
+ </copy>
+ <copy todir="${build.dir}/XWorkflows/WEB-INF/classes">
+ <fileset dir="src">
+ <include name="db.config"/>
+ </fileset>
+ </copy>
+ <copy todir="${build.dir}/XWorkflows/jsp">
+ <fileset dir="jsp"/>
+ </copy>
+ <copy todir="${build.dir}/XWorkflows/WEB-INF/classes">
+ <fileset dir="${build.dest}"/>
+ </copy>
+ <copy todir="${build.dir}/XWorkflows/WEB-INF/lib">
+ <fileset dir="${lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="../build/lib">
+ <include name="*.jar"/>
+ </fileset>
+ </copy>
+ <jar jarfile="${build.dir}/XWorkflows.war" basedir="${build.dir}/XWorkflows">
+ <include name="**"/>
+ </jar>
+ </target>
+
+ <!-- =================================
+ target: default
+ ================================= -->
+ <target name="default" depends="depends" description="--> description">
+
+ </target>
+
+ <!-- - - - - - - - - - - - - - - - - -
+target: depends
+- - - - - - - - - - - - - - - - - -->
+ <target name="depends">
+ </target>
+
+</project>
+
Added: incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowById.jsp
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowById.jsp?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowById.jsp (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowById.jsp Wed May 23 02:29:03 2012
@@ -0,0 +1,117 @@
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.QueryManager" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.WorkflowMonitoringException" %>
+<%@ page import="java.io.InputStream" %>
+<%@ page import="java.sql.Blob" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="java.util.ArrayList" %>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head><title> :: Workflow Information ::</title></head>
+<body>
+<% String workflowId = request.getParameter("workflowId");
+ // proceed only if there is a workflow id
+ if (workflowId != null && !"".equals(workflowId)) {
+
+%>
+
+<h2 align="center"> Wokflow information for the id <%= workflowId%>
+</h2>
+<%
+ /**
+ * This is how this will work. First I retrieve data from the databse for the given Wokflow id. The page will
+ * first list message number with links to the messages. This was not to clutter the page with lot of data.
+ * I first retrieve all the messages and store them in an array list. During the first iteration I print the links
+ * to the messages as well.
+ * After this, during the second iteration, I retrieve the stored messages and print them out with proper bookmark
+ * tages
+ */
+ ArrayList messages = new ArrayList();
+ QueryManager queryManager = new QueryManager();
+
+ // try to retrieve data from the database for the given id
+ ResultSet workflowData = null;
+ int i;
+ try {
+ workflowData = queryManager.getDataRelatesToWorkflowId(workflowId);
+%>
+<table cellspacing="1" cellpadding="3" border="0" width="100%">
+ <%
+
+ int resultsCounter = 0;
+ while (workflowData.next()) {
+
+ // retrieving data from the database
+ Blob xmlBlob = workflowData.getBlob("xml");
+
+ InputStream in = xmlBlob.getBinaryStream();
+ StringBuffer xmlMessage = new StringBuffer();
+
+ int read;
+
+ byte[] buf = new byte[1024];
+ while ((read = in.read(buf)) > 0) {
+ xmlMessage.append(new String(buf, 0, read));
+ }
+ in.close();
+
+ // storing the retreived message
+ messages.add(xmlMessage.toString());
+ %>
+ <!-- Adding links to the messages-->
+ <tr>
+ <td><a href="#message" <%= ++resultsCounter %> /> Message <%=resultsCounter%>
+ </td>
+ </tr>
+ <%
+ }
+ queryManager.close();
+
+ %>
+
+</table>
+
+<% if (messages.isEmpty()) {
+%>
+<h5> There are no fault messages for the Wokflow id <%= workflowId%>
+</h5>
+<%
+} else {
+%>
+<table>
+ <%
+ // now let's display the messages here
+ for (int j = 0; j < messages.size(); j++) {
+ %>
+ <tr bgcolor="#dbeaf5">
+ <td><a name="#message" <%=j%> /> <%=messages.get(j) %>
+ </td>
+ </tr>
+
+ <% }
+ %>
+</table>
+<%
+ }
+} catch (WorkflowMonitoringException e) {
+ e.printStackTrace();
+%>
+<p>An error occurred while processing this request</p>
+<%
+
+ }
+%>
+
+
+<%
+} else {
+%>
+
+<h3> There is no information for the workflow id <%=workflowId%>
+</h3>
+<%
+ }
+%>
+
+</body>
+</html>
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByTimes.jsp
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByTimes.jsp?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByTimes.jsp (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByTimes.jsp Wed May 23 02:29:03 2012
@@ -0,0 +1,160 @@
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.QueryManager" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.WorkflowMonitoringException" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.bean.WorkflowInfo" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.db.DBConstants" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.util.Util" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="java.sql.SQLException" %>
+<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.Collections" %>
+<%@ page import="java.util.HashMap" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Map" %>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+ <title> :: Workflow Information :: </title>
+</head>
+<body>
+
+<%
+ try {
+
+
+ String startTimeString = request.getParameter("startTime");
+
+ long startDate = Util.getTime(startTimeString);
+ long endDate = -1;
+
+ String endTimeString = request.getParameter("endTime");
+ if (endTimeString != null && !"".equals(endTimeString)) {
+ endDate = Util.getTime(endTimeString);
+ }
+
+ QueryManager queryManager = new QueryManager();
+ ResultSet workflowData = queryManager.getWorkflowsWithinTimeRange(startDate, endDate);
+%>
+
+<h2 align="center">Wokflow Information</h2>
+
+<%
+ if (endDate != -1) {
+%>
+<h3>Time Range : <%=startTimeString%> and <%=endTimeString%>
+</h3>
+<%
+} else {
+%>
+<h3>Start Time : <%=startTimeString%>
+</h3>
+<%
+ }
+%>
+
+<br/>
+<br/>
+<br/>
+
+<table cellspacing="1" cellpadding="3" border="0" width="100%">
+ <tr>
+ <th bgcolor="#4682B4"><font color="#ffffff">Wokflow Id</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Template Id</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Username</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Status</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Start Time</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">End Time</font></th>
+ </tr>
+ <%
+
+ String endTime;
+
+ Map<String, WorkflowInfo> workflowInfoObjects = new HashMap<String, WorkflowInfo>();
+
+ while (workflowData.next()) {
+ WorkflowInfo workflow = new WorkflowInfo();
+ workflow.setStatus(workflowData.getString(DBConstants.T_SUMMARY_STATUS));
+ workflow.setTemplateId(workflowData.getString(DBConstants.T_SUMMARY_TEMPLATE_ID));
+ workflow.setUsername(workflowData.getString(DBConstants.T_SUMMARY_USERNAME));
+ String workflowId = workflowData.getString(DBConstants.T_SUMMARY_WORKFLOW_ID);
+ workflow.setWorkflowId(workflowId);
+ workflow.setStartTime(Util.getFormattedDateFromLongValue(workflowData.getString(DBConstants.T_SUMMARY_START_TIME)));
+
+ endTime = workflowData.getString(DBConstants.T_SUMMARY_END_TIME);
+ if (endTime != null && !"".equals(endTime) && !"0".equals(endTime.trim())) {
+ endTime = Util.getFormattedDateFromLongValue(endTime);
+ } else {
+ endTime = "";
+ }
+ workflow.setEndTime(endTime);
+ workflow.setFaultsAvailable("FAILED".equalsIgnoreCase(workflow.getStatus()));
+ workflowInfoObjects.put(workflowId, workflow);
+ }
+
+ ResultSet resultSet = queryManager.getPreviouslyFailedSuccessfulInstances(startDate, endDate);
+
+ if (resultSet != null) {
+ while (resultSet.next()) {
+ String workflowId = resultSet.getString(DBConstants.T_SUMMARY_WORKFLOW_ID);
+ if (workflowInfoObjects.containsKey(workflowId)) {
+ workflowInfoObjects.get(workflowId).setFaultsAvailable(true);
+ }
+ }
+ }
+
+ queryManager.close();
+
+ List<WorkflowInfo> workflowObjectsList = new ArrayList<WorkflowInfo>();
+ for (WorkflowInfo workflowInfo : workflowInfoObjects.values()) {
+ workflowObjectsList.add(workflowInfo);
+ }
+ Collections.sort(workflowObjectsList);
+
+ for (WorkflowInfo workflowInfo : workflowObjectsList) {
+ %>
+ <tr bgcolor="#dbeaf5">
+
+ <td>
+ <%
+ if (workflowInfo.isFaultsAvailable()) {
+ %>
+ <a href="findWorkFlowById.jsp?workflowId=<%=workflowInfo.getWorkflowId()%>"><%=workflowInfo.getWorkflowId()%>
+ </a>
+ <%
+ } else {
+ %>
+ <%=workflowInfo.getWorkflowId()%>
+ <%
+ }
+ %>
+ </td>
+ <td><%=workflowInfo.getTemplateId()%>
+ </td>
+ <td><%=workflowInfo.getUsername()%>
+ </td>
+ <td><%=workflowInfo.getStatus()%>
+ </td>
+ <td><%=workflowInfo.getStartTime()%>
+ </td>
+ <td><%=workflowInfo.getEndTime()%>
+ </td>
+ </tr>
+ <%
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ %>
+ <h4>An error occurred while retreiving data. Please retry later.</h4>
+ <%
+ } catch (WorkflowMonitoringException e) {
+ e.printStackTrace();
+ %>
+ <h4>An error occurred while parsing input data. Make sure all the dates are in mm/dd/yyyy HH.mm format.</h4>
+ <%
+ }
+
+ %>
+</table>
+</body>
+</html>
\ No newline at end of file
Added: incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByUser.jsp
URL: http://svn.apache.org/viewvc/incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByUser.jsp?rev=1341732&view=auto
==============================================================================
--- incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByUser.jsp (added)
+++ incubator/airavata/sandbox/workflow-monitoring-util/web/jsp/findWorkFlowByUser.jsp Wed May 23 02:29:03 2012
@@ -0,0 +1,139 @@
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.QueryManager" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.WorkflowMonitoringException" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.bean.WorkflowInfo" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.db.DBConstants" %>
+<%@ page import="org.apache.airavata.tools.workflow.monitoring.util.Util" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="java.sql.SQLException" %>
+<%@ page import="java.util.HashMap" %>
+<%@ page import="java.util.Map" %>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+ <title> :: Workflow Information :: </title>
+</head>
+<body>
+
+<%
+ try {
+
+
+ String username = request.getParameter("username");
+
+ QueryManager queryManager = new QueryManager();
+ ResultSet workflowData = queryManager.getWorkflowsOfUser(username);
+%>
+
+<h2 align="center">Workflow Information for <%=username%>
+</h2>
+
+<br/>
+<br/>
+<br/>
+
+<table cellspacing="1" cellpadding="3" border="0" width="100%">
+ <tr>
+ <th bgcolor="#4682B4"><font color="#ffffff">Wokflow Id</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Template Id</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Username</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Status</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">Start Time</font></th>
+ <th bgcolor="#4682B4"><font color="#ffffff">End Time</font></th>
+ </tr>
+ <%
+
+
+ if (workflowData == null) {
+ %>
+ <h3> No worflow information available for this user </h3>
+ <%
+
+ } else {
+
+ String endTime;
+
+ Map<String, WorkflowInfo> workflowInfoObjects = new HashMap<String, WorkflowInfo>();
+
+ while (workflowData.next()) {
+ WorkflowInfo workflow = new WorkflowInfo();
+ workflow.setStatus(workflowData.getString(DBConstants.T_SUMMARY_STATUS));
+ workflow.setTemplateId(workflowData.getString(DBConstants.T_SUMMARY_TEMPLATE_ID));
+ workflow.setUsername(workflowData.getString(DBConstants.T_SUMMARY_USERNAME));
+ String workflowId = workflowData.getString(DBConstants.T_SUMMARY_WORKFLOW_ID);
+ workflow.setWorkflowId(workflowId);
+ workflow.setStartTime(Util.getFormattedDateFromLongValue(workflowData.getString(DBConstants.T_SUMMARY_START_TIME)));
+
+ endTime = workflowData.getString(DBConstants.T_SUMMARY_END_TIME);
+ if (endTime != null && !"".equals(endTime) && !"0".equals(endTime.trim())) {
+ endTime = Util.getFormattedDateFromLongValue(endTime);
+ } else {
+ endTime = "";
+ }
+ workflow.setEndTime(endTime);
+ workflow.setFaultsAvailable("FAILED".equalsIgnoreCase(workflow.getStatus()));
+ workflowInfoObjects.put(workflowId, workflow);
+ }
+
+ ResultSet resultSet = queryManager.getPreviouslyFailedSuccessfulInstances(username);
+
+ if (resultSet != null) {
+ while (resultSet.next()) {
+ String workflowId = resultSet.getString(DBConstants.T_SUMMARY_WORKFLOW_ID);
+ if (workflowInfoObjects.containsKey(workflowId)) {
+ workflowInfoObjects.get(workflowId).setFaultsAvailable(true);
+ }
+ }
+ }
+
+ queryManager.close();
+
+
+ for (WorkflowInfo workflowInfo : workflowInfoObjects.values()) {
+ %>
+ <tr bgcolor="#dbeaf5">
+
+ <td>
+ <%
+ if (workflowInfo.isFaultsAvailable()) {
+ %>
+ <a href="findWorkFlowById.jsp?workflowId=<%=workflowInfo.getWorkflowId()%>"><%=workflowInfo.getWorkflowId()%>
+ </a>
+ <%
+ } else {
+ %>
+ <%=workflowInfo.getWorkflowId()%>
+ <%
+ }
+ %>
+ </td>
+ <td><%=Util.extractShortTemplateId(workflowInfo.getTemplateId())%>
+ </td>
+ <td><%=Util.extractUsername(workflowInfo.getUsername())%>
+ </td>
+ <td><%=workflowInfo.getStatus()%>
+ </td>
+ <td><%=workflowInfo.getStartTime()%>
+ </td>
+ <td><%=workflowInfo.getEndTime()%>
+ </td>
+ </tr>
+ <%
+ }
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ %>
+ <h4>An error occurred while retreiving data. Please retry later.</h4>
+ <%
+ } catch (WorkflowMonitoringException e) {
+ e.printStackTrace();
+ %>
+ <h4>An error occurred while parsing input data. Make sure all the dates are in mm/dd/yyyy HH.mm format.</h4>
+ <%
+ }
+
+ %>
+</table>
+</body>
+</html>
\ No newline at end of file