Search in sources :

Example 1 with MessageResponse

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

the class ApplicationApiHandler method setGlobalRotationOverride.

private HttpResponse setGlobalRotationOverride(String tenantName, String applicationName, String instanceName, String environment, String region, boolean inService, HttpRequest request) {
    // Check if request is authorized
    Optional<Tenant> existingTenant = controller.tenants().tenant(new TenantId(tenantName));
    if (!existingTenant.isPresent())
        return ErrorResponse.notFoundError("Tenant '" + tenantName + "' does not exist");
    // Decode payload (reason) and construct parameter to the configserver
    Inspector requestData = toSlime(request.getData()).get();
    String reason = mandatory("reason", requestData).asString();
    String agent = getUserPrincipal(request).getIdentity().getFullName();
    long timestamp = controller.clock().instant().getEpochSecond();
    EndpointStatus.Status status = inService ? EndpointStatus.Status.in : EndpointStatus.Status.out;
    EndpointStatus endPointStatus = new EndpointStatus(status, reason, agent, timestamp);
    // DeploymentId identifies the zone and application we are dealing with
    DeploymentId deploymentId = new DeploymentId(ApplicationId.from(tenantName, applicationName, instanceName), ZoneId.from(environment, region));
    try {
        List<String> rotations = controller.applications().setGlobalRotationStatus(deploymentId, endPointStatus);
        return new MessageResponse(String.format("Rotations %s successfully set to %s service", rotations.toString(), inService ? "in" : "out of"));
    } catch (IOException e) {
        return ErrorResponse.internalServerError("Unable to alter rotation status: " + e.getMessage());
    }
}
Also used : EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) MessageResponse(com.yahoo.vespa.hosted.controller.restapi.MessageResponse) Inspector(com.yahoo.slime.Inspector) IOException(java.io.IOException)

Example 2 with MessageResponse

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

the class ApplicationApiHandler method cancelDeploy.

/**
 * Cancel any ongoing change for given application
 */
// TODO Consider move to API for maintenance related operations
private HttpResponse cancelDeploy(String tenantName, String applicationName) {
    ApplicationId id = ApplicationId.from(tenantName, applicationName, "default");
    Application application = controller.applications().require(id);
    Change change = application.change();
    if (!change.isPresent())
        return new MessageResponse("No deployment in progress for " + application + " at this time");
    controller.applications().lockOrThrow(id, lockedApplication -> controller.applications().deploymentTrigger().cancelChange(id, false));
    return new MessageResponse("Cancelled " + change + " for " + application);
}
Also used : MessageResponse(com.yahoo.vespa.hosted.controller.restapi.MessageResponse) Change(com.yahoo.vespa.hosted.controller.application.Change) ApplicationId(com.yahoo.config.provision.ApplicationId) Application(com.yahoo.vespa.hosted.controller.Application)

Aggregations

MessageResponse (com.yahoo.vespa.hosted.controller.restapi.MessageResponse)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Inspector (com.yahoo.slime.Inspector)1 Application (com.yahoo.vespa.hosted.controller.Application)1 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)1 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)1 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)1 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)1 Change (com.yahoo.vespa.hosted.controller.application.Change)1 IOException (java.io.IOException)1