def handle_event_register_prog(event): """ handle 'register_prog' event data must include 'name', 'checksum' and 'data' :event: event to handle :returns: event result data if event sucessfully handled :raises: ValueError: if program data does not match checksum """ data = event.data['data'] name = event.data['name'] checksum = event.data['checksum'] with client.client_access() as c: user_progs_dir = c.user_progs_dir hardware = c.hardware prog_dir = os.path.join(user_progs_dir, checksum) data_file = os.path.join(prog_dir, 'data.json') os.mkdir(prog_dir) with open(data_file, 'w') as fp: fp.write(data) program = user_prog.UserProg( name, checksum, data_file, hardware, build_dir=prog_dir) program.verify_checksum() with client.client_access() as c: cuda_bin = c.args.bin include_path = c.args.include program.build(cuda_bin=cuda_bin, include_path=include_path) with client.client_access() as c: c.user_programs[checksum] = program LOG.info('Registered program: %s', program) return {}
def program_item(prog_hash): """ GET,DELETE /programs/<prog_hash>: query programs :prog_hash: program checksum/identifier :returns: flask response """ if request.method == 'GET': with client.client_access() as c: prog = c.user_programs.get(prog_hash) return respond_json(prog.properties) if prog else respond_error(404) else: raise NotImplementedError
def handle_event_run_iteration(event): """ handle 'run_iteration' event :event: event to handle :returns: event result with encoded aggregation result """ runtime_id = event.data['runtime_id'] prog_checksum = event.data['checksum'] global_state_enc = event.data['global_state_enc'] with client.client_access() as c: program = c.user_programs[prog_checksum] runtime = program.program_runtimes[runtime_id] aggregation_result_enc = runtime.run_iteration(global_state_enc) return {'aggregation_result_enc': aggregation_result_enc}
def programs(): """ GET,POST /programs: register or list programs :returns: flask response """ if request.method == 'POST': event_data = request.get_json() if not all(n in event_data for n in ('name', 'data', 'checksum')): return respond_error(400) return respond_create_event( 'register_prog', event_data, send_remote_event=event_data.get('send_remote_event')) else: with client.client_access() as c: prog_hashes = list(c.user_programs.keys()) return respond_json({'programs': prog_hashes})
def handle_event_delete_runtime(event): """ handle 'delete_runtime' event data must include: - 'runtime_id', - 'checksum', :event: event to handle :returns: event result """ runtime_id = event.data['runtime_id'] prog_checksum = event.data['checksum'] with client.client_access() as c: program = c.user_programs[prog_checksum] runtime = program.program_runtimes.pop(runtime_id) runtime.free_datastructures() return {}
def handle_event_init_runtime(event): """ handle 'init_runtime' event data must include: - 'runtime_id', - 'dataset_enc', - 'checksum', - 'global_params_enc' :event: event to handle :returns: event result """ runtime_id = event.data['runtime_id'] dataset_enc = event.data['dataset_enc'] prog_checksum = event.data['checksum'] global_params_enc = event.data['global_params_enc'] with client.client_access() as c: program = c.user_programs[prog_checksum] runtime = program.get_new_program_runtime(runtime_id) runtime.prepare_datastructures(global_params_enc) runtime.load_data(dataset_enc) LOG.info('Loaded client program instance') return {}
# create client <<<<<<< HEAD client.create_client(args, hardware) ======= client.create_client(args, tmpdir, hardware) >>>>>>> ef9b13b186c1a356f50a36e78ad91a3ccff76392 # automatically find available port client_port = util.get_free_port() # start client api server call = functools.partial( client.APP.run, debug=False, host='0.0.0.0', port=client_port) thread = threading.Thread(target=call) thread.daemon = True thread.start() # register with server with client.client_access() as c: c.register(client_port) # start client worker worker = client_worker.ClientWorker() LOG.info('starting client worker') try: worker.run() except queue.Empty: with client.client_access() as c: c.shutdown() return 0 def run_server(args, tmpdir): """ entrypoint for server
def _put_remove_event(self): """PUT event status in server remote event map""" with client.client_access() as c: endpoint = os.path.join('/remote_event', c.uuid, self.event_id) c.put(endpoint, self.properties, expect_json=False, add_uuid=False)