public static Set<ServiceCluster> getClusterControllerServiceClusters(ApplicationInstance application) { return application.serviceClusters().stream() .filter(VespaModelUtil::isClusterController) .collect(Collectors.toSet()); }
public static Set<HostName> getHostsUsedByApplicationInstance(ApplicationInstance applicationInstance) { return applicationInstance.serviceClusters().stream() .flatMap(serviceCluster -> getHostsUsedByServiceCluster(serviceCluster).stream()) .collect(toSet()); }
private static boolean applicationInstanceUsesHost(ApplicationInstance applicationInstance, HostName hostName) { return applicationInstance.serviceClusters().stream() .anyMatch(serviceCluster -> serviceCluster.serviceInstances().stream() .anyMatch(serviceInstance -> serviceInstance.hostName().equals(hostName))); }
public static Optional<ServiceInstance> getStorageNodeAtHost(ApplicationInstance application, HostName hostName) { Set<ServiceInstance> storageNodesOnHost = application.serviceClusters().stream() .filter(VespaModelUtil::isStorage) .flatMap(cluster -> cluster.serviceInstances().stream()) .filter(service -> service.hostName().equals(hostName)) .collect(Collectors.toSet()); if (storageNodesOnHost.isEmpty()) { return Optional.empty(); } if (storageNodesOnHost.size() > 1) { throw new RuntimeException("Expected application " + application.applicationInstanceId() + " to have exactly one storage node service on host " + hostName + " but got " + storageNodesOnHost.size() + ": " + storageNodesOnHost); } return storageNodesOnHost.stream().findAny(); }
/** * A content cluster consists of many content-related service clusters, like distributor and storagenode. * All of the service clusters within a content cluster have the same service cluster ID, * which is also called the content ID (specified in services.xml) and also cluster name * (terminology used in Cluster Controller). The cluster name is used when referring to * content cluster resources through the HTTP REST on the Cluster Controller. * * There may be many content clusters within an application. But only one content cluster may be * present on any single host, * * @return The cluster name managed by a Cluster Controller. * @throws IllegalArgumentException if there is not exactly one content cluster name. */ public static ClusterId getContentClusterName(ApplicationInstance application, HostName hostName) { Set<ClusterId> contentClusterIdsOnHost = application.serviceClusters().stream() .filter(VespaModelUtil::isContent) .filter(cluster -> clusterHasInstanceOnHost(cluster, hostName)) .map(ServiceCluster::clusterId) .collect(Collectors.toSet()); if (contentClusterIdsOnHost.size() != 1) { throw new IllegalArgumentException("Expected exactly one content cluster within application " + application.applicationInstanceId() + " and host " + hostName + ", but found " + contentClusterIdsOnHost.size() + ": " + contentClusterIdsOnHost + ", application: " + application); } return contentClusterIdsOnHost.iterator().next(); }
private static Set<ServiceCluster> getServiceClustersInGroup(NodeGroup nodeGroup) { ApplicationInstance applicationInstance = nodeGroup.getApplication(); Set<ServiceCluster> serviceClustersInGroup = new HashSet<>(); for (ServiceCluster cluster : applicationInstance.serviceClusters()) { for (ServiceInstance instance : cluster.serviceInstances()) { if (nodeGroup.contains(instance.hostName())) { serviceClustersInGroup.add(cluster); break; } } } return serviceClustersInGroup; }
@Override public Host getHost(HostName hostName) throws HostNameNotFoundException { ApplicationInstance applicationInstance = getApplicationInstance(hostName); List<ServiceInstance> serviceInstances = applicationInstance .serviceClusters().stream() .flatMap(cluster -> cluster.serviceInstances().stream()) .filter(serviceInstance -> hostName.equals(serviceInstance.hostName())) .collect(Collectors.toList()); HostStatus hostStatus = getNodeStatus(applicationInstance.reference(), hostName); return new Host(hostName, hostStatus, applicationInstance.reference(), serviceInstances); }
throws ApplicationStateChangeDeniedException, ApplicationIdNotFoundException { Set<ClusterId> contentClusterIds = application.serviceClusters().stream() .filter(VespaModelUtil::isContent) .map(ServiceCluster::clusterId)