# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ''' Generates a docker-compose.yaml file from a test-specific template. Each test template either uses the base template directly, or extends the template to customize bits of the cluster. Since the cluster is defined as YAML, the cluster definition is build up internally as a Python data structure made up of maps, arrays and scalars. PyYaml does the grunt work of converting the data structure to the YAML file. ''' import yaml, os, os.path from pathlib import Path # Constants used frequently in the template. DRUID_NETWORK = 'druid-it-net' DRUID_SUBNET = '172.172.172' ZOO_KEEPER = 'zookeeper' METADATA = 'metadata' COORDINATOR = 'coordinator' OVERLORD = 'overlord' ROUTER = 'router' BROKER = 'broker' HISTORICAL = 'historical' INDEXER = 'indexer' MIDDLE_MANAGER = 'middlemanager' def generate(template_path, template): ''' Main routine to generate a docker-compose file from a script with the given template_path, using the template class given. The template path is a convenient way to locate directories in the file system using information that Python itself provides. ''' # Compute the cluster (test category) name from the template path which # we assume to be module//