コード例 #1
0
def re_run_all_submissions_in_phase(phase_pk):
    phase = CompetitionPhase.objects.get(id=phase_pk)

    # Remove duplicate submissions this ugly way because MySQL distinct doesn't work...
    submissions_with_duplicates = CompetitionSubmission.objects.filter(phase=phase)
    submissions_without_duplicates = []
    file_names_seen = []

    for submission in submissions_with_duplicates:
        if submission.file.name not in file_names_seen:
            if settings.USE_AWS:
                file_names_seen.append(submission.s3_file)
            else:
                file_names_seen.append(submission.file.name)
            submissions_without_duplicates.append(submission)

    for submission in submissions_without_duplicates:
        if settings.USE_AWS:
            file_kwarg = {'s3_file': submission.s3_file}
        else:
            file_kwarg = {'file': submission.file}

        new_submission = CompetitionSubmission(
            participant=submission.participant,
            phase=submission.phase,
            docker_image=submission.docker_image,
            **file_kwarg
        )
        new_submission.save(ignore_submission_limits=True)

        evaluate_submission.apply_async((new_submission.pk, submission.phase.is_scoring_only))
コード例 #2
0
 def test_submission_valid_not_retried_again(self):
     # Mark submission for retry
     submission = CompetitionSubmission(phase=self.phase, participant=self.participant, chahub_needs_retry=True)
     with mock.patch('apps.chahub.models.send_to_chahub') as send_to_chahub_mock:
         send_to_chahub_mock.return_value = HttpResponseBase(status=201)
         send_to_chahub_mock.return_value.content = ""
         submission.save()  # NOTE! not called with force_to_chahub=True as retrying would set
         # It does not call send method, only during "do_retries" task should it
         assert not send_to_chahub_mock.called
コード例 #3
0
    def test_submission_invalid_not_marked_for_retry_again(self):
        # Make submission invalid
        self.competition.published = False
        self.competition.save()

        # Mark submission for retry
        submission = CompetitionSubmission(phase=self.phase, participant=self.participant, chahub_needs_retry=True)
        with mock.patch('apps.chahub.models.send_to_chahub') as send_to_chahub_mock:
            submission.save()
            assert not send_to_chahub_mock.called
コード例 #4
0
    def test_submission_invalid_not_sent_to_chahub(self):
        # Make submission invalid
        self.competition.published = False
        self.competition.save()

        submission = CompetitionSubmission(phase=self.phase,
                                           participant=self.participant)
        with mock.patch('apps.web.models.CompetitionSubmission.send_to_chahub'
                        ) as send_to_chahub_mock:
            submission.save()
            assert not send_to_chahub_mock.called
コード例 #5
0
ファイル: add_submission.py プロジェクト: Dryuna/codalab
    def handle(self, *args, **options):
        competition_id = options['competition']
        phase_id = options['phase']
        submission = options['submission']
        competition = None
        phase = None
        if not options['email']:
            print " ERROR ... Email Required ... "
            exit(1)
        if not submission:
            print " ERROR ... Submission File Required ... "
            exit(1)

        user = User.objects.get(email=options['email'])
        while not competition and not phase:
            if competition_id and phase_id:
                try:
                    phase = CompetitionPhase.objects.get(
                        pk=phase_id, competition__pk=competition_id)
                    break
                except Competition.DoesNotExist:
                    pass
            else:
                print "Competition/Phase not specified or not valid:\n"

            clist = CompetitionPhase.objects.order_by('competition__pk').all()
            if not clist:
                print " ... There are no competitions ..."
                exit(1)
            sel = []
            i = 0
            for c in clist:
                sel.append((c.competition, c))
                i = i + 1
                print "%d) %s %s" % (i, c.competition, c)
            try:
                inp = int(raw_input("\n Enter number --> "))
                idx = inp - 1
                competition = sel[idx][0]
                phase = sel[idx][1]
            except ValueError:
                print " ... Bad Input ... "
                competition_id = None
                continue
            except Exception as e:
                print e

        part = CompetitionParticipant.objects.get(user=user,
                                                  competition=competition
                                                  )
        submission_file = File(open(options['submission'], 'rb'))
        s = CompetitionSubmission(
            participant=part, phase=phase, file=submission_file)
        s.save()
コード例 #6
0
    def handle(self, *args, **options):
        competition_id = options['competition']
        phase_id = options['phase']
        submission = options['submission']
        competition = None
        phase = None
        if not options['email']:
            print " ERROR ... Email Required ... "
            exit(1)
        if not submission:
            print " ERROR ... Submission File Required ... "
            exit(1)

        user = User.objects.get(email=options['email'])
        while not competition and not phase:
            if competition_id and phase_id:
                try:
                    phase = CompetitionPhase.objects.get(
                        pk=phase_id, competition__pk=competition_id)
                    break
                except Competition.DoesNotExist:
                    pass
            else:
                print "Competition/Phase not specified or not valid:\n"

            clist = CompetitionPhase.objects.order_by('competition__pk').all()
            if not clist:
                print " ... There are no competitions ..."
                exit(1)
            sel = []
            i = 0
            for c in clist:
                sel.append((c.competition, c))
                i = i + 1
                print "%d) %s %s" % (i, c.competition, c)
            try:
                inp = int(raw_input("\n Enter number --> "))
                idx = inp - 1
                competition = sel[idx][0]
                phase = sel[idx][1]
            except ValueError:
                print " ... Bad Input ... "
                competition_id = None
                continue
            except Exception as e:
                print e

        part = CompetitionParticipant.objects.get(user=user,
                                                  competition=competition)
        submission_file = File(open(options['submission'], 'rb'))
        s = CompetitionSubmission(participant=part,
                                  phase=phase,
                                  file=submission_file)
        s.save()
コード例 #7
0
 def test_submission_valid_not_retried_again(self):
     # Mark submission for retry
     submission = CompetitionSubmission(phase=self.phase,
                                        participant=self.participant,
                                        chahub_needs_retry=True)
     with mock.patch('apps.web.models.CompetitionSubmission.send_to_chahub'
                     ) as send_to_chahub_mock:
         send_to_chahub_mock.return_value = HttpResponseBase(status=201)
         send_to_chahub_mock.return_value.content = ""
         submission.save(
         )  # NOTE! not called with force_to_chahub=True as retrying would set
         # It does not call send method, only during "do_retries" task should it
         assert not send_to_chahub_mock.called
コード例 #8
0
    def test_submission_invalid_not_marked_for_retry_again(self):
        # Make submission invalid
        self.competition.published = False
        self.competition.save()

        # Mark submission for retry
        submission = CompetitionSubmission(phase=self.phase,
                                           participant=self.participant,
                                           chahub_needs_retry=True)
        with mock.patch(
                'apps.chahub.models.send_to_chahub') as send_to_chahub_mock:
            submission.save()
            assert not send_to_chahub_mock.called
コード例 #9
0
    def test_submission_mixin_save_doesnt_resend_same_data(self):
        submission = CompetitionSubmission(phase=self.phase, participant=self.participant)
        with mock.patch('apps.chahub.models.send_to_chahub') as send_to_chahub_mock:
            send_to_chahub_mock.return_value = HttpResponseBase(status=201)
            send_to_chahub_mock.return_value.content = ""
            submission.save()
            # attempts to send to Chahub once
            assert send_to_chahub_mock.called

            # reset
            send_to_chahub_mock.called = False

            # does not call again
            submission.save()
            assert not send_to_chahub_mock.called
コード例 #10
0
    def test_submission_invalid_not_marked_for_retry_again(self):
        # Make submission invalid
        self.competition.published = False
        self.competition.save()

        # Mark submission for retry
        submission = CompetitionSubmission(phase=self.phase,
                                           participant=self.participant,
                                           chahub_needs_retry=True)
        with mock.patch('apps.web.models.CompetitionSubmission.send_to_chahub'
                        ) as send_to_chahub_mock:
            submission.save()
            assert not send_to_chahub_mock.called
            # It did need retry, but since it's invalid it should be unmarked for retry
            assert not CompetitionSubmission.objects.get(
                pk=submission.pk).chahub_needs_retry
コード例 #11
0
    def test_submission_retry_valid_retried_then_sent_and_not_retried_again(self):
        # Mark submission for retry
        submission = CompetitionSubmission(phase=self.phase, participant=self.participant, chahub_needs_retry=True)
        with mock.patch('apps.chahub.models.send_to_chahub') as send_to_chahub_mock:
            send_to_chahub_mock.return_value = HttpResponseBase(status=201)
            send_to_chahub_mock.return_value.content = ""
            submission.save(force_to_chahub=True)
            # It does not need retry any more, and was successful
            assert send_to_chahub_mock.called
            assert not CompetitionSubmission.objects.get(pk=submission.pk).chahub_needs_retry

            # reset
            send_to_chahub_mock.called = False

            # Try sending again
            submission.save(force_to_chahub=True)
            assert not send_to_chahub_mock.called
コード例 #12
0
    def test_submission_mixin_save_only_retries_once(self):
        submission = CompetitionSubmission(phase=self.phase,
                                           participant=self.participant)
        with mock.patch('apps.web.models.CompetitionSubmission.send_to_chahub'
                        ) as send_to_chahub_mock:
            send_to_chahub_mock.return_value = None
            submission.save()
            # attempts to send to Chahub once
            assert send_to_chahub_mock.called

            # reset
            send_to_chahub_mock.called = False

            # does not call again
            submission.save()
            assert not send_to_chahub_mock.called
コード例 #13
0
    def test_submission_mixin_save_doesnt_resend_same_data(self):
        submission = CompetitionSubmission(phase=self.phase,
                                           participant=self.participant)
        with mock.patch('apps.web.models.CompetitionSubmission.send_to_chahub'
                        ) as send_to_chahub_mock:
            send_to_chahub_mock.return_value = HttpResponseBase(status=201)
            send_to_chahub_mock.return_value.content = ""
            submission.save()
            # attempts to send to Chahub once
            assert send_to_chahub_mock.called

            # reset
            send_to_chahub_mock.called = False

            # does not call again
            submission.save()
            assert not send_to_chahub_mock.called
コード例 #14
0
    def test_submission_retry_valid_retried_then_sent_and_not_retried_again(
            self):
        # Mark submission for retry
        submission = CompetitionSubmission(phase=self.phase,
                                           participant=self.participant,
                                           chahub_needs_retry=True)
        with mock.patch('apps.web.models.CompetitionSubmission.send_to_chahub'
                        ) as send_to_chahub_mock:
            send_to_chahub_mock.return_value = HttpResponseBase(status=201)
            send_to_chahub_mock.return_value.content = ""
            submission.save(force_to_chahub=True)
            # It does not need retry any more, and was successful
            assert send_to_chahub_mock.called
            assert not CompetitionSubmission.objects.get(
                pk=submission.pk).chahub_needs_retry

            # reset
            send_to_chahub_mock.called = False

            # Try sending again
            submission.save(force_to_chahub=True)
            assert not send_to_chahub_mock.called
コード例 #15
0
    def perform_create(self, serializer, request):
        kwargs = {}
        try:
            kwargs[
                'participant'] = webmodels.CompetitionParticipant.objects.get(
                    competition=self.kwargs['competition_id'],
                    user=self.request.user)
        except ObjectDoesNotExist:
            raise PermissionDenied()
        if not kwargs['participant'].is_approved:
            raise PermissionDenied()
        phase_id = self.request.query_params.get('phase_id', "")
        submission_phase = webmodels.CompetitionPhase.objects.filter(
            competition=self.kwargs['competition_id'], id=phase_id).first()
        if submission_phase is None or submission_phase.is_active is False:
            raise PermissionDenied(detail='Competition phase is closed.')
        if submission_phase.competition.is_migrating or submission_phase.competition.is_migrating_delayed:
            raise PermissionDenied(
                detail=
                "Failed, competition phase is being migrated, please try again in a few minutes"
            )

        obj = CompetitionSubmission(phase=submission_phase, **kwargs)

        # If this is not a re-ran submission. Re-ran submissions have these kwargs passed.
        if not kwargs.get('file') or kwargs.get('s3_file'):
            if not hasattr(request, 'data'):
                raise ValidationError('Data attribute not found on request')
            blob_name = request.data['id'] if 'id' in request.data else ''

            if len(blob_name) <= 0:
                raise ParseError(detail='Invalid or missing tracking ID.')
            if settings.USE_AWS:
                # Get file name from url and ensure we aren't getting GET params along with it
                obj.readable_filename = blob_name.split('/')[-1]
                obj.readable_filename = obj.readable_filename.split('?')[0]
                obj.s3_file = blob_name
            else:
                obj.file.name = blob_name

            obj.description = re.escape(
                request.query_params.get('description', ""))
            if not submission_phase.disable_custom_docker_image:
                obj.docker_image = re.escape(
                    request.query_params.get('docker_image', ""))
            if not obj.docker_image:
                obj.docker_image = submission_phase.competition.competition_docker_image or settings.DOCKER_DEFAULT_WORKER_IMAGE
            obj.team_name = re.escape(request.query_params.get(
                'team_name', ""))
            obj.organization_or_affiliation = re.escape(
                request.query_params.get('organization_or_affiliation', ""))
            obj.method_name = re.escape(
                request.query_params.get('method_name', ""))
            obj.method_description = re.escape(
                request.query_params.get('method_description', ""))
            obj.project_url = re.escape(
                request.query_params.get('project_url', ""))
            obj.publication_url = re.escape(
                request.query_params.get('publication_url', ""))
            obj.bibtex = re.escape(request.query_params.get('bibtex', ""))
            if submission_phase.competition.queue:
                obj.queue_name = submission_phase.competition.queue.name or ''

        obj.save()

        evaluate_submission.delay(obj.pk, obj.phase.is_scoring_only)
        return obj