int failedTaskCount = 0;
int abortedTaskCount = 0;
int timedOutTaskCount = 0;
for (HostRoleCommand hostRoleCommand : commands) {
HostRoleStatus status = hostRoleCommand.getStatus();
if (status.isCompletedState()) {
completedTaskCount++;
switch (status) {
case ABORTED:
abortedTaskCount++;
break;
case FAILED:
failedTaskCount++;
break;
case TIMEDOUT:
timedOutTaskCount++;
break;
}
} else if (status.equals(HostRoleStatus.QUEUED)) {
queuedTaskCount++;
} else if (status.equals(HostRoleStatus.PENDING)) {
pendingTaskCount++;
}
}
int inProgressTaskCount = taskCount - completedTaskCount - queuedTaskCount - pendingTaskCount;
LOG.debug("taskCount={}, inProgressTaskCount={}, completedTaskCount={}, queuedTaskCount={}, " +
"pendingTaskCount={}, failedTaskCount={}, abortedTaskCount={}, timedOutTaskCount={}",
taskCount, inProgressTaskCount, completedTaskCount, queuedTaskCount, pendingTaskCount,
failedTaskCount, abortedTaskCount, timedOutTaskCount);
// determine request status
HostRoleStatus requestStatus = failedTaskCount > 0 ? HostRoleStatus.FAILED :
abortedTaskCount > 0 ? HostRoleStatus.ABORTED :
timedOutTaskCount > 0 ? HostRoleStatus.TIMEDOUT :
inProgressTaskCount > 0 ? HostRoleStatus.IN_PROGRESS :
completedTaskCount == taskCount ? HostRoleStatus.COMPLETED :
HostRoleStatus.PENDING;
double progressPercent =
((queuedTaskCount * 0.09 + inProgressTaskCount * 0.35 + completedTaskCount) / (double) taskCount) * 100.0;
setResourceProperty(resource, REQUEST_STATUS_PROPERTY_ID, requestStatus.toString(), requestedPropertyIds);
setResourceProperty(resource, REQUEST_TASK_CNT_ID, taskCount, requestedPropertyIds);
setResourceProperty(resource, REQUEST_FAILED_TASK_CNT_ID, failedTaskCount, requestedPropertyIds);
setResourceProperty(resource, REQUEST_ABORTED_TASK_CNT_ID, abortedTaskCount, requestedPropertyIds);
setResourceProperty(resource, REQUEST_TIMED_OUT_TASK_CNT_ID, timedOutTaskCount, requestedPropertyIds);
setResourceProperty(resource, REQUEST_QUEUED_TASK_CNT_ID, queuedTaskCount, requestedPropertyIds);