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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations