Example #1
0
    def __getRequestString(self, requestName):
        """ Obtain the string for request (including all sub-requests)

    :param self: self reference
    :param str requestName: request name
    """
        self.log.info("__getRequestString: Attempting to get string for %s." % requestName)
        res = self.__locateRequest(requestName)
        if not res["OK"]:
            return res
        subRequestPaths = res["Value"]
        try:
            oRequest = RequestContainer(init=False)
            for subRequestPath in subRequestPaths:
                res = self.__readSubRequestString(subRequestPath)
                if not res["OK"]:
                    return res
                subRequestString = res["Value"]
                tempRequest = RequestContainer(subRequestString)
                oRequest.setRequestAttributes(tempRequest.getRequestAttributes()["Value"])
                oRequest.update(tempRequest)
            requestString = oRequest.toXML()["Value"]
            self.log.info("__getRequestString: Successfully obtained string for %s." % requestName)
            result = S_OK(requestString)
            result["Request"] = oRequest
            return result
        except Exception, error:
            errStr = "__getRequestString: Exception while obtaining request string."
            self.log.exception(errStr, requestName, lException=error)
            return S_ERROR(errStr)
Example #2
0
 def __getRequestString(self, requestName):
     """ Obtain the string for request (including all sub-requests)
 """
     gLogger.info(
         "RequestDBFile.__getRequestString: Attempting to get string for %s."
         % requestName)
     res = self.__locateRequest(requestName)
     if not res['OK']:
         return res
     subRequestPaths = res['Value']
     try:
         oRequest = RequestContainer(init=False)
         for subRequestPath in subRequestPaths:
             res = self.__readSubRequestString(subRequestPath)
             if not res['OK']:
                 return res
             subRequestString = res['Value']
             tempRequest = RequestContainer(subRequestString)  #,init=False)
             oRequest.setRequestAttributes(
                 tempRequest.getRequestAttributes()['Value'])
             oRequest.update(tempRequest)
         requestString = oRequest.toXML()['Value']
         gLogger.info(
             "RequestDBFile.__getRequestString: Successfully obtained string for %s."
             % requestName)
         result = S_OK(requestString)
         result['Request'] = oRequest
         return result
     except Exception, x:
         errStr = "RequestDBFile.__getRequestString: Exception while obtaining request string."
         gLogger.exception(errStr, requestName, lException=x)
         return S_ERROR(errStr)
Example #3
0
 def __getRequestString( self, requestName ):
   """ Obtain the string for request (including all sub-requests)
   """
   gLogger.info( "RequestDBFile.__getRequestString: Attempting to get string for %s." % requestName )
   res = self.__locateRequest( requestName )
   if not res['OK']:
     return res
   subRequestPaths = res['Value']
   try:
     oRequest = RequestContainer( init = False )
     for subRequestPath in subRequestPaths:
       res = self.__readSubRequestString( subRequestPath )
       if not res['OK']:
         return res
       subRequestString = res['Value']
       tempRequest = RequestContainer( subRequestString )#,init=False)
       oRequest.setRequestAttributes( tempRequest.getRequestAttributes()['Value'] )
       oRequest.update( tempRequest )
     requestString = oRequest.toXML()['Value']
     gLogger.info( "RequestDBFile.__getRequestString: Successfully obtained string for %s." % requestName )
     result = S_OK( requestString )
     result['Request'] = oRequest
     return result
   except Exception, x:
     errStr = "RequestDBFile.__getRequestString: Exception while obtaining request string."
     gLogger.exception( errStr, requestName, lException = x )
     return S_ERROR( errStr )
Example #4
0
    def __getRequestString(self, requestName):
        """ Obtain the string for request (including all sub-requests)

    :param self: self reference
    :param str requestName: request name
    """
        self.log.info("__getRequestString: Attempting to get string for %s." %
                      requestName)
        res = self.__locateRequest(requestName)
        if not res['OK']:
            return res
        subRequestPaths = res['Value']
        try:
            oRequest = RequestContainer(init=False)
            for subRequestPath in subRequestPaths:
                res = self.__readSubRequestString(subRequestPath)
                if not res['OK']:
                    return res
                subRequestString = res['Value']
                tempRequest = RequestContainer(subRequestString)
                oRequest.setRequestAttributes(
                    tempRequest.getRequestAttributes()['Value'])
                oRequest.update(tempRequest)
            requestString = oRequest.toXML()['Value']
            self.log.info(
                "__getRequestString: Successfully obtained string for %s." %
                requestName)
            result = S_OK(requestString)
            result['Request'] = oRequest
            return result
        except Exception, error:
            errStr = "__getRequestString: Exception while obtaining request string."
            self.log.exception(errStr, requestName, lException=error)
            return S_ERROR(errStr)
Example #5
0
  def execute_request( self ):
    """ Takes one DISET request and forward it to the destination service
    """
    gMonitor.addMark( "Iteration", 1 )
    if self.RequestDB:
      res = self.RequestDB.getRequest( 'diset' )
    else:
      res = self.RequestDBClient.getRequest( 'diset' )
    if not res['OK']:
      gLogger.error( "DISETForwardingAgent.execute: Failed to get request from database." )
      return S_OK()
    elif not res['Value']:
      gLogger.info( "DISETForwardingAgent.execute: No requests to be executed found." )
      return S_OK()

    gMonitor.addMark( "Attempted", 1 )
    requestString = res['Value']['RequestString']
    requestName = res['Value']['RequestName']
    try:
      jobID = int( res['Value']['JobID'] )
    except:
      jobID = 0
    gLogger.info( "DISETForwardingAgent.execute: Obtained request %s" % requestName )

    if self.RequestDB:
      result = self.RequestDB._getRequestAttribute( 'RequestID', requestName = requestName )
      if not result['OK']:
        return S_OK( 'Can not get the request execution order' )
      requestID = result['Value']
      result = self.RequestDB.getCurrentExecutionOrder( requestID )
    else:
      result = self.RequestDBClient.getCurrentExecutionOrder( requestName )
    if result['OK']:
      currentOrder = result['Value']
    else:
      return S_OK( 'Can not get the request execution order' )

    oRequest = RequestContainer( request = requestString )
    requestAttributes = oRequest.getRequestAttributes()['Value']

    ################################################
    # Find the number of sub-requests from the request
    res = oRequest.getNumSubRequests( 'diset' )
    if not res['OK']:
      errStr = "DISETForwardingAgent.execute: Failed to obtain number of diset subrequests."
      gLogger.error( errStr, res['Message'] )
      return S_OK()

    gLogger.info( "DISETForwardingAgent.execute: Found %s sub requests for job %s" % ( res['Value'], jobID ) )
    ################################################
    # For all the sub-requests in the request
    modified = False
    for ind in range( res['Value'] ):
      subRequestAttributes = oRequest.getSubRequestAttributes( ind, 'diset' )['Value']
      subExecutionOrder = int( subRequestAttributes['ExecutionOrder'] )
      subStatus = subRequestAttributes['Status']
      gLogger.info( "DISETForwardingAgent.execute: Processing sub-request %s with execution order %d" % ( ind, subExecutionOrder ) )
      if subStatus == 'Waiting' and subExecutionOrder <= currentOrder:
        operation = subRequestAttributes['Operation']
        gLogger.info( "DISETForwardingAgent.execute: Attempting to forward %s type." % operation )
        rpcStubString = subRequestAttributes['Arguments']
        rpcStub, length = DEncode.decode( rpcStubString )
        res = executeRPCStub( rpcStub )
        if res['OK']:
          gLogger.info( "DISETForwardingAgent.execute: Successfully forwarded." )
          oRequest.setSubRequestStatus( ind, 'diset', 'Done' )
          gMonitor.addMark( "Successful", 1 )
          modified = True
        elif res['Message'] == 'No Matching Job':
          gLogger.warn( "DISETForwardingAgent.execute: No corresponding job found. Setting to done." )
          oRequest.setSubRequestStatus( ind, 'diset', 'Done' )
        else:
          gLogger.error( "DISETForwardingAgent.execute: Failed to forward request.", res['Message'] )
      else:
        gLogger.info( "DISETForwardingAgent.execute: Sub-request %s is status '%s' and  not to be executed." % ( ind, subRequestAttributes['Status'] ) )

    ################################################
    #  Generate the new request string after operation
    requestString = oRequest.toXML()['Value']
    if self.RequestDB:
      res = self.RequestDB.updateRequest( requestName, requestString )
    else:
      res = self.RequestDBClient.updateRequest( requestName, requestString )
    if res['OK']:
      gLogger.info( "DISETForwardingAgent.execute: Successfully updated request." )
    else:
      gLogger.error( "DISETForwardingAgent.execute: Failed to update request" )

    if modified and jobID:
      result = self.RequestDBClient.finalizeRequest( requestName, jobID )

    return S_OK()
Example #6
0
    def execute_request(self):
        """ Takes one DISET request and forward it to the destination service
    """
        gMonitor.addMark("Iteration", 1)
        if self.RequestDB:
            res = self.RequestDB.getRequest('diset')
        else:
            res = self.RequestDBClient.getRequest('diset', url=self.local)
        if not res['OK']:
            gLogger.error(
                "DISETForwardingAgent.execute: Failed to get request from database.",
                self.local)
            return S_OK()
        elif not res['Value']:
            gLogger.info(
                "DISETForwardingAgent.execute: No requests to be executed found."
            )
            return S_OK()

        gMonitor.addMark("Attempted", 1)
        requestString = res['Value']['RequestString']
        requestName = res['Value']['RequestName']
        try:
            jobID = int(res['Value']['JobID'])
        except:
            jobID = 0
        gLogger.info("DISETForwardingAgent.execute: Obtained request %s" %
                     requestName)

        if self.RequestDB:
            result = self.RequestDB._getRequestAttribute(
                'RequestID', requestName=requestName)
            if not result['OK']:
                return S_OK('Can not get the request execution order')
            requestID = result['Value']
            result = self.RequestDB.getCurrentExecutionOrder(requestID)
        else:
            result = self.RequestDBClient.getCurrentExecutionOrder(
                requestName, self.local)
        if result['OK']:
            currentOrder = result['Value']
        else:
            return S_OK('Can not get the request execution order')

        oRequest = RequestContainer(request=requestString)
        requestAttributes = oRequest.getRequestAttributes()['Value']

        ################################################
        # Find the number of sub-requests from the request
        res = oRequest.getNumSubRequests('diset')
        if not res['OK']:
            errStr = "DISETForwardingAgent.execute: Failed to obtain number of diset subrequests."
            gLogger.error(errStr, res['Message'])
            return S_OK()

        gLogger.info(
            "DISETForwardingAgent.execute: Found %s sub requests for job %s" %
            (res['Value'], jobID))
        ################################################
        # For all the sub-requests in the request
        modified = False
        for ind in range(res['Value']):
            subRequestAttributes = oRequest.getSubRequestAttributes(
                ind, 'diset')['Value']
            subExecutionOrder = int(subRequestAttributes['ExecutionOrder'])
            subStatus = subRequestAttributes['Status']
            gLogger.info(
                "DISETForwardingAgent.execute: Processing sub-request %s with execution order %d"
                % (ind, subExecutionOrder))
            if subStatus == 'Waiting' and subExecutionOrder <= currentOrder:
                operation = subRequestAttributes['Operation']
                gLogger.info(
                    "DISETForwardingAgent.execute: Attempting to forward %s type."
                    % operation)
                rpcStubString = subRequestAttributes['Arguments']
                rpcStub, length = DEncode.decode(rpcStubString)
                res = executeRPCStub(rpcStub)
                if res['OK']:
                    gLogger.info(
                        "DISETForwardingAgent.execute: Successfully forwarded."
                    )
                    oRequest.setSubRequestStatus(ind, 'diset', 'Done')
                    gMonitor.addMark("Successful", 1)
                    modified = True
                elif res['Message'] == 'No Matching Job':
                    gLogger.warn(
                        "DISETForwardingAgent.execute: No corresponding job found. Setting to done."
                    )
                    oRequest.setSubRequestStatus(ind, 'diset', 'Done')
                else:
                    gLogger.error(
                        "DISETForwardingAgent.execute: Failed to forward request.",
                        res['Message'])
            else:
                gLogger.info(
                    "DISETForwardingAgent.execute: Sub-request %s is status '%s' and  not to be executed."
                    % (ind, subRequestAttributes['Status']))

        ################################################
        #  Generate the new request string after operation
        requestString = oRequest.toXML()['Value']
        if self.RequestDB:
            res = self.RequestDB.updateRequest(requestName, requestString)
        else:
            res = self.RequestDBClient.updateRequest(requestName,
                                                     requestString, self.local)
        if res['OK']:
            gLogger.info(
                "DISETForwardingAgent.execute: Successfully updated request.")
        else:
            gLogger.error(
                "DISETForwardingAgent.execute: Failed to update request to",
                self.local)

        if modified and jobID:
            result = self.RequestDBClient.finalizeRequest(
                requestName, jobID, self.local)

        return S_OK()