def fetch(cls, project, domain, name, version=None):
        """
        This function uses the engine loader to call create a hydrated task from Admin.
        :param Text project:
        :param Text domain:
        :param Text name:
        :param Text version: [Optional] If not set, the SDK will fetch the active launch plan for the given project,
            domain, and name.
        :rtype: SdkLaunchPlan
        """
        from flytekit.common import workflow as _workflow

        launch_plan_id = _identifier.Identifier(
            _identifier_model.ResourceType.LAUNCH_PLAN, project, domain, name,
            version)

        if launch_plan_id.version:
            lp = _flyte_engine.get_client().get_launch_plan(launch_plan_id)
        else:
            named_entity_id = _common_models.NamedEntityIdentifier(
                launch_plan_id.project, launch_plan_id.domain,
                launch_plan_id.name)
            lp = _flyte_engine.get_client().get_active_launch_plan(
                named_entity_id)

        sdk_lp = cls.promote_from_model(lp.spec)
        sdk_lp._id = lp.id

        # TODO: Add a test for this, and this function as a whole
        wf_id = sdk_lp.workflow_id
        lp_wf = _workflow.SdkWorkflow.fetch(wf_id.project, wf_id.domain,
                                            wf_id.name, wf_id.version)
        sdk_lp._interface = lp_wf.interface
        sdk_lp._has_registered = True
        return sdk_lp
Beispiel #2
0
    def fetch_latest(cls, project, domain, name):
        """
        This function uses the engine loader to call create a latest hydrated task from Admin.
        :param Text project:
        :param Text domain:
        :param Text name:
        :rtype: SdkTask
        """
        named_task = _common_model.NamedEntityIdentifier(project, domain, name)
        client = _flyte_engine.get_client()
        task_list, _ = client.list_tasks_paginated(
            named_task,
            limit=1,
            sort_by=_admin_common.Sort(
                "created_at", _admin_common.Sort.Direction.DESCENDING),
        )
        admin_task = task_list[0] if task_list else None

        if not admin_task:
            raise _user_exceptions.FlyteEntityNotExistException(
                "Named task {} not found".format(named_task))
        sdk_task = cls.promote_from_model(
            admin_task.closure.compiled_task.template)
        sdk_task._id = admin_task.id
        return sdk_task
Beispiel #3
0
def test_fetch_latest_task(mock_client_factory, tasks):
    mock_client = MagicMock()
    mock_client.list_tasks_paginated = MagicMock(return_value=(tasks, 0))
    mock_client_factory.return_value = mock_client

    task = engine.FlyteEngineFactory().fetch_latest_task(_common_models.NamedEntityIdentifier("p", "d", "n"))

    if tasks:
        assert task.id == tasks[0].id
    else:
        assert not task

    mock_client.list_tasks_paginated.assert_called_once_with(
        _common_models.NamedEntityIdentifier("p", "d", "n"),
        limit=1,
        sort_by=_common.Sort("created_at", _common.Sort.Direction.DESCENDING),
    )
Beispiel #4
0
 def fetch_latest(cls, project, domain, name):
     """
     This function uses the engine loader to call create a latest hydrated task from Admin.
     :param Text project:
     :param Text domain:
     :param Text name:
     :rtype: SdkTask
     """
     named_task = _common_model.NamedEntityIdentifier(project, domain, name)
     admin_task = _engine_loader.get_engine().fetch_latest_task(named_task)
     if not admin_task:
         raise _user_exceptions.FlyteEntityNotExistException("Named task {} not found".format(named_task))
     sdk_task = cls.promote_from_model(admin_task.closure.compiled_task.template)
     sdk_task._id = admin_task.id
     return sdk_task
Beispiel #5
0
def test_fetch_active_launch_plan(mock_client_factory):
    mock_client = MagicMock()
    mock_client.get_active_launch_plan = MagicMock(
        return_value=_launch_plan_models.LaunchPlan(
            identifier.Identifier(identifier.ResourceType.LAUNCH_PLAN, "p1", "d1", "n1", "v1"),
            MagicMock(),
            MagicMock(),
        )
    )
    mock_client_factory.return_value = mock_client

    lp = engine.FlyteEngineFactory().fetch_launch_plan(
        identifier.Identifier(identifier.ResourceType.LAUNCH_PLAN, "p", "d", "n", "")
    )
    assert lp.id == identifier.Identifier(identifier.ResourceType.LAUNCH_PLAN, "p1", "d1", "n1", "v1")

    mock_client.get_active_launch_plan.assert_called_once_with(_common_models.NamedEntityIdentifier("p", "d", "n"))
Beispiel #6
0
 def fetch_launch_plan(self, launch_plan_id):
     """
     :param flytekit.models.core.identifier.Identifier launch_plan_id: This identifier should have a resource
         type of kind LaunchPlan.
     :rtype: flytekit.models.launch_plan.LaunchPlan
     """
     if launch_plan_id.version:
         return _FlyteClientManager(
             _platform_config.URL.get(),
             insecure=_platform_config.INSECURE.get(
             )).client.get_launch_plan(launch_plan_id)
     else:
         named_entity_id = _common_models.NamedEntityIdentifier(
             launch_plan_id.project, launch_plan_id.domain,
             launch_plan_id.name)
         return _FlyteClientManager(
             _platform_config.URL.get(),
             insecure=_platform_config.INSECURE.get(
             )).client.get_active_launch_plan(named_entity_id)