@@ -27,6 +27,7 @@ class SdkLaunchPlan(
2727):
2828 def __init__ (self , * args , ** kwargs ):
2929 super (SdkLaunchPlan , self ).__init__ (* args , ** kwargs )
30+ # Set all the attributes we expect this class to have
3031 self ._id = None
3132
3233 # The interface is not set explicitly unless fetched in an engine context
@@ -79,26 +80,6 @@ def fetch(cls, project, domain, name, version=None):
7980 sdk_lp ._interface = lp_wf .interface
8081 return sdk_lp
8182
82- @_exception_scopes .system_entry_point
83- def register (self , project , domain , name , version ):
84- """
85- :param Text project:
86- :param Text domain:
87- :param Text name:
88- :param Text version:
89- """
90- self .validate ()
91- id_to_register = _identifier .Identifier (
92- _identifier_model .ResourceType .LAUNCH_PLAN ,
93- project ,
94- domain ,
95- name ,
96- version
97- )
98- _engine_loader .get_engine ().get_launch_plan (self ).register (id_to_register )
99- self ._id = id_to_register
100- return _six .text_type (self .id )
101-
10283 @property
10384 def id (self ):
10485 """
@@ -225,12 +206,43 @@ def execute_with_literals(self, project, domain, literal_inputs, name=None, noti
225206
226207 @_exception_scopes .system_entry_point
227208 def __call__ (self , * args , ** input_map ):
228- raise _user_exceptions .FlyteAssertion (
229- "TODO: Implement adding of remote launch plans to workflows. Current workaround is to add remote "
230- "workflows directly."
209+ """
210+ :param list[T] args: Do not specify. Kwargs only are supported for this function.
211+ :param dict[Text,T] input_map: Map of inputs. Can be statically defined or OutputReference links.
212+ :rtype: flytekit.common.nodes.SdkNode
213+ """
214+ if len (args ) > 0 :
215+ raise _user_exceptions .FlyteAssertion (
216+ "When adding a launchplan as a node in a workflow, all inputs must be specified with kwargs only. We "
217+ "detected {} positional args." .format (self , len (args ))
218+ )
219+
220+ # Take the default values from the launch plan
221+ default_inputs = {
222+ k : v .sdk_default
223+ for k , v in _six .iteritems (self .default_inputs .parameters ) if not v .required
224+ }
225+ default_inputs .update (input_map )
226+
227+ bindings , upstream_nodes = self .interface .create_bindings_for_inputs (default_inputs )
228+
229+ return _nodes .SdkNode (
230+ id = None ,
231+ metadata = _workflow_models .NodeMetadata ("" , _datetime .timedelta (), _literal_models .RetryStrategy (0 )),
232+ bindings = sorted (bindings , key = lambda b : b .var ),
233+ upstream_nodes = upstream_nodes ,
234+ sdk_launch_plan = self
231235 )
232236
237+ def __repr__ (self ):
238+ """
239+ :rtype: Text
240+ """
241+ return "SdkLaunchPlan(ID: {} Interface: {} WF ID: {})" .format (self .id , self .interface , self .workflow_id )
242+
233243
244+ # The difference between this and the SdkLaunchPlan class is that this runnable class is supposed to only be used for
245+ # launch plans loaded alongside the current Python interpreter.
234246class SdkRunnableLaunchPlan (
235247 _hash_mixin .HashOnReferenceMixin ,
236248 SdkLaunchPlan ,
@@ -272,14 +284,14 @@ def __init__(
272284 if role :
273285 auth = _launch_plan_models .Auth (assumable_iam_role = role )
274286
287+ # The constructor for SdkLaunchPlan sets the id to None anyways so we don't bother passing in an ID. The ID
288+ # should be set in one of three places,
289+ # 1) When the object is registered (in the code above)
290+ # 2) By the dynamic task code after this runnable object has already been __call__'ed. The SdkNode produced
291+ # maintains a link to this object and will set the ID according to the configuration variables present.
292+ # 3) When SdkLaunchPlan.fetch() is run
275293 super (SdkRunnableLaunchPlan , self ).__init__ (
276- _identifier .Identifier (
277- _identifier_model .ResourceType .WORKFLOW ,
278- _internal_config .PROJECT .get (),
279- _internal_config .DOMAIN .get (),
280- _uuid .uuid4 ().hex ,
281- _internal_config .VERSION .get ()
282- ),
294+ None ,
283295 _launch_plan_models .LaunchPlanMetadata (
284296 schedule = schedule or _schedule_model .Schedule ('' ),
285297 notifications = notifications or []
@@ -303,6 +315,26 @@ def __init__(
303315 self ._upstream_entities = {sdk_workflow }
304316 self ._sdk_workflow = sdk_workflow
305317
318+ @_exception_scopes .system_entry_point
319+ def register (self , project , domain , name , version ):
320+ """
321+ :param Text project:
322+ :param Text domain:
323+ :param Text name:
324+ :param Text version:
325+ """
326+ self .validate ()
327+ id_to_register = _identifier .Identifier (
328+ _identifier_model .ResourceType .LAUNCH_PLAN ,
329+ project ,
330+ domain ,
331+ name ,
332+ version
333+ )
334+ _engine_loader .get_engine ().get_launch_plan (self ).register (id_to_register )
335+ self ._id = id_to_register
336+ return _six .text_type (self .id )
337+
306338 @classmethod
307339 def from_flyte_idl (cls , _ ):
308340 raise _user_exceptions .FlyteAssertion (
@@ -356,33 +388,8 @@ def workflow_id(self):
356388 """
357389 return self ._sdk_workflow .id
358390
359- @_exception_scopes .system_entry_point
360- def __call__ (self , * args , ** input_map ):
391+ def __repr__ (self ):
361392 """
362- :param list[T] args: Do not specify. Kwargs only are supported for this function.
363- :param dict[Text,T] input_map: Map of inputs. Can be statically defined or OutputReference links.
364- :rtype: flytekit.common.nodes.SdkNode
393+ :rtype: Text
365394 """
366- if len (args ) > 0 :
367- raise _user_exceptions .FlyteAssertion (
368- "When adding a launchplan as a node in a workflow, all inputs must be specified with kwargs only. We "
369- "detected {} positional args." .format (self , len (args ))
370- )
371-
372- # Take the default values from the launch plan
373- default_inputs = {
374- k : v .sdk_default
375- for k , v in _six .iteritems (self .default_inputs .parameters ) if not v .required
376- }
377- default_inputs .update (input_map )
378-
379- bindings , upstream_nodes = self .interface .create_bindings_for_inputs (default_inputs )
380-
381- # TODO: Remove DEADBEEF
382- return _nodes .SdkNode (
383- id = None ,
384- metadata = _workflow_models .NodeMetadata ("DEADBEEF" , _datetime .timedelta (), _literal_models .RetryStrategy (0 )),
385- bindings = sorted (bindings , key = lambda b : b .var ),
386- upstream_nodes = upstream_nodes ,
387- sdk_launch_plan = self
388- )
395+ return "SdkRunnableLaunchPlan(ID: {} Interface: {} WF ID: {})" .format (self .id , self .interface , self .workflow_id )
0 commit comments