|
| 1 | +# |
| 2 | +# config.py - Global configuration constants and runtime info |
| 3 | +# |
| 4 | + |
| 5 | +import logging |
| 6 | +import time |
| 7 | + |
| 8 | +# Config - defines |
| 9 | +import os |
| 10 | + |
| 11 | + |
| 12 | +class Config(object): |
| 13 | + ##### |
| 14 | + # Part 1: Tango constants for developers |
| 15 | + # |
| 16 | + # These allow developers to run test versions of Tango on the same |
| 17 | + # server as the production Tango |
| 18 | + |
| 19 | + # Unique prefix that defines VM name space for this Tango |
| 20 | + # version. When working in development, this prefix should be your |
| 21 | + # unique identifier. The "prod" prefix is reserved for production |
| 22 | + DEFAULT_PREFIX = "local" |
| 23 | + PREFIX = os.getenv("DOCKER_DEPLOYMENT", DEFAULT_PREFIX).lower() |
| 24 | + |
| 25 | + # Default port for the RESTful server to listen on. |
| 26 | + PORT = 3000 |
| 27 | + |
| 28 | + # Log file. Setting this to None sends the server output to stdout |
| 29 | + LOGFILE = None |
| 30 | + |
| 31 | + # Logging level |
| 32 | + LOGLEVEL = logging.INFO |
| 33 | + |
| 34 | + # Courselabs directory. Must be created before starting Tango |
| 35 | + COURSELABS = "courselabs" |
| 36 | + |
| 37 | + # Directory within each courselab where Tango will copy the output |
| 38 | + # for jobs of that courselab |
| 39 | + OUTPUT_FOLDER = "output" |
| 40 | + |
| 41 | + # VMMS to use. Must be set to a VMMS implemented in vmms/ before |
| 42 | + # starting Tango. Options are: "localDocker", "distDocker", |
| 43 | + # "tashiSSH", and "ec2SSH" |
| 44 | + VMMS_NAME = "localDocker" |
| 45 | + |
| 46 | + # Update this to the 'volumes' directory of your Tango installation if |
| 47 | + # Docker is being used as the VMMs. |
| 48 | + # It must be an absolute path with trailing slash, i.e |
| 49 | + # /opt/TangoService/Tango/volumes/ |
| 50 | + DEFAULT_DOCKER_VOLUME_PATH = "" |
| 51 | + DOCKER_VOLUME_PATH = os.getenv("DOCKER_VOLUME_PATH", DEFAULT_DOCKER_VOLUME_PATH) |
| 52 | + |
| 53 | + |
| 54 | + ##### |
| 55 | + # Part 2: Constants that shouldn't need to change very often. |
| 56 | + # |
| 57 | + |
| 58 | + # Keys for Tango to authenticate client requests |
| 59 | + DEFAULT_KEY = "test" |
| 60 | + KEYS = [os.getenv("RESTFUL_KEY", DEFAULT_KEY)] |
| 61 | + |
| 62 | + # Queue manager checks for new work every so many seconds |
| 63 | + DISPATCH_PERIOD = 0.2 |
| 64 | + |
| 65 | + # Timer polling interval used by timeout() function |
| 66 | + TIMER_POLL_INTERVAL = 1 |
| 67 | + |
| 68 | + # Number of server threads |
| 69 | + NUM_THREADS = 20 |
| 70 | + |
| 71 | + # We have the option to reuse VMs or discard them after each use |
| 72 | + REUSE_VMS = True |
| 73 | + |
| 74 | + # Worker waits this many seconds for functions waitvm, copyin (per |
| 75 | + # file), runjob, and copyout (per file) functions to finish. |
| 76 | + INITIALIZEVM_TIMEOUT = 180 |
| 77 | + WAITVM_TIMEOUT = 60 |
| 78 | + COPYIN_TIMEOUT = 30 |
| 79 | + RUNJOB_TIMEOUT = 60 |
| 80 | + COPYOUT_TIMEOUT = 30 |
| 81 | + |
| 82 | + # Docker constants |
| 83 | + BOOT2DOCKER_INIT_TIMEOUT = 5 |
| 84 | + BOOT2DOCKER_START_TIMEOUT = 30 |
| 85 | + BOOT2DOCKER_ENV_TIMEOUT = 5 |
| 86 | + DOCKER_IMAGE_BUILD_TIMEOUT = 300 |
| 87 | + DOCKER_RM_TIMEOUT = 5 |
| 88 | + DOCKER_HOST_USER = "" |
| 89 | + |
| 90 | + # Docker autograding container resource limits |
| 91 | + DOCKER_CORES_LIMIT = None |
| 92 | + DOCKER_MEMORY_LIMIT = None # in MB |
| 93 | + |
| 94 | + # Maximum size for input files in bytes |
| 95 | + MAX_INPUT_FILE_SIZE = 250 * 1024 * 1024 # 250MiB |
| 96 | + |
| 97 | + # Maximum size for output file in bytes |
| 98 | + MAX_OUTPUT_FILE_SIZE = 1024 * 1024 * 10 # 10MiB |
| 99 | + |
| 100 | + # VM ulimit values |
| 101 | + VM_ULIMIT_FILE_SIZE = 100 * 1024 * 1024 |
| 102 | + VM_ULIMIT_USER_PROC = 100 |
| 103 | + |
| 104 | + # How many times to reschedule a failed job |
| 105 | + JOB_RETRIES = 2 |
| 106 | + |
| 107 | + # How many times to attempt an SSH connection |
| 108 | + SSH_RETRIES = 5 |
| 109 | + |
| 110 | + # Frequency of retrying SSH connections (in seconds) |
| 111 | + SSH_INTERVAL = 0.5 |
| 112 | + |
| 113 | + # Give VMMS this many seconds to destroy a VM before giving up |
| 114 | + DESTROY_SECS = 5 |
| 115 | + |
| 116 | + # Time to wait between creating VM instances to give DNS time to cool down |
| 117 | + CREATEVM_SECS = 1 |
| 118 | + |
| 119 | + # Default vm pool size |
| 120 | + POOL_SIZE = 8 |
| 121 | + |
| 122 | + # Optionally log finer-grained timing information |
| 123 | + LOG_TIMING = False |
| 124 | + |
| 125 | + # Largest job ID |
| 126 | + MAX_JOBID = 10000 |
| 127 | + |
| 128 | + ###### |
| 129 | + # Part 3: Runtime info that you can retrieve using the /info route |
| 130 | + # |
| 131 | + start_time = time.time() |
| 132 | + job_requests = 0 |
| 133 | + job_retries = 0 |
| 134 | + waitvm_timeouts = 0 |
| 135 | + copyin_errors = 0 |
| 136 | + runjob_timeouts = 0 |
| 137 | + runjob_errors = 0 |
| 138 | + copyout_errors = 0 |
| 139 | + |
| 140 | + ###### |
| 141 | + # Part 4: Settings for shared memory |
| 142 | + # |
| 143 | + USE_REDIS = True |
| 144 | + DEFAULT_REDIS_HOSTNAME = "127.0.0.1" |
| 145 | + REDIS_HOSTNAME = os.getenv("DOCKER_REDIS_HOSTNAME", DEFAULT_REDIS_HOSTNAME).lower() |
| 146 | + REDIS_PORT = 6379 |
| 147 | + |
| 148 | + ###### |
| 149 | + # Part 5: EC2 Constants |
| 150 | + # |
| 151 | + EC2_REGION = "" |
| 152 | + EC2_USER_NAME = "" |
| 153 | + DEFAULT_AMI = "" |
| 154 | + DEFAULT_INST_TYPE = "" |
| 155 | + DEFAULT_SECURITY_GROUP = "" |
| 156 | + SECURITY_KEY_PATH = "" |
| 157 | + DYNAMIC_SECURITY_KEY_PATH = "" |
| 158 | + SECURITY_KEY_NAME = "" |
| 159 | + TANGO_RESERVATION_ID = "" |
| 160 | + INSTANCE_RUNNING = 16 # Status code of a instance that is running |
0 commit comments