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 [18/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/tomcat/api/server/Tomcat.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/Tomcat.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/Tomcat.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/Tomcat.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,460 @@
+/*
+* 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.tomcat.api.server;
+
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.Application;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.util.PropertiesFile;
+import org.apache.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Properties;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Tomcat.java,v 1.3 2006/03/07 20:18:55 drtobes Exp $
+ */
+public class Tomcat extends Application<Tomcat> {
+  static final Logger logger = Logger.getLogger(Tomcat.class);
+  private static final TMCBroker<Tomcat> broker = new BrokerFactory<Tomcat>().getBroker();
+  private int tomcatType = 4;
+  private int id;
+  private String name;
+  private String baseLocation;
+  private String tomcatHome;
+  private int httpPort;
+  private String sysUser;
+  private String sysGroup;
+  private String description;
+
+  private String environment;
+  private String javaOptions;
+
+  private String javaHome;
+  private String startClass;
+  private String stdOutLog;
+
+  public int getPk() {
+    return this.id;
+  }
+
+  public void setPk(int pk) {
+    this.id = pk;
+  }
+
+  public String getName() {
+    return this.name + ' ' + this.getDescription();
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getBaseLocation() {
+    return baseLocation;
+  }
+
+  public void setBaseLocation(String baseLocation) {
+    this.baseLocation = baseLocation;
+  }
+
+  public String getTomcatHome() {
+    return tomcatHome;
+  }
+
+  public int getType() {
+    return tomcatType;
+  }
+
+  public void setType(int tomcatType) {
+    this.tomcatType = tomcatType;
+  }
+
+  public void setTomcatHome(String tomcatHome) {
+    this.tomcatHome = tomcatHome;
+  }
+
+  public int getHttpPort() {
+    return httpPort;
+  }
+
+  public void setHttpPort(int httpPort) {
+    this.httpPort = httpPort;
+  }
+
+  public String getSysUser() {
+    return sysUser;
+  }
+
+  public void setSysUser(String sysUser) {
+    this.sysUser = sysUser;
+  }
+
+  public String getSysGroup() {
+    return sysGroup;
+  }
+
+  public void setSysGroup(String sysGroup) {
+    this.sysGroup = sysGroup;
+  }
+
+  public String getEntry() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("java.options=");
+    ret.append(this.getJavaOptions());
+    ret.append("\njava.environment=");
+    ret.append(this.getEnvironment());
+    ret.append('\n');
+    return ret.toString();
+  }
+
+  protected void setEntry(byte[] content) {
+    try {
+      if (content != null) {
+        Properties p = new Properties();
+        p.load(new ByteArrayInputStream(content));
+        this.setJavaOptions(p.getProperty("java.options"));
+        this.setEnvironment(p.getProperty("java.environment"));
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public String getServerName() {
+    return name;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public String getJavaHome() {
+    return javaHome;
+  }
+
+  public void setJavaHome(String javaHome) {
+    this.javaHome = javaHome;
+  }
+
+  public String getStartClass() {
+    return startClass;
+  }
+
+  public void setStartClass(String startClass) {
+    this.startClass = startClass;
+  }
+
+  public String getStdOutLog() {
+    return stdOutLog;
+  }
+
+  public void setStdOutLog(String stdOutLog) {
+    this.stdOutLog = stdOutLog;
+  }
+
+  public String getEnv() {
+    return this.getEnvironment();
+  }
+
+  public String getEnvironment() {
+    return environment;
+  }
+
+  public void setEnvironment(String environment) {
+    this.environment = environment;
+  }
+
+  public String getJavaOptions() {
+    return javaOptions;
+  }
+
+  public void setJavaOptions(String javaOptions) {
+    this.javaOptions = javaOptions;
+  }
+
+  public Tomcat() {
+  }
+
+  public Tomcat(int id, String name, String baseLocation, String tomcatHome,
+                int httpPort, String description, String sysUser, String sysGroup, Blob entry, int version,
+                String stdOutLog, String startClass, String javaHome) throws SQLException {
+    this.setPk(id);
+    this.setName(name);
+    this.setBaseLocation(baseLocation);
+    this.setTomcatHome(tomcatHome);
+    this.setHttpPort(httpPort);
+    this.setSysUser(sysUser);
+    this.setDescription(description);
+    this.setSysGroup(sysGroup);
+    if (entry != null)
+      this.setEntry(entry.getBytes(1, (int) entry.length()));
+    this.setType(version);
+    this.setStdOutLog(stdOutLog);
+    this.setStartClass(startClass);
+    this.setJavaHome(javaHome);
+  }
+
+  public Tomcat(String name, String baseLocation, String tomcatHome,
+                int httpPort, String description, String sysUser, String sysGroup, int version,
+                String stdOutLog, String startClass, String javaHome) {
+    this.setName(name);
+    this.setBaseLocation(baseLocation);
+    this.setTomcatHome(tomcatHome);
+    this.setHttpPort(httpPort);
+    this.setDescription(description);
+    this.setSysUser(sysUser);
+    this.setSysGroup(sysGroup);
+    this.setType(version);
+    this.setStdOutLog(stdOutLog);
+    this.setStartClass(startClass);
+    this.setJavaHome(javaHome);
+  }
+
+  public Tomcat fillObject(ResultSet r) throws SQLException {
+    return new Tomcat(r.getInt("CONTAINER_ID"),
+                      r.getString("CONTAINER_NAME"),
+                      r.getString("BASE_LOCATION"),
+                      r.getString("TOMCAT_HOME"),
+                      r.getInt("HTTP_PORT"),
+                      r.getString("Description"),
+                      r.getString("SYS_USER"),
+                      r.getString("SYS_GROUP"),
+                      r.getBlob("CONF_ENTRY"),
+                      r.getInt("TOMCAT_TYPE"),
+                      r.getString("STD_OUT_LOG"),
+                      r.getString("START_CLASS"),
+                      r.getString("JAVA_HOME"));
+  }
+
+  public static void update(Tomcat tc) throws SQLException {
+    broker.update("tomcat.server.update",
+                  tc.getPk(),
+                  tc.getServerName(),
+                  tc.getBaseLocation(),
+                  tc.getTomcatHome(),
+                  tc.getHttpPort(),
+                  tc.getSysUser(),
+                  tc.getSysGroup(),
+                  tc.getDescription(),
+                  tc.getType(),
+                  tc.getJavaHome(),
+                  tc.getStartClass(),
+                  tc.getStdOutLog(),
+                  (tc.getEntry()).getBytes());
+  }
+
+  public static Tomcat store(Tomcat tc) throws SQLException {
+    tc.setPk(broker.save("tomcat.server.store",
+                         tc.getServerName(),
+                         tc.getBaseLocation(),
+                         tc.getTomcatHome(),
+                         tc.getHttpPort(),
+                         tc.getSysUser(),
+                         tc.getSysGroup(),
+                         tc.getDescription(),
+                         tc.getType(),
+                         tc.getJavaHome(),
+                         tc.getStartClass(),
+                         tc.getStdOutLog(),
+                         (tc.getEntry()).getBytes()));
+    return tc;
+  }
+
+  public static boolean delete(Tomcat tc) throws SQLException {
+    return broker.delete("tomcat.server.delete", tc.getPk());
+  }
+
+  public static Collection<Tomcat> getTomcats() throws SQLException {
+    Collection<Tomcat> c;
+    try {
+      c = broker.getObjects(Tomcat.class, true, "tomcat.server.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<Tomcat> getTomcats(String name, boolean fromCache) throws SQLException {
+    Collection<Tomcat> c;
+    try {
+      c = broker.getObjects(Tomcat.class, fromCache, "tomcat.server.by.name", name);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public Tomcat get(int id) throws SQLException {
+    Tomcat t;
+    try {
+      t = broker.getObject(Tomcat.class, "tomcat.server.by.id", false, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("t=" + t);
+    }
+    return t;
+  }
+
+  public static Tomcat getTomcat(int id, boolean fromCache) throws SQLException {
+    return new Tomcat().get(id);
+  }
+
+  public String buildJvmconfEntry() {
+    StringBuilder ret = new StringBuilder();
+    ret.append(this.getHttpPort());
+    ret.append(".tomcat.name=");
+    ret.append(this.getServerName());
+    ret.append('\n');
+    ret.append(this.getHttpPort());
+    ret.append(".java.param.user=www\n");
+    ret.append(this.getHttpPort());
+    ret.append(".java.param.group=www\n");
+    ret.append(this.getHttpPort());
+    ret.append(".java.param.jvmgroup=tomcat\n");
+    ret.append(this.getHttpPort());
+    ret.append(".java.param.options=-Dcatalina.base=");
+    ret.append(this.getBaseLocation());
+    ret.append(" -Dcatalina.home=");
+    ret.append(this.getTomcatHome());
+    ret.append(' ');
+    ret.append(this.getJavaOptions());
+    ret.append('\n');
+    ret.append(this.getHttpPort());
+    ret.append(".java.param.env=");
+    ret.append(this.getEnvironment());
+    ret.append('\n');
+    ret.append(this.getHttpPort());
+    ret.append(".java.home=");
+    ret.append(this.getJavaHome());
+    ret.append('\n');
+    ret.append(this.getHttpPort());
+    ret.append(".tomcat.startclass=");
+    ret.append(this.getStartClass());
+    ret.append('\n');
+    ret.append(this.getHttpPort());
+    ret.append(".java.param.standard.out.log=");
+    ret.append(this.getStdOutLog());
+    ret.append('\n');
+    ret.append(this.getHttpPort());
+    ret.append(".tomcat.param.jmx=");
+    if (this.getType() >= 6) {
+      ret.append("yes\n");
+    } else {
+      ret.append("no\n");
+    }
+    return ret.toString();
+  }
+
+  public StringBuilder buildShortXMLRepresentation() {
+    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(3, 1);
+    map.put("id", Integer.toString(this.getPk()));
+    map.put("name", this.getName());
+    map.put("href", PropertiesFile.getConstantValue("rest.servlet.url") + "tomcat/" + this.getPk() + '/');
+    return elementBuilder("tomcat", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<tomcat>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("serverName", this.getServerName()));
+    ret.append(elementBuilder("version", Integer.toString(this.getType())));
+    ret.append(elementBuilder("description", this.getDescription()));
+    ret.append(elementBuilder("httpPort", Integer.toString(this.getHttpPort())));
+    ret.append(elementBuilder("baseLocation", this.getBaseLocation()));
+    ret.append(elementBuilder("tomcatHome", this.getTomcatHome()));
+    ret.append(elementBuilder("settings", this.getEntry()));
+    ret.append(elementBuilder("standardOutLog", this.getStdOutLog()));
+    ret.append(elementBuilder("startClass", this.getStartClass()));
+    ret.append(elementBuilder("javaHome", this.getJavaHome()));
+    ret.append("</tomcat>\n");
+    return ret;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Tomcat)) return false;
+
+    final Tomcat tomcat = (Tomcat) o;
+
+    if (httpPort != tomcat.httpPort) return false;
+    if (id != tomcat.id) return false;
+    if (tomcatType != tomcat.tomcatType) return false;
+    if (baseLocation != null ? !baseLocation.equals(tomcat.baseLocation) : tomcat.baseLocation != null) return false;
+    if (description != null ? !description.equals(tomcat.description) : tomcat.description != null) return false;
+    if (environment != null ? !environment.equals(tomcat.environment) : tomcat.environment != null) return false;
+    if (javaHome != null ? !javaHome.equals(tomcat.javaHome) : tomcat.javaHome != null) return false;
+    if (javaOptions != null ? !javaOptions.equals(tomcat.javaOptions) : tomcat.javaOptions != null) return false;
+    if (!name.equals(tomcat.name)) return false;
+    if (startClass != null ? !startClass.equals(tomcat.startClass) : tomcat.startClass != null) return false;
+    if (stdOutLog != null ? !stdOutLog.equals(tomcat.stdOutLog) : tomcat.stdOutLog != null) return false;
+    if (sysGroup != null ? !sysGroup.equals(tomcat.sysGroup) : tomcat.sysGroup != null) return false;
+    if (sysUser != null ? !sysUser.equals(tomcat.sysUser) : tomcat.sysUser != null) return false;
+    if (tomcatHome != null ? !tomcatHome.equals(tomcat.tomcatHome) : tomcat.tomcatHome != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = tomcatType;
+    result = 29 * result + id;
+    result = 29 * result + name.hashCode();
+    result = 29 * result + (baseLocation != null ? baseLocation.hashCode() : 0);
+    result = 29 * result + (tomcatHome != null ? tomcatHome.hashCode() : 0);
+    result = 29 * result + httpPort;
+    result = 29 * result + (sysUser != null ? sysUser.hashCode() : 0);
+    result = 29 * result + (sysGroup != null ? sysGroup.hashCode() : 0);
+    result = 29 * result + (description != null ? description.hashCode() : 0);
+    result = 29 * result + (environment != null ? environment.hashCode() : 0);
+    result = 29 * result + (javaOptions != null ? javaOptions.hashCode() : 0);
+    result = 29 * result + (javaHome != null ? javaHome.hashCode() : 0);
+    result = 29 * result + (startClass != null ? startClass.hashCode() : 0);
+    result = 29 * result + (stdOutLog != null ? stdOutLog.hashCode() : 0);
+    return result;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/TomcatModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/TomcatModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/TomcatModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/server/TomcatModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,96 @@
+/*
+* 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.tomcat.api.server;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.state.State;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.common.interfaces.LokahiModel;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TomcatModel.java,v 1.3 2006/03/07 20:18:55 drtobes Exp $
+ */
+
+public class TomcatModel extends LokahiModel<Tomcat> {
+
+  public void addTomcat(User u, Tomcat a, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+    this.jpInit(f, u, a.getName());
+    if (u.isAllowed(f) && "AddTomcat".equals(f.getCommand())) {
+      Tomcat.store(a);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public void deleteTomcat(User u, Tomcat a, Function f) throws SQLException, AuthorizationException, TMCIllegalArgumentException {
+    if (a == null || a.getPk() < 1) throw new TMCIllegalArgumentException("Tomcat can not be null");
+    this.jpInit(f, u, a.getName());
+    if (u.isAllowed(f) && "DeleteTomcat".equals(f.getCommand())) {
+      Tomcat.delete(a);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public void updateTomcat(User u, Tomcat a, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+    this.jpInit(f, u, a.getName());
+    if (u.isAllowed(f) && "UpdateTomcat".equals(f.getCommand())) {
+      if (a.getPk() >= 1 && a.getName() != null && !"".equals(a.getName())) {
+        Tomcat.update(a);
+      } else {
+        throw new TMCIllegalArgumentException("Tomcat can not be null");
+      }
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public Tomcat viewTomcat(int id) throws SQLException {
+    return Tomcat.getTomcat(id, true);
+  }
+
+  public Collection<Tomcat> viewTomcats() throws SQLException {
+    return Tomcat.getTomcats();
+  }
+
+  public Collection<Tomcat> getObjects() throws SQLException {
+    return new TMCSet<Tomcat>(this.viewTomcats());
+  }
+
+  public Tomcat getObject(int id) throws SQLException {
+    return this.viewTomcat(id);
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/ServerXmlFile.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/ServerXmlFile.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/ServerXmlFile.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/ServerXmlFile.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,412 @@
+/*
+* 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.tomcat.api.worker;
+
+import lokahi.tomcat.api.entity.TomcatContext;
+import lokahi.tomcat.api.server.Tomcat;
+import org.apache.log4j.Logger;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ServerXmlFile.java,v 1.1 2006/03/06 22:31:51 drtobes Exp $
+ */
+public class ServerXmlFile {
+  static final Logger logger = Logger.getLogger(ServerXmlFile.class);
+
+  private TomcatWorker tw;
+
+  public ServerXmlFile(TomcatWorker t) {
+    this.tw = t;
+  }
+
+  public String build() throws SQLException {
+    Document doc = null;
+    if (tw.getType() == 4) {
+      doc = this.build4();
+    } else if (tw.getType() == 5) {
+      doc = this.build5();
+    } else if (tw.getType() == 6) {
+      doc = this.build6();
+    }
+    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + out.outputString(doc));
+    }
+    return out.outputString(doc);
+  }
+
+  private Document build4() throws SQLException {
+    Tomcat tc = tw.getTomcat();
+    Document doc = null;
+    if (tc != null) {
+      int httpPort = tc.getHttpPort();
+      String shutdownPrt = Integer.toString(httpPort - 2);
+      String ajpPort = Integer.toString(httpPort - 1);
+      Element host = elementBuilder("Host", new Attribute[]{
+          new Attribute("name", "localhost"),
+          new Attribute("debug", "0"),
+          new Attribute("appBase", "webapps"),
+          new Attribute("unpackWARs", "false")
+      });
+//      if (tw.getHardware().getInstance().getPk() == 2)
+//        host.addContent(elementBuilder("Valve", new Attribute[]{
+//          new Attribute("className", "org.apache.catalina.valves.RemoteAddrValve"),
+//          new Attribute("allow", "54.23.226.*,54.23.243.*,54.23.244.*,54.23.245.*,54.23.246.*,54.23.247.*,54.23.248.*,127.0.0.1,54.23.230.*,54.23.205.43,54.23.224.79,^54.3.214.1$,^54.23.206.6$,54.62.195.*,54.62.155.*,54.50.56.*,54.48.92.*,54.48.84.*,54.62.241.*")
+//        }));
+      Element defaultContext = new Element("DefaultContext");
+      defaultContext.addContent(elementBuilder("Parameter", new Attribute[]{
+          new Attribute("name", "MrkJvmHttp"),
+          new Attribute("value", Integer.toString(httpPort)),
+          new Attribute("override", "false")
+      }));
+      host.addContent(defaultContext);
+      Element tmAgent = elementBuilder("Context", new Attribute[]{
+          new Attribute("path", "/TMAgent"),
+          new Attribute("docBase", "/usr/local/covalent/tomcat4.0.4/webapps/TMAgent"),
+          new Attribute("debug", "0"),
+          new Attribute("privileged", "true"),
+      });
+/*      Enable below code once the TMAgent has been switched to keyless.
+//todo ENABLE for keyless agent.
+        tmAgent = tmAgent.setContent(elementBuilder("Valve", new Attribute[]{
+        new Attribute("className", "org.apache.catalina.valves.RemoteAddrValve"),
+        new Attribute("allow", "127.0.0.1")
+      }));
+
+      */
+      host = host.addContent(tmAgent);
+      Collection<TomcatContext> c = TomcatContext.getTomcatContexts(tw);
+      for (final TomcatContext context : c) {
+        host.addContent(context.buildServerXML());
+      }
+      Element root = elementBuilder("Server", new Attribute[]{
+          new Attribute("port", shutdownPrt),
+          new Attribute("shutdown", "SHUTDOWN"),
+          new Attribute("debug", "0")
+      });
+      Element manager = elementBuilder("Manager", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.session.PersistentManager"),
+          new Attribute("debug", "0"),
+          new Attribute("saveOnRestart", "true"),
+          new Attribute("maxActiveSessions", "-1"),
+          new Attribute("minIdleSwap", "-1"),
+          new Attribute("maxIdleSwap", "-1"),
+          new Attribute("maxIdleBackup", "-1")
+      });
+      manager = manager.addContent(elementBuilder("Store", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.session.FileStore")
+      }));
+      Element engine = elementBuilder("Engine", new Attribute[]{
+          new Attribute("jvmRoute", tw.getWorkerName()),
+          new Attribute("name", "Agent" + shutdownPrt),
+          new Attribute("defaultHost", "localhost"),
+          new Attribute("debug", "0")
+      });
+      engine = engine.addContent(elementBuilder("Logger", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.logger.FileLogger"),
+          new Attribute("prefix", "Agent" + shutdownPrt + '.'),
+          new Attribute("suffix", ".log"),
+          new Attribute("timestamp", "true")
+      }));
+      engine = engine.addContent(manager);
+      engine = engine.addContent(elementBuilder("Realm", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.realm.MemoryRealm")
+      }));
+      engine = engine.addContent(host);
+      Element service = elementBuilder("Service", new Attribute[]{new Attribute("name", "Agent" + shutdownPrt)});
+      service = service.addContent(elementBuilder("Connector", new Attribute[]{
+          new Attribute("className", "org.apache.ajp.tomcat4.Ajp13Connector"),
+          new Attribute("port", ajpPort),
+          new Attribute("minProcessors", "10"),
+          new Attribute("maxProcessors", "5000"),
+          new Attribute("acceptCount", "40"),
+          new Attribute("debug", "0"),
+          new Attribute("tomcatAuthentication", "false")
+      }));
+      service = service.addContent(elementBuilder("Connector", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.connector.http.HttpConnector"),
+          new Attribute("port", Integer.toString(httpPort)),
+          new Attribute("minProcessors", "10"),
+          new Attribute("maxProcessors", "1000"),
+          new Attribute("enambleLookups", "false"),
+          new Attribute("redirectPort", "8443"),
+          new Attribute("acceptCount", "10"),
+          new Attribute("debug", "0"),
+          new Attribute("connectionTimeout", "60000")
+      }));
+      service = service.addContent(engine);
+      root = root.addContent(service);
+      doc = new Document(root);
+    }
+    return doc;
+  }
+
+  private Document build5() throws SQLException {
+    Tomcat tc = tw.getTomcat();
+    Document doc = null;
+    if (tc != null) {
+      int httpPort = tc.getHttpPort();
+      String shutdownPrt = Integer.toString(httpPort - 2);
+      String ajpPort = Integer.toString(httpPort - 1);
+      Element host = elementBuilder("Host", new Attribute[]{
+          new Attribute("name", "localhost"),
+          new Attribute("debug", "0"),
+          new Attribute("appBase", "webapps"),
+          new Attribute("unpackWARs", "false"),
+          new Attribute("autoDeploy", "true"),
+          new Attribute("xmlValidation", "false"),
+          new Attribute("xmlNamespaceAware", "false")
+      });
+//      if (tw.getHardware().getInstance().getPk() == 2)
+//        host.addContent(elementBuilder("Valve", new Attribute[]{
+//          new Attribute("className", "org.apache.catalina.valves.RemoteAddrValve"),
+//          new Attribute("allow", "54.23.226.*,54.23.243.*,54.23.244.*,54.23.245.*,54.23.246.*,54.23.247.*,54.23.248.*,127.0.0.1,54.23.230.*,54.23.205.43,54.23.224.79,^54.3.214.1$,^54.23.206.6$,54.62.195.*,54.62.155.*,54.50.56.*,54.48.92.*,54.48.84.*,54.62.241.*")
+//        }));
+      Element defaultContext = new Element("DefaultContext");
+      defaultContext.addContent(elementBuilder("Parameter", new Attribute[]{
+          new Attribute("name", "MrkJvmHttp"),
+          new Attribute("value", Integer.toString(httpPort)),
+          new Attribute("override", "false")
+      }));
+      host.addContent(defaultContext);
+      Element tmAgent = elementBuilder("Context", new Attribute[]{
+          new Attribute("path", "/TMAgent"),
+          new Attribute("docBase", "/opt/tmc/tomcat5.0.27/webapps/TMAgent"),
+          new Attribute("debug", "0"),
+          new Attribute("privileged", "true"),
+      });
+/*      Enable below code once the TMAgent has been switched to keyless.
+//todo ENABLE for keyless agent.
+        tmAgent = tmAgent.setContent(elementBuilder("Valve", new Attribute[]{
+        new Attribute("className", "org.apache.catalina.valves.RemoteAddrValve"),
+        new Attribute("allow", "127.0.0.1")
+      }));
+
+      */
+      host = host.addContent(tmAgent);
+      Collection<TomcatContext> c = TomcatContext.getTomcatContexts(tw);
+      for (final TomcatContext context : c) {
+        host.addContent(context.buildServerXML());
+      }
+      Element root = elementBuilder("Server", new Attribute[]{
+          new Attribute("port", shutdownPrt),
+          new Attribute("shutdown", "SHUTDOWN"),
+          new Attribute("debug", "0")
+      });
+      root.addContent(elementBuilder("Listener", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.mbeans.ServerLifecycleListener"),
+          new Attribute("debug", "0")
+      }));
+      root.addContent(elementBuilder("Listener", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"),
+          new Attribute("debug", "0")
+      }));
+      Element manager = elementBuilder("Manager", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.session.PersistentManager"),
+          new Attribute("debug", "0"),
+          new Attribute("saveOnRestart", "true"),
+          new Attribute("maxActiveSessions", "-1"),
+          new Attribute("minIdleSwap", "315"),
+          new Attribute("maxIdleSwap", "390"),
+          new Attribute("maxIdleBackup", "300")
+      });
+      manager = manager.addContent(elementBuilder("Store", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.session.FileStore")
+      }));
+      Element engine = elementBuilder("Engine", new Attribute[]{
+          new Attribute("jvmRoute", tw.getWorkerName()),
+          new Attribute("name", "Agent" + shutdownPrt),
+          new Attribute("defaultHost", "localhost"),
+          new Attribute("debug", "0")
+      });
+      engine = engine.addContent(elementBuilder("Logger", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.logger.FileLogger"),
+          new Attribute("prefix", "Agent" + shutdownPrt + '.'),
+          new Attribute("suffix", ".log"),
+          new Attribute("timestamp", "true")
+      }));
+      engine = engine.addContent(manager);
+      engine = engine.addContent(host);
+      Element service = elementBuilder("Service", new Attribute[]{new Attribute("name", "Agent" + shutdownPrt)});
+      service = service.addContent(elementBuilder("Connector", new Attribute[]{
+          new Attribute("port", Integer.toString(httpPort)),
+          new Attribute("minSpareThreads", "25"),
+          new Attribute("maxSpareThreads", "75"),
+          new Attribute("enableLookups", "false"),
+          new Attribute("redirectPort", "8443"),
+          new Attribute("acceptCount", "100"),
+          new Attribute("debug", "0"),
+          new Attribute("connectionTimeout", "20000"),
+          new Attribute("disableUploadTimeout", "true")
+      }));
+      service = service.addContent(elementBuilder("Connector", new Attribute[]{
+          new Attribute("port", ajpPort),
+          new Attribute("enableLookups", "false"),
+          new Attribute("tomcatAuthentication", "false"),
+          new Attribute("redirectPort", "8443"),
+          new Attribute("minProcessors", "10"),
+          new Attribute("maxProcessors", "5000"),
+          new Attribute("acceptCount", "100"),
+          new Attribute("debug", "0"),
+          new Attribute("protocol", "AJP/1.3")
+      }));
+      service = service.addContent(engine);
+      root = root.addContent(service);
+      doc = new Document(root);
+    }
+    return doc;
+  }
+
+  private Document build6() throws SQLException {
+    Tomcat tc = tw.getTomcat();
+    Document doc = null;
+    if (tc != null) {
+      int httpPort = tc.getHttpPort();
+      String shutdownPrt = Integer.toString(httpPort - 2);
+      String ajpPort = Integer.toString(httpPort - 1);
+      Element host = elementBuilder("Host", new Attribute[]{
+          new Attribute("name", "localhost"),
+          new Attribute("debug", "0"),
+          new Attribute("appBase", "webapps"),
+          new Attribute("unpackWARs", "false"),
+          new Attribute("autoDeploy", "true"),
+          new Attribute("xmlValidation", "false"),
+          new Attribute("xmlNamespaceAware", "false")
+      });
+//      if (tw.getHardware().getInstance().getPk() == 2)
+//        host.addContent(elementBuilder("Valve", new Attribute[]{
+//          new Attribute("className", "org.apache.catalina.valves.RemoteAddrValve"),
+//          new Attribute("allow", "54.23.226.*,54.23.243.*,54.23.244.*,54.23.245.*,54.23.246.*,54.23.247.*,54.23.248.*,127.0.0.1,54.23.230.*,54.23.205.43,54.23.224.79,^54.3.214.1$,^54.23.206.6$,54.62.195.*,54.62.155.*,54.50.56.*,54.48.92.*,54.48.84.*,54.62.241.*")
+//        }));
+      Element defaultContext = new Element("DefaultContext");
+      defaultContext.addContent(elementBuilder("Parameter", new Attribute[]{
+          new Attribute("name", "MrkJvmHttp"),
+          new Attribute("value", Integer.toString(httpPort)),
+          new Attribute("override", "false")
+      }));
+      host.addContent(defaultContext);
+//      Element tmAgent = elementBuilder("Context", new Attribute[]{
+//        new Attribute("path", "/TMAgent"),
+//        new Attribute("docBase", "/opt/tmc/tomcat5.0.27/webapps/TMAgent"),
+//        new Attribute("debug", "0"),
+//        new Attribute("privileged", "true"),
+//      });
+/*      Enable below code once the TMAgent has been switched to keyless.
+//todo ENABLE for keyless agent.
+        tmAgent = tmAgent.setContent(elementBuilder("Valve", new Attribute[]{
+        new Attribute("className", "org.apache.catalina.valves.RemoteAddrValve"),
+        new Attribute("allow", "127.0.0.1")
+      }));
+
+      */
+//      host = host.addContent(tmAgent);
+      Collection<TomcatContext> c = TomcatContext.getTomcatContexts(tw);
+      for (final TomcatContext context : c) {
+        host.addContent(context.buildServerXML());
+      }
+      Element root = elementBuilder("Server", new Attribute[]{
+          new Attribute("port", shutdownPrt),
+          new Attribute("shutdown", "SHUTDOWN"),
+          new Attribute("debug", "0")
+      });
+      root.addContent(elementBuilder("Listener", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.mbeans.ServerLifecycleListener"),
+          new Attribute("debug", "0")
+      }));
+      root.addContent(elementBuilder("Listener", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"),
+          new Attribute("debug", "0")
+      }));
+      root.addContent(elementBuilder("Listener", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.storeconfig.StoreConfigLifecycleListener"),
+          new Attribute("debug", "0")
+      }));
+      Element manager = elementBuilder("Manager", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.session.PersistentManager"),
+          new Attribute("debug", "0"),
+          new Attribute("saveOnRestart", "true"),
+          new Attribute("maxActiveSessions", "-1"),
+          new Attribute("minIdleSwap", "315"),
+          new Attribute("maxIdleSwap", "390"),
+          new Attribute("maxIdleBackup", "300")
+      });
+      manager = manager.addContent(elementBuilder("Store", new Attribute[]{
+          new Attribute("className", "org.apache.catalina.session.FileStore")
+      }));
+      Element engine = elementBuilder("Engine", new Attribute[]{
+          new Attribute("jvmRoute", tw.getWorkerName()),
+          new Attribute("name", "Agent" + shutdownPrt),
+          new Attribute("defaultHost", "localhost"),
+          new Attribute("debug", "0")
+      });
+//      engine = engine.addContent(elementBuilder("Logger", new Attribute[]{
+//        new Attribute("className", "org.apache.catalina.logger.FileLogger"),
+//        new Attribute("prefix", "Agent" + shutdownPrt + '.'),
+//        new Attribute("suffix", ".log"),
+//        new Attribute("timestamp", "true")
+//      }));
+      engine = engine.addContent(manager);
+      engine = engine.addContent(host);
+      Element service = elementBuilder("Service", new Attribute[]{new Attribute("name", "Agent" + shutdownPrt)});
+      service = service.addContent(elementBuilder("Connector", new Attribute[]{
+          new Attribute("port", Integer.toString(httpPort)),
+          new Attribute("maxThreads", "150"),
+          new Attribute("minSpareThreads", "25"),
+          new Attribute("maxSpareThreads", "75"),
+          new Attribute("enableLookups", "false"),
+          new Attribute("redirectPort", "8443"),
+          new Attribute("acceptCount", "100"),
+          new Attribute("debug", "0"),
+          new Attribute("connectionTimeout", "20000"),
+          new Attribute("disableUploadTimeout", "true")
+      }));
+      service = service.addContent(elementBuilder("Connector", new Attribute[]{
+          new Attribute("port", ajpPort),
+          new Attribute("enableLookups", "false"),
+          new Attribute("tomcatAuthentication", "false"),
+          new Attribute("redirectPort", "8443"),
+          new Attribute("minProcessors", "10"),
+          new Attribute("maxProcessors", "5000"),
+          new Attribute("acceptCount", "100"),
+          new Attribute("debug", "0"),
+          new Attribute("protocol", "AJP/1.3")
+      }));
+      service = service.addContent(engine);
+      root = root.addContent(service);
+      doc = new Document(root);
+    }
+    return doc;
+  }
+
+  private static Element elementBuilder(String name, Attribute[] a) {
+    Element ret = new Element(name);
+    for (final Attribute att : a) {
+      ret = ret.setAttribute(att);
+    }
+    return ret;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,428 @@
+/*
+* 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.tomcat.api.worker;
+
+import lokahi.core.api.instance.Instance;
+import lokahi.core.api.server.Hardware;
+import lokahi.core.api.state.State;
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.Server;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.core.common.util.PropertiesFile;
+import lokahi.tomcat.api.entity.TomcatContext;
+import lokahi.tomcat.api.pool.TomcatPool;
+import lokahi.tomcat.api.server.Tomcat;
+import org.apache.log4j.Logger;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TomcatWorker.java,v 1.3 2006/03/07 20:18:56 drtobes Exp $
+ */
+public class TomcatWorker extends TMCDao<TomcatWorker> implements Server {
+  private static final TMCBroker<TomcatWorker> broker = new BrokerFactory<TomcatWorker>().getBroker();
+  static final Logger logger = Logger.getLogger(TomcatWorker.class);
+  private int workerId;
+  private int hardwareId;
+  private int stateId;
+  private int tomcatId;
+
+  private Hardware hardware;
+  private Tomcat tomcat;
+  private State state;
+
+  public int getPk() {
+    return workerId;
+  }
+
+  public void setPk(int pk) {
+    this.workerId = pk;
+  }
+
+  public String getName() {
+    String ret = "Invalid Name";
+    if (this.getHardware() != null && this.getTomcat() != null) {
+      ret = this.getHardware().getName() + ':' + this.getTomcat().getHttpPort();
+    }
+    return ret;
+  }
+
+  public void setName(String name) {
+  }
+
+  public int getWorkerId() {
+    return workerId;
+  }
+
+  public int getTomcatId() {
+    return this.tomcatId;
+  }
+
+  public void setWorkerId(int workerId) {
+    this.workerId = workerId;
+  }
+
+  public void setTomcatId(int workerId) {
+    this.tomcatId = workerId;
+  }
+
+  public String getWorkerName() {
+    return "st" + this.getPk();
+  }
+
+  public int getHardwareId() {
+    return hardwareId;
+  }
+
+  public void setHardwareId(int hardwareId) {
+    this.hardwareId = hardwareId;
+  }
+
+  public int getStateId() {
+    return stateId;
+  }
+
+  public void setStateId(int stateId) {
+    this.stateId = stateId;
+  }
+
+  public Hardware getHardware() {
+    if (hardware == null) {
+      try {
+        this.hardware = Hardware.getHardware(this.getHardwareId(), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return hardware;
+  }
+
+  public void setHardware(Hardware hardware) {
+    this.hardware = hardware;
+    if (hardware != null) {
+      this.setHardwareId(hardware.getPk());
+    }
+  }
+
+  public Tomcat getTomcat() {
+    if (tomcat == null) {
+      try {
+        this.tomcat = Tomcat.getTomcat(this.getTomcatId(), true);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return tomcat;
+  }
+
+  public void setTomcat(Tomcat tomcat) {
+    this.tomcat = tomcat;
+    if (tomcat != null) {
+      this.setTomcatId(tomcat.getPk());
+    }
+  }
+
+  public State getState() {
+    if (state == null) {
+      this.state = State.getState(this.getStateId());
+    }
+    return state;
+  }
+
+  public void setState(State state) {
+    this.state = state;
+    if (state != null) {
+      this.setStateId(state.getPk());
+    }
+  }
+
+  public boolean isActive() {
+    return this.getHardware().isActive();
+  }
+
+  public int getType() {
+    int ret = 0;
+    if (this.getTomcat() != null) {
+      ret = this.getTomcat().getType();
+    }
+    return ret;
+  }
+
+  public TomcatWorker() {
+  }
+
+  public TomcatWorker(Hardware hardware, State state, Tomcat tomcat) {
+    this.setHardware(hardware);
+    this.setState(state);
+    this.setTomcat(tomcat);
+  }
+
+  /** @deprecated  */
+  public TomcatWorker(int workerId, int hardwareId, int stateId, int tomcatId) {
+    this.workerId = workerId;
+    this.hardwareId = hardwareId;
+    this.stateId = stateId;
+    this.tomcatId = tomcatId;
+  }
+
+  public TomcatWorker(int workerId, int stateId, Tomcat t, Hardware h) {
+    this.workerId = workerId;
+    this.stateId = stateId;
+    this.setTomcat(t);
+    this.setHardware(h);
+  }
+
+  public TomcatWorker(int tomcatId, int hardwareId) {
+    this.hardwareId = hardwareId;
+    this.stateId = 8;
+    this.tomcatId = tomcatId;
+  }
+
+  public TomcatWorker(Hardware h, Tomcat t) {
+    this(t.getPk(), h.getPk());
+  }
+
+  public Collection<TomcatContext> getAllContexts() {
+    Collection<TomcatContext> c = null;
+    try {
+      c = TomcatContext.getTomcatContexts(this);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return c;
+  }
+
+  public TomcatWorker fillObject(ResultSet r) throws SQLException {
+    return new TomcatWorker(r.getInt("WORKER_ID"),
+                            r.getInt("STATE_ID"),
+                            new Tomcat().fillObject(r),
+                            new Hardware().fillObject(r));
+  }
+
+  /** @deprecated  */
+  public String buildServerXML() throws SQLException {
+    ServerXmlFile sxf = new ServerXmlFile(this);
+    return sxf.build();
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(TomcatPool tp, boolean cache) throws SQLException {
+    return getTomcatWorkers(tp.getPk(), cache);
+  }
+
+  public String buildConfForWeb() {
+    String ret = "A database error has occurred.";
+    try {
+      ServerXmlFile sxf = new ServerXmlFile(this);
+      ret = sxf.build();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return ret;
+  }
+
+  public static void update(TomcatWorker tw) throws SQLException {
+    broker.update("tomcat.worker.update", tw.getPk(), tw.getHardwareId(), tw.getStateId(), tw.getTomcatId());
+  }
+
+  public static boolean delete(TomcatWorker tw) throws SQLException {
+    return broker.delete("tomcat.worker.delete", tw.getPk());
+  }
+
+  public static TomcatWorker store(TomcatWorker tw) throws SQLException {
+    TomcatWorker ret = getTomcatWorker(tw.getHardware(), tw.getTomcat(), false);
+    if (ret == null) {
+      tw.setPk(broker.save("tomcat.worker.store", tw.getHardwareId(), tw.getStateId(), tw.getTomcatId()));
+      ret = tw;
+    }
+    return ret;
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(int poolId, boolean cache) throws SQLException {
+    Collection<TomcatWorker> c;
+    try {
+      c = broker.getObjects(TomcatWorker.class, cache, "tomcat.worker.by.pool", poolId);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(boolean cache) throws SQLException {
+    Collection<TomcatWorker> c;
+    try {
+      c = broker.getObjects(TomcatWorker.class, cache, "tomcat.worker.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public TomcatWorker get(int id) throws SQLException {
+    TomcatWorker t;
+    try {
+      t = broker.getObject(TomcatWorker.class, "tomcat.worker.by.id", false, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("id=" + id);
+      logger.debug("t=" + t);
+    }
+    return t;
+  }
+
+  public static TomcatWorker getTomcatWorker(int id, boolean cache) throws SQLException {
+    return new TomcatWorker().get(id);
+  }
+
+  public static TomcatWorker getTomcatWorker(Hardware h, Tomcat t, boolean cache) throws SQLException {
+    TomcatWorker tw;
+    try {
+      tw = broker.getObject(TomcatWorker.class, "tomcat.worker.by.hardware.server", cache, h.getPk(), t.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return tw;
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(Hardware h, boolean cache) throws SQLException {
+    Collection<TomcatWorker> c;
+    try {
+      c = broker.getObjects(TomcatWorker.class, cache, "tomcat.worker.by.hardware", h.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(Tomcat t, boolean cache) throws SQLException {
+    Collection<TomcatWorker> c;
+    try {
+      c = broker.getObjects(TomcatWorker.class, cache, "tomcat.worker.by.server", t.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(String name, boolean cache) throws SQLException {
+    Collection<TomcatWorker> c;
+    try {
+      c = broker.getObjects(TomcatWorker.class, cache, "tomcat.worker.by.name", name);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<TomcatWorker> getTomcatWorkers(String name, Instance i, boolean cache) throws SQLException {
+    Collection<TomcatWorker> c;
+    try {
+      c = broker.getObjects(TomcatWorker.class, cache, "tomcat.worker.by.name.instance", name, i.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public StringBuilder buildShortXMLRepresentation() {
+    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(3, 1);
+    map.put("id", Integer.toString(this.getPk()));
+    map.put("name", this.getName());
+    map.put("href", PropertiesFile.getConstantValue("rest.servlet.url") + "tomcatworker/" + this.getPk() + '/');
+    return elementBuilder("tomcatworker", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<tomcatworker>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("version", Integer.toString(this.getType())));
+    ret.append(elementBuilder("workerName", this.getWorkerName()));
+    ret.append(this.getHardware().buildShortXMLRepresentation());
+    ret.append(this.getTomcat().buildShortXMLRepresentation());
+    ret.append(this.getState().buildShortXMLRepresentation());
+    for (final TomcatContext tc : this.getAllContexts()) {
+      ret.append(tc.buildShortXMLRepresentation());
+    }
+    ret.append("</tomcatworker>\n");
+    return ret;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof TomcatWorker)) return false;
+
+    final TomcatWorker tomcatWorker = (TomcatWorker) o;
+
+    if (hardwareId != tomcatWorker.hardwareId) return false;
+    if (tomcatId != tomcatWorker.tomcatId) return false;
+    if (workerId != tomcatWorker.workerId) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = workerId;
+    result = 29 * result + hardwareId;
+    result = 29 * result + tomcatId;
+    return result;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorkerModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorkerModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorkerModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/api/worker/TomcatWorkerModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,241 @@
+/*
+* 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.tomcat.api.worker;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.job.Job;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.project.Project;
+import lokahi.core.api.server.HardwareModel;
+import lokahi.core.api.state.State;
+import lokahi.core.api.user.User;
+import lokahi.core.common.authorization.AuthorizationManager;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AlreadyExistException;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.common.exception.UnsupportedParameterException;
+import lokahi.core.common.interfaces.LokahiModel;
+import lokahi.core.common.util.PropertiesFile;
+import lokahi.tomcat.api.server.Tomcat;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TomcatWorkerModel.java,v 1.3 2006/03/07 20:18:56 drtobes Exp $
+ */
+public class TomcatWorkerModel extends LokahiModel<TomcatWorker> {
+
+  public void restartTomcat(User u, Project p, JobPool jobPool, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    this.function(u, p, "RestartTomcat", "", jobPool, tw);
+  }
+
+  public void restartTomcat(User u, Project p, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    this.function(u, p, "RestartTomcat", "", null, tw);
+  }
+
+  public void startTomcat(User u, Project p, JobPool jobPool, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    this.function(u, p, "StartTomcat", "", jobPool, tw);
+  }
+
+  public void startTomcat(User u, Project p, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    this.function(u, p, "StartTomcat", "", null, tw);
+  }
+
+  public void stopTomcat(User u, Project p, JobPool jobPool, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    this.function(u, p, "StopTomcat", "", jobPool, tw);
+  }
+
+  public void stopTomcat(User u, Project p, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    this.function(u, p, "StopTomcat", "", null, tw);
+  }
+
+  public void updateTomcat(User u, Project p, JobPool jobPool, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    String options;
+    Tomcat tc = tw.getTomcat();
+    if (tc != null) {
+      String delim = PropertiesFile.getConstantValue("agent.delim.options");
+      options = "tc4" + delim +
+          tc.getSysUser() + delim +
+          tc.getSysGroup();
+      this.function(u, p, "UpdateTomcat", options, jobPool, tw);
+    }
+  }
+
+  public void stopTomcat(User u, Collection<TomcatWorker> c, Function f) throws TMCException, TMCIllegalArgumentException, SQLException, NoSuchMethodException, IOException {
+    Method m = TomcatWorkerModel.class.getMethod("stopTomcat", User.class, Project.class, JobPool.class, TomcatWorker.class);
+    tomcatFunction(m, u, c, f);
+  }
+
+  public void startTomcat(User u, Collection<TomcatWorker> c, Function f) throws TMCException, TMCIllegalArgumentException, SQLException, NoSuchMethodException, IOException {
+    Method m = TomcatWorkerModel.class.getMethod("startTomcat", User.class, Project.class, JobPool.class, TomcatWorker.class);
+    tomcatFunction(m, u, c, f);
+  }
+
+  public void restartTomcat(User u, Collection<TomcatWorker> c, Function f) throws TMCException, TMCIllegalArgumentException, SQLException, NoSuchMethodException, IOException {
+    Method m = TomcatWorkerModel.class.getMethod("restartTomcat", User.class, Project.class, JobPool.class, TomcatWorker.class);
+    tomcatFunction(m, u, c, f);
+  }
+
+  public void deployTomcatConfig(User u, Collection<TomcatWorker> c, Function f) throws TMCException, TMCIllegalArgumentException, SQLException, NoSuchMethodException, IOException {
+    Method m = TomcatWorkerModel.class.getMethod("deployTomcatConfig", User.class, Project.class, JobPool.class, TomcatWorker.class);
+    tomcatFunction(m, u, c, f);
+  }
+
+  public void deleteTomcatWorker(User u, Collection<TomcatWorker> c, Function f) throws TMCException, TMCIllegalArgumentException, SQLException, NoSuchMethodException, IOException {
+    if (!u.isAllowed("DeleteTomcatWorker"))
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    this.jpInit(f, u);
+    StringBuffer names = new StringBuffer();
+    for (final TomcatWorker tw : c) {
+      names.append(tw.getName());
+      names.append(',');
+      TomcatWorker.delete(tw);
+    }
+    jp.setOptions(names.toString());
+    jp.setState(State.NEW);
+    JobPool.update(jp);
+  }
+
+  private void tomcatFunction(Method m, User u, Collection<TomcatWorker> c, Function f) throws TMCException, TMCIllegalArgumentException, SQLException, NoSuchMethodException, IOException, UnsupportedParameterException, AlreadyExistException {
+    this.jpInit(f, u);
+    StringBuffer names = new StringBuffer();
+    for (final TomcatWorker tw : c) {
+      names.append(tw.getName());
+      names.append(',');
+      try {
+        m.invoke(this, u, null, jp, tw);
+      } catch (IllegalAccessException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      } catch (InvocationTargetException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("InvocationTargetException: " + e.getMessage());
+        }
+        Throwable ex = e.getCause();
+        if (ex != null) {
+          logger.info("TMCMessage: " + ex.getMessage());
+          logger.info("Class: " + ex.getClass());
+          if (ex instanceof UnsupportedParameterException) {
+            throw new UnsupportedParameterException(ex.getMessage());
+          }
+          if (ex instanceof TMCIllegalArgumentException) {
+            throw new TMCIllegalArgumentException(ex.getMessage());
+          }
+          if (ex instanceof AuthorizationException) {
+            throw new AuthorizationException(ex.getMessage());
+          }
+          if (ex instanceof AlreadyExistException) {
+            throw new AlreadyExistException(ex.getMessage());
+          }
+          if (ex instanceof TMCException) {
+            throw new TMCException(ex.getMessage());
+          }
+          if (ex instanceof SQLException) {
+            throw new SQLException(ex.getMessage());
+          }
+        }
+      }
+    }
+    jp.setOptions(names.toString());
+    jp.setState(State.NEW);
+    JobPool.update(jp);
+  }
+
+  public void deployTomcatConfig(User u, Project p, JobPool jobPool, TomcatWorker tw) throws SQLException, AuthorizationException, IOException, TMCIllegalArgumentException {
+    Function f = Function.getFunction("DeployTomcatConfig");
+    if (!u.isAllowed(f, p)) throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    this.deployTomcatConfig(u, p, jobPool, tw, f);
+  }
+
+  public void deployTomcatConfig(User u, Project p, JobPool jobPool, TomcatWorker tw, Function f) throws SQLException, AuthorizationException, IOException, TMCIllegalArgumentException {
+    f = Function.getFunction("PutFile");
+    State s = State.NEW;
+    if (jobPool == null) {
+      jobPool = new JobPool(p, u, s, tw.getName(), f);
+      jobPool = JobPool.store(jobPool);
+    }
+    if (jobPool != null && tw.getTomcat() != null && f != null) {
+      Job j = new Job(-1, s, tw.getTomcat().getBaseLocation() + "/conf/server.xml", tw.getHardware(), f, jobPool);
+      ServerXmlFile sxf = new ServerXmlFile(tw);
+      j.setResult(sxf.build());
+      Job.store(j);
+      HardwareModel hm = new HardwareModel();
+      hm.deployJvmConf(u, tw.getHardware(), jobPool);
+    } else {
+      throw new TMCIllegalArgumentException("Error with input");
+    }
+  }
+
+  private void function(User u, Project p, String functionCommand, String options, JobPool jobPool, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    Function f = Function.getFunction(functionCommand);
+    this.function(u, p, f, options, jobPool, tw);
+  }
+
+  private void function(User u, Project p, Function f, String origOptions, JobPool jobPool, TomcatWorker tw) throws SQLException, IOException, AuthorizationException {
+    Job ret = null;
+    String options;
+    if (!u.isAllowed(f, p)) throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    if (origOptions == null || "".equals(origOptions)) {
+      options = tw.getTomcat().getServerName();
+    } else {
+      options = tw.getTomcat().getServerName() + PropertiesFile.getConstantValue("agent.delim.options") + origOptions;
+    }
+    State s = State.NEW;
+    AuthorizationManager am = u.getAuthManager();
+    if (am.hasPermission(u, f, p)) {
+      if (jobPool == null) {
+        jobPool = new JobPool(p, u, s, options, f);
+        jobPool = JobPool.store(jobPool);
+      }
+      if (jobPool != null && options != null && !"".equals(options) && f != null) {
+        Job j = new Job(-1, s, options, tw.getHardware(), f, jobPool);
+        ret = Job.store(j);
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + ret);
+    }
+  }
+
+  public TomcatWorker viewTomcatWorker(int id) throws SQLException {
+    return TomcatWorker.getTomcatWorker(id, false);
+  }
+
+  public Collection<TomcatWorker> viewTomcatWorkers() throws SQLException {
+    return TomcatWorker.getTomcatWorkers(false);
+  }
+
+  public Collection<TomcatWorker> getObjects() throws SQLException {
+    return new TMCSet<TomcatWorker>(this.viewTomcatWorkers());
+  }
+
+  public TomcatWorker getObject(int id) throws SQLException {
+    return this.viewTomcatWorker(id);
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/ContextAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/ContextAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/ContextAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/ContextAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,220 @@
+/*
+* 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.tomcat.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.pool.HostingPool;
+import lokahi.core.api.project.Project;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AlreadyExistException;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.gui.www.TMCAction;
+import lokahi.httpd.api.entity.VirtualHost;
+import lokahi.tomcat.api.entity.TomcatContext;
+import lokahi.tomcat.api.entity.TomcatContextModel;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ContextAction.java,v 1.2 2006/03/07 22:05:24 drtobes Exp $
+ */
+public class ContextAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(ContextAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      TomcatContextModel tcm = new TomcatContextModel();
+      String action = f.getCommand();
+      if ("AddContext".equals(action)) {
+        add(form, f, user, tcm);
+      } else if ("DeleteContext".equals(action)) {
+        delete(form, f, user, tcm);
+      } else if ("UpdateContext".equals(action)) {
+        update(form, f, user, tcm);
+      } else if ("RemoveContextFromVhost".equals(action)) {
+        removeContextFromVhost(form, f, user, tcm);
+      } else {
+        String id = (String) form.get("id");
+        Project p = Project.getProject(Integer.parseInt((String) form.get("projectId")));
+        TomcatContext tc = TomcatContext.getTomcatContext(Integer.parseInt(id));
+        tcm.perform(f, new Class[]{p.getClass(), user.getClass(), tc.getClass()}, new Object[]{p, user, tc});
+      }
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand()));
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (AlreadyExistException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.context.name.exists"));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    }
+    return messages;
+  }
+
+  private void add(DynaValidatorForm form, Function f, User u, TomcatContextModel tcm) throws TMCIllegalArgumentException, SQLException, IOException, AlreadyExistException, AuthorizationException {
+    TomcatContext tc = getTemplate(form);
+    if ("0".equals(form.get("vhostId")) || "0".equals(form.get("hpId")) || "0".equals(form.get("projectId")))
+      throw new TMCIllegalArgumentException("Error with input");
+    Project p = null;
+    if (!"".equals(form.get("projectId"))) {
+      int projectId = Integer.parseInt((String) form.get("projectId"));
+      p = Project.getProject(projectId);
+    }
+    HostingPool hp = HostingPool.getHostingPool(Integer.parseInt((String) form.get("hpId")), true);
+    VirtualHost vh = VirtualHost.getVirtualHost(Integer.parseInt((String) form.get("vhostId")));
+    tcm.addContext(tc, vh, hp, p, u, Function.getFunction("AddContext"));
+  }
+
+  public void update(DynaValidatorForm form, Function f, User u, TomcatContextModel tcm) throws SQLException, IOException, TMCIllegalArgumentException, AlreadyExistException, AuthorizationException {
+    TomcatContext tc = TomcatContext.getTomcatContext(Integer.parseInt((String) form.get("contextId")));
+    Project p = null;
+    if (!"-1".equals(form.get("projectId")))
+      p = Project.getProject(Integer.parseInt((String) form.get("projectId")));
+    tc.setName((String) form.get("contextName"));
+    tc.setDocBase((String) form.get("docBase"));
+    String appxml = (String) form.get("appxml");
+    if (!"".equals(form.get("poolId"))) {
+      tc.setTomcatPoolId(Integer.parseInt((String) form.get("poolId")));
+    }
+    tc.setApplicationXml(appxml);
+    tc.setStateId(Integer.parseInt((String) form.get("stateId")));
+    tc.setEnvId(Integer.parseInt((String) form.get("envId")));
+    tcm.updateContext(tc, u, f, p);
+  }
+
+//   				    <form name="Form" method="post" action='$link.setAction("/administration/Context/Delete")'>
+//    #else
+//  				    <form name="Form" method="post" action='$link.setAction("Context/SubmitJobAction")'>
+//    #end
+//              <input type="hidden" id="id" name="id" value="$!{cid}">
+//         #if($vid)
+//              <input type="hidden" id="vhostId" name="vhostId" value="$!{vid}">
+//         #end
+//         #if ($f.getStartCommand() ==  "RemoveContextFromVhost")
+//              Remove from project?  <input type="checkbox" name="removeFromProject" id="removeFromProject" value="true"><br>
+//         #end
+//              <input type="hidden" id="projectId" name="projectId" value="$!{pid}">
+
+  public void removeContextFromVhost(DynaValidatorForm form, Function f, User u, TomcatContextModel tcm) throws SQLException, TMCIllegalArgumentException, AuthorizationException {
+    TomcatContext tc = TomcatContext.getTomcatContext(Integer.parseInt((String) form.get("id")));
+    Project p = Project.getProject(Integer.parseInt((String) form.get("projectId")));
+    VirtualHost vh = VirtualHost.getVirtualHost(Integer.parseInt((String) form.get("vhostId")));
+    if ("true".equalsIgnoreCase((String) form.get("removeFromProject"))) {
+      tcm.removeContextFromVhost(tc, vh, p, u, f, true);
+    } else {
+      tcm.removeContextFromVhost(tc, vh, p, u, f, false);
+    }
+  }
+
+  public void delete(DynaValidatorForm form, Function f, User u, TomcatContextModel tcm) throws SQLException, IOException, TMCIllegalArgumentException, AuthorizationException {
+    Collection<TomcatContext> c = getMultiTemplate(form);
+    tcm.deleteContext(c, u, f);
+  }
+
+  private Collection<TomcatContext> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Collection<TomcatContext> c = new TMCSet<TomcatContext>();
+    String[] ids = (String[]) dynaForm.get("id");
+    if (ids != null && ids.length > 0) {
+      StringBuffer names = new StringBuffer();
+      for (final String newVar : ids) {
+        if (!"".equals(newVar)) {
+          TomcatContext tc = TomcatContext.getTomcatContext(Integer.parseInt(newVar));
+          if (tc != null) {
+            c.add(tc);
+            names.append(tc.getName());
+            names.append(',');
+          }
+        }
+      }
+    }
+    return c;
+  }
+
+  private TomcatContext getTemplate(DynaValidatorForm dynaForm) {
+    TomcatContext tc = new TomcatContext();
+    String contextId = null;
+    if (dynaForm.getMap().containsKey("contextId")) {
+      contextId = (String) dynaForm.get("contextId");
+    }
+    String contextName = (String) dynaForm.get("contextName");
+    String docBase = (String) dynaForm.get("docBase");
+    String stateId = (String) dynaForm.get("stateId");
+    String envId = (String) dynaForm.get("envId");
+    String appxml = (String) dynaForm.get("appxml");
+    tc.setApplicationXml(appxml);
+    if (contextId != null) {
+      tc.setPk(Integer.parseInt(contextId));
+    }
+    if (contextName != null) {
+      tc.setName(contextName);
+    }
+    if (docBase != null) {
+      tc.setDocBase(docBase);
+    }
+    if (stateId != null) {
+      tc.setStateId(Integer.parseInt(stateId));
+    }
+    if (envId != null) {
+      tc.setEnvId(Integer.parseInt(envId));
+    }
+    return tc;
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,146 @@
+/*
+* 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.tomcat.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.gui.www.TMCAction;
+import lokahi.tomcat.api.server.Tomcat;
+import lokahi.tomcat.api.server.TomcatModel;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TomcatAction.java,v 1.1 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class TomcatAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(TomcatAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      TomcatModel tm = new TomcatModel();
+      if ("AddTomcat".equalsIgnoreCase(f.getCommand()) || "UpdateTomcat".equalsIgnoreCase(f.getCommand())) {
+        Tomcat t = getTemplate(form);
+        tm.perform(f, new Class[]{user.getClass(), Tomcat.class, f.getClass()}, new Object[]{user, t, f});
+      } else {
+        Collection<Tomcat> c = getMultiTemplate(form);
+        tm.perform(f, new Class[]{user.getClass(), Collection.class, f.getClass()}, new Object[]{user, c, f});
+      }
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Collection<Tomcat> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Collection<Tomcat> c = new TMCSet<Tomcat>();
+    String[] ids = (String[]) dynaForm.get("id");
+    if (ids != null && ids.length > 0) {
+      StringBuffer names = new StringBuffer();
+      for (final String id : ids) {
+        if (!"".equals(id)) {
+          Tomcat tc = Tomcat.getTomcat(Integer.parseInt(id), true);
+          if (tc != null) {
+            c.add(tc);
+            names.append(tc.getName());
+            names.append(',');
+          }
+        }
+      }
+    }
+    return c;
+  }
+
+  private Tomcat getTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Tomcat t;
+    String tomcatType = (String) dynaForm.get("tomcatType");
+    t = new Tomcat();
+    t.setType(Integer.parseInt(tomcatType));
+    String Id = null;
+    if (dynaForm.getMap().containsKey("id")) {
+      Id = (String) dynaForm.get("id");
+    }
+    String name = (String) dynaForm.get("name");
+    String base = (String) dynaForm.get("baseLocation");
+    String home = (String) dynaForm.get("tomcatHome");
+    String http = (String) dynaForm.get("httpPort");
+    String sUser = (String) dynaForm.get("sysUser");
+    String group = (String) dynaForm.get("sysGroup");
+    String env = (String) dynaForm.get("env");
+    String opts = (String) dynaForm.get("javaOpts");
+    String description = (String) dynaForm.get("description");
+    String javaHome = (String) dynaForm.get("javaHome");
+    String startClass = (String) dynaForm.get("startClass");
+    String stdOutLog = (String) dynaForm.get("stdOutLog");
+    if (Id != null && !"".equals(Id)) {
+      t.setPk(Integer.parseInt(Id));
+    }
+    t.setName(name);
+    t.setEnvironment(env);
+    t.setJavaOptions(opts);
+    t.setBaseLocation(base);
+    t.setTomcatHome(home);
+    t.setDescription(description);
+    if (http != null && !"".equals(http)) {
+      t.setHttpPort(Integer.parseInt(http));
+    }
+    t.setSysUser(sUser);
+    t.setSysGroup(group);
+    t.setStartClass(startClass);
+    t.setStdOutLog(stdOutLog);
+    t.setJavaHome(javaHome);
+    return t;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatPoolAction.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatPoolAction.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatPoolAction.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/tomcat/gui/www/TomcatPoolAction.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,141 @@
+/*
+* 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.tomcat.gui.www;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.server.Hardware;
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.gui.www.TMCAction;
+import lokahi.tomcat.api.pool.TomcatPool;
+import lokahi.tomcat.api.pool.TomcatPoolModel;
+import lokahi.tomcat.api.server.Tomcat;
+import lokahi.tomcat.api.worker.TomcatWorker;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.DynaValidatorForm;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TomcatPoolAction.java,v 1.2 2006/03/07 22:05:24 drtobes Exp $
+ */
+public class TomcatPoolAction extends TMCAction {
+  static final Logger logger = Logger.getLogger(TomcatPoolAction.class);
+
+  public ActionMessages executeFunctions(DynaValidatorForm form, Function f, User user) {
+    ActionMessages messages = new ActionMessages();
+    try {
+      TomcatPoolModel tpm = new TomcatPoolModel();
+      if ("AddTomcatPool".equalsIgnoreCase(f.getCommand()) || "UpdateTomcatPool".equalsIgnoreCase(f.getCommand())) {
+        TomcatPool tp = getTemplate(form);
+        tpm.perform(f, new Class[]{user.getClass(), tp.getClass(), f.getClass()}, new Object[]{user, tp, f});
+      } else {
+        Collection<TomcatPool> c = getMultiTemplate(form);
+        tpm.perform(f, new Class[]{user.getClass(), Collection.class, f.getClass()}, new Object[]{user, c, f});
+      }
+      messages = this.addMessage(messages, SUCCESS_MESSAGE, new ActionMessage("function.success." + f.getCommand()));
+    } catch (AuthorizationException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.notAuthorized"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.db"));
+    } catch (TMCIllegalArgumentException e) {
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.invalidFunction", f.getCommand()));
+    } catch (TMCException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      messages = this.addMessage(messages, new ActionMessage("error.badData"));
+    }
+    return messages;
+  }
+
+  private Collection<TomcatPool> getMultiTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    Collection<TomcatPool> c = new TMCSet<TomcatPool>();
+    String[] ids = (String[]) dynaForm.get("id");
+    if (ids != null && ids.length > 0) {
+      for (int i = 0; i < ids.length; i++) {
+        if (!"".equals(ids[i])) {
+          TomcatPool tp = TomcatPool.getTomcatPool(Integer.parseInt(ids[i]));
+          if (tp != null) {
+            c.add(tp);
+          }
+        }
+      }
+    }
+    return c;
+  }
+
+  private TomcatPool getTemplate(DynaValidatorForm dynaForm) throws SQLException {
+    TomcatPool tp = new TomcatPool();
+    String id = null;
+    if (dynaForm.getMap().containsKey("poolId")) {
+      id = (String) dynaForm.get("poolId");
+    }
+    String name = (String) dynaForm.get("poolName");
+    String envId = (String) dynaForm.get("envId");
+    String[] tomcats = (String[]) dynaForm.get("tomcatId");
+    String[] hardware = (String[]) dynaForm.get("hardwareId");
+    if (id != null && !"".equals(id)) {
+      tp.setPk(Integer.parseInt(id));
+    }
+    if (envId != null && !"".equals(envId)) {
+      tp.setEnvId(Integer.parseInt(envId));
+    }
+    tp.setName(name);
+    if (tomcats != null && tomcats.length > 0) {
+      Collection<TomcatWorker> c = new TMCSet<TomcatWorker>();
+      for (int i = 0; i < tomcats.length; i++) {
+        Hardware h = Hardware.getHardware(Integer.parseInt(hardware[i]), true);
+        Tomcat t = Tomcat.getTomcat(Integer.parseInt(tomcats[i]), true);
+        TomcatWorker tw = TomcatWorker.getTomcatWorker(h, t, false);
+        if (tw != null) {
+          c.add(tw);
+        } else {
+          c.add(TomcatWorker.store(new TomcatWorker(h, t)));
+        }
+      }
+      tp.setTomcatWorkers(c);
+    }
+    return tp;
+  }
+
+}
+
+
+
+
+



Mime
View raw message