-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransitionT0Workflows.py
67 lines (50 loc) · 2.27 KB
/
transitionT0Workflows.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Script used to make request status transition for T0 workflows
"""
from __future__ import print_function, division
import logging
import os
import sys
from WMCore.Configuration import loadConfigurationFile
from WMCore.Services.RequestDB.RequestDBWriter import RequestDBWriter
def setupLogger():
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(module)s:%(message)s")
handler.setFormatter(formatter)
root.addHandler(handler)
return root
def main():
wflowName = "Repack_Run341695_StreamPhysics_Tier0_REPLAY_2021_p4v1_v2105180358_210518_0358"
dictMap = {"new": "Closed",
"Closed": "completed",
"completed": "normal-archived"}
if 'WMAGENT_CONFIG' not in os.environ:
os.environ['WMAGENT_CONFIG'] = '/data/tier0/srv/wmagent/current/config/tier0/config.py'
# config = loadConfigurationFile(os.environ["WMAGENT_CONFIG"])
# config.AnalyticsDataCollector.centralRequestDBURL = 'https://cmsweb.cern.ch/couchdb/t0_request'
# config.AnalyticsDataCollector.RequestCouchApp = 'T0Request'
centralRequestDBURL = 'https://cmsweb.cern.ch/couchdb/t0_request'
RequestCouchApp = "T0Request"
logger = setupLogger()
reqmgrDB = RequestDBWriter(centralRequestDBURL, couchapp=RequestCouchApp)
reqDict = reqmgrDB.getRequestByNames(wflowName)
currentStatus = reqDict[wflowName]['RequestStatus']
logger.info("Current status for workflow %s is: %s", wflowName, currentStatus)
if reqDict[wflowName]['RequestStatus'] not in dictMap:
logger.info("Request %s is already in final state: %s", wflowName, currentStatus)
sys.exit(0)
while True:
logger.info("Transitioning request %s from '%s' to '%s'", wflowName, currentStatus, dictMap[currentStatus])
response = reqmgrDB.updateRequestStatus(wflowName, dictMap[currentStatus])
logger.info("response from the server: %s", response)
if dictMap[currentStatus] not in dictMap:
logger.info("There is no further status transition to happen")
break
sys.exit(0)
if __name__ == '__main__':
sys.exit(main())