Esempio n. 1
0
    def _handleOnlyStateTransition(self, workload, request_args, dn):
        """
        It handles only the state transition.
        Special handling needed if a request is aborted or force completed.
        """
        # if we got here, then the main workflow has been already validated
        # and the status transition is allowed
        req_status = request_args["RequestStatus"]
        cascade = request_args.get("cascade", False)

        if req_status in ["aborted", "force-complete"]:
            # cancel the workflow first
            self.gq_service.cancelWorkflow(workload.name())

        # cascade option is only supported for these 3 statuses. If set, we need to
        # find all the children requests and perform the same status transition
        if req_status in ["rejected", "closed-out", "announced"] and cascade:
            childrenNamesAndStatus = self._retrieveResubmissionChildren(workload.name())
            msg = "Workflow {} has {} ".format(workload.name(), len(childrenNamesAndStatus))
            msg += "children workflows to have a status transition to: {}".format(req_status)
            cherrypy.log(msg)
            for childInfo in childrenNamesAndStatus:
                if check_allowed_transition(childInfo['value'], req_status):
                    cherrypy.log('Updating request status for {} to {}.'.format(childInfo['id'], req_status))
                    self.reqmgr_db_service.updateRequestStatus(childInfo['id'], req_status, dn)
                else:
                    msg = "Status transition from {} to {} ".format(childInfo['value'], req_status)
                    msg += "not allowed for workflow: {}, skipping it!".format(childInfo['id'])
                    cherrypy.log(msg)
        # then update the original/parent workflow status in couchdb
        cherrypy.log('Updating request status for {} to {}.'.format(workload.name(), req_status))
        report = self.reqmgr_db_service.updateRequestStatus(workload.name(), req_status, dn)
        return report
Esempio n. 2
0
 def updateRequestStatus(self, requestName, statusName):
     """ Mock the 'updateRequestStatus' method"""
     currentStatus = self.cacheWflowStatus.get(requestName,
                                               self.currentStatus)
     logging.info("MockReqMgr: updating workflow %s to status: %s",
                  requestName, statusName)
     if check_allowed_transition(currentStatus, statusName):
         self.cacheWflowStatus[requestName] = statusName
         return True
     else:
         raise InvalidStateTransition(requestName, currentStatus,
                                      statusName)
Esempio n. 3
0
def validate_state_transition(reqmgr_db_service, request_name, new_state) :
    """
    validate state transition by getting the current data from
    couchdb
    """
    requests = reqmgr_db_service.getRequestByNames(request_name)
    # generator object can't be subscribed: need to loop.
    # only one row should be returned
    for request in requests.values():
        current_state = request["RequestStatus"]
    if not check_allowed_transition(current_state, new_state):
        raise InvalidStateTransition(current_state, new_state)
    return
Esempio n. 4
0
def validate_state_transition(reqmgr_db_service, request_name, new_state):
    """
    validate state transition by getting the current data from
    couchdb
    """
    requests = reqmgr_db_service.getRequestByNames(request_name)
    # generator object can't be subscribed: need to loop.
    # only one row should be returned
    for request in requests.values():
        current_state = request["RequestStatus"]
    if not check_allowed_transition(current_state, new_state):
        raise InvalidStateTransition(current_state, new_state)
    return
Esempio n. 5
0
 def reportRequestStatus(self, name, status):
     if not check_allowed_transition(self.status[name], status):
         raise RuntimeError("Invalid status move: %s" % status)
     self.status[name] = status
Esempio n. 6
0
 def reportRequestStatus(self, name, status):
     if not check_allowed_transition(self.status[name], status):
         raise RuntimeError("Invalid status move: %s" % status)
     self.status[name] = status