def get_request_cmdline(): if len(sys.argv) == 1: print_help() exit() request = QosRequest() if len(sys.argv) >= 2: request.cmd = sys.argv[1] if len(sys.argv) >= 3: request.data = sys.argv[2] if request.cmd == '-schedule': # new spec --> input arg: spec file path # update spec --> input arg: spec file path, or spec id # Finally we need to store spec.to_string() in request.data if os.path.isfile(sys.argv[2]): with open(sys.argv[2], 'r') as f: request.data = f.read() else: spec_id = sys.argv[2] spec = itf_database.get_spec(spec_id) if spec is not None: request.data = spec.to_string() else: print '[QoS Manager] Unrecognized spec ID: ', spec_id request.cmd = '' request.data = '' return request
def check_satisfiability(spec_id, container_id_list): print '[QoS Checker] Check satisfiability of spec ' + spec_id + \ ' on containers ' + str(container_id_list) satisfied = True spec = itf_database.get_spec(spec_id) if len(container_id_list) == 0: # not scheduled return False container_status = [] for container_id in container_id_list: status = itf_database.get_status(container_id) container_status.append(status) # Check disk space satisfied = satisfied and check_space(spec, container_status) if not satisfied: print '[QoS Checker] Disk space not satisfied for spec: ' + spec_id #check latency satisfied = satisfied and check_latency(spec, container_status) if not satisfied: print '[QoS Checker] Latency not satisfied for spec: ' + spec_id #check dataintegrity satisfied = satisfied and check_dataintegrity(spec, container_status) if not satisfied: print '[QoS Checker] Dataintegrity not satisfied for spec: ' + spec_id # Check reliability satisfied = satisfied and check_reliability(spec, container_status) if not satisfied: print '[QoS Checker] Reliability not satisfied for spec: ' + spec_id # Check availability satisfied = satisfied and check_availability(spec, container_status) if not satisfied: print '[QoS Checker] Availability not satisfied for spec: ' + spec_id # Check bandwidth satisfied = satisfied and check_bandwidth(spec, container_status) if not satisfied: print '[QoS Checker] Bandwidth not satisfied for spec: ' + spec_id if satisfied: print '[QoS Checker] Spec ' + spec_id + ' is satisfied on ' + str(container_id_list) return satisfied
def process_request(request): cmd = request.cmd data = request.data print '[QoS Manager] Incoming request: ' + cmd + ' from ' + \ ('cmdline' if request.from_cmdline else 'socket') if data != '': print 'Data:\n--------------------' print data + '\n--------------------' if cmd == '-schedule': spec = itf_spec.QosSpec() err = spec.parse_string(data) if not err: spec_db = itf_database.get_spec(spec.SpecId) if spec_db == None: # spec does not exist print '[QoS Manager] Schedule for new spec {' + spec.SpecId + '}' scheduled_containers, data = qos_scheduler.schedule(spec, task='new') if len(scheduled_containers) > 0: itf_database.add_scheduled_spec(spec, scheduled_containers, init=True) print '[QoS Manager] Successfully scheduled {' + spec.SpecId + '}' else: print '[QoS Manager] Fail to schedule new spec {' \ + spec.SpecId + '} {' + data + '}' exit(-1) else: # reschedule for updated spec print '[QoS Manager] User specification already exists' print '[QoS Manager] Reschedule for spec {' + spec.SpecId + '}' scheduled_containers, data = qos_scheduler.schedule(spec, task='update') if len(scheduled_containers) > 0: itf_database.add_scheduled_spec(spec, scheduled_containers) print '[QoS Manager] Successfully rescheduled {' + spec.SpecId + '}' else: print '[QoS Manager] Fail to reschedule spec {' \ + spec.SpecId + '} {' + data + '}' exit(-1) else: print '[QoS Manager] Error: Invalid QoS spec.' elif cmd == '-rm_spec': spec_id = data print '[QoS Manager] Remove spec {' + spec_id + '} from database' itf_database.remove_spec(spec_id) elif cmd == '-add_container': # data is the path to the container status file print '[QoS Manager] Add a new container with status: ' + data # this request is from system admin when creating new container monitor_container.insert(data) # insert status to db status = itf_database.get_status(data) print '[QoS Manager] Successfully adds new container ' + data elif cmd == '-rm_container': container_id = data print '[QoS Manager] Remove container id: ' + container_id # Set container availability to 0 for triggering reschedule status = itf_database.get_status(container_id) if status is not None: old_avail = status.ContainerAvailability status.ContainerAvailability = -1 itf_database.update_container(status) # Reschedule every related spec - finally no spec will be on container related_specs = itf_database.get_spec_ids_on_container(container_id) for spec_id in related_specs: print '[QoS Manager] Reschedule for spec {' + spec_id + '}' spec = itf_database.get_spec(spec_id) scheduled_containers, data = qos_scheduler.schedule(spec, task='new') if len(scheduled_containers) > 0: itf_database.add_scheduled_spec(spec, scheduled_containers) print '[QoS Manager] Successfully rescheduled {' + spec_id + '}' else: print '[QoS Manager] Fail to reschedule spec {' \ + spec_id + '} {' + data + '}' status.ContainerAvailability = old_avail itf_database.update_container(status) exit(-1) # Delete container in database # NOTE: Must after finishing the file copy succ = itf_database.remove_container(container_id) if succ: print '[QoS Manager] Container', container_id, 'is removed from database' else: print '[QoS Manager] Container', container_id, 'is not in database' elif cmd == '-show_db': print '[QoS Manager] QoS database summary:' itf_database.summary(verbose=False) elif cmd == '-show_db_verbose': print '[QoS Manager] QoS database summary:' itf_database.summary(verbose=True) elif cmd == '-destroy_db': print '[QoS Manager] Clearing all contents in the QoS database?' prompt = raw_input('[y/n]:') if prompt == 'y' or prompt == 'Y': itf_database.init() elif cmd == '-start_server': if request.from_cmdline: qos_server_main() elif cmd == '-stop_server': if request.from_cmdline: # send a stop request to server request = QosRequest() request.cmd = '-stop_server' client_send(request) else: return 1 # use this value for stop the server main loop else: print '[QoS Manager] Unsupported QoS request command: ', cmd return -1 return 0