use of com.yahoo.vespa.applicationmodel.ServiceInstance in project vespa by vespa-engine.
the class ApplicationApiImpl method getServiceClustersInGroup.
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;
}
use of com.yahoo.vespa.applicationmodel.ServiceInstance in project vespa by vespa-engine.
the class ModelGenerator method toApplicationInstance.
ApplicationInstance toApplicationInstance(ApplicationInfo applicationInfo, Zone zone, ServiceStatusProvider serviceStatusProvider) {
Map<ServiceClusterKey, Set<ServiceInstance>> groupedServiceInstances = new HashMap<>();
for (HostInfo host : applicationInfo.getModel().getHosts()) {
HostName hostName = new HostName(host.getHostname());
for (ServiceInfo serviceInfo : host.getServices()) {
ServiceClusterKey serviceClusterKey = toServiceClusterKey(serviceInfo);
ServiceInstance serviceInstance = toServiceInstance(applicationInfo.getApplicationId(), serviceClusterKey.clusterId(), serviceInfo, hostName, serviceStatusProvider);
if (!groupedServiceInstances.containsKey(serviceClusterKey)) {
groupedServiceInstances.put(serviceClusterKey, new HashSet<>());
}
groupedServiceInstances.get(serviceClusterKey).add(serviceInstance);
}
}
Set<ServiceCluster> serviceClusters = groupedServiceInstances.entrySet().stream().map(entry -> new ServiceCluster(entry.getKey().clusterId(), entry.getKey().serviceType(), entry.getValue())).collect(Collectors.toSet());
ApplicationInstance applicationInstance = new ApplicationInstance(new TenantId(applicationInfo.getApplicationId().tenant().toString()), toApplicationInstanceId(applicationInfo, zone), serviceClusters);
// Fill back-references
for (ServiceCluster serviceCluster : applicationInstance.serviceClusters()) {
serviceCluster.setApplicationInstance(applicationInstance);
for (ServiceInstance serviceInstance : serviceCluster.serviceInstances()) {
serviceInstance.setServiceCluster(serviceCluster);
}
}
return applicationInstance;
}
use of com.yahoo.vespa.applicationmodel.ServiceInstance in project vespa by vespa-engine.
the class ConfigServerApplication method toApplicationInstance.
ApplicationInstance toApplicationInstance(List<String> hostnames) {
Set<ServiceInstance> serviceInstances = hostnames.stream().map(hostname -> new ServiceInstance(new ConfigId(CONFIG_ID_PREFIX + hostname), new HostName(hostname), ServiceStatus.NOT_CHECKED)).collect(Collectors.toSet());
ServiceCluster serviceCluster = new ServiceCluster(CLUSTER_ID, SERVICE_TYPE, serviceInstances);
Set<ServiceCluster> serviceClusters = Stream.of(serviceCluster).collect(Collectors.toSet());
ApplicationInstance applicationInstance = new ApplicationInstance(TENANT_ID, APPLICATION_INSTANCE_ID, serviceClusters);
// Fill back-references
serviceCluster.setApplicationInstance(applicationInstance);
for (ServiceInstance serviceInstance : serviceCluster.serviceInstances()) {
serviceInstance.setServiceCluster(serviceCluster);
}
return applicationInstance;
}
use of com.yahoo.vespa.applicationmodel.ServiceInstance in project vespa by vespa-engine.
the class ModelGeneratorTest method verifyOtherApplication.
private void verifyOtherApplication(ApplicationInstance applicationInstance) {
assertEquals(String.format("%s:%s:%s:%s:%s", ExampleModel.TENANT, ExampleModel.APPLICATION_NAME, ENVIRONMENT, REGION, ExampleModel.INSTANCE_NAME), applicationInstance.reference().toString());
assertEquals(ExampleModel.TENANT, applicationInstance.tenantId().toString());
Set<ServiceCluster> serviceClusters = applicationInstance.serviceClusters();
assertEquals(1, serviceClusters.size());
ServiceCluster serviceCluster = serviceClusters.iterator().next();
assertEquals(ExampleModel.CLUSTER_ID, serviceCluster.clusterId().toString());
assertEquals(ExampleModel.SERVICE_TYPE, serviceCluster.serviceType().toString());
Set<ServiceInstance> serviceInstances = serviceCluster.serviceInstances();
assertEquals(1, serviceClusters.size());
ServiceInstance serviceInstance = serviceInstances.iterator().next();
assertEquals(HOSTNAME, serviceInstance.hostName().toString());
assertEquals(ExampleModel.CONFIG_ID, serviceInstance.configId().toString());
assertEquals(ServiceStatus.UP, serviceInstance.serviceStatus());
}
use of com.yahoo.vespa.applicationmodel.ServiceInstance in project vespa by vespa-engine.
the class ClusterApiImpl method storageNodeInGroup.
private Optional<StorageNode> storageNodeInGroup(Predicate<ServiceInstance> storageServicePredicate) {
if (!VespaModelUtil.isStorage(serviceCluster)) {
return Optional.empty();
}
Set<StorageNode> storageNodes = new HashSet<>();
for (ServiceInstance serviceInstance : servicesInGroup) {
if (!storageServicePredicate.test(serviceInstance)) {
continue;
}
HostName hostName = serviceInstance.hostName();
if (nodeGroup.contains(hostName)) {
if (storageNodes.contains(hostName)) {
throw new IllegalStateException("Found more than 1 storage service instance on " + hostName + ": last service instance is " + serviceInstance.configId() + " in storage cluster " + clusterInfo());
}
StorageNode storageNode = new StorageNodeImpl(nodeGroup.getApplication(), clusterId(), serviceInstance, clusterControllerClientFactory);
storageNodes.add(storageNode);
}
}
if (storageNodes.size() > 1) {
throw new IllegalStateException("Found more than 1 storage node (" + storageNodes + ") in the same cluster (" + clusterInfo() + ") in the same node group (" + getNodeGroup().toCommaSeparatedString() + "): E.g. suspension of such a setup is not supported " + " by the Cluster Controller and is dangerous w.r.t. data redundancy.");
}
return storageNodes.stream().findFirst();
}
Aggregations