Search in sources :

Example 1 with ZoneList

use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneList in project vespa by vespa-engine.

the class ConfigServerRestExecutorImpl method createDiscoveryResponse.

private ProxyResponse createDiscoveryResponse(ProxyRequest proxyRequest) {
    ObjectMapper mapper = new ObjectMapper();
    DiscoveryResponseStructure responseStructure = new DiscoveryResponseStructure();
    String environmentName = proxyRequest.getEnvironment();
    ZoneList zones = zoneRegistry.zones().all();
    if (!environmentName.isEmpty())
        zones = zones.in(Environment.from(environmentName));
    for (ZoneId zoneId : zones.ids()) {
        responseStructure.uris.add(proxyRequest.getScheme() + "://" + proxyRequest.getControllerPrefix() + zoneId.environment().name() + "/" + zoneId.region().value());
    }
    JsonNode node = mapper.valueToTree(responseStructure);
    return new ProxyResponse(proxyRequest, node.toString(), 200, Optional.empty(), "application/json");
}
Also used : ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ZoneList(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneList)

Example 2 with ZoneList

use of com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneList in project vespa by vespa-engine.

the class ZoneApiHandler method root.

private HttpResponse root(HttpRequest request) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor uris = root.setArray("uris");
    ZoneList zoneList = zoneRegistry.zones().controllerManaged();
    zoneList.ids().forEach(zoneId -> uris.addString(request.getUri().resolve("/zone/v2/").resolve(zoneId.environment().value() + "/").resolve(zoneId.region().value()).toString()));
    Cursor zones = root.setArray("zones");
    zoneList.ids().forEach(zoneId -> {
        Cursor object = zones.addObject();
        object.setString("environment", zoneId.environment().value());
        object.setString("region", zoneId.region().value());
    });
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) ZoneList(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneList)

Aggregations

ZoneList (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Cursor (com.yahoo.slime.Cursor)1 Slime (com.yahoo.slime.Slime)1 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)1 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)1