@@ -64,6 +64,43 @@ def show(ctx, runid, jobid=None, pagesize=None, pageno=None, logfileposition=Non
64
64
sys .exit (1 )
65
65
66
66
67
+ @log .command (context_settings = dict (max_content_width = 2000 ), cls = command_required_option_from_option ())
68
+ @click .option ('-j' , '--jobid' , help = "jobid and name is one of required field" )
69
+ @click .option ('-n' , '--name' , help = "name" )
70
+ @click .option ('-ns' , '--namespace' , help = "namespace" )
71
+ @click .option ('-c' , '--clustername' , help = "clustername" )
72
+ @click .option ('-r' , '--readfromtail' , help = "read logs from tail, set value means yes" )
73
+ @click .option ('-l' , '--line_limit' , help = "line_limit, default is 1000" )
74
+ @click .option ('-s' , '--size_limit' , help = "size_limit, default is 100MB" )
75
+ @click .option ('-t' , '--type' , help = "type in deploy or pod" )
76
+ @click .option ('-f' , '--framework' , help = "job framework" )
77
+ @click .pass_context
78
+ def showlimit (ctx , jobid = None , name = None , namespace = None , clustername = None , readfromtail = None , line_limit = None , size_limit = None , type = None , framework = None ):
79
+ """
80
+ show job,deployment,pod log\n
81
+ if jobid is null, it would return deployment or pod logs by <namespace, name, type>
82
+ else it would return PF job logs by jobid
83
+
84
+ When both A and B have values, the minimum value is selected to return to the log
85
+ """
86
+ client = ctx .obj ['client' ]
87
+ output_format = 'text'
88
+ if jobid :
89
+ click .echo ("query job by [jobid]" .format (jobid ))
90
+ elif name :
91
+ click .echo ("query log by [namespace/name]" .format (namespace , name ))
92
+
93
+ valid , response = client .show_log_by_limit (job_id = jobid , name = name , namespace = namespace , cluster_name = clustername , read_from_tail = readfromtail ,
94
+ line_limit = line_limit , size_limit = size_limit , type = type , framework = framework )
95
+ if valid :
96
+ # if jobid is None and len(response['runLog']) > 0:
97
+ # response['runLog'] = [response['runLog'][0]]
98
+ _print_log_by_limit (response , output_format )
99
+ else :
100
+ click .echo ("show logs failed with message[%s]" % response )
101
+ sys .exit (1 )
102
+
103
+
67
104
def _print_run_log (loginfo , out_format ):
68
105
"""print run log """
69
106
submit_loginfo = loginfo ['submitLog' ]
@@ -84,3 +121,35 @@ def _print_run_log(loginfo, out_format):
84
121
if index != len (run_loginfo ) - 1 :
85
122
data .append (['\n ' ])
86
123
print_output (data , [], out_format )
124
+
125
+ def _print_log_by_limit (loginfo , out_format ):
126
+ """print run log by limit """
127
+ eventList = loginfo ['eventList' ]
128
+ logs = loginfo ['logs' ]
129
+
130
+ if eventList is None or len (eventList ) == 0 :
131
+ click .echo (click .style ('eventList is None' , fg = 'green' ))
132
+ else :
133
+ click .echo (click .style ('eventList:' , fg = 'green' ))
134
+ for index , item in enumerate (eventList ):
135
+ click .echo (item )
136
+
137
+ click .echo (click .style ('logs:' , fg = 'green' ))
138
+
139
+ data = []
140
+ if len (logs ) == 0 :
141
+ data .append (["None" ])
142
+ for index , item in enumerate (logs ):
143
+ if item .job_id :
144
+ line = ["jobid:" + item .job_id , "taskid:" + item .task_id , "has_next_page:" + str (item .has_next_page ),
145
+ "truncated:" + str (item .truncated )]
146
+ else :
147
+ line = ["name:" + item .name , "taskid:" + item .task_id , "has_next_page:" + str (item .has_next_page ),
148
+ "line_limit:" + str (item .line_limit ), "size_limit:" + str (item .size_limit ), "truncated:" + str (item .truncated )]
149
+ line_log = []
150
+ line_log .append (item .log_content )
151
+ data .append (line )
152
+ data .append (line_log )
153
+ if index != len (logs ) - 1 :
154
+ data .append (['\n ' ])
155
+ print_output (data , [], out_format )
0 commit comments