private void validateHostInDeleteFriendlyState(HostRequest hostRequest, Clusters clusters) throws AmbariException {
    Set<String> clusterNamesForHost = new HashSet<>();
    String hostName = hostRequest.getHostname();
    if (null != hostRequest.getClusterName()) {
      clusterNamesForHost.add(hostRequest.getClusterName());
    } else {
      Set<Cluster> clustersForHost = clusters.getClustersForHost(hostRequest.getHostname());
      if (null != clustersForHost) {
        for (Cluster c : clustersForHost) {
          clusterNamesForHost.add(c.getClusterName());
        }
      }
    }

    for (String clusterName : clusterNamesForHost) {
      Cluster cluster = clusters.getCluster(clusterName);

      List<ServiceComponentHost> list = cluster.getServiceComponentHosts(hostName);

      if (!list.isEmpty()) {
        List<String> componentsStarted = new ArrayList<>();
        for (ServiceComponentHost sch : list) {
          if (!sch.canBeRemoved()) {
            componentsStarted.add(sch.getServiceComponentName());
          }
        }

        // error if components are running
        if (!componentsStarted.isEmpty()) {
          StringBuilder reason = new StringBuilder("Cannot remove host ")
              .append(hostName)
              .append(" from ")
              .append(hostRequest.getClusterName())
              .append(
                  ".  The following roles exist, and these components are not in the removable state: ");

          reason.append(StringUtils.join(componentsStarted, ", "));

          throw new AmbariException(reason.toString());
        }
      }
    }
  }
@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