def post(self): # TODO? replace with msgpack args = self.deserialise(request.get_data()) # Unpacking the YAML/ZIP file for key in args: if key not in {'bucket_id', 'key_id', 'secret_key'}: comma_idx = args[key].find(',') args[key] = args[key][comma_idx + 1:] if args[key] in {'True', 'False'}: args[key] = True if args[key] == 'True' else False else: args[key] = base64.decodestring(args[key]) if all( [key not in args for key in ['bucket_id', 'key_id', 'secret_key']]): args['upload'] = False else: args['upload'] = True args['args'] = yaml.load(args['args']) try: init_exp_args = args['args'] if 'targets' in args.keys(): target_zipfile = args['targets'] if args.get('upload', True): bucket_id = args['bucket_id'] key_id = args['key_id'] secret_key = args['secret_key'] init_exp_args['args']['bucket_id'] = bucket_id init_exp_args['args']['key_id'] = key_id init_exp_args['args']['secret_key'] = secret_key targets = target_unpacker.unpack(target_zipfile, key_id, secret_key, bucket_id) else: filenames = target_unpacker.get_filenames_from_zip( target_zipfile) utils.debug_print("This will be bold and yellow!") utils.debug_print(filenames) utils.debug_print("This will be bold and yellow!") if len(filenames) != 1: raise ValueError( 'Specify exactly one file in the ZIP file') filename = filenames[0] extension = filename.split('.')[-1] targets = target_unpacker.unpack_text_file(target_zipfile, kind=extension) init_exp_args['args']['targets'] = {'targetset': targets} if 'keys_for_all_targets' in init_exp_args['args']: pairs = init_exp_args['args']['keys_for_all_targets'] for pair in pairs: map( lambda target: target.update( {pair['key']: pair['value']}), init_exp_args['args']['targets']['targetset']) # Init the experiment: app_id = init_exp_args['app_id'] exp_uid = '%030x' % random.randrange(16**30) r = broker.applyAsync(app_id, exp_uid, 'initExp', json.dumps(init_exp_args)) response_json, didSucceed, message = r if not didSucceed: raise ValueError(message) except: tb = traceback.format_exc() info = sys.exc_info() if hasattr(info[1], 'message') and len(info[1].message) > 0: message = info[1].message if 'time' in message: message += ( "\nNOTE: error has to do with time; try " "restarting docker, more detail at " "https://stackoverflow.com/questions/27674968/amazon-s3-docker-403-forbidden-the-difference-between-the-request-time-and" ) else: message = str(info[1]) + str(info[-1]) message = '\n'.join(tb.split('\n')[-5:]) message = message + '\n\nDetails:\n' + tb return {'success': False, 'message': message, 'exp_uid': None} return { 'success': didSucceed, 'message': message, 'exp_uid': exp_uid, 'app_id': args['args']['app_id'] }
def post(self): utils.debug_print('POSTED!') utils.debug_print('H', request.headers) try: utils.debug_print('L', len(request.get_data())) except Exception as exc: print(exc) print('OH NO an error in assistant_blueprint!', exc, sys.exc_info()) # TODO? replace with msgpack args = self.deserialise(request.get_data()) # Unpacking the YAML/ZIP file for key in args: if key not in {'bucket_id', 'key_id', 'secret_key'}: comma_idx = args[key].find(',') args[key] = args[key][comma_idx + 1:] if args[key] in {'True', 'False'}: args[key] = True if args[key] == 'True' else False else: args[key] = base64.decodestring(args[key]) if all([ key not in args for key in ['bucket_id', 'key_id', 'sercret_key'] ]): args['upload'] = False else: args['upload'] = True utils.debug_print('args.keys() = ', args.keys()) args['args'] = yaml.load(args['args']) try: init_exp_args = args['args'] utils.debug_print("args.keys = ", args['args'].keys()) if 'targets' in args.keys(): target_zipfile = args['targets'] utils.debug_print("args = ", args) if args.get('upload', True): bucket_id = args['bucket_id'] key_id = args['key_id'] secret_key = args['secret_key'] for x_ in ['bucket_id', 'secret_key', 'key_id']: utils.debug_print(x_, args[x_]) # Unpack the targets targets = target_unpacker.unpack(target_zipfile, key_id, secret_key, bucket_id) else: targets = target_unpacker.unpack_csv_file(target_zipfile) init_exp_args['args']['targets'] = {'targetset': targets} # Init the experiment: app_id = init_exp_args['app_id'] exp_uid = '%030x' % random.randrange(16**30) r = broker.applyAsync(app_id, exp_uid, 'initExp', json.dumps(init_exp_args)) response_json, didSucceed, message = r if not didSucceed: raise ValueError(message) except: tb = traceback.format_exc() info = sys.exc_info() if hasattr(info[1], 'message') and len(info[1].message) > 0: message = info[1].message if 'time' in message: message += ( "\nNOTE: error has to do with time; try " "restarting docker, more detail at " "https://stackoverflow.com/questions/27674968/amazon-s3-docker-403-forbidden-the-difference-between-the-request-time-and" ) else: message = str(info[1]) + str(info[-1]) message = '\n'.join(tb.split('\n')[-5:]) message = message + '\n\nDetails:\n' + tb return {'success': False, 'message': message, 'exp_uid': None} return { 'success': didSucceed, 'message': message, 'exp_uid': exp_uid, 'app_id': args['args']['app_id'] }
def post(self): utils.debug_print('POSTED!') utils.debug_print('H',request.headers) try: utils.debug_print('L',len(request.get_data())) except Exception as exc: print(exc) print('OH NO an error in assistant_blueprint!',exc,sys.exc_info()) # TODO? replace with msgpack args = self.deserialise(request.get_data()) # Unpacking the YAML/ZIP file for key in args: if key not in {'bucket_id', 'key_id', 'secret_key'}: comma_idx = args[key].find(',') args[key] = args[key][comma_idx + 1:] if args[key] in {'True', 'False'}: args[key] = True if args[key] == 'True' else False else: args[key] = base64.decodestring(args[key]) if all([key not in args for key in ['bucket_id', 'key_id', 'sercret_key']]): args['upload'] = False else: args['upload'] = True utils.debug_print('args.keys() = ', args.keys()) args['args'] = yaml.load(args['args']) try: init_exp_args = args['args'] utils.debug_print("args.keys = ", args['args'].keys()) if 'targets' in args.keys(): target_zipfile = args['targets'] utils.debug_print("args = ", args) if args.get('upload', True): bucket_id = args['bucket_id'] key_id = args['key_id'] secret_key = args['secret_key'] for x_ in ['bucket_id', 'secret_key', 'key_id']: utils.debug_print(x_, args[x_]) # Unpack the targets targets = target_unpacker.unpack(target_zipfile, key_id, secret_key, bucket_id) else: targets = target_unpacker.unpack_csv_file(target_zipfile) init_exp_args['args']['targets'] = {'targetset': targets} # Init the experiment: app_id = init_exp_args['app_id'] exp_uid = '%030x' % random.randrange(16**30) r = broker.applyAsync(app_id, exp_uid, 'initExp', json.dumps(init_exp_args)) response_json, didSucceed, message = r if not didSucceed: raise ValueError(message) except: tb = traceback.format_exc() info = sys.exc_info() if hasattr(info[1], 'message') and len(info[1].message) > 0: message = info[1].message if 'time' in message: message += ("\nNOTE: error has to do with time; try " "restarting docker, more detail at " "https://stackoverflow.com/questions/27674968/amazon-s3-docker-403-forbidden-the-difference-between-the-request-time-and") else: message = str(info[1]) + str(info[-1]) message = '\n'.join(tb.split('\n')[-5:]) message = message + '\n\nDetails:\n' + tb return {'success': False, 'message': message, 'exp_uid': None} return {'success': didSucceed, 'message': message, 'exp_uid': exp_uid, 'app_id': args['args']['app_id']}