private void addStagePK(HostRoleCommand hostRoleCommand) {
    StageEntityPK stageEntityPK = new StageEntityPK();
    stageEntityPK.setRequestId(hostRoleCommand.getRequestId());
    stageEntityPK.setStageId(hostRoleCommand.getStageId());
    if (activeStageMap.containsKey(stageEntityPK)) {
      activeStageMap.get(stageEntityPK).addTaskId(hostRoleCommand.getTaskId());
    } else {
      StageEntity stageEntity = stageDAO.findByPK(stageEntityPK);
      // Stage entity of the hostrolecommand should be persisted before publishing task create event
      assert stageEntity != null;
      Map<Role, Float> successFactors = new HashMap<>();
      Collection<RoleSuccessCriteriaEntity> roleSuccessCriteriaEntities = stageEntity.getRoleSuccessCriterias();
      for (RoleSuccessCriteriaEntity successCriteriaEntity : roleSuccessCriteriaEntities) {
        successFactors.put(successCriteriaEntity.getRole(), successCriteriaEntity.getSuccessFactor().floatValue());
      }
      Set<Long> taskIdSet =  Sets.newHashSet(hostRoleCommand.getTaskId());

      ActiveStage reportedStage = new ActiveStage(stageEntity.getStatus(), stageEntity.getDisplayStatus(),
          successFactors, stageEntity.isSkippable(), taskIdSet);
      activeStageMap.put(stageEntityPK, reportedStage);
    }
  }
Adds new {@link StageEntityPK} to be tracked as running stage in {@link #activeStageMap}
@param hostRoleCommand newly created {@link HostRoleCommand} in {@link #activeTasksMap}
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java