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