FileBased

class FileBased(getGraderLogPath: () -> Path) : CmdOutputHandler

File-based implementation of command line output handler, in which every variable's result is stored as a file.

The algorithm used:

  1. Every add call with a Var against a command will pipe to 3 created/overwritten file at graderLogPath. Files follow a specific naming convention: ".NAME_OF_VARIABLE.{stdout, stderr, ec}".

  2. Since graderLogPath is mounted, so all files are retrievable from the grader host. We search for such "NAME_OF_VARIABLE"s that have all 3 files present at the log path, do truncation if needed, and record them in vars.

  3. When a result of a variable is queried (by calling Var.{stdout,stderr,exitcode} in a pipeline stage), if the underlying variable is registered in vars, read the corresponding file and return file content as list of lines.

One feature that FileBased output handler has is the ability to handle a potentially large command output, that could come from a stream produced by commands like yes and cat of a big file.

Constructors

Link copied to clipboard
constructor(getGraderLogPath: () -> Path)

Properties

Link copied to clipboard
protected val graderLogPath: Path

Root directory path where arbitrary grader output files from stage execution are stored under as logs.

Link copied to clipboard
private lateinit var vars: Set<String>

Internal state storing received outputs after executing one stage.

Functions

Link copied to clipboard
open override fun collectOutput(onSuccess: (Path) -> Unit, onFailure: (Path) -> Unit)

IO action to perform after stage execution (under an environment like a container), in order to load stage output files from the file system for reading and further reporting. This method shall put the contents of output files into a readable internal state representing the outputs.

Link copied to clipboard
open override fun getResultContent(result: CmdUtils.Var.Result<*>): List<String>

Reads the file that stores result if the variable underlying result is registered in vars. Truncates the file content up to Configuration.PipelineStage.OutputTruncation.reportOutputLength bytes if it is too big. Otherwise return empty content.

Link copied to clipboard
open fun onAfterCore(): List<String>

Commands to execute after any core commands.

Link copied to clipboard

Commands to execute after any core commands and onAfterCore commands.

Link copied to clipboard
open override fun onBeforeCore(): List<String>

Delete all files in the mounted log directory, cleaning up for the next stage to output logs.

Link copied to clipboard
open operator fun String.rangeTo(rest: String): String

Command building combinator to concat different parts of the command with proper spacing.

Link copied to clipboard
open override fun CmdUtils.Var.register(cmd: String): String

Register a Var to record the results of cmd for constructing reports after stage execution.

Link copied to clipboard
open fun setup()

Setup actions required to take before container execution for this output handler to run successfully. For example: delete all files at mount mount, create directories at mount point.

Link copied to clipboard
private fun varNames(extension: String): Set<String>

Find all the variable names that have valid log file names with extension searchable from graderLogPath.