incubator-lokahi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tob...@apache.org
Subject svn commit: r392982 [13/25] - in /incubator/lokahi/lokahi/trunk: ./ conf/ database/ docs/ lib/ src/ src/java/ src/java/lokahi/ src/java/lokahi/core/ src/java/lokahi/core/agent/ src/java/lokahi/core/agent/callable/ src/java/lokahi/core/agent/callable/co...
Date Mon, 10 Apr 2006 16:20:11 GMT
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCConstants.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCConstants.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCConstants.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCConstants.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,37 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCConstants.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface TMCConstants {
+  String SESSION_LOGGED_IN_OBJ_PARAM = "User";
+  String LOGOUT_PARAM = "logout";
+  String FORWARD_LOGGED_OUT = "application.forward.login";
+  String FORWARD_APPLICATION_ERROR = "application.forward.error";
+  String FORWARD_APPLICATION_SUCCESS = "application.forward.administration.success";
+  String METHOD_PARAM = "methodToCall";
+  String METHOD_ADD = "add";
+  String METHOD_UPDATE = "update";
+  String METHOD_DELETE = "delete";
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCDao.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCDao.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCDao.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCDao.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,28 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.interfaces;
+
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCDao.java,v 1.2 2006/03/07 22:05:24 drtobes Exp $
+ */
+public abstract class TMCDao<T extends TMCDao> extends RestObject implements Dao<T>, Collectable {
+  public abstract T get(int id) throws SQLException;
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCMessage.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCMessage.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCMessage.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCMessage.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,29 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCMessage.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface TMCMessage {
+  boolean send();
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/XMLDao.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/XMLDao.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/XMLDao.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/XMLDao.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,28 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.interfaces;
+
+import org.jdom.Element;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: XMLDao.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public abstract class XMLDao<T extends XMLDao> extends TMCDao<T> {
+  public abstract T fillObject(Element el);
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/Message.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/Message.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/Message.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/Message.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,31 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.message;
+
+import lokahi.core.common.exception.UnsupportedParameterException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Message.java,v 1.2 2006/03/07 20:18:54 drtobes Exp $
+ */
+public interface Message {
+  String send(String[] obj, boolean hasAttachement, String... params) throws UnsupportedParameterException;
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/MessageFactory.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/MessageFactory.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/MessageFactory.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/MessageFactory.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,34 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.message;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: MessageFactory.java,v 1.1 2006/03/02 19:19:48 drtobes Exp $
+ */
+public class MessageFactory {
+  private MessageFactory() {
+  }
+
+  public static Message getTransport() {
+    return new TMCSOAPMessage();
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/TMCSOAPMessage.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/TMCSOAPMessage.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/TMCSOAPMessage.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/message/TMCSOAPMessage.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,188 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.message;
+
+import lokahi.core.common.exception.UnsupportedParameterException;
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.apache.axis.encoding.XMLType;
+import org.apache.log4j.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.rpc.ParameterMode;
+import javax.xml.rpc.ServiceException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCSOAPMessage.java,v 1.2 2006/03/07 20:18:54 drtobes Exp $
+ */
+public class TMCSOAPMessage implements Message {
+  static final Logger logger = Logger.getLogger(TMCSOAPMessage.class);
+
+  public TMCSOAPMessage() {
+    logger.error("Being Constructed....");
+  }
+  // "JobHandler",  "create"
+
+  //endpoint, String namespace, String method
+
+  public String send(String[] params, boolean hasAttachment, String... objs) throws UnsupportedParameterException {
+    if (logger.isDebugEnabled()) {
+      logger.debug("SENDING JOB!!!!!!");
+    }
+    String retVal = "";
+
+    try {
+      retVal = this.sendMessage(params, hasAttachment, objs);
+    } catch (MalformedURLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (RemoteException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (ServiceException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (UnsupportedParameterException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+
+    return retVal;
+  }
+
+  // Params: endpoint, namespace, method
+  // Params: endpoint, namespace, method, fileContent
+  public String sendMessage(String[] params, boolean hasAttachment, String... objs) throws ServiceException, MalformedURLException, UnsupportedOperationException, RemoteException, UnsupportedParameterException {
+    if (logger.isDebugEnabled()) {
+      logger.debug("SENDING JOB!!!!!!");
+    }
+    String retVal = "";
+    Service service = new Service(); // A new axis Service.
+    Call call = (Call) service.createCall(); // Create a call to the
+    // service.
+    if (logger.isDebugEnabled()) {
+      logger.debug("params[0]=" + params[0]);
+    }
+    call.setTargetEndpointAddress(new URL(params[0]));
+    if (logger.isDebugEnabled()) {
+      logger.debug("params.length=" + params.length);
+      logger.debug("hasAttachment=" + hasAttachment);
+    }
+    if (hasAttachment) {
+      if (params.length < 4) {
+        throw new UnsupportedParameterException("Not enough parameters passed");
+      }
+      retVal = this.buildWithAttach(call, objs, params[1], params[2], params[3]);
+    } else {
+      if (params.length < 3) {
+        throw new UnsupportedParameterException("Not enough parameters passed");
+      }
+      retVal = this.buildNoAttach(call, objs, params[1], params[2]);
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug(" retVal=" + retVal);
+    }
+
+    return retVal;
+  }
+
+  private Call buildCallArgs(Call call, String namespace, String method, String... obj) {
+    return this.buildCallArgs(call, false, namespace, method, obj);
+  }
+
+  private Call buildCallArgs(Call call, boolean withAttach, String namespace, String method, String... obj) {
+    int modifier = 1;
+    if (withAttach) modifier++;
+    call.setOperationName(new QName(namespace, method));
+    for (int i = 0; i < obj.length; i++) {
+      call.addParameter("arg" + (i + modifier), XMLType.XSD_STRING, ParameterMode.IN);
+    }
+    return call;
+  }
+
+  private String buildNoAttach(Call call, String[] objs, String namespace, String method) throws UnsupportedOperationException, RemoteException {
+    String retVal = "";
+    call = buildCallArgs(call, namespace, method, objs);
+    if (logger.isDebugEnabled()) {
+      logger.debug("getting here?");
+    }
+
+    try {
+      call.setReturnType(XMLType.XSD_STRING);
+      retVal = (String) call.invoke(objs);
+    } catch (RemoteException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug(" retVal=" + retVal);
+    }
+    return retVal;
+  }
+
+  private String buildWithAttach(Call call, String[] objs, String namespace, String method, String fileContent) {
+    String retVal = "";
+    byte fcontent[];
+    ByteArrayInputStream bais = null;
+
+    try {
+      fcontent = fileContent.getBytes("UTF-8");
+      //Uncomment following to use a Stream to obtain bytes: transferring binary data
+      //bais = new ByteArrayInputStream(fileContent.getBytes("UTF-8");
+      //fcontent = new byte[bais.available()];
+      //bais.read(fcontent);
+
+      //change argument" arg1 for position of use within parameters
+      call.addParameter("arg1", XMLType.XSD_BASE64, ParameterMode.IN);
+      call = this.buildCallArgs(call, true, namespace, method, objs);
+      call.setReturnType(XMLType.XSD_ANY);
+      //addToArray(objs,fcontent);
+      retVal = (String) call.invoke(addFirstToArray(fcontent, objs));
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+
+    return retVal;
+  }
+
+  private Object[] addFirstToArray(Object o, String... objs) {
+    Object[] objArray = new Object[objs.length + 1];
+    objArray[0] = o;
+    int cnt = 1;
+    for (Object object : objs) {
+      objArray[cnt] = object;
+      cnt++;
+    }
+    return objArray;
+  }
+
+//	public String sendMessage(JobTransmission jt) {}
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/DateComparator.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/DateComparator.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/DateComparator.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/DateComparator.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,37 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.util;
+
+import lokahi.core.common.interfaces.Datable;
+
+import java.util.Comparator;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: DateComparator.java,v 1.3 2006/03/07 20:18:57 drtobes Exp $
+ */
+public class DateComparator<ItemType extends Datable> implements Comparator<ItemType> {
+  public int compare(final ItemType x, final ItemType y) {
+    int ret = 0;
+    ret = y.getSortOnDate().compareTo(x.getSortOnDate());
+    return ret;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/PropertiesFile.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/PropertiesFile.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/PropertiesFile.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/PropertiesFile.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,130 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.util;
+
+import org.apache.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: PropertiesFile.java,v 1.1 2006/03/02 19:19:49 drtobes Exp $
+ */
+public class PropertiesFile {
+  static final Logger logger = Logger.getLogger(PropertiesFile.class);
+
+  private static Properties actionProperties = new Properties();
+
+  // constructor
+  private PropertiesFile() {
+  }
+
+  public static void load(InputStream i) {
+    try {
+      actionProperties.load(i);
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  public static void load(String s) {
+    try {
+      actionProperties.load(new ByteArrayInputStream(s.getBytes()));
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  //###############  SET METHODS #################
+  public static void setConstantValue(String name, String val) {
+    actionProperties.setProperty(name, val);
+  }
+
+  /**
+   * This method gets the value of the property supplied, from the properties file.
+   * If the property is not present, it returns an empty string
+   */
+  public static String getConstantValue(String propertyName) {
+    String ret = "";
+    if (actionProperties != null) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("actionProperties.getProperty(" + propertyName + ") = " + actionProperties.getProperty(propertyName));
+      }
+      ret = actionProperties.getProperty(propertyName);
+      if (!"".equals(actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName)) && actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName) != null)
+      {
+        ret = actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName);
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("ret=" + ret);
+    }
+    return ret;
+  } // end getConstantValue
+
+  /**
+   * This method gets the value of the property supplied, from the properties file.
+   * If the property is not present, it returns an empty string
+   */
+  public static int getIntValue(String propertyName) {
+    int ret = -1;
+    if (actionProperties != null) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("actionProperties.getProperty(" + propertyName + ") = " + actionProperties.getProperty(propertyName));
+      }
+      ret = Integer.parseInt(actionProperties.getProperty(propertyName));
+    }
+    return ret;
+  } // end getIntValue
+
+  /**
+   * This method gets the value of the property supplied, from the properties file.
+   * If the property is not present, it returns an empty string
+   */
+  public static boolean getBooleanValue(String propertyName) {
+    boolean ret = false;
+    if (actionProperties != null) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("actionProperties.getProperty(" + propertyName + ") = " + actionProperties.getProperty(propertyName));
+        logger.debug("actionProperties.getProperty(" + System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName + ")=" + actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName));
+      }
+      if (!"".equals(actionProperties.getProperty(propertyName))) {
+        ret = Boolean.getBoolean(actionProperties.getProperty(propertyName));
+      }
+      if (!"".equals(actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName)) && actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName) != null)
+      {
+        ret = "true".equals(actionProperties.getProperty(System.getProperty("PHYSICAL_LOCATION") + '.' + propertyName));
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("ret=" + ret);
+    }
+    return ret;
+  } // end getIntValue
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/TMCVelocityViewTool.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/TMCVelocityViewTool.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/TMCVelocityViewTool.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/TMCVelocityViewTool.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,1035 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.util;
+
+import lokahi.core.api.environment.Environment;
+import lokahi.core.api.file.File;
+import lokahi.core.api.function.Function;
+import lokahi.core.api.instance.Instance;
+import lokahi.core.api.ipaddress.Ip;
+import lokahi.core.api.job.Job;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.pool.HostingPool;
+import lokahi.core.api.project.Project;
+import lokahi.core.api.server.Hardware;
+import lokahi.core.api.state.State;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCCollectionImpl;
+import lokahi.httpd.api.entity.VirtualHost;
+import lokahi.httpd.api.pool.ApachePool;
+import lokahi.httpd.api.server.Apache;
+import lokahi.httpd.api.worker.ApacheWorker;
+import lokahi.tomcat.api.entity.TomcatContext;
+import lokahi.tomcat.api.pool.TomcatPool;
+import lokahi.tomcat.api.server.Tomcat;
+import lokahi.tomcat.api.worker.TomcatWorker;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.TreeMap;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCVelocityViewTool.java,v 1.4 2006/03/07 19:52:11 drtobes Exp $
+ */
+public class TMCVelocityViewTool {
+  static final Logger logger = Logger.getLogger(TMCVelocityViewTool.class);
+
+  //helper methods for the static methods (for velocity)
+
+  /** @deprecated  */
+  public Collection<Project> getProjectBeginsWith(String name) {
+    Collection<Project> c = null;
+    try {
+      c = Project.getProjects(name.trim() + '%');
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public Collection<Project> getProjectEndsWith(String name) {
+    Collection<Project> c = null;
+    try {
+      c = Project.getProjects('%' + name.trim());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public Collection<Project> getProjectContains(String name) {
+    Collection<Project> c = null;
+    try {
+      c = Project.getProjects('%' + name.trim() + '%');
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public Collection<Project> getProjectByName(String name) {
+    Collection<Project> c = null;
+    try {
+      c = Project.getProjects(name.trim());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public TreeMap<String, TreeMap<Integer, Job>> getRunningJobs() throws SQLException {
+    Collection<Job> c = Job.getJobs(Instance.getInstance(2, true), State.getState(0));
+//    c.addAll(Job.getJobs(Instance.getInstance(2), State.getState(0)));
+    TreeMap<String, TreeMap<Integer, Job>> tm = new TreeMap<String, TreeMap<Integer, Job>>();
+    TreeMap<Integer, Job> tm2 = new TreeMap<Integer, Job>();
+    for (final Job j : c) {
+      if (j.getHardware() != null) {
+        if (tm.keySet().contains(j.getHardware().getName())) {
+          tm2 = tm.get(j.getHardware().getName());
+        }
+        tm2.put(j.getPk(), j);
+        tm.put(j.getHardware().getName(), (TreeMap<Integer, Job>) tm2.clone());
+        tm2.clear();
+      }
+    }
+    return tm;
+  }
+
+  /** @deprecated  */
+  public JobPool getJobPool(int id) {
+    JobPool jp = null;
+    try {
+      jp = JobPool.getJobPool(id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return jp;
+  }
+
+  /** @deprecated  */
+  public JobPool getJobPool(String id) {
+    JobPool jp = null;
+    try {
+      jp = JobPool.getJobPool(Integer.parseInt(id));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return jp;
+  }
+
+  /** @deprecated  */
+  public Collection<HostingPool> getHostingPools() {
+    TMCCollectionImpl<HostingPool> c = new TMCCollectionImpl<HostingPool>();
+    try {
+      c.addAll(HostingPool.getHostingPools());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<HostingPool> getHostingPools(ApachePool ap) {
+    TMCCollectionImpl<HostingPool> c = new TMCCollectionImpl<HostingPool>();
+    try {
+      c.addAll(HostingPool.getHostingPools(ap, true));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<HostingPool> getHostingPools(TomcatPool tp) {
+    TMCCollectionImpl<HostingPool> c = new TMCCollectionImpl<HostingPool>();
+    try {
+      c.addAll(HostingPool.getHostingPools(tp, true));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public HostingPool getHostingPool(String id) {
+    HostingPool hp = null;
+    if (!"".equals(id)) {
+      try {
+        hp = HostingPool.getHostingPool(Integer.parseInt(id), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return hp;
+  }
+
+  public Collection<HostingPool> searchHostingPools(String name) {
+    TMCCollectionImpl<HostingPool> c = new TMCCollectionImpl<HostingPool>();
+    name = '%' + name.trim() + '%';
+    try {
+      c.addAll(HostingPool.getHostingPools(name, true));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public Collection<ApachePool> getApachePools() {
+    TMCCollectionImpl<ApachePool> c = new TMCCollectionImpl<ApachePool>();
+    try {
+      c.addAll(ApachePool.getApachePools());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<ApachePool> getApachePools(ApacheWorker aw) {
+    TMCCollectionImpl<ApachePool> c = new TMCCollectionImpl<ApachePool>();
+    try {
+      c.addAll(ApachePool.getApachePools(aw));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<ApachePool> searchApachePools(String name) {
+    name = '%' + name.trim() + '%';
+    TMCCollectionImpl<ApachePool> c = new TMCCollectionImpl<ApachePool>();
+    try {
+      c.addAll(ApachePool.getApachePools(name));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public ApachePool getApachePool(String id) {
+    ApachePool ap = null;
+    if (!"".equals(id)) {
+      try {
+        ap = ApachePool.getApachePool(Integer.parseInt(id));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return ap;
+  }
+
+  public Collection<Function> getFunctions() {
+    TMCCollectionImpl<Function> c = new TMCCollectionImpl<Function>();
+    try {
+      c.addAll(Function.getFunctions());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public Function getFunctionByCommand(String name) {
+    Function f = null;
+    if (!"".equals(name)) {
+      f = Function.getFunction(name);
+    }
+    return f;
+  }
+
+  /** @deprecated  */
+  public Function getFunction(String id) {
+    Function f = null;
+    if (!"".equals(id)) {
+//      try {
+      f = Function.getFunction(Integer.parseInt(id));
+//      } catch (SQLException e) {
+//        if (logger.isInfoEnabled()) {
+//          logger.info("Exception: " + e.getMessage());
+//        }
+//      }
+    }
+    return f;
+  }
+
+  /** @deprecated  */
+  public Collection<TomcatPool> getTomcatPools() {
+    TMCCollectionImpl<TomcatPool> c = new TMCCollectionImpl<TomcatPool>();
+    try {
+      c.addAll(TomcatPool.getTomcatPools());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<TomcatPool> getTomcatPools(TomcatWorker tw) {
+    TMCCollectionImpl<TomcatPool> c = new TMCCollectionImpl<TomcatPool>();
+    try {
+      c.addAll(TomcatPool.getTomcatPools(tw));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<TomcatPool> searchTomcatPools(String name) {
+    TMCCollectionImpl<TomcatPool> c = new TMCCollectionImpl<TomcatPool>();
+    name = '%' + name.trim() + '%';
+    try {
+      c.addAll(TomcatPool.getTomcatPools(name));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public TomcatPool getTomcatPool(String id) {
+    TomcatPool tp = null;
+    if (!"".equals(id)) {
+      try {
+        tp = TomcatPool.getTomcatPool(Integer.parseInt(id));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return tp;
+  }
+
+  /** @deprecated  */
+  public Collection<Tomcat> getTomcats() {
+    TMCCollectionImpl<Tomcat> c = new TMCCollectionImpl<Tomcat>();
+    try {
+      c.addAll(Tomcat.getTomcats());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<Tomcat> searchTomcats(String name) {
+    TMCCollectionImpl<Tomcat> c = new TMCCollectionImpl<Tomcat>();
+    name = '%' + name.trim() + '%';
+    try {
+      c.addAll(Tomcat.getTomcats(name, true));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public Tomcat getTomcat(String id) {
+    Tomcat tc = null;
+    if (!"".equals(id)) {
+      try {
+        tc = Tomcat.getTomcat(Integer.parseInt(id), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return tc;
+  }
+
+  /** @deprecated  */
+  public Collection<TomcatWorker> getTomcatWorkers() {
+    TMCCollectionImpl<TomcatWorker> c = new TMCCollectionImpl<TomcatWorker>();
+    try {
+      c.addAll(TomcatWorker.getTomcatWorkers(false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<TomcatWorker> getTomcatWorkers(Tomcat t) {
+    TMCCollectionImpl<TomcatWorker> c = new TMCCollectionImpl<TomcatWorker>();
+    try {
+      c.addAll(TomcatWorker.getTomcatWorkers(t, false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<TomcatWorker> searchTomcatWorkers(String name) {
+    TMCCollectionImpl<TomcatWorker> c = new TMCCollectionImpl<TomcatWorker>();
+    name = '%' + name.trim() + '%';
+    try {
+      c.addAll(TomcatWorker.getTomcatWorkers(name, false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public TomcatWorker getTomcatWorker(String id) {
+    TomcatWorker tc = null;
+    if (!"".equals(id)) {
+      try {
+        tc = TomcatWorker.getTomcatWorker(Integer.parseInt(id), false);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    } else {
+      if (logger.isDebugEnabled()) {
+        logger.debug("User is not allowed to view worker.");
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("tc=" + tc);
+    }
+    return tc;
+  }
+
+  /** @deprecated  */
+  public Hardware getHardware(String id) {
+    Hardware h = null;
+    if (!"".equals(id)) {
+      try {
+        h = Hardware.getHardware(Integer.parseInt(id), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return h;
+  }
+
+  /** @deprecated  */
+  public Collection<Hardware> getHardwares() {
+    TMCCollectionImpl<Hardware> c = new TMCCollectionImpl<Hardware>();
+    try {
+      c.addAll(Hardware.getHardwares());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<Hardware> searchHardwares(String name) {
+    name = '%' + name.trim() + '%';
+    TMCCollectionImpl<Hardware> c = new TMCCollectionImpl<Hardware>();
+    try {
+      c.addAll(Hardware.getHardwares(name, true));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public Collection<Apache> getApaches() {
+    TMCCollectionImpl<Apache> c = new TMCCollectionImpl<Apache>();
+    try {
+      c.addAll(Apache.getApaches());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<Apache> searchApaches(String name) {
+    name = '%' + name.trim() + '%';
+    TMCCollectionImpl<Apache> c = new TMCCollectionImpl<Apache>();
+    try {
+      c.addAll(Apache.getApaches(name, true));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public Apache getApache(String id) {
+    Apache ap = null;
+    if (!"".equals(id)) {
+      try {
+        ap = Apache.getApache(Integer.parseInt(id), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return ap;
+  }
+
+  /** @deprecated  */
+  public Collection<ApacheWorker> getApacheWorkers() {
+    TMCCollectionImpl<ApacheWorker> c = new TMCCollectionImpl<ApacheWorker>();
+    try {
+      c.addAll(ApacheWorker.getApacheWorkers(false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<ApacheWorker> searchApacheWorkers(String name) {
+    name = '%' + name.trim() + '%';
+    TMCCollectionImpl<ApacheWorker> c = new TMCCollectionImpl<ApacheWorker>();
+    try {
+      c.addAll(ApacheWorker.getApacheWorkers(name, false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public ApacheWorker getApacheWorker(String id) {
+    ApacheWorker ap = null;
+    if (!"".equals(id)) {
+      try {
+        ap = ApacheWorker.getApacheWorker(Integer.parseInt(id), false);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return ap;
+  }
+
+  /** @deprecated  */
+  public Collection<State> getStates() {
+    Collection<State> c = null;
+    try {
+      c = State.getStates();
+      if (c instanceof TMCCollectionImpl) {
+        c = ((TMCCollectionImpl<State>) c).orderByName().values();
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public State getState(String id) {
+    State s = null;
+    if (!"".equals(id)) {
+      s = State.getState(Integer.parseInt(id));
+    }
+    return s;
+  }
+
+  /** @deprecated  */
+  public Collection<Environment> getEnvironments() {
+    Collection<Environment> c = null;
+    try {
+      c = Environment.getEnviroments();
+      if (c instanceof TMCCollectionImpl) {
+        c = ((TMCCollectionImpl<Environment>) c).orderByName().values();
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + c);
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public Environment getEnvironment(String id) {
+    Environment e = null;
+    if (!"".equals(id)) {
+      try {
+        e = Environment.getEnviroment(Integer.parseInt(id), true);
+      } catch (SQLException e1) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e1.getMessage());
+        }
+      }
+    }
+    return e;
+  }
+
+  /** @deprecated  */
+  public Collection<Instance> getInstances() {
+    Collection<Instance> c = null;
+    try {
+      c = Instance.getInstances();
+      if (c instanceof TMCCollectionImpl) {
+        c = ((TMCCollectionImpl<Instance>) c).orderByName().values();
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public Instance getInstance(String id) {
+    Instance i = null;
+    if (!"".equals(id)) {
+      try {
+        i = Instance.getInstance(Integer.parseInt(id), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return i;
+  }
+
+  /** @deprecated  */
+  public Collection<File> getFiles() {
+    Collection<File> c = null;
+    try {
+      c = File.getFiles();
+      if (c instanceof TMCCollectionImpl) {
+        c = ((TMCCollectionImpl<File>) c).orderByName().values();
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public File getFile(String id) {
+    File file = null;
+    if (!"".equals(id)) {
+      try {
+        file = File.getFile(Integer.parseInt(id));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return file;
+  }
+
+  /** @deprecated  */
+  public Collection<User> getUsers() {
+    TMCCollectionImpl<User> c = new TMCCollectionImpl<User>();
+    try {
+      c.addAll(User.getAllUsers());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public TreeMap<String, User> getUsersSorted() {
+    Collection<User> c = null;
+    try {
+      c = User.getAllUsers();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    TreeMap<String, User> tm = new TreeMap<String, User>();
+    if (c != null) {
+      for (final User u : c) {
+        tm.put(u.getName(), u);
+      }
+    }
+    return tm;
+  }
+
+  /** @deprecated  */
+  public User getUserById(String id) {
+    User user = null;
+    if (!"".equals(id)) {
+      try {
+        user = User.getUser(Integer.parseInt(id));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return user;
+  }
+
+  /** @deprecated  */
+  public Collection<Ip> getIps() {
+    Collection<Ip> c = null;
+    try {
+      c = Ip.getIps();
+      if (c instanceof TMCCollectionImpl) {
+        c = ((TMCCollectionImpl<Ip>) c).orderByName().values();
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  /** @deprecated  */
+  public Ip getIp(String id) {
+    Ip i = null;
+    if (!"".equals(id)) {
+      try {
+        i = Ip.getIp(Integer.parseInt(id), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return i;
+  }
+
+  /** @deprecated  */
+  public Collection<VirtualHost> getVirtualHosts() {
+    TMCCollectionImpl<VirtualHost> c = new TMCCollectionImpl<VirtualHost>();
+    try {
+      c.addAll(VirtualHost.getVirtualHosts());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  public Collection<VirtualHost> searchVirtualHosts(String name) {
+    name = '%' + name.trim() + '%';
+    TMCCollectionImpl<VirtualHost> c = new TMCCollectionImpl<VirtualHost>();
+    try {
+      c.addAll(VirtualHost.getVirtualHosts(name));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c.orderByName().values();
+  }
+
+  /** @deprecated  */
+  public VirtualHost getVirtualHost(String id) {
+    VirtualHost vh = null;
+    if (!"".equals(id)) {
+      try {
+        vh = VirtualHost.getVirtualHost(Integer.parseInt(id));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return vh;
+  }
+
+  /** @deprecated  */
+  public Collection<TomcatContext> getContexts() {
+    Collection<TomcatContext> c = null;
+    TreeMap<String, TomcatContext> tm = new TreeMap<String, TomcatContext>();
+    try {
+      c = TomcatContext.getTomcatContexts();
+      for (final TomcatContext tc : c) {
+        tm.put(tc.getName() + " - " + tc.getTomcatPool().getName(), tc);
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return tm.values();
+  }
+
+  public Collection<TomcatContext> searchContexts(String name) {
+    Collection<TomcatContext> c = null;
+    name = '%' + name.trim() + '%';
+    TreeMap<String, TomcatContext> tm = new TreeMap<String, TomcatContext>();
+    try {
+      c = TomcatContext.getTomcatContexts(name);
+      for (final TomcatContext tc : c) {
+        tm.put(tc.getName() + " - " + tc.getTomcatPool().getName(), tc);
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return tm.values();
+  }
+
+  /** @deprecated  */
+  public TomcatContext getContext(String id) {
+    TomcatContext tc = null;
+    if (!"".equals(id)) {
+      try {
+        tc = TomcatContext.getTomcatContext(Integer.parseInt(id));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return tc;
+  }
+//end helper methods.
+
+  public TMCCollectionImpl<VirtualHost> getVirtualHosts(User u, ApacheWorker aw) {
+    TMCCollectionImpl<VirtualHost> ret = new TMCCollectionImpl<VirtualHost>();
+    if (u.isAllowed("ViewVirtualHost"))
+      try {
+        ret.addAll(VirtualHost.getVirtualHosts(aw));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return ret;
+  }
+
+  public TMCCollectionImpl<VirtualHost> getVirtualHosts(User u, ApachePool ap) {
+    TMCCollectionImpl<VirtualHost> ret = new TMCCollectionImpl<VirtualHost>();
+    if (u.isAllowed("ViewVirtualHost"))
+      try {
+        Collection<HostingPool> hps = HostingPool.getHostingPools(ap, true);
+        for (HostingPool hp : hps) {
+          ret.addAll(VirtualHost.getVirtualHosts(hp));
+        }
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return ret;
+  }
+
+  public TMCCollectionImpl<VirtualHost> getVirtualHosts(User u, HostingPool hp) {
+    TMCCollectionImpl<VirtualHost> ret = new TMCCollectionImpl<VirtualHost>();
+    if (u.isAllowed("ViewVirtualHost"))
+      try {
+        ret.addAll(VirtualHost.getVirtualHosts(hp));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return ret;
+  }
+
+  public TMCCollectionImpl<TomcatContext> getTomcatContexts(User u, TomcatWorker tw) {
+    TMCCollectionImpl<TomcatContext> ret = new TMCCollectionImpl<TomcatContext>();
+    if (u.isAllowed("ViewContext"))
+      try {
+        ret.addAll(TomcatContext.getTomcatContexts(tw));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return ret;
+  }
+
+  public TMCCollectionImpl<TomcatContext> getTomcatContexts(User u, TomcatPool tp) {
+    TMCCollectionImpl<TomcatContext> ret = new TMCCollectionImpl<TomcatContext>();
+    if (u.isAllowed("ViewContext"))
+      try {
+        ret.addAll(TomcatContext.getTomcatContexts(tp));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return ret;
+  }
+
+  public Collection<TomcatContext> getTomcatContexts(User u, HostingPool hp) {
+    TMCCollectionImpl<TomcatContext> ret = new TMCCollectionImpl<TomcatContext>();
+    if (u.isAllowed("ViewContext"))
+      try {
+        if (hp != null && hp.getTomcatPool() != null)
+          ret.addAll(TomcatContext.getTomcatContexts(hp.getTomcatPool()));
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    return ret;
+  }
+
+  public TMCCollectionImpl<TomcatWorker> getTomcatWorkers(Hardware h) {
+    TMCCollectionImpl<TomcatWorker> ret = new TMCCollectionImpl<TomcatWorker>();
+    try {
+      ret.addAll(TomcatWorker.getTomcatWorkers(h, false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public TMCCollectionImpl<ApacheWorker> getApacheWorkers(Hardware h) {
+    TMCCollectionImpl<ApacheWorker> ret = new TMCCollectionImpl<ApacheWorker>();
+    try {
+      ret.addAll(ApacheWorker.getApacheWorkers(h, false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public TMCCollectionImpl<ApacheWorker> getApacheWorkers(Apache a) {
+    TMCCollectionImpl<ApacheWorker> ret = new TMCCollectionImpl<ApacheWorker>();
+    try {
+      ret.addAll(ApacheWorker.getApacheWorkers(a, false));
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public TMCCollectionImpl<JobPool> getJobPools(int userId, String filter, String startDate, String endDate, int... functionIds) {
+    TMCCollectionImpl<JobPool> ret = null;
+    User u = null;
+    Date start = null;
+    Date end = null;
+    Function[] functions = null;
+    try {
+      if (userId > 0) {
+        u = User.getUser(userId);
+      }
+      if (filter == null) {
+        filter = "";
+      }
+      filter = '%' + filter + '%';
+      SimpleDateFormat sdf = new SimpleDateFormat();
+      if (startDate != null && !"".equals(startDate)) {
+        start = sdf.parse(startDate);
+      }
+      if (endDate != null && !"".equals(endDate)) {
+        end = sdf.parse(endDate);
+      }
+      if (functionIds != null) {
+        functions = new Function[functionIds.length];
+        for (int i = 0; i < functionIds.length; i++) {
+          functions[i] = Function.getFunction(functionIds[i]);
+        }
+      }
+      ret = JobPool.getJobPools(u, start, end, filter, functions);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.debug("SQLException:" + e);
+      }
+    } catch (ParseException e) {
+      if (logger.isInfoEnabled()) {
+        logger.debug("ParseException:" + e);
+      }
+    }
+    return ret;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/WapTool.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/WapTool.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/WapTool.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/util/WapTool.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,97 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.common.util;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.instance.Instance;
+import lokahi.core.api.pool.HostingPool;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.httpd.api.pool.ApachePool;
+import lokahi.httpd.api.worker.ApacheWorker;
+import lokahi.tomcat.api.pool.TomcatPool;
+import lokahi.tomcat.api.worker.TomcatWorker;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: WapTool.java,v 1.4 2006/03/07 19:52:11 drtobes Exp $
+ */
+public class WapTool {
+  static final Logger logger = Logger.getLogger(WapTool.class);
+
+  public Collection getObjects(String type, String name, Instance i) {
+    name = '%' + name + '%';
+    Collection ret = null;
+    try {
+      if ("ApacheWorker".equalsIgnoreCase(type)) {
+        ret = ApacheWorker.getApacheWorkers(name, i, false);
+      } else if ("tomcatWorker".equalsIgnoreCase(type)) {
+        ret = TomcatWorker.getTomcatWorkers(name, i, false);
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public Collection getObjects(String type, String name) {
+    name = '%' + name + '%';
+    Collection ret = null;
+    try {
+      if ("ApachePool".equalsIgnoreCase(type)) {
+        ret = ApachePool.getApachePools(name);
+      } else if ("TomcatPool".equalsIgnoreCase(type)) {
+        ret = TomcatPool.getTomcatPools(name);
+      } else if ("ApacheWorker".equalsIgnoreCase(type)) {
+        ret = ApacheWorker.getApacheWorkers(name, false);
+      } else if ("tomcatWorker".equalsIgnoreCase(type)) {
+        ret = TomcatWorker.getTomcatWorkers(name, false);
+      } else if ("hostingpool".equalsIgnoreCase(type)) {
+        ret = HostingPool.getHostingPools(name, true);
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public Collection<Function> getFunctions(String type, User u) {
+    String temp = PropertiesFile.getConstantValue("wap.function." + type);
+    Collection<Function> ret = new TMCSet<Function>();
+    if (temp != null && !"".equals(temp)) {
+      String[] commands = temp.split(",");
+      for (final String command : commands) {
+        Function f = null;
+        f = Function.getFunction(command);
+        if (f != null && u.isAllowed(f)) {
+          ret.add(f);
+        }
+      }
+    }
+    return ret;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/AdminBean.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/AdminBean.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/AdminBean.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/AdminBean.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,237 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+/**
+ * @author Stephen Toback
+ * @version $Id: AdminBean.java,v 1.1 2006/03/07 19:52:00 drtobes Exp $
+ */
+
+package lokahi.core.controller;
+
+import lokahi.core.api.instance.Instance;
+import lokahi.core.common.database.ConnBean;
+import lokahi.core.common.util.PropertiesFile;
+import oracle.jdbc.driver.OracleTypes;
+import oracle.sql.ARRAY;
+import oracle.sql.STRUCT;
+import org.apache.log4j.Logger;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class AdminBean {  //todo scrap this entire thing
+  static final Logger logger = Logger.getLogger(AdminBean.class);
+
+  /** connection bean used to get and return connections to/from the pool */
+  private static final ConnBean connBean = new ConnBean();
+  /** Stored procedure that returns the relevant info about jvms */
+  private static final String stored_proc = "f_get_admin_info(?)";
+  private static Instance instance;
+  /**
+   * Owner of the database schema
+   * This is the oracle userid that owns all the DB schema associated with this package
+   */
+  private static final String schema_owner = PropertiesFile.getConstantValue("tmc.database.user");
+
+  /** Constructor */
+  public AdminBean() {
+  }
+
+  public Instance getInstance() {
+    Instance ret = instance;
+    if (instance == null && !"".equals(PropertiesFile.getConstantValue("tmc.instance.name"))) {
+      try {
+        instance = Instance.getInstance(PropertiesFile.getConstantValue("tmc.instance.name"), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    ret = instance;
+    return ret;
+  }
+
+  /**
+   * This method returns a hashtable of the information retrieved from database.
+   *
+   * @return Hashtable - keys of this hashtable are 'PRIMARY', 'BACKUP' and 'ALTERNATE' and the values are the
+   *         respective values of these admin JVMs in the database
+   */
+  public Hashtable getAllAdminInfo() {
+    Connection conn = null;
+    boolean fromDb = false;
+    if (conn == null) {
+      try {
+        conn = connBean.getConn();
+        fromDb = true;
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        conn = null;
+      }
+    }
+
+    if (conn == null) {
+      return null;
+    }
+
+    Hashtable contHash = new Hashtable();
+    CallableStatement csmt;
+    try {
+      csmt = conn.prepareCall("{? = call  " + schema_owner + "." + stored_proc + "}");
+
+      csmt.registerOutParameter(1, OracleTypes.ARRAY, "BI_LIST");
+      csmt.setInt(2, this.getInstance().getPk());
+      csmt.execute();
+
+      // returns rows with 2 fields
+      // let us build a hashtable out of this, with first field as hashtable key and 2nd as value for this key
+      // retrieve the array as an oracle array
+      ARRAY arr = (ARRAY) csmt.getObject(1);
+      ResultSet rs = arr.getResultSet();
+      while (rs.next()) {
+        STRUCT obj = (STRUCT) rs.getObject(2);
+
+        Object attrs[] = obj.getAttributes();
+        String val1 = (attrs[0] != null) ? (String) attrs[0] : null;
+        String val2 = (attrs[1] != null) ? (String) attrs[1] : "";
+        if (val1 != null) {
+          // overwrite the key if it already exists
+          contHash.put(val1, val2);
+        }
+      } // while rs.next
+      csmt.close();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      contHash = null;
+    } finally {
+      if (fromDb) connBean.returnConn(conn);
+    }
+    return contHash;
+  } // end getAllAdminInfo
+
+  /**
+   * This method changes the role of the machine:port supplied to primary/backup or alternate
+   *
+   * @param admin_jvms - Hashtable with keys PRIMARY, BACKUP AND ALTERNATE, and values are
+   *                   respectively the machine:agentport combination to be updated in the database
+   */
+  public void changeJvmAdminRole(Hashtable admin_jvms) {
+    Connection conn = null;
+    boolean fromDb = false;
+    if (conn == null) {
+      try {
+        conn = connBean.getConn();
+        fromDb = true;
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        return;
+      }
+    }
+
+    if (conn == null) {
+      //Null Database Connection
+      return;
+    }
+
+    // check the alternate jvm string to make sure we are not using the same machine:jvm pair again..
+    String alternate = "";
+    String altstr = (String) admin_jvms.get("ALTERNATE");
+    Hashtable used = new Hashtable();
+
+    if (altstr != null && !altstr.equals("")) {
+      String temp[] = split(altstr, ","); // array of alt_host:port
+      for (int t = 0; t < temp.length; t++) {
+        try {
+          if (temp[t] != null && !temp[t].equals("")) {
+
+            if (!used.containsKey(temp[t])) {
+              used.put(temp[t], "1");
+
+              // if this host:port is to be made primary/backup, do not add it to alternate
+              if (!temp[t].equalsIgnoreCase((String) admin_jvms.get("PRIMARY")) &&
+                  !temp[t].equalsIgnoreCase((String) admin_jvms.get("BACKUP")))
+                alternate += "," + temp[t];
+            }
+          }
+        } catch (ArrayIndexOutOfBoundsException ae) {
+        }
+      } // for each alternate
+    } else {
+      // no need to do anything..
+    }
+
+    // remove leading comma if any
+    if (alternate.startsWith(",")) alternate = alternate.substring(1);
+
+    CallableStatement csmt;
+    try {
+      csmt = conn.prepareCall("{call " + schema_owner + ".sp_update_admin_jvm_role(?,?,?,?)}");
+      csmt.setString(1, (String) admin_jvms.get("PRIMARY")); // primary
+      csmt.setString(2, (String) admin_jvms.get("BACKUP")); // backup
+      csmt.setString(3, alternate); // alternate
+      csmt.setInt(4, this.getInstance().getPk());
+      csmt.execute();
+      csmt.close();
+
+      conn.commit();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } finally {
+      if (fromDb) connBean.returnConn(conn);
+      return;
+    }
+  } // end changeJvmAdminRole
+
+  /**
+   * This method takes a String and returns a String array, by splitting on the delimiter supplied
+   *
+   * @param str   - String to be split
+   * @param delim - delimiter to split the String on
+   *
+   * @return - array of Strings, got by splitting the String passed
+   */
+  public String[] split(String str, String delim) {
+    Vector v = new Vector();  //todo make this a collection.
+
+    StringTokenizer st = new StringTokenizer(str, delim);
+    while (st.hasMoreTokens()) v.addElement(st.nextToken().trim());
+
+    String[] array = new String[v.size()];
+    v.copyInto(array);
+
+    return array;
+  } // end split
+
+} // end AdminBean
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/CheckJvmThread.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/CheckJvmThread.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/CheckJvmThread.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/CheckJvmThread.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,465 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package lokahi.core.controller;
+/**
+ * @author Stephen Toback
+ * @version $Id: CheckJvmThread.java,v 1.2 2006/03/07 20:18:51 drtobes Exp $
+ */
+
+import lokahi.core.api.job.Job;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.common.exception.UnsupportedParameterException;
+import lokahi.core.common.message.Message;
+import lokahi.core.common.message.MessageFactory;
+import lokahi.core.common.util.PropertiesFile;
+import lokahi.core.controller.task.SendJobTask;
+import org.apache.log4j.Logger;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class CheckJvmThread extends Thread {
+  public static final Logger logger = Logger.getLogger(CheckJvmThread.class);
+
+  // my host name
+  private static final String hostname;
+  private static ThreadPoolExecutor tpe;
+
+  // jvmHttp value
+  private static String jvmHttp;
+
+  private static lokahi.core.api.state.State state;
+//  private static tmc.dao.State sentState;
+
+  private static final String myContext;
+
+  // Protocol used to check for the status of the machine:jvmagent
+  private static final String protocol;
+
+  // status page to check if the application is available. The thread makes a http request to http://machine:jvmagent/statusPage
+  // If this page is available, it considers the target machine:jvm pair to be available, else it is considered not available,
+  // and this thread takes that place.
+  // This JSP/servlet must be the absolute path from context path
+  private static final String statusPage;
+
+  // connection bean
+
+  public static final String contentMatch = PropertiesFile.getConstantValue("tmc.thread.contentmatch");
+
+  // variable that determines whether to run the thread or not. If this is false and the main thread
+  // is running, it stops all child threads, destroys the pool and stops running.
+  private static volatile boolean runThread = false;
+
+  // Handle to the AdminBean class
+  private static final AdminBean adminBean;
+
+  // Number of seconds to sleep between successive runs
+  private static final int sleeptime = PropertiesFile.getIntValue("tmc.thread.waittime"); // in seconds
+
+  static {
+    final int corePoolSize = 5;  //5
+    final int maximumPoolSize = 20;  //20
+    final long keepAliveTime = 300;  //how long till existing idle threads are killed
+
+    tpe = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(25));
+    state = lokahi.core.api.state.State.getState(0);
+    myContext = PropertiesFile.getConstantValue("application.root");
+    protocol = PropertiesFile.getConstantValue("tmc.thread.protocol");
+    statusPage = PropertiesFile.getConstantValue("tmc.thread.statuspage");
+    adminBean = new AdminBean();
+    String hostName = "";
+    try {
+      InetAddress inet = InetAddress.getLocalHost();
+      hostName = inet.getHostName();
+      if (logger.isDebugEnabled()) {
+        logger.debug("hostname=" + hostName);
+      }
+    } catch (UnknownHostException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("UnknownHostException: " + e.getMessage());
+      }
+    }
+    hostname = hostName;
+
+  }
+
+  /** Returns a handle to the main thread. sets the jvmHttp value to the value passed */
+  public static CheckJvmThread getThreadInstance(String val) {
+    jvmHttp = val;
+    return new CheckJvmThread();
+  } // end getThreadInstance
+
+  /** private constructor. Instantiates the classes and variables used by this thread */
+  public CheckJvmThread() {
+  } // end constructor
+
+  /**
+   * This method is called when the context shuts down. We should perform all the cleanup
+   * operations related to the thread here.
+   */
+  protected void finalize() throws Throwable {
+    super.finalize();
+  } // end finalize
+
+  /** This method returns the value of the variable 'runThread' */
+  public synchronized boolean runTheThread() {
+    if (logger.isDebugEnabled()) {
+      logger.debug("runThread=" + runThread);
+    }
+    return runThread;
+  } // end runTheThread
+
+  /** This method returns the value of the variable 'runThread' */
+  public static String isTheThreadRunning(String test) {
+    CheckJvmThread thread = new CheckJvmThread();
+    if (logger.isDebugEnabled()) {
+      logger.debug("runThread=" + thread.runTheThread());
+      logger.debug("test=" + test);
+    }
+    String ret = "FAILED";
+    if (thread.runTheThread()) {
+      ret = thread.getContentMatch();
+    }
+    return ret;
+  } // end runTheThread
+
+  public String getContentMatch() {
+    return contentMatch;
+  }
+
+  /**
+   * This method sets the value of the variable 'runThread' to true. The calling servlet/jsp MUST
+   * call the start() method of this class after calling startThread(). The reason start() (actually run..)
+   * cannot be called from here is because startThread() is a static method and run() is not.
+   */
+  public static synchronized void startThread() {
+    runThread = true;
+    if (logger.isDebugEnabled()) {
+      logger.debug("runThread=" + runThread);
+    }
+  } // end startThread
+
+  /** This method sets the value of the variable 'runThread' to false */
+  public static synchronized void stopThread() {
+    runThread = false;
+    if (logger.isDebugEnabled()) {
+      logger.debug("runThread=" + runThread);
+    }
+  }
+
+  /**
+   * This method determines whether or not to run the designated process(e.g. thread) based on whether
+   * thread is primary or backup or alternate.
+   */
+  public void run() {
+    // NOW, perform the desired operation.
+    while (runTheThread()) {
+      if (logger.isDebugEnabled()) {
+        logger.debug(" java.lang.Runtime.getRuntime().freeMemory()=" + Runtime.getRuntime().freeMemory());
+        logger.debug(" java.lang.Runtime.getRuntime().totalMemory()=" + Runtime.getRuntime().totalMemory());
+      }
+      if (isPrimary()) {
+//primary job stuff here.
+        if (logger.isDebugEnabled()) {
+          logger.debug(this.getName() + " - Performing my function here.");
+        }
+        if (logger.isDebugEnabled()) {
+          logger.debug("adminBean.getInstance()=" + adminBean.getInstance());
+        }
+        if (logger.isDebugEnabled()) {
+          logger.debug("state=" + state);
+        }
+        doPrimaryFunction();
+      }
+      if (logger.isDebugEnabled()) {
+        logger.debug("About to SLEEP.");
+      }
+      try {
+        if (logger.isDebugEnabled()) {
+          logger.debug("sleeptime=" + sleeptime);
+        }
+        sleep(sleeptime * 1000);
+      } catch (InterruptedException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("InterruptedException: " + e.getMessage());
+        }
+      }
+    } // while runTheThread()
+    tpe.shutdown();
+    if (logger.isInfoEnabled()) {
+      logger.info("CheckJvmThread stopped running");
+    }
+
+  } // end run
+
+  public static void iterateJobPools(lokahi.core.api.state.State s) {
+    if (s != null) {
+      Collection<JobPool> c = null;
+      try {
+        c = JobPool.getJobPoolsLimited(s);
+        if (logger.isDebugEnabled()) {
+          logger.debug("c.size()=" + c.size());
+        }
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+      if (c != null) {
+        for (final JobPool jp : c) {
+//            Runnable r = new CheckJobPoolTask(jp);
+//            tpe.execute(r);
+        }
+      }
+    }
+  }
+
+  public static void doPrimaryFunction() {
+    Collection<Job> jobs;
+    try {
+      jobs = Job.getJobs(adminBean.getInstance(), state);
+      if (jobs != null && !jobs.isEmpty()) {
+        try {
+          for (final Job j : jobs) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("SENDING j=" + j);
+            }
+            SendJobTask t = new SendJobTask(j);
+//          t.run();
+            try {
+              tpe.execute(t);
+            } catch (RejectedExecutionException e) {
+              logger.info("Exception: " + e.getLocalizedMessage());
+              logger.error("Exception:", e);
+            }
+            if (logger.isInfoEnabled()) {
+              logger.info("tpe.getTaskCount()=" + tpe.getTaskCount());
+              logger.info("tpe.getTaskCount()=" + tpe.getTaskCount());
+              logger.info("tpe.getActiveCount()=" + tpe.getActiveCount());
+              logger.info("tpe.getCompletedTaskCount()=" + tpe.getCompletedTaskCount());
+              logger.info("tpe.tpe.getLargestPoolSize()=" + tpe.getLargestPoolSize());
+              logger.info("tpe.getQueue().remainingCapacity()=" + tpe.getQueue().remainingCapacity());
+            }
+          }
+        } catch (RuntimeException ex) {
+          if (logger.isInfoEnabled()) {
+            logger.info("Exception: " + ex.getMessage());
+            logger.info("Exception: " + ex.getClass());
+            logger.info("Exception: " + ex.getStackTrace());
+          }
+        }
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+//  for (int i=0; i<=2; i++){
+//    try {
+//      iterateJobPools(tmc.dao.State.getState(i));
+//    } catch (SQLException e) {
+//      if (logger.isInfoEnabled()) {
+//        logger.info("Exception: " + e.getMessage());
+//      }
+//    }
+//  }
+  }
+
+  /**
+   * This method checks if the machine:jvm supplied is available, by doing a http request.
+   *
+   * @param pair - machine:jvm whose availability is to be checked
+   *
+   * @return - boolean true if the machine:jvm pair is available and false if not
+   */
+  private boolean pingMachine(String pair) {
+    boolean ret = false;
+    if (pair != null && !"".equals(pair)) {
+      String uri = protocol + "://" + pair + myContext + '/' + statusPage;
+      if (logger.isDebugEnabled()) {
+        logger.debug("uri=" + uri);
+      }
+//      String res = getResultOfURL(uri);
+      String res = usingSoap(uri);
+      if (res.equalsIgnoreCase(contentMatch)) {
+        ret = true;
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + ret);
+    }
+    return ret;
+  } // end pingMachine
+
+  /**
+   * This method determines if this thread must run the desired process. It first checks if the variable 'runThread'
+   * is true. If not, returns false. If it is true, then it checks its own status.
+   * If it is primary, returns true, if not, it checks if the primary/backup  is available, based on its own status
+   * (backup/alternate respectively). It changes its status based on the availability of primary/backup
+   *
+   * @return - boolean true if the thread should run and false if not.
+   */
+  private boolean isPrimary() {
+    boolean shouldIRun = false;
+    if (!runTheThread()) {
+      if (logger.isInfoEnabled()) {
+        logger.info("I am not even supposed to be running! ");
+      }
+    } else {
+      Hashtable admin_jvms = adminBean.getAllAdminInfo();
+      if (admin_jvms == null) admin_jvms = new Hashtable();
+      String primaryTomcatWorker = (admin_jvms.get("PRIMARY") != null) ? (String) admin_jvms.get("PRIMARY") : "";
+      String backupTomcatWorker = (admin_jvms.get("BACKUP") != null) ? (String) admin_jvms.get("BACKUP") : "";
+      String alternateTomcatWorkers = (admin_jvms.get("ALTERNATE") != null) ? (String) admin_jvms.get("ALTERNATE") : "";
+      String myTomcatWorker = hostname + ":" + jvmHttp;
+      if (logger.isDebugEnabled()) {
+        logger.debug("myTomcatWorker=" + myTomcatWorker);
+        logger.debug("primaryTomcatWorker=" + primaryTomcatWorker);
+        logger.debug("backupTomcatWorker=" + backupTomcatWorker);
+        logger.debug("alternateTomcatWorkers=" + alternateTomcatWorkers);
+      }
+      if (myTomcatWorker.equalsIgnoreCase(primaryTomcatWorker)) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("Thread is primary");
+        }
+        shouldIRun = true;
+      } else {
+        if (myTomcatWorker.equalsIgnoreCase(backupTomcatWorker)) {
+          if (logger.isDebugEnabled()) {
+            logger.debug("Thread is the backup");
+          }
+          if (pingMachine(primaryTomcatWorker)) {
+            iterateJobPools(state);
+            iterateJobPools(lokahi.core.api.state.State.getState(1));
+          } else {
+            admin_jvms.put("PRIMARY", myTomcatWorker);
+            admin_jvms.put("BACKUP", primaryTomcatWorker);
+            adminBean.changeJvmAdminRole(admin_jvms);
+          }
+        } else {
+
+          boolean amIAlt = false;
+          if (alternateTomcatWorkers != null && !alternateTomcatWorkers.equals("")) {
+            String temp[] = adminBean.split(alternateTomcatWorkers, ","); // array of alt_host:port
+            int t = 0;
+            while (t < temp.length && amIAlt != true) {
+              if (temp[t] != null && temp[t].equalsIgnoreCase(myTomcatWorker)) {
+                amIAlt = true;
+              }
+              t++;
+            } // for each alternate
+          }
+          if (!amIAlt) {
+            if (admin_jvms.get("ALTERNATE") != null)
+              admin_jvms.put("ALTERNATE", (String) admin_jvms.get("ALTERNATE") + "," + myTomcatWorker);
+            else
+              admin_jvms.put("ALTERNATE", myTomcatWorker);
+            adminBean.changeJvmAdminRole(admin_jvms);
+          } else {
+            if (logger.isDebugEnabled()) {
+              logger.debug("Thread is the alt");
+            }
+            if (pingMachine(backupTomcatWorker)) {
+            } else {
+              admin_jvms.put("BACKUP", myTomcatWorker);
+              admin_jvms.put("ALTERNATE", alternateTomcatWorkers + ',' + backupTomcatWorker);
+              adminBean.changeJvmAdminRole(admin_jvms);
+            }
+          }
+        }
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("runThread=" + this.runTheThread());
+      logger.debug("Returning " + shouldIRun);
+    }
+    return shouldIRun;
+  } // end isPrimary
+
+  /**
+   * This method contacts the supplied machine:jvmagent with the URL supplied and returns the result of
+   * the operation
+   *
+   * @param uri - URL String to hit the target JVM with
+   *
+   * @return - String containing the result of the operation, directly as received from the target JVM
+   */
+  private String getResultOfURL(String uri) {
+    String ret = "Nothing happened!!";
+    try {
+      URL url = new URL(uri);
+      InputStream is = url.openStream();
+      BufferedReader inStream = new BufferedReader(new InputStreamReader(is));
+      String line;
+      while ((line = inStream.readLine()) != null) {
+        ret = line;
+      }
+      inStream.close();
+      is.close();
+    } catch (MalformedURLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      ret = e.getMessage();
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("IOException: " + e.getMessage());
+      }
+      ret = e.getMessage();
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + ret);
+    }
+    return ret;
+
+  } // end getResultIOfURL
+
+  private String usingSoap(String uri) {
+    String namespace = "TmcController";
+    String method = "isTheThreadRunning";
+    String ret = "";
+    Message m = MessageFactory.getTransport();
+    try {
+      ret = m.send(new String[]{"TEST"}, false, new String[]{uri, namespace, method});
+    } catch (UnsupportedParameterException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+} // end CheckJvmThread
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerJobFactory.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerJobFactory.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerJobFactory.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerJobFactory.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,47 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package lokahi.core.controller;
+
+import lokahi.core.api.job.Job;
+import lokahi.core.api.state.State;
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.TMCBroker;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id$
+ */
+public class ControllerJobFactory {
+  private static final TMCBroker<Job> broker = new BrokerFactory<Job>().getBroker();
+
+  public Job fillObject(ResultSet r) throws SQLException {
+    Job j = new Job();
+
+    return j;
+  }
+
+  public Collection<Job> getJobs(State s) {
+    //call the broker in job.class to get our rows.
+    //then iterate it and call the broker here in order to get the ones we're working on.
+
+    return null;
+  }
+
+}
\ No newline at end of file

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerThread.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerThread.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerThread.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/controller/ControllerThread.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,64 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package lokahi.core.controller;
+
+import org.apache.log4j.Logger;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Stephen Toback
+ * @version $Id$
+ */
+public class ControllerThread implements Runnable {
+  static final Logger logger = Logger.getLogger(ControllerThread.class);
+  private static volatile boolean run = false;
+  private static final int corePoolSize = 5;  //5
+  private static final int maximumPoolSize = 20;  //20
+  private static final long keepAliveTime = 300;  //how long till existing idle threads are killed
+  private static ThreadPoolExecutor tpe = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(25));
+
+  public static boolean shouldRun() {
+    return run;
+  }
+
+  public static void setRun(boolean run) {
+    ControllerThread.run = run;
+  }
+
+  public ControllerThread() {
+    setRun(true);
+  }
+
+  public void run() {
+    while (shouldRun()) {
+
+    }
+    try {
+      Thread.sleep(1000);
+    } catch (InterruptedException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+}
+
+



Mime
View raw message