Search in sources :

Example 1 with DeploymentId

use of com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId 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 DeploymentId

use of com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId 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 DeploymentId

use of com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId in project vespa by vespa-engine.

the class ApplicationApiHandler method restart.

/**
 * Schedule restart of deployment, or specific host in a deployment
 */
private HttpResponse restart(String tenantName, String applicationName, String instanceName, String environment, String region, HttpRequest request) {
    DeploymentId deploymentId = new DeploymentId(ApplicationId.from(tenantName, applicationName, instanceName), ZoneId.from(environment, region));
    // TODO: Propagate all filters
    Optional<Hostname> hostname = Optional.ofNullable(request.getProperty("hostname")).map(Hostname::new);
    controller.applications().restart(deploymentId, hostname);
    // TODO: Change to return JSON
    return new StringResponse("Requested restart of " + path(TenantResource.API_PATH, tenantName, ApplicationResource.API_PATH, applicationName, EnvironmentResource.API_PATH, environment, "region", region, "instance", instanceName));
}
Also used : DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Hostname(com.yahoo.vespa.hosted.controller.api.identifiers.Hostname) StringResponse(com.yahoo.vespa.hosted.controller.restapi.StringResponse)

Example 4 with DeploymentId

use of com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId in project vespa by vespa-engine.

the class ApplicationApiHandler method deployment.

private HttpResponse deployment(String tenantName, String applicationName, String instanceName, String environment, String region, HttpRequest request) {
    ApplicationId id = ApplicationId.from(tenantName, applicationName, instanceName);
    Application application = controller.applications().get(id).orElseThrow(() -> new NotExistsException(id + " not found"));
    DeploymentId deploymentId = new DeploymentId(application.id(), ZoneId.from(environment, region));
    Deployment deployment = application.deployments().get(deploymentId.zoneId());
    if (deployment == null)
        throw new NotExistsException(application + " is not deployed in " + deploymentId.zoneId());
    Slime slime = new Slime();
    toSlime(slime.setObject(), deploymentId, deployment, request);
    return new SlimeJsonResponse(slime);
}
Also used : DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) NotExistsException(com.yahoo.vespa.hosted.controller.NotExistsException) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) ApplicationId(com.yahoo.config.provision.ApplicationId) Slime(com.yahoo.slime.Slime) Application(com.yahoo.vespa.hosted.controller.Application)

Example 5 with DeploymentId

use of com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId in project vespa by vespa-engine.

the class ApplicationApiHandler method toSlime.

private void toSlime(Cursor object, Application application, HttpRequest request) {
    object.setString("application", application.id().application().value());
    object.setString("instance", application.id().instance().value());
    // Currently deploying change
    if (application.change().isPresent()) {
        Cursor deployingObject = object.setObject("deploying");
        application.change().platform().ifPresent(v -> deployingObject.setString("version", v.toString()));
        application.change().application().filter(v -> v != ApplicationVersion.unknown).ifPresent(v -> toSlime(v, deployingObject.setObject("revision")));
    }
    // Jobs sorted according to deployment spec
    List<JobStatus> jobStatus = controller.applications().deploymentTrigger().deploymentOrder().sortBy(application.deploymentSpec(), application.deploymentJobs().jobStatus().values());
    Cursor deploymentsArray = object.setArray("deploymentJobs");
    for (JobStatus job : jobStatus) {
        Cursor jobObject = deploymentsArray.addObject();
        jobObject.setString("type", job.type().jobName());
        jobObject.setBool("success", job.isSuccess());
        job.lastTriggered().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("lastTriggered")));
        job.lastCompleted().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("lastCompleted")));
        job.firstFailing().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("firstFailing")));
        job.lastSuccess().ifPresent(jobRun -> toSlime(jobRun, jobObject.setObject("lastSuccess")));
    }
    // Change blockers
    Cursor changeBlockers = object.setArray("changeBlockers");
    application.deploymentSpec().changeBlocker().forEach(changeBlocker -> {
        Cursor changeBlockerObject = changeBlockers.addObject();
        changeBlockerObject.setBool("versions", changeBlocker.blocksVersions());
        changeBlockerObject.setBool("revisions", changeBlocker.blocksRevisions());
        changeBlockerObject.setString("timeZone", changeBlocker.window().zone().getId());
        Cursor days = changeBlockerObject.setArray("days");
        changeBlocker.window().days().stream().map(DayOfWeek::getValue).forEach(days::addLong);
        Cursor hours = changeBlockerObject.setArray("hours");
        changeBlocker.window().hours().forEach(hours::addLong);
    });
    // Compile version. The version that should be used when building an application
    object.setString("compileVersion", application.oldestDeployedVersion().orElse(controller.systemVersion()).toFullString());
    // Rotation
    Cursor globalRotationsArray = object.setArray("globalRotations");
    application.rotation().ifPresent(rotation -> {
        globalRotationsArray.addString(rotation.url().toString());
        globalRotationsArray.addString(rotation.secureUrl().toString());
        object.setString("rotationId", rotation.id().asString());
    });
    // Deployments sorted according to deployment spec
    List<Deployment> deployments = controller.applications().deploymentTrigger().deploymentOrder().sortBy(application.deploymentSpec().zones(), application.deployments().values());
    Cursor instancesArray = object.setArray("instances");
    for (Deployment deployment : deployments) {
        Cursor deploymentObject = instancesArray.addObject();
        deploymentObject.setString("environment", deployment.zone().environment().value());
        deploymentObject.setString("region", deployment.zone().region().value());
        // pointless
        deploymentObject.setString("instance", application.id().instance().value());
        if (application.rotation().isPresent()) {
            Map<String, RotationStatus> rotationHealthStatus = application.rotation().map(rotation -> controller.getHealthStatus(rotation.dnsName())).orElse(Collections.emptyMap());
            setRotationStatus(deployment, rotationHealthStatus, deploymentObject);
        }
        if (// List full deployment information when recursive.
        recurseOverDeployments(request))
            toSlime(deploymentObject, new DeploymentId(application.id(), deployment.zone()), deployment, request);
        else
            deploymentObject.setString("url", withPath(request.getUri().getPath() + "/environment/" + deployment.zone().environment().value() + "/region/" + deployment.zone().region().value() + "/instance/" + application.id().instance().value(), request.getUri()).toString());
    }
    // Metrics
    Cursor metricsObject = object.setObject("metrics");
    metricsObject.setDouble("queryServiceQuality", application.metrics().queryServiceQuality());
    metricsObject.setDouble("writeServiceQuality", application.metrics().writeServiceQuality());
    application.ownershipIssueId().ifPresent(issueId -> object.setString("ownershipIssueId", issueId.value()));
    application.deploymentJobs().issueId().ifPresent(issueId -> object.setString("deploymentIssueId", issueId.value()));
}
Also used : AlreadyExistsException(com.yahoo.vespa.hosted.controller.AlreadyExistsException) EndpointStatus(com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus) Inject(com.google.inject.Inject) URISyntaxException(java.net.URISyntaxException) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) Scanner(java.util.Scanner) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) ConfigServerException(com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException) RegionName(com.yahoo.config.provision.RegionName) TenantName(com.yahoo.config.provision.TenantName) ResourceResponse(com.yahoo.vespa.hosted.controller.restapi.ResourceResponse) Tenant(com.yahoo.vespa.hosted.controller.api.Tenant) ZoneId(com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId) ClusterUtilization(com.yahoo.vespa.hosted.controller.application.ClusterUtilization) Duration(java.time.Duration) Map(java.util.Map) LogLevel(com.yahoo.log.LogLevel) Path(com.yahoo.vespa.hosted.controller.restapi.Path) JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) GitRevision(com.yahoo.vespa.hosted.controller.api.application.v4.model.GitRevision) ClusterCost(com.yahoo.vespa.hosted.controller.application.ClusterCost) BadRequestException(javax.ws.rs.BadRequestException) DeployOptions(com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions) URI(java.net.URI) DeploymentCost(com.yahoo.vespa.hosted.controller.application.DeploymentCost) ScrewdriverBuildJob(com.yahoo.vespa.hosted.controller.api.application.v4.model.ScrewdriverBuildJob) Exceptions(com.yahoo.yolean.Exceptions) AthenzDomain(com.yahoo.vespa.athenz.api.AthenzDomain) ImmutableSet(com.google.common.collect.ImmutableSet) Inspector(com.yahoo.slime.Inspector) NotExistsException(com.yahoo.vespa.hosted.controller.NotExistsException) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ErrorResponse(com.yahoo.vespa.hosted.controller.restapi.ErrorResponse) RestartAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RestartAction) Property(com.yahoo.vespa.hosted.controller.api.identifiers.Property) ApplicationView(com.yahoo.vespa.serviceview.bindings.ApplicationView) Objects(java.util.Objects) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException) List(java.util.List) Principal(java.security.Principal) AthenzPrincipal(com.yahoo.vespa.athenz.api.AthenzPrincipal) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Optional(java.util.Optional) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Controller(com.yahoo.vespa.hosted.controller.Controller) Joiner(com.google.common.base.Joiner) Log(com.yahoo.vespa.hosted.controller.api.integration.configserver.Log) AthenzClientFactory(com.yahoo.vespa.hosted.controller.api.integration.athenz.AthenzClientFactory) GitRepository(com.yahoo.vespa.hosted.controller.api.identifiers.GitRepository) ApplicationName(com.yahoo.config.provision.ApplicationName) AthenzUser(com.yahoo.vespa.athenz.api.AthenzUser) Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) PropertyId(com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId) RefeedAction(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RefeedAction) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Slime(com.yahoo.slime.Slime) AthenzIdentity(com.yahoo.vespa.athenz.api.AthenzIdentity) IOUtils(com.yahoo.io.IOUtils) NToken(com.yahoo.vespa.athenz.api.NToken) Level(java.util.logging.Level) DeploymentMetrics(com.yahoo.vespa.hosted.controller.application.DeploymentMetrics) ApplicationResource(com.yahoo.vespa.hosted.controller.api.application.v4.ApplicationResource) SlimeUtils(com.yahoo.vespa.config.SlimeUtils) Change(com.yahoo.vespa.hosted.controller.application.Change) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) GitBranch(com.yahoo.vespa.hosted.controller.api.identifiers.GitBranch) ServiceInfo(com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ServiceInfo) SetBouncerPassthruHeaderFilter(com.yahoo.vespa.hosted.controller.restapi.filter.SetBouncerPassthruHeaderFilter) EnvironmentResource(com.yahoo.vespa.hosted.controller.api.application.v4.EnvironmentResource) TenantResource(com.yahoo.vespa.hosted.controller.api.application.v4.TenantResource) Application(com.yahoo.vespa.hosted.controller.Application) ActivateResult(com.yahoo.vespa.hosted.controller.api.ActivateResult) Cursor(com.yahoo.slime.Cursor) StringResponse(com.yahoo.vespa.hosted.controller.restapi.StringResponse) ForbiddenException(javax.ws.rs.ForbiddenException) Hostname(com.yahoo.vespa.hosted.controller.api.identifiers.Hostname) Environment(com.yahoo.config.provision.Environment) GitCommit(com.yahoo.vespa.hosted.controller.api.identifiers.GitCommit) HttpRequest(com.yahoo.container.jdisc.HttpRequest) SourceRevision(com.yahoo.vespa.hosted.controller.application.SourceRevision) IOException(java.io.IOException) MessageResponse(com.yahoo.vespa.hosted.controller.restapi.MessageResponse) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) LoggingRequestHandler(com.yahoo.container.jdisc.LoggingRequestHandler) User(com.yahoo.vespa.hosted.controller.api.integration.organization.User) UserId(com.yahoo.vespa.hosted.controller.api.identifiers.UserId) RotationStatus(com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) DayOfWeek(java.time.DayOfWeek) ScrewdriverId(com.yahoo.vespa.hosted.controller.api.identifiers.ScrewdriverId) Collections(java.util.Collections) InputStream(java.io.InputStream) JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) DeploymentId(com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) Cursor(com.yahoo.slime.Cursor) RotationStatus(com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus)

Aggregations

DeploymentId (com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId)9 EndpointStatus (com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus)6 IOException (java.io.IOException)6 ApplicationId (com.yahoo.config.provision.ApplicationId)5 ZoneId (com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId)5 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)5 Slime (com.yahoo.slime.Slime)4 Application (com.yahoo.vespa.hosted.controller.Application)4 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)4 Hostname (com.yahoo.vespa.hosted.controller.api.identifiers.Hostname)4 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)4 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)4 Version (com.yahoo.component.Version)3 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)3 Environment (com.yahoo.config.provision.Environment)3 TenantName (com.yahoo.config.provision.TenantName)3 Cursor (com.yahoo.slime.Cursor)3 NToken (com.yahoo.vespa.athenz.api.NToken)3 ActivateResult (com.yahoo.vespa.hosted.controller.api.ActivateResult)3 DeployOptions (com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions)3