Exemplo n.º 1
0
    def __validateResponse(self, response):
        if not isinstance(response, dict) or 'code' not in response:
            raise errors.InternalError('Invalid reply from the service')

        if response['code'] != 0:
            if 'message' in response:
                raise errors.ConnectionError('Request failed - %s' %
                                             response['message'])

            raise errors.ConnectionError('Request failed')

        if 'data' not in response:
            raise errors.InternalError('Invalid reply from the service')

        return response['data']
Exemplo n.º 2
0
    def list(self):
        data = self.__sendAndValidateResult({"request": "listJobs"})

        if 'jobs' not in data:
            raise errors.InternalError('Rquest failed - missing jobs data')

        return data['jobs']
Exemplo n.º 3
0
    def submit(self, jobs):
        data = self.__sendAndValidateResult({
            "request": "submit",
            "jobs": jobs.jobs()
        })

        if 'submitted' not in data or 'jobs' not in data:
            raise errors.InternalError('Missing response data')

        return data['jobs']
Exemplo n.º 4
0
    def wait4(self, names):
        if isinstance(names, str):
            jNames = [names]
        else:
            jNames = list(names)

        logging.info("waiting for finish of %d jobs" % len(jNames))

        result = {}
        notFinished = jNames
        while len(notFinished) > 0:
            try:
                cStatus = self.status(notFinished)

                notFinished = []
                for jobName, jobData in cStatus['jobs'].items():
                    if 'status' not in jobData['data'] or jobData[
                            'status'] != 0 or 'data' not in jobData:
                        raise errors.InternalError("Missing job's %s data" %
                                                   (jobName))

                    if not self.isStatusFinished(jobData['data']['status']):
                        notFinished.append(jobName)
                    else:
                        result[jobName] = jobData['data']['status']

                if len(notFinished) > 0:
                    logging.info("still %d jobs not finished" %
                                 len(notFinished))
                    time.sleep(self.__pollDelay)

            except Exception as e:
                raise errors.ConnectionError(e.args[0])

        logging.info("all jobs finished")

        return result
Exemplo n.º 5
0
 def cancel(self, names):
     raise errors.InternalError('Request not implemented')