Search in sources :

Example 1 with EndpointStatus

use of com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus in project vespa by vespa-engine.

the class ControllerTest method testGlobalRotations.

@Test
public void testGlobalRotations() throws IOException {
    // Setup tester and app def
    ControllerTester tester = new ControllerTester();
    ZoneId zone = ZoneId.from(Environment.defaultEnvironment(), RegionName.defaultName());
    ApplicationId appId = ApplicationId.from("tenant", "app1", "default");
    DeploymentId deployId = new DeploymentId(appId, zone);
    // Check initial rotation status
    Map<String, EndpointStatus> rotationStatus = tester.controller().applications().getGlobalRotationStatus(deployId);
    assertEquals(1, rotationStatus.size());
    assertTrue(rotationStatus.get("qrs-endpoint").getStatus().equals(EndpointStatus.Status.in));
    // Set the global rotations out of service
    EndpointStatus status = new EndpointStatus(EndpointStatus.Status.out, "Testing I said", "Test", tester.clock().instant().getEpochSecond());
    List<String> overrides = tester.controller().applications().setGlobalRotationStatus(deployId, status);
    assertEquals(1, overrides.size());
    // Recheck the override rotation status
    rotationStatus = tester.controller().applications().getGlobalRotationStatus(deployId);
    assertEquals(1, rotationStatus.size());
    assertTrue(rotationStatus.get("qrs-endpoint").getStatus().equals(EndpointStatus.Status.out));
    assertTrue(rotationStatus.get("qrs-endpoint").getReason().equals("Testing I said"));
}
Also used : EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ApplicationId(com.yahoo.config.provision.ApplicationId) JobType.stagingTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest) JobType.systemTest(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest) Test(org.junit.Test)

Example 2 with EndpointStatus

use of com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus 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 3 with EndpointStatus

use of com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus in project vespa by vespa-engine.

the class ApplicationApiHandler method getGlobalRotationOverride.

private HttpResponse getGlobalRotationOverride(String tenantName, String applicationName, String instanceName, String environment, String region) {
    DeploymentId deploymentId = new DeploymentId(ApplicationId.from(tenantName, applicationName, instanceName), ZoneId.from(environment, region));
    Slime slime = new Slime();
    Cursor c1 = slime.setObject().setArray("globalrotationoverride");
    try {
        Map<String, EndpointStatus> rotations = controller.applications().getGlobalRotationStatus(deploymentId);
        for (String rotation : rotations.keySet()) {
            EndpointStatus currentStatus = rotations.get(rotation);
            c1.addString(rotation);
            Cursor c2 = c1.addObject();
            c2.setString("status", currentStatus.getStatus().name());
            c2.setString("reason", currentStatus.getReason() == null ? "" : currentStatus.getReason());
            c2.setString("agent", currentStatus.getAgent() == null ? "" : currentStatus.getAgent());
            c2.setLong("timestamp", currentStatus.getEpoch());
        }
    } catch (IOException e) {
        return ErrorResponse.internalServerError("Unable to get rotation status: " + e.getMessage());
    }
    return new SlimeJsonResponse(slime);
}
Also used : EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) IOException(java.io.IOException) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor)

Example 4 with EndpointStatus

use of com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus in project vespa by vespa-engine.

the class ApplicationController method getGlobalRotationStatus.

/**
 * Get the endpoint status for the global endpoint of this application
 *
 * @return Map between the endpoint and the rotation status
 * @throws IOException if global rotation status cannot be determined
 */
public Map<String, EndpointStatus> getGlobalRotationStatus(DeploymentId deploymentId) throws IOException {
    Map<String, EndpointStatus> result = new HashMap<>();
    Optional<String> endpoint = getCanonicalGlobalEndpoint(deploymentId);
    if (endpoint.isPresent()) {
        EndpointStatus status = configServer.getGlobalRotationStatus(deploymentId, endpoint.get());
        result.put(endpoint.get(), status);
    }
    return result;
}
Also used : EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) HashMap(java.util.HashMap)

Aggregations

EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)4 DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)3 IOException (java.io.IOException)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Cursor (com.yahoo.slime.Cursor)1 Inspector (com.yahoo.slime.Inspector)1 Slime (com.yahoo.slime.Slime)1 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)1 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)1 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)1 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)1 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)1 MessageResponse (com.yahoo.vespa.hosted.controller.restapi.MessageResponse)1 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1