public void processTaskResponse(String hostname, List<CommandReport> reports,
                                  Map<Long, HostRoleCommand> commands) {
    if (reports == null) {
      return;
    }

    Collections.sort(reports, new Comparator<CommandReport>() {
      @Override
      public int compare(CommandReport o1, CommandReport o2) {
        return (int) (o1.getTaskId()-o2.getTaskId());
      }
    });
    List<CommandReport> reportsToProcess = new ArrayList<>();
    //persist the action response into the db.
    for (CommandReport report : reports) {
      HostRoleCommand command = commands.get(report.getTaskId());
      if (LOG.isDebugEnabled()) {
        LOG.debug("Processing command report : {}", report);
      }
      if (command == null) {
        LOG.warn("The task " + report.getTaskId()
            + " is invalid");
        continue;
      }
      if (! command.getStatus().equals(HostRoleStatus.IN_PROGRESS)
          && ! command.getStatus().equals(HostRoleStatus.QUEUED)
          && ! command.getStatus().equals(HostRoleStatus.ABORTED)) {
        LOG.warn("The task " + command.getTaskId()
            + " is not in progress, ignoring update");
        continue;
      }
      reportsToProcess.add(report);
    }

    db.updateHostRoleStates(reportsToProcess);
  }
Persists command reports into the db
@param reports command reports
@param commands a list of commands that correspond to reports list (it should be
a 1 to 1 matching). We use this list to avoid fetching commands from the DB
twice
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java