def load(self, manager): config = manager.config tracefile = config.get("tracefile") injectfile = config.get("injectionfile") annotationfile = config.get("annotationfile") # Read trace file # Requests is a list of lease requests self.logger.info("Loading tracefile %s" % tracefile) self.requests = None lease_workload = LeaseWorkload.from_xml_file(tracefile, self.starttime) self.requests = lease_workload.get_leases() if injectfile != None: self.logger.info("Loading injection file %s" % injectfile) inj_lease_workload = LeaseWorkload.from_xml_file(injectfile, self.starttime) inj_leases = inj_lease_workload.get_leases() for l in inj_leases: l.id += 1000000 self.requests += inj_leases self.requests.sort(key=operator.attrgetter("submit_time")) if annotationfile != None: self.logger.info("Loading annotation file %s" % annotationfile) annotations = LeaseAnnotations.from_xml_file(annotationfile) annotations.apply_to_leases(self.requests) # Add runtime overhead, if necessary add_overhead = config.get("add-overhead") if add_overhead != constants.RUNTIMEOVERHEAD_NONE: slowdown_overhead = config.get("runtime-slowdown-overhead") boot_overhead = config.get("bootshutdown-overhead") for r in self.requests: if add_overhead == constants.RUNTIMEOVERHEAD_ALL or (add_overhead == constants.RUNTIMEOVERHEAD_BE and r.get_type() == Lease.BEST_EFFORT): if slowdown_overhead != 0: r.add_runtime_overhead(slowdown_overhead) r.add_boot_overhead(boot_overhead) # Override requested memory, if necessary memory = config.get("override-memory") if memory != constants.NO_MEMORY_OVERRIDE: for r in self.requests: for n in r.requested_resources: r.requested_resources[n].set_quantity(constants.RES_MEM, memory) types = {} for r in self.requests: types[r.get_type()] = types.setdefault(r.get_type(), 0) + 1 types_str = " + ".join(["%i %s" % (types[t],Lease.type_str[t]) for t in types]) self.logger.info("Loaded workload with %i requests (%s)" % (len(self.requests), types_str))
def __init__(self, lwffile, utilization_length, annotationfile, verbose = False): # Arbitrary start time self.starttime = DateTime(2006,11,25,13) self.workload = LeaseWorkload.from_xml_file(lwffile, self.starttime) self.site = Site.from_lwf_file(lwffile) if utilization_length == None: self.utilization_length = self.workload.get_leases()[-1].submit_time - self.starttime else: self.utilization_length = utilization_length if annotationfile != None: annotations = LeaseAnnotations.from_xml_file(annotationfile) annotations.apply_to_leases(self.workload.get_leases()) self.verbose = verbose
def generate(self): if self.lwffile == None: annotations = [] for i in xrange(1, self.nleases + 1): annotation = self.__gen_annotation() annotations.append(annotation) else: annotations = {} lease_workload = LeaseWorkload.from_xml_file(self.lwffile) leases = lease_workload.get_leases() for lease in leases: annotation = self.__gen_annotation(lease) annotations[lease.id] = annotation attributes = self._get_attributes() annotations = LeaseAnnotations(annotations, attributes) tree = ET.ElementTree(annotations.to_xml()) outfile = open(self.outfile, "w") tree.write(outfile) outfile.close()
def test_annotation1(): reset_lease_id_counter() lease_workload = LeaseWorkload.from_xml_file("preemption.lwf") annotations = LeaseAnnotations.from_xml_file("annotations1.lwfa") leases = lease_workload.get_leases() annotations.apply_to_leases(leases) lease1 = leases[0] lease2 = leases[1] assert lease1.start.requested == DateTime(0, 1, 1, 10) assert lease1.deadline == DateTime(0, 1, 1, 20) assert isinstance(lease1.software, UnmanagedSoftwareEnvironment) assert lease1.extras["one"] == "1" assert lease1.extras["two"] == "2" assert lease2.start.requested == Timestamp.UNSPECIFIED assert lease2.deadline == None assert isinstance(lease2.software, DiskImageSoftwareEnvironment) assert lease2.software.image_id == "annotation.img" assert lease2.software.image_size == 4096 assert lease2.extras["three"] == "3" assert lease2.extras["four"] == "4"
def load(self, manager): config = manager.config tracefile = config.get("tracefile") injectfile = config.get("injectionfile") imagefile = config.get("imagefile") # Read trace file # Requests is a list of lease requests self.logger.info("Loading tracefile %s" % tracefile) self.requests = None if tracefile.endswith(".swf"): self.requests = LeaseWorkload.from_swf_file(tracefile, self.starttime) elif tracefile.endswith(".lwf") or tracefile.endswith(".xml"): lease_workload = LeaseWorkload.from_xml_file(tracefile, self.starttime) self.requests = lease_workload.get_leases() if injectfile != None: self.logger.info("Loading injection file %s" % injectfile) inj_lease_workload = LeaseWorkload.from_xml_file(injectfile, self.starttime) inj_leases = inj_lease_workload.get_leases() self.requests += inj_leases self.requests.sort(key=operator.attrgetter("submit_time")) if imagefile != None: self.logger.info("Loading image file %s" % imagefile) file = open (imagefile, "r") imagesizes = {} images = [] state = 0 # 0 -> Reading image sizes 1 -> Reading image sequence for line in file: if line[0]=='#': state = 1 elif state == 0: image, size = line.split() imagesizes[image] = int(size) elif state == 1: images.append(line.strip()) for lease, image_id in zip(self.requests, images): lease.software = DiskImageSoftwareEnvironment(image_id, imagesizes[image_id]) # Add runtime overhead, if necessary add_overhead = config.get("add-overhead") if add_overhead != constants.RUNTIMEOVERHEAD_NONE: slowdown_overhead = config.get("runtime-slowdown-overhead") boot_overhead = config.get("bootshutdown-overhead") for r in self.requests: if add_overhead == constants.RUNTIMEOVERHEAD_ALL or (add_overhead == constants.RUNTIMEOVERHEAD_BE and r.get_type() == Lease.BEST_EFFORT): if slowdown_overhead != 0: r.add_runtime_overhead(slowdown_overhead) r.add_boot_overhead(boot_overhead) # Override requested memory, if necessary memory = config.get("override-memory") if memory != constants.NO_MEMORY_OVERRIDE: for r in self.requests: r.requested_resources.set_by_type(constants.RES_MEM, memory) types = {} for r in self.requests: types[r.get_type()] = types.setdefault(r.get_type(), 0) + 1 types_str = " + ".join(["%i %s" % (types[t],Lease.type_str[t]) for t in types]) self.logger.info("Loaded workload with %i requests (%s)" % (len(self.requests), types_str))
def load(self, manager): config = manager.config tracefile = os.path.expanduser(config.get("tracefile")) injectfile = config.get("injectionfile") imagefile = config.get("imagefile") # Read trace file # Requests is a list of lease requests self.logger.info("Loading tracefile %s" % tracefile) self.requests = None if tracefile.endswith(".swf"): self.requests = LeaseWorkload.from_swf_file(tracefile, self.starttime) elif tracefile.endswith(".lwf") or tracefile.endswith(".xml"): lease_workload = LeaseWorkload.from_xml_file(tracefile, self.starttime) self.requests = lease_workload.get_leases() if injectfile != None: self.logger.info("Loading injection file %s" % injectfile) inj_lease_workload = LeaseWorkload.from_xml_file(injectfile, self.starttime) inj_leases = inj_lease_workload.get_leases() self.requests += inj_leases self.requests.sort(key=operator.attrgetter("submit_time")) if imagefile != None: self.logger.info("Loading image file %s" % imagefile) file = open (imagefile, "r") imagesizes = {} images = [] state = 0 # 0 -> Reading image sizes 1 -> Reading image sequence for line in file: if line[0]=='#': state = 1 elif state == 0: image, size = line.split() imagesizes[image] = int(size) elif state == 1: images.append(line.strip()) for lease, image_id in zip(self.requests, images): lease.software = DiskImageSoftwareEnvironment(image_id, imagesizes[image_id]) # Add runtime overhead, if necessary add_overhead = config.get("add-overhead") if add_overhead != constants.RUNTIMEOVERHEAD_NONE: slowdown_overhead = config.get("runtime-slowdown-overhead") boot_overhead = config.get("bootshutdown-overhead") for r in self.requests: if add_overhead == constants.RUNTIMEOVERHEAD_ALL or (add_overhead == constants.RUNTIMEOVERHEAD_BE and r.get_type() == Lease.BEST_EFFORT): if slowdown_overhead != 0: r.add_runtime_overhead(slowdown_overhead) r.add_boot_overhead(boot_overhead) # Override requested memory, if necessary memory = config.get("override-memory") if memory != constants.NO_MEMORY_OVERRIDE: for r in self.requests: r.requested_resources.set_by_type(constants.RES_MEM, memory) types = {} for r in self.requests: types[r.get_type()] = types.setdefault(r.get_type(), 0) + 1 types_str = " + ".join(["%i %s" % (types[t],Lease.type_str[t]) for t in types]) self.logger.info("Loaded workload with %i requests (%s)" % (len(self.requests), types_str))