@Transactional
  protected DeleteStatusMetaData deleteHosts(Set<HostRequest> requests, boolean dryRun)
      throws AmbariException {

    AmbariManagementController controller = getManagementController();
    Clusters                   clusters   = controller.getClusters();
    DeleteStatusMetaData deleteStatusMetaData = new DeleteStatusMetaData();
    List<HostRequest> okToRemove = new ArrayList<>();

    for (HostRequest hostRequest : requests) {
      String hostName = hostRequest.getHostname();
      if (null == hostName) {
        continue;
      }

      try {
        validateHostInDeleteFriendlyState(hostRequest, clusters);
        okToRemove.add(hostRequest);
      } catch (Exception ex) {
        deleteStatusMetaData.addException(hostName, ex);
      }
    }

    //If dry run, don't delete. just assume it can be successfully deleted.
    if (dryRun) {
      for (HostRequest request : okToRemove) {
        deleteStatusMetaData.addDeletedKey(request.getHostname());
      }
    } else {
      processDeleteHostRequests(okToRemove, clusters, deleteStatusMetaData);
    }

    //Do not break behavior for existing clients where delete request contains only 1 host.
    //Response for these requests will have empty body with appropriate error code.
    //dryRun is a new feature so its ok to unify the behavior
    if (!dryRun) {
      if (deleteStatusMetaData.getDeletedKeys().size() + deleteStatusMetaData.getExceptionForKeys().size() == 1) {
        if (deleteStatusMetaData.getDeletedKeys().size() == 1) {
          return null;
        }
        for (Map.Entry<String, Exception> entry : deleteStatusMetaData.getExceptionForKeys().entrySet()) {
          Exception ex = entry.getValue();
          if (ex instanceof AmbariException) {
            throw (AmbariException) ex;
          } else {
            throw new AmbariException(ex.getMessage(), ex);
          }
        }
      }
    }

    return deleteStatusMetaData;
  }
@param osFamily provides OS to OS family lookup; may be null if OS family is ignored anyway (eg. for liveness check)
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java