Skip to content
Snippets Groups Projects
Commit 13f6e267 authored by Hamza Remmal's avatar Hamza Remmal
Browse files

Merge branch 'prepare-1.0.4' into '1.0.x'

Backport necessary changes to 1.0.x

See merge request !271
parents 70363c61 698e3174
No related branches found
No related tags found
1 merge request!271Backport necessary changes to 1.0.x
Pipeline #220737 passed
Showing
with 94 additions and 40 deletions
...@@ -64,10 +64,10 @@ start-tunnel: ...@@ -64,10 +64,10 @@ start-tunnel:
release-autograde: release-autograde:
docker buildx build --platform linux/amd64,linux/arm64 --push -t autograde/autograde-service:1.0.3 autograde-service/ docker buildx build --platform linux/amd64,linux/arm64 --push -t autograde/autograde-service:1.0.4 autograde-service/
release-moodle: release-moodle:
docker buildx build --platform linux/amd64,linux/arm64 --push -t autograde/moodle:1.0.3 -f Dockerfile-moodle-with-autograde ./ docker buildx build --platform linux/amd64,linux/arm64 --push -t autograde/moodle:1.0.4 -f Dockerfile-moodle-with-autograde ./
release-submission-manager: release-submission-manager:
docker buildx build --platform linux/amd64,linux/arm64 --push -t autograde/submission-manager:1.0.3 autograde-submission-manager/ docker buildx build --platform linux/amd64,linux/arm64 --push -t autograde/submission-manager:1.0.4 autograde-submission-manager/
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<!-- HR : Project definition--> <!-- HR : Project definition-->
<groupId>ch.epfl.autograde</groupId> <groupId>ch.epfl.autograde</groupId>
<artifactId>autograde-service</artifactId> <artifactId>autograde-service</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
<name>autograde-service</name> <name>autograde-service</name>
<description> <description>
......
package ch.epfl.autograde; package ch.epfl.autograde;
import ch.epfl.autograde.config.properties.AutogradeConfigProperties;
import ch.epfl.autograde.config.properties.MoodleConfigProperties;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
/** /**
* ??? * ???
...@@ -12,7 +10,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -12,7 +10,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
* @author Hamza REMMAL (hamza.remmal@epfl.ch) * @author Hamza REMMAL (hamza.remmal@epfl.ch)
*/ */
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties({AutogradeConfigProperties.class, MoodleConfigProperties.class}) @ConfigurationPropertiesScan
public class AutogradeServiceApplication { public class AutogradeServiceApplication {
/** /**
......
package ch.epfl.autograde.api.v1.model;
/**
*
* @since 1.1.0
* @see <a href="https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy">Kubernetes Official Documentation</a>
*/
public enum ImagePullPolicy {
Never,
Always,
IfNotPresent
}
package ch.epfl.autograde.api.v1.service; package ch.epfl.autograde.api.v1.service;
import ch.epfl.autograde.config.properties.AutogradeConfigProperties; import ch.epfl.autograde.properties.AutogradeConfigProperties;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
package ch.epfl.autograde.api.v1.service; package ch.epfl.autograde.api.v1.service;
import ch.epfl.autograde.api.v1.entity.SubmissionInfo; import ch.epfl.autograde.api.v1.entity.SubmissionInfo;
import ch.epfl.autograde.properties.AutogradeJobConfig;
import ch.epfl.autograde.properties.AutogradeJobImageConfig;
import ch.epfl.autograde.properties.AutogradeManagerConfig;
import ch.epfl.autograde.utils.KubernetesPreprocessor; import ch.epfl.autograde.utils.KubernetesPreprocessor;
import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.api.model.batch.v1.Job; import io.fabric8.kubernetes.api.model.batch.v1.Job;
import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder; import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder;
import io.fabric8.kubernetes.api.model.batch.v1.JobSpecBuilder; import io.fabric8.kubernetes.api.model.batch.v1.JobSpecBuilder;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Map; import java.util.Map;
...@@ -23,6 +25,7 @@ import static java.lang.String.valueOf; ...@@ -23,6 +25,7 @@ import static java.lang.String.valueOf;
*/ */
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor
public final class KubernetesJobService { public final class KubernetesJobService {
/** Client to communicate with the underlying k8s cluster */ /** Client to communicate with the underlying k8s cluster */
...@@ -39,7 +42,11 @@ public final class KubernetesJobService { ...@@ -39,7 +42,11 @@ public final class KubernetesJobService {
private final AutogradeService autograde; private final AutogradeService autograde;
/** Namespace to run the jobs in - where the current instance of autograde lives in */ /** Namespace to run the jobs in - where the current instance of autograde lives in */
private final String JOBS_NAMESPACE; private final AutogradeJobConfig jobConfig;
private final AutogradeJobImageConfig jobImageConfig;
private final AutogradeManagerConfig managerConfig;
/** Enum to represent the different states of a grading job */ /** Enum to represent the different states of a grading job */
public enum JobStatus { public enum JobStatus {
...@@ -53,21 +60,6 @@ public final class KubernetesJobService { ...@@ -53,21 +60,6 @@ public final class KubernetesJobService {
NOT_FOUND NOT_FOUND
} }
@Autowired
public KubernetesJobService(KubernetesClient k8s,
KubernetesSecretService secrets,
MoodleWebService moodle,
IntegrityService integrity,
AutogradeService autograde,
@Value("${autograde.jobs.namespace}") String namespace) {
this.k8s = k8s;
this.secrets = secrets;
this.moodle = moodle;
this.integrity = integrity;
this.autograde = autograde;
this.JOBS_NAMESPACE = namespace;
}
public String create_grading_submission_job(int id) { public String create_grading_submission_job(int id) {
// Generate the job name // Generate the job name
var jobName = get_job_name(id); var jobName = get_job_name(id);
...@@ -103,7 +95,7 @@ public final class KubernetesJobService { ...@@ -103,7 +95,7 @@ public final class KubernetesJobService {
k8s.batch() k8s.batch()
.v1() .v1()
.jobs() .jobs()
.inNamespace(JOBS_NAMESPACE) .inNamespace(jobConfig.namespace())
.resource(job) .resource(job)
.create(); .create();
} catch (Exception e) { } catch (Exception e) {
...@@ -125,7 +117,7 @@ public final class KubernetesJobService { ...@@ -125,7 +117,7 @@ public final class KubernetesJobService {
var job = k8s.batch() var job = k8s.batch()
.v1() .v1()
.jobs() .jobs()
.inNamespace(JOBS_NAMESPACE) .inNamespace(jobConfig.namespace())
.withName(jobName) .withName(jobName)
.get(); .get();
if (job == null) { if (job == null) {
...@@ -191,6 +183,7 @@ public final class KubernetesJobService { ...@@ -191,6 +183,7 @@ public final class KubernetesJobService {
return new ContainerBuilder() return new ContainerBuilder()
.withName("init") .withName("init")
.withImage(autograde.getSubmissionManager()) .withImage(autograde.getSubmissionManager())
.withImagePullPolicy(managerConfig.pullPolicy().toString())
.withCommand("java", "-jar", "autograde-submission-manager.jar", .withCommand("java", "-jar", "autograde-submission-manager.jar",
autograde.getUrl(), autograde.getUrl(),
autograde.api_key(), autograde.api_key(),
...@@ -225,7 +218,7 @@ public final class KubernetesJobService { ...@@ -225,7 +218,7 @@ public final class KubernetesJobService {
return new ContainerBuilder() return new ContainerBuilder()
.withName("grader") .withName("grader")
.withImage(image_name) .withImage(image_name)
.withImagePullPolicy("Always") .withImagePullPolicy(jobImageConfig.pullPolicy().toString())
.withVolumeMounts(new VolumeMountBuilder() .withVolumeMounts(new VolumeMountBuilder()
.withName(volume.getName()) .withName(volume.getName())
.withMountPath("/data") .withMountPath("/data")
...@@ -257,6 +250,7 @@ public final class KubernetesJobService { ...@@ -257,6 +250,7 @@ public final class KubernetesJobService {
return new ContainerBuilder() return new ContainerBuilder()
.withName("cleanup") .withName("cleanup")
.withImage(autograde.getSubmissionManager()) .withImage(autograde.getSubmissionManager())
.withImagePullPolicy(managerConfig.pullPolicy().toString())
.withCommand("java", "-jar", "autograde-submission-manager.jar", .withCommand("java", "-jar", "autograde-submission-manager.jar",
autograde.getUrl(), autograde.getUrl(),
autograde.api_key(), autograde.api_key(),
...@@ -329,7 +323,7 @@ public final class KubernetesJobService { ...@@ -329,7 +323,7 @@ public final class KubernetesJobService {
.build()) .build())
.build()) .build())
.withBackoffLimit(2) // failed jobs can be retried twice .withBackoffLimit(2) // failed jobs can be retried twice
.withTtlSecondsAfterFinished(60 * 60 * 2) // 2 hours .withTtlSecondsAfterFinished(jobConfig.ttl()) // 2 hours
.build()) .build())
.build(); .build();
} }
......
...@@ -3,7 +3,7 @@ package ch.epfl.autograde.api.v1.service; ...@@ -3,7 +3,7 @@ package ch.epfl.autograde.api.v1.service;
import ch.epfl.autograde.api.v1.entity.AssignmentInfo; import ch.epfl.autograde.api.v1.entity.AssignmentInfo;
import ch.epfl.autograde.api.v1.entity.MoodleFile; import ch.epfl.autograde.api.v1.entity.MoodleFile;
import ch.epfl.autograde.api.v1.entity.SubmissionInfo; import ch.epfl.autograde.api.v1.entity.SubmissionInfo;
import ch.epfl.autograde.config.properties.MoodleConfigProperties; import ch.epfl.autograde.properties.MoodleConfigProperties;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -118,7 +118,7 @@ public final class MoodleWebService { ...@@ -118,7 +118,7 @@ public final class MoodleWebService {
"grade", grade, "grade", grade,
"files", new ObjectMapper().writeValueAsString(feedback) "files", new ObjectMapper().writeValueAsString(feedback)
); );
System.out.println(new ObjectMapper().writeValueAsString(feedback));
// HR : Call the moodle web service // HR : Call the moodle web service
var response = call(FUNCTION_NAME, params, ofString()); var response = call(FUNCTION_NAME, params, ofString());
log.info("call to moodle_upload_feedback returned {}", response.body()); log.info("call to moodle_upload_feedback returned {}", response.body());
......
package ch.epfl.autograde.config.properties; package ch.epfl.autograde.properties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
......
package ch.epfl.autograde.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "autograde.job")
public record AutogradeJobConfig (
String namespace,
int ttl
){}
package ch.epfl.autograde.properties;
import ch.epfl.autograde.api.v1.model.ImagePullPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "autograde.job.image")
public record AutogradeJobImageConfig(
ImagePullPolicy pullPolicy
){}
package ch.epfl.autograde.properties;
import ch.epfl.autograde.api.v1.model.ImagePullPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "autograde.manager")
public record AutogradeManagerConfig(
String image,
ImagePullPolicy pullPolicy
) {
}
package ch.epfl.autograde.config.properties; package ch.epfl.autograde.properties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
......
...@@ -3,4 +3,23 @@ logging.level.ch.epfl.cs107=${GRADING_SERVICE_LOG_LEVEL:-DEBUG} ...@@ -3,4 +3,23 @@ logging.level.ch.epfl.cs107=${GRADING_SERVICE_LOG_LEVEL:-DEBUG}
management.endpoint.health.enabled=true management.endpoint.health.enabled=true
management.endpoints.web.exposure.include=health management.endpoints.web.exposure.include=health
management.endpoint.health.show-details=always management.endpoint.health.show-details=always
autograde.version=@project.version@ autograde.version=@project.version@
\ No newline at end of file
# To keep it inline with the value in v1.0.1, v1.0.2 and v1.0.3
# Note: Default in v1.0.0 was 2 days
autograde.job.ttl=7200
# Renaming of the variable, keeping the old env variable compatibility
# with v1.0.0, v1.0.1, v1.0.2 and v1.0.3
# Note: Old name is not a default starting from v1.1.0
autograde.job.namespace=${AUTOGRADE_JOBS_NAMESPACE}
# Default value to keep it working when migrating from v1.0.0 to v1.0.3
# Note: Default value starting from v1.2.0 is `if-not-present`
autograde.job.image.pull-policy=always
# v1.0.0 up to v1.0.3 will default for `always` in case the tag is `latest`
# and to `if-not-present` otherwise.
# We choose to default to `if-not-present` since we have never used the `latest` tag
# Note: v1.2.x will default to `never`
autograde.manager.pull-policy=ifnotpresent
\ No newline at end of file
package ch.epfl.autograde.config.properties; package ch.epfl.autograde.config.properties;
import ch.epfl.autograde.properties.AutogradeConfigProperties;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
package ch.epfl.autograde.config.properties; package ch.epfl.autograde.config.properties;
import ch.epfl.autograde.properties.MoodleConfigProperties;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>ch.epfl.autograde</groupId> <groupId>ch.epfl.autograde</groupId>
<artifactId>autograde-submission-manager</artifactId> <artifactId>autograde-submission-manager</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
......
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024103100; // HR : October 31st, 2024 $plugin->version = 2024110400; // HR : November 4th, 2024
$plugin->requires = 2022112800; // HR : Moodle 4.1.0 (https://moodledev.io/general/releases#moodle-41-lts) $plugin->requires = 2022112800; // HR : Moodle 4.1.0 (https://moodledev.io/general/releases#moodle-41-lts)
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.0.2'; $plugin->release = '1.0.4';
$plugin->component = 'assignsubmission_autograde'; $plugin->component = 'assignsubmission_autograde';
$plugin->dependencies = array( $plugin->dependencies = array(
'mod_assign' => '2022112800', 'mod_assign' => '2022112800',
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<!-- HR : Project definition--> <!-- HR : Project definition-->
<groupId>ch.epfl.autograde</groupId> <groupId>ch.epfl.autograde</groupId>
<artifactId>autograde</artifactId> <artifactId>autograde</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
<name>autograde</name> <name>autograde</name>
<packaging>pom</packaging> <packaging>pom</packaging>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment