Ejemplo n.º 1
0
 def test_create_run_creation_is_recorded_by_executor(
         self, executor_record):
     run = MagicMock(project=self.project)
     auditor.record(run_events.RUN_CREATED, instance=run)
     assert executor_record.call_count == 1
     call_args, call_kwargs = executor_record.call_args
     assert call_kwargs["event_type"] == run_events.RUN_CREATED
Ejemplo n.º 2
0
def run_created(sender, **kwargs):
    instance = kwargs["instance"]
    if instance.is_managed:
        if (instance.is_clone and instance.content is None) or (
                not instance.is_clone and instance.raw_content is None):
            raise ValidationError(
                "A managed run should have a valid specification.")
    auditor.record(event_type=RUN_CREATED, instance=instance)
Ejemplo n.º 3
0
 def audit(self, request, *args, **kwargs):
     if not self.AUDITOR_EVENT_TYPES:
         return
     event_type = self.AUDITOR_EVENT_TYPES.get(request.method)
     if event_type:
         self.set_owner()
         params = self.get_audit_params(**kwargs)
         auditor.record(
             event_type=event_type,
             actor_id=1,
             actor_name="polyaxon",
             owner_id=self._owner_id,
             **params,
         )
Ejemplo n.º 4
0
 def audit(self, request, *args, **kwargs):
     if not self.AUDITOR_EVENT_TYPES:
         return
     event_type = self.AUDITOR_EVENT_TYPES.get(request.method)
     if (event_type and not user_system.is_system_user(request.user.id)
             and not request.user.is_anonymous):
         self.set_owner_id()
         params = self.get_audit_params(**kwargs)
         auditor.record(
             event_type=event_type,
             actor_id=self.request.user.id,
             actor_name=self.request.user.username,
             owner_id=self._owner_id,
             **params,
         )
Ejemplo n.º 5
0
def delete_runs(view, request, actor, *args, **kwargs):
    runs = get_run_model().objects.filter(project=view.project,
                                          uuid__in=request.data.get(
                                              "uuids", []))
    for run in runs.only("id"):
        auditor.record(
            event_type=RUN_DELETED_ACTOR,
            instance=run,
            actor_id=actor.id,
            actor_name=actor.username,
            owner_id=view.project.owner_id,
            owner_name=view.owner_name,
            project_name=view.project_name,
        )
    # Deletion in progress
    runs.update(live_state=live_state.STATE_DELETION_PROGRESSING)
    return Response(status=status.HTTP_200_OK, data={})
Ejemplo n.º 6
0
def stop_runs(view, request, actor, *args, **kwargs):
    runs = (get_run_model().objects.filter(
        project=view.project, uuid__in=request.data.get(
            "uuids", [])).exclude(status__in=LifeCycle.DONE_VALUES).only("id"))
    runs.update(status=V1Statuses.STOPPING)
    for run in runs:
        auditor.record(
            event_type=RUN_STOPPED_ACTOR,
            instance=run,
            actor_id=actor.id,
            actor_name=actor.username,
            owner_id=view.project.owner_id,
            owner_name=view.owner_name,
            project_name=view.project_name,
        )

    return Response(status=status.HTTP_200_OK, data={})
Ejemplo n.º 7
0
def approve_runs(view, request, actor, *args, **kwargs):
    queryset = (get_run_model().objects.filter(
        project=view.project,
        uuid__in=request.data.get("uuids", [])).exclude(is_approved=True))
    runs = [r for r in queryset]
    queryset.update(is_approved=True)
    for run in runs:
        auditor.record(
            event_type=RUN_APPROVED_ACTOR,
            instance=run,
            actor_id=actor.id,
            actor_name=actor.username,
            owner_id=view.project.owner_id,
            owner_name=view.owner_name,
            project_name=view.project_name,
        )

    return Response(status=status.HTTP_200_OK, data={})
Ejemplo n.º 8
0
def stop_runs(view, request, actor, *args, **kwargs):
    # Immediate stop
    queryset = (
        get_run_model()
        .objects.filter(project=view.project, uuid__in=request.data.get("uuids", []))
        .filter(status__in=LifeCycle.SAFE_STOP_VALUES)
    )
    condition = V1StatusCondition.get_condition(
        type=V1Statuses.STOPPED,
        status="True",
        reason="EventHandler",
        message="User requested to stop the run.",
    )
    bulk_new_run_status(queryset, condition)

    queryset = (
        get_run_model()
        .objects.filter(project=view.project, uuid__in=request.data.get("uuids", []))
        .exclude(status__in=LifeCycle.DONE_OR_IN_PROGRESS_VALUES)
    )
    runs = [r for r in queryset]
    condition = V1StatusCondition.get_condition(
        type=V1Statuses.STOPPING,
        status="True",
        reason="EventHandler",
        message="User requested to stop the run.",
    )
    bulk_new_run_status(runs, condition)
    for run in runs:
        auditor.record(
            event_type=RUN_STOPPED_ACTOR,
            instance=run,
            actor_id=actor.id,
            actor_name=actor.username,
            owner_id=view.project.owner_id,
            owner_name=view.owner_name,
            project_name=view.project_name,
        )

    return Response(status=status.HTTP_200_OK, data={})
Ejemplo n.º 9
0
def new_run_status(run: BaseRun, condition: V1StatusCondition):
    previous_status = new_status(entity=run, condition=condition)
    # Do not audit the new status since it's the same as the previous one
    if (condition.type in {V1Statuses.CREATED, V1Statuses.STOPPING}
            or previous_status == run.status):
        return

    auditor.record(event_type=RUN_NEW_STATUS,
                   instance=run,
                   previous_status=previous_status)
    if run.status == V1Statuses.STOPPED:
        auditor.record(event_type=RUN_STOPPED,
                       instance=run,
                       previous_status=previous_status)
    elif run.status == V1Statuses.FAILED:
        auditor.record(event_type=RUN_FAILED,
                       instance=run,
                       previous_status=previous_status)
    elif run.status == V1Statuses.SUCCEEDED:
        auditor.record(event_type=RUN_SUCCEEDED,
                       instance=run,
                       previous_status=previous_status)
    elif run.status == V1Statuses.SKIPPED:
        auditor.record(event_type=RUN_SKIPPED,
                       instance=run,
                       previous_status=previous_status)
    elif run.status == V1Statuses.RESUMING:
        auditor.record(event_type=RUN_RESUMED, instance=run)

    # handle done status
    if LifeCycle.is_done(run.status):
        auditor.record(event_type=RUN_DONE,
                       instance=run,
                       previous_status=previous_status)