def serialize(self): """ Serializing a launch plan should produce an object similar to what the registration step produces, in preparation for actual registration to Admin. :rtype: flyteidl.admin.launch_plan_pb2.LaunchPlan """ return _launch_plan_models.LaunchPlan( id=self.id, spec=self, closure=_launch_plan_models.LaunchPlanClosure( state=None, expected_inputs=_interface_models.ParameterMap({}), expected_outputs=_interface_models.VariableMap({}), ), ).to_flyte_idl()
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"))
def get_serializable_launch_plan( entity_mapping: OrderedDict, settings: SerializationSettings, entity: LaunchPlan, fast: bool, ) -> _launch_plan_models.LaunchPlan: wf_spec = get_serializable(entity_mapping, settings, entity.workflow) lps = _launch_plan_models.LaunchPlanSpec( workflow_id=wf_spec.template.id, entity_metadata=_launch_plan_models.LaunchPlanMetadata( schedule=entity.schedule, notifications=entity.notifications, ), default_inputs=entity.parameters, fixed_inputs=entity.fixed_inputs, labels=entity.labels or _common_models.Labels({}), annotations=entity.annotations or _common_models.Annotations({}), auth_role=entity._auth_role or _common_models.AuthRole(), raw_output_data_config=entity.raw_output_data_config or _common_models.RawOutputDataConfig(""), ) lp_id = _identifier_model.Identifier( resource_type=_identifier_model.ResourceType.LAUNCH_PLAN, project=settings.project, domain=settings.domain, name=entity.name, version=settings.version, ) lp_model = _launch_plan_models.LaunchPlan( id=lp_id, spec=lps, closure=_launch_plan_models.LaunchPlanClosure( state=None, expected_inputs=interface_models.ParameterMap({}), expected_outputs=interface_models.VariableMap({}), ), ) return lp_model
def get_serializable_launch_plan( entity_mapping: OrderedDict, settings: SerializationSettings, entity: LaunchPlan, recurse_downstream: bool = True, options: Optional[Options] = None, ) -> _launch_plan_models.LaunchPlan: """ :param entity_mapping: :param settings: :param entity: :param options: :param recurse_downstream: This boolean indicate is wf for the entity should also be recursed to :return: """ if recurse_downstream: wf_spec = get_serializable(entity_mapping, settings, entity.workflow, options) wf_id = wf_spec.template.id else: wf_id = _identifier_model.Identifier( resource_type=_identifier_model.ResourceType.WORKFLOW, project=settings.project, domain=settings.domain, name=entity.workflow.name, version=settings.version, ) if not options: options = Options() if options and options.raw_output_data_config: raw_prefix_config = options.raw_output_data_config else: raw_prefix_config = entity.raw_output_data_config or _common_models.RawOutputDataConfig( "") lps = _launch_plan_models.LaunchPlanSpec( workflow_id=wf_id, entity_metadata=_launch_plan_models.LaunchPlanMetadata( schedule=entity.schedule, notifications=options.notifications or entity.notifications, ), default_inputs=entity.parameters, fixed_inputs=entity.fixed_inputs, labels=options.labels or entity.labels or _common_models.Labels({}), annotations=options.annotations or entity.annotations or _common_models.Annotations({}), auth_role=None, raw_output_data_config=raw_prefix_config, max_parallelism=options.max_parallelism or entity.max_parallelism, security_context=options.security_context or entity.security_context, ) lp_id = _identifier_model.Identifier( resource_type=_identifier_model.ResourceType.LAUNCH_PLAN, project=settings.project, domain=settings.domain, name=entity.name, version=settings.version, ) lp_model = _launch_plan_models.LaunchPlan( id=lp_id, spec=lps, closure=_launch_plan_models.LaunchPlanClosure( state=None, expected_inputs=interface_models.ParameterMap({}), expected_outputs=interface_models.VariableMap({}), ), ) return lp_model