Пример #1
0
 def run(self):
     while(True):
         if self.__pendingJob:
             self.__working = True
             self.__currentExeId = self.dbutil.getLatestExecutionId(self.__currentFile)
             self.__callTask(self.__currentFile)
             self.dbutil.finishExecution(self.__currentFile, self.__currentExeId, self.__lastStatus, self.__lastErrorMsg)
             self.logger.debug('restTask Worker:finished rest tasks %s', self.__currentFile)
             #Finish Task
             
             tempFile = self.__currentFile
             self.__currentFile = None
             globalProperty.getRestSchTkMgrInstance().finishTaskByPath(tempFile)
         self.logger.debug('restTask Worker: waiting for new task...')            
         
         self.dbutil.updateMachine()#Update machine here once previous task finished
         self.dbutil.updateMachineInfo()#Update machine here once previous task finished
         
         self.__working = False
         self.__currentFile = self.getTaskFile()
         self.__working = True
         self.logger.info('Worker gets new task:' + self.__currentFile)
         
         self.__currentExeId = self.dbutil.startExecution(self.__currentFile)
         self.__callTask(self.__currentFile)
         self.dbutil.finishExecution(self.__currentFile, self.__currentExeId, self.__lastStatus, self.__lastErrorMsg)
         self.logger.info('Worker finishes task:' + str(self.__currentFile))
         
         #Finish Task
         globalProperty.getRestSchTkMgrInstance().finishTaskByPath(self.__currentFile)
         self.__currentFile = None
         self.__currentExeId = None
Пример #2
0
 def run(self):
     globalProperty.restAdminInstance = self
     
     self.__worker = globalProperty.getRestWorkerInstance()
     
     self.__schMgr = globalProperty.getRestSchTkMgrInstance()
     
     #Start Scheduling Job
     self.__startSchedule()
     
     #Start Worker
     self.__startWorker()
     
     self.__machineAnswer = machineAnswer()
     self.__machineAnswer.setDaemon(False)
     self.__machineAnswer.start()
     
     self.__remoteListener = remoteListener()
     self.__remoteListener.setDaemon(False)
     self.__remoteListener.start()
     
     self.__policyServer = policyServer()
     self.__policyServer.setDaemon(False)
     self.__policyServer.start()
     
     self.__loadRestModules()
     
     self.__start_listen()
     
     time.sleep(5)
Пример #3
0
    def __init__(self, type, priority):
        logging.config.fileConfig("log.config")
        self.logger = logging.getLogger()
        self.logger.info("Create a new " + type + " task with priority " + str(priority))
        self.type = type
        self.runFlag = False
        self.finishFlag = False
        self.parameter = {}
        self.priority = priority
        self.note = ""
        self._schTkMgr = globalProperty.getRestSchTkMgrInstance()
        self._commonDomain = globalProperty.getCommonDomain()
        self._commonUser = globalProperty.getCommonUser()
        self._commonPassword = globalProperty.getCommonPassword()
        self._dbutil = globalProperty.getDbUtil()
        self.__toolsDir = os.path.join(os.getcwd(), "tools")

        self.macAddress = globalProperty.getMacAddress()

        # Following 2 initialization occur in restWkr
        self.jobId = None
        self.exeId = None

        if os.name == "posix":
            self.platform = "osx10"
        elif os.name == "nt":
            self.platform = "win32"
Пример #4
0
    def addNewJob(self, task, jobType):
#    task object:
#        dict: {u'sortpattern': u'linear', 'fileName': 'task_375f6b30-5d50-11dd-9e0a-001aa008bf35.tk', u'startTime': u'17:24:59', u'startDate': u'2008-07-29'}
        comment = task['comment']
        fileName = task['fileName']
        jobId = fileName[5:-3]
        userId = str(task['username'])
        jobTitle = str(task['jobTitle'])
        if task['timeout']:
            timeout = int(task['timeout'])
        else:
            timeout = None
        
        #Comment it out because I think it's not necessary to update machine if just adding job not executing job 
        #self.updateMachine(userId)
        
        '''
        r = self.__query("SELECT * FROM machine WHERE address = %s", self.__macAddress)
        if r != None and not len(r):
            _os = 'win' if os.name == 'nt' else 'mac'
            _hostname = socket.gethostname()
            self.__update("INSERT INTO machine (address, user_id, os_type) VALUES(%s, %s, %s)", (self.__macAddress, userId, _os))
        '''
        
        #for repeated jobs, scheduleOneTask would be called after each execution
        #since there's no such logic to determine if it is the first call, we have to check the database
        #FIXME: got to have a better solution 
        ''' by nlei
        r = self.__query("SELECT * FROM job WHERE job_id = %s", jobId)
        '''
        r = self.__qmsWS.getJobContent(jobId);
        if r != None and not len(r):
            f = open(os.path.join(globalProperty.getRestSchTkMgrInstance().getSchedulTaskDir(), fileName))
            content = f.read()
            if timeout:
                self.__qmsWS.addNewJob(jobId, jobTitle, userId, self.__macAddress, content, comment, fileName, jobType, timeout);
                #self.__update("INSERT INTO job (job_id, user_id, received_time, target_machine, content, comment, timeout, file_name, job_type) VALUES (%s, %s, now(), %s, %s, %s, %s, %s, %s)", 
                #          (jobId, userId, self.__macAddress, content, comment, timeout, fileName, jobType))
            else:
                self.__qmsWS.addNewJob(jobId, jobTitle, userId, self.__macAddress, content, comment, fileName, jobType);
                #self.__update("INSERT INTO job (job_id, user_id, received_time, target_machine, content, comment, file_name, job_type) VALUES (%s, %s, now(), %s, %s, %s, %s, %s)", 
                #          (jobId, userId, self.__macAddress, content, comment, fileName, jobType))
    
            f.seek(0)
            doc = minidom.parse(f)
            params = []
            sequence = 0
            for task in doc.getElementsByTagName("Task"):
                type = task.getAttribute('type')
                if not type in self.taskDict.keys(): break
                taskId = self.taskDict[type]
                sequence += 1
                params.append((jobId, taskId, sequence))
                self.__qmsWS.addNewJobDetail(jobId, taskId, sequence);
            #self.__update("INSERT INTO job_detail (job_id, task_id, sequence) VALUES (%s, %s, %s)", params)
            f.close()
Пример #5
0
 def __init__(self, host='', port=21889, bufsiz=1024):
     Thread.__init__(self)
     self.setName("policyAnswer")
     
     self.__worker = globalProperty.getRestWorkerInstance()
     self.__schMgr = globalProperty.getRestSchTkMgrInstance()
     self.__host = host
     self.__port = port
     self.__bufsiz = bufsiz
     self.__tcpSerSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.__tcpSerSock.bind((host, port))
     self.__tcpSerSock.listen(5)
Пример #6
0
 def addTaskFile(self, fileName, jobAttrs):
     taskFilePath = os.path.join(globalProperty.getSchedulTaskDir(), fileName)
     jobId = fileName[5:-3]
     cloudName = None
     deliverToCloud = False
     if not self.isIdle() and 'cloudName' in jobAttrs and 'cloudType' in jobAttrs:
         cloudName = jobAttrs['cloudName']
         cloudType = jobAttrs['cloudType']
         try:
             f = open(taskFilePath, "r")
             jobContent = f.read()
         except:
             self.logger.debug("Deliver job to cloud failed")
         finally:
             if f!=None:
                 f.close()
         if globalProperty.getCloudNodeInstance().deliverJobToCloud(jobId, jobContent, cloudName, cloudType):
             deliverToCloud = True
                 
     if not deliverToCloud:
         self.taskFileQueue.put(fileName)
     else:
         globalProperty.getRestSchTkMgrInstance().stopTask(jobId)