@Override
  public void addCluster(String clusterName, StackId stackId, SecurityType securityType)
      throws AmbariException {
    Cluster cluster = null;

    if (getClustersByName().containsKey(clusterName)) {
      throw new DuplicateResourceException(
          "Attempted to create a Cluster which already exists" + ", clusterName=" + clusterName);
    }

    // create an admin resource to represent this cluster
    ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
    if (resourceTypeEntity == null) {
      resourceTypeEntity = new ResourceTypeEntity();
      resourceTypeEntity.setId(ResourceType.CLUSTER.getId());
      resourceTypeEntity.setName(ResourceType.CLUSTER.name());
      resourceTypeEntity = resourceTypeDAO.merge(resourceTypeEntity);
    }

    ResourceEntity resourceEntity = new ResourceEntity();
    resourceEntity.setResourceType(resourceTypeEntity);

    StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());

    // retrieve new cluster id
    // add cluster id -> cluster mapping into clustersById
    ClusterEntity clusterEntity = new ClusterEntity();
    clusterEntity.setClusterName(clusterName);
    clusterEntity.setDesiredStack(stackEntity);
    clusterEntity.setResource(resourceEntity);
    if (securityType != null) {
      clusterEntity.setSecurityType(securityType);
    }

    try {
      clusterDAO.create(clusterEntity);
    } catch (RollbackException e) {
      LOG.warn("Unable to create cluster " + clusterName, e);
      throw new AmbariException("Unable to create cluster " + clusterName, e);
    }

    cluster = clusterFactory.create(clusterEntity);
    getClustersByName().put(clusterName, cluster);
    getClustersById().put(cluster.getClusterId(), cluster);
    getClusterHostsMap().put(clusterName,
        Collections.newSetFromMap(new ConcurrentHashMap<>()));

    cluster.setCurrentStackVersion(stackId);

    TreeMap<String, TopologyCluster> addedClusters = new TreeMap<>();
    TopologyCluster addedCluster = new TopologyCluster();
    addedClusters.put(Long.toString(cluster.getClusterId()), addedCluster);
    TopologyUpdateEvent topologyUpdateEvent = new TopologyUpdateEvent(addedClusters,
        UpdateEventType.UPDATE);
    m_topologyHolder.get().updateData(topologyUpdateEvent);
    m_metadataHolder.get().updateData(m_ambariManagementController.get().getClusterMetadata(cluster));
  }
Initializes all of the in-memory state collections that this class
unfortunately uses.
<p>
This method should be called only once, when the data is first needed.
<p/>
Because some of these stateful initializations may actually reference this
{@link Clusters} instance, we must do this after the object has been
instantiated and injected.
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java