def launch_with_literals( self, project: str, domain: str, literal_inputs: _literal_models.LiteralMap, name: str = None, notification_overrides: List[_common_models.Notification] = None, label_overrides: _common_models.Labels = None, annotation_overrides: _common_models.Annotations = None, ) -> _workflow_execution.FlyteWorkflowExecution: """ Executes the launch plan and returns the execution identifier. This version of execution is meant for when you already have a LiteralMap of inputs. :param project: :param domain: :param literal_inputs: Inputs to the execution. :param name: If specified, an execution will be created with this name. Note: the name must be unique within the context of the project and domain. :param notification_overrides: If specified, these are the notifications that will be honored for this execution. An empty list signals to disable all notifications. :param label_overrides: :param annotation_overrides: """ # Kubernetes requires names starting with an alphabet for some resources. name = name or "f" + _uuid.uuid4().hex[:19] disable_all = notification_overrides == [] if disable_all: notification_overrides = None else: notification_overrides = _execution_models.NotificationList( notification_overrides or []) disable_all = None client = _flyte_engine.get_client() try: exec_id = client.create_execution( project, domain, name, _execution_models.ExecutionSpec( self.id, _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode. MANUAL, "sdk", # TODO: get principle 0, # TODO: Detect nesting ), notifications=notification_overrides, disable_all=disable_all, labels=label_overrides, annotations=annotation_overrides, ), literal_inputs, ) except _user_exceptions.FlyteEntityAlreadyExistsException: exec_id = _identifier.WorkflowExecutionIdentifier( project, domain, name) return _workflow_execution.FlyteWorkflowExecution.promote_from_model( client.get_execution(exec_id))
def test_execution_notification_overrides(mock_client_factory): mock_client = MagicMock() mock_client.create_execution = MagicMock( return_value=identifier.WorkflowExecutionIdentifier('xp', 'xd', 'xn')) mock_client_factory.return_value = mock_client m = MagicMock() type(m).id = PropertyMock(return_value=identifier.Identifier( identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version")) engine.FlyteLaunchPlan(m).execute('xp', 'xd', 'xn', literals.LiteralMap({}), notification_overrides=[]) mock_client.create_execution.assert_called_once_with( 'xp', 'xd', 'xn', _execution_models.ExecutionSpec( identifier.Identifier(identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version"), literals.LiteralMap({}), _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode.MANUAL, 'sdk', 0), disable_all=True, ))
def test_execution_notification_soft_overrides(mock_client_factory): mock_client = MagicMock() mock_client.create_execution = MagicMock( return_value=identifier.WorkflowExecutionIdentifier('xp', 'xd', 'xn')) mock_client_factory.return_value = mock_client m = MagicMock() type(m).id = PropertyMock(return_value=identifier.Identifier( identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version")) notification = _common_models.Notification( [0, 1, 2], email=_common_models.EmailNotification(["*****@*****.**"])) engine.FlyteLaunchPlan(m).execute('xp', 'xd', 'xn', literals.LiteralMap({}), notification_overrides=[notification]) mock_client.create_execution.assert_called_once_with( 'xp', 'xd', 'xn', _execution_models.ExecutionSpec( identifier.Identifier(identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version"), literals.LiteralMap({}), _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode.MANUAL, 'sdk', 0), notifications=_execution_models.NotificationList([notification]), ))
def launch(self, project, domain, name=None, inputs=None, notification_overrides=None, label_overrides=None, annotation_overrides=None, auth_role=None): """ Executes the task as a single task execution and returns the identifier. :param Text project: :param Text domain: :param Text name: :param flytekit.models.literals.LiteralMap inputs: The inputs to pass :param list[flytekit.models.common.Notification] notification_overrides: If specified, override the notifications. :param flytekit.models.common.Labels label_overrides: :param flytekit.models.common.Annotations annotation_overrides: :param flytekit.models.common.AuthRole auth_role: :rtype: flytekit.models.execution.Execution """ disable_all = (notification_overrides == []) if disable_all: notification_overrides = None else: notification_overrides = _execution_models.NotificationList( notification_overrides or [] ) disable_all = None if not auth_role: assumable_iam_role = _auth_config.ASSUMABLE_IAM_ROLE.get() kubernetes_service_account = _auth_config.KUBERNETES_SERVICE_ACCOUNT.get() if not (assumable_iam_role or kubernetes_service_account): _logging.warning("Using deprecated `role` from config. " "Please update your config to use `assumable_iam_role` instead") assumable_iam_role = _sdk_config.ROLE.get() auth_role = _common_models.AuthRole(assumable_iam_role=assumable_iam_role, kubernetes_service_account=kubernetes_service_account) try: # TODO(katrogan): Add handling to register the underlying task if it's not already. client = _FlyteClientManager(_platform_config.URL.get(), insecure=_platform_config.INSECURE.get()).client exec_id = client.create_execution( project, domain, name, _execution_models.ExecutionSpec( self.sdk_task.id, _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode.MANUAL, 'sdk', # TODO: get principle 0 # TODO: Detect nesting ), notifications=notification_overrides, disable_all=disable_all, labels=label_overrides, annotations=annotation_overrides, auth_role=auth_role, ), inputs, ) except _user_exceptions.FlyteEntityAlreadyExistsException: exec_id = _identifier.WorkflowExecutionIdentifier(project, domain, name) return client.get_execution(exec_id)
def launch( self, project, domain, name, inputs, notification_overrides=None, label_overrides=None, annotation_overrides=None, ): """ Creates a workflow execution using parameters specified in the launch plan. :param Text project: :param Text domain: :param Text name: :param flytekit.models.literals.LiteralMap inputs: :param list[flytekit.models.common.Notification] notification_overrides: If specified, override the notifications. :param flytekit.models.common.Labels label_overrides: :param flytekit.models.common.Annotations annotation_overrides: :rtype: flytekit.models.execution.Execution """ disable_all = notification_overrides == [] if disable_all: notification_overrides = None else: notification_overrides = _execution_models.NotificationList( notification_overrides or []) disable_all = None try: client = _FlyteClientManager( _platform_config.URL.get(), insecure=_platform_config.INSECURE.get()).client exec_id = client.create_execution( project, domain, name, _execution_models.ExecutionSpec( self.sdk_launch_plan.id, _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode. MANUAL, "sdk", # TODO: get principle 0, # TODO: Detect nesting ), notifications=notification_overrides, disable_all=disable_all, labels=label_overrides, annotations=annotation_overrides, ), inputs, ) except _user_exceptions.FlyteEntityAlreadyExistsException: exec_id = _identifier.WorkflowExecutionIdentifier( project, domain, name) return client.get_execution(exec_id)
def test_execution_metadata(): obj = _execution.ExecutionMetadata(_execution.ExecutionMetadata.ExecutionMode.MANUAL, "tester", 1) assert obj.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL assert obj.principal == "tester" assert obj.nesting == 1 obj2 = _execution.ExecutionMetadata.from_flyte_idl(obj.to_flyte_idl()) assert obj == obj2 assert obj2.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL assert obj2.principal == "tester" assert obj2.nesting == 1
def execute(self, project, domain, name, inputs, notification_overrides=None, label_overrides=None, annotation_overrides=None): """ Executes the launch plan. :param Text project: :param Text domain: :param Text name: :param flytekit.models.literals.LiteralMap inputs: :param list[flytekit.models.common.Notification] notification_overrides: If specified, override the notifications. :param flytekit.models.common.Labels label_overrides: :param flytekit.models.common.Annotations annotation_overrides: :rtype: flytekit.models.execution.Execution """ disable_all = (notification_overrides == []) if disable_all: notification_overrides = None else: notification_overrides = _execution_models.NotificationList( notification_overrides or []) disable_all = None # TODO: Handle idempotency when admin is prepared. client = _FlyteClientManager( _platform_config.URL.get(), insecure=_platform_config.INSECURE.get()).client exec_id = client.create_execution( project, domain, name, _execution_models.ExecutionSpec( self.sdk_launch_plan.id, inputs, _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode.MANUAL, 'sdk', # TODO: get principle 0 # TODO: Detect nesting ), notifications=notification_overrides, disable_all=disable_all, labels=label_overrides, annotations=annotation_overrides, )) return client.get_execution(exec_id)
def test_execution_annotation_overrides(mock_client_factory): mock_client = MagicMock() mock_client.create_execution = MagicMock( return_value=identifier.WorkflowExecutionIdentifier("xp", "xd", "xn")) mock_client_factory.return_value = mock_client m = MagicMock() type(m).id = PropertyMock(return_value=identifier.Identifier( identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version")) annotations = _common_models.Annotations({"my": "annotation"}) engine.FlyteLaunchPlan(m).launch( "xp", "xd", "xn", literals.LiteralMap({}), notification_overrides=[], annotation_overrides=annotations, ) mock_client.create_execution.assert_called_once_with( "xp", "xd", "xn", _execution_models.ExecutionSpec( identifier.Identifier( identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version", ), _execution_models.ExecutionMetadata( _execution_models.ExecutionMetadata.ExecutionMode.MANUAL, "sdk", 0), disable_all=True, annotations=annotations, ), literals.LiteralMap({}), )
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"), _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.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 ] assert obj.notifications.notifications[0].pager_duty.recipients_email == [ "a", "b", "c", ] assert obj.disable_all is None obj2 = _execution.ExecutionSpec.from_flyte_idl(obj.to_flyte_idl()) assert obj == obj2 assert obj2.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN assert obj2.launch_plan.domain == "domain" assert obj2.launch_plan.project == "project" assert obj2.launch_plan.name == "name" assert obj2.launch_plan.version == "version" assert obj2.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL assert obj2.metadata.nesting == 1 assert obj2.metadata.principal == "tester" assert obj2.notifications.notifications[0].phases == [ _core_exec.WorkflowExecutionPhase.ABORTED ] assert obj2.notifications.notifications[0].pager_duty.recipients_email == [ "a", "b", "c", ] assert obj2.disable_all is None obj = _execution.ExecutionSpec( _identifier.Identifier(_identifier.ResourceType.LAUNCH_PLAN, "project", "domain", "name", "version"), _execution.ExecutionMetadata( _execution.ExecutionMetadata.ExecutionMode.MANUAL, "tester", 1), disable_all=True, ) 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.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL assert obj.metadata.nesting == 1 assert obj.metadata.principal == "tester" assert obj.notifications is None assert obj.disable_all is True obj2 = _execution.ExecutionSpec.from_flyte_idl(obj.to_flyte_idl()) assert obj == obj2 assert obj2.launch_plan.resource_type == _identifier.ResourceType.LAUNCH_PLAN assert obj2.launch_plan.domain == "domain" assert obj2.launch_plan.project == "project" assert obj2.launch_plan.name == "name" assert obj2.launch_plan.version == "version" assert obj2.metadata.mode == _execution.ExecutionMetadata.ExecutionMode.MANUAL assert obj2.metadata.nesting == 1 assert obj2.metadata.principal == "tester" assert obj2.notifications is None assert obj2.disable_all is True
def launch_with_literals( self, project, domain, literal_inputs, name=None, notification_overrides=None, label_overrides=None, annotation_overrides=None, ): """ Launches a single task execution and returns the execution identifier. :param Text project: :param Text domain: :param flytekit.models.literals.LiteralMap literal_inputs: Inputs to the execution. :param Text name: [Optional] If specified, an execution will be created with this name. Note: the name must be unique within the context of the project and domain. :param list[flytekit.common.notifications.Notification] notification_overrides: [Optional] If specified, these are the notifications that will be honored for this execution. An empty list signals to disable all notifications. :param flytekit.models.common.Labels label_overrides: :param flytekit.models.common.Annotations annotation_overrides: :rtype: flytekit.common.workflow_execution.SdkWorkflowExecution """ disable_all = notification_overrides == [] if disable_all: notification_overrides = None else: notification_overrides = _admin_execution_models.NotificationList( notification_overrides or []) disable_all = None assumable_iam_role = _auth_config.ASSUMABLE_IAM_ROLE.get() kubernetes_service_account = _auth_config.KUBERNETES_SERVICE_ACCOUNT.get( ) if not (assumable_iam_role or kubernetes_service_account): _logging.warning( "Using deprecated `role` from config. " "Please update your config to use `assumable_iam_role` instead" ) assumable_iam_role = _sdk_config.ROLE.get() auth_role = _common_model.AuthRole( assumable_iam_role=assumable_iam_role, kubernetes_service_account=kubernetes_service_account, ) client = _flyte_engine.get_client() try: # TODO(katrogan): Add handling to register the underlying task if it's not already. exec_id = client.create_execution( project, domain, name, _admin_execution_models.ExecutionSpec( self.id, _admin_execution_models.ExecutionMetadata( _admin_execution_models.ExecutionMetadata. ExecutionMode.MANUAL, "sdk", # TODO: get principle 0, # TODO: Detect nesting ), notifications=notification_overrides, disable_all=disable_all, labels=label_overrides, annotations=annotation_overrides, auth_role=auth_role, ), literal_inputs, ) except _user_exceptions.FlyteEntityAlreadyExistsException: exec_id = _identifier.WorkflowExecutionIdentifier( project, domain, name) execution = client.get_execution(exec_id) return _workflow_execution.SdkWorkflowExecution.promote_from_model( execution)