You are viewing a plain text version of this content. The canonical link for it is here.
Posted to lokahi-commits@incubator.apache.org by to...@apache.org on 2006/07/18 21:14:18 UTC

svn commit: r423254 - in /incubator/lokahi/lokahi/trunk/src: java/org/apache/lokahi/core/agent/callable/tomcat/ java/org/apache/lokahi/core/agent/interfaces/ java/org/apache/lokahi/core/agent/jmx/ java/org/apache/lokahi/core/agent/task/ java/org/apache...

Author: toback
Date: Tue Jul 18 14:14:17 2006
New Revision: 423254

URL: http://svn.apache.org/viewvc?rev=423254&view=rev
Log:
Fix for starting jvms.

Modified:
    incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java
    incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/interfaces/AgentTomcat.java
    incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/jmx/JMXTomcat.java
    incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/RestartTomcatTask.java
    incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/StopTomcatTask.java
    incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/tomcat/HttpTomcat.java
    incubator/lokahi/lokahi/trunk/src/www/Tomcat/Server/update.vm

Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/callable/tomcat/StartTomcatCallable.java Tue Jul 18 14:14:17 2006
@@ -6,9 +6,9 @@
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
-* 
+*
 *   http://www.apache.org/licenses/LICENSE-2.0
-* 
+*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,18 +20,25 @@
 
 import org.apache.lokahi.core.agent.interfaces.AgentTomcat;
 import org.apache.lokahi.core.agent.util.ProcessFactory;
+import org.apache.log4j.Logger;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.Map;
 import java.util.concurrent.Callable;
+import java.util.List;
 
 /**
  * @author Stephen Toback
  * @version $Id$
  */
 public class StartTomcatCallable implements Callable<Boolean> {
+  static final Logger logger = Logger.getLogger(StartTomcatCallable.class);
   private AgentTomcat tc;
-
+  
   public StartTomcatCallable(AgentTomcat tc) {
     this.tc = tc;
   }
@@ -39,11 +46,23 @@
   public Boolean call() throws Exception {
     ProcessBuilder pb = new ProcessBuilder(tc.getStartCommand());
     Map<String, String> env = pb.environment();
-    env.clear();
     env.putAll(tc.getEnv());
     pb.directory(new File("/"));
+    pb.redirectErrorStream(true);
     Process p = pb.start();
+    
+    //File outputFile = new File(tc.getStandardOutLog());
+    //FileWriter out = new FileWriter(outputFile, true);
+    //InputStream is = p.getInputStream();
+    //InputStreamReader isr = new InputStreamReader(is);
+    //BufferedReader br = new BufferedReader(isr);
+    //String line;
+
+    //while ((line = br.readLine()) != null) {
+    //    out.write(line);
+    //}
+    
     ProcessFactory.addProcess(tc, p);
     return true;
   }
-}
\ No newline at end of file
+}

Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/interfaces/AgentTomcat.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/interfaces/AgentTomcat.java?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/interfaces/AgentTomcat.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/interfaces/AgentTomcat.java Tue Jul 18 14:14:17 2006
@@ -6,9 +6,9 @@
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
-* 
+*
 *   http://www.apache.org/licenses/LICENSE-2.0
-* 
+*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -49,7 +49,9 @@
 
   void setStandardOutLog(String logLocation);
 
-  String getStartCommand();
+  String getStandardOutLog();
+
+  String[] getStartCommand();
 }
 
 

Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/jmx/JMXTomcat.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/jmx/JMXTomcat.java?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/jmx/JMXTomcat.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/jmx/JMXTomcat.java Tue Jul 18 14:14:17 2006
@@ -6,9 +6,9 @@
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
-* 
+*
 *   http://www.apache.org/licenses/LICENSE-2.0
-* 
+*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -55,13 +55,13 @@
     if (s!=null) {
   	  try {
     	while (!"".equals(s.trim())) {
-    		env.put(s.substring(0, s.indexOf('=') - 1), s.substring(s.indexOf('='), s.indexOf(';') - 1));
-    		s = s.substring(s.indexOf(';'));
+    		env.put(s.substring(0, s.indexOf('=')), s.substring(s.indexOf('=') + 1, s.indexOf(';')));
+    		s = s.substring(s.indexOf(';') + 1);
     	}
 	  }
 	  catch(Exception e){
 		  if (logger.isInfoEnabled()) {
-		        logger.info("Exception: " + e.getMessage());
+		        logger.info("BAD Exception: " + e.getMessage());
 		  }
 	  }
     }
@@ -368,8 +368,8 @@
     return ret;
   }
 
-  public String getStartCommand() {
-    return javaHome + "/bin/java " + this.getJavaOptions() + ' ' + this.getStartClass() + " start >>" + standardOutLog;
+  public String[] getStartCommand() {
+    return (javaHome + "/bin/java " + this.getJavaOptions() + ' ' + this.getStartClass() + " start").split(" ");
   }
 
   private boolean invokeVoidMethod(ObjectName obj, String method, Object[] params, String[] signature) {
@@ -453,6 +453,25 @@
 
   public void update() throws SQLException {//TODO finish this.
 
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    final JMXTomcat jmxTomcat = (JMXTomcat) o;
+
+    if (httpPort != jmxTomcat.httpPort) return false;
+    if (name != null ? !name.equals(jmxTomcat.name) : jmxTomcat.name != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = httpPort;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    return result;
   }
 }
 

Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/RestartTomcatTask.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/RestartTomcatTask.java?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/RestartTomcatTask.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/RestartTomcatTask.java Tue Jul 18 14:14:17 2006
@@ -6,9 +6,9 @@
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
-* 
+*
 *   http://www.apache.org/licenses/LICENSE-2.0
-* 
+*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -51,7 +51,7 @@
     int flowLevel = 0;
     AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
     if (j.getOptions().length >= 2) {
-      flowLevel = Integer.parseInt(j.getOptions()[1]);
+     // flowLevel = Integer.parseInt(j.getOptions()[1]);
     }
     this.task = new FutureTask<Boolean>(new RestartTomcatCallable(tc, flowLevel));
   }

Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/StopTomcatTask.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/StopTomcatTask.java?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/StopTomcatTask.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/task/StopTomcatTask.java Tue Jul 18 14:14:17 2006
@@ -6,9 +6,9 @@
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
-* 
+*
 *   http://www.apache.org/licenses/LICENSE-2.0
-* 
+*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -51,7 +51,7 @@
     int flowLevel = 0;
     AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
     if (j.getOptions().length >= 2) {
-      flowLevel = Integer.parseInt(j.getOptions()[1]);
+//      flowLevel = Integer.parseInt(j.getOptions()[1]);
     }
     this.task = new FutureTask<Boolean>(new StopTomcatCallable(tc, flowLevel));
   }

Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/tomcat/HttpTomcat.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/tomcat/HttpTomcat.java?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/tomcat/HttpTomcat.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/tomcat/HttpTomcat.java Tue Jul 18 14:14:17 2006
@@ -6,9 +6,9 @@
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
-* 
+*
 *   http://www.apache.org/licenses/LICENSE-2.0
-* 
+*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -163,8 +163,8 @@
     return ret;
   }
 
-  public String getStartCommand() {
-    return javaHome + "/bin/java " + this.javaOptions + ' ' + this.getStartClass() + " start >>" + standardOutLog;
+  public String[] getStartCommand() {
+    return (javaHome + "/bin/java " + this.getJavaOptions() + ' ' + this.getStartClass() + " start").split(" ");
   }
 
   public Map<String, String> getEnv() {
@@ -197,6 +197,25 @@
 
   public void setShouldRestart(boolean shouldRestart) {
     this.shouldRestart = shouldRestart;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    final HttpTomcat that = (HttpTomcat) o;
+
+    if (pk != that.pk) return false;
+    if (name != null ? !name.equals(that.name) : that.name != null) return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = pk;
+    result = 29 * result + (name != null ? name.hashCode() : 0);
+    return result;
   }
 }
 

Modified: incubator/lokahi/lokahi/trunk/src/www/Tomcat/Server/update.vm
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/www/Tomcat/Server/update.vm?rev=423254&r1=423253&r2=423254&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/www/Tomcat/Server/update.vm (original)
+++ incubator/lokahi/lokahi/trunk/src/www/Tomcat/Server/update.vm Tue Jul 18 14:14:17 2006
@@ -64,8 +64,8 @@
 Start Class: <input type="text" id="startClass" name="startClass" value="$!{tomcat.getStartClass()}"><br />
 Standard Out Log: <input type="text" id="stdOutLog" name="stdOutLog" value="$!{tomcat.getStdOutLog()}"><br />
 Java Home: <input type="text" id="javaHome" name="javaHome" value="$!{tomcat.getJavaHome()}"><br />
-Environment Varibles:  <textarea id="env" name="env" cols="40" rows="5"> $!{tomcat.getEnv()} </textarea><br />
-Java Options:  <textarea id="javaOpts" name="javaOpts" cols="40" rows="5"> $!{tomcat.getJavaOptions()} </textarea><br />
+Environment Varibles:  <textarea id="env" name="env" cols="40" rows="5">$!{tomcat.getEnv()}</textarea><br />
+Java Options:  <textarea id="javaOpts" name="javaOpts" cols="40" rows="5">$!{tomcat.getJavaOptions()}</textarea><br />
         <input type="hidden" name="methodToCall" value="UpdateTomcat">
         <input type="submit" value="Update"><br />
       </form>