Repository: dmwm/wmcore
Issue: RequestTransition records the wrong DN

https://cmsweb.cern.ch/reqmgr2/fetch?rid=prozober_task_EXO-RunIISummer16DR80Premix-07611__v1_T_170220_173516_7037

unless really mistake @prozober has not toggled the status into acquired, running, ...

Changed files:
src/python/WMCore/ReqMgr/CherryPyThreads/StatusChangeTasks.py

diff --git a/src/python/WMCore/ReqMgr/CherryPyThreads/StatusChangeTasks.py b/src/python/WMCore/ReqMgr/CherryPyThreads/StatusChangeTasks.py
index a15c3ee37..3dcf1f281 100644
--- a/src/python/WMCore/ReqMgr/CherryPyThreads/StatusChangeTasks.py
+++ b/src/python/WMCore/ReqMgr/CherryPyThreads/StatusChangeTasks.py
@@ -6,14 +6,14 @@ from __future__ import (division, print_function)
 from WMCore.REST.CherryPyPeriodicTask import CherryPyPeriodicTask
 from WMCore.ReqMgr.DataStructs.RequestStatus import AUTO_TRANSITION
 from WMCore.Services.WorkQueue.WorkQueue import WorkQueue
-from WMCore.Services.RequestDB.RequestDBWriter import RequestDBWriter
+from WMCore.Services.ReqMgr.ReqMgr import ReqMgr
 
 
-def moveForwardStatus(reqDBWriter, wfStatusDict, logger):
+def moveForwardStatus(reqmgrSvc, wfStatusDict, logger):
     
     for status, nextStatus in AUTO_TRANSITION.iteritems():
         count = 0
-        requests = reqDBWriter.getRequestByStatus([status])
+        requests = reqmgrSvc.getRequestByStatus([status], detail=False)
         for wf in requests:
             stateFromGQ = wfStatusDict.get(wf, None)
             if stateFromGQ is None:
@@ -22,7 +22,7 @@ def moveForwardStatus(reqDBWriter, wfStatusDict, logger):
                 continue
             elif stateFromGQ == "failed" and status == "assigned":
                 count += 1
-                reqDBWriter.updateRequestStatus(wf, stateFromGQ)
+                reqmgrSvc.updateRequestStatus(wf, stateFromGQ)
                 logger.debug("%s in %s moved to %s", wf, status, stateFromGQ)
                 continue
 
@@ -34,18 +34,18 @@ def moveForwardStatus(reqDBWriter, wfStatusDict, logger):
             # special case for aborted workflow - aborted-completed instead of completed
             if status == "aborted" and i == 0:
                 count += 1
-                reqDBWriter.updateRequestStatus(wf, "aborted-completed")
+                reqmgrSvc.updateRequestStatus(wf, "aborted-completed")
                 logger.debug("%s in %s moved to %s", wf, status, "aborted-completed")
             else:
                 for j in range(i + 1):
                     count += 1
-                    reqDBWriter.updateRequestStatus(wf, nextStatus[j])
+                    reqmgrSvc.updateRequestStatus(wf, nextStatus[j])
                     logger.debug("%s in %s moved to %s", wf, status, nextStatus[j])
         logger.info("%s requests moved to new state from %s", count, status)
     return
 
 
-def moveToArchivedForNoJobs(reqDBWriter, wfStatusDict, logger):
+def moveToArchivedForNoJobs(reqmgrSvc, wfStatusDict, logger):
     """
     Handle the case when request is aborted/rejected before elements are created in GQ
     """
@@ -55,14 +55,14 @@ def moveToArchivedForNoJobs(reqDBWriter, wfStatusDict, logger):
                         "rejected": ["rejected-archived"]}
 
     for status, nextStatusList in statusTransition.items():
-        requests = reqDBWriter.getRequestByStatus([status])
+        requests = reqmgrSvc.getRequestByStatus([status])
         count = 0
         for wf in requests:
             # check whether wq elements exists for given request
             # if not, it means 
             if wf not in wfStatusDict:
                 for nextStatus in nextStatusList:
-                    reqDBWriter.updateRequestStatus(wf, nextStatus)
+                    reqmgrSvc.updateRequestStatus(wf, nextStatus)
                     count += 1
         # convert to start status for the logging purpose
         initStatus = "aborted" if status == "aborted-completed" else status
@@ -86,14 +86,14 @@ class StatusChangeTasks(CherryPyPeriodicTask):
         gather active data statistics
         """
 
-        reqDBWriter = RequestDBWriter(config.reqmgrdb_url)
+        reqmgrSvc = ReqMgr(config.reqmgr2_url)
         gqService = WorkQueue(config.workqueue_url)
         
         self.logger.info("Getting GQ data for status check")
         wfStatusDict = gqService.getWorkflowStatusFromWQE()
         
         self.logger.info("Advancing status")
-        moveForwardStatus(reqDBWriter, wfStatusDict, self.logger)
-        moveToArchivedForNoJobs(reqDBWriter, wfStatusDict, self.logger)
+        moveForwardStatus(reqmgrSvc, wfStatusDict, self.logger)
+        moveToArchivedForNoJobs(reqmgrSvc, wfStatusDict, self.logger)
 
         return