public Cluster getCluster(ViewInstanceDefinition viewInstance) {
    if (viewInstance != null) {
      Long clusterId = viewInstance.getClusterHandle();

      if (clusterId != null && viewInstance.getClusterType() == ClusterType.LOCAL_AMBARI) {
        try {
          return new ClusterImpl(clustersProvider.get().getCluster(clusterId));
        } catch (AmbariException e) {
          LOG.error("Could not find the cluster identified by {}.", clusterId);
          throw new IllegalClusterException(e);
        }

      } else if (clusterId != null && viewInstance.getClusterType() == ClusterType.REMOTE_AMBARI) {
        try {
          return remoteAmbariClusterRegistry.get(clusterId);
        } catch (MalformedURLException e) {
          LOG.error("Remote Cluster with id={} had invalid URL.", clusterId, e);
          throw new IllegalClusterException(e);
        } catch (ClusterNotFoundException e) {
          LOG.error("Cannot get Remote Cluster with id={}.", clusterId, e);
          throw new IllegalClusterException(e);
        }
      }
    }
    return null;
  }
Get the cluster associated with the given view instance.

@param viewInstance the view instance
@return the cluster
ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java