Beispiel #1
0
def test__getInputs(mocker, mockReplyInput, manifestOptions, expected):

    mockReply.return_value = mockReplyInput

    module_str = "DIRAC.WorkloadManagementSystem.Client.JobState.JobState.JobDB.getInputData"
    mocker.patch(module_str, side_effect=mockReply)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Client.JobState.JobState.JobDB.__init__",
        side_effect=mockNone)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Client.JobState.JobState.JobLoggingDB.__init__",
        side_effect=mockNone)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Client.JobState.JobState.TaskQueueDB.__init__",
        side_effect=mockNone)

    inputData = InputData()
    js = CachedJobState(1)
    js.setAttribute('JobType', 'User')

    manifest = JobManifest()
    for varName, varValue in manifestOptions.iteritems():
        manifest.setOption(varName, varValue)

    js.setManifest(manifest)
    res = inputData._getInputs(js)
    assert res['OK'] is True
    assert res['Value'] == expected
Beispiel #2
0
 def __loadJobs(cls, eTypes=None):
     log = cls.log
     if cls.__loadTaskId:
         period = cls.srv_getCSOption("LoadJobPeriod", 300)
         ThreadScheduler.gThreadScheduler.setTaskPeriod(
             cls.__loadTaskId, period)
     if not eTypes:
         eConn = cls.getExecutorsConnected()
         eTypes = [eType for eType in eConn if eConn[eType] > 0]
     if not eTypes:
         log.info("No optimizer connected. Skipping load")
         return S_OK()
     log.info("Getting jobs for %s" % ",".join(eTypes))
     checkingMinors = [
         eType.split("/")[1] for eType in eTypes
         if eType != "WorkloadManagement/JobPath"
     ]
     for opState in cls.__optimizationStates:
         #For Received states
         if opState == "Received":
             if 'WorkloadManagement/JobPath' not in eTypes:
                 continue
             jobCond = {'Status': opState}
         #For checking states
         if opState == "Checking":
             if not checkingMinors:
                 continue
             jobCond = {'Status': opState, 'MinorStatus': checkingMinors}
         #Do the magic
         jobTypeCondition = cls.srv_getCSOption("JobTypeRestriction", [])
         if jobTypeCondition:
             jobCond['JobType'] = jobTypeCondition
         result = cls.__jobDB.selectJobs(jobCond,
                                         limit=cls.srv_getCSOption(
                                             "JobQueryLimit", 10000))
         if not result['OK']:
             return result
         jidList = result['Value']
         knownJids = cls.getTaskIds()
         added = 0
         for jid in jidList:
             jid = long(jid)
             if jid not in knownJids:
                 #Same as before. Check that the state is ok.
                 cls.executeTask(jid, CachedJobState(jid))
                 added += 1
         log.info("Added %s/%s jobs for %s state" %
                  (added, len(jidList), opState))
     return S_OK()
 def msg_OptimizeJobs( self, msgObj ):
   jids = msgObj.jids
   for jid in jids:
     try:
       jid = int( jid )
     except ValueError:
       self.log.error( "Job ID %s has to be an integer" % jid )
       continue
     #Forget and add task to ensure state is reset
     self.forgetTask( jid )
     result = self.executeTask( jid, CachedJobState( jid ) )
     if not result[ 'OK' ]:
       self.log.error( "Could not add job %s to optimization: %s" % ( jid, result[ 'Value' ] ) )
     else:
       self.log.info( "Received new job %s" % jid )
   return S_OK()
Beispiel #4
0
def test__getInputSandbox(mocker, manifestOptions, expected):

    mocker.patch("DIRAC.WorkloadManagementSystem.Client.JobState.JobState.JobDB.__init__", side_effect=mockNone)
    mocker.patch("DIRAC.WorkloadManagementSystem.Client.JobState.JobState.JobLoggingDB.__init__", side_effect=mockNone)
    mocker.patch("DIRAC.WorkloadManagementSystem.Client.JobState.JobState.TaskQueueDB.__init__", side_effect=mockNone)

    inputData = InputData()
    js = CachedJobState(1)
    js.setAttribute("JobType", "User")

    manifest = JobManifest()
    for varName, varValue in manifestOptions.items():
        manifest.setOption(varName, varValue)

    js.setManifest(manifest)
    res = inputData._getInputSandbox(js)
    assert res["OK"] is True
    assert res["Value"] == expected
Beispiel #5
0
 def deserializeTask(self, taskStub):
   return CachedJobState.deserialize(taskStub)
 def exec_deserializeTask( cls, taskStub ):
   return CachedJobState.deserialize( taskStub )
Beispiel #7
0
 def deserializeTask(self, taskStub):
   return CachedJobState.deserialize(taskStub)