Search in sources :

Example 6 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse in project vespa by vespa-engine.

the class ApplicationApiHandler method deploy.

private HttpResponse deploy(String tenantName, String applicationName, String instanceName, String environment, String region, HttpRequest request) {
    ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, instanceName);
    ZoneId zone = ZoneId.from(environment, region);
    Map<String, byte[]> dataParts = new MultipartParser().parse(request);
    if (!dataParts.containsKey("deployOptions"))
        return ErrorResponse.badRequest("Missing required form part 'deployOptions'");
    Inspector deployOptions = SlimeUtils.jsonToSlime(dataParts.get("deployOptions")).get();
    Optional<ApplicationPackage> applicationPackage = Optional.ofNullable(dataParts.get("applicationZip")).map(ApplicationPackage::new);
    verifyApplicationIdentityConfiguration(tenantName, applicationPackage);
    // TODO: get rid of the json object
    DeployOptions deployOptionsJsonClass = new DeployOptions(screwdriverBuildJobFromSlime(deployOptions.field("screwdriverBuildJob")), optional("vespaVersion", deployOptions).map(Version::new), deployOptions.field("ignoreValidationErrors").asBool(), deployOptions.field("deployCurrentVersion").asBool());
    ActivateResult result = controller.applications().deployApplication(applicationId, zone, applicationPackage, deployOptionsJsonClass);
    return new SlimeJsonResponse(toSlime(result));
}
Also used : DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) Inspector(com.yahoo.slime.Inspector) ApplicationId(com.yahoo.config.provision.ApplicationId) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage)

Example 7 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse in project vespa by vespa-engine.

the class ZoneApiHandler method root.

private HttpResponse root(HttpRequest request) {
    List<Environment> environments = zoneRegistry.zones().all().ids().stream().map(ZoneId::environment).distinct().sorted(Comparator.comparing(Environment::value)).collect(Collectors.toList());
    Slime slime = new Slime();
    Cursor root = slime.setArray();
    environments.forEach(environment -> {
        Cursor object = root.addObject();
        object.setString("name", environment.value());
        // Returning /zone/v2 is a bit strange, but that's what the original Jersey implementation did
        object.setString("url", request.getUri().resolve("/zone/v2/environment/").resolve(environment.value()).toString());
    });
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Environment(com.yahoo.config.provision.Environment) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 8 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse in project vespa by vespa-engine.

the class ApplicationApiHandler method rotationStatus.

private HttpResponse rotationStatus(String tenantName, String applicationName, String instanceName, String environment, String region) {
    ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, instanceName);
    Application application = controller.applications().require(applicationId);
    if (!application.rotation().isPresent()) {
        throw new NotExistsException("global rotation does not exist for '" + environment + "." + region + "'");
    }
    Slime slime = new Slime();
    Cursor response = slime.setObject();
    Map<String, RotationStatus> rotationHealthStatus = controller.getHealthStatus(application.rotation().get().dnsName());
    for (String rotationEndpoint : rotationHealthStatus.keySet()) {
        if (rotationEndpoint.contains(toDns(environment)) && rotationEndpoint.contains(toDns(region))) {
            Cursor bcpStatusObject = response.setObject("bcpStatus");
            bcpStatusObject.setString("rotationStatus", rotationHealthStatus.getOrDefault(rotationEndpoint, RotationStatus.UNKNOWN).name());
        }
    }
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) NotExistsException(com.yahoo.vespa.hosted.controller.NotExistsException) ApplicationId(com.yahoo.config.provision.ApplicationId) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) RotationStatus(com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus) Application(com.yahoo.vespa.hosted.controller.Application)

Example 9 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse in project vespa by vespa-engine.

the class ApplicationApiHandler method createApplication.

private HttpResponse createApplication(String tenantName, String applicationName, HttpRequest request) {
    Application application;
    try {
        application = controller.applications().createApplication(ApplicationId.from(tenantName, applicationName, "default"), getUserPrincipal(request).getNToken());
    } catch (ZmsException e) {
        // TODO: Push conversion down
        if (e.getCode() == com.yahoo.jdisc.Response.Status.FORBIDDEN)
            throw new ForbiddenException("Not authorized to create application", e);
        else
            throw e;
    }
    Slime slime = new Slime();
    toSlime(application, slime.setObject(), request);
    return new SlimeJsonResponse(slime);
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException) Slime(com.yahoo.slime.Slime) Application(com.yahoo.vespa.hosted.controller.Application)

Example 10 with SlimeJsonResponse

use of com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse in project vespa by vespa-engine.

the class ApplicationApiHandler method tenantPipelines.

/**
 * Lists the screwdriver project id for each application
 */
private HttpResponse tenantPipelines() {
    Slime slime = new Slime();
    Cursor response = slime.setObject();
    Cursor pipelinesArray = response.setArray("tenantPipelines");
    for (Application application : controller.applications().asList()) {
        if (!application.deploymentJobs().projectId().isPresent())
            continue;
        Cursor pipelineObject = pipelinesArray.addObject();
        pipelineObject.setString("screwdriverId", String.valueOf(application.deploymentJobs().projectId().get()));
        pipelineObject.setString("tenant", application.id().tenant().value());
        pipelineObject.setString("application", application.id().application().value());
        pipelineObject.setString("instance", application.id().instance().value());
    }
    // not used but may need to be present
    response.setArray("brokenTenantPipelines");
    return new SlimeJsonResponse(slime);
}
Also used : SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Application(com.yahoo.vespa.hosted.controller.Application)

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