Skip to content

Commit

Permalink
Introduce SimpleDockerPlatform
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszimmermann committed Jan 24, 2019
1 parent ad0aae1 commit f59c642
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 62 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
}

group 'de.difuture.ekut.pht'
version '0.9.0'
version '0.9.1'

repositories {
jcenter()
Expand Down Expand Up @@ -106,7 +106,7 @@ publishing {

model {
tasks.generatePomFileForMavenPublication {
destination = file("$buildDir/libs/lib-0.9.0.pom")
destination = file("$buildDir/libs/lib-0.9.1.pom")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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.api.TrainCommand

object CheckRequirementsExecutor
object RunExecutor
: DockerArrivalExecutor<RunResponse> {

override val command = TrainCommand.RUN
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import de.difuture.ekut.pht.lib.train.api.TrainDeparture
import de.difuture.ekut.pht.lib.train.api.DepartureExecutor

/**
* A TrainStation is a client of the TrainAPI that consistently uses
* A Platform is a client of the TrainAPI that consistently uses
* the provided [RuntimeClient]. Instances of this class hence serve as an entrypoint
* for running commands on train arrivals or departures or to generate new departures from
* arrivals
Expand All @@ -19,7 +19,7 @@ import de.difuture.ekut.pht.lib.train.api.DepartureExecutor
* @since 0.1.7
*
*/
open class TrainStation<T : RuntimeClient>(
open class Platform<T : RuntimeClient>(

protected open val client: T,
protected open val stationInfo: StationRuntimeInfo
Expand Down
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)
}
}
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))
}

0 comments on commit f59c642

Please sign in to comment.