summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKanagaraj Manickam <mkr1481@gmail.com>2016-04-14 16:18:21 +0530
committerKanagaraj Manickam <mkr1481@gmail.com>2016-04-14 16:18:21 +0530
commitb4863bfd2b41d5789f6ddb62ae5c8a4933ac5501 (patch)
tree710c532c49de266ced96b8247c5302d73bc49209
parent350f37bbc51ac66636e74ddea59b32b2240b3616 (diff)
config file update
Notes
Notes (review): Code-Review+2: Kanagaraj Manickam <mkr1481@gmail.com> Workflow+1: Kanagaraj Manickam <mkr1481@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 18 Apr 2016 10:37:59 +0000 Reviewed-on: https://review.openstack.org/307069 Project: openstack/namos Branch: refs/heads/master
-rw-r--r--etc/namos.conf2
-rw-r--r--namos/common/config.py3
-rw-r--r--namos/common/messaging.py5
-rw-r--r--namos/conductor/manager.py72
-rw-r--r--namos/conductor/rpcapi.py20
-rw-r--r--namos/db/api.py5
-rw-r--r--namos/db/sqlalchemy/api.py22
7 files changed, 113 insertions, 16 deletions
diff --git a/etc/namos.conf b/etc/namos.conf
index e13a2eb..8430f53 100644
--- a/etc/namos.conf
+++ b/etc/namos.conf
@@ -11,7 +11,7 @@ rabbit_hosts = 172.241.0.101
11connection = mysql+pymysql://root:password@172.241.0.101/namos?charset=utf8 11connection = mysql+pymysql://root:password@172.241.0.101/namos?charset=utf8
12 12
13[os_manager] 13[os_manager]
14workers=20 14workers=2
15 15
16[os_namos] 16[os_namos]
17region_name=RegionTwo 17region_name=RegionTwo
diff --git a/namos/common/config.py b/namos/common/config.py
index 4107090..710ce5a 100644
--- a/namos/common/config.py
+++ b/namos/common/config.py
@@ -32,7 +32,8 @@ SCvsNT = dict(
32 'heat-engine', 32 'heat-engine',
33 'namos-manager', 33 'namos-manager',
34 'ceilometer-api', 'ceilometer-polling', 'ceilometer-collector', 34 'ceilometer-api', 'ceilometer-polling', 'ceilometer-collector',
35 'ceilometer-agent-notification', 35 'ceilometer-agent-notification', 'aodh-evaluator',
36 'aodh-notifier', 'aodh-api', 'aodh-listener',
36 'tacker-server' 37 'tacker-server'
37 ], 38 ],
38 compute=['nova-compute', 'neutron-openvswitch-agent', 39 compute=['nova-compute', 'neutron-openvswitch-agent',
diff --git a/namos/common/messaging.py b/namos/common/messaging.py
index bb15caa..b7223cb 100644
--- a/namos/common/messaging.py
+++ b/namos/common/messaging.py
@@ -91,7 +91,7 @@ def get_rpc_server(host, exchange, topic, version, endpoint):
91 serializer=serializer) 91 serializer=serializer)
92 92
93 93
94def get_rpc_client(topic, exchange, version, retry=None, **kwargs): 94def get_rpc_client(topic, exchange, version, retry=None, timeout=60, **kwargs):
95 """Return a configured olso.messaging RPCClient.""" 95 """Return a configured olso.messaging RPCClient."""
96 oslo_messaging.set_transport_defaults(exchange) 96 oslo_messaging.set_transport_defaults(exchange)
97 target = oslo_messaging.Target(version=version, 97 target = oslo_messaging.Target(version=version,
@@ -101,7 +101,8 @@ def get_rpc_client(topic, exchange, version, retry=None, **kwargs):
101 return oslo_messaging.RPCClient(transport, target, 101 return oslo_messaging.RPCClient(transport, target,
102 serializer=serializer, 102 serializer=serializer,
103 retry=retry, 103 retry=retry,
104 version_cap=version) 104 version_cap=version,
105 timeout=timeout)
105 106
106 107
107def cleanup(): 108def cleanup():
diff --git a/namos/conductor/manager.py b/namos/conductor/manager.py
index 950ebe4..8ce4896 100644
--- a/namos/conductor/manager.py
+++ b/namos/conductor/manager.py
@@ -141,21 +141,24 @@ class ConductorManager(object):
141 return service_worker_id 141 return service_worker_id
142 142
143 def _regisgration_ackw(self, context, identification): 143 def _regisgration_ackw(self, context, identification):
144 client = messaging.get_rpc_client(topic='namos.CONF.%s' % 144 client = messaging.get_rpc_client(
145 identification, 145 topic=self.os_namos_listener_topic(identification),
146 version=self.RPC_API_VERSION, 146 version=self.RPC_API_VERSION,
147 exchange=namos_config.PROJECT_NAME) 147 exchange=namos_config.PROJECT_NAME)
148 client.cast(context, 148 client.cast(context,
149 'regisgration_ackw', 149 'regisgration_ackw',
150 identification=identification) 150 identification=identification)
151 LOG.info("REGISTER [%s] ACK" % identification) 151 LOG.info("REGISTER [%s] ACK" % identification)
152 152
153 @request_context 153 def os_namos_listener_topic(self, identification):
154 def ping(self, context, identification): 154 return 'namos.CONF.%s' % identification
155
156 def _ping(self, context, identification):
155 client = messaging.get_rpc_client( 157 client = messaging.get_rpc_client(
156 topic='namos.CONF.%s' % identification, 158 topic=self.os_namos_listener_topic(identification),
157 version=self.RPC_API_VERSION, 159 version=self.RPC_API_VERSION,
158 exchange=namos_config.PROJECT_NAME) 160 exchange=namos_config.PROJECT_NAME,
161 timeout=1)
159 try: 162 try:
160 client.call(context, 163 client.call(context,
161 'ping_me', 164 'ping_me',
@@ -167,6 +170,19 @@ class ConductorManager(object):
167 LOG.info("PING [%s] FAILED" % identification) 170 LOG.info("PING [%s] FAILED" % identification)
168 return False 171 return False
169 172
173 def update_config_file(self, context, identification, name, content):
174 client = messaging.get_rpc_client(
175 topic=self.os_namos_listener_topic(identification),
176 version=self.RPC_API_VERSION,
177 exchange=namos_config.PROJECT_NAME,
178 timeout=2)
179 client.call(context,
180 'update_config_file',
181 identification=identification,
182 name=name,
183 content=content)
184 LOG.info("CONF FILE [%s] UPDATE [%s] DONE" % (name, identification))
185
170 @request_context 186 @request_context
171 def heart_beat(self, context, identification, dieing=False): 187 def heart_beat(self, context, identification, dieing=False):
172 try: 188 try:
@@ -262,6 +278,46 @@ class ConductorManager(object):
262 return dict(file=file, entry=cfg_es) 278 return dict(file=file, entry=cfg_es)
263 279
264 @request_context 280 @request_context
281 def config_file_update(self, context, config_file_id, content):
282 # update the db
283 db_api.config_file_update(context, config_file_id, {'file': content})
284 cf = self.config_file_get(context, config_file_id)['file']
285
286 # update the corresponding file in the respetive node
287 sc_list = db_api.service_component_get_all_by_config_file(
288 context,
289 config_file_id
290 )
291
292 # TODO(mrkanag) update the config file entries
293
294 # Find the first active service workr launcher to update the conf file
295 if sc_list:
296 for sc in sc_list:
297 sw_list = db_api.service_worker_get_all_by(
298 context,
299 service_component_id=sc_list[0].id,
300 is_launcher=True
301 )
302 if sw_list:
303 for sw in sw_list:
304 # TODO(mrkanag) is ping() better option instead?
305 if utils.find_status(sw):
306 try:
307 self.update_config_file(context,
308 sw.pid,
309 cf.name,
310 cf.file)
311 cf['status'] = 'completed'
312 return cf
313 except: # noqa
314 # try on next available sw
315 pass
316
317 cf['status'] = 'failed'
318 return cf
319
320 @request_context
265 def config_schema(self, context, project, with_file_link=False): 321 def config_schema(self, context, project, with_file_link=False):
266 # provide the manage oslo_config_schema --gen 322 # provide the manage oslo_config_schema --gen
267 file_schema = dict() 323 file_schema = dict()
diff --git a/namos/conductor/rpcapi.py b/namos/conductor/rpcapi.py
index bfc91dd..43d3933 100644
--- a/namos/conductor/rpcapi.py
+++ b/namos/conductor/rpcapi.py
@@ -191,6 +191,13 @@ class ConductorAPI(object):
191 config_file_id=config_file_id) 191 config_file_id=config_file_id)
192 192
193 @wrapper_function 193 @wrapper_function
194 def config_file_update(self, context, config_file_id, content):
195 return self.client.call(context,
196 'config_file_update',
197 config_file_id=config_file_id,
198 content=content)
199
200 @wrapper_function
194 def config_schema(self, context, project, with_file_link=False): 201 def config_schema(self, context, project, with_file_link=False):
195 return self.client.call(context, 202 return self.client.call(context,
196 'config_schema', 203 'config_schema',
@@ -233,5 +240,14 @@ if __name__ == '__main__':
233 with_file_link=True 240 with_file_link=True
234 ))) 241 )))
235 242
236 print_config_schema() 243 def sample_config_update():
237 print_view_360() 244 with open('/tmp/sample.conf', 'r') as content_file:
245 content = content_file.read()
246
247 print (c.config_file_update(context.RequestContext(),
248 'dcf0f17b-99f6-49e9-8d5f-23b3ad1167dc',
249 content))
250
251 # print_config_schema()
252 # print_view_360()
253 sample_config_update()
diff --git a/namos/db/api.py b/namos/db/api.py
index cce18e4..e75ccae 100644
--- a/namos/db/api.py
+++ b/namos/db/api.py
@@ -270,6 +270,11 @@ def service_component_get_all(context):
270 return IMPL.service_component_get_all(context) 270 return IMPL.service_component_get_all(context)
271 271
272 272
273def service_component_get_all_by_config_file(context, config_file_id):
274 return IMPL.service_component_get_all_by_config_file(context,
275 config_file_id)
276
277
273def service_component_delete(context, _id): 278def service_component_delete(context, _id):
274 return IMPL.service_component_delete(context, _id) 279 return IMPL.service_component_delete(context, _id)
275 280
diff --git a/namos/db/sqlalchemy/api.py b/namos/db/sqlalchemy/api.py
index 1e2793f..81d98e6 100644
--- a/namos/db/sqlalchemy/api.py
+++ b/namos/db/sqlalchemy/api.py
@@ -445,6 +445,17 @@ def service_component_get_all_by_node_for_service(context,
445 return query.all() 445 return query.all()
446 446
447 447
448def service_component_get_all_by_config_file(context, config_file_id):
449 query = _model_query(context,
450 models.OsloConfigFileEntry.service_component_id). \
451 filter_by(oslo_config_file_id=config_file_id).distinct()
452 query_sc = _model_query(context, models.ServiceComponent).filter(
453 models.ServiceComponent.id.in_(query)
454 )
455
456 return query_sc.all()
457
458
448def service_component_get_all(context): 459def service_component_get_all(context):
449 return _get_all(context, models.ServiceComponent) 460 return _get_all(context, models.ServiceComponent)
450 461
@@ -1152,5 +1163,12 @@ if __name__ == '__main__':
1152 # perp_json = json.dumps(persp, indent=4) 1163 # perp_json = json.dumps(persp, indent=4)
1153 # print perp_json 1164 # print perp_json
1154 1165
1155 import json 1166 # import json
1156 print (json.dumps(view_360(None, True, True))) 1167 # print (json.dumps(view_360(None, True, True)))
1168
1169 sc = service_component_get_all_by_config_file(
1170 None,
1171 '03cccfb4-5433-47fc-af3c-63869f270d78')
1172 print (service_worker_get_all_by(None,
1173 service_component_id=sc[0].id,
1174 is_launcher=True))