Last active
May 13, 2016 13:22
-
-
Save seregasheypak/2009c84b546b4f38316bfbfa180d8d25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
test("Test generate sequential jobs") { | |
val xml = RunWorkflow | |
.getXMLString(new RunSequentialJobsWorkflow() | |
.createPipeline("com.job.A,com.job.B,com.job.C")) // naive way to interpolate ${JobsList} | |
// there are over 9999 elegant ways to do it in Scala | |
println(xml) | |
xml.length should be > 0 | |
} | |
class RunSequentialJobsWorkflow { | |
import dsl._ | |
import jobs._ | |
// ${JobsList} should be interpolated/injected before execution | |
def createPipeline(jobsList:String="${JobsList}"): Workflow = { | |
val jobNames = Var.List.ofStrings(jobsList) | |
val javaJobs = jobNames.map(jobName => JavaJob(mainClass = jobName)) | |
val linked = linkJobs(Start, javaJobs) | |
val end = End dependsOn linked | |
val wf = Workflow("Variable list of sequential jobs", end) | |
wf | |
} | |
def linkJobs(dep: Dependency, jobs: List[Job]): Node = { | |
def linkNodes(prevNode:Node, jobs: List[Job]): Node = { | |
jobs.headOption match { | |
case None => prevNode | |
case Some(job: Job) => linkNodes(job dependsOn prevNode, jobs.tail) | |
} | |
} | |
linkNodes(jobs.head dependsOn dep, jobs.tail) | |
} | |
object Var { | |
object List { | |
def ofStrings(placeholder: String) = { | |
placeholder.split(",").toList | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment