@Override
@Transactional
public synchronized Cluster getClusterById(long id) throws AmbariException {
if (!clustersById.containsKey(id)) {
ClusterEntity clusterEntity = clusterDAO.findById(id);
if (clusterEntity != null) {
Cluster cluster = clusterFactory.create(clusterEntity);
clustersById.put(cluster.getClusterId(), cluster);
clusters.put(clusterEntity.getClusterName(), cluster);
if (!clusterHostMap.containsKey(clusterEntity.getClusterName()))
clusterHostMap.put(clusterEntity.getClusterName(), new HashSet<Host>());
} else {
throw new ClusterNotFoundException("clusterID=" + id);
}
}
return clustersById.get(id);