Search in sources :

Example 1 with Host

use of com.yahoo.vespa.orchestrator.Host 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 Host

use of com.yahoo.vespa.orchestrator.Host in project vespa by vespa-engine.

the class HostResource method getHost.

@Override
public GetHostResponse getHost(String hostNameString) {
    HostName hostName = new HostName(hostNameString);
    try {
        Host host = orchestrator.getHost(hostName);
        URI applicationUri = uriInfo.getBaseUriBuilder().path(InstanceResource.class).path(host.getApplicationInstanceReference().asString()).build();
        List<HostService> hostServices = host.getServiceInstances().stream().map(serviceInstance -> new HostService(serviceInstance.getServiceCluster().clusterId().s(), serviceInstance.getServiceCluster().serviceType().s(), serviceInstance.configId().s(), serviceInstance.serviceStatus().name())).collect(Collectors.toList());
        return new GetHostResponse(host.getHostName().s(), host.getHostStatus().name(), applicationUri.toString(), hostServices);
    } catch (HostNameNotFoundException e) {
        log.log(LogLevel.INFO, "Host not found: " + hostName);
        throw new NotFoundException(e);
    }
}
Also used : OrchestrationException(com.yahoo.vespa.orchestrator.OrchestrationException) PatchHostRequest(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostRequest) Path(javax.ws.rs.Path) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) Inject(javax.inject.Inject) GetHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse) MediaType(javax.ws.rs.core.MediaType) HostName(com.yahoo.vespa.applicationmodel.HostName) HostStateChangeDeniedException(com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException) HostStateChangeDenialReason(com.yahoo.vespa.orchestrator.restapi.wire.HostStateChangeDenialReason) Component(com.yahoo.container.jaxrs.annotation.Component) LogLevel(com.yahoo.log.LogLevel) Host(com.yahoo.vespa.orchestrator.Host) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) UpdateHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.UpdateHostResponse) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) Context(javax.ws.rs.core.Context) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) Response(javax.ws.rs.core.Response) HostService(com.yahoo.vespa.orchestrator.restapi.wire.HostService) WebApplicationException(javax.ws.rs.WebApplicationException) HostStatus(com.yahoo.vespa.orchestrator.status.HostStatus) UriInfo(javax.ws.rs.core.UriInfo) PatchHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse) HostApi(com.yahoo.vespa.orchestrator.restapi.HostApi) HostService(com.yahoo.vespa.orchestrator.restapi.wire.HostService) GetHostResponse(com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) Host(com.yahoo.vespa.orchestrator.Host) URI(java.net.URI) HostName(com.yahoo.vespa.applicationmodel.HostName) HostNameNotFoundException(com.yahoo.vespa.orchestrator.HostNameNotFoundException)

Aggregations

HostName (com.yahoo.vespa.applicationmodel.HostName)2 Host (com.yahoo.vespa.orchestrator.Host)2 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)2 GetHostResponse (com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse)2 URI (java.net.URI)2 Component (com.yahoo.container.jaxrs.annotation.Component)1 LogLevel (com.yahoo.log.LogLevel)1 ApplicationInstanceId (com.yahoo.vespa.applicationmodel.ApplicationInstanceId)1 ApplicationInstanceReference (com.yahoo.vespa.applicationmodel.ApplicationInstanceReference)1 ClusterId (com.yahoo.vespa.applicationmodel.ClusterId)1 ConfigId (com.yahoo.vespa.applicationmodel.ConfigId)1 ServiceCluster (com.yahoo.vespa.applicationmodel.ServiceCluster)1 ServiceInstance (com.yahoo.vespa.applicationmodel.ServiceInstance)1 ServiceType (com.yahoo.vespa.applicationmodel.ServiceType)1 TenantId (com.yahoo.vespa.applicationmodel.TenantId)1 HostNameNotFoundException (com.yahoo.vespa.orchestrator.HostNameNotFoundException)1 OrchestrationException (com.yahoo.vespa.orchestrator.OrchestrationException)1 HostStateChangeDeniedException (com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException)1 HostApi (com.yahoo.vespa.orchestrator.restapi.HostApi)1 HostService (com.yahoo.vespa.orchestrator.restapi.wire.HostService)1