String reservationType = "Unmanaged";
if(duccwork instanceof DuccWorkJob) {
reservationType = "Managed";
}
StringBuffer sb;
DuccId duccId = duccwork.getDuccId();
// Terminate
sb = new StringBuffer();
String id = normalize(duccId);
sb.append("<span class=\"ducc-col-terminate\">");
if(terminateEnabled) {
if(!duccwork.isCompleted()) {
String disabled = getDisabledWithHover(request,duccwork);
String user = duccwork.getStandardInfo().getUser();
if(user != null) {
DuccPropertiesResolver dpr = DuccPropertiesResolver.getInstance();
String jdHostUser = dpr.getCachedProperty(DuccPropertiesResolver.ducc_jd_host_user);
// We presume that user is sufficient to identify JD shares
if(user.equals(jdHostUser)) {
disabled = "disabled=\"disabled\"";
}
}
sb.append("<input type=\"button\" onclick=\"ducc_confirm_terminate_reservation("+id+")\" value=\"Terminate\" "+disabled+"/>");
}
}
sb.append("</span>");
row.add(new JsonPrimitive(sb.toString()));
// Id
sb = new StringBuffer();
if(reservationType.equals("Managed")) {
sb.append("<span>");
sb.append("<a href=\"reservation.details.html?id="+id+"\">"+id+"</a>");
sb.append("</span>");
}
else {
sb.append("<span>");
sb.append(id);
sb.append("</span>");
}
row.add(new JsonPrimitive(sb.toString()));
// Start
sb = new StringBuffer();
sb.append("<span title=\""+DuccConstants.hintPreferencesDateStyle+"\">");
sb.append(getTimeStamp(request,duccwork.getDuccId(), duccwork.getStandardInfo().getDateOfSubmission()));
sb.append("</span>");
row.add(new JsonPrimitive(sb.toString()));
// Duration
sb = new StringBuffer();
if(duccwork instanceof DuccWorkReservation) {
DuccWorkReservation reservation = (DuccWorkReservation) duccwork;
switch(reservation.getReservationState()) {
case Completed:
sb.append("<span>");
String duration = getDuration(request,reservation);
String decoratedDuration = decorateDuration(request,reservation, duration);
sb.append(decoratedDuration);
sb.append("</span>");
break;
default:
sb.append("<span class=\"health_green\""+">");
duration = getDuration(request,reservation,now);
decoratedDuration = decorateDuration(request,reservation, duration);
sb.append(decoratedDuration);
sb.append("</span>");
break;
}
}
else if(duccwork instanceof DuccWorkJob) {
DuccWorkJob job = (DuccWorkJob) duccwork;
switch(job.getJobState()) {
case Completed:
sb.append("<span>");
String duration = getDuration(request,job);
String decoratedDuration = decorateDuration(request,job, duration);
sb.append(decoratedDuration);
sb.append("</span>");
break;
default:
sb.append("<span class=\"health_green\""+">");
duration = getDuration(request,job,now);
decoratedDuration = decorateDuration(request,job, duration);
sb.append(decoratedDuration);
sb.append("</span>");
break;
}
}
row.add(new JsonPrimitive(sb.toString()));
// User
sb = new StringBuffer();
String title = "";
String submitter = duccwork.getStandardInfo().getSubmitter();
if(submitter != null) {
title = "title=\"submitter PID@host: "+submitter+"\"";
}
sb.append("<span "+title+">");
UserId userId = new UserId(duccwork.getStandardInfo().getUser());
sb.append(userId.toString());
sb.append("</span>");
row.add(new JsonPrimitive(sb.toString()));
// Class
row.add(new JsonPrimitive(stringNormalize(duccwork.getSchedulingInfo().getSchedulingClass(),messages.fetch("default"))));
// Type
sb = new StringBuffer();
sb.append(reservationType);
row.add(new JsonPrimitive(sb.toString()));
// State
sb = new StringBuffer();
String state = duccwork.getStateObject().toString();
sb.append("<span>");
if(duccData.isLive(duccId)) {
if(duccwork.isOperational()) {
sb.append("<span class=\"active_state\">");
}
else {
sb.append("<span class=\"completed_state\">");
}
sb.append(state);
sb.append("</span>");
}
else {
sb.append("<span class=\"historic_state\">");
sb.append(state);
sb.append("</span>");
}
sb.append("</span>");
row.add(new JsonPrimitive(sb.toString()));
// Reason
sb = new StringBuffer();
if(duccwork instanceof DuccWorkReservation) {
DuccWorkReservation reservation = (DuccWorkReservation) duccwork;
switch(reservation.getCompletionType()) {
case Undefined:
break;
case CanceledByUser:
case CanceledByAdmin:
try {
String cancelUser = duccwork.getStandardInfo().getCancelUser();
if(cancelUser != null) {
sb.append("<span title=\"canceled by "+cancelUser+"\">");
sb.append(duccwork.getCompletionTypeObject().toString());
sb.append("</span>");
}
else {
IRationale rationale = reservation.getCompletionRationale();
if(rationale != null) {
sb.append("<span title=\""+rationale+"\">");
sb.append(duccwork.getCompletionTypeObject().toString());
sb.append("</span>");
}
else {
sb.append(duccwork.getCompletionTypeObject().toString());
}
}
}
catch(Exception e) {
IRationale rationale = reservation.getCompletionRationale();
if(rationale != null) {
sb.append("<span title=\""+rationale+"\">");
sb.append(duccwork.getCompletionTypeObject().toString());
sb.append("</span>");
}
else {
sb.append(duccwork.getCompletionTypeObject().toString());
}
}
break;
default:
IRationale rationale = reservation.getCompletionRationale();
if(rationale != null) {
sb.append("<span title=\""+rationale+"\">");
sb.append(duccwork.getCompletionTypeObject().toString());
sb.append("</span>");
}
else {
sb.append(duccwork.getCompletionTypeObject().toString());
}
break;
}
}
else if(duccwork instanceof DuccWorkJob) {
// Reason
DuccWorkJob job = (DuccWorkJob) duccwork;
sb = getReason(job,DuccType.Reservation);
}
row.add(new JsonPrimitive(sb.toString()));
// Allocation
sb = new StringBuffer();
sb.append("<span>");
sb.append(duccwork.getSchedulingInfo().getInstancesCount());
sb.append("</span>");
row.add(new JsonPrimitive(sb.toString()));
// User Processes
sb = new StringBuffer();
TreeMap<String,Integer> nodeMap = new TreeMap<String,Integer>();
if(duccwork instanceof DuccWorkReservation) {
DuccWorkReservation reservation = (DuccWorkReservation) duccwork;
if(!reservation.getReservationMap().isEmpty()) {
IDuccReservationMap map = reservation.getReservationMap();
for (DuccId key : map.keySet()) {
IDuccReservation value = reservation.getReservationMap().get(key);
String node = value.getNodeIdentity().getName();
if(!nodeMap.containsKey(node)) {
nodeMap.put(node,new Integer(0));
}
Integer count = nodeMap.get(node);
count++;
nodeMap.put(node,count);
}
}
boolean qualify = false;
if(!nodeMap.isEmpty()) {
if(nodeMap.keySet().size() > 1) {
qualify = true;
}
}
ArrayList<String> qualifiedPids = new ArrayList<String>();
if(duccwork.isOperational()) {
DuccMachinesData machinesData = DuccMachinesData.getInstance();
for (String node: nodeMap.keySet()) {
NodeId nodeId = new NodeId(node);
List<String> nodePids = machinesData.getPids(nodeId, userId);
for( String pid : nodePids ) {
if(qualify) {
qualifiedPids.add(node+":"+pid);
}
else {
qualifiedPids.add(pid);
}
}
}
}
if(qualifiedPids.size() > 0) {
String list = "";
for( String entry : qualifiedPids ) {
list += entry+" ";
}
sb.append("<span title=\""+list.trim()+"\">");
sb.append(""+qualifiedPids.size());
sb.append("</span>");
}
else {
sb.append(""+qualifiedPids.size());
}
}
else {
DuccWorkJob job = (DuccWorkJob) duccwork;
if(job.isOperational()) {
sb.append(duccwork.getSchedulingInfo().getInstancesCount());
}
else {
sb.append("0");
}
Iterator<DuccId> iterator = job.getProcessMap().keySet().iterator();
while(iterator.hasNext()) {
DuccId processId = iterator.next();
IDuccProcess process = job.getProcessMap().get(processId);
String node = process.getNodeIdentity().getName();
nodeMap.put(node, 1);
}
}