-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #436 from azakkerman/master
Introduce JobsObserver interface and place both JobStats and error notification behind that interface
- Loading branch information
Showing
17 changed files
with
216 additions
and
184 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/scala/org/apache/mesos/chronos/notification/JobNotificationObserver.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.apache.mesos.chronos.notification | ||
|
||
import java.util.logging.Logger | ||
|
||
import akka.actor.ActorRef | ||
import com.google.inject.Inject | ||
import org.apache.mesos.chronos.scheduler.jobs._ | ||
import org.joda.time.{DateTimeZone, DateTime} | ||
|
||
class JobNotificationObserver @Inject()(val notificationClients: List[ActorRef] = List(), | ||
val clusterName: Option[String] = None) { | ||
private[this] val log = Logger.getLogger(getClass.getName) | ||
val clusterPrefix = clusterName.map(name => s"[$name]").getOrElse("") | ||
|
||
def asObserver: JobsObserver.Observer = { | ||
case JobRemoved(job) => sendNotification(job, "%s [Chronos] Your job '%s' was deleted!".format(clusterPrefix, job.name), None) | ||
case JobDisabled(job, cause) => sendNotification( | ||
job, | ||
"%s [Chronos] job '%s' disabled".format(clusterPrefix, job.name), | ||
Some(cause)) | ||
|
||
case JobRetriesExhausted(job, taskStatus, attempts) => | ||
val msg = "\n'%s'. Retries attempted: %d.\nTask id: %s\n" | ||
.format(DateTime.now(DateTimeZone.UTC), job.retries, taskStatus.getTaskId.getValue) | ||
sendNotification(job, "%s [Chronos] job '%s' failed!".format(clusterPrefix, job.name), | ||
Some(TaskUtils.appendSchedulerMessage(msg, taskStatus))) | ||
} | ||
|
||
def sendNotification(job: BaseJob, subject: String, message: Option[String] = None) { | ||
for (client <- notificationClients) { | ||
val subowners = job.owner.split("\\s*,\\s*") | ||
for (subowner <- subowners) { | ||
log.info("Sending mail notification to:%s for job %s using client: %s".format(subowner, job.name, client)) | ||
client !(job, subowner, subject, message) | ||
} | ||
} | ||
|
||
log.info(subject) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/scala/org/apache/mesos/chronos/scheduler/config/JobStatsModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.