def foreman_waiting(sys_time): # this function selects job_id and container_type of the jobs whose arrival time # is equal to system time con, c = initialiseDB() c.execute("select job_id, container_type from jobs where arrival_time = " + str(sys_time)) waiting = c.fetchall() terminateDB(con) if len(waiting) == 0: return None else: return waiting
def ack_allocation(job_id, server_id, error=False): if not error: query = "update jobs set server_id ='" + str(server_id) + "', status = 'PROCESSING' where job_id = '" + str(job_id) + "'" else: query = "update jobs set server_id ='" + str(server_id) + "', status = 'ERROR' where job_id = '" + str(job_id) + "'" try: con, c = initialiseDB() c.execute(query) con.commit() terminateDB(con) return except Exception as e: logging.error(str(e))
def sys_time_inc(): try: con, c = initialiseDB() c.execute("select min(arrival_time) from jobs where status = 'WAITING'") arrival = c.fetchone() terminateDB(con) except Exception as e: logging.error(str(e)) # if there is a waiting job with minimum arrival time it will return # arrival time of that job, If no record then returns -1 if not arrival[0]: return None else: return arrival[0]
def least_arr_time(): con, c = initialiseDB() c.execute("select * from jobs where status = 'WAITING'") waiting = c.fetchall() if len(waiting) == 0: return None else: c.execute("select min(arrival_time) from jobs where status = 'WAITING'") arrival = c.fetchone() terminateDB(con) if not arrival[0]: return None else: return arrival[0]
def foreman(sys_time): # this function updates the jobs to status DONE whose current status is PROCESSING and # end_time is less than system time con, c = initialiseDB() c.execute("select server_id, container_type from jobs where end_time<= " + str(sys_time) +" and status='PROCESSING'") upcoming = c.fetchall() query = "update jobs set status='PROCESSING' where arrival_time<= "+str(sys_time)+" and status='WAITING'" c.execute(query) con.commit() terminateDB(con) if len(upcoming) == 0: return None else: return upcoming
def showall(): con, c = initialiseDB() c.execute("select * from jobs") data = c.fetchall() print(data) #min__arrival = systimeinc() #print(min__arrival) #result = foreman(90) #print(result) #showall() terminateDB(con) logging.info(data)
def jobGeneration(n): containerTypes = ['A', 'B', 'C', 'D'] con, c = initialiseDB() query = "DELETE FROM jobs WHERE 1 = 1;" c.execute(query) con.commit() terminateDB(con) arrivalTime = 0 for i in range(n): requestType = ''.join( random.choices(containerTypes, [0.6, 0.2, 0.1, 0.1])) requestTime = random.randint(0, 20) + random.randint( 0, 20) + random.randint(0, 20) arrivalTime = random.randint(0, 20) + arrivalTime con, c = initialiseDB() query = "INSERT INTO jobs (job_id, Container_type, status, Duration, Arrival_time) VALUES('" + str( i) + "', '" + str(requestType) + "', 'WAITING', '" + str( requestTime) + "', '" + str(arrivalTime) + "');" c.execute(query) con.commit() terminateDB(con) con, c = initialiseDB() query = "UPDATE jobs SET end_time = (duration + arrival_time) WHERE 1 = 1;" c.execute(query) con.commit() terminateDB(con) print("Job Generation is done.")