use of com.yahoo.vespa.applicationmodel.ServiceCluster in project vespa by vespa-engine.
the class VespaModelUtilTest method verifyNonContentClusterIsNotRecognized.
@Test
public void verifyNonContentClusterIsNotRecognized() {
ServiceCluster cluster = createServiceCluster(new ServiceType("foo"));
assertFalse(VespaModelUtil.isContent(cluster));
}
use of com.yahoo.vespa.applicationmodel.ServiceCluster in project vespa by vespa-engine.
the class HostResourceTest method getHost_works.
@Test
public void getHost_works() throws Exception {
Orchestrator orchestrator = mock(Orchestrator.class);
HostResource hostResource = new HostResource(orchestrator, uriInfo);
HostName hostName = new HostName("hostname");
UriBuilder baseUriBuilder = mock(UriBuilder.class);
when(uriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
when(baseUriBuilder.path(any(String.class))).thenReturn(baseUriBuilder);
when(baseUriBuilder.path(any(Class.class))).thenReturn(baseUriBuilder);
URI uri = new URI("https://foo.com/bar");
when(baseUriBuilder.build()).thenReturn(uri);
ServiceInstance serviceInstance = new ServiceInstance(new ConfigId("configId"), hostName, ServiceStatus.UP);
ServiceCluster serviceCluster = new ServiceCluster(new ClusterId("clusterId"), new ServiceType("serviceType"), Collections.singleton(serviceInstance));
serviceInstance.setServiceCluster(serviceCluster);
Host host = new Host(hostName, HostStatus.ALLOWED_TO_BE_DOWN, new ApplicationInstanceReference(new TenantId("tenantId"), new ApplicationInstanceId("applicationId")), Collections.singletonList(serviceInstance));
when(orchestrator.getHost(hostName)).thenReturn(host);
GetHostResponse response = hostResource.getHost(hostName.s());
assertEquals("https://foo.com/bar", response.applicationUrl());
assertEquals("hostname", response.hostname());
assertEquals("ALLOWED_TO_BE_DOWN", response.state());
assertEquals(1, response.services().size());
assertEquals("clusterId", response.services().get(0).clusterId);
assertEquals("configId", response.services().get(0).configId);
assertEquals("UP", response.services().get(0).serviceStatus);
assertEquals("serviceType", response.services().get(0).serviceType);
}
use of com.yahoo.vespa.applicationmodel.ServiceCluster in project vespa by vespa-engine.
the class OrchestratorImplTest method testGetHost.
@Test
public void testGetHost() throws Exception {
ClusterControllerClientFactory clusterControllerClientFactory = mock(ClusterControllerClientFactory.class);
StatusService statusService = mock(StatusService.class);
InstanceLookupService lookupService = mock(InstanceLookupService.class);
orchestrator = new OrchestratorImpl(clusterControllerClientFactory, statusService, new OrchestratorConfig(new OrchestratorConfig.Builder()), lookupService);
HostName hostName = new HostName("host.yahoo.com");
TenantId tenantId = new TenantId("tenant");
ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId("applicationInstanceId");
ApplicationInstanceReference reference = new ApplicationInstanceReference(tenantId, applicationInstanceId);
ApplicationInstance applicationInstance = new ApplicationInstance(tenantId, applicationInstanceId, Stream.of(new ServiceCluster(new ClusterId("clusterId"), new ServiceType("serviceType"), Stream.of(new ServiceInstance(new ConfigId("configId1"), hostName, ServiceStatus.UP), new ServiceInstance(new ConfigId("configId2"), hostName, ServiceStatus.NOT_CHECKED)).collect(Collectors.toSet()))).collect(Collectors.toSet()));
when(lookupService.findInstanceByHost(hostName)).thenReturn(Optional.of(applicationInstance));
ReadOnlyStatusRegistry readOnlyStatusRegistry = mock(ReadOnlyStatusRegistry.class);
when(statusService.forApplicationInstance(reference)).thenReturn(readOnlyStatusRegistry);
when(readOnlyStatusRegistry.getHostStatus(hostName)).thenReturn(HostStatus.ALLOWED_TO_BE_DOWN);
Host host = orchestrator.getHost(hostName);
assertEquals(reference, host.getApplicationInstanceReference());
assertEquals(hostName, host.getHostName());
assertEquals(HostStatus.ALLOWED_TO_BE_DOWN, host.getHostStatus());
assertEquals(2, host.getServiceInstances().size());
}
use of com.yahoo.vespa.applicationmodel.ServiceCluster 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.ServiceCluster 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;
}
Aggregations