VespaModelUtil { public static List<HostName> getClusterControllerInstancesInOrder(ApplicationInstance application, ClusterId contentClusterId) { Set<ServiceCluster> controllerClusters = getClusterControllerServiceClusters(application); Collection<ServiceCluster> controllerClustersForContentCluster = filter(controllerClusters, contentClusterId); Set<ServiceInstance> clusterControllerInstances; if (controllerClustersForContentCluster.size() == 1) { clusterControllerInstances = first(controllerClustersForContentCluster).serviceInstances(); } else if (controllerClusters.size() == 1) { ServiceCluster cluster = first(controllerClusters); log.warning("No cluster controller cluster for content cluster " + contentClusterId + ", using the only cluster controller cluster available: " + cluster.clusterId()); clusterControllerInstances = cluster.serviceInstances(); } else { throw new RuntimeException("Failed getting cluster controller for content cluster " + contentClusterId + ". Available clusters = " + controllerClusters + ", matching clusters = " + controllerClustersForContentCluster); } return clusterControllerInstances.stream() .sorted(CLUSTER_CONTROLLER_INDEX_COMPARATOR) .map(serviceInstance -> serviceInstance.hostName()) .collect(Collectors.toList()); }  static boolean isClusterController(ServiceCluster cluster); static boolean isStorage(ServiceCluster cluster); static boolean isContent(ServiceCluster cluster); static List<HostName> getClusterControllerInstancesInOrder(ApplicationInstance application,
                                                                          ClusterId contentClusterId); static Set<ServiceCluster> getClusterControllerServiceClusters(ApplicationInstance application); static HostName getControllerHostName(ApplicationInstance application, ClusterId contentClusterId); static ClusterId getContentClusterName(ApplicationInstance application, HostName hostName); static int getStorageNodeIndex(ApplicationInstance application, HostName hostName); static Optional<ServiceInstance> getStorageNodeAtHost(ApplicationInstance application, 
                                                                        HostName hostName); static int getClusterControllerIndex(ConfigId configId); static int getStorageNodeIndex(ConfigId configId); static final ApplicationId TENANT_HOST_APPLICATION_ID; static final ClusterId ADMIN_CLUSTER_ID; static final ServiceType SLOBROK_SERVICE_TYPE; static final ServiceType CLUSTER_CONTROLLER_SERVICE_TYPE; static final ServiceType DISTRIBUTOR_SERVICE_TYPE; static final ServiceType SEARCHNODE_SERVICE_TYPE; static final ServiceType STORAGENODE_SERVICE_TYPE; static final ServiceType METRICS_PROXY_SERVICE_TYPE; }
@Test public void testGettingClusterControllerInstances() { List<HostName> controllers = VespaModelUtil.getClusterControllerInstancesInOrder(application, CONTENT_CLUSTER_ID); List<HostName> expectedControllers = Arrays.asList(controller0.hostName(), controller1.hostName()); assertEquals(expectedControllers, controllers); }