Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing jobs ids validation on workflow starting #228

Merged
merged 2 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ object TimeSeriesCalendar {
* @param firstDay The first day of the week for these weeks.
*/
case class Weekly(tz: ZoneId, firstDay: DayOfWeek) extends TimeSeriesCalendar {
private def truncateToWeek(t: ZonedDateTime) = t.`with`(TemporalAdjusters.previousOrSame(firstDay)).truncatedTo(DAYS)
private def truncateToWeek(t: ZonedDateTime) =
t.`with`(TemporalAdjusters.previousOrSame(firstDay)).truncatedTo(DAYS)
def truncate(t: Instant) = truncateToWeek(t.atZone(tz)).toInstant
def next(t: Instant) = truncateToWeek(t.atZone(tz)).plus(1, WEEKS).toInstant
}
Expand Down Expand Up @@ -720,9 +721,10 @@ private[timeseries] object TimeSeriesUtils {
val UTC: ZoneId = ZoneId.of("UTC")

/**
* Validation of cycle absence in workflow DAG and an absence the (execution, dependency) tuple that execution has
* a start date after an execution's start date.
* It's implemented based on Kahn's algorithm.
* Validation of:
* - cycle absence in workflow DAG, implemented based on Kahn's algorithm
* - absence the (child, parent) tuple that child has a start date before parent's start date
* - absence of jobs with the same id
* @param workflow workflow to be validated
* @return either a validation errors list or an unit
*/
Expand Down Expand Up @@ -755,6 +757,12 @@ private[timeseries] object TimeSeriesUtils {

if (edges.nonEmpty) errors += "Workflow has at least one cycle"

workflow.vertices.groupBy(_.id).collect {
case (id: String, jobs) if jobs.size > 1 => id
} foreach (id => {
errors += s"Id $id is used by more than 1 job"
})

if (errors.nonEmpty) Left(errors.toList)
else Right(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,22 @@ class TimeSeriesSpec extends FunSuite with TestScheduling {
assert(validationRes.isLeft, "workflow passed start date validation")
assert(validationRes.left.get === List("Workflow has at least one cycle"), "errors messages are bad")
}

test("it shouldn't validate a workflow that contains jobs with same ids") {
val id = "badJob"
val badJob = Job(id, hourly(date"2117-03-25T02:00:00Z"))(completed)
val badJobClone = Job(id, hourly(date"2117-03-24T02:00:00Z"))(completed)
val workflowParentChild = badJob dependsOn badJobClone
val workflowSiblings = badJob and badJobClone

val validationParentChild = TimeSeriesUtils.validate(workflowParentChild)
assert(validationParentChild.isLeft, "it means that workflow passed duplicate id validation")
assert(validationParentChild.left.get === List(s"Id badJob is used by more than 1 job"),
"it means that errors messages are bad")

val validationSiblings = TimeSeriesUtils.validate(workflowSiblings)
assert(validationSiblings.isLeft, "it means that workflow passed duplicate id validation")
assert(validationSiblings.left.get === List(s"Id badJob is used by more than 1 job"),
"it means that errors messages are bad")
}
}