Ejemplo n.º 1
0
class ForwardDISET(OperationHandlerBase):
    """
  .. class:: ForwardDISET

  functor forwarding DISET operations
  """
    def __init__(self, operation=None, csPath=None):
        """ c'tor

    :param Operation operation: an Operation instance
    :param str csPath: CS path for this handler
    """
        # # call base class c'tor
        OperationHandlerBase.__init__(self, operation, csPath)

    def __call__(self):
        """ execute RPC stub """
        # # decode arguments
        try:
            decode, length = DEncode.decode(self.operation.Arguments)
            self.log.debug("decoded len=%s val=%s" % (length, decode))
        except ValueError, error:
            self.log.exception(error)
            self.operation.Error = str(error)
            self.operation.Status = "Failed"
            return S_ERROR(str(error))
        forward = executeRPCStub(decode)
        if not forward["OK"]:
            self.log.error("unable to execute '%s' operation: %s" %
                           (self.operation.Type, forward["Message"]))
            self.operation.Error = forward["Message"]
            return forward
        self.log.info("DISET forwarding done")
        self.operation.Status = "Done"
        return S_OK()
Ejemplo n.º 2
0
    def __call__(self):
        """ execute RPC stub """
        # # decode arguments
        try:
            decode, length = DEncode.decode(self.operation.Arguments)
            self.log.debug("decoded len=%s val=%s" % (length, decode))
        except ValueError as error:
            self.log.exception(error)
            self.operation.Error = str(error)
            self.operation.Status = "Failed"
            return S_ERROR(str(error))

        # Ensure the forwarded request is done on behalf of the request owner
        decode[0][1]['delegatedDN'] = self.request.OwnerDN
        decode[0][1]['delegatedGroup'] = self.request.OwnerGroup

        # ForwardDiset is supposed to be used with a host certificate
        useServerCertificate = gConfig.useServerCertificate()
        gConfigurationData.setOptionInCFG(
            '/DIRAC/Security/UseServerCertificate', 'true')
        forward = executeRPCStub(decode)
        if not useServerCertificate:
            gConfigurationData.setOptionInCFG(
                '/DIRAC/Security/UseServerCertificate', 'false')

        if not forward["OK"]:
            self.log.error(
                "unable to execute operation",
                "'%s' : %s" % (self.operation.Type, forward["Message"]))
            self.operation.Error = forward["Message"]
            return forward
        self.log.info("DISET forwarding done")
        self.operation.Status = "Done"
        return S_OK()
Ejemplo n.º 3
0
class ForwardDISET(OperationHandlerBase):
    """
  .. class:: ForwardDISET

  functor forwarding DISET operations
  """
    def __init__(self, operation=None, csPath=None):
        """ c'tor

    :param Operation operation: an Operation instance
    :param str csPath: CS path for this handler
    """
        # # call base class c'tor
        OperationHandlerBase.__init__(self, operation, csPath)

    def __call__(self):
        """ execute RPC stub """
        # # decode arguments
        try:
            decode, length = DEncode.decode(self.operation.Arguments)
            self.log.debug("decoded len=%s val=%s" % (length, decode))
        except ValueError, error:
            self.log.exception(error)
            self.operation.Error = str(error)
            self.operation.Status = "Failed"
            return S_ERROR(str(error))

        # ForwardDiset is supposed to be used with a host certificate
        useServerCertificate = gConfig.useServerCertificate()
        gConfigurationData.setOptionInCFG(
            '/DIRAC/Security/UseServerCertificate', 'true')
        forward = executeRPCStub(decode)
        if not useServerCertificate:
            gConfigurationData.setOptionInCFG(
                '/DIRAC/Security/UseServerCertificate', 'false')

        if not forward["OK"]:
            self.log.error(
                "unable to execute operation",
                "'%s' : %s" % (self.operation.Type, forward["Message"]))
            self.operation.Error = forward["Message"]
            return forward
        self.log.info("DISET forwarding done")
        self.operation.Status = "Done"
        return S_OK()
Ejemplo n.º 4
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()
Ejemplo n.º 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', 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()