Browse Source

config file update

Change-Id: Ibb1f0bcb8aee568814ebb85864b9eaff0ef3dccf
changes/69/307069/1
Kanagaraj Manickam 3 years ago
parent
commit
b4863bfd2b

+ 1
- 1
etc/namos.conf View File

@@ -11,7 +11,7 @@ rabbit_hosts = 172.241.0.101
11 11
 connection = mysql+pymysql://root:password@172.241.0.101/namos?charset=utf8
12 12
 
13 13
 [os_manager]
14
-workers=20
14
+workers=2
15 15
 
16 16
 [os_namos]
17 17
 region_name=RegionTwo

+ 2
- 1
namos/common/config.py View File

@@ -32,7 +32,8 @@ SCvsNT = dict(
32 32
                 'heat-engine',
33 33
                 'namos-manager',
34 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 37
                 'tacker-server'
37 38
                 ],
38 39
     compute=['nova-compute', 'neutron-openvswitch-agent',

+ 3
- 2
namos/common/messaging.py View File

@@ -91,7 +91,7 @@ def get_rpc_server(host, exchange, topic, version, endpoint):
91 91
                                          serializer=serializer)
92 92
 
93 93
 
94
-def get_rpc_client(topic, exchange, version, retry=None, **kwargs):
94
+def get_rpc_client(topic, exchange, version, retry=None, timeout=60, **kwargs):
95 95
     """Return a configured olso.messaging RPCClient."""
96 96
     oslo_messaging.set_transport_defaults(exchange)
97 97
     target = oslo_messaging.Target(version=version,
@@ -101,7 +101,8 @@ def get_rpc_client(topic, exchange, version, retry=None, **kwargs):
101 101
     return oslo_messaging.RPCClient(transport, target,
102 102
                                     serializer=serializer,
103 103
                                     retry=retry,
104
-                                    version_cap=version)
104
+                                    version_cap=version,
105
+                                    timeout=timeout)
105 106
 
106 107
 
107 108
 def cleanup():

+ 64
- 8
namos/conductor/manager.py View File

@@ -141,21 +141,24 @@ class ConductorManager(object):
141 141
         return service_worker_id
142 142
 
143 143
     def _regisgration_ackw(self, context, identification):
144
-        client = messaging.get_rpc_client(topic='namos.CONF.%s' %
145
-                                                identification,
146
-                                          version=self.RPC_API_VERSION,
147
-                                          exchange=namos_config.PROJECT_NAME)
144
+        client = messaging.get_rpc_client(
145
+            topic=self.os_namos_listener_topic(identification),
146
+            version=self.RPC_API_VERSION,
147
+            exchange=namos_config.PROJECT_NAME)
148 148
         client.cast(context,
149 149
                     'regisgration_ackw',
150 150
                     identification=identification)
151 151
         LOG.info("REGISTER [%s] ACK" % identification)
152 152
 
153
-    @request_context
154
-    def ping(self, context, identification):
153
+    def os_namos_listener_topic(self, identification):
154
+        return 'namos.CONF.%s' % identification
155
+
156
+    def _ping(self, context, identification):
155 157
         client = messaging.get_rpc_client(
156
-            topic='namos.CONF.%s' % identification,
158
+            topic=self.os_namos_listener_topic(identification),
157 159
             version=self.RPC_API_VERSION,
158
-            exchange=namos_config.PROJECT_NAME)
160
+            exchange=namos_config.PROJECT_NAME,
161
+            timeout=1)
159 162
         try:
160 163
             client.call(context,
161 164
                         'ping_me',
@@ -167,6 +170,19 @@ class ConductorManager(object):
167 170
             LOG.info("PING [%s] FAILED" % identification)
168 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 186
     @request_context
171 187
     def heart_beat(self, context, identification, dieing=False):
172 188
         try:
@@ -261,6 +277,46 @@ class ConductorManager(object):
261 277
         )
262 278
         return dict(file=file, entry=cfg_es)
263 279
 
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
+
264 320
     @request_context
265 321
     def config_schema(self, context, project, with_file_link=False):
266 322
         # provide the manage oslo_config_schema --gen

+ 18
- 2
namos/conductor/rpcapi.py View File

@@ -190,6 +190,13 @@ class ConductorAPI(object):
190 190
                                 'config_file_get',
191 191
                                 config_file_id=config_file_id)
192 192
 
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
+
193 200
     @wrapper_function
194 201
     def config_schema(self, context, project, with_file_link=False):
195 202
         return self.client.call(context,
@@ -233,5 +240,14 @@ if __name__ == '__main__':
233 240
                     with_file_link=True
234 241
                 )))
235 242
 
236
-    print_config_schema()
237
-    print_view_360()
243
+    def sample_config_update():
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()

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

@@ -270,6 +270,11 @@ def service_component_get_all(context):
270 270
     return IMPL.service_component_get_all(context)
271 271
 
272 272
 
273
+def 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
+
273 278
 def service_component_delete(context, _id):
274 279
     return IMPL.service_component_delete(context, _id)
275 280
 

+ 20
- 2
namos/db/sqlalchemy/api.py View File

@@ -445,6 +445,17 @@ def service_component_get_all_by_node_for_service(context,
445 445
     return query.all()
446 446
 
447 447
 
448
+def 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
+
448 459
 def service_component_get_all(context):
449 460
     return _get_all(context, models.ServiceComponent)
450 461
 
@@ -1152,5 +1163,12 @@ if __name__ == '__main__':
1152 1163
     # perp_json = json.dumps(persp, indent=4)
1153 1164
     # print perp_json
1154 1165
 
1155
-    import json
1156
-    print (json.dumps(view_360(None, True, True)))
1166
+    # import json
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))

Loading…
Cancel
Save