#coding=utf-8
import json
import time
import os
import sys
import datetime
import time
from configobj import ConfigObj
config = ConfigObj("./conf.ini",encoding='UTF8')
host=config['host']['host']
port=config['port']['port']
kylin_home=config['path']['kylin_home']
job_time=config['sleep']['job_time']
request_time=config['sleep']['resquest_time']
user=config['user']['user']
passwd=config['password']['pass']
count=config['count']['count']
AT=config['Naenvvar']['AUTO']
enable=config['enable']['enable']
reload(sys)
sys.setdefaultencoding('utf-8')
shellres="curl -u "+ user +":" + passwd + " -X GET http://"+ host +":"+ port + "/kylin/api/jobs" + " >> response.json"
os.popen(shellres)
print ("正在获取失败jobid")
time.sleep(int(request_time))
file_path=kylin_home + "response.json"
f=open(file_path,'r')
text=f.read()
items=[]
data=json.loads(text)
for itema in data:
items.append(itema)
list_err=[]
list=[]
def decide_code():
global list
if ("code" in items and int(data["code"]) == 000):
list = data["data"]["jobs"]
append_error()
elif ("code" in items and int(data["code"]) != 000):
print("返回错误的json,请检查请求RestApi")
else:
list = data
append_error()
def append_error():
for item in list:
# timestamp=item["last_modified"]
# timestamp /=1000.0
# date=time.localtime(timestamp)
# new_date=time.strftime("%Y-%m-%d",date)
# d1=datetime.datetime.strptime(str(new_date),'%Y-%m-%d')
# d2=datetime.datetime.strptime(str(current_time),'%Y-%m-%d')
# delta=d2-d1
# days=delta.days
if(item["job_status"]=="FINISHED" ):
list_err.append(item["uuid"])
def draw():
path = os.getenv(AT)
if(enable=="true"):
for i in range(0,int(count)):
print(list_err)
if (path == "true" ):
for jobid in list_err:
print("=========================开始恢复"+ jobid +"==========================")
draw_shell = "curl -u " + user + ":" + passwd + " -X PUT http://" + host + ":" + port + "/kylin/api/jobs/" + jobid + "/resume"
os.popen(draw_shell)
time.sleep(int(job_time))
print(jobid + "已恢复成功")
print("\n")
else:
print("系统环境变量设置错误,请到/etc/profile文件下设置")
else:
for i in range(0,int(count)):
print(list_err)
for jobid in list_err:
print("=========================开始恢复"+ jobid +"==========================")
draw_shell = "curl -u " + user + ":" + passwd + " -X PUT http://" + host + ":" + port + "/kylin/api/jobs/" + jobid + "/resume"
os.popen(draw_shell)
time.sleep(int(job_time))
print(jobid + "已恢复成功")
print("\n")
def decide_draw():
decide_code()
if(list_err.__len__() == 0 ):
print("没有失败的job")
else:
print("已获取到" + str(list_err.__len__())+ "个失败的jobid")
print("开始恢复失败的job")
draw()
if __name__ == '__main__':
os.remove(file_path)
decide_draw()
os.remove(file_path)
失败job重启
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 配置fastDfs时的坑:CentOs7上重启防火墙报 或者 参考博客: CentOs7与CentOs6的差异问题...
- 查看[root@localhost ~]# cat /etc/sysconfig/network-scripts/...
- 报错信息: rails console terminal报错信息显示: 原因: 跳过一步: 直接做了这步: rai...
- 影片中每一次男主演奏时我的全身细胞都会跟着紧张起来,神经也绷得紧紧的,随着音乐越来越快,节奏越来越强,屏幕外的人也...
- 错误信息 解决办法 在 workflow shell action 中添加以下属性: