How to use the flytekit.models.common function in flytekit

To help you get started, weโ€™ve selected a few flytekit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyft / flytekit / tests / flytekit / unit / common_tests / test_launch_plan.py View on Github external
def test_labels():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            'required_input': _workflow.Input(_types.Types.Integer),
            'default_input': _workflow.Input(_types.Types.Integer, default=5)
        }
    )
    lp = workflow_to_test.create_launch_plan(
        fixed_inputs={'required_input': 5},
        schedule=_schedules.CronSchedule("* * ? * * *"),
        role='what',
        labels=_common_models.Labels({"my": "label"})
    )
    assert lp.labels.values == {"my": "label"}
github lyft / flytekit / tests / flytekit / unit / models / test_execution.py View on Github external
def test_execution_spec(literal_value_pair):
    literal_value, _ = literal_value_pair

    obj = _execution.ExecutionSpec(
        _identifier.Identifier(_identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version"),
        _literal_models.LiteralMap(literals={'a': literal_value}),
        _execution.ExecutionMetadata(_execution.ExecutionMetadata.ExecutionMode.MANUAL, 'tester', 1),
        notifications=_execution.NotificationList(
            [
                _common_models.Notification(
                    [_core_exec.WorkflowExecutionPhase.ABORTED],
                    pager_duty=_common_models.PagerDutyNotification(recipients_email=['a', 'b', 'c'])
                )
            ]
        )
    )
    assert obj.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN
    assert obj.launch_plan.domain == "domain"
    assert obj.launch_plan.project == "project"
    assert obj.launch_plan.name == "name"
    assert obj.launch_plan.version == "version"
    assert obj.inputs.literals['a'] == literal_value
    assert obj.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL
    assert obj.metadata.nesting == 1
    assert obj.metadata.principal == 'tester'
    assert obj.notifications.notifications[0].phases == [_core_exec.WorkflowExecutionPhase.ABORTED]
github lyft / flytekit / tests / flytekit / unit / common_tests / test_launch_plan.py View on Github external
def test_annotations():
    workflow_to_test = _workflow.workflow(
        {},
        inputs={
            'required_input': _workflow.Input(_types.Types.Integer),
            'default_input': _workflow.Input(_types.Types.Integer, default=5)
        }
    )
    lp = workflow_to_test.create_launch_plan(
        fixed_inputs={'required_input': 5},
        schedule=_schedules.CronSchedule("* * ? * * *"),
        role='what',
        annotations=_common_models.Annotations({"my": "annotation"})
    )
    assert lp.annotations.values == {"my": "annotation"}
github lyft / flytekit / flytekit / models / launch_plan.py View on Github external
    @classmethod
    def enum_to_string(cls, val):
        """
        :param int val:
        :rtype: Text
        """
        if val == cls.INACTIVE:
            return "INACTIVE"
        elif val == cls.ACTIVE:
            return "ACTIVE"
        else:
            return ""


class LaunchPlanClosure(_common.FlyteIdlEntity):

    def __init__(self, state, expected_inputs, expected_outputs):
        """
        :param LaunchPlanState state: Indicate the Launch plan phase
        :param flytekit.models.interface.ParameterMap expected_inputs: Indicates the set of inputs to execute
            the Launch plan
        :param flytekit.models.interface.VariableMap expected_outputs: Indicates the set of outputs from the Launch plan
        """
        self._state = state
        self._expected_inputs = expected_inputs
        self._expected_outputs = expected_outputs

    @property
    def state(self):
        """
        :rtype: LaunchPlanState
github lyft / flytekit / flytekit / models / launch_plan.py View on Github external
def from_flyte_idl(cls, pb2_object):
        """
        :param flyteidl.admin.launch_plan_pb2.LaunchPlanMetadata pb2_object:
        :rtype: LaunchPlanMetadata
        """
        return cls(schedule=_schedule.Schedule.from_flyte_idl(pb2_object.schedule) if pb2_object.HasField("schedule")
                   else None,
                   notifications=[_common.Notification.from_flyte_idl(n) for n in pb2_object.notifications])
github lyft / flytekit / flytekit / models / presto.py View on Github external
from __future__ import absolute_import

## Todo - change this to qubole_presto once Luis's PR get's merged
# from flyteidl.plugins import qubole_presto as _qubole
from flyteidl.plugins import presto_pb2 as _presto

from flytekit.models import common as _common


class PrestoQuery(_common.FlyteIdlEntity):
    def __init__(self, routing_group, catalog, schema, statement):
        """
        Initializes a new PrestoQuery.

        :param string routing_group:
        :param string catalog:
        :param string schema:
        :param string statement:

        """
        self._routing_group = routing_group
        self._catalog = catalog
        self._schema = schema
        self._statement = statement

    @property
github lyft / flytekit / flytekit / models / task.py View on Github external
def from_flyte_idl(cls, pb2_object):
        """
        :param flyteidl.admin.task_pb2.Task pb2_object:
        :rtype: Container
        """
        return cls(
            image=pb2_object.image,
            command=pb2_object.command,
            args=pb2_object.args,
            resources=Resources.from_flyte_idl(pb2_object.resources),
            env={kv.key: kv.value for kv in pb2_object.env},
            config={kv.key: kv.value for kv in pb2_object.config}
        )


class SidecarJob(_common.FlyteIdlEntity):

    def __init__(self, pod_spec, primary_container_name):
        """
        A sidecar job represents the full kubernetes pod spec and related metadata required for executing a sidecar
        task.

        :param pod_spec: k8s.io.api.core.v1.PodSpec
        :param primary_container_name: Text
        """
        self._pod_spec = pod_spec
        self._primary_container_name = primary_container_name

    @property
    def pod_spec(self):
        """
        :rtype: k8s.io.api.core.v1.PodSpec
github lyft / flytekit / flytekit / common / launch_plan.py View on Github external
#   3) When SdkLaunchPlan.fetch() is run
        super(SdkRunnableLaunchPlan, self).__init__(
            None,
            _launch_plan_models.LaunchPlanMetadata(
                schedule=schedule or _schedule_model.Schedule(''),
                notifications=notifications or []
            ),
            _interface_models.ParameterMap(default_inputs),
            _type_helpers.pack_python_std_map_to_literal_map(
                fixed_inputs,
                {
                    k: _type_helpers.get_sdk_type_from_literal_type(var.type)
                    for k, var in _six.iteritems(sdk_workflow.interface.inputs) if k in fixed_inputs
                }
            ),
            labels or _common_models.Labels({}),
            annotations or _common_models.Annotations({}),
            auth,
        )
        self._interface = _interface.TypedInterface(
            {k: v.var for k, v in _six.iteritems(default_inputs)},
            sdk_workflow.interface.outputs
        )
        self._upstream_entities = {sdk_workflow}
        self._sdk_workflow = sdk_workflow
github lyft / flytekit / flytekit / clients / friendly.py View on Github external
specify token="foo". Please see the notes for this function about the caveats of the paginated API.
        :param flytekit.models.admin.common.Sort sort_by: [Optional] If provided, the results will be sorted.
        :raises: TODO
        :rtype: list[flytekit.models.common.NamedEntityIdentifier], Text
        """
        identifier_list = super(SynchronousFlyteClient, self).list_task_ids_paginated(
            _common_pb2.NamedEntityIdentifierListRequest(
                project=project,
                domain=domain,
                limit=limit,
                token=token,
                sort_by=None if sort_by is None else sort_by.to_flyte_idl()
            )
        )
        return [
                   _common.NamedEntityIdentifier.from_flyte_idl(identifier_pb)
                   for identifier_pb in identifier_list.entities
               ], _six.text_type(identifier_list.token)
github lyft / flytekit / flytekit / models / sagemaker / parameter_ranges.py View on Github external
from __future__ import absolute_import

from flyteidl.plugins.sagemaker import parameter_ranges_pb2 as _idl_parameter_ranges
from flytekit.models import common as _common
from flytekit.sdk.sagemaker import types as _sdk_sagemaker_types
from flytekit.common.exceptions import user as _user_exceptions


class ContinuousParameterRange(_common.FlyteIdlEntity):
    def __init__(
            self,
            max_value,
            min_value,
            scaling_type
    ):
        """

        :param float max_value:
        :param float min_value:
        :param _sdk_sagemaker_types.HyperparameterScalingType scaling_type:
        """
        self._max_value = max_value
        self._min_value = min_value
        self._scaling_type = scaling_type