-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad0aae1
commit f59c642
Showing
6 changed files
with
84 additions
and
62 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
44 changes: 0 additions & 44 deletions
44
src/main/kotlin/de/difuture/ekut/pht/lib/train/station/DockerTrainStation.kt
This file was deleted.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
src/main/kotlin/de/difuture/ekut/pht/lib/train/station/SimpleDockerPlatform.kt
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,59 @@ | ||
package de.difuture.ekut.pht.lib.train.station | ||
|
||
import de.difuture.ekut.pht.lib.runtime.api.docker.DockerRuntimeClient | ||
import de.difuture.ekut.pht.lib.train.api.DockerRebaseStrategy | ||
import de.difuture.ekut.pht.lib.train.api.RunResponse | ||
import de.difuture.ekut.pht.lib.train.api.StationRuntimeInfo | ||
import de.difuture.ekut.pht.lib.train.impl.docker.DockerRegistryTrainArrival | ||
import de.difuture.ekut.pht.lib.train.impl.docker.DockerRegistryTrainDeparture | ||
import de.difuture.ekut.pht.lib.train.impl.docker.RunExecutor | ||
import jdregistry.client.data.Tag as DockerTag | ||
import java.nio.file.Paths | ||
|
||
class SimpleDockerPlatform( | ||
|
||
override val client: DockerRuntimeClient, | ||
override val stationInfo: StationRuntimeInfo | ||
) : Platform<DockerRuntimeClient>(client, stationInfo) { | ||
|
||
fun departWithAlgorithm(arrival: DockerRegistryTrainArrival): DockerRegistryTrainDeparture { | ||
|
||
val output = RunExecutor.execArrival(arrival, this.client, this.stationInfo) | ||
val response = output.response | ||
|
||
// The Output has an error if there either is an error or the response is null | ||
if (output.error != null || response == null) { | ||
|
||
throw TrainException.Output(output) | ||
} | ||
|
||
if (response.state != RunResponse.AlgorithmExitState.SUCCESS) { | ||
|
||
throw TrainException.RunAlgorithmFailed(output) | ||
} | ||
val rebase = response.rebase | ||
|
||
// SimpleDockerPlatform only supports the DockerRebaseStrategy | ||
if (rebase is DockerRebaseStrategy) { | ||
|
||
val nextTrainTag = rebase.next_train_tag | ||
|
||
// Now the container needs to be commited to create the imageId for the | ||
val imageId = this.client.commitByRebase( | ||
output.containerOutput.containerId, | ||
rebase.export_files.map { Paths.get(it) }, | ||
rebase.from, | ||
arrival.repoName, | ||
DockerTag.from(nextTrainTag.repr) | ||
) | ||
// Return the train departure. The trainId is not going to change, the new TrainTag | ||
// is communicated via the nextTrainTag | ||
return DockerRegistryTrainDeparture( | ||
imageId, | ||
arrival.trainName, | ||
nextTrainTag, | ||
this.client) | ||
} | ||
throw TrainException.UnsupportedRebaseStrategy(rebase) | ||
} | ||
} |
33 changes: 20 additions & 13 deletions
33
src/main/kotlin/de/difuture/ekut/pht/lib/train/station/TrainException.kt
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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
package de.difuture.ekut.pht.lib.train.station | ||
|
||
//sealed class TrainException(msg: String?) : Exception(msg) { | ||
// | ||
// /** | ||
// * Exception to be thrown when the TrainOutput contains an error message | ||
// */ | ||
// data class Output(val output: TrainOutput<*>) : TrainException(output.error) | ||
// | ||
// /** | ||
// * Exception to be thrown when the 'success' field of the RunAlgorithmResponse failed | ||
// */ | ||
// data class RunAlgorithmFailed(val output: TrainOutput<TrainResponse.RunAlgorithmResponse>) | ||
// : TrainException(output.response?.message) | ||
//} | ||
import de.difuture.ekut.pht.lib.train.api.RebaseStrategy | ||
import de.difuture.ekut.pht.lib.train.api.RunResponse | ||
import de.difuture.ekut.pht.lib.train.api.TrainOutput | ||
|
||
sealed class TrainException(msg: String?) : Exception(msg) { | ||
|
||
/** | ||
* Exception to be thrown when the TrainOutput contains an error message | ||
*/ | ||
data class Output(val output: TrainOutput<*>) : TrainException(output.error) | ||
|
||
/** | ||
* Exception to be thrown when the 'success' field of the RunAlgorithmResponse failed | ||
*/ | ||
data class RunAlgorithmFailed(val output: TrainOutput<RunResponse>) | ||
: TrainException(output.response?.free_text_message) | ||
|
||
data class UnsupportedRebaseStrategy(val rebase: RebaseStrategy) | ||
: TrainException("Unsupported Rebase Strategy: {}. Train cannot depart.".format(rebase.display)) | ||
} |