-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlauncher.py
132 lines (117 loc) · 4.05 KB
/
launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import argparse
import resource
from adf_core_python.core.config.config import Config
from adf_core_python.core.launcher.agent_launcher import AgentLauncher
from adf_core_python.core.launcher.config_key import ConfigKey
from adf_core_python.core.logger.logger import configure_logger, get_logger
class Launcher:
def __init__(
self,
launcher_config_file: str,
) -> None:
resource.setrlimit(resource.RLIMIT_NOFILE, (8192, 9223372036854775807))
configure_logger()
self.logger = get_logger(__name__)
self.launcher_config = Config(launcher_config_file)
parser = argparse.ArgumentParser(description="Agent Launcher")
parser.add_argument(
"--host",
type=str,
help="host name(Default: localhost)",
metavar="",
)
parser.add_argument(
"--port",
type=int,
help="port number(Default: 27931)",
metavar="",
)
parser.add_argument(
"-a",
"--ambulanceteam",
type=int,
help="number of ambulance agents(Default: all ambulance)",
metavar="",
)
parser.add_argument(
"-f",
"--firebrigade",
type=int,
help="number of firebrigade agents(Default: all firebrigade)",
metavar="",
)
parser.add_argument(
"-p",
"--policeforce",
type=int,
help="number of policeforce agents(Default: all policeforce)",
metavar="",
)
parser.add_argument(
"-ac",
"--ambulancecenter",
type=int,
help="number of ambulance center agents(Default: all ambulance center)",
metavar="",
)
parser.add_argument(
"-fs",
"--firestation",
type=int,
help="number of fire station agents(Default: all fire station)",
metavar="",
)
parser.add_argument(
"-po",
"--policeoffice",
type=int,
help="number of police office agents(Default: all police office)",
metavar="",
)
parser.add_argument(
"--precompute",
action="store_true",
help="precompute flag",
)
parser.add_argument("--debug", action="store_true", help="debug flag")
parser.add_argument(
"--java",
action="store_true",
help="using java module flag",
)
args = parser.parse_args()
config_map = {
ConfigKey.KEY_KERNEL_HOST: args.host,
ConfigKey.KEY_KERNEL_PORT: args.port,
ConfigKey.KEY_AMBULANCE_TEAM_COUNT: args.ambulanceteam,
ConfigKey.KEY_FIRE_BRIGADE_COUNT: args.firebrigade,
ConfigKey.KEY_POLICE_FORCE_COUNT: args.policeforce,
ConfigKey.KEY_AMBULANCE_CENTRE_COUNT: args.ambulancecenter,
ConfigKey.KEY_FIRE_STATION_COUNT: args.firestation,
ConfigKey.KEY_POLICE_OFFICE_COUNT: args.policeoffice,
ConfigKey.KEY_PRECOMPUTE: args.precompute,
ConfigKey.KEY_DEBUG_FLAG: args.debug,
ConfigKey.KEY_GATEWAY_FLAG: args.java,
}
for key, value in config_map.items():
if value is not None:
self.launcher_config.set_value(key, value)
self.logger.debug(f"launcher_config: {self.launcher_config}")
def launch(self) -> None:
agent_launcher: AgentLauncher = AgentLauncher(
self.launcher_config,
)
agent_launcher.init_connector()
try:
agent_launcher.launch()
except KeyboardInterrupt:
self.logger.info("Agent launcher interrupted")
except Exception as e:
self.logger.exception("Agent launcher failed", exc_info=e)
raise e
self.logger.info("Agent launcher finished")
if __name__ == "__main__":
launcher = Launcher(
"config/launcher.yaml",
)
launcher.launch()