| 1 |
# mypy: allow-untyped-defs |
| 2 |
|
| 3 |
import os |
| 4 |
import logging |
| 5 |
|
| 6 |
from . import configuration_loader |
| 7 |
|
| 8 |
from .network.http_handler import HttpHandler |
| 9 |
from .network.api.sessions_api_handler import SessionsApiHandler |
| 10 |
from .network.api.tests_api_handler import TestsApiHandler |
| 11 |
from .network.api.results_api_handler import ResultsApiHandler |
| 12 |
from .network.api.devices_api_handler import DevicesApiHandler |
| 13 |
from .network.api.general_api_handler import GeneralApiHandler |
| 14 |
from .network.static_handler import StaticHandler |
| 15 |
|
| 16 |
from .testing.sessions_manager import SessionsManager |
| 17 |
from .testing.results_manager import ResultsManager |
| 18 |
from .testing.tests_manager import TestsManager |
| 19 |
from .testing.devices_manager import DevicesManager |
| 20 |
from .testing.test_loader import TestLoader |
| 21 |
from .testing.event_dispatcher import EventDispatcher |
| 22 |
|
| 23 |
VERSION_STRING = "v3.3.0" |
| 24 |
|
| 25 |
|
| 26 |
class WaveServer: |
| 27 |
def initialize(self, |
| 28 |
tests, |
| 29 |
configuration_file_path=None, |
| 30 |
application_directory_path=None, |
| 31 |
reports_enabled=None): |
| 32 |
if configuration_file_path is None: |
| 33 |
configuration_file_path = "" |
| 34 |
if application_directory_path is None: |
| 35 |
application_directory_path = "" |
| 36 |
if reports_enabled is None: |
| 37 |
reports_enabled = False |
| 38 |
|
| 39 |
logger = logging.getLogger("wave-server") |
| 40 |
|
| 41 |
logger.debug("Loading configuration ...") |
| 42 |
configuration = configuration_loader.load(configuration_file_path) |
| 43 |
|
| 44 |
# Initialize Managers |
| 45 |
event_dispatcher = EventDispatcher( |
| 46 |
event_cache_duration=configuration["event_cache_duration"] |
| 47 |
) |
| 48 |
sessions_manager = SessionsManager() |
| 49 |
results_manager = ResultsManager() |
| 50 |
tests_manager = TestsManager() |
| 51 |
devices_manager = DevicesManager() |
| 52 |
test_loader = TestLoader() |
| 53 |
|
| 54 |
sessions_manager.initialize( |
| 55 |
test_loader=test_loader, |
| 56 |
event_dispatcher=event_dispatcher, |
| 57 |
tests_manager=tests_manager, |
| 58 |
results_directory=configuration["results_directory_path"], |
| 59 |
results_manager=results_manager, |
| 60 |
configuration=configuration |
| 61 |
) |
| 62 |
|
| 63 |
results_manager.initialize( |
| 64 |
results_directory_path=configuration["results_directory_path"], |
| 65 |
sessions_manager=sessions_manager, |
| 66 |
tests_manager=tests_manager, |
| 67 |
import_results_enabled=configuration["import_results_enabled"], |
| 68 |
reports_enabled=reports_enabled, |
| 69 |
persisting_interval=configuration["persisting_interval"] |
| 70 |
) |
| 71 |
|
| 72 |
tests_manager.initialize( |
| 73 |
test_loader, |
| 74 |
results_manager=results_manager, |
| 75 |
sessions_manager=sessions_manager, |
| 76 |
event_dispatcher=event_dispatcher |
| 77 |
) |
| 78 |
|
| 79 |
devices_manager.initialize(event_dispatcher) |
| 80 |
|
| 81 |
exclude_list_file_path = os.path.abspath("./excluded.json") |
| 82 |
include_list_file_path = os.path.abspath("./included.json") |
| 83 |
test_loader.initialize( |
| 84 |
exclude_list_file_path, |
| 85 |
include_list_file_path, |
| 86 |
results_manager=results_manager, |
| 87 |
api_titles=configuration["api_titles"] |
| 88 |
) |
| 89 |
|
| 90 |
test_loader.load_tests(tests) |
| 91 |
|
| 92 |
# Initialize HTTP handlers |
| 93 |
static_handler = StaticHandler( |
| 94 |
web_root=configuration["web_root"], |
| 95 |
http_port=configuration["wpt_port"], |
| 96 |
https_port=configuration["wpt_ssl_port"] |
| 97 |
) |
| 98 |
sessions_api_handler = SessionsApiHandler( |
| 99 |
sessions_manager=sessions_manager, |
| 100 |
results_manager=results_manager, |
| 101 |
event_dispatcher=event_dispatcher, |
| 102 |
web_root=configuration["web_root"], |
| 103 |
read_sessions_enabled=configuration["read_sessions_enabled"] |
| 104 |
) |
| 105 |
tests_api_handler = TestsApiHandler( |
| 106 |
tests_manager=tests_manager, |
| 107 |
sessions_manager=sessions_manager, |
| 108 |
wpt_port=configuration["wpt_port"], |
| 109 |
wpt_ssl_port=configuration["wpt_ssl_port"], |
| 110 |
hostname=configuration["hostname"], |
| 111 |
web_root=configuration["web_root"], |
| 112 |
test_loader=test_loader |
| 113 |
) |
| 114 |
devices_api_handler = DevicesApiHandler( |
| 115 |
devices_manager=devices_manager, |
| 116 |
event_dispatcher=event_dispatcher, |
| 117 |
web_root=configuration["web_root"] |
| 118 |
) |
| 119 |
results_api_handler = ResultsApiHandler( |
| 120 |
results_manager, |
| 121 |
sessions_manager, |
| 122 |
web_root=configuration["web_root"] |
| 123 |
) |
| 124 |
general_api_handler = GeneralApiHandler( |
| 125 |
web_root=configuration["web_root"], |
| 126 |
read_sessions_enabled=configuration["read_sessions_enabled"], |
| 127 |
import_results_enabled=configuration["import_results_enabled"], |
| 128 |
reports_enabled=reports_enabled, |
| 129 |
version_string=VERSION_STRING, |
| 130 |
test_type_selection_enabled=configuration["enable_test_type_selection"], |
| 131 |
test_file_selection_enabled=configuration["enable_test_file_selection"] |
| 132 |
) |
| 133 |
|
| 134 |
# Initialize HTTP server |
| 135 |
http_handler = HttpHandler( |
| 136 |
static_handler=static_handler, |
| 137 |
sessions_api_handler=sessions_api_handler, |
| 138 |
tests_api_handler=tests_api_handler, |
| 139 |
results_api_handler=results_api_handler, |
| 140 |
devices_api_handler=devices_api_handler, |
| 141 |
general_api_handler=general_api_handler, |
| 142 |
http_port=configuration["wpt_port"], |
| 143 |
web_root=configuration["web_root"] |
| 144 |
) |
| 145 |
self.handle_request = http_handler.handle_request |