Search in sources :

Example 96 with Cursor

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

the class DeploymentApiHandler method root.

private HttpResponse root(HttpRequest request) {
    Slime slime = new Slime();
    Cursor root = slime.setObject();
    Cursor platformArray = root.setArray("versions");
    for (VespaVersion version : controller.versionStatus().versions()) {
        Cursor versionObject = platformArray.addObject();
        versionObject.setString("version", version.versionNumber().toString());
        versionObject.setString("confidence", version.confidence().name());
        versionObject.setString("commit", version.releaseCommit());
        versionObject.setLong("date", version.committedAt().toEpochMilli());
        versionObject.setBool("controllerVersion", version.isSelfVersion());
        versionObject.setBool("systemVersion", version.isCurrentSystemVersion());
        Cursor configServerArray = versionObject.setArray("configServers");
        for (String configServerHostnames : version.configServerHostnames()) {
            Cursor configServerObject = configServerArray.addObject();
            configServerObject.setString("hostname", configServerHostnames);
        }
        Cursor failingArray = versionObject.setArray("failingApplications");
        for (ApplicationId id : version.statistics().failing()) {
            controller.applications().get(id).ifPresent(application -> {
                firstFailingOn(version.versionNumber(), application).ifPresent(firstFailing -> {
                    Cursor applicationObject = failingArray.addObject();
                    toSlime(applicationObject, application, request);
                    applicationObject.setString("failing", firstFailing.type().jobName());
                });
            });
        }
        Cursor productionArray = versionObject.setArray("productionApplications");
        for (ApplicationId id : version.statistics().production()) {
            controller.applications().get(id).ifPresent(application -> {
                int successes = productionSuccessesFor(version.versionNumber(), application);
                // Just upgraded to a newer version.
                if (successes == 0)
                    return;
                Cursor applicationObject = productionArray.addObject();
                toSlime(applicationObject, application, request);
                applicationObject.setLong("productionJobs", productionJobsFor(application));
                applicationObject.setLong("productionSuccesses", productionSuccessesFor(version.versionNumber(), application));
            });
        }
        Cursor runningArray = versionObject.setArray("deployingApplications");
        for (ApplicationId id : version.statistics().deploying()) {
            controller.applications().get(id).ifPresent(application -> {
                lastDeployingTo(version.versionNumber(), application).ifPresent(lastDeploying -> {
                    Cursor applicationObject = runningArray.addObject();
                    toSlime(applicationObject, application, request);
                    applicationObject.setString("running", lastDeploying.type().jobName());
                });
            });
        }
    }
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) VespaVersion(com.yahoo.vespa.hosted.controller.versions.VespaVersion) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 97 with Cursor

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

the class ScrewdriverApiHandler method trigger.

private HttpResponse trigger(HttpRequest request, String tenantName, String applicationName) {
    JobType jobType = Optional.of(asString(request.getData())).filter(s -> !s.isEmpty()).map(JobType::fromJobName).orElse(JobType.component);
    ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, "default");
    controller.applications().lockOrThrow(applicationId, application -> {
        // Since this is a manual operation we likely want it to trigger as soon as possible so we add it at to the
        // front of the queue
        application = controller.applications().deploymentTrigger().trigger(new DeploymentTrigger.Triggering(application, jobType, true, "Triggered from screwdriver/v1"), Collections.emptySet(), true);
        controller.applications().store(application);
    });
    Slime slime = new Slime();
    Cursor cursor = slime.setObject();
    cursor.setString("message", "Triggered " + jobType.jobName() + " for " + applicationId);
    return new SlimeJsonResponse(slime);
}
Also used : JobType(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ApplicationId(com.yahoo.config.provision.ApplicationId) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 98 with Cursor

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

the class ScrewdriverApiHandler method vespaVersion.

private HttpResponse vespaVersion() {
    VespaVersion version = controller.versionStatus().version(controller.systemVersion());
    if (version == null)
        return ErrorResponse.notFoundError("Information about the current system version is not available at this time");
    Slime slime = new Slime();
    Cursor cursor = slime.setObject();
    cursor.setString("version", version.versionNumber().toString());
    cursor.setString("sha", version.releaseCommit());
    cursor.setLong("date", version.committedAt().toEpochMilli());
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) VespaVersion(com.yahoo.vespa.hosted.controller.versions.VespaVersion) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 99 with Cursor

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

the class ScrewdriverApiHandler method buildJobs.

private HttpResponse buildJobs(List<BuildJob> buildJobs) {
    Slime slime = new Slime();
    Cursor buildJobArray = slime.setArray();
    for (BuildJob buildJob : buildJobs) {
        Cursor buildJobObject = buildJobArray.addObject();
        buildJobObject.setLong("projectId", buildJob.projectId());
        buildJobObject.setString("jobName", buildJob.jobName());
    }
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) BuildJob(com.yahoo.vespa.hosted.controller.api.integration.BuildService.BuildJob) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 100 with Cursor

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

the class ZoneApiHandler method environment.

private HttpResponse environment(HttpRequest request, Environment environment) {
    List<ZoneId> zones = zoneRegistry.zones().all().in(environment).ids();
    Slime slime = new Slime();
    Cursor root = slime.setArray();
    zones.forEach(zone -> {
        Cursor object = root.addObject();
        object.setString("name", zone.region().value());
        object.setString("url", request.getUri().resolve("/zone/v2/environment/").resolve(environment.value() + "/").resolve("region/").resolve(zone.region().value()).toString());
    });
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) 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