use of com.yahoo.vespa.serviceview.bindings.ClusterView 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;
}
use of com.yahoo.vespa.serviceview.bindings.ClusterView 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));
}
use of com.yahoo.vespa.serviceview.bindings.ClusterView 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);
}
}
}
use of com.yahoo.vespa.serviceview.bindings.ClusterView 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;
}
use of com.yahoo.vespa.serviceview.bindings.ClusterView in project vespa by vespa-engine.
the class ServiceModel method showAllClusters.
/**
* The top level view of a given application.
*
* @return a top level view of the entire application in a form suitable for
* consumption by a REST API
*/
public ApplicationView showAllClusters(String uriBase, String applicationIdentifier) {
ApplicationView response = new ApplicationView();
List<ClusterView> clusterViews = new ArrayList<>();
for (Cluster c : clusters) {
clusterViews.add(showCluster(c, uriBase, applicationIdentifier));
}
response.clusters = clusterViews;
return response;
}
Aggregations