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/04/10 16:20:11 UTC
svn commit: r392982 [8/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...
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/Watchdog.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/Watchdog.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/Watchdog.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/runnable/Watchdog.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,82 @@
+/*
+* 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.agent.runnable;
+
+import lokahi.core.agent.interfaces.Monitor;
+import lokahi.core.agent.util.ProcessFactory;
+import org.apache.log4j.Logger;
+
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Watchdog.java,v 1.1 2006/03/02 19:19:41 drtobes Exp $
+ */
+public class Watchdog implements Runnable {
+ static final Logger logger = Logger.getLogger(Watchdog.class);
+ private static volatile boolean run = false;
+ private Collection<Monitor> monitors;
+
+ public static boolean shouldRun() {
+ return run;
+ }
+
+ public static void setRun(boolean run) {
+ Watchdog.run = run;
+ }
+
+ public Watchdog() {
+ setRun(true);
+ }
+
+ public void run() {
+ monitors = ProcessFactory.getMonitors();
+ while (shouldRun()) {
+ //checkForNew();
+ check();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ }
+ }
+
+ /**
+ * This method iterates through
+ * all the processes we should be
+ * monitoring and checks each one.
+ * calling a start for it if it should
+ * be restarted.
+ */
+ public void check() {
+ for (Monitor m : monitors) {
+ m.refresh();
+ m.check();
+ if (m.shouldRestartProc()) {
+ ProcessFactory.scheduleStart(m.getProcess());
+ }
+ }
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/servlets/AgentStatusServlet.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/servlets/AgentStatusServlet.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/servlets/AgentStatusServlet.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/servlets/AgentStatusServlet.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.agent.servlets;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AgentStatusServlet.java,v 1.1 2006/03/02 19:19:42 drtobes Exp $
+ */
+public class AgentStatusServlet extends HttpServlet {
+
+ public void init() throws ServletException {
+ super.init();
+ }
+
+ public void destroy() {
+ super.destroy();
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ doGet(request, response);
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/soap/JobTransmission.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/soap/JobTransmission.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/soap/JobTransmission.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/soap/JobTransmission.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,114 @@
+/*
+* 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.agent.soap;
+
+import lokahi.core.api.function.Function;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: JobTransmission.java,v 1.2 2006/03/06 22:31:44 drtobes Exp $
+ */
+public class JobTransmission implements Serializable {
+ private String name;
+ private String parentName;
+ private int statusId;
+ private Function function;
+ private String[] options;
+ private String result;
+ private Date date;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getParentName() {
+ return parentName;
+ }
+
+ public void setParentName(String parentName) {
+ this.parentName = parentName;
+ }
+
+ public int getStatusId() {
+ return statusId;
+ }
+
+ public void setStatusId(int statusId) {
+ this.statusId = statusId;
+ }
+
+ public Function getFunction() {
+ return function;
+ }
+
+ public void setFunction(Function function) {
+ this.function = function;
+ }
+
+ public String[] getOptions() {
+ return options;
+ }
+
+ public void setOptions(String[] options) {
+ this.options = options;
+ }
+
+ public String getResult() {
+ return result;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public JobTransmission(String name, String parentName, Function function, String[] options, Date date) {
+ this.name = name;
+ this.parentName = parentName;
+ this.function = function;
+ this.options = options;
+ this.date = date;
+ }
+
+ public JobTransmission(String name, String parentName, int statusId, Function function, String[] options, String result, Date date) {
+ this.name = name;
+ this.parentName = parentName;
+ this.statusId = statusId;
+ this.function = function;
+ this.options = options;
+ this.result = result;
+ this.date = date;
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/AddContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/AddContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/AddContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/AddContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,62 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.AddContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AddContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class AddContextTask extends AbstractAgentTask<Boolean> {
+
+ public AddContextTask(int jobId, TaskType t, AgentTomcat tc, String contextName, String docBase) {
+ this.task = new FutureTask<Boolean>(new AddContextCallable(tc, contextName, docBase));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public AddContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new AddContextCallable(tc, j.getOptions()[1], j.getOptions()[2]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public AddContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in context add");
+ return "Context add was sucessful";
+ }
+
+}
+
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ConfigtestApacheTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ConfigtestApacheTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ConfigtestApacheTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ConfigtestApacheTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,41 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ConfigtestApacheTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class ConfigtestApacheTask extends HttpsdctlTask {
+
+ public ConfigtestApacheTask(AgentJob j) {
+ this(j.getPk(), j.getType(), j.getOptions()[0]);
+ }
+
+ public ConfigtestApacheTask(int jobId, TaskType t, String apacheRoot) {
+ super(jobId, t, apacheRoot, " configtest ");
+ }
+
+ public ConfigtestApacheTask() {
+ }
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GetSessionsTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GetSessionsTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GetSessionsTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GetSessionsTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,60 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.GetSessionsCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: GetSessionsTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class GetSessionsTask extends AbstractAgentTask<String> {
+
+ public GetSessionsTask(int jobId, TaskType t, AgentTomcat tc, String contextName) {
+ this.task = new FutureTask<String>(new GetSessionsCallable(tc, contextName));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public GetSessionsTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<String>(new GetSessionsCallable(tc, j.getOptions()[1]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public GetSessionsTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ return task.get();
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GracefulApacheTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GracefulApacheTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GracefulApacheTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/GracefulApacheTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,41 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: GracefulApacheTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class GracefulApacheTask extends HttpsdctlTask {
+
+ public GracefulApacheTask(int jobId, TaskType t, String apacheRoot) {
+ super(jobId, t, apacheRoot, " graceful ");
+ }
+
+ public GracefulApacheTask(AgentJob j) {
+ this(j.getPk(), j.getType(), j.getOptions()[0]);
+ }
+
+ public GracefulApacheTask() {
+ }
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/HttpsdctlTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/HttpsdctlTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/HttpsdctlTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/HttpsdctlTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,49 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.util.CommandLineProcess;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HttpsdctlTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class HttpsdctlTask extends AbstractAgentTask<String> {
+
+ HttpsdctlTask(int jobId, TaskType t, String apacheRoot, String command) {
+ this.task = new FutureTask<String>(new CommandLineProcess("sudo ", apacheRoot.trim() + "/bin/httpsdctl ", command));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ HttpsdctlTask() {
+ }
+
+ public String getResult() throws ExecutionException, InterruptedException, TMCTaskException {
+ return task.get();
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ListContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ListContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ListContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ListContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,65 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.ListContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ListContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class ListContextTask extends AbstractAgentTask<String[]> {
+
+ public ListContextTask(int jobId, TaskType t, AgentTomcat tc) {
+ this.task = new FutureTask<String[]>(new ListContextCallable(tc));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public ListContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<String[]>(new ListContextCallable(tc));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public ListContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ String[] ret = task.get();
+ StringBuilder retur = new StringBuilder();
+ for (final String s : ret) {
+ retur.append(s);
+ retur.append('\n');
+ }
+ return retur.toString();
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/MakeDirTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/MakeDirTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/MakeDirTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/MakeDirTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,44 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.MakeDirCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: MakeDirTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class MakeDirTask extends AbstractAgentTask<Boolean> {
+
+ public MakeDirTask(AgentJob j) {
+ this.task = new FutureTask<Boolean>(new MakeDirCallable(j.getOptions()[0]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public String getResult() throws ExecutionException, InterruptedException, TMCTaskException {
+ String ret = "Directory creation failed.";
+ if (task.get())
+ ret = "Directory created. ";
+ return ret;
+ }
+}
\ No newline at end of file
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/PutFileTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/PutFileTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/PutFileTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/PutFileTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,46 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.PutFileCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: PutFileTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class PutFileTask extends AbstractAgentTask<Boolean> {
+
+ public PutFileTask(AgentJob j) {
+ this.task = new FutureTask<Boolean>(new PutFileCallable(j.getAttachment(), j.getOptions()[0]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public PutFileTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in deploying file");
+ return "File was sucessful";
+ }
+
+}
\ No newline at end of file
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RedeployContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RedeployContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RedeployContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RedeployContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,62 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.RedeployContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RedeployContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class RedeployContextTask extends AbstractAgentTask<Boolean> {
+
+ /** @deprecated */
+ public RedeployContextTask(int jobId, TaskType t, AgentTomcat tc, String contextName, String docBase) {
+ this.task = new FutureTask<Boolean>(new RedeployContextCallable(tc, contextName, docBase));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public RedeployContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new RedeployContextCallable(tc, j.getOptions()[1], j.getOptions()[2]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public RedeployContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in context redeploy");
+ return "Context redeploy was sucessful";
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ReloadContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ReloadContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ReloadContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/ReloadContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,61 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.ReloadContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ReloadContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class ReloadContextTask extends AbstractAgentTask<Boolean> {
+
+ public ReloadContextTask(int jobId, TaskType t, AgentTomcat tc, String contextName) {
+ this.task = new FutureTask<Boolean>(new ReloadContextCallable(tc, contextName));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public ReloadContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new ReloadContextCallable(tc, j.getOptions()[1]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public ReloadContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in context reload");
+ return "Context reload was sucessful";
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RemoveContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RemoveContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RemoveContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RemoveContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,60 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.RemoveContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RemoveContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class RemoveContextTask extends AbstractAgentTask<Boolean> {
+
+ public RemoveContextTask(int jobId, TaskType t, AgentTomcat tc, String contextName) {
+ this.task = new FutureTask<Boolean>(new RemoveContextCallable(tc, contextName));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public RemoveContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new RemoveContextCallable(tc, j.getOptions()[1]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public RemoveContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in context removal");
+ return "Context remove was sucessful";
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartApacheTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartApacheTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartApacheTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartApacheTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,41 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RestartApacheTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class RestartApacheTask extends HttpsdctlTask {
+
+ public RestartApacheTask(int jobId, TaskType t, String apacheRoot) {
+ super(jobId, t, apacheRoot, " restart ");
+ }
+
+ public RestartApacheTask(AgentJob j) {
+ this(j.getPk(), j.getType(), j.getOptions()[0]);
+ }
+
+ public RestartApacheTask() {
+ }
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartTomcatTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartTomcatTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartTomcatTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/RestartTomcatTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,71 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.tomcat.RestartTomcatCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RestartTomcatTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class RestartTomcatTask extends AbstractAgentTask<Boolean> {
+
+ RestartTomcatTask(int jobId, TaskType t, AgentTomcat tc, int flowLevel) {
+ this.task = new FutureTask<Boolean>(new RestartTomcatCallable(tc, flowLevel));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ RestartTomcatTask(int jobId, TaskType t, AgentTomcat tc) {
+ this(jobId, t, tc, 0);
+ }
+
+ public RestartTomcatTask(AgentJob j) {
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ int flowLevel = 0;
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ if (j.getOptions().length >= 2) {
+ flowLevel = Integer.parseInt(j.getOptions()[1]);
+ }
+ this.task = new FutureTask<Boolean>(new RestartTomcatCallable(tc, flowLevel));
+ }
+
+ public RestartTomcatTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (task.get()) {
+ return "Tomcat restarted successfully.";
+ }
+ return "Error restarting tomcat.";
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartApacheTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartApacheTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartApacheTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartApacheTask.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.agent.task;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StartApacheTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class StartApacheTask extends HttpsdctlTask {
+
+ public StartApacheTask(int jobId, TaskType t, String apacheRoot) {
+ super(jobId, t, apacheRoot, " start ");
+ }
+
+ public StartApacheTask(AgentJob j) {
+ this(j.getPk(), j.getType(), j.getOptions()[0]);
+ }
+
+ public StartApacheTask() {
+ }
+
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,60 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.StartContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StartContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class StartContextTask extends AbstractAgentTask<Boolean> {
+
+ public StartContextTask(int jobId, TaskType t, AgentTomcat tc, String contextName) {
+ this.task = new FutureTask<Boolean>(new StartContextCallable(tc, contextName));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public StartContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new StartContextCallable(tc, j.getOptions()[1]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public StartContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in context start");
+ return "Context start was sucessful";
+ }
+
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartTomcatTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartTomcatTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartTomcatTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StartTomcatTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,56 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.tomcat.StartTomcatCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StartTomcatTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class StartTomcatTask extends AbstractAgentTask<Boolean> {
+
+ public StartTomcatTask(AgentJob j) {
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new StartTomcatCallable(tc));
+ }
+
+ public StartTomcatTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ String ret = "JVM failed to start.";
+ if (task.get())
+ ret = "JVM started.";
+ return ret;
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopApacheTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopApacheTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopApacheTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopApacheTask.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.agent.task;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StopApacheTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class StopApacheTask extends HttpsdctlTask {
+
+ public StopApacheTask(int jobId, TaskType t, String apacheRoot) {
+ super(jobId, t, apacheRoot, " stop ");
+ }
+
+ public StopApacheTask(AgentJob j) {
+ this(j.getPk(), j.getType(), j.getOptions()[0]);
+ }
+
+ public StopApacheTask() {
+ }
+
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopContextTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopContextTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopContextTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopContextTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,61 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.context.StopContextCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StopContextTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class StopContextTask extends AbstractAgentTask<Boolean> {
+
+ public StopContextTask(int jobId, TaskType t, AgentTomcat tc, String contextName) {
+ this.task = new FutureTask<Boolean>(new StopContextCallable(tc, contextName));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ public StopContextTask(AgentJob j) {
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ this.task = new FutureTask<Boolean>(new StopContextCallable(tc, j.getOptions()[1]));
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ }
+
+ public StopContextTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ if (!task.get()) throw new TMCTaskException("Error in context stop");
+ return "Context stop was sucessful";
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopTomcatTask.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopTomcatTask.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopTomcatTask.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/task/StopTomcatTask.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,74 @@
+/*
+* 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.agent.task;
+
+import lokahi.core.agent.AbstractAgentTask;
+import lokahi.core.agent.callable.tomcat.StopTomcatCallable;
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.dao.TaskType;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.ProcessFactory;
+import lokahi.core.agent.util.TMCTaskException;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: StopTomcatTask.java,v 1.1 2006/03/02 19:19:43 drtobes Exp $
+ */
+public class StopTomcatTask extends AbstractAgentTask<Boolean> {
+
+ StopTomcatTask(int jobId, TaskType t, AgentTomcat tc, int flowLevel) {
+ this.task = new FutureTask<Boolean>(new StopTomcatCallable(tc, flowLevel));
+ this.setJobId(jobId);
+ this.setType(t);
+ }
+
+ StopTomcatTask(int jobId, TaskType t, AgentTomcat tc) {
+ this(jobId, t, tc, 0);
+ }
+
+ public StopTomcatTask(AgentJob j) {
+ this.setJobId(j.getPk());
+ this.setType(j.getType());
+ int flowLevel = 0;
+ AgentTomcat tc = ProcessFactory.getTomcatByHttpPort(j.getOptions()[0]);
+ if (j.getOptions().length >= 2) {
+ flowLevel = Integer.parseInt(j.getOptions()[1]);
+ }
+ this.task = new FutureTask<Boolean>(new StopTomcatCallable(tc, flowLevel));
+ }
+
+ public StopTomcatTask() {
+ }
+
+ public String getResult() throws TMCTaskException, ExecutionException, InterruptedException {
+ String ret;
+ if (task.get()) {
+ ret = "JVM stopped successfully.";
+ } else {
+ ret = "JVM was unsuccessfully stopped.";
+ }
+ return ret;
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/tomcat/HttpTomcat.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/tomcat/HttpTomcat.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/tomcat/HttpTomcat.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/tomcat/HttpTomcat.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,203 @@
+/*
+* 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.agent.tomcat;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.util.TMCAgentBrowser;
+import lokahi.core.api.state.State;
+import org.apache.log4j.Logger;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: HttpTomcat.java,v 1.2 2006/03/06 22:31:44 drtobes Exp $
+ */
+public class HttpTomcat implements AgentTomcat {
+ static final Logger logger = Logger.getLogger(HttpTomcat.class);
+ private int pk;
+ private int pid;
+ private String name;
+ private String javaOptions;
+ private int httpPort;
+ private String javaHome;
+ private boolean shouldRestart;
+ private String standardOutLog;
+ private State state;
+ private String startClass;
+ private HashMap<String, String> env = new HashMap<String, String>();
+
+ public void setEnvironment(String s) {
+ while (!"".equals(s.trim())) {
+ env.put(s.substring(0, s.indexOf('=') - 1), s.substring(s.indexOf('='), s.indexOf(';') - 1));
+ s = s.substring(s.indexOf(';'));
+ }
+ }
+
+ public int getPk() {
+ return pk;
+ }
+
+ public void setPk(int pk) {
+ this.pk = pk;
+ }
+
+ public String getStartClass() {
+ return startClass;
+ }
+
+ public void setStartClass(String startClass) {
+ this.startClass = startClass;
+ }
+
+ public String getStandardOutLog() {
+ return standardOutLog;
+ }
+
+ public void setStandardOutLog(String standardOutLog) {
+ this.standardOutLog = standardOutLog;
+ }
+
+ public String getJavaHome() {
+ return javaHome;
+ }
+
+ public void setJavaHome(String javaHome) {
+ this.javaHome = javaHome;
+ }
+
+ public int getHttpPort() {
+ return httpPort;
+ }
+
+ public void setHttpPort(int httpPort) {
+ this.httpPort = httpPort;
+ }
+
+ public int getPid() {
+ return pid;
+ }
+
+ public void setPid(int pid) {
+ this.pid = pid;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getJavaOptions() {
+ return javaOptions;
+ }
+
+ public void setJavaOptions(String javaOptions) {
+ this.javaOptions = javaOptions;
+ }
+
+ public boolean startContext(String context) {
+ return httpRequest("start&path=" + checkContextName(context)).startsWith("OK");
+ }
+
+ public boolean stopContext(String context) {
+ return httpRequest("stop&path=" + checkContextName(context)).startsWith("OK");
+ }
+
+ public boolean reloadContext(String context) {
+ return httpRequest("reload&path=" + checkContextName(context)).startsWith("OK");
+ }
+
+ public boolean addContext(String path, String docBase) {
+ docBase = "file:" + docBase;
+ if (docBase.endsWith(".war")) {
+ docBase = "jar:" + docBase + "!/";
+ }
+ return httpRequest("install&path=" + checkContextName(path) + "&war=" + docBase).startsWith("OK");
+ }
+
+ public String[] listContexts() {
+ return httpRequest("list").split("\n");
+ }
+
+ public boolean removeContext(String context) {
+ return httpRequest("remove&path=" + checkContextName(context)).startsWith("OK");
+ }
+
+ public String getSessions(String context) {
+ return httpRequest("sessions&path=" + checkContextName(context));
+ }
+
+ private String httpRequest(String url) {
+ String ret = "Error, malformed URL";
+ try {
+ ret = TMCAgentBrowser.get(new URL("http://127.0.0.1:" + httpPort + "/TMAgent/TMAgentManagerServlet?command=" + url));
+ } catch (MalformedURLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ return ret;
+ }
+
+ public String getStartCommand() {
+ return javaHome + "/bin/java " + this.javaOptions + ' ' + this.getStartClass() + " start >>" + standardOutLog;
+ }
+
+ public Map<String, String> getEnv() {
+ return env;
+ }
+
+ public boolean shouldRestart() {
+ return shouldRestart;
+ }
+
+ public AgentJob localRestart() { //TODO finish this.
+ return null;
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State s) {
+ this.state = s;
+ }
+
+ public void update() throws SQLException {//TODO finish this.
+ }
+
+ protected static String checkContextName(String name) {
+ if (!name.trim().startsWith("/")) name = new StringBuilder(name.trim()).insert(0, '/').toString();
+ return name.trim();
+ }
+
+ public void setShouldRestart(boolean shouldRestart) {
+ this.shouldRestart = shouldRestart;
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/CommandLineProcess.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/CommandLineProcess.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/CommandLineProcess.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/CommandLineProcess.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,94 @@
+/*
+* 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.agent.util;
+
+import org.apache.log4j.Logger;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: CommandLineProcess.java,v 1.1 2006/03/02 19:19:44 drtobes Exp $
+ */
+public class CommandLineProcess implements Callable<String> {
+ static final Logger logger = Logger.getLogger(CommandLineProcess.class);
+
+ private ProcessBuilder pb;
+ private Process p;
+ private InputStream is;
+
+ public CommandLineProcess(String... command) {
+ pb = new ProcessBuilder(command);
+ pb.redirectErrorStream(true);
+ }
+
+ public void setDirectory(String directory) {
+ pb.directory(new File(directory));
+
+ }
+
+ public void start() throws IOException {
+ p = getPb().start();
+ is = p.getInputStream();
+ }
+
+ public String getOutput() throws IOException {
+ String s = "";
+ StringBuilder sb = new StringBuilder();
+ BufferedReader bfread = new BufferedReader(new InputStreamReader(is));
+ while ((s = bfread.readLine()) != null) {
+ sb.append(s);
+ sb.append('\n');
+ }
+ return sb.toString();
+ }
+
+ public int getExitCode() {
+ int ret = -10;
+ try {
+ ret = p.waitFor();
+ } catch (InterruptedException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception:" + e.getMessage());
+ }
+ }
+ return ret;
+ }
+
+ public ProcessBuilder getPb() {
+ return pb;
+ }
+
+ public void setPb(ProcessBuilder pb) {
+ this.pb = pb;
+ }
+
+ public String call() throws Exception {
+ this.start();
+ return this.getOutput();
+ }
+}
+
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessFactory.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessFactory.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessFactory.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessFactory.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,125 @@
+/*
+* 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.agent.util;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.interfaces.AgentTomcat;
+import lokahi.core.agent.interfaces.Monitor;
+import lokahi.core.agent.interfaces.MonitoredProcess;
+import lokahi.core.agent.jmx.JMXTomcat;
+import lokahi.core.agent.tomcat.HttpTomcat;
+import lokahi.core.api.state.State;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ProcessFactory.java,v 1.2 2006/03/06 22:31:44 drtobes Exp $
+ */
+public class ProcessFactory {
+ static final Logger logger = Logger.getLogger(ProcessFactory.class);
+ private static final ProcessTable table = new ProcessTable();
+ private static Properties tomcatProps = new Properties();
+
+ private ProcessFactory() {
+ }
+
+ public static void loadProperties(InputStream in) {
+ try {
+ tomcatProps.load(in);
+ } catch (IOException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ }
+
+ public static synchronized <T extends MonitoredProcess> void addProcess(T t, Process p) {
+ table.add(t, p);
+ }
+
+ public static synchronized <T extends MonitoredProcess> Process getProcess(T t) {
+ return table.get(t);
+ }
+
+ public static synchronized <T extends MonitoredProcess> void removeProcess(T t) {
+ table.remove(t);
+ }
+
+ public static Collection<Monitor> getMonitors() {
+ return null;
+ }
+
+ /**
+ * This checks the process to see if it should be
+ * restarted, if so, it schedules a start for it.
+ *
+ * @param p
+ */
+ public static void scheduleStart(MonitoredProcess p) {
+ if (p.shouldRestart()) {
+ try {
+ AgentJob.store(p.localRestart());
+ p.setState(State.FAILED);
+ p.update();
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ } else {
+ try {
+ p.setState(State.FAILED);
+ p.update();
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ }
+ }
+
+ public static AgentTomcat getTomcatByHttpPort(int port) {
+ return getTomcatByHttpPort(Integer.toString(port));
+ }
+
+ public static AgentTomcat getTomcatByHttpPort(String port) {
+ AgentTomcat t;
+ if ("yes".equalsIgnoreCase(tomcatProps.getProperty(port + ".tomcat.param.jmx"))) {
+ t = new JMXTomcat();
+ } else {
+ t = new HttpTomcat();
+ }
+ t.setName(tomcatProps.getProperty(port + ".tomcat.name"));
+ t.setJavaOptions(tomcatProps.getProperty(port + ".java.para.options"));
+ t.setEnvironment(tomcatProps.getProperty(port + ".java.param.env"));
+ t.setJavaHome(tomcatProps.getProperty(port + ".java.home"));
+ t.setStartClass(tomcatProps.getProperty(port + ".tomcat.startclass"));
+ t.setStandardOutLog(tomcatProps.getProperty(port + ".java.param.standard.out.log"));
+
+ return t;
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessTable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessTable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessTable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/ProcessTable.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.agent.util;
+
+import lokahi.core.agent.interfaces.MonitoredProcess;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ProcessTable.java,v 1.1 2006/03/02 19:19:44 drtobes Exp $
+ */
+public class ProcessTable {
+ private Map<MonitoredProcess, Process> table = Collections.synchronizedMap(new HashMap<MonitoredProcess, Process>());
+
+ public <T extends MonitoredProcess> void add(T t, Process p) {
+ table.put(t, p);
+ }
+
+ public <T extends MonitoredProcess> Process get(T t) {
+ return table.get(t);
+ }
+
+ public <T extends MonitoredProcess> void remove(T t) {
+ table.remove(t);
+ }
+}
\ No newline at end of file
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCAgentBrowser.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCAgentBrowser.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCAgentBrowser.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCAgentBrowser.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,85 @@
+/*
+* 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.agent.util;
+
+import org.apache.log4j.Logger;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.concurrent.Callable;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCAgentBrowser.java,v 1.1 2006/03/02 19:19:44 drtobes Exp $
+ */
+public class TMCAgentBrowser implements Callable<String> {
+ static final Logger logger = Logger.getLogger(TMCAgentBrowser.class);
+ private URL url;
+
+ public TMCAgentBrowser(URL url) {
+ this.url = url;
+ }
+
+ public static String get(String url) {
+ String ret = "Error, malformed URL";
+ try {
+ ret = get(new URL(url));
+ } catch (MalformedURLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ return ret;
+ }
+
+ public static String get(URL url) {
+ StringBuilder ret = new StringBuilder();
+ try {
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+ conn.connect();
+ BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ int i = 0;
+ while (i != -1) {
+ i = in.read();
+ if (i != -1) {
+ char c = (char) i;
+ ret.append(c);
+ }
+ }
+ } catch (IOException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ ret.append("Error connecting to the URL");
+ }
+ return ret.toString();
+ }
+
+ public String call() throws Exception {
+ return get(url);
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCTaskException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCTaskException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCTaskException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TMCTaskException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,54 @@
+/*
+* 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.agent.util;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCTaskException.java,v 1.1 2006/03/02 19:19:44 drtobes Exp $
+ */
+public class TMCTaskException extends Exception {
+
+ /**
+ *
+ */
+ public TMCTaskException() {
+ super();
+ }
+
+ /** @param message */
+ public TMCTaskException(String message) {
+ super(message);
+ }
+
+ /** @param cause */
+ public TMCTaskException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public TMCTaskException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TaskFactory.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TaskFactory.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TaskFactory.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/agent/util/TaskFactory.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.agent.util;
+
+import lokahi.core.agent.dao.AgentJob;
+import lokahi.core.agent.interfaces.AgentTask;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TaskFactory.java,v 1.1 2006/03/02 19:19:44 drtobes Exp $
+ */
+public class TaskFactory {
+ static final Logger logger = Logger.getLogger(TaskFactory.class);
+ private Properties translator = new Properties();
+
+ private TaskFactory() {
+ }
+
+ public void load(InputStream in) {
+ try {
+ translator.load(in);
+ } catch (IOException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ }
+
+ public static AgentTask getTask(AgentJob j) {
+
+ return null;
+ }
+
+}
\ No newline at end of file
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertDAO.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertDAO.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertDAO.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertDAO.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,346 @@
+/*
+* 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.alert;
+
+import lokahi.core.api.user.User;
+import lokahi.core.common.database.BrokerFactory;
+import lokahi.core.common.interfaces.Collectable;
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.interfaces.Datable;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.util.PropertiesFile;
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AlertDAO.java,v 1.4 2006/03/07 20:18:56 drtobes Exp $
+ */
+public class AlertDAO implements Datable, Dao, Collectable {
+ static final Logger logger = Logger.getLogger(AlertDAO.class);
+ private static final TMCBroker<AlertDAO> broker = new BrokerFactory<AlertDAO>().getBroker();
+ private int id;
+ private String title;
+ private String content;
+ private boolean format = true;
+ private int authorId;
+ private Date submissionDate;
+ private URL link;
+
+ private User author;
+// private Collection AffectedProjects;
+
+ public int getPk() {
+ return id;
+ }
+
+ public void setPk(int pk) {
+ this.id = pk;
+ }
+
+ public String getName() {
+ return this.title;
+ }
+
+ public void setName(String name) {
+ this.title = name;
+ }
+
+ public void setLink(String link) throws MalformedURLException {
+ if (link == null || "".equals(link)) {
+ this.link = null;
+ } else {
+ this.link = new URL(link);
+ }
+ }
+
+ public void setLink(URL link) {
+ this.link = link;
+ }
+
+ public String getLink() {
+ String ret = PropertiesFile.getConstantValue("application.full.url");
+ if (this.link != null) {
+ ret = this.link.toString();
+ }
+ return ret;
+ }
+
+ public String getContent() {
+ if (content == null) {
+ content = "";
+ }
+ return content;
+ }
+
+ public void setEntry(Blob content) throws SQLException {
+ if (content != null) {
+ this.content = new String(content.getBytes(1, (int) content.length()));
+ } else {
+ this.content = "";
+ }
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public int getAuthorId() {
+ return authorId;
+ }
+
+ public void setAuthorId(int authorId) {
+ this.authorId = authorId;
+ }
+
+ public boolean getFormat() {
+ return format;
+ }
+
+ public void setFormat(boolean flag) {
+ this.format = flag;
+ }
+
+ public User getAuthor() {
+ if (author == null) {
+ try {
+ this.author = User.getUser(this.getAuthorId());
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ }
+ return author;
+ }
+
+ public void setAuthor(User author) {
+ this.author = author;
+ if (author != null) {
+ this.setAuthorId(author.getPk());
+ }
+ }
+
+ public Date getSubmissionDate() {
+ return submissionDate;
+ }
+
+ public String getSubmissionDateAsText() {
+ SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
+ return sdf.format(submissionDate);
+ }
+
+ public void setSubmissionDate(Date submissionDate) {
+ this.submissionDate = submissionDate;
+ }
+
+ public AlertDAO() {
+ }
+
+ public AlertDAO(int id, String title, int authorId, Date submissionDate, String Link, Blob content) throws SQLException {
+ this.setPk(id);
+ this.setName(title);
+ this.setAuthorId(authorId);
+ this.setSubmissionDate(submissionDate);
+ this.setFormat(true);
+ this.setEntry(content);
+ try {
+ this.setLink(Link);
+ } catch (MalformedURLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ }
+
+ public AlertDAO(String title, User author, String Content) {
+ this.setPk(0);
+ this.setName(title);
+ this.setAuthor(author);
+ this.setContent(Content);
+ this.setSubmissionDate(new Date());
+ this.setFormat(false);
+ }
+
+ public AlertDAO(String title, String content, User author) {
+ this.setName(title);
+ this.setContent(content);
+ this.setAuthor(author);
+ this.setSubmissionDate(new Date());
+ this.setFormat(true);
+ }
+
+ public AlertDAO fillObject(ResultSet r) throws SQLException {
+ return new AlertDAO(r.getInt("ALERT_ID"),
+ r.getString("ALERT_TITLE"),
+ r.getInt("SUBMITTER_ID"),
+ r.getTimestamp("SUBMISION_DATE"),
+ r.getString("ALERT_LINK"),
+ r.getBlob("ALERT_CONTENTS"));
+ }
+
+ public String buildHTML() {
+ if (!this.getFormat()) {
+ this.setContent(this.convertToHtml());
+ }
+ StringBuffer ret = new StringBuffer();
+ ret.append("<div class=\"alerttitle\">");
+ ret.append(this.getName());
+ ret.append("</div>");
+ ret.append("<div class=\"alertdate\">");
+ ret.append(this.getSubmissionDate().toString());
+ ret.append("</div>");
+ User u = this.getAuthor();
+ if (u != null) {
+ ret.append("<div class=\"alertauthor\">");
+ ret.append(" Submitted by ");
+ ret.append(u.getFullName());
+ ret.append("</div>");
+ }
+ ret.append("<div class=\"alertcontent\">");
+ ret.append(this.getContent());
+ ret.append("</div>");
+ return ret.toString();
+ }
+
+ private String convertToHtml() {
+ String ret;
+ ret = this.getContent().replaceAll(">", ">");
+ ret = ret.replaceAll("<", "<");
+ ret = ret.replaceAll("\n", "<BR>");
+ this.setFormat(true);
+ return ret;
+ }
+
+ public static boolean delete(AlertDAO al) throws SQLException {
+ return broker.delete("util.alert.delete", al.getPk());
+ }
+
+ public boolean deleteRelationToProjs() throws SQLException {
+ return broker.delete("util.alert.delete.rel.project", this.getPk());
+ }
+
+ public static AlertDAO store(AlertDAO al) throws SQLException {
+ if (!al.getFormat()) {
+ al.setContent(al.convertToHtml());
+ }
+ al.setPk(broker.save("util.alert.store", al.getName(), al.getAuthorId(), al.getLink(), al.getContent().getBytes()));
+ return al;
+ }
+
+ public static void update(AlertDAO al) throws SQLException {
+ broker.update("util.alert.update", al.getPk(), al.getName(), al.getLink(), al.getAuthorId(), al.getContent().getBytes());
+ }
+
+ public void storeRelatedProjects() throws SQLException {
+ broker.modifyRelationship("oracle.util.alert.rel.project.store", this.getPk(), -1);
+ }
+
+ public static Collection<AlertDAO> getCurrentAlertsForAll() throws SQLException {
+ Collection<AlertDAO> c;
+ try {
+ c = broker.getObjects(AlertDAO.class, false, "util.alert.all");
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ throw e;
+ }
+ return c;
+ }
+
+ public static AlertDAO getAlertById(int id) {
+ AlertDAO a = null;
+ try {
+ a = broker.getObject(AlertDAO.class, "util.alert.by.id", false, id);
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
+ return a;
+ }
+
+ public Date getSortOnDate() {
+ if (this.getSubmissionDate() == null) {
+ this.setSubmissionDate(new Date());
+ }
+ return this.getSubmissionDate();
+ }
+
+ public Element buildXMLRepresention() {
+ Element e = new Element("item");
+ e.addContent(new Element("title").setText(this.getName()));
+ e.addContent(new Element("link").setText(this.getLink()));
+ e.addContent(new Element("description").setText(this.getContent()));
+ e.addContent(new Element("author").setText(this.getAuthor().getEmail()));
+ e.addContent(new Element("pubDate").setText(this.getSubmissionDateAsText()));
+ return e;
+ }
+
+ public Element buildShortXMLRepresentation() {
+ return this.buildXMLRepresention();
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof AlertDAO)) return false;
+
+ final AlertDAO alertDAO = (AlertDAO) o;
+
+ if (authorId != alertDAO.authorId) return false;
+ if (id != alertDAO.id) return false;
+ if (submissionDate != null ? !submissionDate.equals(alertDAO.submissionDate) : alertDAO.submissionDate != null)
+ return false;
+ if (title != null ? !title.equals(alertDAO.title) : alertDAO.title != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = id;
+ result = 29 * result + (title != null ? title.hashCode() : 0);
+ result = 29 * result + authorId;
+ result = 29 * result + (submissionDate != null ? submissionDate.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "AlertDAO{" +
+ "id=" + id +
+ ", title='" + title + '\'' +
+ ", content='" + content + '\'' +
+ ", format=" + format +
+ ", authorId=" + authorId +
+ ", submissionDate=" + submissionDate +
+ '}';
+ }
+}
+
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,93 @@
+/*
+* 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.alert;
+
+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.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.common.interfaces.LokahiModel;
+import lokahi.core.common.interfaces.TMCDao;
+import org.apache.log4j.Logger;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AlertModel.java,v 1.5 2006/03/07 20:18:56 drtobes Exp $
+ */
+public class AlertModel extends LokahiModel {
+ static final Logger logger = Logger.getLogger(AlertModel.class);
+
+ public void addAlert(User u, AlertDAO fi, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+ this.jpInit(f, u, fi.getName());
+ if (u.isAllowed(f) && "AddAlert".equals(f.getCommand())) {
+ AlertDAO.store(fi);
+ } else {
+ throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+ }
+ jp.setState(State.COMPLETE);
+ JobPool.update(jp);
+ }
+
+ public void deleteAlert(User u, AlertDAO fi, Function f) throws SQLException, AuthorizationException, TMCIllegalArgumentException {
+ if (fi == null || fi.getPk() < 1) throw new TMCIllegalArgumentException("Alert can not be null");
+ this.jpInit(f, u, fi.getName());
+ if (u.isAllowed(f) && "DeleteAlert".equals(f.getCommand())) {
+ AlertDAO.delete(fi);
+ } else {
+ throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+ }
+ jp.setState(State.COMPLETE);
+ JobPool.update(jp);
+ }
+
+ public void updateAlert(User u, AlertDAO fi, Function f) throws AuthorizationException, TMCIllegalArgumentException, SQLException, IOException {
+ this.jpInit(f, u, fi.getName());
+ if (logger.isDebugEnabled()) {
+ logger.debug("u=" + u);
+ logger.debug("fi=" + fi);
+ logger.debug("f=" + f);
+ }
+ if (u.isAllowed(f) && "UpdateAlert".equals(f.getCommand())) {
+ if (fi.getPk() > 1 && fi.getName() != null && !"".equals(fi.getName())) {
+ AlertDAO.update(fi);
+ } else {
+ throw new TMCIllegalArgumentException("Alert can not be null");
+ }
+ } else {
+ throw new AuthorizationException("User " + u.getName() + " Not allowed to " + f.getName());
+ }
+ jp.setState(State.COMPLETE);
+ JobPool.update(jp);
+ }
+
+ public Collection<TMCDao> getObjects() throws SQLException {
+ return null;
+ }
+
+ public TMCDao getObject(int id) throws SQLException {
+ return null;
+ }
+}
+
+
+
+
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertTool.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertTool.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertTool.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/api/alert/AlertTool.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,66 @@
+/*
+* 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.alert;
+
+import lokahi.core.api.user.User;
+import lokahi.core.common.collection.TMCCollectionImpl;
+import lokahi.core.common.util.DateComparator;
+import org.apache.log4j.Logger;
+
+import java.sql.SQLException;
+import java.util.SortedSet;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AlertTool.java,v 1.2 2006/03/06 22:31:53 drtobes Exp $
+ */
+public class AlertTool {
+ static final Logger logger = Logger.getLogger(AlertTool.class);
+
+ public AlertTool() {
+ }
+
+ public SortedSet<AlertDAO> getRecentAlerts() {
+ TMCCollectionImpl<AlertDAO> col;
+ try {
+ col = new TMCCollectionImpl<AlertDAO>(AlertDAO.getCurrentAlertsForAll());
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ User u = new User("toback");
+ u.setFirstName("Steve");
+ u.setLastName("Toback");
+ AlertDAO a = new AlertDAO("Database Unavailable", u, "\nThe database is currently unavailable. This service is currently unavailable.\n\n");
+ col = new TMCCollectionImpl<AlertDAO>();
+ col.add(a);
+ }
+ SortedSet<AlertDAO> set = col.getSortedSetByDate(new DateComparator<AlertDAO>(), 5);
+ if (logger.isDebugEnabled()) {
+ logger.debug("set=" + set);
+ }
+ return set;
+ }
+
+ public AlertDAO getAlertById(int id) {
+ return AlertDAO.getAlertById(id);
+ }
+}
+
+
+
+
+