def post(self, computerName): computerName = computerName.lower() if computerName.startswith(('1', '2')): return Http403(message="Cannot register a RenderNode without a name", content="Cannot register a RenderNode without a name") dct = self.getBodyAsJSON() if computerName in self.getDispatchTree().renderNodes: if 'commands' in dct: for cmdId in dct['commands']: self.getDispatchTree().renderNodes[computerName].commands[cmdId] = self.getDispatchTree().commands[cmdId] if 'status' in dct: self.getDispatchTree().renderNodes[computerName].status = int(dct['status']) return HttpResponse(304, "RenderNode already registered.") else: for key in ('name', 'port', 'status', 'cores', 'speed', 'ram', 'pools', 'caracteristics'): if not key in dct: return Http400("Missing key %r" % key, content="Missing key %r" % key) port = int(dct['port']) status = int(dct['status']) if status not in (RN_UNKNOWN, RN_PAUSED, RN_IDLE, RN_BOOTING): # FIXME: CONFLICT is not a good value maybe return HttpConflict("Unallowed status for RenderNode registration") cores = int(dct['cores']) speed = float(dct['speed']) ram = int(dct['ram']) pools = dct['pools'] caracteristics = dct['caracteristics'] name, port = computerName.split(":", 1) renderNode = RenderNode(None, computerName, cores, speed, name, port, ram, caracteristics) renderNode.status = status poolList = [] # check the existence of the pools for poolName in pools: try: pool = self.getDispatchTree().pools[poolName] poolList.append(pool) except KeyError: return HttpConflict("Pool %s is not a registered pool", poolName) # add the rendernode to the pools for pool in poolList: pool.addRenderNode(renderNode) # add the rendernode to the list of rendernodes renderNode.pools = poolList self.getDispatchTree().renderNodes[renderNode.name] = renderNode self.writeCallback(json.dumps(renderNode.to_json()))
def initPoolsDataFromBackend(self): ''' Loads pools and workers from appropriate backend. ''' try: if settings.POOLS_BACKEND_TYPE == "file": manager = FilePoolManager() elif settings.POOLS_BACKEND_TYPE == "ws": manager = WebServicePoolManager() elif settings.POOLS_BACKEND_TYPE == "db": return False except Exception: return False computers = manager.listComputers() ### recreate the pools poolsList = manager.listPools() poolsById = {} for poolDesc in poolsList: pool = Pool(id=int(poolDesc.id), name=str(poolDesc.name)) self.dispatchTree.toCreateElements.append(pool) poolsById[pool.id] = pool ### recreate the rendernodes rnById = {} for computerDesc in computers: try: computerDesc.name = socket.getfqdn(computerDesc.name) ip = socket.gethostbyname(computerDesc.name) except socket.gaierror: continue renderNode = RenderNode( computerDesc.id, computerDesc.name + ":" + str(computerDesc.port), computerDesc.cpucount * computerDesc.cpucores, computerDesc.cpufreq, ip, computerDesc.port, computerDesc.ramsize, json.loads(computerDesc.properties)) self.dispatchTree.toCreateElements.append(renderNode) ## add the rendernodes to the pools for pool in computerDesc.pools: poolsById[pool.id].renderNodes.append(renderNode) renderNode.pools.append(poolsById[pool.id]) self.dispatchTree.renderNodes[str(renderNode.name)] = renderNode rnById[renderNode.id] = renderNode # add the pools to the dispatch tree for pool in poolsById.values(): self.dispatchTree.pools[pool.name] = pool if self.cleanDB or not self.enablePuliDB: graphs = FolderNode(1, "graphs", self.dispatchTree.root, "root", 0, 0, 0, FifoStrategy()) self.dispatchTree.toCreateElements.append(graphs) self.dispatchTree.nodes[graphs.id] = graphs ps = PoolShare(1, self.dispatchTree.pools["default"], graphs, PoolShare.UNBOUND) self.dispatchTree.toCreateElements.append(ps) if self.enablePuliDB: # clean the tables pools and rendernodes (overwrite) self.pulidb.dropPoolsAndRnsTables() self.pulidb.createElements(self.dispatchTree.toCreateElements) self.dispatchTree.resetDbElements() return True
def post(self, computerName): """ A worker send a request to get registered on the server. """ if singletonconfig.get('CORE', 'GET_STATS'): singletonstats.theStats.cycleCounts['add_rns'] += 1 computerName = computerName.lower() if computerName.startswith(('1', '2')): return Http403(message="Cannot register a RenderNode without a name", content="Cannot register a RenderNode without a name") dct = self.getBodyAsJSON() if computerName in self.getDispatchTree().renderNodes: # When the registering worker is already listed in RN list logger.warning("RenderNode already registered: %s" % computerName) existingRN = self.getDispatchTree().renderNodes[computerName] if 'commands' not in dct: # No commands in current RN, reset command that might be still assigned to this RN existingRN.reset() else: logger.warning("Reset commands that are assigned to this RN: %r" % dct.get('commands', '-')) for cmdId in dct['commands']: existingRN.commands[cmdId] = self.getDispatchTree().commands[cmdId] if 'status' in dct: existingRN.status = int(dct['status']) return HttpResponse(304, "RenderNode already registered.") else: # Add a new worker (and set infos given in request body) for key in ('name', 'port', 'status', 'cores', 'speed', 'ram', 'pools', 'caracteristics'): if not key in dct: return Http400("Missing key %r" % key, content="Missing key %r" % key) port = int(dct['port']) status = int(dct['status']) if status not in (RN_UNKNOWN, RN_PAUSED, RN_IDLE, RN_BOOTING): # FIXME: CONFLICT is not a good value maybe return HttpConflict("Unallowed status for RenderNode registration") cores = int(dct['cores']) speed = float(dct['speed']) ram = int(dct['ram']) pools = dct['pools'] caracteristics = dct['caracteristics'] name, port = computerName.split(":", 1) puliversion = dct.get('puliversion', "unknown") createDate = dct.get('createDate', time.time()) renderNode = RenderNode(None, computerName, cores, speed, name, port, ram, caracteristics, puliversion=puliversion, createDate=createDate) renderNode.status = status poolList = [] # check the existence of the pools for poolName in pools: try: pool = self.getDispatchTree().pools[poolName] poolList.append(pool) except KeyError: return HttpConflict("Pool %s is not a registered pool", poolName) # add the rendernode to the pools for pool in poolList: pool.addRenderNode(renderNode) # add the rendernode to the list of rendernodes renderNode.pools = poolList self.getDispatchTree().renderNodes[renderNode.name] = renderNode self.writeCallback(json.dumps(renderNode.to_json()))
def post(self, computerName): """ A worker send a request to get registered on the server. """ if singletonconfig.get('CORE', 'GET_STATS'): singletonstats.theStats.cycleCounts['add_rns'] += 1 computerName = computerName.lower() if computerName.startswith(('1', '2')): return Http403( message="Cannot register a RenderNode without a name", content="Cannot register a RenderNode without a name") dct = self.getBodyAsJSON() if computerName in self.getDispatchTree().renderNodes: # When the registering worker is already listed in RN list logger.warning("RenderNode already registered: %s" % computerName) existingRN = self.getDispatchTree().renderNodes[computerName] if 'commands' not in dct: # No commands in current RN, reset command that might be still assigned to this RN existingRN.reset() else: logger.warning( "Reset commands that are assigned to this RN: %r" % dct.get('commands', '-')) for cmdId in dct['commands']: existingRN.commands[cmdId] = self.getDispatchTree( ).commands[cmdId] if 'status' in dct: existingRN.status = int(dct['status']) return HttpResponse(304, "RenderNode already registered.") else: # Add a new worker (and set infos given in request body) for key in ('name', 'port', 'status', 'cores', 'speed', 'ram', 'pools', 'caracteristics'): if not key in dct: return Http400("Missing key %r" % key, content="Missing key %r" % key) port = int(dct['port']) status = int(dct['status']) if status not in (RN_UNKNOWN, RN_PAUSED, RN_IDLE, RN_BOOTING): # FIXME: CONFLICT is not a good value maybe return HttpConflict( "Unallowed status for RenderNode registration") cores = int(dct['cores']) speed = float(dct['speed']) ram = int(dct['ram']) pools = dct['pools'] caracteristics = dct['caracteristics'] name, port = computerName.split(":", 1) puliversion = dct.get('puliversion', "unknown") createDate = dct.get('createDate', time.time()) renderNode = RenderNode(None, computerName, cores, speed, name, port, ram, caracteristics, puliversion=puliversion, createDate=createDate) renderNode.status = status poolList = [] # check the existence of the pools for poolName in pools: try: pool = self.getDispatchTree().pools[poolName] poolList.append(pool) except KeyError: return HttpConflict("Pool %s is not a registered pool", poolName) # add the rendernode to the pools for pool in poolList: pool.addRenderNode(renderNode) # add the rendernode to the list of rendernodes renderNode.pools = poolList self.getDispatchTree().renderNodes[renderNode.name] = renderNode self.writeCallback(json.dumps(renderNode.to_json()))