private void processCancelledRequestsList() throws AmbariException {
    synchronized (requestsToBeCancelled) {
      // Now, cancel stages completely
      for (Long requestId : requestsToBeCancelled) {
        // only pull back entities that have not completed; pulling back all
        // entities for the request can cause OOM problems on large requests,
        // like those for upgrades
        List<HostRoleCommandEntity> entitiesToDequeue = hostRoleCommandDAO.findByRequestIdAndStatuses(
            requestId, HostRoleStatus.NOT_COMPLETED_STATUSES);

        if (!entitiesToDequeue.isEmpty()) {
          List<HostRoleCommand> tasksToDequeue = new ArrayList<>(entitiesToDequeue.size());
          for (HostRoleCommandEntity hrcEntity : entitiesToDequeue) {
            HostRoleCommand task = hostRoleCommandFactory.createExisting(hrcEntity);
            tasksToDequeue.add(task);
          }

          String reason = requestCancelReasons.get(requestId);
          cancelHostRoleCommands(tasksToDequeue, reason);
        }

        // abort any stages in progress that belong to this request; don't execute this for all stages since
        // that could lead to OOM errors on large requests, like those for
        // upgrades
        List<Stage> stagesInProgress = db.getStagesInProgressForRequest(requestId);
        for (Stage stageInProgress : stagesInProgress) {
          abortOperationsForStage(stageInProgress);
        }
      }

      requestsToBeCancelled.clear();
      requestCancelReasons.clear();
    }
  }
Aborts all stages that belong to requests that are being cancelled
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java