Browse Source

namos.cfg RPC server enabled

Change-Id: I7f05316a69344cc286339100da3cd90447df7ceb
Kanagaraj Manickam 3 years ago
parent
commit
ce9913a9e5

+ 5
- 0
etc/namos.conf View File

@@ -1,5 +1,10 @@
1 1
 [DEFAULT]
2 2
 rpc_backend = rabbit
3
+debug=True
4
+logging_exception_prefix = %(color)s%(asctime)s.%(msecs)03d TRACE %(name)s %(instance)s
5
+logging_debug_format_suffix = from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d
6
+logging_default_format_string = %(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s
7
+logging_context_format_string = %(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %(user)s %(tenant)s%(color)s] %(instance)s%(color)s%(message)s
3 8
 
4 9
 [oslo_messaging_rabbit]
5 10
 rabbit_userid = stackrabbit

+ 8
- 3
namos/cmd/manage.py View File

@@ -45,7 +45,9 @@ class HeartBeat(object):
45 45
     def report_status(self):
46 46
         # TODO(mrkanag) Make like Node: Service: worker: status
47 47
         for sw in api.service_worker_get_all(None):
48
-            print ('[', 'T' if self.find_status(sw) else 'F', ']', sw.name)
48
+            msg = '[%s] %s' % ('T' if self.find_status(sw) else 'F',
49
+                               sw.name)
50
+            print (msg)
49 51
 
50 52
 
51 53
 class OsloConfigSchemaManager(object):
@@ -108,8 +110,11 @@ class OsloConfigSchemaManager(object):
108 110
                             except exception.AlreadyExist:
109 111
                                 _a = 'F'
110 112
 
111
-                            print ('[', _a, ']', namespace, ':', grp, ':',
112
-                                   name)
113
+                            msg = '[%s] %s::%s::%s' % (_a,
114
+                                                       namespace,
115
+                                                       grp,
116
+                                                       name)
117
+                            print (msg)
113 118
 
114 119
 
115 120
 class DBCommand(object):

+ 1
- 1
namos/common/messaging.py View File

@@ -80,7 +80,7 @@ def get_transport(url=None, optional=False, cache=True):
80 80
 
81 81
 def get_rpc_server(host, exchange, topic, version, endpoint):
82 82
     """Return a configured olso.messaging rpc server."""
83
-    oslo_messaging.set_transport_defaults(exchange)
83
+    # oslo_messaging.set_transport_defaults(exchange)
84 84
     target = oslo_messaging.Target(server=host,
85 85
                                    topic=topic,
86 86
                                    version=version)

+ 34
- 15
namos/conductor/manager.py View File

@@ -21,6 +21,7 @@ from oslo_utils import timeutils
21 21
 
22 22
 from namos.common import config
23 23
 from namos.common import exception
24
+from namos.common import messaging
24 25
 from namos.db import api as db_api
25 26
 from namos.db import openstack_drivers
26 27
 
@@ -60,8 +61,11 @@ class ConductorManager(object):
60 61
 
61 62
     @request_context
62 63
     def register_myself(self, context, registration_info):
63
-        LOG.info("REGISTER [%s.%s] START" % (registration_info['project_name'],
64
-                                             registration_info['prog_name']))
64
+        LOG.info("REGISTER [%s.%s.%s] START" % (
65
+            registration_info['project_name'],
66
+            registration_info['prog_name'],
67
+            registration_info['identification']
68
+        ))
65 69
 
66 70
         # Service processing
67 71
         sp = ServiceProcessor(registration_info)
@@ -71,11 +75,25 @@ class ConductorManager(object):
71 75
         dp = DriverProcessor(service_worker_id,
72 76
                              registration_info['config_dict'])
73 77
         dp.process_drivers(context)
74
-        LOG.info("REGISTER [%s.%s] DONE" % (registration_info['project_name'],
75
-                                            registration_info['prog_name']))
76
-
78
+        LOG.info("REGISTER [%s.%s.%s] DONE" % (
79
+            registration_info['project_name'],
80
+            registration_info['prog_name'],
81
+            registration_info['identification']
82
+        ))
83
+        self._regisgration_ackw(context,
84
+                                registration_info['identification'])
77 85
         return service_worker_id
78 86
 
87
+    def _regisgration_ackw(self, context, identification):
88
+        client = messaging.get_rpc_client(topic='namos.CONF.%s' %
89
+                                                identification,
90
+                                          version=self.RPC_API_VERSION,
91
+                                          exchange=config.PROJECT_NAME)
92
+        client.cast(context,
93
+                    'regisgration_ackw',
94
+                    identification=identification)
95
+        LOG.info("REGISTER [%s] ACK" % identification)
96
+
79 97
     @request_context
80 98
     def heart_beat(self, context, identification, dieing=False):
81 99
         try:
@@ -215,13 +233,14 @@ class ServiceProcessor(object):
215 233
                     dict(name=cfg_f,
216 234
                          file=self.registration_info[
217 235
                              'config_file_dict'][cfg_f],
218
-                         service_component_id=service_component.id))
236
+                         service_component_id=service_component.id,
237
+                         service_node_id=node.id))
219 238
                 LOG.info('Oslo config file %s is created' % config_file)
220 239
             except exception.AlreadyExist:
221 240
                 config_files = \
222
-                    db_api.config_file_get_by_name_for_service_component(
241
+                    db_api.config_file_get_by_name_for_service_node(
223 242
                         context,
224
-                        service_component_id=service_component.id,
243
+                        service_node_id=node.id,
225 244
                         name=cfg_f
226 245
                     )
227 246
                 if len(config_files) == 1:
@@ -288,8 +307,8 @@ class ServiceProcessor(object):
288 307
 
289 308
             if len(cfg_schs) > 1:
290 309
                 cfg_sche = cfg_schs[0]
291
-                LOG.info("Config Schema %s is existing and is updated" %
292
-                         cfg_sche)
310
+                LOG.debug("Config Schema %s is existing and is updated" %
311
+                          cfg_sche)
293 312
             else:
294 313
                 try:
295 314
                     cfg_sche = db_api.config_schema_create(
@@ -306,7 +325,7 @@ class ServiceProcessor(object):
306 325
                             name=cfg_obj['name']
307 326
                         )
308 327
                     )
309
-                    LOG.info("Config Schema %s is created" % cfg_sche)
328
+                    LOG.debug("Config Schema %s is created" % cfg_sche)
310 329
                 except exception.AlreadyExist:
311 330
                     cfg_schs = db_api.config_schema_get_by(
312 331
                         context=context,
@@ -316,8 +335,8 @@ class ServiceProcessor(object):
316 335
                     )
317 336
 
318 337
                     cfg_sche = cfg_schs[0]
319
-                    LOG.info("Config Schema %s is existing and is updated" %
320
-                             cfg_sche)
338
+                    LOG.debug("Config Schema %s is existing and is updated" %
339
+                              cfg_sche)
321 340
 
322 341
             cfg_obj_ = dict(
323 342
                 service_worker_id=service_worker.id,
@@ -328,7 +347,7 @@ class ServiceProcessor(object):
328 347
 
329 348
             try:
330 349
                 config = db_api.config_create(context, cfg_obj_)
331
-                LOG.info("Config %s is created" % config)
350
+                LOG.debug("Config %s is created" % config)
332 351
             except exception.AlreadyExist:
333 352
                 configs = db_api.config_get_by_name_for_service_worker(
334 353
                     context,
@@ -338,7 +357,7 @@ class ServiceProcessor(object):
338 357
                     config = db_api.config_update(context,
339 358
                                                   configs[0].id,
340 359
                                                   cfg_obj_)
341
-                    LOG.info("Config %s is existing and is updated" % config)
360
+                    LOG.debug("Config %s is existing and is updated" % config)
342 361
 
343 362
         return service_worker.id
344 363
 

+ 4
- 4
namos/db/api.py View File

@@ -397,13 +397,13 @@ def config_file_get_by_name(context, name):
397 397
     return IMPL.config_file_get_by_name(context, name)
398 398
 
399 399
 
400
-def config_file_get_by_name_for_service_component(
400
+def config_file_get_by_name_for_service_node(
401 401
         context,
402
-        service_component_id,
402
+        service_node_id,
403 403
         name=None):
404
-    return IMPL.config_file_get_by_name_for_service_component(
404
+    return IMPL.config_file_get_by_name_for_service_node(
405 405
         context,
406
-        service_component_id,
406
+        service_node_id,
407 407
         name)
408 408
 
409 409
 

+ 5
- 5
namos/db/sqlalchemy/api.py View File

@@ -629,12 +629,12 @@ def config_file_get_by_name(context, name):
629 629
     return config
630 630
 
631 631
 
632
-def config_file_get_by_name_for_service_component(
632
+def config_file_get_by_name_for_service_node(
633 633
         context,
634
-        service_component_id,
634
+        service_node_id,
635 635
         name=None):
636 636
     query = _model_query(context, models.OsloConfigFile). \
637
-        filter_by(service_component_id=service_component_id)
637
+        filter_by(service_node_id=service_node_id)
638 638
     if name is not None:
639 639
         query = query.filter_by(name=name)
640 640
 
@@ -934,9 +934,9 @@ def view_360(context):
934 934
                     'service_component'][srv_cmp.id] = dict()
935 935
                 view['region'][rg.id]['service_node'][srv_nd.id][
936 936
                     'service_component'][srv_cmp.id]['config_file'] = dict()
937
-                cfg_fl_lst = config_file_get_by_name_for_service_component(
937
+                cfg_fl_lst = config_file_get_by_name_for_service_node(
938 938
                     context,
939
-                    service_component_id=srv_cmp.id
939
+                    service_node_id=srv_nd.id
940 940
                 )
941 941
                 for cfg_fl in cfg_fl_lst:
942 942
                     # config file

+ 10
- 2
namos/db/sqlalchemy/models.py View File

@@ -22,7 +22,9 @@ from sqlalchemy import UniqueConstraint
22 22
 import uuid
23 23
 
24 24
 from namos.db.sqlalchemy.types import Json
25
+from namos.db.sqlalchemy.types import LongText
25 26
 from namos.db.sqlalchemy.types import Uuid
27
+
26 28
 from oslo_db.sqlalchemy import models
27 29
 from oslo_utils import timeutils
28 30
 
@@ -376,7 +378,7 @@ class OsloConfigFile(BASE,
376 378
                      Extra):
377 379
     __tablename__ = 'oslo_config_file'
378 380
     __table_args__ = (
379
-        UniqueConstraint("name", "service_component_id"),
381
+        UniqueConstraint("name", "service_node_id"),
380 382
     )
381 383
 
382 384
     name = sqlalchemy.Column(sqlalchemy.String(255),
@@ -385,10 +387,16 @@ class OsloConfigFile(BASE,
385 387
                              default=lambda: str(uuid.uuid4()))
386 388
 
387 389
     file = sqlalchemy.Column(
388
-        sqlalchemy.Text
390
+        LongText
389 391
     )
392
+    # Always having last one updated the conf file
390 393
     service_component_id = sqlalchemy.Column(
391 394
         Uuid,
392 395
         sqlalchemy.ForeignKey('service_component.id'),
393 396
         nullable=False
394 397
     )
398
+    service_node_id = sqlalchemy.Column(
399
+        Uuid,
400
+        sqlalchemy.ForeignKey('service_node.id'),
401
+        nullable=False
402
+    )

+ 10
- 0
namos/db/sqlalchemy/types.py View File

@@ -53,3 +53,13 @@ class Uuid(TypeDecorator):
53 53
 
54 54
     def process_result_value(self, value, dialect):
55 55
         return value
56
+
57
+
58
+class LongText(TypeDecorator):
59
+    impl = Text
60
+
61
+    def load_dialect_impl(self, dialect):
62
+        if dialect.name == 'mysql':
63
+            return dialect.type_descriptor(mysql.LONGTEXT())
64
+        else:
65
+            return self.impl

Loading…
Cancel
Save