@Override
  public void mapHostToCluster(String hostname, String clusterName)
      throws AmbariException {

    Host host = getHost(hostname);
    Cluster cluster = getCluster(clusterName);
    ConcurrentHashMap<String, Set<Cluster>> hostClustersMap = getHostClustersMap();

    // check to ensure there are no duplicates
    for (Cluster c : hostClustersMap.get(hostname)) {
      if (c.getClusterName().equals(clusterName)) {
        throw new DuplicateResourceException("Attempted to create a host which already exists: clusterName=" +
          clusterName + ", hostName=" + hostname);
      }
    }

    long clusterId = cluster.getClusterId();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Mapping host {} to cluster {} (id={})", hostname, clusterName,
        clusterId);
    }

    mapHostClusterEntities(hostname, clusterId);
    hostClustersMap.get(hostname).add(cluster);
    getClusterHostsMap().get(clusterName).add(host);
  }
Attempts to map the host to the cluster via clusterhostmapping table if not already present, and add a host_version
record for the cluster's currently applied (stack, version) if not already present.
@param hostname Host name
@param clusterName Cluster name
@throws AmbariException May throw a DuplicateResourceException.
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java