-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull_time.py
53 lines (42 loc) · 1.22 KB
/
pull_time.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/11 16:36
# @Author : laazy
# @Site :
# @File : pull_time.py
# @Software: PyCharm
import os
class TimePuller:
properties = {}
def __init__(self):
pass
def pull_properties(self, raw_id):
with os.popen("/home/wuchunghsuan/hadoop-2.8.5/bin/yarn application -status " + raw_id, "r") as f:
raw_str = f.read()
self.properties = self.process_properties(raw_str)
if self.properties == {}:
return -1
else:
return 0
@staticmethod
def process_properties(raw_str):
s = raw_str.split("\n\t")
if len(s) < 3:
return {}
ret_pro = {}
for i in s:
i = i.strip()
i = i.split(":")
ret_pro[i[0].strip()] = i[1].strip()
return ret_pro
def get_property(self, name):
return self.properties[name]
def get_start_time(self):
return self.get_property("Start-Time")
def get_finish_time(self):
return self.get_property("Finish-Time")
if __name__ == '__main__':
te = TimePuller()
te.pull_properties("application_1552279621115_0003")
ans = te.properties
print(ans)