Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2012-09-14 21:12:10 +0000
committerRoberto E. Escobar2012-09-14 21:12:10 +0000
commit76b481d2866c8342014c3174258074ff314115d4 (patch)
treefb325bedd463d96f78b29a221d3460f9a0ef92d2
parent0ce3b4e7e1f6af9792edcaf5c75ad79774345fa0 (diff)
downloadorg.eclipse.osee-76b481d2866c8342014c3174258074ff314115d4.tar.gz
org.eclipse.osee-76b481d2866c8342014c3174258074ff314115d4.tar.xz
org.eclipse.osee-76b481d2866c8342014c3174258074ff314115d4.zip
feature[ats_V8CC2]: Add ServerTaskStatusCommand
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/OSGI-INF/server.task.stats.console.command.xml8
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTask.java12
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTaskScheduler.java8
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerTaskInfo.java44
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java97
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/console/ServerTaskStatsCommand.java114
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java63
7 files changed, 331 insertions, 15 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.server/OSGI-INF/server.task.stats.console.command.xml b/plugins/org.eclipse.osee.framework.core.server/OSGI-INF/server.task.stats.console.command.xml
new file mode 100644
index 00000000000..99cd89f6d2f
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/OSGI-INF/server.task.stats.console.command.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.framework.core.server.internal.console.ServerTaskStatsCommand">
+ <implementation class="org.eclipse.osee.framework.core.server.internal.console.ServerTaskStatsCommand"/>
+ <service>
+ <provide interface="org.eclipse.osee.console.admin.ConsoleCommand"/>
+ </service>
+ <reference bind="setTaskScheduler" cardinality="1..1" interface="org.eclipse.osee.framework.core.server.IServerTaskScheduler" name="IServerTaskScheduler" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTask.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTask.java
index a1d030730cb..652e178e06a 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTask.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTask.java
@@ -11,20 +11,22 @@
package org.eclipse.osee.framework.core.server;
import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.IStatus;
/**
* @author Roberto E. Escobar
*/
public interface IServerTask extends Runnable {
- public String getName();
+ String getName();
- public SchedulingScheme getSchedulingScheme();
+ SchedulingScheme getSchedulingScheme();
- public long getInitialDelay();
+ long getInitialDelay();
- public long getPeriod();
+ long getPeriod();
- public TimeUnit getTimeUnit();
+ TimeUnit getTimeUnit();
+ IStatus getLastStatus();
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTaskScheduler.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTaskScheduler.java
index 7c9f5c42920..fa3867a8ca4 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTaskScheduler.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IServerTaskScheduler.java
@@ -10,13 +10,17 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server;
+import java.util.List;
+
/**
* @author Roberto E. Escobar
*/
public interface IServerTaskScheduler {
- public void addServerTask(IServerTask taskProvider);
+ void addServerTask(IServerTask taskProvider);
+
+ void removeServerTask(IServerTask taskProvider);
- public void removeServerTask(IServerTask taskProvider);
+ List<ServerTaskInfo> getServerTaskInfo();
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerTaskInfo.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerTaskInfo.java
new file mode 100644
index 00000000000..f0e6dad0e44
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerTaskInfo.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server;
+
+import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ServerTaskInfo {
+
+ public static enum TaskState {
+ SCHEDULED,
+ RUNNING,
+ CANCELLED,
+ WAITING,
+ DONE;
+ }
+
+ String getName();
+
+ SchedulingScheme getSchedulingScheme();
+
+ long getInitialDelay();
+
+ long getPeriod();
+
+ TimeUnit getTimeUnit();
+
+ IStatus getLastStatus();
+
+ long getTimeUntilNextRun();
+
+ TaskState getTaskState();
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java
index 47b74de85d6..b7c59fdb5cb 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java
@@ -10,16 +10,23 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server.internal;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.osee.framework.core.server.IApplicationServerManager;
import org.eclipse.osee.framework.core.server.IServerTask;
import org.eclipse.osee.framework.core.server.IServerTaskScheduler;
+import org.eclipse.osee.framework.core.server.SchedulingScheme;
+import org.eclipse.osee.framework.core.server.ServerTaskInfo;
+import org.eclipse.osee.framework.core.server.ServerTaskInfo.TaskState;
import org.eclipse.osee.logger.Log;
/**
@@ -29,7 +36,8 @@ public class ServerTaskScheduler implements IServerTaskScheduler {
private Log logger;
- private final Map<Runnable, ScheduledFuture<?>> futures = new ConcurrentHashMap<Runnable, ScheduledFuture<?>>();
+ private final Map<IServerTask, ScheduledFuture<?>> futures =
+ new ConcurrentHashMap<IServerTask, ScheduledFuture<?>>();
private ScheduledExecutorService executor;
private IApplicationServerManager serverManager;
@@ -88,18 +96,99 @@ public class ServerTaskScheduler implements IServerTaskScheduler {
}
}
- private void scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
+ private void scheduleAtFixedRate(IServerTask command, long initialDelay, long period, TimeUnit unit) {
ScheduledFuture<?> futureTask = executor.scheduleAtFixedRate(command, initialDelay, period, unit);
futures.put(command, futureTask);
}
- private void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
+ private void scheduleWithFixedDelay(IServerTask command, long initialDelay, long delay, TimeUnit unit) {
ScheduledFuture<?> futureTask = executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
futures.put(command, futureTask);
}
- private void scheduleOneShot(Runnable command, long initialDelay, TimeUnit unit) {
+ private void scheduleOneShot(IServerTask command, long initialDelay, TimeUnit unit) {
ScheduledFuture<?> futureTask = executor.schedule(command, initialDelay, unit);
futures.put(command, futureTask);
}
+
+ @Override
+ public List<ServerTaskInfo> getServerTaskInfo() {
+ List<ServerTaskInfo> infos = new ArrayList<ServerTaskInfo>();
+
+ for (Entry<IServerTask, ScheduledFuture<?>> entry : futures.entrySet()) {
+ IServerTask task = entry.getKey();
+
+ ScheduledFuture<?> future = entry.getValue();
+ long waitTimeForNextRun = future.getDelay(TimeUnit.MILLISECONDS);
+
+ TaskState state = TaskState.SCHEDULED;
+ if (waitTimeForNextRun == 0 && (!future.isDone() || !future.isCancelled())) {
+ state = TaskState.RUNNING;
+ } else if (future.isCancelled()) {
+ state = TaskState.CANCELLED;
+ } else if (waitTimeForNextRun > 0) {
+ state = TaskState.WAITING;
+ } else if (future.isDone()) {
+ state = TaskState.DONE;
+ }
+
+ ServerTaskInfo info = new ServerTaskInfoImpl(task, state, waitTimeForNextRun);
+ infos.add(info);
+ }
+ return infos;
+ }
+ private final static class ServerTaskInfoImpl implements ServerTaskInfo {
+
+ private final IServerTask task;
+ private final TaskState state;
+ private final long timeTilNextRun;
+
+ public ServerTaskInfoImpl(IServerTask task, TaskState state, long timeTilNextRun) {
+ super();
+ this.task = task;
+ this.state = state;
+ this.timeTilNextRun = timeTilNextRun;
+ }
+
+ @Override
+ public String getName() {
+ return task.getName();
+ }
+
+ @Override
+ public SchedulingScheme getSchedulingScheme() {
+ return task.getSchedulingScheme();
+ }
+
+ @Override
+ public long getInitialDelay() {
+ return task.getInitialDelay();
+ }
+
+ @Override
+ public long getPeriod() {
+ return task.getPeriod();
+ }
+
+ @Override
+ public long getTimeUntilNextRun() {
+ return timeTilNextRun;
+ }
+
+ @Override
+ public TimeUnit getTimeUnit() {
+ return task.getTimeUnit();
+ }
+
+ @Override
+ public IStatus getLastStatus() {
+ return task.getLastStatus();
+ }
+
+ @Override
+ public TaskState getTaskState() {
+ return state;
+ }
+
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/console/ServerTaskStatsCommand.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/console/ServerTaskStatsCommand.java
new file mode 100644
index 00000000000..d1e8655f58d
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/console/ServerTaskStatsCommand.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.console;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.osee.console.admin.Console;
+import org.eclipse.osee.console.admin.ConsoleCommand;
+import org.eclipse.osee.console.admin.ConsoleParameters;
+import org.eclipse.osee.framework.core.server.IServerTaskScheduler;
+import org.eclipse.osee.framework.core.server.ServerTaskInfo;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class ServerTaskStatsCommand implements ConsoleCommand {
+
+ private IServerTaskScheduler scheduler;
+
+ public void setTaskScheduler(IServerTaskScheduler scheduler) {
+ this.scheduler = scheduler;
+ }
+
+ @Override
+ public String getName() {
+ return "server_task_status";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Displays server scheduled task information";
+ }
+
+ @Override
+ public String getUsage() {
+ return "";
+ }
+
+ @Override
+ public Callable<?> createCallable(Console console, ConsoleParameters params) {
+ return new SchedulingCallable(console, scheduler);
+ }
+
+ private final class SchedulingCallable implements Callable<Boolean> {
+ private final Console ci;
+ private final IServerTaskScheduler scheduler;
+
+ public SchedulingCallable(Console ci, IServerTaskScheduler scheduler) {
+ this.ci = ci;
+ this.scheduler = scheduler;
+ }
+
+ @Override
+ public Boolean call() throws Exception {
+ List<ServerTaskInfo> infos = scheduler.getServerTaskInfo();
+ int count = 0;
+ for (ServerTaskInfo task : infos) {
+ IStatus status = task.getLastStatus();
+
+ ci.writeln();
+ ci.writeln("Task:[%s][%s] Status:[%s] NextRunIn:[%s]", ++count, task.getName(), task.getTaskState(),
+ Lib.asTimeString(task.getTimeUntilNextRun()));
+ ci.writeln("Scheme:[%s]", task.getSchedulingScheme());
+ ci.writeln("Period:[%s %s]", task.getPeriod(), task.getTimeUnit().toString().toLowerCase());
+ ci.write("\tLast Run Status:[");
+ int severity = status.getSeverity();
+ switch (severity) {
+ case IStatus.OK:
+ ci.write("OK");
+ break;
+ case IStatus.ERROR:
+ ci.write("ERROR");
+ break;
+ case IStatus.WARNING:
+ ci.write("WARNING");
+ break;
+ case IStatus.INFO:
+ ci.write("INFO");
+ break;
+ case IStatus.CANCEL:
+ ci.write("CANCEL");
+ break;
+ default:
+ ci.write(severity);
+ break;
+ }
+ ci.writeln("] Code:[%s]", status.getCode());
+ String message = status.getMessage();
+ if (Strings.isValid(message)) {
+ ci.write("\tMessage:%s", message.replaceAll("\n", "\n\t"));
+ }
+ Throwable th = status.getException();
+ if (th != null) {
+ ci.write("\tException: [%s]", Lib.exceptionToString(th).replaceAll("\n", "\n\t"));
+ }
+ ci.writeln();
+
+ }
+ return Boolean.TRUE;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java
index 117b0287b4b..84b42d345ab 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java
@@ -13,7 +13,12 @@ package org.eclipse.osee.framework.core.server.internal.task;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.server.IServerTask;
import org.eclipse.osee.framework.core.server.ISession;
@@ -22,6 +27,9 @@ import org.eclipse.osee.framework.core.server.SchedulingScheme;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.logger.Log;
/**
@@ -49,6 +57,11 @@ public class CleanJoinTablesServerTask implements IServerTask {
private IOseeDatabaseService dbService;
private Log logger;
private ISessionManager sessionManager;
+ private IStatus lastStatus = Status.OK_STATUS;
+ private final Map<String, Integer> deletedByTime = new ConcurrentHashMap<String, Integer>();
+ private final CompositeKeyHashMap<String, String, Integer> sessionDeletes =
+ new CompositeKeyHashMap<String, String, Integer>(10, true);
+ private long lastRan = 0;
public void setDbService(IOseeDatabaseService dbService) {
this.dbService = dbService;
@@ -70,13 +83,21 @@ public class CleanJoinTablesServerTask implements IServerTask {
@Override
public void run() {
try {
- Timestamp time = new Timestamp(System.currentTimeMillis() - THREE_HOURS);
+ lastRan = System.currentTimeMillis();
+ deletedByTime.clear();
+ sessionDeletes.clear();
+
+ Timestamp time = new Timestamp(lastRan - THREE_HOURS);
for (String table : TABLES) {
- ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TIME, table), time);
+ int rows = ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TIME, table), time);
+ deletedByTime.put(table, rows);
}
deleteFromJoinCleanup();
+ lastStatus = Status.OK_STATUS;
} catch (OseeCoreException ex) {
- logger.warn(ex, "Error cleaning up tables");
+ String message = "Error cleaning up tables";
+ logger.warn(ex, message);
+ lastStatus = new Status(IStatus.ERROR, CleanJoinTablesServerTask.class.getName(), message, ex);
}
}
@@ -99,7 +120,9 @@ public class CleanJoinTablesServerTask implements IServerTask {
}
if (!isAlive) {
queryIds.add(new Integer[] {queryId});
- ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TABLE_SESSION, tableName), queryId);
+ int rows =
+ ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TABLE_SESSION, tableName), queryId);
+ sessionDeletes.put(sessionId, tableName, rows);
}
prevSessionId = sessionId;
}
@@ -128,4 +151,36 @@ public class CleanJoinTablesServerTask implements IServerTask {
public TimeUnit getTimeUnit() {
return TimeUnit.MINUTES;
}
+
+ @Override
+ public IStatus getLastStatus() {
+ IStatus toReturn = lastStatus;
+ if (toReturn.isOK()) {
+ String message = buildMessage();
+ toReturn = new Status(IStatus.OK, CleanJoinTablesServerTask.class.getName(), message.toString());
+ }
+ return toReturn;
+ }
+
+ private String buildMessage() {
+ StringBuilder message = new StringBuilder();
+ message.append(String.format("[%s] - Last ran: [", getName()));
+ if (lastRan != 0) {
+ message.append(Lib.getElapseString(lastRan));
+ message.append(" ago]\n");
+ } else {
+ message.append("Never]\n");
+ }
+ for (Entry<String, Integer> entry : deletedByTime.entrySet()) {
+ message.append(String.format("Deleted [%s] from table [%s]\n", entry.getValue(), entry.getKey()));
+ }
+
+ for (Entry<Pair<String, String>, Integer> entry : sessionDeletes.entrySet()) {
+ String sessionId = entry.getKey().getFirst();
+ String tableName = entry.getKey().getSecond();
+ Integer rows = entry.getValue();
+ message.append(String.format("Deleted [%s] from table [%s] for sessionId [%s]\n", rows, tableName, sessionId));
+ }
+ return message.toString();
+ }
}

Back to the top