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 [9/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/con...
Date Mon, 10 Apr 2006 16:20:11 GMT
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/Environment.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/Environment.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/Environment.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/Environment.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,208 @@
+/*
+* 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.api.environment;
+
+import lokahi.core.api.project.Project;
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.core.common.util.PropertiesFile;
+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: Environment.java,v 1.4 2006/03/13 21:56:56 drtobes Exp $
+ */
+public class Environment extends TMCDao<Environment> {
+  static final Logger logger = Logger.getLogger(Environment.class);
+  private static final TMCBroker<Environment> broker = new BrokerFactory<Environment>().getBroker();
+  private int id;
+  private String name;
+  private String comment;
+
+  public int getPk() {
+    return id;
+  }
+
+  public void setPk(int id) {
+    this.id = id;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getComment() {
+    return comment;
+  }
+
+  public void setComment(String comment) {
+    this.comment = comment;
+  }
+
+  public Environment() {
+  }
+
+  public Environment(String name) {
+    this.setName(name);
+    this.setComment("");
+  }
+
+  public Environment(String name, String comment) {
+    this.setName(name);
+    this.setComment(comment);
+  }
+
+  public Environment(int id, String name, String comment) {
+    this.setPk(id);
+    this.setName(name);
+    this.setComment(comment);
+  }
+
+  public Environment get(int id) throws SQLException {
+    return broker.getObject(Environment.class, "core.environment.by.id", true, id);
+  }
+
+  /**
+   * @param id
+   * @param fromCache
+   *
+   * @return
+   * @throws SQLException
+   * @deprecated
+   */
+  public static Environment getEnviroment(int id, boolean fromCache) throws SQLException {
+    Environment en;
+    try {
+      en = broker.getObject(Environment.class, "core.environment.by.id", fromCache, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Input id=" + id + "Returning en =" + en);
+    }
+    return en;
+  }
+
+  public static Collection<Environment> getEnviroments() throws SQLException {
+    Collection<Environment> c;
+    try {
+      c = broker.getObjects(Environment.class, true, "core.environment.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<Environment> getEnviroments(Project p) throws SQLException {
+    Collection<Environment> c;
+    try {
+      c = broker.getObjects(Environment.class, true, "core.environment.by.project", p.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  static Environment store(Environment env) throws SQLException {
+    env.setPk(broker.save("core.environment.store", env.getName(), env.getComment()));
+    return env;
+  }
+
+  static boolean delete(Environment env) throws SQLException {
+    return broker.delete("core.environment.delete", env.getPk());
+  }
+
+  static void update(Environment env) throws SQLException {
+    broker.update("core.environment.update", env.getPk(), env.getName(), env.getComment());
+  }
+
+  public Environment fillObject(ResultSet r) throws SQLException {
+    return new Environment(r.getInt("ENV_ID"), r.getString("ENV_NAME"), r.getString("COMMENTS"));
+  }
+
+  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") + "environment/" + this.getPk() + '/');
+    return elementBuilder("environment", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<environment>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("comment", this.getComment()));
+    ret.append("</environment>\n");
+    return ret;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Environment)) return false;
+
+    final Environment environment = (Environment) o;
+
+    if (id != environment.id) return false;
+    if (comment != null ? !comment.equals(environment.comment) : environment.comment != null) return false;
+    if (name != null ? !name.equals(environment.name) : environment.name != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = id;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    result = 29 * result + (comment != null ? comment.hashCode() : 0);
+    return result;
+  }
+
+  public String toString() {
+    final StringBuffer buf = new StringBuffer();
+    buf.append("Environment");
+    buf.append("{id=").append(id);
+    buf.append(",name=").append(name);
+    buf.append(",comment=").append(comment);
+    buf.append('}');
+    return buf.toString();
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/EnvironmentModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/EnvironmentModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/EnvironmentModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/environment/EnvironmentModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,99 @@
+/*
+* 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.api.environment;
+
+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.TMCException;
+import lokahi.core.common.interfaces.LokahiModel;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: EnvironmentModel.java,v 1.3 2006/03/07 20:18:46 drtobes Exp $
+ */
+public class EnvironmentModel extends LokahiModel<Environment> {
+
+  public EnvironmentModel() {
+  }
+
+  public void addEnvironment(User u, Environment e, Function f) throws SQLException, TMCException {
+    jpInit(f, u, e.getName());
+    if (u.isAllowed(f) && "AddEnvironmen".equals(f.getName())) {
+      Environment.store(e);
+      jp.setState(State.COMPLETE);
+      JobPool.update(jp);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " not allowed to " + f.getName());
+    }
+  }
+
+  public void deleteEnvironment(User u, Environment e, Function f) throws SQLException, TMCException {
+    jpInit(f, u, e.getName());
+    if (u.isAllowed(f) && "DeleteEnvironment".equals(f.getName())) {
+      if (Environment.delete(e)) {
+        jp.setState(State.COMPLETE);
+        JobPool.update(jp);
+      } else {
+        throw new IllegalArgumentException("Environment could not be deleted check DB");
+      }
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " not allowed to " + f.getName());
+    }
+  }
+
+  public void updateEnvironment(User u, Environment e, Function f) throws SQLException, TMCException {
+    jpInit(f, u, e.getName());
+    if (u.isAllowed(f) && "DeleteEnvironment".equals(f.getName())) {
+      if (e.getPk() < 1 || e.getName() == null) {
+        throw new IllegalArgumentException("error.badData");
+      }
+      Environment.update(e);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public Environment viewEnvironment(int id) throws SQLException {
+    return Environment.getEnviroment(id, true);
+  }
+
+  public Collection<Environment> viewEnvironments() throws SQLException {
+    return Environment.getEnviroments();
+  }
+
+  public Collection<Environment> getObjects() throws SQLException {
+    return new TMCSet<Environment>(this.viewEnvironments());
+  }
+
+  public Environment getObject(int id) throws SQLException {
+    return this.viewEnvironment(id);
+  }
+}
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/File.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/File.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/File.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/File.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,282 @@
+/*
+* 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.api.file;
+
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.Entity;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.core.common.util.PropertiesFile;
+import org.apache.log4j.Logger;
+
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: File.java,v 1.3 2006/03/13 21:56:57 drtobes Exp $
+ */
+public class File extends TMCDao<File> implements Entity {
+  static final Logger logger = Logger.getLogger(File.class);
+  private static final TMCBroker<File> broker = new BrokerFactory<File>().getBroker();
+  private int pk;
+  private String name;
+  private String content;
+  private String descriptor;
+  private String path;
+
+  public File() {
+  }
+
+  public File(String name, String content, String discriptor, String path) {
+    this.name = name;
+    this.content = content;
+    this.descriptor = discriptor;
+    this.path = path;
+  }
+
+  public File(int pk, String name, String discriptor, String path, Blob content) throws SQLException {
+    this.pk = pk;
+    this.name = name;
+    this.descriptor = discriptor;
+    this.path = path;
+    if (content != null)
+      this.setContent(content.getBytes(1, (int) content.length()));
+  }
+
+  public int getPk() {
+    return pk;
+  }
+
+  public void setPk(int pk) {
+    this.pk = pk;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getContent() {
+    if (content == null) {
+      content = "";
+    }
+    return content;
+  }
+
+  public void setContent(byte[] content) throws SQLException {
+    if (content != null) {
+      this.content = new String(content);
+    } else {
+      if (logger.isDebugEnabled()) {
+        logger.debug("content=" + content);
+      }
+      this.content = "";
+    }
+  }
+
+  public void setContent(String content) {
+    this.content = content;
+  }
+
+  public String getDescriptor() {
+    return descriptor;
+  }
+
+  public void setDescriptor(String discriptor) {
+    this.descriptor = discriptor;
+  }
+
+  public String getPath() {
+    return path;
+  }
+
+  public void setPath(String path) {
+    this.path = path;
+  }
+
+  public File fillObject(ResultSet r) throws SQLException {
+    return new File(r.getInt("FILE_ID"), r.getString("FILE_NAME"), r.getString("FILE_DESCRIPTOR"), r.getString("FILE_PATH"), r.getBlob("FILE_CONTENT"));
+  }
+
+  static File store(File f) throws SQLException {
+    File ret = null;
+    try {
+      f.setPk(broker.save("core.file.store", f.getName(), f.getDescriptor(), f.getPath()));
+      if (logger.isDebugEnabled()) {
+        logger.debug("f=" + f);
+      }
+      if (storeBlob(f.getPk(), f.getContent())) {
+        ret = f;
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + ret);
+    }
+    return ret;
+  }
+
+  static boolean update(File f) throws SQLException {
+    boolean ret = false;
+    try {
+      broker.update("core.file.update", f.getPk(), f.getName(), f.getDescriptor(), f.getPath());
+      if (logger.isDebugEnabled()) {
+        logger.debug("f=" + f);
+      }
+      if (storeBlob(f.getPk(), f.getContent())) {
+        ret = true;
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + ret);
+    }
+    return ret;
+  }
+
+  private static boolean storeBlob(int id, String toStore) throws SQLException {
+    boolean ret = false;
+    try {
+      broker.useSQL("core.file.prep.blob", id);
+      if (toStore == null) toStore = "";
+      byte[] blobBytes = toStore.getBytes();
+      broker.blobHack("core.file.content.lock", "core.file.content.update", id, blobBytes);
+      ret = true;
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return ret;
+  }
+
+  static boolean delete(File f) throws SQLException {
+    return broker.delete("core.file.delete", f.getPk());
+  }
+
+  public File get(int id) throws SQLException {
+    return broker.getObject(File.class, "core.file.by.id", false, id);
+  }
+
+  /**
+   * @param id
+   *
+   * @return
+   * @throws SQLException
+   * @deprecated
+   */
+  public static File getFile(int id) throws SQLException {
+    File f;
+    try {
+      f = broker.getObject(File.class, "core.file.by.id", false, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return f;
+  }
+
+  public static Collection<File> getFiles() throws SQLException {
+    Collection<File> c;
+    try {
+      c = broker.getObjects(File.class, false, "core.file.all");
+    } 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") + "file/" + this.getPk() + '/');
+    return elementBuilder("file", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<file>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("content", this.getContent()));
+    ret.append(elementBuilder("descriptor", this.getDescriptor()));
+    ret.append(elementBuilder("path", this.getPath()));
+    ret.append("</file>\n");
+    return ret;
+  }
+
+  public String toString() {
+    final StringBuffer buf = new StringBuffer();
+    buf.append("File");
+    buf.append("{pk=").append(pk);
+    buf.append(",name=").append(name);
+    buf.append(",content=").append(content);
+    buf.append(",descriptor=").append(descriptor);
+    buf.append(",path=").append(path);
+    buf.append('}');
+    return buf.toString();
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof File)) return false;
+
+    final File file = (File) o;
+
+    if (pk != file.pk) return false;
+    if (descriptor != null ? !descriptor.equals(file.descriptor) : file.descriptor != null) return false;
+    if (name != null ? !name.equals(file.name) : file.name != null) return false;
+    if (path != null ? !path.equals(file.path) : file.path != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = pk;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    result = 29 * result + (descriptor != null ? descriptor.hashCode() : 0);
+    result = 29 * result + (path != null ? path.hashCode() : 0);
+    return result;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/FileModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/FileModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/FileModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/file/FileModel.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.core.api.file;
+
+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: FileModel.java,v 1.3 2006/03/07 20:18:47 drtobes Exp $
+ */
+public class FileModel extends LokahiModel<File> {
+
+  public void addFile(User u, File fi, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+    this.jpInit(f, u, fi.getName());
+    if (u.isAllowed(f) && "AddFile".equals(f.getCommand())) {
+      File.store(fi);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public void deleteFile(User u, File fi, Function f) throws SQLException, AuthorizationException, TMCIllegalArgumentException {
+    if (fi == null || fi.getPk() < 1) throw new TMCIllegalArgumentException("File can not be null");
+    this.jpInit(f, u, fi.getName());
+    if (u.isAllowed(f) && "DeleteFile".equals(f.getCommand())) {
+      File.delete(fi);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public void updateFile(User u, File fi, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+    this.jpInit(f, u, fi.getName());
+    if (u.isAllowed(f) && "UpdateFile".equals(f.getCommand())) {
+      if (fi.getPk() > 1 && fi.getName() != null && !"".equals(fi.getName())) {
+        File.update(fi);
+      } else {
+        throw new TMCIllegalArgumentException("File can not be null");
+      }
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public File viewFile(int id) throws SQLException {
+    return File.getFile(id);
+  }
+
+  public Collection<File> viewFiles() throws SQLException {
+    return File.getFiles();
+  }
+
+  public Collection<File> getObjects() throws SQLException {
+    return new TMCSet<File>(this.viewFiles());
+  }
+
+  public File getObject(int id) throws SQLException {
+    return this.viewFile(id);
+  }
+}
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/Function.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/Function.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/Function.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/Function.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,195 @@
+/*
+* 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.api.function;
+
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.ReadOnlyBroker;
+import lokahi.core.common.interfaces.XMLDao;
+import lokahi.core.common.util.PropertiesFile;
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import java.io.Serializable;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Function.java,v 1.4 2006/03/13 21:56:59 drtobes Exp $
+ */
+public class Function extends XMLDao<Function> implements Serializable {
+  static final Logger logger = Logger.getLogger(Function.class);
+  private static final ReadOnlyBroker<Function> broker = new BrokerFactory<Function>().getBroker(new java.io.File(PropertiesFile.getConstantValue("prop.location") + "/WEB-INF/classes/function.xml"), Function.class);
+  private int id;
+  private String name;
+  private String command;
+
+  public int getPk() {
+    return this.id;
+  }
+
+  public void setPk(int pk) {
+    this.id = pk;
+  }
+
+  public String getName() {
+    return this.name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getCommand() {
+    return command;
+  }
+
+  public void setCommand(String command) {
+    this.command = command;
+  }
+
+  public Function() {
+  }
+
+  public Function(String name, String command) {
+    this.setName(name);
+    this.setCommand(command);
+  }
+
+  public Function(int pk, String name, String command) {
+    this.setPk(pk);
+    this.setName(name);
+    this.setCommand(command);
+  }
+
+  public Function get(int id) {
+    Function f = null;
+    try {
+      f = broker.getObject(Function.class, "core.function.by.id", true, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Getting id=" + id + "Setting f to " + f);
+    }
+    return f;
+  }
+
+  /**
+   * @param id
+   *
+   * @return function
+   * @deprecated
+   */
+  public static Function getFunction(int id) {
+    Function f = new Function();
+    return f.get(id);
+  }
+
+  public static Function getFunction(String command) {
+    Function f = null;
+    try {
+      f = broker.getObject(Function.class, "core.function.by.command", true, command);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Getting command=" + command + "Setting f to " + f);
+    }
+    return f;
+  }
+
+  public static Collection<Function> getFunctions() throws SQLException {
+    Collection<Function> c;
+    try {
+      c = broker.getObjects(Function.class, true, "core.function.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public Function fillObject(ResultSet r) throws SQLException {
+    return new Function(r.getInt("FUNCTION_ID"), r.getString("FUNCTION_NAME"), r.getString("FUNCTION_COMMAND"));
+  }
+
+  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("command", this.getCommand());
+    return elementBuilder("function", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<function>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("command", this.getCommand()));
+    ret.append("</function>\n");
+    return ret;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Function)) return false;
+
+    final Function function = (Function) o;
+
+    if (id != function.id) return false;
+    if (command != null ? !command.equals(function.command) : function.command != null) return false;
+    if (name != null ? !name.equals(function.name) : function.name != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = id;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    result = 29 * result + (command != null ? command.hashCode() : 0);
+    return result;
+  }
+
+  public String toString() {
+    final StringBuffer buf = new StringBuffer();
+    buf.append("Function");
+    buf.append("{id=").append(id);
+    buf.append(",name=").append(name);
+    buf.append(",command=").append(command);
+    buf.append('}');
+    return buf.toString();
+  }
+
+  public Function fillObject(Element el) {
+    return new Function(Integer.parseInt(el.getAttribute("id").getValue()), el.getAttribute("name").getValue(), el.getAttribute("command").getValue());
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/FunctionModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/FunctionModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/FunctionModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/function/FunctionModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,52 @@
+/*
+* 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.api.function;
+
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.interfaces.LokahiModel;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: FunctionModel.java,v 1.1 2006/03/06 22:31:46 drtobes Exp $
+ */
+public class FunctionModel extends LokahiModel<Function> {
+
+  public Function viewFunction(int id) throws SQLException {
+    return Function.getFunction(id);
+  }
+
+  public Collection<Function> viewFunctions() throws SQLException {
+    return Function.getFunctions();
+  }
+
+  public Collection<Function> getObjects() throws SQLException {
+    Collection<Function> c = new TMCSet<Function>();
+    c.addAll(this.viewFunctions());
+    return c;
+  }
+
+  public Function getObject(int id) throws SQLException {
+    return this.viewFunction(id);
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/Instance.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/Instance.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/Instance.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/Instance.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,213 @@
+/*
+* 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.api.instance;
+
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.core.common.util.PropertiesFile;
+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: Instance.java,v 1.2 2006/03/07 20:18:47 drtobes Exp $
+ */
+public class Instance extends TMCDao<Instance> {
+  static final Logger logger = Logger.getLogger(Instance.class);
+  private static final TMCBroker<Instance> broker = new BrokerFactory<Instance>().getBroker();
+  private int id;
+  private String name;
+  private String comments;
+
+  public int getPk() {
+    return id;
+  }
+
+  public void setPk(int id) {
+    this.id = id;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getComments() {
+    return comments;
+  }
+
+  public void setComments(String comments) {
+    this.comments = comments;
+  }
+
+  public Instance() {
+  }
+
+  public Instance(String name) {
+    this.setName(name);
+    this.setComments("");
+  }
+
+  public Instance(String name, String comments) {
+    this.setName(name);
+    this.setComments(comments);
+  }
+
+  public Instance(int id, String name, String comments) {
+    this.setPk(id);
+    this.setName(name);
+    this.setComments(comments);
+  }
+
+  public Instance get(int id) throws SQLException {
+    Instance i;
+    try {
+      i = broker.getObject(Instance.class, "core.instance.by.id", true, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Input " + id + " Returning i=" + i);
+    }
+    return i;
+  }
+
+  /**
+   * @param id
+   * @param fromCache
+   *
+   * @return
+   * @throws SQLException
+   * @deprecated
+   */
+  public static Instance getInstance(int id, boolean fromCache) throws SQLException {
+    Instance i = new Instance();
+    return i.get(id);
+  }
+
+  public static Instance getInstance(String name, boolean fromCache) throws SQLException {
+    Instance i;
+    try {
+      i = broker.getObject(Instance.class, "core.instance.by.name", fromCache, name);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Input " + name + " Returning i=" + i);
+    }
+    return i;
+  }
+
+  public static Collection<Instance> getInstances() throws SQLException {
+    Collection<Instance> c;
+    try {
+      c = broker.getObjects(Instance.class, true, "core.instance.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  static Instance store(Instance i) throws SQLException {
+    i.setPk(broker.save("core.instance.store", i.getName(), i.getComments()));
+    return i;
+  }
+
+  static boolean delete(Instance i) throws SQLException {
+    return broker.delete("core.instance.delete", i.getPk());
+  }
+
+  static void update(Instance i) throws SQLException {
+    broker.update("core.instance.update", i.getPk(), i.getName(), i.getComments());
+  }
+
+  public Instance fillObject(ResultSet r) throws SQLException {
+    return new Instance(r.getInt("INSTANCE_ID"),
+                        r.getString("INSTANCE_NAME"),
+                        r.getString("COMMENTS"));
+  }
+
+  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") + "instance/" + this.getPk() + '/');
+    return elementBuilder("instance", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<instance>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("comments", this.getComments()));
+    ret.append("</instance>\n");
+    return ret;
+  }
+
+  public String toString() {
+    final StringBuffer buf = new StringBuffer();
+    buf.append("Instance");
+    buf.append("{id=").append(id);
+    buf.append(",name=").append(name);
+    buf.append(",comments=").append(comments);
+    buf.append('}');
+    return buf.toString();
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Instance)) return false;
+
+    final Instance instance = (Instance) o;
+
+    if (id != instance.id) return false;
+    if (comments != null ? !comments.equals(instance.comments) : instance.comments != null) return false;
+    if (name != null ? !name.equals(instance.name) : instance.name != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = id;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    result = 29 * result + (comments != null ? comments.hashCode() : 0);
+    return result;
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/InstanceModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/InstanceModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/InstanceModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/instance/InstanceModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,95 @@
+/*
+* 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.api.instance;
+
+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: InstanceModel.java,v 1.3 2006/03/07 20:18:47 drtobes Exp $
+ */
+public class InstanceModel extends LokahiModel<Instance> {
+
+  public void addInstance(User u, Instance i, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+    this.jpInit(f, u, i.getName());
+    if (u.isAllowed(f) && "AddInstance".equals(f.getCommand())) {
+      Instance.store(i);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public void deleteInstance(User u, Instance i, Function f) throws SQLException, AuthorizationException, TMCIllegalArgumentException {
+    if (i == null || i.getPk() < 1) throw new TMCIllegalArgumentException("Instance can not be null");
+    this.jpInit(f, u, i.getName());
+    if (u.isAllowed(f) && "DeleteInstance".equals(f.getCommand())) {
+      Instance.delete(i);
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public void updateInstance(User u, Instance i, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+    this.jpInit(f, u, i.getName());
+    if (u.isAllowed(f) && "UpdateInstance".equals(f.getCommand())) {
+      if (i.getPk() > 1 && i.getName() != null && !"".equals(i.getName())) {
+        Instance.update(i);
+      } else {
+        throw new TMCIllegalArgumentException("Instance can not be null");
+      }
+    } else {
+      throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+    }
+    jp.setState(State.COMPLETE);
+    JobPool.update(jp);
+  }
+
+  public Instance viewInstance(int id) throws SQLException {
+    return Instance.getInstance(id, true);
+  }
+
+  public Collection<Instance> viewInstances() throws SQLException {
+    return Instance.getInstances();
+  }
+
+  public Collection<Instance> getObjects() throws SQLException {
+    return new TMCSet<Instance>(this.viewInstances());
+  }
+
+  public Instance getObject(int id) throws SQLException {
+    return this.viewInstance(id);
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/Ip.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/Ip.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/Ip.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/Ip.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,207 @@
+/*
+* 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.api.ipaddress;
+
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.httpd.api.entity.VirtualHost;
+import org.apache.log4j.Logger;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Ip.java,v 1.2 2006/03/07 20:18:48 drtobes Exp $
+ */
+
+public class Ip extends TMCDao<Ip> {
+  static final Logger logger = Logger.getLogger(Ip.class);
+  private static final TMCBroker<Ip> broker = new BrokerFactory<Ip>().getBroker();
+  private int id;
+  private String name;
+
+  public StringBuilder buildXMLRepresention() {
+    return this.buildShortXMLRepresentation();
+  }
+
+  public StringBuilder buildShortXMLRepresentation() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<ip>\n");
+    ret.append(this.getName());
+    ret.append("</ip>\n");
+    return ret;
+  }
+
+  public int getPk() {
+    return this.id;
+  }
+
+  public void setPk(int pk) {
+    this.id = pk;
+  }
+
+  public String getName() {
+    return this.name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public Ip() {
+  }
+
+  public Ip(String Ip) {
+    this.setName(Ip);
+  }
+
+  public Ip(int id, String Ip) {
+    this.setName(Ip);
+    this.setPk(id);
+  }
+
+  public Ip get(int id) throws SQLException {
+    return broker.getObject(Ip.class, "core.ip.by.id", false, id);
+  }
+
+  public static Ip getIp(int id, boolean fromCache) throws SQLException {
+    Ip ip;
+    try {
+      ip = broker.getObject(Ip.class, "core.ip.by.id", fromCache, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return ip;
+  }
+
+  public static Ip getIp(String name, boolean fromCache) throws SQLException {
+    Ip ip;
+    try {
+      ip = broker.getObject(Ip.class, "core.ip.by.name", fromCache, name);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return ip;
+  }
+
+  public static Collection<Ip> getIps(int Id, boolean fromCache) throws SQLException {
+    Collection<Ip> c;
+    try {
+      c = broker.getObjects(Ip.class, fromCache, "core.ip.by.hardware", Id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<Ip> getIps(VirtualHost vh, boolean fromCache) throws SQLException {
+    Collection<Ip> c;
+    try {
+      c = broker.getObjects(Ip.class,
+                            fromCache, "core.ip.by.virtualhost",
+                            vh.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Collection<Ip> getIps() throws SQLException {
+    Collection<Ip> c;
+    try {
+      c = broker.getObjects(Ip.class, true, "core.ip.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Ip store(Ip ip) throws SQLException {
+    Ip ret;
+    ret = getIp(ip.getName(), true);
+    if (ret == null) {
+      ip.setPk(broker.save("core.ip.store", ip.getName()));
+      ret = ip;
+    }
+    return ret;
+  }
+
+  static boolean delete(Ip ip) throws SQLException {
+    return broker.delete("core.ip.delete", ip.getPk());
+  }
+
+  static void update(Ip ip) throws SQLException {
+    broker.update("core.ip.update", ip.getPk(), ip.getName());
+  }
+
+  public Ip fillObject(ResultSet r) throws SQLException {
+    return new Ip(r.getInt("IP_ID"),
+                  r.getString("IP"));
+  }
+
+  public String toString() {
+    final StringBuffer buf = new StringBuffer();
+    buf.append("Ip");
+    buf.append("{id=").append(id);
+    buf.append(",name=").append(name);
+    buf.append('}');
+    return buf.toString();
+  }
+
+  public boolean equals(Object o) {
+    boolean ret = false;
+    if (this == o) {
+      ret = true;
+    } else if (o instanceof Ip) {
+      final Ip ip = (Ip) o;
+
+      if (id == ip.id && !(name != null ? !name.equals(ip.name) : ip.name != null)) ret = true;
+    }
+    return ret;
+  }
+
+  public int hashCode() {
+    int result;
+    result = id;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    return result;
+  }
+}
+
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/IpModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/IpModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/IpModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/ipaddress/IpModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,36 @@
+/*
+* 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.api.ipaddress;
+
+import lokahi.core.common.interfaces.LokahiModel;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id$
+ */
+public class IpModel extends LokahiModel<Ip> {
+
+  public Collection<Ip> getObjects() throws SQLException {
+    return Ip.getIps();
+  }
+
+  public Ip getObject(int id) throws SQLException {
+    return Ip.getIp(id, false);
+  }
+}
\ No newline at end of file

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/Job.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/Job.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/Job.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/Job.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,872 @@
+/*
+* 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.api.job;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.instance.Instance;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.server.Hardware;
+import lokahi.core.api.state.State;
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.database.ConnBean;
+import lokahi.core.common.exception.UnsupportedParameterException;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.TMCDao;
+import lokahi.core.common.interfaces.TMCMessage;
+import lokahi.core.common.message.TMCSOAPMessage;
+import lokahi.core.common.util.PropertiesFile;
+import lokahi.core.controller.AdminBean;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedHashMap;
+
+/**
+ * A <b>Job</b> is an action that the controller needs to
+ * instruct the agent to perform
+ *
+ * @author Stephen Toback
+ * @version $Id: Job.java,v 1.5 2006/03/07 20:18:52 drtobes Exp $
+ */
+
+public class Job extends TMCDao implements TMCMessage {
+  static final Logger logger = Logger.getLogger(Job.class);
+  private static final AdminBean adminBean = new AdminBean();
+  private static final TMCBroker<Job> broker = new BrokerFactory<Job>().getBroker();
+
+  private int id;
+  private int poolId;
+  private String name;
+  private String result;
+  private int hardwareId;
+  private Date startTime;
+  private Date finishTime;
+  private int parentId = -1;
+  private int stateId;
+  private String options;
+  private int instanceId;
+  private int functionId;
+
+  private JobPool jobPool;
+  private Hardware hardware;
+  private State state;
+  private Function function;
+  private Job parent;
+
+  public Job() {
+  }
+
+  public Job(int parentId, State state, String options, Hardware h, Function func, JobPool jp) {
+    this.setParentId(parentId);
+    this.setState(state);
+    this.setOptions(options);
+    this.setFunction(func);
+    this.setJobPool(jp);
+    this.setHardware(h);
+    if (h != null) {
+      this.setInstanceId(h.getInstanceId());
+    }
+  }
+
+  public Job(String options, Hardware h, Function f, JobPool jp) {
+    this.setStateId(0);
+    this.setOptions(options);
+    this.setFunction(f);
+    this.setJobPool(jp);
+    this.setHardware(h);
+    if (h != null && h.getInstance() != null) {
+      this.setInstanceId(h.getInstance().getPk());
+    }
+  }
+
+  public Job(Job parent, String options, Hardware h, Function f, JobPool jp) {
+    if (parent != null)
+      this.setParentId(parent.getPk());
+    this.setParent(parent);
+    this.setStateId(0);
+    this.setOptions(options);
+    this.setFunction(f);
+    this.setJobPool(jp);
+    this.setHardware(h);
+    if (h != null && h.getInstance() != null) {
+      this.setInstanceId(h.getInstance().getPk());
+    }
+  }
+
+  public Job(String name, int state, String result, String options, String server, String command) throws SQLException {
+    this.setName(name);
+    this.setStateId(state);
+    this.setResult(result);
+    this.setOptions(options);
+    this.setHardware(Hardware.getHardware(server, adminBean.getInstance(), true));
+    this.setHardwareId(this.getHardware().getPk());
+    this.setFunction(Function.getFunction(command));
+    this.setFunctionId(this.getFunction().getPk());
+    this.setInstanceId(this.getHardware().getInstanceId());
+  }
+
+  public Job(int id, int poolId, String name, Blob result, int serverId, Date startTime, Date finishTime, int parentId, int stateId, String options, int instanceId, int functionId) throws SQLException {
+    this.setPk(id);
+    this.setPoolId(poolId);
+    this.setName(name);
+    this.setResult(result);
+    this.setHardwareId(serverId);
+    this.setStartTime(startTime);
+    this.setFinishTime(finishTime);
+    this.setParentId(parentId);
+    this.setStateId(stateId);
+    this.setOptions(options);
+    this.setInstanceId(instanceId);
+    this.setFunctionId(functionId);
+  }
+
+  public JobPool getJobPool() {
+    if (this.jobPool == null) {
+      try {
+        this.jobPool = JobPool.getJobPool(this.getPoolId());
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    }
+    return jobPool;
+  }
+
+  public void setJobPool(JobPool jobPool) {
+    this.jobPool = jobPool;
+    if (jobPool != null) {
+      this.setPoolId(jobPool.getPk());
+    }
+  }
+
+  public State getState() {
+    if (this.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 Hardware getHardware() {
+    if (this.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 Function getFunction() {
+    if (this.function == null) {
+      this.function = Function.getFunction(this.getFunctionId());
+    }
+    return function;
+  }
+
+  public void setFunction(Function function) {
+    this.function = function;
+    if (function != null) {
+      this.setFunctionId(function.getPk());
+    }
+  }
+
+  public Job getParent() throws SQLException {
+    if (this.parent == null) {
+      if (this.getParentId() == -1) {
+        this.parent = new Job();
+        this.parent.setName("");
+      } else {
+        this.parent = getJob(this.getParentId());
+      }
+    }
+    return parent;
+  }
+
+  public void setParent(Job parent) {
+    this.parent = parent;
+  }
+
+  public int getPk() {
+    return id;
+  }
+
+  public void setPk(int pk) {
+    this.id = pk;
+  }
+
+  public int getPoolId() {
+    return poolId;
+  }
+
+  public void setPoolId(int poolId) {
+    this.poolId = poolId;
+  }
+
+  public String getName() {
+    if (this.name == null) {
+      this.name = this.generateName();
+    }
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getResult() {
+    if (result == null)
+      result = "";
+    return result;
+  }
+
+  public void setResult(String result) {
+    this.result = result;
+  }
+
+  public void setResult(Blob content) throws SQLException {
+    if (content != null) {
+      this.result = new String(content.getBytes(1, (int) content.length()));
+    } else {
+      if (logger.isDebugEnabled()) {
+        logger.debug("content from DB WAS NULL");
+      }
+      this.result = "";
+    }
+  }
+
+  public int getHardwareId() {
+    return hardwareId;
+  }
+
+  public void setHardwareId(int containerId) {
+    this.hardwareId = containerId;
+  }
+
+  public Date getStartTime() {
+    return startTime;
+  }
+
+  public void setStartTime(Date startTime) {
+    this.startTime = startTime;
+  }
+
+  public Date getFinishTime() {
+    return finishTime;
+  }
+
+  public void setFinishTime(Date finishTime) {
+    this.finishTime = finishTime;
+  }
+
+  public int getParentId() {
+    return parentId;
+  }
+
+  public void setParentId(int parentId) {
+    this.parentId = parentId;
+  }
+
+  public int getStateId() {
+    return stateId;
+  }
+
+  public void setStateId(int stateId) {
+    this.stateId = stateId;
+    if (this.state != null && this.state.getPk() != stateId) this.setState(null);
+  }
+
+  public String getOptions() {
+    return options;
+  }
+
+  public void setOptions(String options) {
+    this.options = options;
+  }
+
+  public int getInstanceId() {
+    return instanceId;
+  }
+
+  public void setInstanceId(int instanceId) {
+    this.instanceId = instanceId;
+  }
+
+  public int getFunctionId() {
+    return functionId;
+  }
+
+  public void setFunctionId(int id) {
+    this.functionId = id;
+  }
+
+  public Instance getInstance() {
+    Instance i = null;
+    try {
+      Instance.getInstance(this.getInstanceId(), true);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return i;
+  }
+
+  public String generateName() {
+    String n = "C" + new Date().getTime();
+    return n;
+  }
+
+  public String receiveResponse(String key, String JobName, String parentJob, int jobState, String jobResult, String server) {
+    if (logger.isDebugEnabled()) {
+      logger.debug("Key: " + key + " Name: " + JobName + " Parent: " + parentJob + " State: " + jobState + " Result: " + jobResult + " Server: " + server);
+    }
+    Job j = null;
+    try {
+      j = getJob(JobName);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("j=" + j);
+    }
+    if (j != null) {
+      j.setResult(jobResult);
+      j.setStateId(jobState);
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("j=" + j);
+    }
+    // store the response and jobState in the DB and send a confirmation to the agent
+    String ret;
+    boolean thing = false;
+    if (j != null)
+      try {
+        ConnBean.connectionReporting();
+        thing = update(j);
+        ConnBean.connectionReporting();
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      } catch (IOException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    if (thing) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("Job.update completed successfully.");
+      }
+      ret = "Thanks for the submission of " + JobName;
+    } else {
+      logger.warn("Job.update failed...");
+      ret = "";
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Sending a thanks for jobId: " + JobName);
+    }
+    return ret;
+  } // end of receiveResponse
+
+  public String receiveResponse(String key, String jobName, String jobParent, int state, String result, String server, String command, String options, String user) {
+    Job j = null;
+    try {
+      j = new Job(jobName, state, result, options, server, command);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    // store the response and state in the DB and send a confirmation to the agent
+    if (j != null)
+      try {
+        j = store(j);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      } catch (IOException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    if (logger.isDebugEnabled()) {
+      logger.debug("j=" + j);
+    }
+    String ret;
+    boolean temp = false;
+    if (j != null)
+      try {
+        temp = update(j);
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      } catch (IOException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+    if (temp) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("Job.update completed successfully.");
+      }
+      ret = "Thanks for the submission of " + this.getName();
+    } else {
+      logger.warn("Job.update failed...");
+      ret = "";
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Sending a thanks for jobId: " + jobName);
+    }
+    return ret;
+  } // end of overloaded receiveResponse for TMCAgent created jobs.
+
+  public static Job store(Job j) throws SQLException, IOException {
+    Job ret = null;
+    if (j != null) {
+      try {
+        j.setPk(broker.save("core.job.store", j.getInstanceId(), j.getFunctionId(), j.getPoolId(), j.getHardwareId(), j.getParentId(), -1, j.getOptions()));
+        j.setName(j.getName() + j.getPk());
+        if (logger.isDebugEnabled()) {
+          logger.debug("j.getName()=" + j.getName());
+        }
+        broker.useSQL("core.job.prep.blob", j.getPk());
+        broker.blobHack("core.job.lock.result", "core.job.set.result", j.getPk(), j.getResult().getBytes());
+        broker.update("core.job.store.finish", j.getPk(), j.getName(), j.getStateId());
+        ret = j;
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("SQLException: " + e.getMessage());
+        }
+        throw e;
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Returning " + ret);
+    }
+    return ret;
+  } // end store
+
+  /**
+   * This method stores the job into the database, so the
+   * user can keep checking his 'Recent Jobs' to see if the request is processed
+   *
+   * @param j - Job to update
+   */
+  public static boolean update(Job j) throws SQLException, IOException {
+//    Connection conn = null;
+    boolean ret = false;
+    //   CallableStatement csmt;
+    try {
+//      conn = connBean.getConn();
+//      conn.setAutoCommit(false);
+//      csmt = conn.prepareCall("{call sp_tmc_update_job(?,?,?,EMPTY_BLOB())}");
+      int temp = broker.save("core.job.update", j.getPk(), j.getStateId());
+//      csmt.registerOutParameter(1, Types.INTEGER);
+//      csmt.setInt(2, j.getPk());
+//      csmt.setInt(3, j.getStateId());
+//      csmt.execute();
+//      conn.commit();
+//      int temp = csmt.getInt(1);
+//      csmt.close();
+      if (logger.isDebugEnabled()) {
+        logger.debug("j.getResult()=" + j.getResult());
+        logger.debug("Out Parameter=" + temp);
+      }
+      if (temp > 0) {
+        broker.useSQL("core.job.prep.blob", j.getPk());
+        broker.blobHack("core.job.lock.result", "core.job.set.result", j.getPk(), j.getResult().getBytes());
+        //         broker.useSQL(, j.getResult().getBytes(), j.getPk());
+//        PreparedStatement ps = conn.prepareStatement("SELECT RESULT FROM TMC_JOB where job_id=" + j.getPk() + " FOR UPDATE");
+//        ResultSet rs = ps.executeQuery();
+//        String jobResult = j.getResult();
+//        if (jobResult == null) jobResult = "";
+//        byte[] blobBytes = jobResult.getBytes();
+//        if (rs.next()) {
+//          BLOB dbBlob = (BLOB) rs.getBlob(1);
+//          if (dbBlob == null) {
+//            if (logger.isDebugEnabled()) {
+//              logger.debug("dbBlob is null, returning " + dbBlob);
+//            }
+//          } else {
+//            OutputStream os = dbBlob.getBinaryOutputStream();
+//            os.write(blobBytes);
+//            os.close();
+//            ps = conn.prepareStatement("UPDATE TMC_JOB  SET RESULT = ? where job_id=?");
+//            dbBlob.putBytes(1, blobBytes);
+//            ps.setBlob(1, dbBlob);
+//            ps.setInt(2, j.getPk());
+//            rs.close();
+//            ps.close();
+//            conn.commit();
+        ret = true;
+//          }
+//        }
+      } else if (temp == -1) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("temp=" + temp);
+          logger.debug("Something wierd happened out Value was -1!");
+        }
+      } else if (temp == 0) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("Not Updating because the database data is newer.");
+        }
+        ret = true;
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return ret;
+  } // end update
+
+  /**
+   * This method sends commands to the agent
+   *
+   * @return String
+   */
+  private String sendRequest() throws UnsupportedParameterException {
+    String ret = "";
+    if (this.getHardware() != null) {
+      String url = PropertiesFile.getConstantValue("AGENT_PROTOCOL") + this.getHardware().getServerName() + ':' + PropertiesFile.getConstantValue("AGENT_PORT") + PropertiesFile.getConstantValue("AGENT_ENDPOINT");
+      String ReturnTo = PropertiesFile.getConstantValue("AGENT_REPLY_TO_ADDRESS");
+      String ReturnEndpoint = PropertiesFile.getConstantValue("AGENT_REPLY_WEB_SERVICE_NAME");
+      String ReturnMethod = PropertiesFile.getConstantValue("AGENT_METHOD_TO_CALL_BACK");
+      String namespace = "JobHandler";
+      String method = "create";
+      String key = "";
+      TMCSOAPMessage m = new TMCSOAPMessage();
+      String[] args = null;
+      String[] params = null;
+      boolean hasAttach = false;
+      Job parentJob = null;
+      try {
+        parentJob = this.getParent();
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      }
+      if (this.getStateId() >= 0 && this.getFunction() != null && parentJob != null) {
+        params = new String[]{key,
+            this.getName(),
+            parentJob.getName(),
+            this.getFunction().getCommand() + PropertiesFile.getConstantValue("agent.delim.options") + this.getOptions(),
+            ReturnTo,
+            ReturnEndpoint,
+            ReturnMethod};
+
+        String functionCommand = this.getFunction().getCommand();
+        if ("PutFile".equals(functionCommand)) {
+          if (this.getResult() != null) {
+            //&& this.saveFileBackup(this.getResult())) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("Sending job with attachment... j=" + this);
+            }
+            hasAttach = true;
+            args = new String[]{url, namespace, method, this.getResult()};  //no ATTACHMENT!
+//          ret = this.sendRequestWithAttachent(this.getResult());
+          }
+        } else {
+          if (logger.isDebugEnabled()) {
+            logger.debug("Sending job with no attach=" + this);
+          }
+          args = new String[]{url, namespace, method};  //no ATTACHMENT!
+//        ret = this.sendRequestNoAttachment(); // null - parent
+        }
+      }
+      try {
+        if (logger.isDebugEnabled()) {
+          logger.debug("args=" + args);
+          logger.debug("params=" + params);
+          logger.debug("hasAttach=" + hasAttach);
+        }
+        if (args != null) {
+          if (logger.isDebugEnabled()) {
+            logger.debug("Are we even getting to this point?");
+          }
+          ret = m.send(params, hasAttach, args);
+        }
+      } catch (UnsupportedParameterException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        throw e;
+      } catch (Exception ex) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("ex.getMessage()=" + ex.getMessage());
+          logger.debug("ex.getStackTrace()=" + ex.toString());
+          logger.debug("ex.getClass()=" + ex.getClass());
+        }
+      }
+    } else {
+      if (logger.isInfoEnabled()) {
+        logger.info("ERROR: Hardware is null");
+      }
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("ret=" + ret);
+    }
+    return ret;
+  } // end sendRequest
+
+  public Job get(int id) throws SQLException {
+    Job j;
+    try {
+      j = broker.getObject(Job.class, "core.job.by.id", false, id);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return j;
+  }
+
+  public static Job getJob(int id) throws SQLException {
+    return new Job().get(id);
+  }
+
+  public static Collection<Job> getJobs() throws SQLException {
+    Collection<Job> c;
+    try {
+      c = broker.getObjects(Job.class, false, "core.job.all");
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public static Job getJob(String name) throws SQLException {
+    Job j;
+    if (logger.isDebugEnabled()) {
+      logger.debug("name=" + name);
+    }
+    try {
+      j = broker.getObject(Job.class, "core.job.by.name", false, name);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return j;
+  }
+
+  public static Collection<Job> getJobs(Instance i, State s) throws SQLException {
+    Collection<Job> c;
+    try {
+      c = broker.getObjects(Job.class,
+                            false, "core.job.by.instance.state",
+                            i.getPk(), s.getPk());
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  /**
+   * Returns a collection of ints that are the ids of the jobs in the job pool.
+   *
+   * @param poolId - pool id of the jobs to look for.
+   *
+   * @return Collection of jobs
+   */
+  public static Collection<Job> getJobs(int poolId) throws SQLException {
+    Collection<Job> c;
+    try {
+      c = broker.getObjects(Job.class,
+                            false, "core.job.by.pool",
+                            poolId);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    }
+    return c;
+  }
+
+  public Job fillObject(ResultSet r) throws SQLException {
+    Job j = new Job(r.getInt("JOB_ID"), r.getInt("POOL_ID"), r.getString("JOB_NAME"), r.getBlob("RESULT"),
+                    r.getInt("SERVER_ID"), r.getTimestamp("START_TIME"), r.getTimestamp("FINISH_TIME"), r.getInt("PARENT_ID"),
+                    r.getInt("STATE_ID"), r.getString("OPTIONS"), r.getInt("INSTANCE_ID"), r.getInt("FUNCTION_ID"));
+    return j;
+  }
+
+  public boolean send() {
+    boolean ret = false;
+    if (logger.isDebugEnabled()) {
+      logger.debug("Sending Job =" + this);
+    }
+    String returned = null;
+    try {
+      returned = this.sendRequest();
+    } catch (UnsupportedParameterException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (Exception e) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("Exception: " + e.getMessage());
+      }
+    }
+    if (returned != null && returned.indexOf(PropertiesFile.getConstantValue("agent.reply.message")) > -1) {
+      ret = true;
+    }
+    if (logger.isDebugEnabled()) {
+      logger.debug("Send message returned " + returned);
+      logger.debug("Returning " + ret);
+    }
+    return ret;
+  }
+
+  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") + "job/" + this.getPk() + '/');
+    return elementBuilder("job", map);
+  }
+
+  public StringBuilder buildXMLRepresention() {
+    StringBuilder ret = new StringBuilder();
+    ret.append("<job>\n");
+    ret.append(elementBuilder("id", Integer.toString(this.getPk())));
+    ret.append(elementBuilder("name", this.getName()));
+    ret.append(elementBuilder("start-time", this.getStartTime().toString()));
+    ret.append(elementBuilder("end-time", this.getFinishTime().toString()));
+    ret.append(elementBuilder("options", this.getOptions()));
+    ret.append(this.getInstance().buildShortXMLRepresentation());
+    ret.append(this.getHardware().buildShortXMLRepresentation());
+    ret.append(this.getState().buildShortXMLRepresentation());
+    ret.append(this.getFunction().buildShortXMLRepresentation());
+    try {
+      if (this.getParent() != null)
+        ret.append(this.getParent().buildShortXMLRepresentation());
+    } catch (SQLException e1) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e1.getMessage());
+      }
+    }
+    ret.append(this.getJobPool().buildShortXMLRepresentation());
+    ret.append("</job>\n");
+    return ret;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Job)) return false;
+
+    final Job job = (Job) o;
+
+    if (functionId != job.functionId) return false;
+    if (id != job.id) return false;
+    if (instanceId != job.instanceId) return false;
+    if (parentId != job.parentId) return false;
+    if (poolId != job.poolId) return false;
+    if (hardwareId != job.hardwareId) return false;
+    if (stateId != job.stateId) return false;
+    if (finishTime != null ? !finishTime.equals(job.finishTime) : job.finishTime != null) return false;
+    if (name != null ? !name.equals(job.name) : job.name != null) return false;
+    if (options != null ? !options.equals(job.options) : job.options != null) return false;
+    if (result != null ? !result.equals(job.result) : job.result != null) return false;
+    if (startTime != null ? !startTime.equals(job.startTime) : job.startTime != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result1;
+    result1 = id;
+    result1 = 29 * result1 + poolId;
+    result1 = 29 * result1 + (name != null ? name.hashCode() : 0);
+    result1 = 29 * result1 + (result != null ? result.hashCode() : 0);
+    result1 = 29 * result1 + hardwareId;
+    result1 = 29 * result1 + (startTime != null ? startTime.hashCode() : 0);
+    result1 = 29 * result1 + (finishTime != null ? finishTime.hashCode() : 0);
+    result1 = 29 * result1 + parentId;
+    result1 = 29 * result1 + stateId;
+    result1 = 29 * result1 + (options != null ? options.hashCode() : 0);
+    result1 = 29 * result1 + instanceId;
+    result1 = 29 * result1 + functionId;
+    return result1;
+  }
+
+  public String toString() {
+    final StringBuffer buf = new StringBuffer();
+    buf.append("Job");
+    buf.append("{id=").append(id);
+    buf.append(",poolId=").append(poolId);
+    buf.append(",name=").append(name);
+    buf.append(",hardwareId=").append(hardwareId);
+    buf.append(",startTime=").append(startTime);
+    buf.append(",finishTime=").append(finishTime);
+    buf.append(",parentId=").append(parentId);
+    buf.append(",stateId=").append(stateId);
+    buf.append(",options=").append(options);
+    buf.append(",instanceId=").append(instanceId);
+    buf.append(",functionId=").append(functionId);
+    buf.append(",jobPool=").append(jobPool);
+    buf.append(",hardware=").append(hardware);
+    buf.append(",state=").append(state);
+    buf.append(",function=").append(function);
+    buf.append(",parent=").append(parent);
+    buf.append('}');
+    return buf.toString();
+  }
+
+} // end of Job
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/JobModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/JobModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/JobModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/job/JobModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,42 @@
+/*
+* 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.api.job;
+
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.interfaces.LokahiModel;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: JobModel.java,v 1.4 2006/03/07 19:52:06 drtobes Exp $
+ */
+public class JobModel extends LokahiModel<Job> {
+
+  public Collection<Job> getObjects() throws SQLException {
+    return new TMCSet<Job>(Job.getJobs());
+  }
+
+  public Job getObject(int id) throws SQLException {
+    return Job.getJob(id);
+  }
+}
+
+
+
+
+



Mime
View raw message