-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathschema-tes.py
executable file
·137 lines (114 loc) · 3.5 KB
/
schema-tes.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
#!/usr/bin/python3
####################################################################################
#
# Copyright (c) 2018 Thanasis Vergoulis & Konstantinos Zagganas & Loukas Kavouras
# for the Information Management Systems Institute, "Athena" Research Center.
#
# This file is part of SCHeMa.
#
# SCHeMa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SCHeMa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <https://www.gnu.org/licenses/>.
#
####################################################################################
import sys
import tesInputFiler
import tesOutputFiler
import tesConfigFileCreator
import tesCleaner
import tesJobMonitor
import json
import psycopg2 as psg
import os.path
import subprocess
configFileName=os.path.dirname(os.path.abspath(__file__)) + '/configuration.json'
configFile=open(configFileName,'r')
config=json.load(configFile)
configFile.close()
db=config['database']
host=db['host']
dbuser=db['username']
passwd=db['password']
dbname=db['database']
dataFile=sys.argv[1]
folder=sys.argv[2]
jobid=sys.argv[3]
nfsIp=sys.argv[4]
maxCores=sys.argv[5]
maxMem=sys.argv[6]
#
# Auxiliary function to change job status
#
def updateJobStatus(code,jobid,config):
conn=psg.connect(host=host, user=dbuser, password=passwd, dbname=dbname)
cur=conn.cursor()
query="UPDATE run_history SET remote_status_code='" + code + "' WHERE jobid='" + jobid + "'"
cur.execute(query)
conn.commit()
conn.close()
####
# Main code starts here
####
#
# Read the json from the data file
#
f=open(dataFile,'r')
try:
data=json.load(f)
except:
updateJobStatus('-1',config)
exit(1)
f.close()
#
# Available status codes:
# 2: Initializing
# 3: Running
# 4: Complete or Canceled
# -2..-8: System error
# -9: Executor Error
# -10: Canceled
updateJobStatus('2',jobid,config)
returnCode,mounts,referenceMounts=tesInputFiler.getInputs(data,folder,config)
if returnCode!=0:
updateJobStatus('-2','Error',jobid,config)
exit(returnCode)
returnCode,yamlFile,jobName=tesConfigFileCreator.createFile(data,mounts+referenceMounts,folder,jobid,nfsIp,maxCores,maxMem)
if returnCode!=0:
updateJobStatus('-3',jobid,config)
exit(returnCode)
updateJobStatus('3',jobid,config)
returnCode=subprocess.call(['kubectl','apply','-f',yamlFile])
if returnCode!=0:
updateJobStatus('-4',jobid,config)
exit(returnCode)
returnCode=tesJobMonitor.monitorJob(jobName,jobid)
if returnCode!=0:
updateJobStatus('-5',jobid,config)
#
# On error clean job
#
tesCleaner.cleanJob(mounts,folder,jobName)
subprocess.call(['kubectl','delete','-f',yamlFile])
exit(returnCode)
returnCode=tesOutputFiler.uploadOutput(data,config,folder)
if returnCode!=0:
updateJobStatus('-6',jobid,config)
exit(returnCode)
updateJobStatus('4',jobid,config)
returnCode=tesCleaner.cleanJob(mounts,folder,jobName)
if returnCode!=0:
updateJobStatus('-7',jobid,config)
exit(returnCode)
returnCode=subprocess.call(['kubectl','delete','-f',yamlFile])
if returnCode!=0:
updateJobStatus('-8',jobid,config)
exit(returnCode)