-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
201 lines (147 loc) · 4.45 KB
/
config.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import sys
import yaml
import importlib
from util import dirname
class API:
def __init__(self, port, endpoint, host=None, *args, **kwargs):
self.__host = host
self.__port = int(port)
self.__endpoint = endpoint
@property
def host(self):
return self.__host
@property
def port(self):
return self.__port
@property
def endpoint(self):
return self.__endpoint
@host.setter
def host(self, h):
self.__host = h
@port.setter
def port(self, p):
self.__port = int(p)
class MesosAPI(API):
def __init__(self, port=5050, *args, **kwargs):
kwargs.update(port=port, endpoint='')
super(MesosAPI, self).__init__(*args, **kwargs)
class MarathonAPI(API):
def __init__(self, port=8080, *args, **kwargs):
kwargs.update(port=port, endpoint='/v2')
super(MarathonAPI, self).__init__(*args, **kwargs)
class ChronosAPI(API):
def __init__(self, port=9090, *args, **kwargs):
kwargs.update(port=port, endpoint='/v1/scheduler')
super(ChronosAPI, self).__init__(*args, **kwargs)
class ExhibitorAPI(API):
def __init__(self, port=8181, *args, **kwargs):
kwargs.update(port=port, endpoint='/exhibitor/v1')
super(ExhibitorAPI, self).__init__(*args, **kwargs)
class CephAPI(API):
def __init__(self, port=8080, *args, **kwargs):
kwargs.update(port=port, endpoint='/')
super(CephAPI, self).__init__(*args, **kwargs)
class GeneralConfig:
def __init__(self, master, port=9090, n_parallel=1,
scheduler='schedule.universal.DefaultGlobalScheduler', https=False, *args, **kwargs):
self.__master = master
self.__port = port
self.__n_parallel = n_parallel
self.__scheduler = scheduler
self.__https = https
@property
def master(self):
return self.__master
@property
def port(self):
return self.__port
@property
def n_parallel(self):
return self.__n_parallel
@master.setter
def master(self, master):
self.__master = master
@property
def scheduler(self):
return self.__scheduler
@property
def https(self):
return self.__https
class DatabaseConfig:
def __init__(self, host, port, name, *args, **kwargs):
self.__host = host
self.__port = port
self.__name = name
@property
def host(self):
return self.__host
@property
def port(self):
return self.__port
@property
def name(self):
return self.__name
class Configuration:
@classmethod
def read_config(cls, cfg_file_path):
cfg = yaml.load(open(cfg_file_path))
try:
pivot_cfg = GeneralConfig(**cfg.get('pivot', {}))
except Exception as e:
sys.stderr.write(str(e))
sys.stderr.write('PIVOT configuration is not set correctly\n')
sys.exit(1)
try:
db_cfg = DatabaseConfig(**cfg.get('db', {}))
except Exception as e:
sys.stderr.write(str(e) + '\n')
sys.stderr.write('Database configuration is not set correctly\n')
sys.exit(2)
return Configuration(pivot=pivot_cfg,
db=db_cfg,
mesos=MesosAPI(**cfg.get('mesos', {})),
marathon=MarathonAPI(**cfg.get('marathon', {})),
chronos=ChronosAPI(**cfg.get('chronos', {})),
exhibitor=ExhibitorAPI(**cfg.get('exhibitor', {})),
ceph=CephAPI(**cfg.get('ceph', {})))
def __init__(self, pivot, db, mesos=None, marathon=None, chronos=None,
exhibitor=None, ceph=None, *args, **kwargs):
self.__pivot = pivot
self.__db = db
self.__mesos = mesos
self.__marathon = marathon
self.__chronos = chronos
self.__exhibitor = exhibitor
self.__ceph = ceph
@property
def pivot(self):
return self.__pivot
@property
def db(self):
return self.__db
@property
def mesos(self):
return self.__mesos
@property
def marathon(self):
return self.__marathon
@property
def chronos(self):
return self.__chronos
@property
def exhibitor(self):
return self.__exhibitor
@property
def ceph(self):
return self.__ceph
config = Configuration.read_config('%s/config.yml'%dirname(__file__))
def get_global_scheduler():
try:
sched_mod = '.'.join(config.pivot.scheduler.split('.')[:-1])
sched_class = config.pivot.scheduler.split('.')[-1]
return getattr(importlib.import_module(sched_mod), sched_class)()
except Exception as e:
sys.stderr.write(str(e) + '\n')
from schedule.universal import DefaultGlobalScheduler
return DefaultGlobalScheduler()