This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the code to allow different dispatcher (#57)
- Loading branch information
1 parent
fe8edb0
commit 3d2fb6b
Showing
9 changed files
with
306 additions
and
159 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
32 changes: 32 additions & 0 deletions
32
starport-core/src/main/scala/com/krux/starport/dispatcher/TaskDispatcher.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,32 @@ | ||
package com.krux.starport.dispatcher | ||
|
||
import com.krux.starport.cli.SchedulerOptions | ||
import com.krux.starport.db.record.{Pipeline, ScheduledPipeline} | ||
import com.krux.starport.exception.StarportException | ||
import com.krux.starport.config.StarportSettings | ||
import com.krux.starport.db.record.ScheduledPipeline | ||
|
||
trait TaskDispatcher { | ||
|
||
/** | ||
* This method deploys and activates a Pipeline object using hyperion cli. | ||
* It should be implemented in a thread safe manner as dispatch tasks can be executed in parallel | ||
* @param pipeline | ||
* @param options | ||
* @param jar | ||
* @param conf | ||
* @return Unit - This is a side effect function | ||
*/ | ||
def dispatch(pipeline: Pipeline, options: SchedulerOptions, jar: String, conf: StarportSettings): Either[StarportException, Unit] | ||
|
||
/** | ||
* This method retrieves all the pipeline Ids for the the pipelines deployed via dispatch. | ||
* It is meant to be invoked before starting task dispatching or after all the tasks have been dispatched. | ||
* This operation is not meant to be Threadsafe and should not be executed in parallel. | ||
* @param conf | ||
* @return Seq of all ScheduledPipelines | ||
*/ | ||
def retrieve(conf: StarportSettings): Seq[ScheduledPipeline] | ||
|
||
} | ||
|
33 changes: 33 additions & 0 deletions
33
starport-core/src/main/scala/com/krux/starport/dispatcher/impl/ConcurrentQueueHelpers.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,33 @@ | ||
package com.krux.starport.dispatcher.impl | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue | ||
import collection.JavaConverters._ | ||
import com.krux.starport.db.record.ScheduledPipeline | ||
|
||
/** | ||
* This object contains few methods to make the java implementation of ConcurrentLinkedQueue nicer to use | ||
*/ | ||
object ConcurrentQueueHelpers { | ||
|
||
implicit class AugmentedConcurrentQueue(q: ConcurrentLinkedQueue[ScheduledPipeline]) { | ||
/** | ||
* Empties the queue | ||
*/ | ||
def consumeAll(): Unit = { | ||
while(!q.isEmpty) { | ||
q.poll() | ||
} | ||
} | ||
|
||
/** | ||
* Returns all the elements of the queue in an ordered List and removes all the elements from the queue | ||
* @return | ||
*/ | ||
def retrieveAll() = { | ||
val elements = q.iterator().asScala.toList | ||
consumeAll() | ||
elements | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.