Skip to content

Commit

Permalink
Made image uninstall happen threaded. Changed validTemplate so at lea…
Browse files Browse the repository at this point in the history
…st one Test is required. Added docker image check to testCheck
  • Loading branch information
Triver1 committed May 8, 2024
1 parent 7a54c9c commit e306fc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ private ResponseEntity<?> alterTests(
//Update fields
if (dockerImage != null || !httpMethod.equals(HttpMethod.PATCH)) {
testEntity.setDockerImage(dockerImage);
if (dockerImage == null && !testRepository.imageIsUsed(dockerImage)) {
DockerSubmissionTestModel.removeDockerImage(
dockerImage); //TODO: move this to different thread if takes a while
if (!testRepository.imageIsUsed(dockerImage)) {
// Do it on a different thread
String finalDockerImage1 = dockerImage;
CompletableFuture.runAsync(() -> {
DockerSubmissionTestModel.removeDockerImage(
finalDockerImage1);
});

}
}
if (dockerScript != null || !httpMethod.equals(HttpMethod.PATCH)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,15 @@ public static boolean isValidTemplate(String template) {
// lines with @ should be the first of a string
// @ is always the first character
// ">" options under the template should be "required, optional or description="..."
boolean atLeastOne = false; // Template should not be empty
String[] lines = template.split("\n");
if (lines[0].charAt(0) != '@') {
return false;
}
boolean isConfigurationLine = false;
for (String line : lines) {
if (line.charAt(0) == '@') {
atLeastOne = true;
isConfigurationLine = true;
continue;
}
Expand All @@ -314,7 +316,7 @@ public static boolean isValidTemplate(String template) {
}
}
}
return true;
return atLeastOne;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public TestEntity getTestIfExists(long projectId) {
* @param dockerImage docker image for the test
* @param dockerScript docker script for the test
* @param dockerTemplate docker template for the test
* @param structureTemplate structure template for the test
* @param httpMethod http method used to update the test
* @return CheckResult with the status of the check and the test and project
*/
Expand Down Expand Up @@ -85,8 +84,8 @@ public CheckResult<Pair<TestEntity, ProjectEntity>> checkForTestUpdate(
return new CheckResult<>(HttpStatus.BAD_REQUEST, "A test script is required in a docker test.", null);
}

if(!httpMethod.equals(HttpMethod.PATCH) && dockerScript != null && dockerImage == null) {
return new CheckResult<>(HttpStatus.BAD_REQUEST, "A docker image is required in a docker test.", null);
if(!httpMethod.equals(HttpMethod.PATCH) && dockerScript != null && dockerImage == null && DockerSubmissionTestModel.imageExists(dockerImage)) {
return new CheckResult<>(HttpStatus.BAD_REQUEST, "A valid docker image is required in a docker test.", null);
}

if (!httpMethod.equals(HttpMethod.PATCH) && dockerTemplate != null && dockerScript == null) {
Expand Down

0 comments on commit e306fc3

Please sign in to comment.