def TestGetterGood(): print ('Running TestGetterGood...') global bw2 bw2 = BeaconWrapper(beacon, self_port + 1, 'services/' + target, {}) bw2.beacon_setter() bw.beacon_getter() time.sleep(10) assert bw[target] == 'http://127.0.0.1:'+str(self_port+1), 'TestGetterGood failed' print('TestGetterGood passed')
def TestGetterGood(): print('Running TestGetterGood...') global bw2 bw2 = BeaconWrapper(beacon, self_port + 1, 'services/' + target, {}) bw2.beacon_setter() bw.beacon_getter() time.sleep(10) assert bw[target] == 'http://127.0.0.1:' + str(self_port + 1), 'TestGetterGood failed' print('TestGetterGood passed')
def api_404(msg = 'Not found'): return response_builder({'error': msg}, 404) @app.errorhandler(408) def api_408(msg = 'Timed out'): return response_builder({'error': msg}, 408) @app.errorhandler(456) def api_456(msg = 'Unrecoverable error'): return response_builder({'error': msg}, 456) @app.errorhandler(200) def api_200(data = {}): return response_builder(data, 200) ### Other ### if __name__ == '__main__': host = '0.0.0.0' beacon, port = parse_argv(sys.argv, 'data_backend:port[,data_backend:port]') dbcss = sys.argv[3] ss = dbcss.split(',') app.config.update(DATA_BACKENDS = ss) print('Starting with settings: Beacon: {0} self: {1}:{2} data_backends: {3}'.format(beacon, host, port, ss)) bw = BeaconWrapper(beacon, port, 'services/database') bw.beacon_setter() shards = list(map(lambda x: shard_name_fmt.format(x), app.config['DATA_BACKENDS'][:SHARDS_COUNT])) print(app.config['GRID_CALC_ROLE']) platform_dependent_on_run(app.config['GRID_CALC_ROLE']) app.run(host = host, port = port)
return post_item(table, value) ### Error handlers ### @app.errorhandler(500) def api_500(msg = 'Internal error'): return response_builder({'error': msg, 'shard' : SHARD_NUMBER}, 500) @app.errorhandler(400) def api_400(msg = 'Bad request'): return response_builder({'error': msg, 'shard' : SHARD_NUMBER}, 400) @app.errorhandler(404) def api_404(msg = 'Not found'): return response_builder({'error': msg, 'shard' : SHARD_NUMBER}, 404) @app.errorhandler(200) def api_200(data = {}): return response_builder(data, 200) ### Other ### if __name__ == '__main__': bw = BeaconWrapper(beacon, port, 'services/shard') bw.beacon_setter() print(app.config['GRID_CALC_ROLE']) print('#' * 80) print('IMPORTANT: Acting as shard #{0} of {1}'.format(SHARD_NUMBER, SHARDS_COUNT)) print('This means that all autoincrement IDs WILL be changed accordingly.') print('#' * 80) platform_dependent_on_run(app.config['GRID_CALC_ROLE']) app.run(host = host, port = port)
def TestCreation(): print('Running TestCreation...') global bw bw = BeaconWrapper(beacon, self_port, 'services/' + name, targets) assert bw != None, 'TestCreation failed' print('TestCreation passed')