@Test public void testCalculateStatusCounts() throws Exception { Collection<HostRoleStatus> hostRoleStatuses = new LinkedList<HostRoleStatus>(); hostRoleStatuses.add(HostRoleStatus.PENDING); hostRoleStatuses.add(HostRoleStatus.QUEUED); hostRoleStatuses.add(HostRoleStatus.HOLDING); hostRoleStatuses.add(HostRoleStatus.HOLDING_FAILED); hostRoleStatuses.add(HostRoleStatus.HOLDING_TIMEDOUT); hostRoleStatuses.add(HostRoleStatus.IN_PROGRESS); hostRoleStatuses.add(HostRoleStatus.IN_PROGRESS); hostRoleStatuses.add(HostRoleStatus.COMPLETED); hostRoleStatuses.add(HostRoleStatus.COMPLETED); hostRoleStatuses.add(HostRoleStatus.COMPLETED); hostRoleStatuses.add(HostRoleStatus.COMPLETED); hostRoleStatuses.add(HostRoleStatus.FAILED); hostRoleStatuses.add(HostRoleStatus.TIMEDOUT); hostRoleStatuses.add(HostRoleStatus.ABORTED); hostRoleStatuses.add(HostRoleStatus.SKIPPED_FAILED); Map<HostRoleStatus, Integer> counts = CalculatedStatus.calculateStatusCounts(hostRoleStatuses); assertEquals(1L, (long) counts.get(HostRoleStatus.PENDING)); assertEquals(1L, (long) counts.get(HostRoleStatus.QUEUED)); assertEquals(1L, (long) counts.get(HostRoleStatus.HOLDING)); assertEquals(1L, (long) counts.get(HostRoleStatus.HOLDING_FAILED)); assertEquals(1L, (long) counts.get(HostRoleStatus.HOLDING_TIMEDOUT)); assertEquals(5L, (long) counts.get(HostRoleStatus.IN_PROGRESS)); assertEquals(8L, (long) counts.get(HostRoleStatus.COMPLETED)); assertEquals(1L, (long) counts.get(HostRoleStatus.FAILED)); assertEquals(1L, (long) counts.get(HostRoleStatus.TIMEDOUT)); assertEquals(1L, (long) counts.get(HostRoleStatus.ABORTED)); assertEquals(1L, (long) counts.get(HostRoleStatus.SKIPPED_FAILED)); }
public static Map<HostRoleStatus, Integer> calculateStatusCounts(Collection<HostRoleStatus> hostRoleStatuses) { Map<HostRoleStatus, Integer> counters = new HashMap<HostRoleStatus, Integer>(); for (HostRoleStatus hostRoleStatus : HostRoleStatus.values()) { counters.put(hostRoleStatus, 0); } for (HostRoleStatus status : hostRoleStatuses) { if (status.isCompletedState() && status != HostRoleStatus.COMPLETED) { counters.put(HostRoleStatus.COMPLETED, counters.get(HostRoleStatus.COMPLETED) + 1); } counters.put(status, counters.get(status) + 1); } counters.put(HostRoleStatus.IN_PROGRESS, hostRoleStatuses.size() - counters.get(HostRoleStatus.COMPLETED) - counters.get(HostRoleStatus.QUEUED) - counters.get(HostRoleStatus.PENDING)); return counters; }
CalculatedStatus { public static Map<HostRoleStatus, Integer> calculateStatusCounts(Collection<HostRoleStatus> hostRoleStatuses) { Map<HostRoleStatus, Integer> counters = new HashMap<HostRoleStatus, Integer>(); for (HostRoleStatus hostRoleStatus : HostRoleStatus.values()) { counters.put(hostRoleStatus, 0); } for (HostRoleStatus status : hostRoleStatuses) { if (status.isCompletedState() && status != HostRoleStatus.COMPLETED) { counters.put(HostRoleStatus.COMPLETED, counters.get(HostRoleStatus.COMPLETED) + 1); } counters.put(status, counters.get(status) + 1); } counters.put(HostRoleStatus.IN_PROGRESS, hostRoleStatuses.size() - counters.get(HostRoleStatus.COMPLETED) - counters.get(HostRoleStatus.QUEUED) - counters.get(HostRoleStatus.PENDING)); return counters; } }
CalculatedStatus { public static Map<HostRoleStatus, Integer> calculateStatusCounts(Collection<HostRoleStatus> hostRoleStatuses) { Map<HostRoleStatus, Integer> counters = new HashMap<HostRoleStatus, Integer>(); for (HostRoleStatus hostRoleStatus : HostRoleStatus.values()) { counters.put(hostRoleStatus, 0); } for (HostRoleStatus status : hostRoleStatuses) { if (status.isCompletedState() && status != HostRoleStatus.COMPLETED) { counters.put(HostRoleStatus.COMPLETED, counters.get(HostRoleStatus.COMPLETED) + 1); } counters.put(status, counters.get(status) + 1); } counters.put(HostRoleStatus.IN_PROGRESS, hostRoleStatuses.size() - counters.get(HostRoleStatus.COMPLETED) - counters.get(HostRoleStatus.QUEUED) - counters.get(HostRoleStatus.PENDING)); return counters; } private  CalculatedStatus(HostRoleStatus status, double percent); private  CalculatedStatus(HostRoleStatus status, HostRoleStatus displayStatus, double percent); }
CalculatedStatus { public static Map<HostRoleStatus, Integer> calculateStatusCounts(Collection<HostRoleStatus> hostRoleStatuses) { Map<HostRoleStatus, Integer> counters = new HashMap<HostRoleStatus, Integer>(); for (HostRoleStatus hostRoleStatus : HostRoleStatus.values()) { counters.put(hostRoleStatus, 0); } for (HostRoleStatus status : hostRoleStatuses) { if (status.isCompletedState() && status != HostRoleStatus.COMPLETED) { counters.put(HostRoleStatus.COMPLETED, counters.get(HostRoleStatus.COMPLETED) + 1); } counters.put(status, counters.get(status) + 1); } counters.put(HostRoleStatus.IN_PROGRESS, hostRoleStatuses.size() - counters.get(HostRoleStatus.COMPLETED) - counters.get(HostRoleStatus.QUEUED) - counters.get(HostRoleStatus.PENDING)); return counters; } 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); }
CalculatedStatus { public static Map<HostRoleStatus, Integer> calculateStatusCounts(Collection<HostRoleStatus> hostRoleStatuses) { Map<HostRoleStatus, Integer> counters = new HashMap<HostRoleStatus, Integer>(); for (HostRoleStatus hostRoleStatus : HostRoleStatus.values()) { counters.put(hostRoleStatus, 0); } for (HostRoleStatus status : hostRoleStatuses) { if (status.isCompletedState() && status != HostRoleStatus.COMPLETED) { counters.put(HostRoleStatus.COMPLETED, counters.get(HostRoleStatus.COMPLETED) + 1); } counters.put(status, counters.get(status) + 1); } counters.put(HostRoleStatus.IN_PROGRESS, hostRoleStatuses.size() - counters.get(HostRoleStatus.COMPLETED) - counters.get(HostRoleStatus.QUEUED) - counters.get(HostRoleStatus.PENDING)); return counters; } 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; }