Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style |
| 3 | # license that can be found in the LICENSE file or at |
| 4 | # https://developers.google.com/open-source/licenses/bsd |
| 5 | |
| 6 | """Main program for Monorail. |
| 7 | |
| 8 | Monorail is an issue tracking tool that is based on the code.google.com |
| 9 | issue tracker, but it has been ported to Google AppEngine and Google Cloud SQL. |
| 10 | """ |
| 11 | from __future__ import print_function |
| 12 | from __future__ import division |
| 13 | from __future__ import absolute_import |
| 14 | |
| 15 | import logging |
| 16 | import webapp2 |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 17 | from flask import Flask |
| 18 | from werkzeug.middleware import dispatcher |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 19 | |
| 20 | from components import endpoints_webapp2 |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 21 | import gae_ts_mon |
| 22 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 23 | import flaskregisterpages |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 24 | import registerpages |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 25 | from framework import sorting, urls |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 26 | from services import api_svc_v1 |
| 27 | from services import service_manager |
| 28 | |
| 29 | |
| 30 | services = service_manager.set_up_services() |
| 31 | sorting.InitializeArtValues(services) |
| 32 | registry = registerpages.ServletRegistry() |
| 33 | app_routes = registry.Register(services) |
| 34 | app = webapp2.WSGIApplication( |
| 35 | app_routes, config={'services': services}) |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 36 | # TODO(crbug.com/1322775) Migrate away from the shared prodx-mon-chrome-infra |
| 37 | # service account and change to gae_ts_mon.initialize_prod() |
| 38 | gae_ts_mon.initialize_adhoc(app) |
| 39 | |
| 40 | flask_regist = flaskregisterpages.ServletRegistry() |
| 41 | |
| 42 | app = dispatcher.DispatcherMiddleware( |
| 43 | app, { |
| 44 | urls.EXCESSIVE_ACTIVITY: |
| 45 | flask_regist.RegisterExcesiveActivity(services), |
| 46 | }) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 47 | |
| 48 | endpoints = endpoints_webapp2.api_server( |
| 49 | [api_svc_v1.MonorailApi, api_svc_v1.ClientConfigApi]) |
| 50 | |
| 51 | # TODO(crbug/monorail/8221): Remove this code during this milestone. |
| 52 | # It only serves as a safe way to begin connecting to redis without risking |
| 53 | # user facing problems. |
| 54 | try: |
| 55 | logging.info('Starting initial redis connection verification.') |
| 56 | from framework import redis_utils |
| 57 | redis_utils.AsyncVerifyRedisConnection() |
| 58 | except: # pylint: disable=bare-except |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 59 | logging.exception('Exception when instantiating redis connection.') |