From 5c7bd44ce8fdcf25d2ef2d614a9e724525366f6c Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Thu, 20 Feb 2020 09:16:35 +0100 Subject: Make sure we keep sending email when new run failre statuses are added --- .../controller/deployment/InternalStepRunner.java | 35 +++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'controller-server') diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java index 9d666c6f7b5..cbce9ad48f1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java @@ -38,6 +38,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; import com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterCloud; import com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterId; import com.yahoo.vespa.hosted.controller.api.integration.organization.DeploymentFailureMails; +import com.yahoo.vespa.hosted.controller.api.integration.organization.Mail; import com.yahoo.vespa.hosted.controller.application.ApplicationPackage; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; @@ -672,22 +673,36 @@ public class InternalStepRunner implements StepRunner { return; try { - if (run.status() == outOfCapacity && run.id().type().isProduction()) - controller.serviceRegistry().mailer().send(mails.outOfCapacity(run.id(), recipients)); - if (run.status() == deploymentFailed) - controller.serviceRegistry().mailer().send(mails.deploymentFailure(run.id(), recipients)); - if (run.status() == installationFailed) - controller.serviceRegistry().mailer().send(mails.installationFailure(run.id(), recipients)); - if (run.status() == testFailure) - controller.serviceRegistry().mailer().send(mails.testFailure(run.id(), recipients)); - if (run.status() == error) - controller.serviceRegistry().mailer().send(mails.systemError(run.id(), recipients)); + mailOf(run, recipients).ifPresent(controller.serviceRegistry().mailer()::send); } catch (RuntimeException e) { logger.log(INFO, "Exception trying to send mail for " + run.id(), e); } } + private Optional mailOf(Run run, List recipients) { + switch (run.status()) { + case running: + case aborted: + case success: + return Optional.empty(); + case outOfCapacity: + return run.id().type().isProduction() ? Optional.of(mails.outOfCapacity(run.id(), recipients)) : Optional.empty(); + case deploymentFailed: + return Optional.of(mails.deploymentFailure(run.id(), recipients)); + case installationFailed: + return Optional.of(mails.installationFailure(run.id(), recipients)); + case testFailure: + return Optional.of(mails.testFailure(run.id(), recipients)); + case error: + case endpointCertificateTimeout: + return Optional.of(mails.systemError(run.id(), recipients)); + default: + logger.log(WARNING, "Don't know what mail to send for run status '" + run.status() + "'"); + return Optional.of(mails.systemError(run.id(), recipients)); + } + } + /** Returns the deployment of the real application in the zone of the given job, if it exists. */ private Optional deployment(ApplicationId id, JobType type) { return Optional.ofNullable(application(id).deployments().get(type.zone(controller.system()))); -- cgit v1.2.3