def create_tileserver_from_config(config): """create a tileserve object from yaml configuration""" query_config = config['queries'] queries_config_path = query_config['config'] template_path = query_config['template-path'] reload_templates = query_config['reload-templates'] with open(queries_config_path) as query_cfg_fp: queries_config = yaml.load(query_cfg_fp) all_layer_data, layer_data, post_process_data = parse_layer_data( queries_config, template_path, reload_templates) all_layer_names = [x['name'] for x in all_layer_data] layer_config = LayerConfig(all_layer_names, layer_data) conn_info = config['postgresql'] n_conn = len(layer_data) io_pool = ThreadPool(n_conn) data_fetcher = DataFetcher(conn_info, all_layer_data, io_pool, n_conn) store = None store_config = config.get('store') if store_config: store_type = store_config.get('type') store_name = store_config.get('name') if store_type and store_name: store = make_store(store_type, store_name, store_config) redis_cache_index = None redis_config = config.get('redis') if redis_config: from redis import StrictRedis from tilequeue.cache import RedisCacheIndex redis_host = redis_config.get('host', 'localhost') redis_port = redis_config.get('port', 6379) redis_db = redis_config.get('db', 0) redis_client = StrictRedis(redis_host, redis_port, redis_db) redis_cache_index = RedisCacheIndex(redis_client) health_checker = None health_check_config = config.get('health') if health_check_config: health_check_url = health_check_config['url'] health_checker = HealthChecker(health_check_url, conn_info) tile_server = TileServer(layer_config, data_fetcher, post_process_data, io_pool, store, redis_cache_index, health_checker) return tile_server
def create_tileserver_from_config(config): """create a tileserve object from yaml configuration""" query_config = config['queries'] queries_config_path = query_config['config'] template_path = query_config['template-path'] reload_templates = query_config['reload-templates'] buffer_cfg = config.get('buffer', {}) extensions_config = config.get('formats') extensions = set() if extensions_config: for extension in extensions_config: assert extension in extension_to_format, \ 'Unknown format: %s' % extension extensions.add(extension) else: extensions = set(['json', 'topojson', 'mvt']) with open(queries_config_path) as query_cfg_fp: queries_config = yaml.load(query_cfg_fp) all_layer_data, layer_data, post_process_data = parse_layer_data( queries_config, buffer_cfg, template_path, reload_templates, os.path.dirname(queries_config_path)) all_layer_names = [x['name'] for x in all_layer_data] layer_config = LayerConfig(all_layer_names, layer_data) conn_info = config['postgresql'] n_conn = len(layer_data) io_pool = ThreadPool(n_conn) data_fetcher = DataFetcher( conn_info, all_layer_data, io_pool, n_conn) store = None store_config = config.get('store') if store_config: store_type = store_config.get('type') store_name = store_config.get('name') if store_type and store_name: store = make_store(store_type, store_name, store_config) redis_cache_index = None sqs_queue = None redis_config = config.get('redis') if redis_config: from redis import StrictRedis from tilequeue.cache import RedisCacheIndex redis_host = redis_config.get('host', 'localhost') redis_port = redis_config.get('port', 6379) redis_db = redis_config.get('db', 0) redis_client = StrictRedis(redis_host, redis_port, redis_db) redis_cache_index = RedisCacheIndex(redis_client) queue_config = config.get('queue') if queue_config: queue_type = queue_config.get('type') queue_name = queue_config.get('name') sqs_queue = make_queue(queue_type, queue_name, redis_client) health_checker = None health_check_config = config.get('health') if health_check_config: health_check_url = health_check_config['url'] health_checker = HealthChecker(health_check_url, conn_info) add_cors_headers = config.get('cors', False) tile_server = TileServer( layer_config, extensions, data_fetcher, post_process_data, io_pool, store, redis_cache_index, sqs_queue, buffer_cfg, health_checker, add_cors_headers) return tile_server
def create_tileserver_from_config(config): """create a tileserve object from yaml configuration""" query_config = config['queries'] queries_config_path = query_config['config'] template_path = query_config['template-path'] reload_templates = query_config['reload-templates'] buffer_cfg = config.get('buffer', {}) extensions_config = config.get('formats') extensions = set() formats = [] if extensions_config: for extension in extensions_config: assert extension in extension_to_format, \ 'Unknown format: %s' % extension extensions.add(extension) formats.append(extension_to_format[extension]) else: extensions = set(['json', 'topojson', 'mvt']) formats = [json_format, topojson_format, mvt_format] with open(queries_config_path) as query_cfg_fp: queries_config = yaml.load(query_cfg_fp) all_layer_data, layer_data, post_process_data = parse_layer_data( queries_config, buffer_cfg, os.path.dirname(queries_config_path)) all_layer_names = [x['name'] for x in all_layer_data] layer_config = LayerConfig(all_layer_names, layer_data) conn_info = config['postgresql'] postgres_url = os.environ.get('POSTGRES_URL') if postgres_url: import urlparse parsed = urlparse.urlparse(postgres_url) conn_info['host'] = parsed.hostname conn_info['port'] = parsed.port conn_info['user'] = parsed.username conn_info['password'] = parsed.password conn_info['dbnames'] = [parsed.path[1:]] n_conn = len(layer_data) io_pool = ThreadPool(n_conn) data_fetcher = make_db_data_fetcher(conn_info, template_path, reload_templates, queries_config, io_pool) cache = NullCache() cache_config = config.get('cache') or os.environ.get('CACHE_TYPE') if cache_config: cache_type = os.environ.get('CACHE_TYPE') or cache_config.get('type') if cache_type == 'redis': import redis from tileserver.cache import RedisCache redis_config = cache_config.get('redis', {}) redis_url = os.environ.get('REDIS_URL') if not redis_url: redis_url = redis_config.get('url') redis_client = redis.from_url(redis_url) redis_options = redis_config.get('options') or {} cache = RedisCache(redis_client, **redis_options) elif cache_type == 'file': from tileserver.cache import FileCache file_config = cache_config.get('file', {}) cache = FileCache(file_config.get('prefix')) health_checker = None health_check_config = config.get('health') if health_check_config: health_check_url = health_check_config['url'] health_checker = HealthChecker(health_check_url, conn_info) http_cfg = config.get('http', {}) add_cors_headers = bool(http_cfg.get('cors', False)) max_age = http_cfg.get('max-age') if max_age is not None: max_age = int(max_age) path_tile_size = config.get('path_tile_size') max_interesting_zoom = config.get('max_interesting_zoom') yaml_config = config.get('yaml') assert yaml_config, 'Missing yaml configuration' output_calc_mapping = make_output_calc_mapping(yaml_config) tile_server = TileServer(layer_config, extensions, data_fetcher, post_process_data, io_pool, cache, buffer_cfg, formats, health_checker, add_cors_headers, max_age, path_tile_size, max_interesting_zoom, output_calc_mapping) return tile_server