コード例 #1
0
def runs_stop(run_id: int,
              run: Optional[BaseRun],
              update_status=False,
              message=None) -> bool:
    run = get_run(run_id=run_id, run=run)
    if not run:
        return True

    stopped = True
    should_stop = (LifeCycle.is_k8s_stoppable(run.status)
                   or run.status == V1Statuses.STOPPING)
    if run.is_managed and should_stop:
        in_cluster = conf.get(K8S_IN_CLUSTER)
        if in_cluster and (run.is_service or run.is_job):
            stopped = manager.stop(
                run_uuid=run.uuid.hex,
                run_kind=run.kind,
                namespace=conf.get(K8S_NAMESPACE),
                in_cluster=in_cluster,
            )

    if not stopped:
        return False

    if not update_status:
        return True

    new_run_stop_status(run=run, message=message)
    return True
コード例 #2
0
ファイル: test_views.py プロジェクト: vishalbelsare/polyaxon
    def test_get(self):
        resp = self.client.get(self.url)
        assert resp.status_code == status.HTTP_200_OK

        data = resp.data
        assert len(data["status_conditions"]) == 0
        assert data == self.serializer_class(self.object).data

        new_run_status(
            self.object,
            condition=V1StatusCondition.get_condition(type=V1Statuses.RUNNING,
                                                      status=True),
        )
        self.object.refresh_from_db()
        resp = self.client.get(self.url)
        assert resp.status_code == status.HTTP_200_OK

        data = resp.data
        assert len(data["status_conditions"]) == 1
        assert data == self.serializer_class(self.object).data

        new_run_stop_status(run=self.object, message="foo")
        self.object.refresh_from_db()
        resp = self.client.get(self.url)
        assert resp.status_code == status.HTTP_200_OK

        data = resp.data
        assert len(data["status_conditions"]) == 2
        assert data == self.serializer_class(self.object).data
コード例 #3
0
ファイル: manager.py プロジェクト: opentechfn/polyaxon
def runs_stop(
    run_id: int,
    run: Optional[BaseRun],
    update_status=False,
    message=None,
    clean=False,
) -> bool:
    run = get_run(run_id=run_id, run=run)
    if not run:
        return True

    stopped = True
    should_stop = (LifeCycle.is_k8s_stoppable(run.status)
                   or run.status == V1Statuses.STOPPING)

    def _clean():
        try:
            manager.clean(
                run_uuid=run.uuid.hex,
                run_kind=run.kind,
                namespace=conf.get(K8S_NAMESPACE),
                in_cluster=in_cluster,
            )
        except (PolyaxonK8SError, ApiException) as e:
            _logger.warning(
                "Something went wrong, the run `%s` could not be stopped, error %s",
                run.uuid,
                e,
            )
            return False

    if run.is_managed and should_stop:
        in_cluster = conf.get(K8S_IN_CLUSTER)
        if in_cluster and (run.is_service or run.is_job):
            if clean:
                _clean()
            try:
                stopped = manager.stop(
                    run_uuid=run.uuid.hex,
                    run_kind=run.kind,
                    namespace=conf.get(K8S_NAMESPACE),
                    in_cluster=in_cluster,
                )
            except (PolyaxonK8SError, ApiException) as e:
                _logger.warning(
                    "Something went wrong, the run `%s` could not be stopped, error %s",
                    run.uuid,
                    e,
                )
                return False

    if not stopped:
        return False

    if not update_status:
        return True

    new_run_stop_status(run=run, message=message)
    return True
コード例 #4
0
 def create_one(self):
     run = super().create_one()
     condition = V1StatusCondition.get_condition(
         type=V1Statuses.RUNNING,
         status="True",
         reason="Run is running",
         message="foo",
     )
     new_run_status(run, condition)
     new_run_stop_status(run, "stopping")
     return run