#!/usr/bin/env python # coding: utf-8 """ """ from __future__ import absolute_import from puliclient.server.server import Server from puliclient.server.queueHandler import QueueHandler from octopus.core import enums qh = QueueHandler(Server("localhost", 8004)) allJobsList, summary = qh.getAllJobs() for job in allJobsList: print "id:%s name:%s user:%s" % (job.id, job.name, job.user) print qh.getAllJobs() print qh.getJobsByStatus([enums.NODE_CANCELED, enums.NODE_RUNNING]) print qh.getJobsById(range(1, 100)) print qh.getJobsByName(['.*test'], False) print qh.getJobsByUser(['jsa'], False)[0] print qh.getJobsByProd(['prod_name'], False) print qh.getJobsByTags({'nbFrames': [10]}, False) print qh.getJobsByTags({'nbFrames': [10], 'prod': ['test']}, False) print qh.getJobsByPool(['renderfarm'], False) print qh.getJobs(idList=[28, 32], nameList=['.*test'], poolList=["default", "renderfarm"], statusList=[enums.NODE_DONE],
class QueueHandler(object): """ """ def __init__(self, server=None): self.__server = Server() if server is None else server def processRequest(self, body=None, url="query/job"): """ :param body: :return: """ result = [] try: response = self.__server.post(url, data=json.dumps(body)) jobs = response.get("items") summary = response.get("summary") for job in jobs: result.append(Job(job)) except (RequestTimeoutError, RequestError) as err: raise err return result, summary def getAllJobs(self, recursive=True): """ Retrieves all jobs on the server :param recursive: :return: a tuple with list of jobs and a summary dict """ body = {"recursive": recursive} return self.processRequest(body) def getJobs( self, idList=None, nameList=None, poolList=None, statusList=None, userList=None, tagsDict=None, ): """ Retrieves job list on server given several filter :param idList: Job id :param nameList: Job name :param poolList: Job pool name :param statusList: Job statuses see octopus.core.enums.nodes.NODE_STATUS :param userList: Job create user :param tagsDict: a dict of tags key and possible values :return: a tuple with list of results and a summary dict :raises InvalidParamError: if filter params are not valid :raises RequestTimeoutError: if the request reaches a timeout :raises RequestError: if the request response code is an error or if any other network error occur """ if idList == []: raise InvalidParamError("Error: empty idList given for request") if nameList == []: raise InvalidParamError("Error: empty nameList given for request") if poolList == []: raise InvalidParamError("Error: empty poolList given for request") if statusList == []: raise InvalidParamError( "Error: empty statusList given for request") if userList == []: raise InvalidParamError("Error: empty userList given for request") if tagsDict == []: raise InvalidParamError("Error: empty tagsDict given for request") body = {} if idList is not None: body['id'] = idList if nameList is not None: body['name'] = nameList if poolList is not None: body['pool'] = poolList if statusList is not None: body['status'] = statusList if userList is not None: body['user'] = userList if tagsDict is not None: body['tags'] = tagsDict return self.processRequest(body) def getJobsById(self, idList, recursive=True): """ Retrieves job list on server given a list of ids. :param idList: job ids :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if idList == []: raise InvalidParamError("Error: empty idList given for request") body = {"id": idList, "recursive": recursive} return self.processRequest(body) def getJobsByName(self, nameList, recursive=True): """ Retrieves job list on server given a list of name regular expresssion. :param nameList: job name expresssions :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if nameList == []: raise InvalidParamError("Error: empty nameList given for request") body = {"name": nameList, "recursive": recursive} return self.processRequest(body) def getJobsByProd(self, prodList, recursive=True): """ Retrieves job list on server given a list of prods. :param prodList: job prod, stored under "prod" key in tags dict :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if prodList == []: raise InvalidParamError("Error: empty prodList given for request") body = {"tags": {"prod": prodList}, "recursive": recursive} return self.processRequest(body) def getJobsByPool(self, poolList, recursive=True): """ Retrieves job list on server given a list of pool names. :param poolList: pool name list :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if poolList == []: raise InvalidParamError("Error: empty poolList given for request") body = {"pool": poolList, "recursive": recursive} return self.processRequest(body) def getJobsByStatus(self, statusList, recursive=True): """ Retrieves job list on server given a list of job statuses. :param statusList: job status (in range [0-6] cf enum NODE_STATUS) :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if statusList == []: raise InvalidParamError("Error: empty nameList given for request") cleanStatus = [] for status in statusList: try: cleanStatus.append(NODE_STATUS[int(status)]) except IndexError as err: logging.error("Status index out of range: %s" % status) raise err except Exception as err: raise err body = {"status": statusList, "recursive": recursive} return self.processRequest(body) def getJobsByTags(self, tagsDict, recursive=True): """ Retrieves job list on server given a list of tags, each tag having one or several possible values. Jobs will be selected if any given tag is found. :param tagsDict: a tags dict, each key being the tag name and each value being one or several possible values :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if tagsDict == {}: raise InvalidParamError("Error: empty tagsDict given for request") body = {"tags": tagsDict, "recursive": recursive} return self.processRequest(body) def getJobsByUser(self, userList, recursive=True): """ Retrieves job list on server given a list of user. :param userList: job users :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if userList == []: raise InvalidParamError("Error: empty userList given for request") body = {"user": userList, "recursive": recursive} return self.processRequest(body)
def __init__(self, server=None): self.__server = Server() if server is None else server
class RenderNodeHandler(object): """ """ def __init__(self, server=None): self.__server = Server() if server is None else server def processRequest(self, body=None, url="query/rendernode"): """ :param body: :return: """ result = [] try: response = self.__server.post(url, data=json.dumps(body)) renderNodes = response.get("items") summary = response.get("summary") for rn in renderNodes: result.append(RenderNode(rn)) except (RequestTimeoutError, RequestError) as err: raise err return result, summary def getAllRenderNodes(self): """ Retrieves all jobs on the server :param: :return: """ body = {} return self.processRequest(body) def getRenderNodesByHost(self, hostnameList): """ Retrieves RNs list on server given a list of hostname regular expresssion. :param hostList: render node hostname expresssions :return: a tuple with list of results and a summary dict """ if hostnameList == [] or hostnameList is None: raise InvalidParamError("Error: empty hostnameList given for request") body = { "host": hostnameList, } return self.processRequest(body) def getRenderNodesById(self, idList): """ Retrieves job list on server given a list of ids. :param idList: rn ids :return: a tuple with list of results and a summary dict """ if idList == [] or idList is None: raise InvalidParamError("Error: empty idList given for request") body = { "id": idList, } return self.processRequest(body) def getRenderNodesByName(self, nameList): """ Retrieves RNs list on server given a list of name regular expresssion. :param nameList: render node name expresssions :return: a tuple with list of results and a summary dict """ if nameList == [] or nameList is None: raise InvalidParamError("Error: empty nameList given for request") body = { "name": nameList, } return self.processRequest(body) def getRenderNodesByPool(self, poolList): """ Retrieves RNs on server given a list of exact pool names. :param poolList: pool names :return: a tuple with list of results and a summary dict """ if poolList == [] or poolList is None: raise InvalidParamError("Error: empty idList given for request") body = { "pool": poolList, } return self.processRequest(body) def getRenderNodesByStatus(self, statusList): """ Retrieves RNs list on server given a list of statuses. :param statusList: job status (in range [0-6] cf enum NODE_STATUS) :return: a tuple with list of results and a summary dict """ if statusList == [] or statusList is None: raise InvalidParamError("Error: empty nameList given for request") cleanStatus = [] for status in statusList: try: cleanStatus.append(RN_STATUS[int(status)]) except IndexError as err: logging.error("Status index out of range: %s" % status) raise err except Exception as err: raise err logging.debug("clean statuses = %s" % cleanStatus) body = { "status": statusList, } return self.processRequest(body) def getRenderNodesByVersion(self, versionList): """ Retrieves RNs list on server given a list of version exact values. :param versionList: render node versions :return: a tuple with list of results and a summary dict """ if versionList == [] or versionList is None: raise InvalidParamError("Error: empty versionList given for request") body = { "version": versionList, } return self.processRequest(body) def getRenderNodes( self, hostList=None, idList=None, nameList=None, poolList=None, statusList=None, versionList=None ): """ Retrieves RNs list on server given several filter :param hostList: RN hostname :param idList: RN id :param nameList: RN name, i.e. "<hostname>:<port>" :param poolList: RN pool name :param statusList: RN statuses see octopus.core.enums.rendernode.RN_STATUS :param versionList: RN puliversion :return: a tuple with list of results and a summary dict :raises InvalidParamError: if filter params are not valid :raises RequestTimeoutError: if the request reaches a timeout :raises RequestError: if the request response code is an error or if any other network error occur """ if hostList == []: raise InvalidParamError("Error: empty hostList given for request") if idList == []: raise InvalidParamError("Error: empty idList given for request") if nameList == []: raise InvalidParamError("Error: empty nameList given for request") if poolList == []: raise InvalidParamError("Error: empty poolList given for request") if statusList == []: raise InvalidParamError("Error: empty statusList given for request") if versionList == []: raise InvalidParamError("Error: empty versionList given for request") body = {} if hostList is not None: body['host'] = hostList if idList is not None: body['id'] = idList if nameList is not None: body['name'] = nameList if poolList is not None: body['pool'] = poolList if statusList is not None: body['status'] = statusList if versionList is not None: body['version'] = versionList return self.processRequest(body)
class RenderNodeHandler(object): """ """ def __init__(self, server=None): self.__server = Server() if server is None else server def processRequest(self, body=None, url="query/rendernode"): """ :param body: :return: """ result = [] try: response = self.__server.post(url, data=json.dumps(body)) renderNodes = response.get("items") summary = response.get("summary") for rn in renderNodes: result.append(RenderNode(rn)) except (RequestTimeoutError, RequestError) as err: raise err return result, summary def getAllRenderNodes(self): """ Retrieves all jobs on the server :param: :return: """ body = {} return self.processRequest(body) def getRenderNodesByHost(self, hostnameList): """ Retrieves RNs list on server given a list of hostname regular expresssion. :param hostList: render node hostname expresssions :return: a tuple with list of results and a summary dict """ if hostnameList == [] or hostnameList is None: raise InvalidParamError( "Error: empty hostnameList given for request") body = { "host": hostnameList, } return self.processRequest(body) def getRenderNodesById(self, idList): """ Retrieves job list on server given a list of ids. :param idList: rn ids :return: a tuple with list of results and a summary dict """ if idList == [] or idList is None: raise InvalidParamError("Error: empty idList given for request") body = { "id": idList, } return self.processRequest(body) def getRenderNodesByName(self, nameList): """ Retrieves RNs list on server given a list of name regular expresssion. :param nameList: render node name expresssions :return: a tuple with list of results and a summary dict """ if nameList == [] or nameList is None: raise InvalidParamError("Error: empty nameList given for request") body = { "name": nameList, } return self.processRequest(body) def getRenderNodesByPool(self, poolList): """ Retrieves RNs on server given a list of exact pool names. :param poolList: pool names :return: a tuple with list of results and a summary dict """ if poolList == [] or poolList is None: raise InvalidParamError("Error: empty idList given for request") body = { "pool": poolList, } return self.processRequest(body) def getRenderNodesByStatus(self, statusList): """ Retrieves RNs list on server given a list of statuses. :param statusList: job status (in range [0-6] cf enum NODE_STATUS) :return: a tuple with list of results and a summary dict """ if statusList == [] or statusList is None: raise InvalidParamError("Error: empty nameList given for request") cleanStatus = [] for status in statusList: try: cleanStatus.append(RN_STATUS[int(status)]) except IndexError as err: logging.error("Status index out of range: %s" % status) raise err except Exception as err: raise err logging.debug("clean statuses = %s" % cleanStatus) body = { "status": statusList, } return self.processRequest(body) def getRenderNodesByVersion(self, versionList): """ Retrieves RNs list on server given a list of version exact values. :param versionList: render node versions :return: a tuple with list of results and a summary dict """ if versionList == [] or versionList is None: raise InvalidParamError( "Error: empty versionList given for request") body = { "version": versionList, } return self.processRequest(body) def getRenderNodes(self, hostList=None, idList=None, nameList=None, poolList=None, statusList=None, versionList=None): """ Retrieves RNs list on server given several filter :param hostList: RN hostname :param idList: RN id :param nameList: RN name, i.e. "<hostname>:<port>" :param poolList: RN pool name :param statusList: RN statuses see octopus.core.enums.rendernode.RN_STATUS :param versionList: RN puliversion :return: a tuple with list of results and a summary dict :raises InvalidParamError: if filter params are not valid :raises RequestTimeoutError: if the request reaches a timeout :raises RequestError: if the request response code is an error or if any other network error occur """ if hostList == []: raise InvalidParamError("Error: empty hostList given for request") if idList == []: raise InvalidParamError("Error: empty idList given for request") if nameList == []: raise InvalidParamError("Error: empty nameList given for request") if poolList == []: raise InvalidParamError("Error: empty poolList given for request") if statusList == []: raise InvalidParamError( "Error: empty statusList given for request") if versionList == []: raise InvalidParamError( "Error: empty versionList given for request") body = {} if hostList is not None: body['host'] = hostList if idList is not None: body['id'] = idList if nameList is not None: body['name'] = nameList if poolList is not None: body['pool'] = poolList if statusList is not None: body['status'] = statusList if versionList is not None: body['version'] = versionList return self.processRequest(body)
if hostList is not None: body['host'] = hostList if idList is not None: body['id'] = idList if nameList is not None: body['name'] = nameList if poolList is not None: body['pool'] = poolList if statusList is not None: body['status'] = statusList if versionList is not None: body['version'] = versionList return self.processRequest(body) if __name__ == '__main__': from octopus.core import enums rnHandler = RenderNodeHandler(Server("localhost", 8004)) print rnHandler.getAllRenderNodes() print rnHandler.getRenderNodesById(range(1, 100)) print rnHandler.getRenderNodesByName(['.*vfxpc*']) print rnHandler.getRenderNodesByStatus([enums.RN_IDLE, enums.RN_WORKING]) print rnHandler.getRenderNodesByHost(['vfxpc64']) print rnHandler.getRenderNodesByVersion(['1.7.12']) print rnHandler.getRenderNodesByPool(None) (results, summary) = rnHandler.getRenderNodes( idList=[4, 5, 6], nameList=["vfxpc.*:8000"], hostList=["vfxpc64"], versionList=["dev"], poolList=["default", "renderfarm"], statusList=[enums.RN_IDLE],
class QueueHandler(object): """ """ def __init__(self, server=None): self.__server = Server() if server is None else server def processRequest(self, body=None, url="query/job"): """ :param body: :return: """ result = [] try: response = self.__server.post(url, data=json.dumps(body)) jobs = response.get("items") summary = response.get("summary") for job in jobs: result.append(Job(job)) except (RequestTimeoutError, RequestError) as err: raise err return result, summary def getAllJobs(self, recursive=True): """ Retrieves all jobs on the server :param recursive: :return: a tuple with list of jobs and a summary dict """ body = { "recursive": recursive } return self.processRequest(body) def getJobs( self, idList=None, nameList=None, poolList=None, statusList=None, userList=None, tagsDict=None, ): """ Retrieves job list on server given several filter :param idList: Job id :param nameList: Job name :param poolList: Job pool name :param statusList: Job statuses see octopus.core.enums.nodes.NODE_STATUS :param userList: Job create user :param tagsDict: a dict of tags key and possible values :return: a tuple with list of results and a summary dict :raises InvalidParamError: if filter params are not valid :raises RequestTimeoutError: if the request reaches a timeout :raises RequestError: if the request response code is an error or if any other network error occur """ if idList == []: raise InvalidParamError("Error: empty idList given for request") if nameList == []: raise InvalidParamError("Error: empty nameList given for request") if poolList == []: raise InvalidParamError("Error: empty poolList given for request") if statusList == []: raise InvalidParamError("Error: empty statusList given for request") if userList == []: raise InvalidParamError("Error: empty userList given for request") if tagsDict == []: raise InvalidParamError("Error: empty tagsDict given for request") body = {} if idList is not None: body['id'] = idList if nameList is not None: body['name'] = nameList if poolList is not None: body['pool'] = poolList if statusList is not None: body['status'] = statusList if userList is not None: body['user'] = userList if tagsDict is not None: body['tags'] = tagsDict return self.processRequest(body) def getJobsById(self, idList, recursive=True): """ Retrieves job list on server given a list of ids. :param idList: job ids :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if idList == []: raise InvalidParamError("Error: empty idList given for request") body = { "id": idList, "recursive": recursive } return self.processRequest(body) def getJobsByName(self, nameList, recursive=True): """ Retrieves job list on server given a list of name regular expresssion. :param nameList: job name expresssions :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if nameList == []: raise InvalidParamError("Error: empty nameList given for request") body = { "name": nameList, "recursive": recursive } return self.processRequest(body) def getJobsByProd(self, prodList, recursive=True): """ Retrieves job list on server given a list of prods. :param prodList: job prod, stored under "prod" key in tags dict :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if prodList == []: raise InvalidParamError("Error: empty prodList given for request") body = { "tags": {"prod": prodList}, "recursive": recursive } return self.processRequest(body) def getJobsByPool(self, poolList, recursive=True): """ Retrieves job list on server given a list of pool names. :param poolList: pool name list :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if poolList == []: raise InvalidParamError("Error: empty poolList given for request") body = { "pool": poolList, "recursive": recursive } return self.processRequest(body) def getJobsByStatus(self, statusList, recursive=True): """ Retrieves job list on server given a list of job statuses. :param statusList: job status (in range [0-6] cf enum NODE_STATUS) :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if statusList == []: raise InvalidParamError("Error: empty nameList given for request") cleanStatus = [] for status in statusList: try: cleanStatus.append(NODE_STATUS[int(status)]) except IndexError as err: logging.error("Status index out of range: %s" % status) raise err except Exception as err: raise err body = { "status": statusList, "recursive": recursive } return self.processRequest(body) def getJobsByTags(self, tagsDict, recursive=True): """ Retrieves job list on server given a list of tags, each tag having one or several possible values. Jobs will be selected if any given tag is found. :param tagsDict: a tags dict, each key being the tag name and each value being one or several possible values :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if tagsDict == {}: raise InvalidParamError("Error: empty tagsDict given for request") body = { "tags": tagsDict, "recursive": recursive } return self.processRequest(body) def getJobsByUser(self, userList, recursive=True): """ Retrieves job list on server given a list of user. :param userList: job users :param recursive: retrieve a whole hierarchy or only single level top job(s) (default=True) :return: a tuple with list of jobs and a summary dict """ if userList == []: raise InvalidParamError("Error: empty userList given for request") body = { "user": userList, "recursive": recursive } return self.processRequest(body)