def __init__(self, preallocator): """ Here we maintain several data structures used to keep track of the jobs present for the autograder. Live jobs contains: - jobs that are yet to be assigned and run - jobs that are currently running Dead jobs contains: - jobs that have been completed, or have been 'deleted' when in the live jobs queue Unassigned jobs: This is a FIFO queue of jobs that are pending assignment. - We enforce the invariant that all jobs in this queue must be present in live jobs queueLock protects all the internal data structure of JobQueue. This is needed since there are multiple worker threads and they might be using the makeUnassigned api. """ self.liveJobs = TangoDictionary("liveJobs") self.deadJobs = TangoDictionary("deadJobs") self.unassignedJobs = TangoQueue("unassignedLiveJobs") self.queueLock = threading.Lock() self.preallocator = preallocator self.log = logging.getLogger("JobQueue") self.nextID = 1
def __init__(self, preallocator): self.liveJobs = TangoDictionary("liveJobs") self.deadJobs = TangoDictionary("deadJobs") self.queueLock = threading.Lock() self.preallocator = preallocator self.log = logging.getLogger("JobQueue") self.nextID = 1
def __init__(self, preallocator): # Create two dictionaries that, for each job currently in the dictionary, also maintains a mapping # from output file to the job. This allows easy, constant-time lookup for job based on output file. self.liveJobs = WrappingDictionary("liveJobsWrapped", TangoDictionary("liveJobs"), lambda j: j.outputFile) self.deadJobs = WrappingDictionary("deadJobsWrapped", TangoDictionary("deadJobs"), lambda j: j.outputFile) self.queueLock = threading.Lock() self.preallocator = preallocator self.log = logging.getLogger("JobQueue") self.nextID = 1 self.max_pool_size = TangoIntValue("max_pool_size", -1) if (hasattr(Config, 'MAX_POOL_SIZE') and Config.MAX_POOL_SIZE >= 0): self.max_pool_size.set(Config.MAX_POOL_SIZE)
def runDictionaryTests(self): test_dict = TangoDictionary("test") self.assertEqual(test_dict.keys(), []) self.assertEqual(test_dict.values(), []) for key in self.test_entries: test_dict.set(key, self.test_entries[key]) for key in self.test_entries: self.assertTrue(key in test_dict) self.assertEqual(test_dict.get(key), self.test_entries[key]) for (key, val) in test_dict.items(): self.assertEqual(self.test_entries.get(key), val) self.assertEqual(test_dict.keys(), [str(key) for key in self.test_entries.keys()]) self.assertEqual(test_dict.values(), list(self.test_entries.values())) self.assertTrue("key_not_present" not in test_dict) self.assertEqual(test_dict.get("key_not_present"), None) test_dict.set("key", "new_value") self.assertEqual(test_dict.get("key"), "new_value") test_dict.delete("key") self.assertTrue("key" not in test_dict)
def __init__(self, vmms): self.machines = TangoDictionary("machines") self.lock = threading.Lock() self.nextID = TangoIntValue("nextID", 1000) self.vmms = vmms self.log = logging.getLogger("Preallocator-" + str(os.getpid())) self.low_water_mark = TangoIntValue("low_water_mark", -1) if (hasattr(Config, 'POOL_SIZE_LOW_WATER_MARK') and Config.POOL_SIZE_LOW_WATER_MARK >= 0): self.low_water_mark.set(Config.POOL_SIZE_LOW_WATER_MARK)
def __init__(self, vmms): self.machines = TangoDictionary("machines") self.lock = threading.Lock() self.nextID = TangoIntValue("nextID", 1000) self.vmms = vmms self.log = logging.getLogger("Preallocator")