2010-06-15 12:43:46 +08:00
|
|
|
package org.broadinstitute.sting.queue.function
|
|
|
|
|
|
|
|
|
|
import java.io.File
|
2010-06-23 02:39:20 +08:00
|
|
|
import java.lang.management.ManagementFactory
|
2010-06-26 04:51:13 +08:00
|
|
|
import org.broadinstitute.sting.queue.function.scattergather.{Gather, SimpleTextGatherFunction}
|
|
|
|
|
import org.broadinstitute.sting.queue.util.IOUtils
|
2010-07-07 11:15:10 +08:00
|
|
|
import org.broadinstitute.sting.commandline.{ClassType, Output, Input}
|
2010-06-15 12:43:46 +08:00
|
|
|
|
2010-06-23 02:39:20 +08:00
|
|
|
trait DispatchFunction extends InputOutputFunction {
|
2010-06-15 12:43:46 +08:00
|
|
|
def commandLine: String
|
|
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Input(doc="Upper memory limit", required=false)
|
2010-07-07 11:15:10 +08:00
|
|
|
@ClassType(classOf[Int])
|
2010-06-23 02:39:20 +08:00
|
|
|
var memoryLimit: Option[Int] = None
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The directory where the command should run.
|
|
|
|
|
*/
|
2010-06-26 04:51:13 +08:00
|
|
|
@Input(doc="Directory to write any files", required=false)
|
2010-06-23 02:39:20 +08:00
|
|
|
var commandDirectory: File = IOUtils.CURRENT_DIR
|
|
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Input(doc="Prefix for automatic job name creation", required=false)
|
2010-06-23 02:39:20 +08:00
|
|
|
var jobNamePrefix: String = _
|
|
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Input(doc="Job name to run on the farm", required=false)
|
2010-06-15 12:43:46 +08:00
|
|
|
var jobName: String = _
|
2010-06-23 02:39:20 +08:00
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Output(doc="File to redirect any output", required=false)
|
2010-06-23 02:39:20 +08:00
|
|
|
@Gather(classOf[SimpleTextGatherFunction])
|
2010-06-15 12:43:46 +08:00
|
|
|
var jobOutputFile: File = _
|
2010-06-23 02:39:20 +08:00
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Output(doc="File to redirect any errors", required=false)
|
2010-06-23 02:39:20 +08:00
|
|
|
@Gather(classOf[SimpleTextGatherFunction])
|
2010-06-15 12:43:46 +08:00
|
|
|
var jobErrorFile: File = _
|
|
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Input(doc="Job project to run the command", required=false)
|
2010-06-15 12:43:46 +08:00
|
|
|
var jobProject = "Queue"
|
|
|
|
|
|
2010-06-26 04:51:13 +08:00
|
|
|
@Input(doc="Job queue to run the command", required=false)
|
2010-06-15 12:43:46 +08:00
|
|
|
var jobQueue = "broad"
|
2010-06-23 02:39:20 +08:00
|
|
|
|
|
|
|
|
override def freeze = {
|
|
|
|
|
if (jobNamePrefix == null)
|
|
|
|
|
jobNamePrefix = DispatchFunction.processNamePrefix
|
|
|
|
|
|
|
|
|
|
if (jobName == null)
|
|
|
|
|
jobName = DispatchFunction.nextJobName(jobNamePrefix)
|
|
|
|
|
|
|
|
|
|
if (jobOutputFile == null)
|
|
|
|
|
jobOutputFile = new File(jobName + ".out")
|
|
|
|
|
|
|
|
|
|
if (jobErrorFile == null)
|
|
|
|
|
jobErrorFile = new File(jobName + ".err")
|
|
|
|
|
|
|
|
|
|
commandDirectory = IOUtils.absolute(IOUtils.CURRENT_DIR, commandDirectory)
|
|
|
|
|
|
|
|
|
|
super.freeze
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Override the canon function to change any relative path to an absolute path.
|
|
|
|
|
*/
|
|
|
|
|
override protected def canon(value: Any) = {
|
|
|
|
|
value match {
|
|
|
|
|
case file: File => IOUtils.absolute(commandDirectory, file)
|
|
|
|
|
case x => super.canon(x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def absolute(file: File) = IOUtils.absolute(commandDirectory, file)
|
|
|
|
|
def temp(subDir: String) = IOUtils.sub(commandDirectory, jobName + "-" + subDir)
|
|
|
|
|
|
|
|
|
|
override def toString = commandLine
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object DispatchFunction {
|
|
|
|
|
private val processNamePrefix = "Q-" + {
|
|
|
|
|
var prefix = ManagementFactory.getRuntimeMXBean.getName
|
|
|
|
|
val index = prefix.indexOf(".")
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
prefix = prefix.substring(0, index)
|
|
|
|
|
prefix
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private var jobIndex = 0
|
|
|
|
|
|
|
|
|
|
private def nextJobName(prefix: String) = {
|
|
|
|
|
jobIndex += 1
|
|
|
|
|
prefix + "-" + jobIndex
|
|
|
|
|
}
|
2010-06-15 12:43:46 +08:00
|
|
|
}
|