@Subscribe
  public void processHostRemovedEvent(HostsRemovedEvent hostsRemovedEvent) {

    if (hostsRemovedEvent.getHostNames().isEmpty()) {
      LOG.warn("Missing host name from host removed event [{}] !", hostsRemovedEvent);
      return;
    }

    LOG.info("Removing hosts [{}] from available hosts on hosts removed event.", hostsRemovedEvent.getHostNames());
    Set<HostImpl> toBeRemoved = new HashSet<>();

    // synchronization is required here as the list may be modified concurrently. See comments in this whole class.
    synchronized (availableHosts) {
      for (HostImpl hostImpl : availableHosts) {
        for (String hostName : hostsRemovedEvent.getHostNames()) {
          if (hostName.equals(hostImpl.getHostName())) {
            toBeRemoved.add(hostImpl);
            break;
          }
        }
      }

      if (!toBeRemoved.isEmpty()) {
        for (HostImpl host : toBeRemoved) {
          availableHosts.remove(host);
          LOG.info("Removed host: [{}] from available hosts", host.getHostName());
        }
      } else {
        LOG.debug("No any host [{}] found in available hosts", hostsRemovedEvent.getHostNames());
      }
    }
  }
Removes a host from the available hosts when the host gets deleted.
@param hostsRemovedEvent the event containing the hostname
ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java