@Override public int percentageOfServicesDownIfGroupIsAllowedToBeDown() { int numberOfServicesDown = servicesDownAndNotInGroup.size() + servicesInGroup.size(); return numberOfServicesDown * 100 / serviceCluster.serviceInstances().size(); }
@Override public int percentageOfServicesDown() { int numberOfServicesDown = servicesDownAndNotInGroup.size() + servicesDownInGroup.size(); return numberOfServicesDown * 100 / serviceCluster.serviceInstances().size(); }
public static Set<HostName> getHostsUsedByServiceCluster(ServiceCluster serviceCluster) { return serviceCluster.serviceInstances().stream() .map(ServiceInstance::hostName) .collect(toSet()); }
private static boolean clusterHasInstanceOnHost(ServiceCluster cluster, HostName hostName) { return cluster.serviceInstances().stream().anyMatch(service -> Objects.equals(hostName, service.hostName())); }
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 Stream<ServiceInstance> serviceInstancesOnHost(ServiceCluster serviceCluster, HostName hostName) { return serviceCluster.serviceInstances().stream() .filter(instance -> instance.hostName().equals(hostName)); }
public ClusterApiImpl(ApplicationApi applicationApi, ServiceCluster serviceCluster, NodeGroup nodeGroup, Map<HostName, HostStatus> hostStatusMap, ClusterControllerClientFactory clusterControllerClientFactory) { this.applicationApi = applicationApi; this.serviceCluster = serviceCluster; this.nodeGroup = nodeGroup; this.hostStatusMap = hostStatusMap; this.clusterControllerClientFactory = clusterControllerClientFactory; Map<Boolean, Set<ServiceInstance>> serviceInstancesByLocality = serviceCluster.serviceInstances().stream() .collect( Collectors.groupingBy( instance -> nodeGroup.contains(instance.hostName()), Collectors.toSet())); servicesInGroup = serviceInstancesByLocality.getOrDefault(true, Collections.emptySet()); servicesNotInGroup = serviceInstancesByLocality.getOrDefault(false, Collections.emptySet()); servicesDownInGroup = servicesInGroup.stream().filter(this::serviceEffectivelyDown).collect(Collectors.toSet()); servicesDownAndNotInGroup = servicesNotInGroup.stream().filter(this::serviceEffectivelyDown).collect(Collectors.toSet()); }
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(); }
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; }
/** * @return The set of all Cluster Controller service instances for the application. */ 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()); }
@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); }