This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support replay and a major refactor.
Refactor task and exec system prior to new execution system.
- Loading branch information
Showing
82 changed files
with
1,960 additions
and
801 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017 Fulcrum GenomicsLLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
package dagr.core.exec | ||
|
||
import scala.collection.mutable | ||
|
||
object ExecDef { | ||
/** Create a thread-safe mutable map. */ | ||
def concurrentMap[A,B](): mutable.Map[A,B] = { | ||
import scala.collection.convert.decorateAsScala._ | ||
new java.util.concurrent.ConcurrentHashMap[A, B]().asScala | ||
} | ||
|
||
/** Create a thread-safe mutable set. */ | ||
def concurrentSet[A](): mutable.Set[A] = { | ||
import scala.collection.convert.decorateAsScala._ | ||
val map: java.util.Map[A, java.lang.Boolean] = new java.util.concurrent.ConcurrentHashMap[A, java.lang.Boolean]() | ||
val set: java.util.Set[A] = java.util.Collections.newSetFromMap[A](map) | ||
set.asScala | ||
} | ||
} |
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,105 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017 Fulcrum Genomics LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
package dagr.core.exec | ||
|
||
import com.fulcrumgenomics.commons.CommonsDef.{DirPath, yieldAndThen} | ||
import dagr.core.execsystem.{SystemResources, TaskManager} | ||
import dagr.core.reporting.ReportingDef.{TaskLogger, TaskRegister} | ||
import dagr.core.reporting.{FinalStatusReporter, TaskStatusLogger} | ||
import dagr.core.tasksystem.Task | ||
import dagr.core.tasksystem.Task.{TaskInfo, TaskStatus} | ||
|
||
import scala.collection.mutable.ListBuffer | ||
import scala.concurrent.ExecutionContext | ||
|
||
object Executor { | ||
/** Create a new executor. */ | ||
def apply(resources: SystemResources, | ||
scriptsDirectory: Option[DirPath], | ||
logDirectory: Option[DirPath] | ||
)(implicit ex: ExecutionContext): Executor = { | ||
new TaskManager(taskManagerResources=resources, scriptsDirectory=scriptsDirectory, logDirectory=logDirectory) | ||
} | ||
} | ||
|
||
/** All executors of tasks should extend this trait. */ | ||
trait Executor extends FinalStatusReporter { | ||
|
||
/** A list of [[TaskCache]] to use to determine if a task should be manually succeeded. */ | ||
protected val taskCaches: ListBuffer[TaskCache] = ListBuffer[TaskCache]() | ||
|
||
/** The loggers to be notified when a task's status is updated. */ | ||
private val _loggers: ListBuffer[TaskLogger] = ListBuffer[TaskLogger](new TaskStatusLogger) | ||
|
||
/** The loggers to be notified when a task's status is updated. */ | ||
private val _registers: ListBuffer[TaskRegister] = ListBuffer[TaskRegister]() | ||
|
||
/** Record that the task information has changed for a task. */ | ||
final def record(info: TaskInfo): Unit = this.synchronized { | ||
this._loggers.foreach(_.record(info=info)) | ||
} | ||
|
||
/** The method that will be called on the result of `Task.getTasks`. */ | ||
final def register(parent: Task, child: Task*): Unit = this.synchronized { | ||
this._registers.foreach(_.register(parent, child:_*)) | ||
} | ||
|
||
/** Adds the [[dagr.core.reporting.ReportingDef.TaskLogger]] to the list of loggers to be notified when a task's status is updated. */ | ||
final def withLogger(logger: TaskLogger): Unit = this.synchronized { | ||
if (!this._loggers.contains(logger)) { | ||
this._loggers.append(logger) | ||
} | ||
} | ||
|
||
/** Adds the [[TaskRegister]] to the list of registers to be notified when a list of tasks is returned by [[Task.getTasks]] */ | ||
final def withTaskRegister(register: TaskRegister): this.type = this.synchronized { | ||
yieldAndThen[this.type](this)(this._registers.append(register)) | ||
} | ||
|
||
/** Adds the [[TaskCache]] to the list of caches to use to determine if a task should be manually succeeded. */ | ||
final def withTaskCache(taskCache: TaskCache): this.type = yieldAndThen[this.type](this) { | ||
this.withTaskRegister(taskCache) | ||
this.taskCaches.append(taskCache) | ||
} | ||
|
||
/** Start the execution of this task and all tasks that depend on it. Returns the number of tasks that were not | ||
* executed. A given task should only be attempted once. */ | ||
final def execute(task: Task): Int = { | ||
task._executor = Some(this) | ||
this.register(task, task) | ||
this._execute(task=task) | ||
} | ||
|
||
/** Returns the task status by ordinal */ | ||
def from(ordinal: Int): TaskStatus | ||
|
||
/** Returns the log directory. */ | ||
def logDir: DirPath | ||
|
||
/** Start the execution of this task and all tasks that depend on it. Returns the number of tasks that were not | ||
* executed. A given task should only be attempted once. All executors should implement this method. */ | ||
protected def _execute(task: Task): Int | ||
} |
Oops, something went wrong.