Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/controller.py: 80.95%

42 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-22 21:04 +0000

1# Copyright (C) 2018 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16""" 

17Execution Controller 

18==================== 

19 

20An instance of the Execution controller. 

21 

22All this stuff you need to make the execution service work. 

23 

24Contains scheduler, execution instance, an interface to the bots 

25and an operations instance. 

26""" 

27 

28 

29import logging 

30 

31from .scheduler import Scheduler 

32from .bots.instance import BotsInterface 

33from .execution.instance import ExecutionInstance 

34from .operations.instance import OperationsInstance 

35from .._enums import ServiceName 

36 

37 

38class ExecutionController: 

39 

40 def __init__(self, data_store, *, property_keys, match_properties, 

41 storage=None, 

42 action_cache=None, action_browser_url=None, 

43 bot_session_keepalive_timeout=None, 

44 permissive_bot_session=None, 

45 services=ServiceName.default_services(), 

46 discard_unwatched_jobs=False, 

47 max_execution_timeout=None, 

48 max_list_operations_page_size=None, 

49 logstream_url=None, 

50 logstream_credentials=None, 

51 logstream_instance_name=None): 

52 

53 self.__logger = logging.getLogger(__name__) 

54 self._services = services 

55 

56 self._storage = storage 

57 self._action_cache = action_cache 

58 

59 scheduler = Scheduler( 

60 data_store, 

61 action_cache=action_cache, 

62 action_browser_url=action_browser_url, 

63 max_execution_timeout=max_execution_timeout, 

64 logstream_url=logstream_url, 

65 logstream_credentials=logstream_credentials, 

66 logstream_instance_name=logstream_instance_name 

67 ) 

68 

69 if ServiceName.EXECUTION.value in self._services: 

70 self._execution_instance = ExecutionInstance( 

71 scheduler, storage, property_keys, match_properties, 

72 discard_unwatched_jobs, action_cache=action_cache) 

73 if ServiceName.BOTS.value in self._services: 

74 self._bots_interface = BotsInterface( 

75 data_store, action_cache=action_cache, 

76 bot_session_keepalive_timeout=bot_session_keepalive_timeout, 

77 permissive_bot_session=permissive_bot_session, 

78 logstream_url=logstream_url, 

79 logstream_credentials=logstream_credentials, 

80 logstream_instance_name=logstream_instance_name) 

81 if ServiceName.OPERATIONS.value in self._services: 

82 self._operations_instance = OperationsInstance( 

83 scheduler, max_list_operations_page_size=max_list_operations_page_size) 

84 

85 def register_instance_with_server(self, instance_name, server): 

86 if ServiceName.EXECUTION.value in self._services: 

87 self._execution_instance.register_instance_with_server(instance_name, server) 

88 if ServiceName.BOTS.value in self._services: 

89 self._bots_interface.register_instance_with_server(instance_name, server) 

90 if ServiceName.OPERATIONS.value in self._services: 

91 self._operations_instance.register_instance_with_server(instance_name, server) 

92 

93 @property 

94 def execution_instance(self): 

95 try: 

96 return self._execution_instance 

97 except AttributeError: 

98 return None 

99 

100 @property 

101 def bots_interface(self): 

102 try: 

103 return self._bots_interface 

104 except AttributeError: 

105 return None 

106 

107 @property 

108 def operations_instance(self): 

109 try: 

110 return self._operations_instance 

111 except AttributeError: 

112 return None