Search in sources :

Example 1 with Change

use of com.yahoo.vespa.hosted.controller.application.Change 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)

Example 2 with Change

use of com.yahoo.vespa.hosted.controller.application.Change in project vespa by vespa-engine.

the class ApplicationSerializer method fromSlime.

// ------------------ Deserialization
public Application fromSlime(Slime slime) {
    Inspector root = slime.get();
    ApplicationId id = ApplicationId.fromSerializedForm(root.field(idField).asString());
    DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(root.field(deploymentSpecField).asString(), false);
    ValidationOverrides validationOverrides = ValidationOverrides.fromXml(root.field(validationOverridesField).asString());
    List<Deployment> deployments = deploymentsFromSlime(root.field(deploymentsField));
    DeploymentJobs deploymentJobs = deploymentJobsFromSlime(root.field(deploymentJobsField));
    Change deploying = changeFromSlime(root.field(deployingField));
    Change outstandingChange = changeFromSlime(root.field(outstandingChangeField));
    Optional<IssueId> ownershipIssueId = optionalString(root.field(ownershipIssueIdField)).map(IssueId::from);
    ApplicationMetrics metrics = new ApplicationMetrics(root.field(queryQualityField).asDouble(), root.field(writeQualityField).asDouble());
    Optional<RotationId> rotation = rotationFromSlime(root.field(rotationField));
    return new Application(id, deploymentSpec, validationOverrides, deployments, deploymentJobs, deploying, outstandingChange, ownershipIssueId, metrics, rotation);
}
Also used : Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) Change(com.yahoo.vespa.hosted.controller.application.Change) DeploymentSpec(com.yahoo.config.application.api.DeploymentSpec) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) Inspector(com.yahoo.slime.Inspector) IssueId(com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId) ApplicationId(com.yahoo.config.provision.ApplicationId) ValidationOverrides(com.yahoo.config.application.api.ValidationOverrides) ApplicationMetrics(com.yahoo.vespa.hosted.controller.api.integration.MetricsService.ApplicationMetrics) RotationId(com.yahoo.vespa.hosted.controller.rotation.RotationId) Application(com.yahoo.vespa.hosted.controller.Application)

Example 3 with Change

use of com.yahoo.vespa.hosted.controller.application.Change 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)

Example 4 with Change

use of com.yahoo.vespa.hosted.controller.application.Change in project vespa by vespa-engine.

the class DeploymentTester method completeDeployment.

private void completeDeployment(Application application, ApplicationPackage applicationPackage, Optional<JobType> failOnJob, boolean includingProductionZones) {
    DeploymentOrder order = new DeploymentOrder(controller());
    List<JobType> jobs = order.jobsFrom(applicationPackage.deploymentSpec());
    if (!includingProductionZones)
        jobs = jobs.stream().filter(job -> !job.isProduction()).collect(Collectors.toList());
    for (JobType job : jobs) {
        boolean failJob = failOnJob.map(j -> j.equals(job)).orElse(false);
        deployAndNotify(application, applicationPackage, !failJob, false, job);
        if (failJob) {
            break;
        }
    }
    if (failOnJob.isPresent()) {
        assertTrue(applications().require(application.id()).change().isPresent());
        assertTrue(applications().require(application.id()).deploymentJobs().hasFailures());
    } else if (includingProductionZones) {
        assertFalse(applications().require(application.id()).change().isPresent());
    } else {
        assertTrue(applications().require(application.id()).change().isPresent());
    }
}
Also used : Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) DeploymentJobs(com.yahoo.vespa.hosted.controller.application.DeploymentJobs) JobControl(com.yahoo.vespa.hosted.controller.maintenance.JobControl) ArtifactRepositoryMock(com.yahoo.vespa.hosted.controller.ArtifactRepositoryMock) Change(com.yahoo.vespa.hosted.controller.application.Change) TenantId(com.yahoo.vespa.hosted.controller.api.identifiers.TenantId) Duration(java.time.Duration) Application(com.yahoo.vespa.hosted.controller.Application) Upgrader(com.yahoo.vespa.hosted.controller.maintenance.Upgrader) Environment(com.yahoo.config.provision.Environment) ApplicationController(com.yahoo.vespa.hosted.controller.ApplicationController) ConfigServerClientMock(com.yahoo.vespa.hosted.controller.ConfigServerClientMock) ManualClock(com.yahoo.test.ManualClock) Assert.assertTrue(org.junit.Assert.assertTrue) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) JobType(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType) List(java.util.List) ControllerTester(com.yahoo.vespa.hosted.controller.ControllerTester) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) BuildService(com.yahoo.vespa.hosted.controller.api.integration.BuildService) ReadyJobsTrigger(com.yahoo.vespa.hosted.controller.maintenance.ReadyJobsTrigger) VersionStatus(com.yahoo.vespa.hosted.controller.versions.VersionStatus) Controller(com.yahoo.vespa.hosted.controller.Controller) Assert.assertEquals(org.junit.Assert.assertEquals) JobType(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType)

Example 5 with Change

use of com.yahoo.vespa.hosted.controller.application.Change in project vespa by vespa-engine.

the class DeploymentTrigger method changeDeployed.

/**
 * Returns whether the given application should skip deployment of its current change to the given production job zone.
 *
 * If the currently deployed application has a newer platform or application version than the application's
 * current change, the method returns {@code true}, to avoid a downgrade.
 * Otherwise, it returns whether the current change is redundant, i.e., all its components are already deployed.
 */
private boolean changeDeployed(Application application, JobType job) {
    if (!job.isProduction())
        throw new IllegalArgumentException(job + " is not a production job!");
    Deployment deployment = application.deployments().get(job.zone(controller.system()).get());
    if (deployment == null)
        return false;
    int applicationComparison = application.change().application().map(version -> version.compareTo(deployment.applicationVersion())).orElse(0);
    int platformComparion = application.change().platform().map(version -> version.compareTo(deployment.version())).orElse(0);
    if (applicationComparison == -1 || platformComparion == -1)
        // Avoid downgrades!
        return true;
    return applicationComparison == 0 && platformComparion == 0;
}
Also used : Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) JobReport(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobReport) ApplicationList(com.yahoo.vespa.hosted.controller.application.ApplicationList) JobList(com.yahoo.vespa.hosted.controller.application.JobList) Change(com.yahoo.vespa.hosted.controller.application.Change) Duration(java.time.Duration) JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) Application(com.yahoo.vespa.hosted.controller.Application) LockedApplication(com.yahoo.vespa.hosted.controller.LockedApplication) ApplicationController(com.yahoo.vespa.hosted.controller.ApplicationController) Collection(java.util.Collection) ApplicationVersion(com.yahoo.vespa.hosted.controller.application.ApplicationVersion) CuratorDb(com.yahoo.vespa.hosted.controller.persistence.CuratorDb) Instant(java.time.Instant) Logger(java.util.logging.Logger) JobError(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobError) Objects(java.util.Objects) JobType(com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType) List(java.util.List) Stream(java.util.stream.Stream) SystemName(com.yahoo.config.provision.SystemName) Clock(java.time.Clock) Optional(java.util.Optional) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment) Collections(java.util.Collections) Controller(com.yahoo.vespa.hosted.controller.Controller) Deployment(com.yahoo.vespa.hosted.controller.application.Deployment)

Aggregations

Change (com.yahoo.vespa.hosted.controller.application.Change)6 ApplicationId (com.yahoo.config.provision.ApplicationId)5 Application (com.yahoo.vespa.hosted.controller.Application)5 Version (com.yahoo.component.Version)3 Inspector (com.yahoo.slime.Inspector)3 Controller (com.yahoo.vespa.hosted.controller.Controller)3 Deployment (com.yahoo.vespa.hosted.controller.application.Deployment)3 DeploymentJobs (com.yahoo.vespa.hosted.controller.application.DeploymentJobs)3 Duration (java.time.Duration)3 List (java.util.List)3 Optional (java.util.Optional)3 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)2 Environment (com.yahoo.config.provision.Environment)2 ApplicationController (com.yahoo.vespa.hosted.controller.ApplicationController)2 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)2 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)2 ApplicationVersion (com.yahoo.vespa.hosted.controller.application.ApplicationVersion)2 JobType (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType)2 JobStatus (com.yahoo.vespa.hosted.controller.application.JobStatus)2 Collections (java.util.Collections)2