CalculatedStatus { public static CalculatedStatus statusFromTaskEntities(Collection<HostRoleCommandEntity> tasks, boolean skippable) { int size = tasks.size(); Map<HostRoleStatus, Integer> taskStatusCounts = CalculatedStatus.calculateTaskEntityStatusCounts(tasks); HostRoleStatus status = calculateSummaryStatus(taskStatusCounts, size, skippable); double progressPercent = calculateProgressPercent(taskStatusCounts, size); return new CalculatedStatus(status, progressPercent); } private  CalculatedStatus(HostRoleStatus status, double percent); private  CalculatedStatus(HostRoleStatus status, HostRoleStatus displayStatus, double percent); HostRoleStatus getStatus(); HostRoleStatus getDisplayStatus(); double getPercent(); static CalculatedStatus statusFromTaskEntities(Collection<HostRoleCommandEntity> tasks, boolean skippable); static CalculatedStatus statusFromStageEntities(Collection<StageEntity> stages); static CalculatedStatus statusFromStages(Collection<Stage> stages); static Map<HostRoleStatus, Integer> calculateStatusCounts(Collection<HostRoleStatus> hostRoleStatuses); static Map<HostRoleStatus, Integer> calculateStatusCountsForTasks(Collection<HostRoleCommand> hostRoleCommands); static Map<StatusType,Map<HostRoleStatus, Integer>> calculateStatusCountsForStage(Collection<TaskStatusListener.ActiveStage> stages); static Map<HostRoleStatus, Integer> calculateStatusCountsForTasks(Collection<HostRoleCommand> hostRoleCommands, StageEntityPK stage); static Map<HostRoleStatus, Integer> calculateTaskEntityStatusCounts(Collection<HostRoleCommandEntity> tasks); static Map<HostRoleStatus, Integer> calculateTaskStatusCounts(
      Map<Long, HostRoleCommandStatusSummaryDTO> stageDto, Set<Long> stageIds); static CalculatedStatus statusFromStageSummary(Map<Long, HostRoleCommandStatusSummaryDTO> stageDto,
      Set<Long> stageIds); static HostRoleStatus calculateSummaryStatus(Map<HostRoleStatus, Integer> counters,
      int total, boolean skippable); static HostRoleStatus calculateSummaryStatusFromPartialSet(Map<HostRoleStatus, Integer> counters,
                                                      boolean skippable); static HostRoleStatus calculateStageStatus(List <HostRoleCommand> hostRoleCommands, Map<HostRoleStatus, Integer> counters, Map<Role, Float> successFactors,
                                                    boolean skippable); static HostRoleStatus getOverallStatusForRequest(Collection<HostRoleStatus> hostRoleStatuses); static HostRoleStatus getOverallDisplayStatusForRequest(Collection<HostRoleStatus> hostRoleStatuses); static HostRoleStatus calculateSummaryDisplayStatus(
      Map<HostRoleStatus, Integer> counters, int total, boolean skippable); static final CalculatedStatus COMPLETED; static final CalculatedStatus PENDING; }
@Test public void testStatusFromTaskEntities() throws Exception { Collection<HostRoleCommandEntity> tasks = getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING); CalculatedStatus status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.PENDING, status.getStatus()); assertEquals(0.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.FAILED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.FAILED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.FAILED, HostRoleStatus.FAILED, HostRoleStatus.FAILED, HostRoleStatus.FAILED); status = CalculatedStatus.statusFromTaskEntities(tasks, true); assertEquals(HostRoleStatus.COMPLETED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.TIMEDOUT, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.TIMEDOUT, HostRoleStatus.FAILED, HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT); status = CalculatedStatus.statusFromTaskEntities(tasks, true); assertEquals(HostRoleStatus.COMPLETED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.ABORTED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED); status = CalculatedStatus.statusFromTaskEntities(tasks, true); assertEquals(HostRoleStatus.ABORTED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.IN_PROGRESS, status.getStatus()); assertEquals(40.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.COMPLETED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.HOLDING, status.getStatus()); assertEquals(54.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING_FAILED, HostRoleStatus.PENDING, HostRoleStatus.PENDING); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.HOLDING_FAILED, status.getStatus()); assertEquals(54.0, status.getPercent(), 0.1); tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING_TIMEDOUT, HostRoleStatus.PENDING, HostRoleStatus.PENDING); status = CalculatedStatus.statusFromTaskEntities(tasks, false); assertEquals(HostRoleStatus.HOLDING_TIMEDOUT, status.getStatus()); assertEquals(54.0, status.getPercent(), 0.1); }