Search in sources :

Example 1 with ServiceView

use of com.yahoo.vespa.serviceview.bindings.ServiceView in project vespa by vespa-engine.

the class ServiceModelTest method test.

@Test
public final void test() {
    final String uriBase = "http://configserver:5000/";
    ApplicationView x = model.showAllClusters(uriBase, "/tenant/default/application/default");
    assertEquals(2, x.clusters.size());
    String urlTracking = null;
    for (com.yahoo.vespa.serviceview.bindings.ClusterView c : x.clusters) {
        for (ServiceView s : c.services) {
            if ("examplename".equals(s.serviceName)) {
                assertEquals("something", s.serviceType);
                urlTracking = s.url;
                break;
            }
        }
    }
    assertNotNull(urlTracking);
    final String serviceIdentifier = urlTracking.substring(urlTracking.indexOf("something"), urlTracking.length() - "/state/v1/".length());
    Service y = model.getService(serviceIdentifier);
    assertEquals("examplename", y.name);
}
Also used : ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) HostService(com.yahoo.vespa.serviceview.bindings.HostService) Test(org.junit.Test)

Example 2 with ServiceView

use of com.yahoo.vespa.serviceview.bindings.ServiceView in project vespa by vespa-engine.

the class ConfigServerClientMock method getApplicationView.

// Returns a canned example response
@Override
public ApplicationView getApplicationView(String tenantName, String applicationName, String instanceName, String environment, String region) {
    ApplicationView applicationView = new ApplicationView();
    ClusterView cluster = new ClusterView();
    cluster.name = "cluster1";
    cluster.type = "content";
    cluster.url = "http://localhost:8080/application/v4/tenant/tenant1/application/application1/environment/prod/region/us-west-1/instance/default/service/container-clustercontroller-6s8slgtps7ry8uh6lx21ejjiv/cluster/v2/cluster1";
    ServiceView service = new ServiceView();
    service.configId = "cluster1/storage/0";
    service.host = "host1";
    service.serviceName = "storagenode";
    service.serviceType = "storagenode";
    service.url = "http://localhost:8080/application/v4/tenant/tenant1/application/application1/environment/prod/region/us-west-1/instance/default/service/storagenode-awe3slno6mmq2fye191y324jl/state/v1/";
    cluster.services = new ArrayList<>();
    cluster.services.add(service);
    applicationView.clusters = new ArrayList<>();
    applicationView.clusters.add(cluster);
    return applicationView;
}
Also used : ClusterView(com.yahoo.vespa.serviceview.bindings.ClusterView) ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView)

Example 3 with ServiceView

use of com.yahoo.vespa.serviceview.bindings.ServiceView in project vespa by vespa-engine.

the class ServiceApiResponseTest method testServiceViewResponse.

@Test
public void testServiceViewResponse() throws URISyntaxException, IOException {
    ServiceApiResponse response = new ServiceApiResponse(ZoneId.from(Environment.prod, RegionName.from("us-west-1")), ApplicationId.from("tenant1", "application1", "default"), Collections.singletonList(new URI("config-server1")), new URI("http://server1:4080/request/path?foo=bar"));
    ApplicationView applicationView = new ApplicationView();
    ClusterView clusterView = new ClusterView();
    clusterView.type = "container";
    clusterView.name = "cluster1";
    clusterView.url = "cluster-url";
    ServiceView serviceView = new ServiceView();
    serviceView.url = null;
    serviceView.serviceType = "container";
    serviceView.serviceName = "service1";
    serviceView.configId = "configId1";
    serviceView.host = "host1";
    serviceView.legacyStatusPages = "legacyPages";
    clusterView.services = Collections.singletonList(serviceView);
    applicationView.clusters = Collections.singletonList(clusterView);
    response.setResponse(applicationView);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    response.render(stream);
    Slime responseSlime = SlimeUtils.jsonToSlime(stream.toByteArray());
    Slime expectedSlime = SlimeUtils.jsonToSlime(IOUtils.readFile(new File(responseFiles + "service-api-response.json")).getBytes(StandardCharsets.UTF_8));
    assertEquals("service-api-response.json", new String(SlimeUtils.toJsonBytes(expectedSlime), StandardCharsets.UTF_8), new String(SlimeUtils.toJsonBytes(responseSlime), StandardCharsets.UTF_8));
}
Also used : ClusterView(com.yahoo.vespa.serviceview.bindings.ClusterView) ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Slime(com.yahoo.slime.Slime) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 4 with ServiceView

use of com.yahoo.vespa.serviceview.bindings.ServiceView in project vespa by vespa-engine.

the class ServiceApiResponse method setResponse.

public void setResponse(ApplicationView applicationView) {
    Cursor clustersArray = slime.setObject().setArray("clusters");
    for (ClusterView clusterView : applicationView.clusters) {
        Cursor clusterObject = clustersArray.addObject();
        clusterObject.setString("name", clusterView.name);
        clusterObject.setString("type", clusterView.type);
        setNullableString("url", rewriteIfUrl(clusterView.url, requestUri), clusterObject);
        Cursor servicesArray = clusterObject.setArray("services");
        for (ServiceView serviceView : clusterView.services) {
            Cursor serviceObject = servicesArray.addObject();
            setNullableString("url", rewriteIfUrl(serviceView.url, requestUri), serviceObject);
            serviceObject.setString("serviceType", serviceView.serviceType);
            serviceObject.setString("serviceName", serviceView.serviceName);
            serviceObject.setString("configId", serviceView.configId);
            serviceObject.setString("host", serviceView.host);
        }
    }
}
Also used : ClusterView(com.yahoo.vespa.serviceview.bindings.ClusterView) ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) Cursor(com.yahoo.slime.Cursor)

Example 5 with ServiceView

use of com.yahoo.vespa.serviceview.bindings.ServiceView in project vespa by vespa-engine.

the class ServiceModel method showCluster.

private ClusterView showCluster(Cluster c, String uriBase, String applicationIdentifier) {
    List<ServiceView> services = new ArrayList<>();
    for (Service s : c.services) {
        ServiceView service = new ServiceView();
        StringBuilder buffer = getLinkBuilder(uriBase).append(applicationIdentifier).append('/');
        service.url = buffer.append("service/").append(s.getIdentifier(s.statePort)).append("/state/v1/").toString();
        service.serviceType = s.serviceType;
        service.serviceName = s.name;
        service.configId = s.configId;
        service.host = s.host;
        addLegacyLink(uriBase, applicationIdentifier, s, service);
        services.add(service);
    }
    ClusterView v = new ClusterView();
    v.services = services;
    v.name = c.name;
    v.type = c.type;
    if (CONTENT_CLUSTER_TYPENAME.equals(c.type)) {
        Service s = getFirstClusterController();
        StringBuilder buffer = getLinkBuilder(uriBase).append(applicationIdentifier).append('/');
        buffer.append("service/").append(s.getIdentifier(s.statePort)).append("/cluster/v2/").append(c.name);
        v.url = buffer.toString();
    } else {
        v.url = null;
    }
    return v;
}
Also used : ClusterView(com.yahoo.vespa.serviceview.bindings.ClusterView) ServiceView(com.yahoo.vespa.serviceview.bindings.ServiceView) ArrayList(java.util.ArrayList) HostService(com.yahoo.vespa.serviceview.bindings.HostService)

Aggregations

ServiceView (com.yahoo.vespa.serviceview.bindings.ServiceView)7 ClusterView (com.yahoo.vespa.serviceview.bindings.ClusterView)6 ApplicationView (com.yahoo.vespa.serviceview.bindings.ApplicationView)5 Slime (com.yahoo.slime.Slime)3 URI (java.net.URI)3 Test (org.junit.Test)3 Cursor (com.yahoo.slime.Cursor)2 HostService (com.yahoo.vespa.serviceview.bindings.HostService)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 JsonFormat (com.yahoo.slime.JsonFormat)1 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)1 Uri (com.yahoo.vespa.hosted.controller.restapi.Uri)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1