Skip to content

Commit

Permalink
Merge pull request #470 from dres-dev/dev
Browse files Browse the repository at this point in the history
v2.0.1 Quality of Live Improvements
  • Loading branch information
sauterl authored May 27, 2024
2 parents 8c43e8b + b832cd4 commit d038275
Show file tree
Hide file tree
Showing 30 changed files with 316 additions and 116 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,7 @@ _none_

### Frontend

**Safari is NOT supported**
* Task duration greater than `9999999` break things. Do not use such long tasks.
* Safari is NOT supported


2 changes: 1 addition & 1 deletion backend/src/main/kotlin/dev/dres/DRES.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import kotlin.system.exitProcess
*/
object DRES {
/** Version of DRES. */
const val VERSION = "2.0.0"
const val VERSION = "2.0.1"

/** Application root; should be relative to JAR file or classes path. */
val APPLICATION_ROOT: Path =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.dres.api.rest.handler.download

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.dres.api.rest.handler.GetRestHandler
import dev.dres.api.rest.types.evaluation.ApiEvaluation
import dev.dres.api.rest.types.status.ErrorStatus
import dev.dres.api.rest.types.status.ErrorStatusException
import dev.dres.data.model.run.DbEvaluation
Expand All @@ -18,7 +18,7 @@ import kotlinx.dnq.query.query
* @author Ralph Gasser
* @version 1.0.0
*/
class EvaluationDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler<String> {
class EvaluationDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler<ApiEvaluation> {

/** The route of this [EvaluationDownloadHandler]. */
override val route = "download/evaluation/{evaluationId}"
Expand All @@ -32,14 +32,14 @@ class EvaluationDownloadHandler(private val store: TransientEntityStore) : Abstr
OpenApiParam("evaluationId", String::class, "The evaluation ID.", required = true)
],
responses = [
OpenApiResponse("200", [OpenApiContent(String::class, type = "application/json")]),
OpenApiResponse("200", [OpenApiContent(ApiEvaluation::class)]),
OpenApiResponse("400", [OpenApiContent(ErrorStatus::class)]),
OpenApiResponse("401", [OpenApiContent(ErrorStatus::class)]),
OpenApiResponse("404", [OpenApiContent(ErrorStatus::class)])
],
methods = [HttpMethod.GET]
)
override fun doGet(ctx: Context): String {
override fun doGet(ctx: Context): ApiEvaluation {
/* Obtain run id and run. */
val evaluationId = ctx.pathParamMap().getOrElse("evaluationId") { throw ErrorStatusException(400, "Parameter 'evaluationId' is missing!'", ctx) }
val evaluation = this.store.transactional(true) {
Expand All @@ -51,7 +51,6 @@ class EvaluationDownloadHandler(private val store: TransientEntityStore) : Abstr
ctx.header("Content-Disposition", "attachment; filename=\"run-${evaluationId}.json\"")

/* Return value. */
val mapper = jacksonObjectMapper()
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(evaluation)
return evaluation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.dres.api.rest.handler.GetRestHandler
import dev.dres.api.rest.types.status.ErrorStatus
import dev.dres.api.rest.types.status.ErrorStatusException
import dev.dres.api.rest.types.template.ApiEvaluationTemplate
import dev.dres.data.model.template.DbEvaluationTemplate
import io.javalin.http.Context
import io.javalin.openapi.*
Expand All @@ -18,7 +19,8 @@ import kotlinx.dnq.query.query
* @author Ralph Gasser
* @version 1.0.0
*/
class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler<String> {
class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(),
GetRestHandler<ApiEvaluationTemplate> {

/** The route of this [EvaluationTemplateDownloadHandler]. */
override val route = "download/template/{templateId}"
Expand All @@ -39,7 +41,7 @@ class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore)
],
methods = [HttpMethod.GET]
)
override fun doGet(ctx: Context): String {
override fun doGet(ctx: Context): ApiEvaluationTemplate {
/* Obtain run id and run. */
val templateId = ctx.pathParamMap()["templateId"] ?: throw ErrorStatusException(400, "Parameter 'templateId' is missing!'", ctx)
val template = this.store.transactional(true) {
Expand All @@ -51,7 +53,6 @@ class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore)
ctx.header("Content-Disposition", "attachment; filename=\"evaluation-template-${templateId}.json")

/* Return value. */
val mapper = jacksonObjectMapper()
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(template)
return template
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.dres.api.rest.handler.evaluation.viewer

import dev.dres.DRES
import dev.dres.api.rest.handler.GetRestHandler
import dev.dres.api.rest.handler.evaluation.viewer.AbstractEvaluationViewerHandler
import dev.dres.api.rest.types.ViewerInfo
import dev.dres.api.rest.types.template.tasks.ApiHintContent
import dev.dres.api.rest.types.status.ErrorStatus
Expand Down Expand Up @@ -140,8 +139,8 @@ class GetTaskHintHandler(private val store: TransientEntityStore, private val ca
private fun ApiHint.toContentElement(): ApiContentElement {

//TODO find a better place for this lookup
val item = this.mediaItem?.let {itemId ->
DbMediaItem.filter { it.mediaItemId eq itemId }.firstOrNull()
val item = this.item?.let { item ->
DbMediaItem.filter { it.mediaItemId eq item.mediaItemId }.firstOrNull()
}
val range = if (item?.fps != null) {
this.range?.toTemporalRange(item.fps!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.dres.api.rest.types.evaluation

import dev.dres.api.rest.types.evaluation.submission.ApiAnswerSet
import dev.dres.api.rest.types.evaluation.submission.ApiClientSubmission
import dev.dres.api.rest.types.evaluation.submission.ApiSubmission
import dev.dres.data.model.run.DbTask
import dev.dres.data.model.run.TaskId
import dev.dres.data.model.template.TemplateId
Expand All @@ -19,5 +21,5 @@ data class ApiTask(
val templateId: TemplateId,
val started: Long?,
val ended: Long?,
val submissions: List<ApiAnswerSet>
)
val submissions: List<ApiSubmission>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dres.api.rest.types.template.tasks

import dev.dres.api.rest.types.collection.ApiMediaItem
import dev.dres.api.rest.types.collection.time.ApiTemporalRange
import dev.dres.data.model.template.*
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -65,12 +66,7 @@ data class ApiHint(
*
* This is the reference to the media item
*/
val mediaItem: String? = null,

/**
* This is a reference to the media item's name, in case there is one.
*/
val mediaItemName: String? = null,
val item: ApiMediaItem? = null,

/**
* In case [type] is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dres.api.rest.types.template.tasks

import dev.dres.api.rest.types.collection.ApiMediaItem
import dev.dres.api.rest.types.collection.time.ApiTemporalRange
import dev.dres.data.model.template.task.DbTaskTemplateTarget
import kotlinx.serialization.Serializable
Expand All @@ -19,7 +20,7 @@ data class ApiTarget(
val target: String? = null,
val range: ApiTemporalRange? = null,
/**
* The name of the target, which is defined for certain types (e.g. [ApiTargetType]-MEDIA_TIEM )
* The target as item, which is only defined for certain types (e.g. [ApiTargetType]-MEDIA_TIEM )
*/
val name: String? = null
val item: ApiMediaItem? = null
)
11 changes: 8 additions & 3 deletions backend/src/main/kotlin/dev/dres/data/model/run/DbTask.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.dres.data.model.run

import dev.dres.api.rest.types.evaluation.ApiTask
import dev.dres.api.rest.types.evaluation.submission.ApiClientSubmission
import dev.dres.data.model.PersistentEntity
import dev.dres.data.model.submissions.AnswerSet
import dev.dres.data.model.template.task.DbTaskTemplate
Expand All @@ -11,6 +12,7 @@ import dev.dres.data.model.template.team.DbTeam
import jetbrains.exodus.entitystore.Entity
import kotlinx.dnq.*
import kotlinx.dnq.query.asSequence
import kotlinx.dnq.query.mapDistinct
import kotlinx.dnq.util.isInstanceOf
import java.lang.IllegalStateException

Expand Down Expand Up @@ -47,9 +49,12 @@ class DbTask(entity: Entity) : PersistentEntity(entity) {
/** Link to a [DbTeam] this [DbTask] was created for. Can be NULL!*/
var team by xdLink0_1(DbTeam)

/** List of [DbSubmission]s received by this [DbTask]. */
/** List of [DbAnswerSet]s received by this [DbTask]. */
val answerSets by xdLink0_N<DbTask,DbAnswerSet>(DbAnswerSet::task)

/** List of [DbSubmission]s received by this [DbTask].*/
fun submissions() = this.answerSets.asSequence().map{it.submission}.toList()

/**
* Converts this [DbTask] to a RESTful API representation [ApiTask].
*
Expand All @@ -62,6 +67,6 @@ class DbTask(entity: Entity) : PersistentEntity(entity) {
templateId = this.template.id,
started = this.started,
ended = this.ended,
submissions = this.answerSets.asSequence().map { it.toApi() }.toList()
submissions = submissions().map { it.toApi() }.toList()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class DbHint(entity: Entity) : XdEntity(entity) {
start = this.start,
end = this.end,
description = this.text,
mediaItem = this.item?.id,
mediaItemName = this.item?.name,
item = this.item?.toApi(),
dataType = this.type.mimeType,
path = this.path,
range = this.range?.let { ApiTemporalRange(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DbTaskTemplateTarget(entity: Entity) : XdEntity(entity) {
type=this.type.toApi(),
target = this.item?.id,
range= this.range?.let { ApiTemporalRange(it) },
name= this.item?.name
item = this.item?.toApi()
)
DbTargetType.TEXT -> ApiTarget(this.type.toApi(), this.text)
else -> throw IllegalStateException("Task description of type ${this.type.description} is not supported.")
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/kotlin/dev/dres/mgmt/TemplateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ object TemplateManager {
task.hints.add(DbHint.new {
this.type = hint.type.toDb()
this.item =
hint.mediaItem?.let { DbMediaItem.query(DbMediaItem::id eq hint.mediaItem).firstOrNull() }
hint.item?.let { DbMediaItem.query(DbMediaItem::id eq hint.item.mediaItemId).firstOrNull() }
this.text = hint.description

this.path = hint.path
this.start = hint.start
this.end = hint.end
Expand Down
16 changes: 13 additions & 3 deletions backend/src/main/kotlin/dev/dres/run/RunExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,19 @@ object RunExecutor {
DbEvaluation.filter { (it.ended eq null) }.asSequence().forEach { evaluation ->
try {
this.schedule(evaluation.toRunManager(store)) /* Re-schedule evaluations. */
} catch (e: IllegalStateException) {
logger.error("Could not re-schedule previous run: ${e.message}")
evaluation.ended = System.currentTimeMillis()
} catch (e: RuntimeException) {
when (e) {
is IllegalStateException,
is IllegalArgumentException -> {
logger.error("Could not re-schedule previous run: ${e.message}")
evaluation.ended = System.currentTimeMillis()
}

else -> {
logger.error("Fatal error during re-scheduling of previous run (${evaluation.evaluationId}): ${e.message}")
throw e
}
}
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions doc/oas-client.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"openapi" : "3.0.3",
"info" : {
"title" : "DRES Client API",
"version" : "2.0.0-RC5",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0-RC5"
"version" : "2.0.1",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.1"
},
"paths" : {
"/api/v2/client/evaluation/currentTask/{evaluationId}" : {
Expand Down Expand Up @@ -1342,7 +1342,7 @@
"submissions" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiAnswerSet"
"$ref" : "#/components/schemas/ApiSubmission"
}
}
},
Expand Down Expand Up @@ -2021,11 +2021,8 @@
"dataType" : {
"type" : "string"
},
"mediaItem" : {
"type" : "string"
},
"mediaItemName" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
},
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
Expand Down Expand Up @@ -2069,8 +2066,8 @@
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
},
"name" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
}
},
"required" : [ "type" ]
Expand Down
21 changes: 9 additions & 12 deletions doc/oas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"openapi" : "3.0.3",
"info" : {
"title" : "DRES API",
"version" : "2.0.0-RC5",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0-RC5",
"version" : "2.0.1",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.1",
"contact" : {
"name" : "The DRES Dev Team",
"url" : "https://dres.dev"
Expand Down Expand Up @@ -594,9 +594,9 @@
"200" : {
"description" : "OK",
"content" : {
"text/plain" : {
"application/json" : {
"schema" : {
"type" : "string"
"$ref" : "#/components/schemas/ApiEvaluation"
}
}
}
Expand Down Expand Up @@ -5756,7 +5756,7 @@
"submissions" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiAnswerSet"
"$ref" : "#/components/schemas/ApiSubmission"
}
}
},
Expand Down Expand Up @@ -6435,11 +6435,8 @@
"dataType" : {
"type" : "string"
},
"mediaItem" : {
"type" : "string"
},
"mediaItemName" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
},
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
Expand Down Expand Up @@ -6483,8 +6480,8 @@
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
},
"name" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
}
},
"required" : [ "type" ]
Expand Down
Loading

0 comments on commit d038275

Please sign in to comment.