Search in sources :

Example 21 with ProgrammingExerciseStudentParticipation

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());
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 22 with ProgrammingExerciseStudentParticipation

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;
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 23 with ProgrammingExerciseStudentParticipation

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());
        }
    });
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 24 with ProgrammingExerciseStudentParticipation

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;
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 25 with 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);
    }
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Submission(de.tum.in.www1.artemis.domain.Submission) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)58 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 WithMockUser (org.springframework.security.test.context.support.WithMockUser)24 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)20 Test (org.junit.jupiter.api.Test)20 Result (de.tum.in.www1.artemis.domain.Result)18 BeforeEach (org.junit.jupiter.api.BeforeEach)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ZonedDateTime (java.time.ZonedDateTime)16 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Feedback (de.tum.in.www1.artemis.domain.Feedback)14 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)14 ModelFactory (de.tum.in.www1.artemis.util.ModelFactory)14 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)14 List (java.util.List)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AfterEach (org.junit.jupiter.api.AfterEach)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)12