def __init__(self, hy=None, hy_rid=None, ): if hy_rid: self.hy = {} for hy_label, hy_level_roids in iteritems(hy_rid): self.hy[hy_label] = [ ordered_ids2itvs(ids) for k, ids in iteritems(hy_level_roids)] else: if hy: self.hy = hy else: raise Exception("Hierarchy description must be provided")
def find_treematch(itvs_avail, hy_res_rqts, hy, beginning, matrix_file ): res_set = oar.kao.scheduling.find_resource_hierarchies_job(itvs_avail,hy_res_rqts,hy) if res_set == []: return [] if beginning: here_path = os.path.dirname(os.path.realpath(__file__)) mapping_exe = " {}/../../treematch-0.3.0/src/treematch/mapping".format(here_path) topo_file = " {}/../../treematch-0.3.0/topo.tgt".format(here_path) restriction_file = "{}/../../treematch-0.3.0/tmp/restrictions.bind".format(here_path) #create a temporary restriction file with open(restriction_file, "w") as rf: for (a,b) in itvs_avail: for i in range(a,b+1): rf.write(str(i) + " ") cmd = "{} -t {} -c {} -b {}".format(mapping_exe,topo_file,matrix_file,restriction_file) row_result = os.popen(cmd).read() os.remove(restriction_file) if(row_result == ""): print("find_treematch : invalid arguments") return [] elif (row_result[0:9] != "TreeMatch"): print(row_result) return [] #condition the row result from treematch row_result = (row_result.split(':')[1]).split(',') row_result = [int(val) for val in row_result] return ordered_ids2itvs(row_result) else: return res_set
def __init__(self): # prepare resource order/indirection stuff order_by_clause = config["SCHEDULER_RESOURCE_ORDER"] self.rid_i2o = array("i", [0] * MAX_NB_RESOURCES) self.rid_o2i = array("i", [0] * MAX_NB_RESOURCES) # suspend suspendable_roids = [] if "SCHEDULER_AVAILABLE_SUSPENDED_RESOURCE_TYPE" not in config: config["SCHEDULER_AVAILABLE_SUSPENDED_RESOURCE_TYPE"] = "default" res_suspend_types = ( config["SCHEDULER_AVAILABLE_SUSPENDED_RESOURCE_TYPE"]).split() # prepare hierarchy stuff # "HIERARCHY_LABELS" = "resource_id,network_address" conf_hy_labels = config[ "HIERARCHY_LABELS"] if "HIERARCHY_LABELS" in config else "resource_id,network_address" hy_labels = conf_hy_labels.split(",") hy_labels_w_id = ["id" if v == "resource_id" else v for v in hy_labels] hy_roid = {} for hy_label in hy_labels_w_id: hy_roid[hy_label] = OrderedDict() # available_upto for pseudo job in slot available_upto = {} self.available_upto = {} roids = [] default_rids = [] # retreive resource in order from DB self.resources_db = db.query(Resource).order_by(text(order_by_clause)).all() # fill the different structures for roid, r in enumerate(self.resources_db): if (r.state == "Alive") or (r.state == "Absent"): rid = int(r.id) roids.append(roid) if r.type == 'default': default_rids.append(rid) self.rid_i2o[rid] = roid self.rid_o2i[roid] = rid # fill hy_rid structure for hy_label in hy_labels_w_id: v = getattr(r, hy_label) if v in hy_roid[hy_label]: hy_roid[hy_label][v].append(roid) else: hy_roid[hy_label][v] = [roid] # fill available_upto structure if r.available_upto in available_upto: available_upto[r.available_upto].append(roid) else: available_upto[r.available_upto] = [roid] # fill resource available for suspended job if r.type in res_suspend_types: suspendable_roids.append(roid) # global ordered resources intervals # print roids self.roid_itvs = ordered_ids2itvs(roids) if "id" in hy_roid: hy_roid["resource_id"] = hy_roid["id"] del hy_roid["id"] # create hierarchy self.hierarchy = Hierarchy(hy_rid=hy_roid).hy # transform available_upto for k, v in iteritems(available_upto): self.available_upto[k] = ordered_ids2itvs(v) # self.suspendable_roid_itvs = ordered_ids2itvs(suspendable_roids) default_roids = [self.rid_i2o[i] for i in default_rids] self.default_resource_itvs = unordered_ids2itvs(default_roids) # update global variable default_resource_itvs = self.default_resource_itvs
def test_ordered_ids2itvs(): y = [1, 3, 4, 5, 7, 10, 11, 12, 23] r = [(1, 1), (3, 5), (7, 7), (10, 12), (23, 23)] a = ordered_ids2itvs(y) assert a == r