def register(self, project, domain, name, version): """ :param Text project: :param Text domain: :param Text name: :param Text version: """ self.validate() id_to_register = _identifier.Identifier( _identifier_model.ResourceType.LAUNCH_PLAN, project, domain, name, version ) client = _flyte_engine.get_client() try: client.create_launch_plan(id_to_register, self) except _user_exceptions.FlyteEntityAlreadyExistsException: pass self._id = id_to_register self._has_registered = True return str(self.id)
def outputs(self): """ Returns the outputs to the execution in the standard Python format as dictated by the type engine. If the execution ended in error or the execution is in progress, an exception will be raised. :rtype: dict[Text, T] """ if not self.is_complete: raise _user_exceptions.FlyteAssertion( "Please what until the node execution has completed before requesting the outputs." ) if self.error: raise _user_exceptions.FlyteAssertion( "Outputs could not be found because the execution ended in failure." ) if self._outputs is None: client = _flyte_engine.get_client() execution_data = client.get_node_execution_data(self.id) # Outputs are returned inline unless they are too big, in which case a url blob pointing to them is returned. if bool(execution_data.full_outputs.literals): output_map = execution_data.full_outputs elif execution_data.outputs.bytes > 0: with _common_utils.AutoDeletingTempDir() as t: tmp_name = _os.path.join(t.name, "outputs.pb") _data_proxy.Data.get_data(execution_data.outputs.url, tmp_name) output_map = _literal_models.LiteralMap.from_flyte_idl( _common_utils.load_proto_from_file( _literals_pb2.LiteralMap, tmp_name)) else: output_map = _literal_models.LiteralMap({}) self._outputs = _type_helpers.unpack_literal_map_to_sdk_python_std( output_map) return self._outputs
def outputs(self) -> Dict[str, Any]: """ Returns the outputs of the task execution, if available, in the standard Python format that is produced by the type engine. :raises: ``FlyteAssertion`` error if execution is in progress or execution ended in error. """ if not self.is_complete: raise _user_exceptions.FlyteAssertion( "Please what until the task execution has completed before requesting the outputs." ) if self.error: raise _user_exceptions.FlyteAssertion( "Outputs could not be found because the execution ended in failure." ) if self._outputs is None: client = _flyte_engine.get_client() execution_data = client.get_task_execution_data(self.id) # Inputs are returned inline unless they are too big, in which case a url blob pointing to them is returned. output_map = _literal_models.LiteralMap({}) if bool(execution_data.full_outputs.literals): output_map = execution_data.full_outputs elif execution_data.outputs.bytes > 0: with _common_utils.AutoDeletingTempDir() as t: tmp_name = _os.path.join(t.name, "outputs.pb") _data_proxy.Data.get_data(execution_data.outputs.url, tmp_name) output_map = _literal_models.LiteralMap.from_flyte_idl( _common_utils.load_proto_from_file( _literals_pb2.LiteralMap, tmp_name)) # TODO: need to convert flyte literals to python types. For now just use literals # self._outputs = TypeEngine.literal_map_to_kwargs(ctx=FlyteContext.current_context(), lm=output_map) self._outputs = output_map return self._outputs
def inputs(self) -> Dict[str, Any]: """ Returns the inputs to the execution in the standard python format as dictated by the type engine. """ if self._inputs is None: client = _flyte_engine.get_client() execution_data = client.get_execution_data(self.id) # Inputs are returned inline unless they are too big, in which case a url blob pointing to them is returned. input_map: LiteralMap = _literal_models.LiteralMap({}) if bool(execution_data.full_inputs.literals): input_map = execution_data.full_inputs elif execution_data.inputs.bytes > 0: with _common_utils.AutoDeletingTempDir() as tmp_dir: tmp_name = _os.path.join(tmp_dir.name, "inputs.pb") _data_proxy.Data.get_data(execution_data.inputs.url, tmp_name) input_map = _literal_models.LiteralMap.from_flyte_idl( _common_utils.load_proto_from_file( _literals_pb2.Literalmap, tmp_name)) # TODO: need to convert flyte literals to python types. For now just use literals # self._inputs = TypeEngine.literal_map_to_kwargs(ctx=FlyteContext.current_context(), lm=input_map) self._inputs = input_map return self._inputs
def inputs(self): """ Returns the inputs to the execution in the standard Python format as dictated by the type engine. :rtype: dict[Text, T] """ if self._inputs is None: client = _flyte_engine.get_client() execution_data = client.get_node_execution_data(self.id) # Inputs are returned inline unless they are too big, in which case a url blob pointing to them is returned. if bool(execution_data.full_inputs.literals): input_map = execution_data.full_inputs elif execution_data.inputs.bytes > 0: with _common_utils.AutoDeletingTempDir() as t: tmp_name = _os.path.join(t.name, "inputs.pb") _data_proxy.Data.get_data(execution_data.inputs.url, tmp_name) input_map = _literal_models.LiteralMap.from_flyte_idl( _common_utils.load_proto_from_file(_literals_pb2.LiteralMap, tmp_name) ) else: input_map = _literal_models.LiteralMap({}) self._inputs = _type_helpers.unpack_literal_map_to_sdk_python_std(input_map) return self._inputs
def outputs(self) -> Dict[str, Any]: """ Returns the outputs to the execution in the standard python format as dictated by the type engine. :raises: ``FlyteAssertion`` error if execution is in progress or execution ended in error. """ if not self.is_complete: raise _user_exceptions.FlyteAssertion( "Please wait until the node execution has completed before requesting the outputs." ) if self.error: raise _user_exceptions.FlyteAssertion("Outputs could not be found because the execution ended in failure.") if self._outputs is None: client = _flyte_engine.get_client() execution_data = client.get_execution_data(self.id) # Outputs are returned inline unless they are too big, in which case a url blob pointing to them is returned. output_map: _literal_models.LiteralMap = _literal_models.LiteralMap({}) if bool(execution_data.full_outputs.literals): output_map = execution_data.full_outputs elif execution_data.outputs.bytes > 0: with _common_utils.AutoDeletingTempDir() as tmp_dir: tmp_name = _os.path.join(tmp_dir.name, "outputs.pb") _data_proxy.Data.get_data(execution_data.outputs.url, tmp_name) output_map = _literal_models.LiteralMap.from_flyte_idl( _common_utils.load_proto_from_file(_literals_pb2.LiteralMap, tmp_name) ) lp_id = self.spec.launch_plan workflow = _workflow.FlyteWorkflow.fetch(lp_id.project, lp_id.domain, lp_id.name, lp_id.version) self._outputs = TypeEngine.literal_map_to_kwargs( ctx=FlyteContextManager.current_context(), lm=output_map, python_types=TypeEngine.guess_python_types(workflow.interface.outputs), ) return self._outputs
def update(self, state: _launch_plan_models.LaunchPlanState): if not self.id: raise _user_exceptions.FlyteAssertion( "Failed to update launch plan because the launch plan's ID is not set. Please call register to fetch " "or register the identifier first") return _flyte_engine.get_client().update_launch_plan(self.id, state)
def terminate(self, cause: str): _flyte_engine.get_client().terminate_execution(self.id, cause)
def _sync_closure(self): if not self.is_complete: client = _flyte_engine.get_client() self._closure = client.get_execution(self.id).closure
def fetch(cls, project: str, domain: str, name: str) -> "FlyteWorkflowExecution": return cls.promote_from_model(_flyte_engine.get_client().get_execution( _core_identifier.WorkflowExecutionIdentifier(project=project, domain=domain, name=name)))
def _sync_closure(self): """ Syncs the closure of the underlying execution artifact with the state observed by the platform. """ self._closure = _flyte_engine.get_client().get_node_execution( self.id).closure
def launch_with_literals( self, project, domain, literal_inputs, name=None, notification_overrides=None, label_overrides=None, annotation_overrides=None, ): """ 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 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 """ # 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) execution = client.get_execution(exec_id) return _workflow_execution.SdkWorkflowExecution.promote_from_model( execution)
def terminate(self, cause): """ :param Text cause: """ _flyte_engine.get_client().terminate_execution(self.id, cause)
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)
def get_node_executions(self, filters: List[_filter_models.Filter] = None) -> Dict[str, _nodes.FlyteNodeExecution]: client = _flyte_engine.get_client() return { node.id.node_id: _nodes.FlyteNodeExecution.promote_from_model(node) for node in _iterate_node_executions(client, self.id, filters=filters) }