use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class AutomaticProgrammingExerciseCleanupService method deleteBuildPlans.
private void deleteBuildPlans(Set<ProgrammingExerciseStudentParticipation> participationsWithBuildPlanToDelete) {
// Limit to 5000 deletions per night
List<ProgrammingExerciseStudentParticipation> actualParticipationsToClean = participationsWithBuildPlanToDelete.stream().limit(5000).toList();
List<String> buildPlanIds = actualParticipationsToClean.stream().map(ProgrammingExerciseStudentParticipation::getBuildPlanId).toList();
log.info("Build plans to cleanup: {}", buildPlanIds);
int index = 0;
for (ProgrammingExerciseStudentParticipation participation : actualParticipationsToClean) {
if (index > 0 && index % externalSystemRequestBatchSize == 0) {
try {
log.info("Sleep for {}s during cleanupBuildPlansOnContinuousIntegrationServer", externalSystemRequestBatchWaitingTime / 1000);
Thread.sleep(externalSystemRequestBatchWaitingTime);
} catch (InterruptedException ex) {
log.error("Exception encountered when pausing before cleaning up build plans", ex);
}
}
try {
participationService.cleanupBuildPlan(participation);
} catch (Exception ex) {
log.error("Could not cleanup build plan in participation " + participation.getId(), ex);
}
index++;
}
log.info("{} build plans have been cleaned", actualParticipationsToClean.size());
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingExerciseScheduleService method invokeOperationOnAllParticipationsThatSatisfy.
/**
* Invokes the given <code>operation</code> on all student participations that satisfy the <code>condition</code>-{@link Predicate}.
* <p>
*
* @param programmingExerciseId the programming exercise whose participations should be processed
* @param operation the operation to perform
* @param condition the condition that tests whether to invoke the operation on a participation
* @param operationName the name of the operation, this is only used for logging
* @return a list containing all participations for which the operation has failed with an exception
* @throws EntityNotFoundException if the programming exercise can't be found.
*/
private List<ProgrammingExerciseStudentParticipation> invokeOperationOnAllParticipationsThatSatisfy(Long programmingExerciseId, BiConsumer<ProgrammingExercise, ProgrammingExerciseStudentParticipation> operation, Predicate<ProgrammingExerciseStudentParticipation> condition, String operationName) {
log.info("Invoking (scheduled) task '{}' for programming exercise with id {}.", operationName, programmingExerciseId);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findWithEagerStudentParticipationsById(programmingExerciseId).orElseThrow(() -> new EntityNotFoundException("ProgrammingExercise", programmingExerciseId));
List<ProgrammingExerciseStudentParticipation> failedOperations = new ArrayList<>();
for (StudentParticipation studentParticipation : programmingExercise.getStudentParticipations()) {
ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
try {
if (condition.test(programmingExerciseStudentParticipation)) {
operation.accept(programmingExercise, programmingExerciseStudentParticipation);
}
} catch (Exception e) {
log.error(String.format("'%s' failed for programming exercise with id %d for student repository with participation id %d", operationName, programmingExercise.getId(), studentParticipation.getId()), e);
failedOperations.add(programmingExerciseStudentParticipation);
}
}
return failedOperations;
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingExerciseScheduleService method scheduleBuildAndTestAfterDueDateForParticipation.
private void scheduleBuildAndTestAfterDueDateForParticipation(ProgrammingExerciseStudentParticipation participation) {
scheduleService.scheduleParticipationTask(participation, ParticipationLifecycle.BUILD_AND_TEST_AFTER_DUE_DATE, () -> {
final ProgrammingExercise exercise = participation.getProgrammingExercise();
SecurityUtils.setAuthorizationObject();
try {
log.info("Invoking scheduled task for participation {} in programming exercise with id {}.", participation.getId(), exercise.getId());
programmingSubmissionService.triggerBuildForParticipations(List.of(participation));
} catch (EntityNotFoundException ex) {
log.error("Programming participation with id {} in exercise {} is no longer available in database for use in scheduled task.", participation.getId(), exercise.getId());
}
});
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingSubmissionResultSimulationService method createParticipation.
/**
* This method creates a new participation for the provided user
* This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
* @param programmingExercise the used programmingExercise
* @param participant the participant object of the user
* @param user the user who wants to participate
* @return the newly created and stored participation
*/
public ProgrammingExerciseStudentParticipation createParticipation(ProgrammingExercise programmingExercise, Participant participant, User user) {
ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation = new ProgrammingExerciseStudentParticipation();
programmingExerciseStudentParticipation.setBuildPlanId(programmingExercise.getProjectKey() + "-" + user.getLogin().toUpperCase());
programmingExerciseStudentParticipation.setParticipant(participant);
programmingExerciseStudentParticipation.setInitializationState(InitializationState.INITIALIZED);
programmingExerciseStudentParticipation.setRepositoryUrl("http://" + user.getLogin() + "@" + programmingExerciseSimulationService.domain + programmingExercise.getProjectKey() + "/" + programmingExercise.getProjectKey().toLowerCase() + "-" + user.getLogin() + ".git");
programmingExerciseStudentParticipation.setInitializationDate(ZonedDateTime.now());
programmingExerciseStudentParticipation.setProgrammingExercise(programmingExercise);
participationRepository.save(programmingExerciseStudentParticipation);
return programmingExerciseStudentParticipation;
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingExerciseTest method findAppropriateSubmissionRespectingIndividualDueDate.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void findAppropriateSubmissionRespectingIndividualDueDate(boolean isSubmissionAfterIndividualDueDate) {
ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(programmingExerciseId);
exercise.setDueDate(ZonedDateTime.now());
exercise = programmingExerciseRepository.save(exercise);
ProgrammingSubmission submission = new ProgrammingSubmission();
submission.setType(SubmissionType.OTHER);
if (isSubmissionAfterIndividualDueDate) {
submission.setSubmissionDate(ZonedDateTime.now().plusHours(26));
} else {
// submission time after exercise due date but before individual due date
submission.setSubmissionDate(ZonedDateTime.now().plusHours(1));
}
submission = database.addProgrammingSubmission(exercise, submission, "student1");
ProgrammingExerciseStudentParticipation participation = participationRepository.findByExerciseIdAndStudentLogin(programmingExerciseId, "student1").get();
participation.setIndividualDueDate(ZonedDateTime.now().plusDays(1));
submission.setParticipation(participation);
Submission latestValidSubmission = exercise.findAppropriateSubmissionByResults(Set.of(submission));
if (isSubmissionAfterIndividualDueDate) {
assertThat(latestValidSubmission).isNull();
} else {
assertThat(latestValidSubmission).isEqualTo(submission);
}
}
Aggregations