Search in sources :

Example 16 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse 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 17 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse 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 18 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse 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 19 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse 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 20 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse 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)

Aggregations

SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)23 Slime (com.yahoo.slime.Slime)22 Cursor (com.yahoo.slime.Cursor)17 ApplicationId (com.yahoo.config.provision.ApplicationId)7 Application (com.yahoo.vespa.hosted.controller.Application)7 NotExistsException (com.yahoo.vespa.hosted.controller.NotExistsException)4 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)3 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)3 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)3 Environment (com.yahoo.config.provision.Environment)2 RegionName (com.yahoo.config.provision.RegionName)2 TenantName (com.yahoo.config.provision.TenantName)2 Inspector (com.yahoo.slime.Inspector)2 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)2 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)2 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)2 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)2 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)2 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)2 VespaVersion (com.yahoo.vespa.hosted.controller.versions.VespaVersion)2