@Test public void testStatusFromStages() throws Exception { Collection<Stage> stages; CalculatedStatus status; stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.COMPLETED, status.getStatus()); assertEquals(100.0, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.IN_PROGRESS, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.IN_PROGRESS, status.getStatus()); assertEquals(48.3, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.PENDING, status.getStatus()); assertEquals(0.0, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.FAILED, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.FAILED, status.getStatus()); assertEquals(55.55, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.TIMEDOUT), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.TIMEDOUT, status.getStatus()); assertEquals(66.66, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.HOLDING, status.getStatus()); assertEquals(47.5, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.HOLDING, status.getStatus()); assertEquals(47.5, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.HOLDING, status.getStatus()); assertNull(status.getDisplayStatus()); assertEquals(47.5, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.ABORTED), getTaskEntities(HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED), getTaskEntities(HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.ABORTED, status.getStatus()); assertNull(status.getDisplayStatus()); assertEquals(100.0, status.getPercent(), 0.1); stages = getStages( getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED), getTaskEntities(HostRoleStatus.ABORTED, HostRoleStatus.ABORTED, HostRoleStatus.PENDING), getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING) ); status = CalculatedStatus.statusFromStages(stages); assertEquals(HostRoleStatus.IN_PROGRESS, status.getStatus()); assertNull(status.getDisplayStatus()); assertEquals(66.6, status.getPercent(), 0.1); }
public static CalculatedStatus statusFromStages(Collection<Stage> stages) { Collection<HostRoleStatus> stageStatuses = new HashSet<HostRoleStatus>(); Collection<HostRoleCommand> tasks = new HashSet<HostRoleCommand>(); for (Stage stage : stages) { Collection<HostRoleCommand> stageTasks = stage.getOrderedHostRoleCommands(); HostRoleStatus stageStatus = calculateSummaryStatus(calculateTaskStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable()); stageStatuses.add(stageStatus); tasks.addAll(stageTasks); } HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size()); double progressPercent = calculateProgressPercent(calculateTaskStatusCounts(tasks), tasks.size()); return new CalculatedStatus(status, progressPercent); }
CalculatedStatus { public static CalculatedStatus statusFromStages(Collection<Stage> stages) { Collection<HostRoleStatus> stageStatuses = new HashSet<HostRoleStatus>(); Collection<HostRoleCommand> tasks = new HashSet<HostRoleCommand>(); for (Stage stage : stages) { Collection<HostRoleCommand> stageTasks = stage.getOrderedHostRoleCommands(); HostRoleStatus stageStatus = calculateSummaryStatus(calculateTaskStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable()); stageStatuses.add(stageStatus); tasks.addAll(stageTasks); } HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size()); double progressPercent = calculateProgressPercent(calculateTaskStatusCounts(tasks), tasks.size()); return new CalculatedStatus(status, progressPercent); } }
CalculatedStatus { public static CalculatedStatus statusFromStages(Collection<Stage> stages) { Collection<HostRoleStatus> stageStatuses = new HashSet<HostRoleStatus>(); Collection<HostRoleCommand> tasks = new HashSet<HostRoleCommand>(); for (Stage stage : stages) { Collection<HostRoleCommand> stageTasks = stage.getOrderedHostRoleCommands(); HostRoleStatus stageStatus = calculateSummaryStatus(calculateTaskStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable()); stageStatuses.add(stageStatus); tasks.addAll(stageTasks); } HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size()); double progressPercent = calculateProgressPercent(calculateTaskStatusCounts(tasks), tasks.size()); return new CalculatedStatus(status, progressPercent); } private  CalculatedStatus(HostRoleStatus status, double percent); private  CalculatedStatus(HostRoleStatus status, HostRoleStatus displayStatus, double percent); }
CalculatedStatus { public static CalculatedStatus statusFromStages(Collection<Stage> stages) { Collection<HostRoleStatus> stageStatuses = new HashSet<HostRoleStatus>(); Collection<HostRoleCommand> tasks = new HashSet<HostRoleCommand>(); for (Stage stage : stages) { Collection<HostRoleCommand> stageTasks = stage.getOrderedHostRoleCommands(); HostRoleStatus stageStatus = calculateSummaryStatus(calculateTaskStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable()); stageStatuses.add(stageStatus); tasks.addAll(stageTasks); } HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size()); double progressPercent = calculateProgressPercent(calculateTaskStatusCounts(tasks), tasks.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); }
CalculatedStatus { public static CalculatedStatus statusFromStages(Collection<Stage> stages) { Collection<HostRoleStatus> stageStatuses = new HashSet<HostRoleStatus>(); Collection<HostRoleCommand> tasks = new HashSet<HostRoleCommand>(); for (Stage stage : stages) { Collection<HostRoleCommand> stageTasks = stage.getOrderedHostRoleCommands(); HostRoleStatus stageStatus = calculateSummaryStatus(calculateTaskStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable()); stageStatuses.add(stageStatus); tasks.addAll(stageTasks); } HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size()); double progressPercent = calculateProgressPercent(calculateTaskStatusCounts(tasks), tasks.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; }