Skip to content

Commit

Permalink
(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarasssDev committed Aug 1, 2023
1 parent aa9c320 commit ae7dd8b
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 413 deletions.
61 changes: 2 additions & 59 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,75 +1,18 @@
FROM --platform=linux/amd64 ubuntu:18.04
FROM ubuntu:18.04
MAINTAINER Roman Shishkin <romashkin.2001@yandex.ru>
LABEL Description="This image is for grading system for TRIK Studio testing system"

#Setting directories args
ARG APP_DIR=grading-system
ARG TRIK_STUDIO_DIR=TRIKStudio
ARG INSTALLER_DIR=installer

#Setting installers args
ARG INSTALLER=installer.run
ARG RELEASE_INSTALLER_URL=https://dl.trikset.com/ts/trik-studio-installer-gnu64.run
ARG MASTER_INSTALLER_URL=https://dl.trikset.com/ts/fresh/installer/trik-studio-installer-linux-master.run

#Updating system and installing packages
WORKDIR /
ARG DEBIAN_FRONTEND=noninteractive

RUN echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/99norecommends \
&& apt-get -y update \
&& apt-get -y install \
apt-utils \
default-jdk \
wget \
curl \
libpulse0 \
locales \
libxkbcommon-x11-0 \
&& apt-get autoremove -y \
&& apt-get clean -y

RUN echo 'ru_RU.UTF-8 UTF-8' > /etc/locale.gen \
&& locale-gen
ENV LANG ru_RU.UTF-8
ENV LANGUAGE ru_RU:ru
ENV LC_LANG ru_RU.UTF-8
ENV LC_ALL ru_RU.UTF-8

#Copying intalling script for master installer
WORKDIR /$APP_DIR/$INSTALLER_DIR
COPY docker/trik_studio_installscript.qs install_script.qs

#Downloading TRIK Studio
WORKDIR /$APP_DIR/$INSTALLER_DIR
RUN curl --output $INSTALLER $MASTER_INSTALLER_URL

#Setting installer executable
WORKDIR /$APP_DIR/$INSTALLER_DIR
RUN chmod +x $INSTALLER

#Installing TRIKStudio
WORKDIR /$APP_DIR
#Command to install master version
RUN env INSTALL_DIR=/$APP_DIR/$TRIK_STUDIO_DIR ./$INSTALLER_DIR/$INSTALLER --script ./$INSTALLER_DIR/install_script.qs --platform minimal --verbose
#Command to install release version
#RUN ./$INSTALLER_DIR/$INSTALLER --am --al --confirm-command -t /$APP_DIR/$TRIK_STUDIO_DIR install

#Checking TRIK Studio version
WORKDIR /$APP_DIR/$TRIK_STUDIO_DIR
RUN ./trik-studio -platform offscreen --version | grep -F \
$(curl -s https://api.github.com/repos/trikset/trik-studio/commits/master | grep sha | head -n 1 | cut -d '"' -f 4 | cut -c 1-6)

#Removing installer and script
WORKDIR /$APP_DIR
RUN rm -r $INSTALLER_DIR

##Copying tasks (only for testing container)
#WORKDIR /
#COPY tasks tasks

##Creating directory for submissions
#WORKDIR /
#RUN mkdir submissions

#Copying application
WORKDIR /$APP_DIR
Expand Down
10 changes: 9 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ group = "Pupsen&Vupsen"
version = "3.0.0"
java.sourceCompatibility = JavaVersion.VERSION_16


repositories {
mavenCentral()
}
Expand All @@ -30,6 +31,13 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.beust:klaxon:5.6")

//implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

implementation("io.ktor:ktor-client-core:1.6.8")
implementation("io.ktor:ktor-client-cio:1.6.8")
//implementation("io.ktor:ktor-client-java:1.6.8")
//implementation("io.ktor:ktor-client-curl:1.6.8")

implementation("com.h2database:h2")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.springframework.boot:spring-boot-starter-test")
Expand Down Expand Up @@ -80,4 +88,4 @@ tasks.jacocoTestReport {
exclude(jacocoExclude)
}
})
}
}
77 changes: 0 additions & 77 deletions docker/trik_studio_installscript.qs

This file was deleted.

50 changes: 37 additions & 13 deletions src/main/kotlin/trik/testsys/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.web.servlet.MultipartConfigFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import org.springframework.scheduling.TaskScheduler
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
import org.springframework.util.unit.DataSize
import org.springframework.util.unit.DataUnit

import java.util.concurrent.Executor
import javax.servlet.MultipartConfigElement


@SpringBootApplication
@Configuration
@EnableScheduling
class Application {

@Bean
fun taskScheduler(): TaskScheduler? {
val threadPoolTaskScheduler = ThreadPoolTaskScheduler()
threadPoolTaskScheduler.poolSize = 2
threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler")
return threadPoolTaskScheduler
}

@Bean
fun multipartConfigElement(): MultipartConfigElement {
val factory = MultipartConfigFactory()
Expand All @@ -25,19 +34,34 @@ class Application {
return factory.createMultipartConfig()
}

@Bean("testExecutor")
fun createTestExecutor(): Executor? {
val executor = ThreadPoolTaskExecutor()
executor.corePoolSize = 15
executor.maxPoolSize = 15
executor.setQueueCapacity(5000)
executor.initialize()
return executor
}

companion object {

// fun kek(submissionId: Long, status: Status) {
// println("Id: $submissionId Status: $status")
// }

@JvmStatic
fun main(args: Array<String>) {
// val nodePool = GradingNodePool("/home/viktor/Documents/code/pet/TestGradingSystem/appdata/grader.conf", ::kek)
// val task1 = "/home/viktor/Desktop/tasks/task1"
// val task1solution = "/home/viktor/Downloads/Telegram Desktop/Task_2.1_reshenie.qrs"
// nodePool.grade(GradingNode.SubmissionInfo(
// submissionId = 1,
// submissionFilePath = task1solution,
// fieldsDirectoryPath = task1,
// resultsDirectoryPath = "/home/viktor/Desktop"
// ))
// nodePool.grade(GradingNode.SubmissionInfo(
// submissionId = 2,
// submissionFilePath = "$task1/Task_2.1.xml",
// fieldsDirectoryPath = task1,
// resultsDirectoryPath = "/home/viktor/Desktop"
// ))
// while(true){
// Thread.sleep(15_000)
// nodePool.poll()
// }

SpringApplication.run(Application::class.java, *args)
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/trik/testsys/grading/Event.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package trik.testsys.grading

class Event<T> {
private val observers = mutableListOf<(T) -> Unit>()

operator fun plusAssign(observer: (T) -> Unit) {
observers.add(observer)
}

operator fun minusAssign(observer: (T) -> Unit) {
observers.remove(observer)
}

operator fun invoke(value: T) {
for (observer in observers)
observer(value)
}
}
58 changes: 58 additions & 0 deletions src/main/kotlin/trik/testsys/grading/Grader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package trik.testsys.grading

import org.slf4j.LoggerFactory
import trik.testsys.gradingsystem.entities.Submission
import trik.testsys.gradingsystem.enums.FilePostfixes
import trik.testsys.gradingsystem.enums.Paths
import trik.testsys.gradingsystem.enums.Status

class Grader(graderConfigPath: String) {

private val logger = LoggerFactory.getLogger(this::class.java)
private val submissions = mutableMapOf<Long, Submission>()
private val gradingNodePool = GradingNodePool(graderConfigPath, ::onGradingFinished)
val gradingFinishedEvent = Event<Submission>()

//region Custom exceptions
class IncorrectConfigException(msg: String):
Exception(msg)
//endregion


//region Paths
private fun getResultsDirectory(submission: Submission): String {
val submissionDir = "${Paths.SUBMISSIONS.text}${submission.id}/"
return "${submissionDir}${Paths.RESULTS.text}${FilePostfixes.RESULT.text}"
}
//endregion


private fun onGradingFinished(submissionId: Long, status: Status) {
val submission = submissions[submissionId]!!
submission.changeStatus(status)
gradingFinishedEvent(submission)
}

//region SubmissionInfo creating
private fun submissionInfoFromSubmission(submission: Submission): GradingNode.SubmissionInfo{
val submissionDir = "${Paths.SUBMISSIONS.text}${submission.id}/"
val submissionFilePath = "${submissionDir}${submission}${FilePostfixes.QRS.text}"
val fieldsDirectoryPath = "${submissionDir}${Paths.TESTS.text}"
return GradingNode.SubmissionInfo(
submissionId = submission.id!!,
submissionFilePath = submissionFilePath,
fieldsDirectoryPath = fieldsDirectoryPath,
resultsDirectoryPath = getResultsDirectory(submission)
)
}
//endregion

fun grade(submission: Submission) {
val submissionInfo = submissionInfoFromSubmission(submission)
gradingNodePool.grade(submissionInfo)
}

fun poll() {
gradingNodePool.poll()
}
}
Loading

0 comments on commit ae7dd8b

Please sign in to comment.