/
main.py
1874 lines (1660 loc) · 68.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import absolute_import
import importlib as _importlib
import os as _os
import sys as _sys
import stat as _stat
import click as _click
import six as _six
from flyteidl.core import literals_pb2 as _literals_pb2, identifier_pb2 as _identifier_pb2
from flyteidl.admin import launch_plan_pb2 as _launch_plan_pb2, workflow_pb2 as _workflow_pb2, task_pb2 as _task_pb2
from flytekit import __version__
from flytekit.clients import friendly as _friendly_client
from flytekit.clis.helpers import construct_literal_map_from_variable_map as _construct_literal_map_from_variable_map, \
construct_literal_map_from_parameter_map as _construct_literal_map_from_parameter_map, \
parse_args_into_dict as _parse_args_into_dict
from flytekit.common import utils as _utils, launch_plan as _launch_plan_common
from flytekit.common.core import identifier as _identifier
from flytekit.common.tasks import task as _tasks_common
from flytekit.common.types import helpers as _type_helpers
from flytekit.common.utils import load_proto_from_file as _load_proto_from_file
from flytekit.configuration import platform as _platform_config
from flytekit.configuration import set_flyte_config_file
from flytekit.interfaces.data import data_proxy as _data_proxy
from flytekit.models import common as _common_models, filters as _filters, launch_plan as _launch_plan, literals as \
_literals, named_entity as _named_entity
from flytekit.models.admin import common as _admin_common
from flytekit.models.core import execution as _core_execution_models, identifier as _core_identifier
from flytekit.models.execution import ExecutionSpec as _ExecutionSpec, ExecutionMetadata as _ExecutionMetadata
from flytekit.models.matchable_resource import ClusterResourceAttributes as _ClusterResourceAttributes,\
ExecutionQueueAttributes as _ExecutionQueueAttributes, ExecutionClusterLabel as _ExecutionClusterLabel,\
MatchingAttributes as _MatchingAttributes
from flytekit.models.project import Project as _Project
from flytekit.models.schedule import Schedule as _Schedule
from flytekit.common.exceptions import user as _user_exceptions
import requests as _requests
try: # Python 3
import urllib.parse as _urlparse
except ImportError: # Python 2
import urlparse as _urlparse
_tt = _six.text_type
# Similar to how kubectl has a config file in the users home directory, this Flyte CLI will also look for one.
# The format of this config file is the same as a workflow's config file, except that the relevant fields are different.
# Please see the example.config file
_default_config_file_dir = ".flyte"
_default_config_file_name = "config"
def _welcome_message():
_click.secho("Welcome to Flyte CLI! Version: {}".format(_tt(__version__)), bold=True)
def _get_user_filepath_home():
return _os.path.expanduser("~")
def _get_config_file_path():
home = _get_user_filepath_home()
return _os.path.join(home, _default_config_file_dir, _default_config_file_name)
def _detect_default_config_file():
config_file = _get_config_file_path()
if _get_user_filepath_home() and _os.path.exists(config_file):
_click.secho("Using default config file at {}".format(_tt(config_file)), fg='blue')
set_flyte_config_file(config_file_path=config_file)
else:
_click.secho("""Config file not found at default location, relying on environment variables instead.
To setup your config file run 'flyte-cli setup-config'""", fg='blue')
# Run this as the module is loading to pick up settings that click can then use when constructing the commands
_detect_default_config_file()
def _get_io_string(literal_map, verbose=False):
"""
:param flytekit.models.literals.LiteralMap literal_map:
:param bool verbose:
:rtype: Text
"""
value_dict = _type_helpers.unpack_literal_map_to_sdk_object(literal_map)
if value_dict:
return "\n" + "\n".join(
"{:30}: {}".format(
k,
_prefix_lines("{:30} ".format(""), v.verbose_string() if verbose else v.short_string())
) for k, v in _six.iteritems(value_dict)
)
else:
return "(None)"
def _fetch_and_stringify_literal_map(path, verbose=False):
"""
:param Text path:
:param bool verbose:
:rtype: Text
"""
with _utils.AutoDeletingTempDir("flytecli") as tmp:
try:
fname = tmp.get_named_tempfile("literalmap.pb")
_data_proxy.Data.get_data(path, fname)
literal_map = _literals.LiteralMap.from_flyte_idl(
_utils.load_proto_from_file(_literals_pb2.LiteralMap, fname)
)
return _get_io_string(literal_map, verbose=verbose)
except:
return "Failed to pull data from {}. Do you have permissions?".format(path)
def _prefix_lines(prefix, txt):
"""
:param Text prefix:
:param Text txt:
:rtype: Text
"""
return "\n{}".format(prefix).join(txt.splitlines())
def _secho_workflow_status(status, nl=True):
red_phases = {
_core_execution_models.WorkflowExecutionPhase.FAILED,
_core_execution_models.WorkflowExecutionPhase.ABORTED,
_core_execution_models.WorkflowExecutionPhase.FAILING,
_core_execution_models.WorkflowExecutionPhase.TIMED_OUT
}
yellow_phases = {
_core_execution_models.WorkflowExecutionPhase.QUEUED,
_core_execution_models.WorkflowExecutionPhase.UNDEFINED
}
green_phases = {
_core_execution_models.WorkflowExecutionPhase.SUCCEEDED,
_core_execution_models.WorkflowExecutionPhase.SUCCEEDING
}
if status in red_phases:
fg = 'red'
elif status in yellow_phases:
fg = 'yellow'
elif status in green_phases:
fg = 'green'
else:
fg = 'blue'
_click.secho(
"{:10} ".format(_tt(_core_execution_models.WorkflowExecutionPhase.enum_to_string(status))),
bold=True,
fg=fg,
nl=nl
)
def _secho_node_execution_status(status, nl=True):
red_phases = {
_core_execution_models.NodeExecutionPhase.FAILING,
_core_execution_models.NodeExecutionPhase.FAILED,
_core_execution_models.NodeExecutionPhase.ABORTED,
_core_execution_models.NodeExecutionPhase.TIMED_OUT
}
yellow_phases = {
_core_execution_models.NodeExecutionPhase.QUEUED,
_core_execution_models.NodeExecutionPhase.UNDEFINED
}
green_phases = {
_core_execution_models.NodeExecutionPhase.SUCCEEDED
}
if status in red_phases:
fg = 'red'
elif status in yellow_phases:
fg = 'yellow'
elif status in green_phases:
fg = 'green'
else:
fg = 'blue'
_click.secho(
"{:10} ".format(_tt(_core_execution_models.NodeExecutionPhase.enum_to_string(status))),
bold=True,
fg=fg,
nl=nl
)
def _secho_task_execution_status(status, nl=True):
red_phases = {
_core_execution_models.TaskExecutionPhase.ABORTED,
_core_execution_models.TaskExecutionPhase.FAILED,
}
yellow_phases = {
_core_execution_models.TaskExecutionPhase.QUEUED,
_core_execution_models.TaskExecutionPhase.UNDEFINED,
_core_execution_models.TaskExecutionPhase.RUNNING
}
green_phases = {
_core_execution_models.TaskExecutionPhase.SUCCEEDED
}
if status in red_phases:
fg = 'red'
elif status in yellow_phases:
fg = 'yellow'
elif status in green_phases:
fg = 'green'
else:
fg = 'blue'
_click.secho(
"{:10} ".format(_tt(_core_execution_models.TaskExecutionPhase.enum_to_string(status))),
bold=True,
fg=fg,
nl=nl
)
def _secho_one_execution(ex, urns_only):
if not urns_only:
_click.echo(
"{:100} {:40} {:40}".format(
_tt(_identifier.WorkflowExecutionIdentifier.promote_from_model(ex.id)),
_tt(ex.id.name),
_tt(ex.spec.launch_plan.name),
),
nl=False
)
_secho_workflow_status(ex.closure.phase)
else:
_click.echo(
"{:100}".format(
_tt(_identifier.WorkflowExecutionIdentifier.promote_from_model(ex.id))
),
nl=True
)
def _terminate_one_execution(client, urn, cause, shouldPrint=True):
if shouldPrint:
_click.echo("{:100} {:40}".format(_tt(urn), _tt(cause)))
client.terminate_execution(
_identifier.WorkflowExecutionIdentifier.from_python_std(urn),
cause
)
def _update_one_launch_plan(urn, host, insecure, state):
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
if state == "active":
state = _launch_plan.LaunchPlanState.ACTIVE
else:
state = _launch_plan.LaunchPlanState.INACTIVE
client.update_launch_plan(_identifier.Identifier.from_python_std(urn), state)
_click.echo("Successfully updated {}".format(_tt(urn)))
def _render_schedule_expr(lp):
sched_expr = "NONE"
if lp.spec.entity_metadata.schedule.cron_expression:
sched_expr = "cron({cron_expr})".format(
cron_expr=_tt(lp.spec.entity_metadata.schedule.cron_expression)
)
elif lp.spec.entity_metadata.schedule.rate:
sched_expr = "rate({unit}={value})".format(
unit=_tt(_Schedule.FixedRateUnit.enum_to_string(
lp.spec.entity_metadata.schedule.rate.unit
)),
value=_tt(lp.spec.entity_metadata.schedule.rate.value)
)
return "{:30}".format(sched_expr)
# These two flags are special in that they are specifiable in both the user's default ~/.flyte/config file, and in the
# flyte-cli command itself, both in the parent-command position (flyte-cli) , and in the child-command position
# (e.g. list-task-names). To get around this, first we read the value of the config object, and store it. Later in the
# file below are options for each of these options, one for the parent command, and one for the child command. If not
# set by the parent, and also not set by the child, then the value from the config file is used.
#
# For both host and insecure, command line values will override the setting in ~/.flyte/config file.
#
# The host url option is a required setting, so if missing it will fail, but it may be set in the click command, so we
# don't have to check now. It will be checked later.
_HOST_URL = None
try:
_HOST_URL = _platform_config.URL.get()
except _user_exceptions.FlyteAssertion:
pass
_INSECURE_FLAG = _platform_config.INSECURE.get()
_PROJECT_FLAGS = ["-p", "--project"]
_DOMAIN_FLAGS = ["-d", "--domain"]
_NAME_FLAGS = ["-n", "--name"]
_HOST_FLAGS = ["-h", "--host"]
_PRINCIPAL_FLAGS = ["-r", "--principal"]
_INSECURE_FLAGS = ["-i", "--insecure"]
_project_option = _click.option(
*_PROJECT_FLAGS,
required=True,
help="The project namespace to query."
)
_optional_project_option = _click.option(
*_PROJECT_FLAGS,
required=False,
default=None,
help="[Optional] The project namespace to query."
)
_domain_option = _click.option(
*_DOMAIN_FLAGS,
required=True,
help="The domain namespace to query."
)
_optional_domain_option = _click.option(
*_DOMAIN_FLAGS,
required=False,
default=None,
help="[Optional] The domain namespace to query."
)
_name_option = _click.option(
*_NAME_FLAGS,
required=True,
help="The name to query."
)
_optional_name_option = _click.option(
*_NAME_FLAGS,
required=False,
type=str,
default=None,
help="[Optional] The name to query."
)
_principal_option = _click.option(
*_PRINCIPAL_FLAGS,
required=True,
help="Your team name, or your name"
)
_optional_principal_option = _click.option(
*_PRINCIPAL_FLAGS,
required=False,
type=str,
default=None,
help="[Optional] Your team name, or your name"
)
_insecure_option = _click.option(
*_INSECURE_FLAGS,
is_flag=True,
required=False,
default=_INSECURE_FLAG,
help="Do not use SSL"
)
_insecure_optional_option = _click.option(
*_INSECURE_FLAGS,
is_flag=True,
required=False,
default=False,
help="Do not use SSL communication"
)
_urn_option = _click.option(
"-u", "--urn",
required=True,
help="The unique identifier for an entity."
)
_optional_urn_option = _click.option(
"-u", "--urn",
required=False,
help="The unique identifier for an entity."
)
_host_option = _click.option(
*_HOST_FLAGS,
required=not bool(_HOST_URL),
default=_HOST_URL,
help="The URL for the Flyte Admin Service. If you intend for this to be consistent, set the FLYTE_PLATFORM_URL "
"environment variable to the desired URL and this will not need to be set."
)
_token_option = _click.option(
"-t", "--token",
required=False,
default="",
type=str,
help="Pagination token from which to start listing in the list of results."
)
_limit_option = _click.option(
"-l", "--limit",
required=False,
default=100,
type=int,
help="Maximum number of results to return for this call."
)
_show_all_option = _click.option(
"-a", "--show-all",
is_flag=True,
default=False,
help="Set this flag to page through and list all results."
)
# TODO: Provide documentation on filter format
_filter_option = _click.option(
"-f", "--filter",
multiple=True,
help="Filter to be applied. Multiple filters can be applied and they will be ANDed together."
)
_state_choice = _click.option(
"--state",
type=_click.Choice(["active", "inactive"]),
required=True,
help="Whether or not to set schedule as active."
)
_named_entity_state_choice = _click.option(
"--state",
type=_click.Choice(["active", "archived"]),
required=True,
help="The state change to apply to a named entity"
)
_named_entity_description_option = _click.option(
"--description",
required=False,
type=str,
help="Concise description for the entity."
)
_sort_by_option = _click.option(
"--sort-by",
required=False,
help="Provide an entity type and field to be sorted. i.e. asc(workflow.name) or desc(workflow.name)"
)
_show_io_option = _click.option(
"--show-io",
is_flag=True,
default=False,
help="Set this flag to view inputs and outputs. Pair with the --verbose flag to get the full textual description"
" inputs and outputs."
)
_verbose_option = _click.option(
"--verbose",
is_flag=True,
default=False,
help="Set this flag to view the full textual description of all fields."
)
_filename_option = _click.option(
'-f', '--filename',
required=True,
help="File path of pb file"
)
_idl_class_option = _click.option(
'-p', '--proto_class',
required=True,
help="Dot (.) separated path to Python IDL class. (e.g. flyteidl.core.workflow_closure_pb2.WorkflowClosure)"
)
_cause_option = _click.option(
'-c', '--cause',
required=True,
help="The message signaling the cause of the termination of the execution(s)"
)
_optional_urns_only_option = _click.option(
'--urns-only',
is_flag=True,
default=False,
required=False,
help="[Optional] Set the flag if you want to list the urns only"
)
_project_identifier_option = _click.option(
'--identifier',
required=True,
type=str,
help="Unique identifier for the project."
)
_project_name_option = _click.option(
'-n', '--name',
required=True,
type=str,
help="The human-readable name for the project."
)
_project_description_option = _click.option(
'-d', '--description',
required=True,
type=str,
help="Concise description for the project."
)
class _FlyteSubCommand(_click.Command):
_PASSABLE_ARGS = {
'project': _PROJECT_FLAGS[0],
'domain': _DOMAIN_FLAGS[0],
'name': _NAME_FLAGS[0],
'host': _HOST_FLAGS[0],
}
_PASSABLE_FLAGS = {
'insecure': _INSECURE_FLAGS[0],
}
def make_context(self, cmd_name, args, parent=None):
prefix_args = []
for param in self.params:
if param.name in type(self)._PASSABLE_ARGS and \
param.name in parent.params and \
parent.params[param.name] is not None:
prefix_args.extend([type(self)._PASSABLE_ARGS[param.name], _six.text_type(parent.params[param.name])])
# For flags, we don't append the value of the flag, otherwise click will fail to parse
if param.name in type(self)._PASSABLE_FLAGS and \
param.name in parent.params and \
parent.params[param.name]:
prefix_args.append(type(self)._PASSABLE_FLAGS[param.name])
ctx = super(_FlyteSubCommand, self).make_context(cmd_name, prefix_args + args, parent=parent)
return ctx
@_click.option(
*_HOST_FLAGS,
required=False,
type=str,
default=None,
help="[Optional] The host to pass to the sub-command (if applicable). If set again in the sub-command, "
"the sub-command's parameter takes precedence."
)
@_click.option(
*_PROJECT_FLAGS,
required=False,
type=str,
default=None,
help="[Optional] The project to pass to the sub-command (if applicable) If set again in the sub-command, "
"the sub-command's parameter takes precedence."
)
@_click.option(
*_DOMAIN_FLAGS,
required=False,
type=str,
default=None,
help="[Optional] The domain to pass to the sub-command (if applicable) If set again in the sub-command, "
"the sub-command's parameter takes precedence."
)
@_click.option(
*_NAME_FLAGS,
required=False,
type=str,
default=None,
help="[Optional] The name to pass to the sub-command (if applicable) If set again in the sub-command, "
"the sub-command's parameter takes precedence."
)
@_insecure_optional_option
@_click.group("flyte-cli")
@_click.pass_context
def _flyte_cli(ctx, host, project, domain, name, insecure):
"""
Command line tool for interacting with all entities on the Flyte Platform.
"""
pass
########################################################################################################################
#
# Miscellaneous Commands
#
########################################################################################################################
@_flyte_cli.command('parse-proto', cls=_click.Command)
@_filename_option
@_idl_class_option
def parse_proto(filename, proto_class):
_welcome_message()
splitted = proto_class.split('.')
idl_module = '.'.join(splitted[:-1])
idl_obj = splitted[-1]
mod = _importlib.import_module(idl_module)
idl = getattr(mod, idl_obj)
obj = _load_proto_from_file(idl, filename)
_click.echo(obj)
_click.echo("")
########################################################################################################################
#
# Task Commands
#
########################################################################################################################
@_flyte_cli.command('list-task-names', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_sort_by_option
def list_task_names(project, domain, host, insecure, token, limit, show_all, sort_by):
"""
List the name of the tasks that are in the registered workflow under
a specific project and domain.
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
_click.echo("Task Names Found in {}:{}\n".format(_tt(project), _tt(domain)))
while True:
task_ids, next_token = client.list_task_ids_paginated(
project,
domain,
limit=limit,
token=token,
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for t in task_ids:
_click.echo("\t{}".format(_tt(t.name)))
if show_all is not True:
if next_token:
_click.echo("Received next token: {}\n".format(next_token))
break
if not next_token:
break
token = next_token
_click.echo("")
@_flyte_cli.command('list-task-versions', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_optional_name_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_filter_option
@_sort_by_option
def list_task_versions(project, domain, name, host, insecure, token, limit, show_all, filter, sort_by):
"""
List all the versions of the tasks under a specific {Project, Domain} tuple.
If the name of a certain task is supplied, this command will list all the
versions of that particular task (identifiable by {Project, Domain, Name}).
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
_click.echo("Task Versions Found for {}:{}:{}\n".format(_tt(project), _tt(domain), _tt(name or '*')))
_click.echo("{:50} {:40}".format('Version', 'Urn'))
while True:
task_list, next_token = client.list_tasks_paginated(
_common_models.NamedEntityIdentifier(
project,
domain,
name
),
limit=limit,
token=token,
filters=[_filters.Filter.from_python_std(f) for f in filter],
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for t in task_list:
_click.echo("{:50} {:40}".format(_tt(t.id.version), _tt(_identifier.Identifier.promote_from_model(t.id))))
if show_all is not True:
if next_token:
_click.echo("Received next token: {}\n".format(next_token))
break
if not next_token:
break
token = next_token
_click.echo("")
@_flyte_cli.command('get-task', cls=_FlyteSubCommand)
@_urn_option
@_host_option
@_insecure_option
def get_task(urn, host, insecure):
"""
Get the details of a certain version of a task identified by the URN of it.
The URN of the versioned task is in the form of ``tsk:<project>:<domain>:<task_name>:<version>``.
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
t = client.get_task(_identifier.Identifier.from_python_std(urn))
_click.echo(_tt(t))
_click.echo("")
@_flyte_cli.command('launch-task', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_optional_name_option
@_host_option
@_insecure_option
@_urn_option
@_click.argument('task_args', nargs=-1, type=_click.UNPROCESSED)
def launch_task(project, domain, name, host, insecure, urn, task_args):
"""
Kick off a single task execution. Note that the {project, domain, name} specified in the command line
will be for the execution. The project/domain for the task are specified in the urn.
Use a -- to separate arguments to this cli, and arguments to the task.
e.g.
$ flyte-cli -h localhost:30081 -p flyteexamples -d development launch-task \
-u tsk:flyteexamples:development:some-task:abc123 -- input=hi \
other-input=123 moreinput=qwerty
These arguments are then collected, and passed into the `task_args` variable as a Tuple[Text].
Users should use the get-task command to ascertain the names of inputs to use.
"""
_welcome_message()
with _platform_config.URL.get_patcher(host), _platform_config.INSECURE.get_patcher(_tt(insecure)):
task_id = _identifier.Identifier.from_python_std(urn)
task = _tasks_common.SdkTask.fetch(task_id.project, task_id.domain, task_id.name, task_id.version)
text_args = _parse_args_into_dict(task_args)
inputs = {}
for var_name, variable in _six.iteritems(task.interface.inputs):
sdk_type = _type_helpers.get_sdk_type_from_literal_type(variable.type)
if var_name in text_args and text_args[var_name] is not None:
inputs[var_name] = sdk_type.from_string(text_args[var_name]).to_python_std()
# TODO: Implement notification overrides
# TODO: Implement label overrides
# TODO: Implement annotation overrides
execution = task.launch(project, domain, inputs=inputs, name=name)
_click.secho("Launched execution: {}".format(_tt(execution.id)), fg='blue')
_click.echo("")
########################################################################################################################
#
# Workflow Commands
#
########################################################################################################################
@_flyte_cli.command('list-workflow-names', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_sort_by_option
def list_workflow_names(project, domain, host, insecure, token, limit, show_all, sort_by):
"""
List the names of the workflows under a scope specified by ``{project, domain}``.
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
_click.echo("Workflow Names Found in {}:{}\n".format(_tt(project), _tt(domain)))
while True:
wf_ids, next_token = client.list_workflow_ids_paginated(
project,
domain,
limit=limit,
token=token,
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for i in wf_ids:
_click.echo("\t{}".format(_tt(i.name)))
if show_all is not True:
if next_token:
_click.echo("Received next token: {}\n".format(next_token))
break
if not next_token:
break
token = next_token
_click.echo("")
@_flyte_cli.command('list-workflow-versions', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_optional_name_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_filter_option
@_sort_by_option
def list_workflow_versions(project, domain, name, host, insecure, token, limit, show_all, filter, sort_by):
"""
List all the versions of the workflows under the scope specified by ``{project, domain}``.
If the name of a a certain workflow is supplied, this command will list all the
versions of that particular workflow (identifiable by ``{project, domain, name}``).
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
_click.echo("Workflow Versions Found for {}:{}:{}\n".format(_tt(project), _tt(domain), _tt(name or '*')))
_click.echo("{:50} {:40}".format('Version', 'Urn'))
while True:
wf_list, next_token = client.list_workflows_paginated(
_common_models.NamedEntityIdentifier(
project,
domain,
name
),
limit=limit,
token=token,
filters=[_filters.Filter.from_python_std(f) for f in filter],
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for w in wf_list:
_click.echo("{:50} {:40}".format(_tt(w.id.version), _tt(_identifier.Identifier.promote_from_model(w.id))))
if show_all is not True:
if next_token:
_click.echo("Received next token: {}\n".format(next_token))
break
if not next_token:
break
token = next_token
_click.echo("")
@_flyte_cli.command('get-workflow', cls=_FlyteSubCommand)
@_urn_option
@_host_option
@_insecure_option
def get_workflow(urn, host, insecure):
"""
Get the details of a certain version of a workflow identified by the URN in the form of
``wf:<project>:<domain>:<workflow_name>:<version>``
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
_click.echo(client.get_workflow(_identifier.Identifier.from_python_std(urn)))
# TODO: Print workflow pretty
_click.echo("")
########################################################################################################################
#
# Launch Plan Commands
#
########################################################################################################################
@_flyte_cli.command('list-launch-plan-names', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_sort_by_option
def list_launch_plan_names(project, domain, host, insecure, token, limit, show_all, sort_by):
"""
List the names of the launch plans under the scope specified by {project, domain}.
"""
_welcome_message()
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
_click.echo("Launch Plan Names Found in {}:{}\n".format(_tt(project), _tt(domain)))
while True:
wf_ids, next_token = client.list_launch_plan_ids_paginated(
project,
domain,
limit=limit,
token=token,
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for i in wf_ids:
_click.echo("\t{}".format(_tt(i.name)))
if show_all is not True:
if next_token:
_click.echo("Received next token: {}\n".format(next_token))
break
if not next_token:
break
token = next_token
_click.echo("")
@_flyte_cli.command('list-active-launch-plans', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_sort_by_option
@_optional_urns_only_option
def list_active_launch_plans(project, domain, host, insecure, token, limit, show_all, sort_by, urns_only):
"""
List the information of all the active launch plans under the scope specified by {project, domain}.
An active launch plan is a launch plan with an active schedule associated with it.
"""
if not urns_only:
_welcome_message()
_click.echo("Active Launch Plan Found in {}:{}\n".format(_tt(project), _tt(domain)))
_click.echo("{:30} {:50} {:80}".format('Schedule', 'Version', 'Urn'))
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
while True:
active_lps, next_token = client.list_active_launch_plans_paginated(
project,
domain,
limit=limit,
token=token,
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for lp in active_lps:
if urns_only:
_click.echo("{:80}".format(
_tt(_identifier.Identifier.promote_from_model(lp.id))
))
else:
_click.echo(
"{:30} {:50} {:80}".format(
_render_schedule_expr(lp),
_tt(lp.id.version),
_tt(_identifier.Identifier.promote_from_model(lp.id)),
),
)
if show_all is not True:
if next_token and not urns_only:
_click.echo("Received next token: {}\n".format(next_token))
break
if not next_token:
break
token = next_token
if not urns_only:
_click.echo("")
return
@_flyte_cli.command('list-launch-plan-versions', cls=_FlyteSubCommand)
@_project_option
@_domain_option
@_optional_name_option
@_host_option
@_insecure_option
@_token_option
@_limit_option
@_show_all_option
@_filter_option
@_sort_by_option
@_optional_urns_only_option
def list_launch_plan_versions(project, domain, name, host, insecure, token, limit, show_all, filter, sort_by,
urns_only):
"""
List the versions of all the launch plans under the scope specified by {project, domain}.
"""
if not urns_only:
_welcome_message()
_click.echo("Launch Plan Versions Found for {}:{}:{}\n".format(_tt(project), _tt(domain), _tt(name)))
_click.echo("{:50} {:80} {:30} {:15}".format('Version', 'Urn', "Schedule", "Schedule State"))
client = _friendly_client.SynchronousFlyteClient(host, insecure=insecure)
while True:
lp_list, next_token = client.list_launch_plans_paginated(
_common_models.NamedEntityIdentifier(
project,
domain,
name
),
limit=limit,
token=token,
filters=[_filters.Filter.from_python_std(f) for f in filter],
sort_by=_admin_common.Sort.from_python_std(sort_by) if sort_by else None
)
for l in lp_list:
if urns_only:
_click.echo(_tt(_identifier.Identifier.promote_from_model(l.id)))
else:
_click.echo(
"{:50} {:80} ".format(
_tt(l.id.version),
_tt(_identifier.Identifier.promote_from_model(l.id))
),
nl=False
)
if l.spec.entity_metadata.schedule.cron_expression or l.spec.entity_metadata.schedule.rate:
_click.echo(
"{:30} ".format(_render_schedule_expr(l)),
nl=False
)
_click.secho(
_launch_plan.LaunchPlanState.enum_to_string(l.closure.state),
fg="green" if l.closure.state == _launch_plan.LaunchPlanState.ACTIVE else None
)
else:
_click.echo()
if show_all is not True:
if next_token and not urns_only:
_click.echo("Received next token: {}\n".format(next_token))