def getDynamicNodeInfo(): nodeID = request.json["nodeID"] nodeType = nodeID.split(":")[0].split("/")[-1] if nodeType == "machine": try: status = session.query(MachineResource).get(nodeID).status result = {"nodeID":nodeID, "status":status} except AttributeError: app.logger.error("Machine %s not found" %nodeID) result = None elif nodeType == "router": try: status = session.query(RouterResource).get(nodeID).status result = {"nodeID":nodeID, "status":status} except AttributeError: app.logger.error("Router %s not found" %nodeID) result = None elif nodeType == "storage": try: status = session.query(StorageResource).get(nodeID).status result = {"nodeID":nodeID, "status":status} except AttributeError: app.logger.error("Storage %s not found" %nodeID) result = None else: result = None result = json.dumps({"result":result}) return result
def testMachineType(self, data=TEST_DB_DATA["machine"]): machineType = MachineType(data["typeID"], data["numcpu"], data["numcore"], data["frequency"], data["numfpga"], data["memfpga"], data["numgpu"], data["memory"], data["disk"], data["typegpu"], data["typefpga"]) session.add(machineType) session.commit() dbType = session.query(MachineType).get("MACHINE") self.assertEqual(dbType.numcpu,data["numcpu"]) self.assertEqual(dbType.numcore,data["numcore"]) self.assertEqual(dbType.frequency,data["frequency"]) self.assertEqual(dbType.numfpga,data["numfpga"]) self.assertEqual(dbType.memfpga,data["memfpga"]) self.assertEqual(dbType.numgpu,data["numgpu"]) self.assertEqual(dbType.memory,data["memory"]) self.assertEqual(dbType.disk,data["disk"]) self.assertEqual(dbType.typegpu,data["typegpu"]) self.assertEqual(dbType.typefpga,data["typefpga"])
def testStorageType(self, data=TEST_DB_DATA["storage"]): storageType = StorageType(data["typeID"], data["capacity"], data["ranbw"], data["seqbw"]) session.add(storageType) session.commit() dbType = session.query(StorageType).get("STORAGE") self.assertEqual(dbType.capacity, data["capacity"]) self.assertEqual(dbType.ranbw, data["ranbw"]) self.assertEqual(dbType.seqbw, data["seqbw"])
def createReservation(): reservID = str(uuid.uuid4()) machineList = request.json["reservDescriptor"]["machine"] storageList = request.json["reservDescriptor"]["storage"] routerList = request.json["reservDescriptor"]["router"] try: for nodes in machineList: nodeID = json.loads(json.dumps(nodes)).keys()[0] session.query(MachineResource).filter_by(resourceID=nodeID).\ update({"reservID":reservID, "status":"reserved"}) for nodes in storageList: nodeID = json.loads(json.dumps(nodes)).keys()[0] session.query(StorageResource).filter_by(resourceID=nodeID).\ update({"reservID":reservID, "status":"reserved"}) for nodes in routerList: nodeID = json.loads(json.dumps(nodes)).keys()[0] session.query(RouterResource).filter_by(resourceID=nodeID).\ update({"reservID":reservID, "status":"reserved"}) except AttributeError: app.logger.error("Resource not found") reservID = "RESOURCE_NOT_FOUND" result = json.dumps({"result":reservID}) return result
def cancelReservation(): session.query(MachineResource).filter_by(reservID = request.json["reservID"]).\ update({"status":"free","reservID":""}) session.query(StorageResource).filter_by(reservID = request.json["reservID"]).\ update({"status":"free","reservID":""}) session.query(RouterResource).filter_by(reservID = request.json["reservID"]).\ update({"status":"free","reservID":""}) result = json.dumps({"result":True})\ return result
def testRouterType(self, data=TEST_DB_DATA["router"]): routerType = RouterType(data["typeID"], data["inbw"], data["outbw"], data["buffer"], data["capacity"], data["connector"], data["version"]) session.add(routerType) session.commit() dbType = session.query(RouterType).get("ROUTER") self.assertEqual(dbType.inbw, data["inbw"]) self.assertEqual(dbType.outbw, data["outbw"]) self.assertEqual(dbType.buffer, data["buffer"]) self.assertEqual(dbType.capacity, data["capacity"]) self.assertEqual(dbType.connector, data["connector"]) self.assertEqual(dbType.version, data["version"])
def createReservation(): """ Catch exception when input request format is wrong """ try: configID = request.json["configID"] except ValueError: app.logger.error("Input request format is wrong, " "no configID found to create reservation") result = json.dumps({"result": None}) return result """ Access database to get reservation description """ reservInfo = session.query(AppConfigSchedule).get(configID) """ If there is not a reservation available yet """ if not reservInfo: result = json.dumps({"result": None}) return result else: storageInfo = json.loads(reservInfo.storageInfo)["storage"] machineInfo = json.loads(reservInfo.machineInfo)["machine"] networkInfo = "" routerInfo = json.loads(reservInfo.routerInfo)["router"] reservDescriptor = { "reservDescriptor": { "storage": storageInfo, "machine": machineInfo, "network": networkInfo, "router": routerInfo } } """ Connect to the IaaS layer for creating reservation on resources, catch exception when cannot make connection to the IaaS service """ try: result = iaasConn.request(method, "/createReservation", json.dumps(reservDescriptor)) except NotConnected: app.logger.error("Cannot make http request to the IaaS service") result = json.dumps({"result": None}) return result
def getStaticNodeInfo(): nodeID = request.json["nodeID"] nodeType = nodeID.split(":")[0].split("/")[-1] if nodeType == "machine": try: typeID = session.query(MachineResource).get(nodeID).typeID nodeInfo = session.query(MachineType).get(typeID) result = {"nodeID":nodeID, "numcpu":nodeInfo.numcpu, "numcore":nodeInfo.numcore, "frequency":nodeInfo.frequency, "numfpga":nodeInfo.numfpga, "memfpga":nodeInfo.memfpga, "typefpga":nodeInfo.typefpga, "numgpu":nodeInfo.numgpu, "typegpu":nodeInfo.typegpu, "memory":nodeInfo.memory, "disk":nodeInfo.disk} except AttributeError: app.logger.error("Machine %s not found" %nodeID) result = None elif nodeType == "router": try: typeID = session.query(RouterResource).get(nodeID).typeID nodeInfo = session.query(RouterType).get(typeID) result = {"nodeID":nodeID, "inbw":nodeInfo.inbw, "outbw":nodeInfo.outbw, "buffer":nodeInfo.buffer, "capacity":nodeInfo.capacity, "connector":nodeInfo.connector, "version":nodeInfo.version} except AttributeError: app.logger.error("Router %s not found" %nodeID) result = None elif nodeType == "storage": try: typeID = session.query(StorageResource).get(nodeID).typeID nodeInfo = session.query(StorageType).get(typeID) result = {"nodeID":nodeID, "capacity":nodeInfo.capacity, "ranbw":nodeInfo.ranbw, "seqbw":nodeInfo.seqbw} except AttributeError: app.logger.error("Storage %s not found" %nodeID) result = None else: result = None result = json.dumps({"result":result}) return result
def testRouterType(self,data=TEST_DB_DATA["router"]): routerType = RouterType(data["typeID"], data["inbw"], data["outbw"], data["buffer"], data["capacity"], data["connector"], data["version"]) session.add(routerType) session.commit() dbType = session.query(RouterType).get("ROUTER") self.assertEqual(dbType.inbw,data["inbw"]) self.assertEqual(dbType.outbw,data["outbw"]) self.assertEqual(dbType.buffer,data["buffer"]) self.assertEqual(dbType.capacity,data["capacity"]) self.assertEqual(dbType.connector,data["connector"]) self.assertEqual(dbType.version,data["version"])
def testMachineType(self, data=TEST_DB_DATA["machine"]): machineType = MachineType(data["typeID"], data["numcpu"], data["numcore"], data["frequency"], data["numfpga"], data["memfpga"], data["numgpu"], data["memory"], data["disk"], data["typegpu"], data["typefpga"]) session.add(machineType) session.commit() dbType = session.query(MachineType).get("MACHINE") self.assertEqual(dbType.numcpu, data["numcpu"]) self.assertEqual(dbType.numcore, data["numcore"]) self.assertEqual(dbType.frequency, data["frequency"]) self.assertEqual(dbType.numfpga, data["numfpga"]) self.assertEqual(dbType.memfpga, data["memfpga"]) self.assertEqual(dbType.numgpu, data["numgpu"]) self.assertEqual(dbType.memory, data["memory"]) self.assertEqual(dbType.disk, data["disk"]) self.assertEqual(dbType.typegpu, data["typegpu"]) self.assertEqual(dbType.typefpga, data["typefpga"])
def getAvailableNodeList(): nodeDescriptor = request.json["nodeDescriptor"] numNode = request.json["numNode"] nodeType = json.loads(json.dumps(nodeDescriptor)).keys()[0] nodeIDs = [] if nodeType == "machine": try: nodeDescriptor = nodeDescriptor["machine"] listType = [] for instance in session.query(MachineType): satisfy = (instance.numcpu >= nodeDescriptor["numcpu"] and instance.numcore >= nodeDescriptor["numcore"] and instance.frequency >= nodeDescriptor["frequency"] and instance.numfpga >= nodeDescriptor["numfpga"] and instance.memfpga >= nodeDescriptor["memfpga"] and instance.numgpu >= nodeDescriptor["numgpu"] and instance.typegpu == nodeDescriptor["typegpu"] and instance.memory >= nodeDescriptor["memory"] and instance.disk >= nodeDescriptor["disk"] and instance.typefpga == nodeDescriptor["typefpga"]) if satisfy: listType.append(instance.typeID) for i in range(len(listType)): for resource in session.query(MachineResource).\ filter_by(typeID=listType[i]).\ filter_by(status="free"): nodeIDs.append(resource.resourceID) except AttributeError: app.logger.error("Machine type not found") elif nodeType == "router": try: nodeDescriptor = nodeDescriptor["router"] listType = [] for instance in session.query(RouterType): satisfy = (instance.inbw >= nodeDescriptor["inbw"] and instance.outbw >= nodeDescriptor["outbw"] and instance.buffer >= nodeDescriptor["buffer"] and instance.capacity >= nodeDescriptor["capacity"] and instance.connector == nodeDescriptor["connector"] and instance.version == nodeDescriptor["version"]) if satisfy: listType.append(instance.typeID) for i in range(len(listType)): for resource in session.query(RouterResource).\ filter_by(typeID=listType[i]).\ filter_by(status="free"): nodeIDs.append(resource.resourceID) except AttributeError: app.logger.error("Router type not found") elif nodeType == "storage": try: nodeDescriptor = nodeDescriptor["storage"] listType = [] for instance in session.query(StorageType): satisfy = (instance.capacity >= nodeDescriptor["capacity"] and instance.ranbw >= nodeDescriptor["ranbw"] and instance.seqbw >= nodeDescriptor["seqbw"]) if satisfy: listType.append(instance.typeID) for i in range(len(listType)): for resource in session.query(StorageResource).\ filter_by(typeID=listType[i]).\ filter_by(status="free"): nodeIDs.append(resource.resourceID) except AttributeError: app.logger.error("Storage type not found") result = json.dumps({"result":nodeIDs[0:min(numNode,len(nodeIDs))]}) return result