Exemplo n.º 1
0
def test_lp_documentation():
    @task
    def t1(a: int) -> typing.NamedTuple("OutputsBC", t1_int_output=int, c=str):
        a = a + 2
        return a, "world-" + str(a)

    @workflow
    def wf(a: int, c: str) -> (int, str):
        x, y = t1(a=a)
        return x, y

    # fixed_and_default_start
    launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                         name="your_lp_name_1",
                                         default_inputs={"a": 3},
                                         fixed_inputs={"c": "4"})
    # fixed_and_default_end

    # schedule_start
    sched = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc")
    email_notif = notification.Email(
        phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED],
        recipients_email=["*****@*****.**"])
    launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                         name="your_lp_name_2",
                                         schedule=sched,
                                         notifications=[email_notif])
    # schedule_end

    # auth_role_start
    auth_role_model = AuthRole(assumable_iam_role="my:iam:role")
    launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="your_lp_name_3",
    )

    labels_model = Labels({"label": "foo"})
    annotations_model = Annotations({"annotate": "bar"})
    launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="your_lp_name_4",
        auth_role=auth_role_model,
        labels=labels_model,
        annotations=annotations_model,
    )

    raw_output_data_config = RawOutputDataConfig("s3://foo/output")
    launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="your_lp_name_5",
        raw_output_data_config=raw_output_data_config)
Exemplo n.º 2
0
def test_lp_all_parameters():
    nt = typing.NamedTuple("OutputsBC", t1_int_output=int, c=str)

    @task
    def t1(a: int) -> nt:
        a = a + 2
        return nt(a, "world-" + str(a))

    @task
    def t2(a: str, b: str, c: str) -> str:
        return b + a + c

    @workflow
    def wf(a: int, c: str) -> str:
        x, y = t1(a=a)
        u = t2(a=x, b=y, c=c)
        return u

    obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc")
    obj1 = CronSchedule("10 * ? * * *", kickoff_time_input_arg="abc")
    slack_notif = notification.Slack(
        phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED],
        recipients_email=["*****@*****.**"])
    auth_role_model = AuthRole(assumable_iam_role="my:iam:role")
    labels = Labels({"label": "foo"})
    annotations = Annotations({"anno": "bar"})
    raw_output_data_config = RawOutputDataConfig("s3://foo/output")

    lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create",
        default_inputs={"a": 3},
        fixed_inputs={"c": "4"},
        schedule=obj,
        notifications=[slack_notif],
        auth_role=auth_role_model,
        labels=labels,
        annotations=annotations,
        raw_output_data_config=raw_output_data_config,
    )
    lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create",
        default_inputs={"a": 3},
        fixed_inputs={"c": "4"},
        schedule=obj,
        notifications=[slack_notif],
        auth_role=auth_role_model,
        labels=labels,
        annotations=annotations,
        raw_output_data_config=raw_output_data_config,
    )

    assert lp is lp2

    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(
            workflow=wf,
            name="get_or_create",
            default_inputs={"a": 3},
            fixed_inputs={"c": "4"},
            schedule=obj1,
            notifications=[slack_notif],
            auth_role=auth_role_model,
            labels=labels,
            annotations=annotations,
            raw_output_data_config=raw_output_data_config,
        )
Exemplo n.º 3
0
from flytekit.common import notifications as _notifications
from flytekit.models.common import Labels, Annotations
from flytekit.models.core import execution as _execution

from workflows import workflows

# This is a launchplan that is created with default values of inputs and added some annotations, labels and
# notification preferences. Default values make it possible to still override when an execution is requested
scale_rotate_default_launchplan = workflows.ScaleAndRotateWorkflow.create_launch_plan(
    labels=Labels({
        'flyte.org/managed': 'true',
    }),
    annotations=Annotations({
        'flyte.org/secret-inject': 'required',
    }),
    notifications=[
        _notifications.Slack(
            [
                _execution.WorkflowExecutionPhase.SUCCEEDED,
                _execution.WorkflowExecutionPhase.FAILED,
                _execution.WorkflowExecutionPhase.TIMED_OUT,
                _execution.WorkflowExecutionPhase.ABORTED,
            ],
            ['*****@*****.**'],
        ),
    ],
    default_inputs={})

# This launch plan customizes the input angle to 90 and the scale factor to 4x as `fixed_inputs`. Inputs cannot be
# changed now
scale4x_rotate90degrees_launchplan = workflows.ScaleAndRotateWorkflow.create_launch_plan(
Exemplo n.º 4
0
def test_lp_each_parameter():
    @task
    def t1(a: int) -> typing.NamedTuple("OutputsBC", t1_int_output=int, c=str):
        a = a + 2
        return a, "world-" + str(a)

    @workflow
    def wf(a: int, c: str) -> (int, str):
        x, y = t1(a=a)
        return x, y

    # Fixed Inputs Parameter
    launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                         name="get_or_create_fixed",
                                         fixed_inputs={
                                             "a": 1,
                                             "c": "4"
                                         })
    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                             name="get_or_create_fixed")

    # Schedule Parameter
    obj = CronSchedule("* * ? * * *", kickoff_time_input_arg="abc")
    schedule_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", schedule=obj)
    schedule_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_schedule", schedule=obj)

    assert schedule_lp is schedule_lp1

    # Default Inputs Parameter
    launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_schedule_def_inputs",
        default_inputs={"a": 9})
    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(
            workflow=wf,
            name="get_or_create_schedule_def_inputs",
            default_inputs={"a": 19})

    # Notifications Parameter
    email_notif = notification.Email(
        phases=[_execution_model.WorkflowExecutionPhase.SUCCEEDED],
        recipients_email=["*****@*****.**"])
    notification_lp = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_notification",
        notifications=[email_notif])
    notification_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_notification",
        notifications=[email_notif])

    assert notification_lp is notification_lp1

    # Auth Parameter
    auth_role_model1 = AuthRole(assumable_iam_role="my:iam:role")
    auth_role_model2 = _launch_plan_idl.Auth(
        kubernetes_service_account="my:service:account")
    launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                         name="get_or_create_auth",
                                         auth_role=auth_role_model1)
    with pytest.raises(AssertionError):
        launch_plan.LaunchPlan.get_or_create(workflow=wf,
                                             name="get_or_create_auth",
                                             auth_role=auth_role_model2)

    # Labels parameters
    labels_model1 = Labels({"label": "foo"})
    labels_model2 = Labels({"label": "foo"})
    labels_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model1)
    labels_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model2)
    assert labels_lp1 is labels_lp2

    # Annotations parameters
    annotations_model1 = Annotations({"anno": "bar"})
    annotations_model2 = Annotations({"anno": "bar"})
    annotations_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model1)
    annotations_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model2)
    assert annotations_lp1 is annotations_lp2

    # Raw output prefix parameters
    raw_output_data_config1 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config2 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config1)
    raw_output_data_config_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config2)
    assert raw_output_data_config_lp1 is raw_output_data_config_lp2

    # Max parallelism
    max_parallelism = 100
    max_parallelism_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    max_parallelism_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    assert max_parallelism_lp1 is max_parallelism_lp2

    # Labels parameters
    labels_model1 = Labels({"label": "foo"})
    labels_model2 = Labels({"label": "foo"})
    labels_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model1)
    labels_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model2)
    assert labels_lp1 is labels_lp2

    # Annotations parameters
    annotations_model1 = Annotations({"anno": "bar"})
    annotations_model2 = Annotations({"anno": "bar"})
    annotations_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model1)
    annotations_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model2)
    assert annotations_lp1 is annotations_lp2

    # Raw output prefix parameters
    raw_output_data_config1 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config2 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config1)
    raw_output_data_config_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config2)
    assert raw_output_data_config_lp1 is raw_output_data_config_lp2

    # Max parallelism
    max_parallelism = 100
    max_parallelism_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    max_parallelism_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    assert max_parallelism_lp1 is max_parallelism_lp2

    # Labels parameters
    labels_model1 = Labels({"label": "foo"})
    labels_model2 = Labels({"label": "foo"})
    labels_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model1)
    labels_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf, name="get_or_create_labels", labels=labels_model2)
    assert labels_lp1 is labels_lp2

    # Annotations parameters
    annotations_model1 = Annotations({"anno": "bar"})
    annotations_model2 = Annotations({"anno": "bar"})
    annotations_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model1)
    annotations_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_annotations",
        annotations=annotations_model2)
    assert annotations_lp1 is annotations_lp2

    # Raw output prefix parameters
    raw_output_data_config1 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config2 = RawOutputDataConfig("s3://foo/output")
    raw_output_data_config_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config1)
    raw_output_data_config_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_raw_output_prefix",
        raw_output_data_config=raw_output_data_config2)
    assert raw_output_data_config_lp1 is raw_output_data_config_lp2

    # Max parallelism
    max_parallelism = 100
    max_parallelism_lp1 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    max_parallelism_lp2 = launch_plan.LaunchPlan.get_or_create(
        workflow=wf,
        name="get_or_create_max_parallelism",
        max_parallelism=max_parallelism,
    )
    assert max_parallelism_lp1 is max_parallelism_lp2

    # Default LaunchPlan
    name_lp = launch_plan.LaunchPlan.get_or_create(workflow=wf)
    name_lp1 = launch_plan.LaunchPlan.get_or_create(workflow=wf)

    assert name_lp is name_lp1
Exemplo n.º 5
0
def double(a: int) -> int:
    return a * 2


@task
def add(a: int, b: int) -> int:
    return a + b


@workflow
def my_childwf(a: int = 42) -> int:
    b = double(a=a)
    return b


child_lp = LaunchPlan.get_or_create(my_childwf,
                                    name="my_fixed_child_lp",
                                    labels=Labels({"l1": "v1"}))


@workflow
def parent_wf(a: int) -> int:
    x = double(a=a)
    y = child_lp(a=x)
    z = add(a=x, b=y)
    return z


if __name__ == "__main__":
    print(f"Running parent_wf(a=3) {parent_wf(a=3)}")