-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project revamp and docker integration #251
Changes from 7 commits
744c649
3de42d8
9b9151e
7f946da
355aa0f
7184232
1b19348
25c4a1a
6021861
e8ef87e
1c840ca
8f04b8d
b65e433
ad2ee51
7a54c9c
e306fc3
6aa5957
adff602
133e658
7121013
b0377a9
d669531
fd00a86
5e4d1ee
c35e8cb
59c24ca
b672fda
cc22cdd
5e1b86a
1630a15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
import com.ugent.pidgeon.model.json.GroupJson; | ||
import com.ugent.pidgeon.model.json.LastGroupSubmissionJson; | ||
import com.ugent.pidgeon.model.json.SubmissionJson; | ||
import com.ugent.pidgeon.model.submissionTesting.DockerOutput; | ||
import com.ugent.pidgeon.model.submissionTesting.DockerSubmissionTestModel; | ||
import com.ugent.pidgeon.model.submissionTesting.DockerTestOutput; | ||
import com.ugent.pidgeon.model.submissionTesting.SubmissionTemplateModel; | ||
import com.ugent.pidgeon.postgre.models.*; | ||
import com.ugent.pidgeon.postgre.models.types.UserRole; | ||
|
@@ -30,7 +33,7 @@ | |
import java.util.zip.ZipFile; | ||
|
||
@RestController | ||
public class SubmissionController { | ||
public class SubmissionController { | ||
|
||
@Autowired | ||
private GroupRepository groupRepository; | ||
|
@@ -58,20 +61,52 @@ public class SubmissionController { | |
|
||
|
||
private SubmissionTemplateModel.SubmissionResult runStructureTest(ZipFile file, TestEntity testEntity) throws IOException { | ||
// Get the test file from the server | ||
FileEntity testfileEntity = fileRepository.findById(testEntity.getStructureTestId()).orElse(null); | ||
if (testfileEntity == null) { | ||
// There is no structure test for this project | ||
if(testEntity.getStructureTemplate() == null){ | ||
return null; | ||
} | ||
String testfile = Filehandler.getStructureTestString(Path.of(testfileEntity.getPath())); | ||
String structureTemplateString = testEntity.getStructureTemplate(); | ||
|
||
// Parse the file | ||
SubmissionTemplateModel model = new SubmissionTemplateModel(); | ||
model.parseSubmissionTemplate(testfile); | ||
|
||
model.parseSubmissionTemplate(structureTemplateString); | ||
return model.checkSubmission(file); | ||
} | ||
|
||
private DockerOutput runDockerTest(ZipFile file, TestEntity testEntity, Path outputPath) throws IOException { | ||
|
||
// Get the test file from the server | ||
String testScript = testEntity.getDockerTestScript(); | ||
String testTemplate = testEntity.getDockerTestTemplate(); | ||
String image = testEntity.getDockerImage(); | ||
|
||
// The first script must always be null, otherwise there is nothing to run on the container | ||
if(testScript == null){ | ||
return null; | ||
} | ||
|
||
// Init container and add input files | ||
DockerSubmissionTestModel model = new DockerSubmissionTestModel(image); | ||
model.addZipInputFiles(file); | ||
|
||
// Copy artifacts to the destination | ||
List<File> artifacts = model.getArtifacts(); | ||
|
||
// filehandler copy zips | ||
Filehandler.copyFilesAsZip(artifacts, outputPath); | ||
|
||
// cleanup docker | ||
model.cleanUp(); | ||
|
||
if(testTemplate == null){ | ||
// This docker test is configured in the simple mode (store test console logs) | ||
return model.runSubmission(testScript); | ||
}else{ | ||
// This docker test is configured in the template mode (store json with feedback) | ||
return model.runSubmissionWithTemplate(testScript, testTemplate); | ||
} | ||
} | ||
|
||
/** | ||
* Function to get a submission by its ID | ||
* | ||
|
@@ -170,7 +205,6 @@ public ResponseEntity<?> submitFile(@RequestParam("file") MultipartFile file, @P | |
|
||
long groupId = checkResult.getData(); | ||
|
||
//TODO: execute the docker tests onces these are implemented | ||
try { | ||
//Save the file entry in the database to get the id | ||
FileEntity fileEntity = new FileEntity("", "", userId); | ||
|
@@ -203,24 +237,39 @@ public ResponseEntity<?> submitFile(@RequestParam("file") MultipartFile file, @P | |
|
||
// Run structure tests | ||
TestEntity testEntity = testRepository.findByProjectId(projectid).orElse(null); | ||
SubmissionTemplateModel.SubmissionResult testresult; | ||
SubmissionTemplateModel.SubmissionResult structureTestResult; | ||
DockerOutput dockerOutput; | ||
if (testEntity == null) { | ||
Logger.getLogger("SubmissionController").info("no test"); | ||
testresult = new SubmissionTemplateModel.SubmissionResult(true, "No structure requirements for this project."); | ||
Logger.getLogger("SubmissionController").info("no tests"); | ||
submission.setStructureFeedback("No specific structure requested for this project."); | ||
submission.setStructureAccepted(true); | ||
} else { | ||
testresult = runStructureTest(new ZipFile(savedFile), testEntity); | ||
} | ||
if (testresult == null) { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error while running tests: test files not found"); | ||
|
||
// Check file structure | ||
structureTestResult = runStructureTest(new ZipFile(savedFile), testEntity); | ||
if (structureTestResult == null) { | ||
submission.setStructureFeedback( | ||
"No specific structure requested for this project."); | ||
submission.setStructureAccepted(true); | ||
} else { | ||
submission.setStructureAccepted(structureTestResult.passed); | ||
submission.setStructureFeedback(structureTestResult.feedback); | ||
} | ||
// Check if docker tests succeed | ||
dockerOutput = runDockerTest(new ZipFile(savedFile), testEntity, Filehandler.getSubmissionPath(projectid, groupId, submission.getId())); | ||
if (dockerOutput == null) { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body("Error while running docker tests."); | ||
} | ||
// Representation of dockerOutput, this will be a json(easily displayable in frontend) if it is a template test | ||
// or a string if it is a simple test | ||
submission.setDockerFeedback(dockerOutput.toString()); | ||
submission.setDockerAccepted(dockerOutput.isAllowed()); | ||
} | ||
submission.setTestFinished(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dit is niet helemaal hoe ik het in gedachten had. Dit heeft nu vrij weinig nut want op het moment dat de frontend de response krijgt is de volledige dockertest dus al gerund en zal dit veld dus altijd true zijn. Tis eerder de bedoeling dat er een reponse wordt teruggegeven waar dit dus default op false staat en dat dan in de achtergrond de dockertesten gerunt worden & dit veld geupdate wordt. Op deze manier kan de user al feedback krijgen over de structure test terwijl de docker testen aan het runnen zijn. |
||
submissionRepository.save(submissionEntity); | ||
// Update the submission with the test resultsetAccepted | ||
submission.setStructureAccepted(testresult.passed); | ||
// Update the dataabse | ||
submission = submissionRepository.save(submission); | ||
|
||
// Update the submission with the test feedbackfiles | ||
submission.setDockerFeedback("TEMP DOCKER FEEDBACK"); | ||
submission.setStructureFeedback(testresult.feedback); | ||
submissionRepository.save(submission); | ||
|
||
return ResponseEntity.ok(entityToJsonConverter.getSubmissionJson(submissionEntity)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ksnap nie helemaal hoe de artifacts gekopieërd worden voordat het script gelopen wordt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad dit is een logic error. Het kopieeren gebeurd 5 lines erboven maar mijn order of execution was verkeerd.