Author: degenaro
Date: Sat Mar 16 10:56:41 2013
New Revision: 1457235
URL: http://svn.apache.org/r1457235
Log:
UIMA-2734 DUCC webserver (WS) refactor DuccWebMonitor in anticipation of
support for monitoring of Managed Reservations
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/IWebMonitor.java
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerProxy.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebMonitor.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java?rev=1457235&r1=1457234&r2=1457235&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccAbstractHandler.java
Sat Mar 16 10:56:41 2013
@@ -42,6 +42,7 @@ import org.apache.uima.ducc.transport.ev
import org.apache.uima.ducc.transport.event.common.IDuccProcess;
import org.apache.uima.ducc.transport.event.common.IDuccProcessMap;
import org.apache.uima.ducc.transport.event.common.IDuccSchedulingInfo;
+import org.apache.uima.ducc.transport.event.common.IDuccTypes.DuccType;
import org.apache.uima.ducc.transport.event.common.IDuccUnits.MemoryUnits;
import org.apache.uima.ducc.transport.event.common.IDuccWork;
import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
@@ -898,8 +899,8 @@ public abstract class DuccAbstractHandle
protected String getMonitor(DuccId duccId, boolean multi) {
StringBuffer sb = new StringBuffer();
DuccWebMonitor duccWebMonitor = DuccWebMonitor.getInstance();
- Long expiry = duccWebMonitor.getExpiry(duccId);
- if(!duccWebMonitor.isCanceler()) {
+ Long expiry = duccWebMonitor.getExpiry(DuccType.Job, duccId);
+ if(!duccWebMonitor.isAutoCancelEnabled()) {
if(expiry != null) {
String text = "webserver not primary";
sb.append("<span class=\"health_neutral\"
title=\""+text+"\">");
@@ -945,7 +946,7 @@ public abstract class DuccAbstractHandle
}
sb.append("</span>");
}
- else if(duccWebMonitor.isCancelPending(duccId)) {
+ else if(duccWebMonitor.isCanceled(DuccType.Job, duccId)) {
sb.append("<span class=\"health_red\" >");
sb.append("CancelPending...");
sb.append("</span>");
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerProxy.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerProxy.java?rev=1457235&r1=1457234&r2=1457235&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerProxy.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerProxy.java
Sat Mar 16 10:56:41 2013
@@ -29,6 +29,7 @@ import org.apache.uima.ducc.common.json.
import org.apache.uima.ducc.common.utils.DuccLogger;
import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.IDuccTypes.DuccType;
import org.eclipse.jetty.server.Request;
import com.google.gson.Gson;
@@ -92,7 +93,7 @@ public class DuccHandlerProxy extends Du
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
message);
}
else {
- MonitorInfo monitorInfo = duccWebMonitor.renew(jobId);
+ MonitorInfo monitorInfo =
duccWebMonitor.renew(DuccType.Job, jobId);
Gson gson = new Gson();
String jSon = gson.toJson(monitorInfo);
duccLogger.debug(location, jobid, jSon);
@@ -110,7 +111,7 @@ public class DuccHandlerProxy extends Du
duccLogger.trace(location, jobid, "enter");
duccLogger.info(location, jobid, request.toString());
- ConcurrentHashMap<DuccId,Long> eMap =
duccWebMonitor.getExpiryMap();
+ ConcurrentHashMap<DuccId,Long> eMap =
duccWebMonitor.getExpiryMap(DuccType.Job);
Gson gson = new Gson();
String jSon = gson.toJson(eMap);
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebMonitor.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebMonitor.java?rev=1457235&r1=1457234&r2=1457235&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebMonitor.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebMonitor.java
Sat Mar 16 10:56:41 2013
@@ -23,6 +23,7 @@ import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.uima.ducc.cli.DuccUiConstants;
@@ -37,34 +38,31 @@ import org.apache.uima.ducc.transport.ev
import org.apache.uima.ducc.transport.event.common.DuccWorkMap;
import org.apache.uima.ducc.transport.event.common.IDuccSchedulingInfo;
import org.apache.uima.ducc.transport.event.common.IDuccState.JobState;
+import org.apache.uima.ducc.transport.event.common.IDuccTypes.DuccType;
import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
import org.apache.uima.ducc.ws.IListenerOrchestrator;
-public class DuccWebMonitor implements IListenerOrchestrator {
+public class DuccWebMonitor implements IListenerOrchestrator, IWebMonitor {
private static DuccLogger duccLogger =
DuccLoggerComponents.getWsLogger(DuccWebMonitor.class.getName());
private static DuccId jobid = null;
public static DuccWebMonitor instance = new DuccWebMonitor();
- public static DuccWebMonitor getInstance() {
- return instance;
- }
+ public String key_automatic_cancel_minutes =
"ducc.ws.automatic.cancel.minutes";
+ public String key_node = "ducc.ws.node";
+ public String key_head = "ducc.head";
+ public String key_port = "ducc.ws.port";
+
+ private Properties properties = new Properties();
private long millisPerMinute = 60*1000;
private long timeoutMinutes = 10;
private long timeoutMillis = timeoutMinutes*millisPerMinute;
- private boolean disabledMessageAlreadyGiven = false;
-
- private Properties properties;
-
- private ConcurrentHashMap<DuccId,MonitorInfo> jMap = new
ConcurrentHashMap<DuccId,MonitorInfo>();
- private ConcurrentHashMap<DuccId,TrackingInfo> tMap = new
ConcurrentHashMap<DuccId,TrackingInfo>();
-
+ private AtomicBoolean operational = new AtomicBoolean(true);
private AtomicInteger updateCounter = new AtomicInteger(0);
-
- private ConcurrentHashMap<DuccId,Long> cMap = new
ConcurrentHashMap<DuccId,Long>();
+ private AtomicBoolean statusMessageIssued = new AtomicBoolean(false);
private String monitor_host = null;
private String monitor_port = null;
@@ -72,6 +70,14 @@ public class DuccWebMonitor implements I
private String actual_host = null;
private String actual_port = null;
+ private ConcurrentHashMap<DuccId,MonitorInfo> jmMap = new
ConcurrentHashMap<DuccId,MonitorInfo>();
+ private ConcurrentHashMap<DuccId,TrackingInfo> jtMap = new
ConcurrentHashMap<DuccId,TrackingInfo>();
+ private ConcurrentHashMap<DuccId,Long> jcMap = new
ConcurrentHashMap<DuccId,Long>();
+
+ public static DuccWebMonitor getInstance() {
+ return instance;
+ }
+
public DuccWebMonitor() {
super();
initialize();
@@ -80,7 +86,7 @@ public class DuccWebMonitor implements I
private void initialize() {
String location = "initialize";
properties = DuccWebProperties.get();
- String key = "ducc.ws.job.automatic.cancel.minutes";
+ String key = key_automatic_cancel_minutes;
if(properties.containsKey(key)) {
String value = properties.getProperty(key);
try {
@@ -93,6 +99,7 @@ public class DuccWebMonitor implements I
}
}
else {
+ duccLogger.warn(location, jobid, "not found: "+key);
duccLogger.info(location, jobid, "timeout minutes
(default): "+timeoutMinutes);
}
String me = System.getProperty("user.name");
@@ -101,127 +108,33 @@ public class DuccWebMonitor implements I
}
DuccListeners.getInstance().register(this);
//
- monitor_host = properties.getProperty("ducc.ws.node");
+ monitor_host = properties.getProperty(key_node);
if(monitor_host == null) {
- monitor_host = properties.getProperty("ducc.head");
- }
- monitor_port = properties.getProperty("ducc.ws.port");
- }
-
- public void registerHostPort(String host, String port) {
- String location = "registerHostPort";
- actual_host = host;
- actual_port = port;
- if(isCanceler()) {
- duccLogger.info(location, jobid, host+":"+port+" is
cancel monitor "+monitor_host+":"+monitor_port);
- }
- else {
- duccLogger.warn(location, jobid, host+":"+port+" is
*not* cancel monitor "+monitor_host+":"+monitor_port);
- }
- }
-
- public boolean isCanceler() {
- if(actual_host == null) {
- return false;
- }
- if(monitor_host == null) {
- return false;
- }
- if(!actual_host.equals(monitor_host)) {
- String actual_domainless_host =
actual_host.split("\\.")[0];
- String monitor_domainless_host =
monitor_host.split("\\.")[0];
-
if(!actual_domainless_host.equals(monitor_domainless_host)) {
- return false;
- }
- }
- if(actual_port == null) {
- return false;
- }
- if(monitor_port == null) {
- return false;
- }
- if(!actual_port.equals(monitor_port)) {
- return false;
- }
- return true;
- }
-
- private void cancel(DuccId duccId) {
- String location = "cancel";
- duccLogger.trace(location, jobid, "enter");
-
- String userId = System.getProperty("user.name");
-
- duccLogger.info(location, duccId, userId);
-
- String java = "/bin/java";
- String jhome = System.getProperty("java.home");
- String cp = System.getProperty("java.class.path");
- String jclass = "org.apache.uima.ducc.cli.DuccJobCancel";
- String arg1 = "--"+JobRequestProperties.key_id;
- String arg2 = ""+duccId;
- String arg3 = "--"+SpecificationProperties.key_reason;
- String arg4 = "\"submitter terminated, therefore job canceled
automatically\"";
- String arg5 =
"--"+SpecificationProperties.key_role_administrator;
-
- String[] arglistUser = { "-u", userId, "--", jhome+java, "-cp",
cp, jclass, arg1, arg2, arg3, arg4, arg5 };
- String result = DuccAsUser.duckling(userId, arglistUser);
- duccLogger.warn(location, duccId, result);
-
- cMap.put(duccId, new Long(System.currentTimeMillis()));
- tMap.remove(duccId);
-
- duccLogger.trace(location, jobid, "exit");
- }
-
- private void canceler() {
- String location = "canceler";
- duccLogger.trace(location, jobid, "enter");
-
- long nowMillis = System.currentTimeMillis();
-
- Enumeration<DuccId> keys = tMap.keys();
- while(keys.hasMoreElements()) {
- DuccId duccId = keys.nextElement();
- TrackingInfo ti = tMap.get(duccId);
- long expiryMillis = ti.time;
- if(nowMillis > expiryMillis) {
- if(isCancelable(duccId)) {
- cancel(duccId);
- }
- else {
- duccLogger.debug(location, duccId, "not
cancelable");
- }
- }
+ monitor_host = properties.getProperty(key_head);
}
-
- duccLogger.trace(location, jobid, "exit");
- }
-
- public boolean isCanceled(DuccId duccId) {
- return cMap.containsKey(duccId);
+ monitor_port = properties.getProperty(key_port);
}
+ @Override
public void update(OrchestratorStateDuccEvent duccEvent) {
String location = "update";
duccLogger.trace(location, jobid, "enter");
- if(timeoutMillis > 0) {
+ if(operational.get()) {
updateCounter.incrementAndGet();
monitor(duccEvent);
}
else {
- if(!disabledMessageAlreadyGiven) {
- duccLogger.info(location, jobid, "Job monitor
disabled");
- disabledMessageAlreadyGiven = true;
+ if(!statusMessageIssued.getAndSet(true)) {
+ duccLogger.info(location, jobid, "auto-cancel
monitor disabled");
}
}
duccLogger.trace(location, jobid, "exit");
}
- private void monitor(OrchestratorStateDuccEvent duccEvent) {
- String location = "monitor";
+ private void monitorJobs(OrchestratorStateDuccEvent duccEvent) {
+ String location = "monitorJobs";
duccLogger.trace(location, jobid, "enter");
DuccWorkMap dwm = duccEvent.getWorkMap();
@@ -231,7 +144,7 @@ public class DuccWebMonitor implements I
Iterator<DuccId> iterator;
ArrayList<DuccId> gone = new ArrayList<DuccId>();
- iterator = jMap.keySet().iterator();
+ iterator = jmMap.keySet().iterator();
while( iterator.hasNext() ) {
DuccId duccId = iterator.next();
gone.add(duccId);
@@ -244,18 +157,18 @@ public class DuccWebMonitor implements I
DuccId duccId = iterator.next();
IDuccWorkJob dwj =
(IDuccWorkJob)dwm.findDuccWork(duccId);
gone.remove(duccId);
- if(!jMap.containsKey(duccId)) {
+ if(!jmMap.containsKey(duccId)) {
MonitorInfo monitorInfo = new MonitorInfo();
- jMap.put(duccId, monitorInfo);
+ jmMap.put(duccId, monitorInfo);
duccLogger.info(location, duccId, "Job monitor
start");
- if(!tMap.containsKey(duccId)) {
+ if(!jtMap.containsKey(duccId)) {
try {
Properties properties =
DuccFile.getJobProperties(dwj);
if(properties.containsKey(DuccUiConstants.name_monitor_cancel_job_on_interrupt))
{
TrackingInfo ti = new
TrackingInfo();
ti.time = expiryMillis;
ti.user =
dwj.getStandardInfo().getUser();
- tMap.put(duccId,ti);
+ jtMap.put(duccId,ti);
duccLogger.info(location, duccId, "Job auto-cancel on");
}
else {
@@ -267,7 +180,7 @@ public class DuccWebMonitor implements I
}
}
}
- MonitorInfo monitorInfo = jMap.get(duccId);
+ MonitorInfo monitorInfo = jmMap.get(duccId);
IDuccSchedulingInfo si = dwj.getSchedulingInfo();
monitorInfo.total = si.getWorkItemsTotal();
monitorInfo.done = si.getWorkItemsCompleted();
@@ -286,24 +199,180 @@ public class DuccWebMonitor implements I
iterator = gone.iterator();
while( iterator.hasNext() ) {
DuccId duccId = iterator.next();
- jMap.remove(duccId);
- tMap.remove(duccId);
+ jmMap.remove(duccId);
+ jtMap.remove(duccId);
duccLogger.info(location, duccId, "Job monitor stop");
}
- if(isCanceler()) {
- canceler();
+ duccLogger.trace(location, jobid, "exit");
+ }
+
+ private void monitorManagedReservations(OrchestratorStateDuccEvent
duccEvent) {
+ String location = "monitorManagedReservations";
+ duccLogger.trace(location, jobid, "enter");
+
+ // TODO
+
+ duccLogger.trace(location, jobid, "exit");
+ }
+
+ private void cancelJobs(long nowMillis) {
+ String location = "cancelJobs";
+ duccLogger.trace(location, jobid, "enter");
+
+ Enumeration<DuccId> keys = jtMap.keys();
+ while(keys.hasMoreElements()) {
+ DuccId duccId = keys.nextElement();
+ TrackingInfo ti = jtMap.get(duccId);
+ long expiryMillis = ti.time;
+ if(nowMillis > expiryMillis) {
+ if(isCancelableJob(duccId)) {
+ cancelJob(duccId);
+ }
+ else {
+ duccLogger.debug(location, duccId, "not
cancelable");
+ }
+ }
+ }
+
+ duccLogger.trace(location, jobid, "exit");
+ }
+
+ private boolean isCanceledJob(DuccId duccId) {
+ return jcMap.containsKey(duccId);
+ }
+
+ private boolean isCancelableJob(DuccId duccId) {
+ String location = "isCancelableJob";
+ duccLogger.trace(location, duccId, "enter");
+ boolean retVal = false;
+ if(!jcMap.containsKey(duccId)) {
+ MonitorInfo monitorInfo = jmMap.get(duccId);
+ if(monitorInfo != null) {
+ ArrayList<String> stateSequence =
monitorInfo.stateSequence;
+ if(stateSequence != null) {
+
if(stateSequence.contains(JobState.Completing.toString())) {
+ duccLogger.debug(location,
duccId, "state: <uncancelable> "+stateSequence);
+ }
+ else
if(stateSequence.contains(JobState.Completed.toString())) {
+ duccLogger.debug(location,
duccId, "state: <uncancelable> "+stateSequence);
+ }
+ else {
+ duccLogger.debug(location,
duccId, "state: <cancelable> "+stateSequence);
+ retVal = true;
+ }
+ }
+ else {
+ duccLogger.warn(location, duccId,
"stateSequence: <null>");
+ }
+ }
+ else {
+ duccLogger.warn(location, duccId, "monitorInfo:
<null>");
+ }
}
else {
- duccLogger.debug(location, jobid, "Canceler disabled");
+ duccLogger.debug(location, duccId, "already canceled");
}
+ duccLogger.trace(location, duccId, "exit");
+ return retVal;
+ }
+
+ private void cancelJob(DuccId duccId) {
+ String location = "cancelJob";
+ duccLogger.trace(location, jobid, "enter");
+
+ String userId = System.getProperty("user.name");
+ duccLogger.info(location, duccId, userId);
+
+ String java = "/bin/java";
+ String jhome = System.getProperty("java.home");
+ String cp = System.getProperty("java.class.path");
+ String jclass = "org.apache.uima.ducc.cli.DuccJobCancel";
+ String arg1 = "--"+JobRequestProperties.key_id;
+ String arg2 = ""+duccId;
+ String arg3 = "--"+SpecificationProperties.key_reason;
+ String arg4 = "\"submitter terminated, therefore job canceled
automatically\"";
+ String arg5 =
"--"+SpecificationProperties.key_role_administrator;
+
+ String[] arglistUser = { "-u", userId, "--", jhome+java, "-cp",
cp, jclass, arg1, arg2, arg3, arg4, arg5 };
+ String result = DuccAsUser.duckling(userId, arglistUser);
+ duccLogger.warn(location, duccId, result);
+
+ jcMap.put(duccId, new Long(System.currentTimeMillis()));
+ jtMap.remove(duccId);
+
+ duccLogger.trace(location, jobid, "exit");
+ }
+
+ private void cancelManagedReservations(long nowMillis) {
+ String location = "cancelManagedReservations";
+ duccLogger.trace(location, jobid, "enter");
+
+ // TODO
+
+ duccLogger.trace(location, jobid, "exit");
+ }
+
+ private void monitor(OrchestratorStateDuccEvent duccEvent) {
+ String location = "monitor";
+ duccLogger.trace(location, jobid, "enter");
+ monitorJobs(duccEvent);
+ monitorManagedReservations(duccEvent);
+ if(isAutoCancelEnabled()) {
+ long nowMillis = System.currentTimeMillis();
+ cancelJobs(nowMillis);
+ cancelManagedReservations(nowMillis);
+ }
+ else {
+ duccLogger.debug(location, jobid, "auto-cancel monitor
disabled");
+ }
duccLogger.trace(location, jobid, "exit");
}
+ @Override
+ public void register(String host, String port) {
+ String location = "register";
+ actual_host = host;
+ actual_port = port;
+ if(isAutoCancelEnabled()) {
+ duccLogger.info(location, jobid, host+":"+port+" is
cancel monitor "+monitor_host+":"+monitor_port);
+ }
+ else {
+ duccLogger.warn(location, jobid, host+":"+port+" is
*not* cancel monitor "+monitor_host+":"+monitor_port);
+ }
+ }
+
+ @Override
+ public boolean isAutoCancelEnabled() {
+ if(actual_host == null) {
+ return false;
+ }
+ if(monitor_host == null) {
+ return false;
+ }
+ if(!actual_host.equals(monitor_host)) {
+ String actual_domainless_host =
actual_host.split("\\.")[0];
+ String monitor_domainless_host =
monitor_host.split("\\.")[0];
+
if(!actual_domainless_host.equals(monitor_domainless_host)) {
+ return false;
+ }
+ }
+ if(actual_port == null) {
+ return false;
+ }
+ if(monitor_port == null) {
+ return false;
+ }
+ if(!actual_port.equals(monitor_port)) {
+ return false;
+ }
+ return true;
+ }
+
private DuccId getKey(String jobId) {
DuccId retVal = null;
- Enumeration<DuccId> keys = jMap.keys();
+ Enumeration<DuccId> keys = jmMap.keys();
while(keys.hasMoreElements()) {
DuccId duccId = keys.nextElement();
String mapId = ""+duccId.getFriendly();
@@ -315,8 +384,8 @@ public class DuccWebMonitor implements I
return retVal;
}
- public MonitorInfo renew(String jobId) {
- String location = "renew";
+ public MonitorInfo renewJob(String jobId) {
+ String location = "renewJob";
duccLogger.trace(location, jobid, "enter");
MonitorInfo monitorInfo = new MonitorInfo();
@@ -352,10 +421,10 @@ public class DuccWebMonitor implements I
}
if(duccId != null) {
- monitorInfo = jMap.get(duccId);
- if(tMap.containsKey(duccId)) {
+ monitorInfo = jmMap.get(duccId);
+ if(jtMap.containsKey(duccId)) {
long expiryMillis =
System.currentTimeMillis()+timeoutMillis+1;
- TrackingInfo ti = tMap.get(duccId);
+ TrackingInfo ti = jtMap.get(duccId);
ti.time = expiryMillis;
duccLogger.info(location, duccId, "Job
auto-cancel expiry extended");
}
@@ -376,19 +445,98 @@ public class DuccWebMonitor implements I
return monitorInfo;
}
- public ConcurrentHashMap<DuccId,Long> getExpiryMap() {
- String location = "getExpiryMap";
+ @Override
+ public MonitorInfo renew(DuccType duccType, String id) {
+ MonitorInfo monitorInfo = new MonitorInfo();
+ if(duccType != null) {
+ if(id != null) {
+ switch(duccType) {
+ case Job:
+ monitorInfo = renewJob(id);
+ break;
+ case Reservation:
+ break;
+ case Service:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return monitorInfo;
+ }
+
+ private Long getExpiryJob(DuccId duccId) {
+ String location = "getExpiryJob";
+ duccLogger.trace(location, duccId, "enter");
+ Long retVal = null;
+ if(!isCanceledJob(duccId)) {
+ if(isCancelableJob(duccId)) {
+ ConcurrentHashMap<DuccId,Long> eMap =
getExpiryMapJobs();
+ if(eMap.containsKey(duccId)) {
+ retVal = eMap.get(duccId);
+ }
+ }
+ }
+ duccLogger.trace(location, duccId, "exit");
+ return retVal;
+ }
+
+ @Override
+ public Long getExpiry(DuccType duccType, DuccId duccId) {
+ Long expiry = null;
+ if(duccType != null) {
+ if(duccId != null) {
+ switch(duccType) {
+ case Job:
+ expiry = getExpiryJob(duccId);
+ break;
+ case Reservation:
+ break;
+ case Service:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return expiry;
+ }
+
+ @Override
+ public boolean isCanceled(DuccType duccType, DuccId duccId) {
+ boolean flag = false;
+ if(duccType != null) {
+ if(duccId != null) {
+ switch(duccType) {
+ case Job:
+ flag = isCanceledJob(duccId);
+ break;
+ case Reservation:
+ break;
+ case Service:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return flag;
+ }
+
+ public ConcurrentHashMap<DuccId,Long> getExpiryMapJobs() {
+ String location = "getExpiryMapJobs";
duccLogger.trace(location, jobid, "enter");
ConcurrentHashMap<DuccId,Long> eMap = new
ConcurrentHashMap<DuccId,Long>();
long nowMillis = System.currentTimeMillis();
- Enumeration<DuccId> keys = tMap.keys();
+ Enumeration<DuccId> keys = jtMap.keys();
while(keys.hasMoreElements()) {
long minutesLeft = 0;
DuccId duccId = keys.nextElement();
- TrackingInfo ti = tMap.get(duccId);
+ TrackingInfo ti = jtMap.get(duccId);
long expiryMillis = ti.time;
if(nowMillis < expiryMillis) {
minutesLeft = (expiryMillis - nowMillis) /
millisPerMinute;
@@ -401,59 +549,23 @@ public class DuccWebMonitor implements I
return eMap;
}
- private boolean isCancelable(DuccId duccId) {
- String location = "isCancelable";
- duccLogger.trace(location, duccId, "enter");
- boolean retVal = false;
- if(!cMap.containsKey(duccId)) {
- MonitorInfo monitorInfo = jMap.get(duccId);
- if(monitorInfo != null) {
- ArrayList<String> stateSequence =
monitorInfo.stateSequence;
- if(stateSequence != null) {
-
if(stateSequence.contains(JobState.Completing.toString())) {
- duccLogger.debug(location,
duccId, "state: <uncancelable> "+stateSequence);
- }
- else
if(stateSequence.contains(JobState.Completed.toString())) {
- duccLogger.debug(location,
duccId, "state: <uncancelable> "+stateSequence);
- }
- else {
- duccLogger.debug(location,
duccId, "state: <cancelable> "+stateSequence);
- retVal = true;
- }
- }
- else {
- duccLogger.warn(location, duccId,
"stateSequence: <null>");
- }
- }
- else {
- duccLogger.warn(location, duccId, "monitorInfo:
<null>");
- }
- }
- else {
- duccLogger.debug(location, duccId, "already canceled");
- }
- duccLogger.trace(location, duccId, "exit");
- return retVal;
- }
-
- public boolean isCancelPending(DuccId duccId) {
- return cMap.containsKey(duccId);
- }
-
- public Long getExpiry(DuccId duccId) {
- String location = "getExpiry";
- duccLogger.trace(location, duccId, "enter");
- Long retVal = null;
- if(!isCanceled(duccId)) {
- if(isCancelable(duccId)) {
- ConcurrentHashMap<DuccId,Long> eMap =
getExpiryMap();
- if(eMap.containsKey(duccId)) {
- retVal = eMap.get(duccId);
- }
+ @Override
+ public ConcurrentHashMap<DuccId,Long> getExpiryMap(DuccType duccType) {
+ ConcurrentHashMap<DuccId,Long> eMap = new
ConcurrentHashMap<DuccId,Long>();
+ if(duccType != null) {
+ switch(duccType) {
+ case Job:
+ eMap = getExpiryMapJobs();
+ break;
+ case Reservation:
+ break;
+ case Service:
+ break;
+ default:
+ break;
}
}
- duccLogger.trace(location, duccId, "exit");
- return retVal;
+ return eMap;
}
}
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java?rev=1457235&r1=1457234&r2=1457235&view=diff
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java
(original)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccWebServer.java
Sat Mar 16 10:56:41 2013
@@ -144,7 +144,7 @@ public class DuccWebServer {
try {
InetAddress inetAddress = InetAddress.getLocalHost();
String host = inetAddress.getCanonicalHostName();
- DuccWebMonitor.getInstance().registerHostPort(host,
""+port);
+ DuccWebMonitor.getInstance().register(host, ""+port);
}
catch(Exception e) {
logger.error(methodName, jobid, e);
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/IWebMonitor.java
URL:
http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/IWebMonitor.java?rev=1457235&view=auto
==============================================================================
---
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/IWebMonitor.java
(added)
+++
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/IWebMonitor.java
Sat Mar 16 10:56:41 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.ws.server;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.uima.ducc.common.json.MonitorInfo;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.apache.uima.ducc.transport.event.common.IDuccTypes.DuccType;
+
+public interface IWebMonitor {
+ public void register(String host, String port);
+ public boolean isAutoCancelEnabled();
+ public MonitorInfo renew(DuccType duccType, String id);
+ public Long getExpiry(DuccType duccType, DuccId duccId);
+ public ConcurrentHashMap<DuccId,Long> getExpiryMap(DuccType duccType);
+ public boolean isCanceled(DuccType duccType, DuccId duccId);
+}