Skip to content

Commit

Permalink
TG-583: get version WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlord committed Sep 6, 2023
1 parent d0abfc8 commit 8e1b159
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions http-proxy/conf.d-prod/ngnix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ server {
proxy_pass http://biab-script-server:8080/pipeline/;
}

location /api/ {
proxy_pass http://biab-script-server:8080/api/;
}

location /tiler/ {
proxy_pass http://biab-tiler:8000/;
Expand Down
4 changes: 4 additions & 0 deletions http-proxy/conf.d/ngnix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ server {
proxy_pass http://biab-script-server:8080/pipeline/;
}

location /api/ {
proxy_pass http://biab-script-server:8080/api/;
}

## Server to use when making changes to the OpenAPI specification. (dev only)
location /swagger/ {
proxy_pass http://swagger_editor:8080/swagger/;
Expand Down
16 changes: 16 additions & 0 deletions script-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ paths:
description: Bad request
"404":
description: id not found
/api/versions:
get:
summary: Returns the version of system components.
responses:
"200":
description: The version of system components.
content:
text/plain:
schema:
type: string
x-content-type: text/plain
example: |
R runner: 2023-06-15T14:09:32.212670687-04:00
Rscript (R) version 4.2.3 (2023-03-15)
components:
parameters:
stepType:
Expand Down
12 changes: 12 additions & 0 deletions script-server/src/main/kotlin/org/geobon/server/plugins/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.geobon.pipeline.*
import org.geobon.pipeline.Pipeline.Companion.createMiniPipelineFromScript
import org.geobon.pipeline.Pipeline.Companion.createRootPipeline
import org.geobon.pipeline.RunContext.Companion.scriptRoot
import org.geobon.utils.runCommand
import org.geobon.utils.toMD5
import org.json.JSONObject
import org.slf4j.Logger
Expand Down Expand Up @@ -209,5 +212,14 @@ fun Application.configureRouting() {
call.respond(HttpStatusCode.OK)
} ?: call.respond(/*412*/HttpStatusCode.PreconditionFailed, "The pipeline wasn't running")
}

get("/api/versions") {
println("getting the versions")
val rRunner =
call.respond("""
R runner: ${"docker inspect --type=image -f '{{ .Created }}' biab_20-runner-r".runCommand()?.trim()}
${"docker exec -i biab-runner-r Rscript --version".runCommand()}
""".trimIndent())
}
}
}
19 changes: 19 additions & 0 deletions script-server/src/main/kotlin/org/geobon/utils/runCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.geobon.utils

import java.io.File
import java.util.concurrent.TimeUnit


fun String.runCommand(
workingDir: File = File("."),
timeoutAmount: Long = 1,
timeoutUnit: TimeUnit = TimeUnit.SECONDS
): String? = runCatching {
println("bash -c $this")
ProcessBuilder("bash", "-c", this)
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectErrorStream(true) // Merges stderr into stdout
.start().also { it.waitFor(timeoutAmount, timeoutUnit) }
.inputStream.bufferedReader().readText()
}.onFailure { it.printStackTrace() }.getOrNull()
10 changes: 10 additions & 0 deletions script-server/src/test/kotlin/org/geobon/server/ApplicationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,14 @@ class ApplicationTest {
assertEquals(HttpStatusCode.OK, status)
}
}

@Test
fun testGetVersion() = testApplication {
application { configureRouting() }

client.get("/api/versions").apply {
assertEquals(HttpStatusCode.OK, status)
println(bodyAsText())
}
}
}

0 comments on commit 8e1b159

Please sign in to comment.