Author: burn
Date: Thu Aug 15 18:51:19 2019
New Revision: 1865251

URL: http://svn.apache.org/viewvc?rev=1865251&view=rev
Log:
UIMA-6114 Reformatted the new experiments code

Modified:
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccPlugins.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/experiments/HandlerExperimentsAbstract.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/experiments/HandlerExperimentsServlets.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/utilities/HandlersUtilities.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/utilities/ResponseHelper.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/log/WsLog.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccLocalConstants.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccLocalCookies.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/Experiment.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/ExperimentException.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/ExperimentsRegistryManager.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/ExperimentsRegistryUtilities.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/IExperiment.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/Jed.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/Task.java
    
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/xd/TaskArray.java

Modified: 
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccPlugins.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccPlugins.java?rev=1865251&r1=1865250&r2=1865251&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccPlugins.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/DuccPlugins.java
 Thu Aug 15 18:51:19 2019
@@ -33,98 +33,93 @@ import org.apache.uima.ducc.ws.xd.Experi
 import org.eclipse.jetty.server.Handler;
 
 public class DuccPlugins {
-       
-       private static DuccLogger logger = 
DuccLogger.getLogger(DuccPlugins.class);
-       private static DuccId jobid = null;
-       
-       private static DuccPlugins instance = new DuccPlugins();
-       
-       public static DuccPlugins getInstance() {
-               return instance;
-       }
-       
-       private static ExperimentsRegistryManager experimentsRegistryManager = 
ExperimentsRegistryManager.getInstance();
-
-       /**
-        * The restore methods are called during boot of the web server.
-        * This is an opportunity to have local mods plug-in for
-        * processing that may be desirable relative to each Job,
-        * Reservation, and Service during the restoration from history.
-        */
-       
-       public void restore(IDuccWorkJob job) {
-               String location = "restore";
-               try {
-                       if(job != null) {
-                               String user = job.getStandardInfo().getUser();
-                               String directory = 
job.getStandardInfo().getLogDirectory();
-                               logger.info(location, jobid, "user", user, 
"directory", directory);
-                               experimentsRegistryManager.initialize(user, 
directory);
-                       }
-               }
-               catch(Throwable t) {
-                       logger.error(location, jobid, t);
-               }
-       }
-       
-       public void restore(IDuccWorkReservation reservation) {
-               String location = "restore";
-               try {
-                       //loc mods here
-               }
-               catch(Throwable t) {
-                       logger.error(location, jobid, t);
-               }
-       }
-       
-       public void restore(IDuccWorkService service) {
-               String location = "restore";
-               try {
-                       // Also process managed reservations in case the 
experiment has only these.
-                   if(service != null && service.getServiceDeploymentType() == 
ServiceDeploymentType.other) {
-                       String user = service.getStandardInfo().getUser();
-                       String directory = 
service.getStandardInfo().getLogDirectory();
-                       experimentsRegistryManager.initialize(user, directory);
-                   }
-               }
-               catch(Throwable t) {
-                       logger.error(location, jobid, t);
-               }
-       }
-       
-       /**
-        * The update method is called for each Orchestrator publication.
-        * This is an opportunity to have local mods plug-in for
-        * processing that may be desirable relative to each Job,
-        * Reservation, and Service within the published map.
-        */
-       
-       public void update(IDuccWorkMap dwm) {
-               String location = "update";
-               try {
-                       experimentsRegistryManager.update(dwm);
-               }
-               catch(Throwable t) {
-                       logger.error(location, jobid, t);
-               }
-       }
-       
-       /**
-        * The gethandlers method is called during boot of the web server.
-        * This is an opportunity to have local mods plug-in for
-        * processing that may be desirable relative to http/s requests.
-        */
-       
-       public ArrayList<Handler> gethandlers(DuccWebServer duccWebServer) {
-               String location = "gethandlers";
-               ArrayList<Handler> handlersList = new ArrayList<Handler> ();
-               try {
-                       HandlerExperimentsServlets handlerExperimentsServlets = 
new HandlerExperimentsServlets(duccWebServer);
-                       handlersList.add(handlerExperimentsServlets);
-               }
-               catch(Throwable t) {
-                       logger.error(location, jobid, t);
-               }
-               return handlersList;
-       }
+
+  private static DuccLogger logger = DuccLogger.getLogger(DuccPlugins.class);
+
+  private static DuccId jobid = null;
+
+  private static DuccPlugins instance = new DuccPlugins();
+
+  public static DuccPlugins getInstance() {
+    return instance;
+  }
+
+  private static ExperimentsRegistryManager experimentsRegistryManager = 
ExperimentsRegistryManager
+          .getInstance();
+
+  /**
+   * The restore methods are called during boot of the web server. This is an 
opportunity to have
+   * local mods plug-in for processing that may be desirable relative to each 
Job, Reservation, and
+   * Service during the restoration from history.
+   */
+
+  public void restore(IDuccWorkJob job) {
+    String location = "restore";
+    try {
+      if (job != null) {
+        String user = job.getStandardInfo().getUser();
+        String directory = job.getStandardInfo().getLogDirectory();
+        logger.info(location, jobid, "user", user, "directory", directory);
+        experimentsRegistryManager.initialize(user, directory);
+      }
+    } catch (Throwable t) {
+      logger.error(location, jobid, t);
+    }
+  }
+
+  public void restore(IDuccWorkReservation reservation) {
+    String location = "restore";
+    try {
+      // loc mods here
+    } catch (Throwable t) {
+      logger.error(location, jobid, t);
+    }
+  }
+
+  public void restore(IDuccWorkService service) {
+    String location = "restore";
+    try {
+      // Also process managed reservations in case the experiment has only 
these.
+      if (service != null && service.getServiceDeploymentType() == 
ServiceDeploymentType.other) {
+        String user = service.getStandardInfo().getUser();
+        String directory = service.getStandardInfo().getLogDirectory();
+        experimentsRegistryManager.initialize(user, directory);
+      }
+    } catch (Throwable t) {
+      logger.error(location, jobid, t);
+    }
+  }
+
+  /**
+   * The update method is called for each Orchestrator publication. This is an 
opportunity to have
+   * local mods plug-in for processing that may be desirable relative to each 
Job, Reservation, and
+   * Service within the published map.
+   */
+
+  public void update(IDuccWorkMap dwm) {
+    String location = "update";
+    try {
+      experimentsRegistryManager.update(dwm);
+    } catch (Throwable t) {
+      logger.error(location, jobid, t);
+    }
+  }
+
+  /**
+   * The gethandlers method is called during boot of the web server. This is 
an opportunity to have
+   * local mods plug-in for processing that may be desirable relative to 
http/s requests.
+   */
+
+  public ArrayList<Handler> gethandlers(DuccWebServer duccWebServer) {
+    String location = "gethandlers";
+    ArrayList<Handler> handlersList = new ArrayList<Handler>();
+    try {
+      HandlerExperimentsServlets handlerExperimentsServlets = new 
HandlerExperimentsServlets(
+              duccWebServer);
+      handlersList.add(handlerExperimentsServlets);
+    } catch (Throwable t) {
+      logger.error(location, jobid, t);
+    }
+    return handlersList;
+  }
 }

Modified: 
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/experiments/HandlerExperimentsAbstract.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/experiments/HandlerExperimentsAbstract.java?rev=1865251&r1=1865250&r2=1865251&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/experiments/HandlerExperimentsAbstract.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/handlers/experiments/HandlerExperimentsAbstract.java
 Thu Aug 15 18:51:19 2019
@@ -42,366 +42,359 @@ import org.eclipse.jetty.server.handler.
 public abstract class HandlerExperimentsAbstract extends AbstractHandler {
 
   // NOTE - this variable used to hold the class name before WsLog was 
simplified
-       private static DuccLogger cName = 
DuccLogger.getLogger(HandlerExperimentsAbstract.class);
-       
-       private static DuccData duccData = DuccData.getInstance();
-
-       public final String duccContext = DuccLocalConstants.duccContext;
-
-       protected DuccWebServer duccWebServer = null;
-
-       public void init(DuccWebServer duccWebServer) {
-               this.duccWebServer = duccWebServer;
-       }
-
-       public boolean isIgnorable(Throwable t) {
-               return HandlersUtilities.isIgnorable(t);
-       }
-
-       public String getFmtDuration(IDuccWorkJob job, HttpServletRequest 
request, long now) {
-               String retVal = "";
-               StringBuffer tb = new StringBuffer();
-               if(job.isCompleted()) {
-                       String duration = getDuration(request,job);
-                       String decoratedDuration = 
decorateDuration(request,job, duration);
-                       tb.append("<span>");
-                       tb.append(decoratedDuration);
-                       tb.append("</span>");
-                       retVal = tb.toString();
-               }
-               else {
-                       String duration = getDuration(request,job,now);
-                       String decoratedDuration = 
decorateDuration(request,job, duration);
-                       tb.append("<span class=\"health_green\""+">");
-                       tb.append(decoratedDuration);
-                       tb.append("</span>");
-                       String projection = getProjection(request,job);
-                       tb.append(projection);
-                       retVal = tb.toString();
-               }
-               return retVal;
-       }
-
-       public String getLink(IDuccWorkJob job) {
-               String retVal = "";
-               String parm = job.getDuccId().toString();
-               String displayId =  "j"+parm;
-               String link = "<a 
href=\"job.details.html?id="+parm+"\">"+displayId+"</a>";
-               retVal = link;
-               return retVal;
-       }
-
-       public String getTotal(IDuccWorkJob job) {
-               String retVal = "";
-               String total = job.getSchedulingInfo().getWorkItemsTotal();
-               retVal = total;
-               return retVal;
-       }
-
-       public String getDone(IDuccWorkJob job) {
-               String retVal = "";
-               String done = job.getSchedulingInfo().getWorkItemsCompleted();
-               IDuccPerWorkItemStatistics perWorkItemStatistics = 
job.getSchedulingInfo().getPerWorkItemStatistics();
-               if (perWorkItemStatistics != null) {
-                       double max = 
Math.round(perWorkItemStatistics.getMax()/100.0)/10.0;
-                       double min = 
Math.round(perWorkItemStatistics.getMin()/100.0)/10.0;
-                       double avg = 
Math.round(perWorkItemStatistics.getMean()/100.0)/10.0;
-                       double dev = 
Math.round(perWorkItemStatistics.getStandardDeviation()/100.0)/10.0;
-                       done = "<span title=\""+"seconds-per-work-item 
"+"Max:"+max+" "+"Min:"+min+" "+"Avg:"+avg+" 
"+"Dev:"+dev+"\""+">"+done+"</span>";
-               }
-               retVal = done;
-               return retVal;
-       }
-
-       public String getDispatch(IDuccWorkJob job) {
-               String retVal = "";
-               if(duccData.isLive(job.getDuccId())) {
-                       int unassigned = 
job.getSchedulingInfo().getCasQueuedMap().size();
-                       try {
-                               int dispatched = 
Integer.parseInt(job.getSchedulingInfo().getWorkItemsDispatched())-unassigned;
-                               retVal = ""+dispatched;
-                       }
-                       catch(Exception e) {
-                       }
-               }
-               else {
-                       retVal = "0";
-               }
-               return retVal;
-       }
-
-       public String getError(IDuccWorkJob job) {
-               String retVal = "";
-               retVal = buildErrorLink(job);
-               return retVal;
-       }
-
-       public String getRetry(IDuccWorkJob job) {
-               String retVal = "";
-               retVal = job.getSchedulingInfo().getWorkItemsRetry();
-               return retVal;
-       }
-
-       public String getPreempt(IDuccWorkJob job) {
-               String retVal = "";
-               retVal = job.getSchedulingInfo().getWorkItemsPreempt();
-               return retVal;
-       }
-
-       public String buildErrorLink(IDuccWorkJob job) {
-               return(buildErrorLink(job,null));
-       }
-
-       public final String duccLogData                   = 
duccContext+"/log-data";
-
-       public String buildErrorLink(IDuccWorkJob job, String name) {
-               String retVal = job.getSchedulingInfo().getWorkItemsError();
-               if(!retVal.equals("0")) {
-                       String errorCount = retVal;
-                       if(name == null) {
-                               name = errorCount;
-                       }
-                       String logfile = job.getUserLogDir() + "jd.err.log";
-                       String href = "<a 
href=\""+duccLogData+"?"+"fname="+logfile+"\" onclick=\"var newWin = 
window.open(this.href,'child','height=800,width=1200,scrollbars');  
newWin.focus(); return false;\">"+name+"</a>";
-                       retVal = href;
-               }
-               return retVal;
-       }
-
-       public String getDuration(HttpServletRequest request, IDuccWork dw) {
-               String mName = "getDuration";
-               String retVal = "";
-               try {
-                       String v2 = dw.getStandardInfo().getDateOfCompletion();
-                       String v1 = dw.getStandardInfo().getDateOfSubmission();
-                       WsLog.trace(cName, mName, "v2:"+v2+" v1:"+v1);
-                       retVal = getDuration(dw.getDuccId(),v2,v1);
-               }
-               catch(Exception e) {
-                       //
-               }
-               catch(Throwable t) {
-                       //
-               }
-               return retVal;
-       }
-
-       public String getDuration(HttpServletRequest request, IDuccWork dw, 
long now) {
-               String retVal = "";
-               try {
-                       String v2 = ""+now;
-                       String v1 = dw.getStandardInfo().getDateOfSubmission();
-                       retVal = getDuration(dw.getDuccId(),v2,v1);
-               }
-               catch(Exception e) {
-               }
-               catch(Throwable t) {
-               }
-               return retVal;
-       }
-
-       public String getDuration(DuccId jobId, String millisV2, String 
millisV1) {
-               String retVal = "";
-               try {
-                       long d2 = Long.parseLong(millisV2);
-                       long d1 = Long.parseLong(millisV1);
-                       long diff = d2 - d1;
-                       retVal = FormatHelper.duration(diff,Precision.Whole);
-               }
-               catch(Exception e) {
-                       //
-               }
-               catch(Throwable t) {
-                       //
-               }
-               return retVal;
-       }
-
-       public String decorateDuration(HttpServletRequest request, IDuccWorkJob 
job, String duration) {
-               String mName = "decorateDuration";
-               String retVal = duration;
-               try {
-                       StringBuffer title = new StringBuffer();
-                       double avgMillisPerWorkItem = 
getAvgMillisPerWorkItem(request, job);
-                       if(avgMillisPerWorkItem > 0) {
-                               if(avgMillisPerWorkItem < 500) {
-                                       avgMillisPerWorkItem = 500;
-                               }
-                       }
-                       int iAvgMillisPerWorkItem = (int)avgMillisPerWorkItem;
-                       if(iAvgMillisPerWorkItem > 0) {
-                               if(title.length() > 0) {
-                                       title.append("; ");
-                               }
-                               title.append("Time (ddd:hh:mm:ss) elapsed for 
job, average processing time per work 
item="+FormatHelper.duration(iAvgMillisPerWorkItem,Precision.Whole));
-                       }
-                       String cVal = getCompletion(request,job);
-                       if(cVal != null) {
-                               if(cVal.length() > 0) {
-                                       if(title.length() > 0) {
-                                               title.append("; ");
-                                       }
-                                       title.append("End="+cVal);
-                               }
-                       }
-                       if(title.length() > 0) {
-                               retVal = "<span 
"+"title=\""+title+"\""+">"+duration+"</span>";
-                       }
-               }
-               catch(Exception e) {
-                       WsLog.error(cName, mName, e);
-               }
-               return retVal;
-       }
-
-       public String decorateDuration(HttpServletRequest request, 
IDuccWorkReservation reservation, String duration) {
-               String retVal = duration;
-               String cVal = getCompletion(request,reservation);
-               if(cVal != null) {
-                       if(cVal.length() > 0) {
-                               String title = "title=\""+"End="+cVal+"\"";
-                               retVal = "<span "+title+">"+duration+"</span>";
-                       }
-               }
-               return retVal;
-       }
-
-
-       public double getAvgMillisPerWorkItem(HttpServletRequest request, 
IDuccWorkJob job) {
-               double avgMillis = 0;
-               IDuccSchedulingInfo schedulingInfo = job.getSchedulingInfo();
-               IDuccPerWorkItemStatistics perWorkItemStatistics = 
schedulingInfo.getPerWorkItemStatistics();
-               if (perWorkItemStatistics != null) {
-                       avgMillis = perWorkItemStatistics.getMean();
-               }
-               return avgMillis;
-}
+  private static DuccLogger cName = 
DuccLogger.getLogger(HandlerExperimentsAbstract.class);
+
+  private static DuccData duccData = DuccData.getInstance();
+
+  public final String duccContext = DuccLocalConstants.duccContext;
+
+  protected DuccWebServer duccWebServer = null;
 
-       public String getCompletion(HttpServletRequest request, IDuccWorkJob 
job) {
-               String retVal = "";
-               try {
-                       String tVal = 
job.getStandardInfo().getDateOfCompletion();
-                       retVal = getTimeStamp(request,job.getDuccId(),tVal);
-               }
-               catch(Exception e) {
-               }
-               catch(Throwable t) {
-               }
-               return retVal;
-       }
-
-       public String getCompletion(HttpServletRequest request, 
IDuccWorkReservation reservation) {
-               String retVal = "";
-               try {
-                       String tVal = 
reservation.getStandardInfo().getDateOfCompletion();
-                       retVal = 
getTimeStamp(request,reservation.getDuccId(),tVal);
-               }
-               catch(Exception e) {
-               }
-               catch(Throwable t) {
-               }
-               return retVal;
-       }
-
-       public String getTimeStamp(HttpServletRequest request, DuccId jobId, 
String millis) {
-               return 
getTimeStamp(DuccCookies.getDateStyle(request),getTimeStamp(jobId, millis));
-       }
-
-       private String getTimeStamp(DuccId jobId, String millis) {
-               String mName = "getTimeStamp";
-               String retVal = "";
-               try {
-                       retVal = TimeStamp.simpleFormat(millis);
-               }
-               catch(Throwable t) {
-                       WsLog.debug(cName, mName, "millis:"+millis);
-               }
-               return retVal;
-       }
-
-       public String getTimeStamp(DateStyle dateStyle, String date) {
-               String mName = "getTimeStamp";
-               StringBuffer sb = new StringBuffer();
-               if(date != null) {
-                       sb.append(date);
-                       if(date.trim().length() > 0) {
-                               try {
-                                       switch(dateStyle) {
-                                       case Long:
-                                               break;
-                                       case Medium:
-                                               String day = 
sb.substring(sb.length()-4);
-                                               sb.delete(0, 5);
-                                               sb.delete(sb.lastIndexOf(":"), 
sb.length());
-                                               sb.append(day);
-                                               break;
-                                       case Short:
-                                               sb.delete(0, 5);
-                                               sb.delete(sb.lastIndexOf(":"), 
sb.length());
-                                               break;
-                                       }
-                               }
-                               catch(Exception e) {
-                                        WsLog.error(cName, mName, e);
-                               }
-                       }
-               }
-               return sb.toString();
-       }
-
-       public String getProjection(HttpServletRequest request, IDuccWorkJob 
job) {
-               String mName = "getProjection";
-               String retVal = "";
-               try {
-                       IDuccSchedulingInfo schedulingInfo = 
job.getSchedulingInfo();
-                       IDuccPerWorkItemStatistics perWorkItemStatistics = 
schedulingInfo.getPerWorkItemStatistics();
-                       if (perWorkItemStatistics == null) {
-                               return "";
-                       }
-                       int total = schedulingInfo.getIntWorkItemsTotal();
-                       int completed = 
schedulingInfo.getIntWorkItemsCompleted();
-                       int error = schedulingInfo.getIntWorkItemsError();
-                       int remainingWorkItems = total - (completed + error);
-                       if(remainingWorkItems > 0) {
-                               int usableProcessCount = 
job.getProcessMap().getUsableProcessCount();
-                               if(usableProcessCount > 0) {
-                                       if(completed > 0) {
-                                               int threadsPerProcess = 
schedulingInfo.getIntThreadsPerProcess();
-                                               int totalThreads = 
usableProcessCount * threadsPerProcess;
-                                               double remainingIterations = 
remainingWorkItems / totalThreads;
-                                               double avgMillis = 
perWorkItemStatistics.getMean();
-                                               double leastOperatingMillis = 
job.getWiMillisOperatingLeast();
-                                               double mostCompletedMillis = 
job.getWiMillisCompletedMost();
-                                               double projectedTime = 
(avgMillis * remainingIterations) + (mostCompletedMillis - 
leastOperatingMillis);
-                                               String text = 
"avgMillis:"+avgMillis+" "+"remainingIterations:"+remainingIterations+" 
"+"mostCompleteMillis:"+mostCompletedMillis+" 
"+"leastOperatingMillis:"+leastOperatingMillis;
-                                               WsLog.trace(cName, mName, text);
-                                               if(projectedTime > 0) {
-                                                       long millis = 
Math.round(projectedTime);
-                                                       if(millis > 1000) {
-                                                               String 
projection = FormatHelper.duration(millis,Precision.Whole);
-                                                               String health = 
"class=\"health_yellow\"";
-                                                               String title = 
"title=\"Time (ddd:hh:mm:ss) until projected completion\"";
-                                                               retVal = 
"+"+"<span "+health+" "+title+"><i>"+projection+"</i></span>";
-                                                               retVal = " 
{"+retVal+"}";
-                                                       }
-                                               }
-                                               else {
-                                                       long millis = 
Math.round(0-projectedTime);
-                                                       if(millis > 1000) {
-                                                               String 
projection = FormatHelper.duration(millis,Precision.Whole);
-                                                               String health = 
"class=\"health_purple\"";
-                                                               String title = 
"title=\"Time (ddd:hh:mm:ss) past-due projected completion\"";
-                                                               retVal = 
"-"+"<span "+health+" "+title+"><i>"+projection+"</i></span>";
-                                                               retVal = " 
{"+retVal+"}";
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-               catch(Throwable t) {
-                       WsLog.error(cName, mName, t);
-               }
-               return retVal;
-       }
+  public void init(DuccWebServer duccWebServer) {
+    this.duccWebServer = duccWebServer;
+  }
+
+  public boolean isIgnorable(Throwable t) {
+    return HandlersUtilities.isIgnorable(t);
+  }
+
+  public String getFmtDuration(IDuccWorkJob job, HttpServletRequest request, 
long now) {
+    String retVal = "";
+    StringBuffer tb = new StringBuffer();
+    if (job.isCompleted()) {
+      String duration = getDuration(request, job);
+      String decoratedDuration = decorateDuration(request, job, duration);
+      tb.append("<span>");
+      tb.append(decoratedDuration);
+      tb.append("</span>");
+      retVal = tb.toString();
+    } else {
+      String duration = getDuration(request, job, now);
+      String decoratedDuration = decorateDuration(request, job, duration);
+      tb.append("<span class=\"health_green\"" + ">");
+      tb.append(decoratedDuration);
+      tb.append("</span>");
+      String projection = getProjection(request, job);
+      tb.append(projection);
+      retVal = tb.toString();
+    }
+    return retVal;
+  }
+
+  public String getLink(IDuccWorkJob job) {
+    String retVal = "";
+    String parm = job.getDuccId().toString();
+    String displayId = "j" + parm;
+    String link = "<a href=\"job.details.html?id=" + parm + "\">" + displayId 
+ "</a>";
+    retVal = link;
+    return retVal;
+  }
+
+  public String getTotal(IDuccWorkJob job) {
+    String retVal = "";
+    String total = job.getSchedulingInfo().getWorkItemsTotal();
+    retVal = total;
+    return retVal;
+  }
+
+  public String getDone(IDuccWorkJob job) {
+    String retVal = "";
+    String done = job.getSchedulingInfo().getWorkItemsCompleted();
+    IDuccPerWorkItemStatistics perWorkItemStatistics = job.getSchedulingInfo()
+            .getPerWorkItemStatistics();
+    if (perWorkItemStatistics != null) {
+      double max = Math.round(perWorkItemStatistics.getMax() / 100.0) / 10.0;
+      double min = Math.round(perWorkItemStatistics.getMin() / 100.0) / 10.0;
+      double avg = Math.round(perWorkItemStatistics.getMean() / 100.0) / 10.0;
+      double dev = Math.round(perWorkItemStatistics.getStandardDeviation() / 
100.0) / 10.0;
+      done = "<span title=\"" + "seconds-per-work-item " + "Max:" + max + " " 
+ "Min:" + min + " "
+              + "Avg:" + avg + " " + "Dev:" + dev + "\"" + ">" + done + 
"</span>";
+    }
+    retVal = done;
+    return retVal;
+  }
+
+  public String getDispatch(IDuccWorkJob job) {
+    String retVal = "";
+    if (duccData.isLive(job.getDuccId())) {
+      int unassigned = job.getSchedulingInfo().getCasQueuedMap().size();
+      try {
+        int dispatched = 
Integer.parseInt(job.getSchedulingInfo().getWorkItemsDispatched())
+                - unassigned;
+        retVal = "" + dispatched;
+      } catch (Exception e) {
+      }
+    } else {
+      retVal = "0";
+    }
+    return retVal;
+  }
+
+  public String getError(IDuccWorkJob job) {
+    String retVal = "";
+    retVal = buildErrorLink(job);
+    return retVal;
+  }
+
+  public String getRetry(IDuccWorkJob job) {
+    String retVal = "";
+    retVal = job.getSchedulingInfo().getWorkItemsRetry();
+    return retVal;
+  }
+
+  public String getPreempt(IDuccWorkJob job) {
+    String retVal = "";
+    retVal = job.getSchedulingInfo().getWorkItemsPreempt();
+    return retVal;
+  }
+
+  public String buildErrorLink(IDuccWorkJob job) {
+    return (buildErrorLink(job, null));
+  }
+
+  public final String duccLogData = duccContext + "/log-data";
+
+  public String buildErrorLink(IDuccWorkJob job, String name) {
+    String retVal = job.getSchedulingInfo().getWorkItemsError();
+    if (!retVal.equals("0")) {
+      String errorCount = retVal;
+      if (name == null) {
+        name = errorCount;
+      }
+      String logfile = job.getUserLogDir() + "jd.err.log";
+      String href = "<a href=\"" + duccLogData + "?" + "fname=" + logfile
+              + "\" onclick=\"var newWin = 
window.open(this.href,'child','height=800,width=1200,scrollbars');  
newWin.focus(); return false;\">"
+              + name + "</a>";
+      retVal = href;
+    }
+    return retVal;
+  }
+
+  public String getDuration(HttpServletRequest request, IDuccWork dw) {
+    String mName = "getDuration";
+    String retVal = "";
+    try {
+      String v2 = dw.getStandardInfo().getDateOfCompletion();
+      String v1 = dw.getStandardInfo().getDateOfSubmission();
+      WsLog.trace(cName, mName, "v2:" + v2 + " v1:" + v1);
+      retVal = getDuration(dw.getDuccId(), v2, v1);
+    } catch (Exception e) {
+      //
+    } catch (Throwable t) {
+      //
+    }
+    return retVal;
+  }
+
+  public String getDuration(HttpServletRequest request, IDuccWork dw, long 
now) {
+    String retVal = "";
+    try {
+      String v2 = "" + now;
+      String v1 = dw.getStandardInfo().getDateOfSubmission();
+      retVal = getDuration(dw.getDuccId(), v2, v1);
+    } catch (Exception e) {
+    } catch (Throwable t) {
+    }
+    return retVal;
+  }
+
+  public String getDuration(DuccId jobId, String millisV2, String millisV1) {
+    String retVal = "";
+    try {
+      long d2 = Long.parseLong(millisV2);
+      long d1 = Long.parseLong(millisV1);
+      long diff = d2 - d1;
+      retVal = FormatHelper.duration(diff, Precision.Whole);
+    } catch (Exception e) {
+      //
+    } catch (Throwable t) {
+      //
+    }
+    return retVal;
+  }
+
+  public String decorateDuration(HttpServletRequest request, IDuccWorkJob job, 
String duration) {
+    String mName = "decorateDuration";
+    String retVal = duration;
+    try {
+      StringBuffer title = new StringBuffer();
+      double avgMillisPerWorkItem = getAvgMillisPerWorkItem(request, job);
+      if (avgMillisPerWorkItem > 0) {
+        if (avgMillisPerWorkItem < 500) {
+          avgMillisPerWorkItem = 500;
+        }
+      }
+      int iAvgMillisPerWorkItem = (int) avgMillisPerWorkItem;
+      if (iAvgMillisPerWorkItem > 0) {
+        if (title.length() > 0) {
+          title.append("; ");
+        }
+        title.append("Time (ddd:hh:mm:ss) elapsed for job, average processing 
time per work item="
+                + FormatHelper.duration(iAvgMillisPerWorkItem, 
Precision.Whole));
+      }
+      String cVal = getCompletion(request, job);
+      if (cVal != null) {
+        if (cVal.length() > 0) {
+          if (title.length() > 0) {
+            title.append("; ");
+          }
+          title.append("End=" + cVal);
+        }
+      }
+      if (title.length() > 0) {
+        retVal = "<span " + "title=\"" + title + "\"" + ">" + duration + 
"</span>";
+      }
+    } catch (Exception e) {
+      WsLog.error(cName, mName, e);
+    }
+    return retVal;
+  }
+
+  public String decorateDuration(HttpServletRequest request, 
IDuccWorkReservation reservation,
+          String duration) {
+    String retVal = duration;
+    String cVal = getCompletion(request, reservation);
+    if (cVal != null) {
+      if (cVal.length() > 0) {
+        String title = "title=\"" + "End=" + cVal + "\"";
+        retVal = "<span " + title + ">" + duration + "</span>";
+      }
+    }
+    return retVal;
+  }
+
+  public double getAvgMillisPerWorkItem(HttpServletRequest request, 
IDuccWorkJob job) {
+    double avgMillis = 0;
+    IDuccSchedulingInfo schedulingInfo = job.getSchedulingInfo();
+    IDuccPerWorkItemStatistics perWorkItemStatistics = 
schedulingInfo.getPerWorkItemStatistics();
+    if (perWorkItemStatistics != null) {
+      avgMillis = perWorkItemStatistics.getMean();
+    }
+    return avgMillis;
+  }
+
+  public String getCompletion(HttpServletRequest request, IDuccWorkJob job) {
+    String retVal = "";
+    try {
+      String tVal = job.getStandardInfo().getDateOfCompletion();
+      retVal = getTimeStamp(request, job.getDuccId(), tVal);
+    } catch (Exception e) {
+    } catch (Throwable t) {
+    }
+    return retVal;
+  }
+
+  public String getCompletion(HttpServletRequest request, IDuccWorkReservation 
reservation) {
+    String retVal = "";
+    try {
+      String tVal = reservation.getStandardInfo().getDateOfCompletion();
+      retVal = getTimeStamp(request, reservation.getDuccId(), tVal);
+    } catch (Exception e) {
+    } catch (Throwable t) {
+    }
+    return retVal;
+  }
+
+  public String getTimeStamp(HttpServletRequest request, DuccId jobId, String 
millis) {
+    return getTimeStamp(DuccCookies.getDateStyle(request), getTimeStamp(jobId, 
millis));
+  }
+
+  private String getTimeStamp(DuccId jobId, String millis) {
+    String mName = "getTimeStamp";
+    String retVal = "";
+    try {
+      retVal = TimeStamp.simpleFormat(millis);
+    } catch (Throwable t) {
+      WsLog.debug(cName, mName, "millis:" + millis);
+    }
+    return retVal;
+  }
+
+  public String getTimeStamp(DateStyle dateStyle, String date) {
+    String mName = "getTimeStamp";
+    StringBuffer sb = new StringBuffer();
+    if (date != null) {
+      sb.append(date);
+      if (date.trim().length() > 0) {
+        try {
+          switch (dateStyle) {
+            case Long:
+              break;
+            case Medium:
+              String day = sb.substring(sb.length() - 4);
+              sb.delete(0, 5);
+              sb.delete(sb.lastIndexOf(":"), sb.length());
+              sb.append(day);
+              break;
+            case Short:
+              sb.delete(0, 5);
+              sb.delete(sb.lastIndexOf(":"), sb.length());
+              break;
+          }
+        } catch (Exception e) {
+          WsLog.error(cName, mName, e);
+        }
+      }
+    }
+    return sb.toString();
+  }
+
+  public String getProjection(HttpServletRequest request, IDuccWorkJob job) {
+    String mName = "getProjection";
+    String retVal = "";
+    try {
+      IDuccSchedulingInfo schedulingInfo = job.getSchedulingInfo();
+      IDuccPerWorkItemStatistics perWorkItemStatistics = 
schedulingInfo.getPerWorkItemStatistics();
+      if (perWorkItemStatistics == null) {
+        return "";
+      }
+      int total = schedulingInfo.getIntWorkItemsTotal();
+      int completed = schedulingInfo.getIntWorkItemsCompleted();
+      int error = schedulingInfo.getIntWorkItemsError();
+      int remainingWorkItems = total - (completed + error);
+      if (remainingWorkItems > 0) {
+        int usableProcessCount = job.getProcessMap().getUsableProcessCount();
+        if (usableProcessCount > 0) {
+          if (completed > 0) {
+            int threadsPerProcess = schedulingInfo.getIntThreadsPerProcess();
+            int totalThreads = usableProcessCount * threadsPerProcess;
+            double remainingIterations = remainingWorkItems / totalThreads;
+            double avgMillis = perWorkItemStatistics.getMean();
+            double leastOperatingMillis = job.getWiMillisOperatingLeast();
+            double mostCompletedMillis = job.getWiMillisCompletedMost();
+            double projectedTime = (avgMillis * remainingIterations)
+                    + (mostCompletedMillis - leastOperatingMillis);
+            String text = "avgMillis:" + avgMillis + " " + 
"remainingIterations:"
+                    + remainingIterations + " " + "mostCompleteMillis:" + 
mostCompletedMillis + " "
+                    + "leastOperatingMillis:" + leastOperatingMillis;
+            WsLog.trace(cName, mName, text);
+            if (projectedTime > 0) {
+              long millis = Math.round(projectedTime);
+              if (millis > 1000) {
+                String projection = FormatHelper.duration(millis, 
Precision.Whole);
+                String health = "class=\"health_yellow\"";
+                String title = "title=\"Time (ddd:hh:mm:ss) until projected 
completion\"";
+                retVal = "+" + "<span " + health + " " + title + "><i>" + 
projection
+                        + "</i></span>";
+                retVal = " {" + retVal + "}";
+              }
+            } else {
+              long millis = Math.round(0 - projectedTime);
+              if (millis > 1000) {
+                String projection = FormatHelper.duration(millis, 
Precision.Whole);
+                String health = "class=\"health_purple\"";
+                String title = "title=\"Time (ddd:hh:mm:ss) past-due projected 
completion\"";
+                retVal = "-" + "<span " + health + " " + title + "><i>" + 
projection
+                        + "</i></span>";
+                retVal = " {" + retVal + "}";
+              }
+            }
+          }
+        }
+      }
+    } catch (Throwable t) {
+      WsLog.error(cName, mName, t);
+    }
+    return retVal;
+  }
 }


Reply via email to