Search in sources :

Example 91 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ApplicationApiHandler method properties.

private HttpResponse properties() {
    Slime slime = new Slime();
    Cursor response = slime.setObject();
    Cursor array = response.setArray("properties");
    for (Map.Entry<PropertyId, Property> entry : controller.fetchPropertyList().entrySet()) {
        Cursor propertyObject = array.addObject();
        propertyObject.setString("propertyid", entry.getKey().id());
        propertyObject.setString("property", entry.getValue().id());
    }
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Map(java.util.Map) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property) PropertyId(com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId)

Example 92 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ApplicationApiHandler method tenantInTenantsListToSlime.

// A tenant has different content when in a list ... antipattern, but not solvable before application/v5
private void tenantInTenantsListToSlime(Tenant tenant, URI requestURI, Cursor object) {
    object.setString("tenant", tenant.getId().id());
    Cursor metaData = object.setObject("metaData");
    metaData.setString("type", tenant.tenantType().name());
    tenant.getAthensDomain().ifPresent(a -> metaData.setString("athensDomain", a.getName()));
    tenant.getProperty().ifPresent(p -> metaData.setString("property", p.id()));
    object.setString("url", withPath("/application/v4/tenant/" + tenant.getId().id(), requestURI).toString());
}
Also used : Cursor(com.yahoo.slime.Cursor)

Example 93 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ApplicationApiHandler method applications.

private HttpResponse applications(String tenantName, HttpRequest request) {
    TenantName tenant = TenantName.from(tenantName);
    Slime slime = new Slime();
    Cursor array = slime.setArray();
    for (Application application : controller.applications().asList(tenant)) toSlime(application, array.addObject(), request);
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) TenantName(com.yahoo.config.provision.TenantName) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Application(com.yahoo.vespa.hosted.controller.Application)

Example 94 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class ApplicationApiHandler method toSlime.

public static void toSlime(DeploymentCost deploymentCost, Cursor object) {
    object.setLong("tco", (long) deploymentCost.getTco());
    object.setLong("waste", (long) deploymentCost.getWaste());
    object.setDouble("utilization", deploymentCost.getUtilization());
    Cursor clustersObject = object.setObject("cluster");
    for (Map.Entry<String, ClusterCost> clusterEntry : deploymentCost.getCluster().entrySet()) toSlime(clusterEntry.getValue(), clustersObject.setObject(clusterEntry.getKey()));
}
Also used : ClusterCost(com.yahoo.vespa.hosted.controller.application.ClusterCost) Cursor(com.yahoo.slime.Cursor) Map(java.util.Map)

Example 95 with Cursor

use of com.yahoo.slime.Cursor in project vespa by vespa-engine.

the class JobsResponse method render.

@Override
public void render(OutputStream stream) throws IOException {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor jobArray = root.setArray("jobs");
    for (String jobName : jobControl.jobs()) jobArray.addObject().setString("name", jobName);
    Cursor inactiveArray = root.setArray("inactive");
    for (String jobName : jobControl.inactiveJobs()) inactiveArray.addString(jobName);
    new JsonFormat(true).encode(stream, slime);
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Aggregations

Cursor (com.yahoo.slime.Cursor)112 Slime (com.yahoo.slime.Slime)79 Test (org.junit.Test)33 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 DefParser (com.yahoo.config.codegen.DefParser)15 InnerCNode (com.yahoo.config.codegen.InnerCNode)15 StringReader (java.io.StringReader)15 IOException (java.io.IOException)9 ApplicationId (com.yahoo.config.provision.ApplicationId)8 JsonFormat (com.yahoo.slime.JsonFormat)8 Application (com.yahoo.vespa.hosted.controller.Application)6 List (java.util.List)6 Map (java.util.Map)6 Inspector (com.yahoo.slime.Inspector)5 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)5 Ignore (org.junit.Ignore)5 Version (com.yahoo.component.Version)4 RegionName (com.yahoo.config.provision.RegionName)4 TenantName (com.yahoo.config.provision.TenantName)4