Search in sources :

Example 1 with ApplicationInstanceId

use of com.yahoo.vespa.applicationmodel.ApplicationInstanceId 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);
}
Also used : ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) Host(com.yahoo.vespa.orchestrator.Host) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) URI(java.net.URI) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) GetHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) UriBuilder(javax.ws.rs.core.UriBuilder) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 2 with ApplicationInstanceId

use of com.yahoo.vespa.applicationmodel.ApplicationInstanceId 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());
}
Also used : OrchestratorConfig(com.yahoo.vespa.orchestrator.config.OrchestratorConfig) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) StatusService(com.yahoo.vespa.orchestrator.status.StatusService) InMemoryStatusService(com.yahoo.vespa.orchestrator.status.InMemoryStatusService) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) ReadOnlyStatusRegistry(com.yahoo.vespa.orchestrator.status.ReadOnlyStatusRegistry) ClusterControllerClientFactory(com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Example 3 with ApplicationInstanceId

use of com.yahoo.vespa.applicationmodel.ApplicationInstanceId in project vespa by vespa-engine.

the class OrchestratorUtil method parseAppInstanceReference.

/**
 * Returns an ApplicationInstanceReference constructed from the serialized format used in the REST API.
 */
public static ApplicationInstanceReference parseAppInstanceReference(String restFormat) {
    if (restFormat == null) {
        throw new IllegalArgumentException("Could not construct instance id from null string");
    }
    Matcher matcher = APPLICATION_INSTANCE_REFERENCE_REST_FORMAT_PATTERN.matcher(restFormat);
    if (!matcher.matches()) {
        throw new IllegalArgumentException("Could not construct instance id from string \"" + restFormat + "\"");
    }
    TenantId tenantId = new TenantId(matcher.group(1));
    ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(matcher.group(2));
    return new ApplicationInstanceReference(tenantId, applicationInstanceId);
}
Also used : ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) Matcher(java.util.regex.Matcher) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)

Example 4 with ApplicationInstanceId

use of com.yahoo.vespa.applicationmodel.ApplicationInstanceId in project vespa by vespa-engine.

the class ServiceMonitorStub method getAllApplicationInstances.

@Override
public Map<ApplicationInstanceReference, ApplicationInstance> getAllApplicationInstances() {
    // Convert apps information to the response payload to return
    Map<ApplicationInstanceReference, ApplicationInstance> status = new HashMap<>();
    for (Map.Entry<ApplicationId, MockDeployer.ApplicationContext> app : apps.entrySet()) {
        Set<ServiceInstance> serviceInstances = new HashSet<>();
        for (Node node : nodeRepository.getNodes(app.getValue().id(), Node.State.active)) {
            serviceInstances.add(new ServiceInstance(new ConfigId("configid"), new HostName(node.hostname()), getHostStatus(node.hostname())));
        }
        Set<ServiceCluster> serviceClusters = new HashSet<>();
        serviceClusters.add(new ServiceCluster(new ClusterId(app.getValue().clusterContexts().get(0).cluster().id().value()), new ServiceType("serviceType"), serviceInstances));
        TenantId tenantId = new TenantId(app.getKey().tenant().value());
        ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(app.getKey().application().value());
        status.put(new ApplicationInstanceReference(tenantId, applicationInstanceId), new ApplicationInstance(tenantId, applicationInstanceId, serviceClusters));
    }
    return status;
}
Also used : HashMap(java.util.HashMap) ServiceCluster(com.yahoo.vespa.applicationmodel.ServiceCluster) ClusterId(com.yahoo.vespa.applicationmodel.ClusterId) Node(com.yahoo.vespa.hosted.provision.Node) ServiceInstance(com.yahoo.vespa.applicationmodel.ServiceInstance) ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) ServiceType(com.yahoo.vespa.applicationmodel.ServiceType) ApplicationInstanceReference(com.yahoo.vespa.applicationmodel.ApplicationInstanceReference) ConfigId(com.yahoo.vespa.applicationmodel.ConfigId) ApplicationId(com.yahoo.config.provision.ApplicationId) HashMap(java.util.HashMap) Map(java.util.Map) HostName(com.yahoo.vespa.applicationmodel.HostName) HashSet(java.util.HashSet)

Example 5 with ApplicationInstanceId

use of com.yahoo.vespa.applicationmodel.ApplicationInstanceId in project vespa by vespa-engine.

the class NodeGroupTest method testBasics.

@Test
public void testBasics() {
    ApplicationInstance applicationInstance = new ApplicationInstance(new TenantId("tenant"), new ApplicationInstanceId("application-instance"), new HashSet<>());
    HostName hostName1 = new HostName("host1");
    HostName hostName2 = new HostName("host2");
    HostName hostName3 = new HostName("host3");
    NodeGroup nodeGroup = new NodeGroup(applicationInstance, hostName1, hostName3);
    nodeGroup.addNode(hostName2);
    // hostnames are sorted (for no good reason other than testability due to stability, readability)
    assertEquals(Arrays.asList(hostName1, hostName2, hostName3), nodeGroup.getHostNames());
    assertEquals("host1,host2,host3", nodeGroup.toCommaSeparatedString());
}
Also used : ApplicationInstanceId(com.yahoo.vespa.applicationmodel.ApplicationInstanceId) TenantId(com.yahoo.vespa.applicationmodel.TenantId) ApplicationInstance(com.yahoo.vespa.applicationmodel.ApplicationInstance) HostName(com.yahoo.vespa.applicationmodel.HostName) Test(org.junit.Test)

Aggregations

ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)5 TenantId (com.yahoo.vespa.applicationmodel.TenantId)5 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)4 HostName (com.yahoo.vespa.applicationmodel.HostName)4 ApplicationInstance (com.yahoo.vespa.applicationmodel.ApplicationInstance)3 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)3 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)3 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)3 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)3 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)3 Test (org.junit.Test)3 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Node (com.yahoo.vespa.hosted.provision.Node)1 Host (com.yahoo.vespa.orchestrator.Host)1 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)1 OrchestratorConfig (com.yahoo.vespa.orchestrator.config.OrchestratorConfig)1 ClusterControllerClientFactory (com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory)1 GetHostResponse (com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse)1 InMemoryStatusService (com.yahoo.vespa.orchestrator.status.InMemoryStatusService)1 ReadOnlyStatusRegistry (com.yahoo.vespa.orchestrator.status.ReadOnlyStatusRegistry)1