Browse Source

Added support for OsloConfigFile

Change-Id: Ib9aaf7e16be0920696690b86cdcb14e06f1b643c
changes/63/307063/1
Kanagaraj Manickam 3 years ago
parent
commit
72e7f2cd38

+ 5
- 0
namos/common/exception.py View File

@@ -125,3 +125,8 @@ class ServiceWorkerNotFound(NotFound):
125 125
 class ConfigNotFound(NotFound):
126 126
     msg_fmt = ("Config %(config_id)s does not found")
127 127
     error_code = 0x0a001
128
+
129
+
130
+class ConfigFileNotFound(NotFound):
131
+    msg_fmt = ("Config file %(config_file_id)s does not found")
132
+    error_code = 0x0b001

+ 27
- 0
namos/conductor/manager.py View File

@@ -184,6 +184,33 @@ class ServiceProcessor(object):
184 184
                          service_component)
185 185
             # TODO(mrkanag) what to do when service_components size is > 1
186 186
 
187
+        # config file
188
+        for cfg_f in self.registration_info['config_file_list']:
189
+            try:
190
+                config_file = db_api.config_file_create(
191
+                    context,
192
+                    dict(name=cfg_f,
193
+                         file=self.registration_info[
194
+                             'config_file_dict'][cfg_f],
195
+                         service_component_id=service_component.id))
196
+                LOG.info('Oslo config file %s is created' % config_file)
197
+            except exception.AlreadyExist:
198
+                config_files = \
199
+                    db_api.config_file_get_by_name_for_service_component(
200
+                        context,
201
+                        service_component_id=service_component.id,
202
+                        name=cfg_f
203
+                    )
204
+                if len(config_files) == 1:
205
+                    config_file = \
206
+                        db_api.config_file_update(
207
+                            context,
208
+                            config_files[0].id,
209
+                            dict(file=self.registration_info[
210
+                                'config_file_dict'][cfg_f]))
211
+                    LOG.info('Oslo config file %s is existing and is updated'
212
+                             % config_file)
213
+
187 214
         # Service Worker
188 215
         try:
189 216
             service_worker = db_api.service_worker_create(

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

@@ -344,6 +344,40 @@ def config_delete(context, _id):
344 344
     return IMPL.config_delete(context, _id)
345 345
 
346 346
 
347
+def config_file_create(context, values):
348
+    return IMPL.config_file_create(context, values)
349
+
350
+
351
+def config_file_update(context, _id, values):
352
+    return IMPL.config_file_update(context, _id, values)
353
+
354
+
355
+def config_file_get(context, _id):
356
+    return IMPL.config_file_get(context, _id)
357
+
358
+
359
+def config_file_get_by_name(context, name):
360
+    return IMPL.config_file_get_by_name(context, name)
361
+
362
+
363
+def config_file_get_by_name_for_service_component(
364
+        context,
365
+        service_component_id,
366
+        name=None):
367
+    return IMPL.config_file_get_by_name_for_service_component(
368
+        context,
369
+        service_component_id,
370
+        name)
371
+
372
+
373
+def config_file_get_all(context):
374
+    return IMPL.config_file_get_all(context)
375
+
376
+
377
+def config_file_delete(context, _id):
378
+    return IMPL.config_file_delete(context, _id)
379
+
380
+
347 381
 def service_perspective_get(context, service_id,
348 382
                             include_details=False):
349 383
     return IMPL.service_perspective_get(context,

+ 1
- 0
namos/db/sqlalchemy/alembic/versions/48ebec3cd6f6_initial_version.py View File

@@ -177,6 +177,7 @@ def upgrade():
177 177
 
178 178
 
179 179
 def downgrade():
180
+    op.drop_table('oslo_config_file')
180 181
     op.drop_table('oslo_config')
181 182
     op.drop_table('device_driver')
182 183
     op.drop_table('service_worker')

+ 61
- 0
namos/db/sqlalchemy/api.py View File

@@ -548,6 +548,55 @@ def config_delete(context, _id):
548 548
     return _delete(context, models.OsloConfig, _id)
549 549
 
550 550
 
551
+# Config file
552
+def config_file_create(context, values):
553
+    return _create(context, models.OsloConfigFile(), values)
554
+
555
+
556
+def config_file_update(context, _id, values):
557
+    return _update(context, models.OsloConfigFile, _id, values)
558
+
559
+
560
+def config_file_get(context, _id):
561
+    config = _get(context, models.OsloConfigFile, _id)
562
+    if config is None:
563
+        raise exception.ConfigFileNotFound(config_file_id=_id)
564
+
565
+    return config
566
+
567
+
568
+def config_file_get_by_name(context, name):
569
+    config = _get_by_name(context, models.OsloConfigFile, name)
570
+    if config is None:
571
+        raise exception.ConfigFileNotFound(config_file_id=name)
572
+
573
+    return config
574
+
575
+
576
+def config_file_get_by_name_for_service_component(
577
+        context,
578
+        service_component_id,
579
+        name=None):
580
+    query = _model_query(context, models.OsloConfigFile). \
581
+        filter_by(service_component_id=service_component_id)
582
+    if name is not None:
583
+        query = query.filter_by(name=name)
584
+
585
+    return query.all()
586
+
587
+
588
+def config_file_get_all(context):
589
+    return _get_all(context, models.OsloConfigFile)
590
+
591
+
592
+def _config_file_get_all_by(context, **kwargs):
593
+    return _get_all_by(context, models.OsloConfigFile, **kwargs)
594
+
595
+
596
+def config_file_delete(context, _id):
597
+    return _delete(context, models.OsloConfigFile, _id)
598
+
599
+
551 600
 # REST-API
552 601
 def service_perspective_get(context, service_id, include_details=False):
553 602
     # 1. itr over Service Components and find name vs set of components
@@ -827,6 +876,18 @@ def view_360(context):
827 876
 
828 877
                 view['region'][rg.id]['service_node'][srv_nd.id][
829 878
                     'service_component'][srv_cmp.id] = dict()
879
+                view['region'][rg.id]['service_node'][srv_nd.id][
880
+                    'service_component'][srv_cmp.id]['config_file'] = dict()
881
+                cfg_fl_lst = config_file_get_by_name_for_service_component(
882
+                    context,
883
+                    service_component_id=srv_cmp.id
884
+                )
885
+                for cfg_fl in cfg_fl_lst:
886
+                    # config file
887
+                    view['region'][rg.id]['service_node'][srv_nd.id][
888
+                        'service_component'][srv_cmp.id][
889
+                        'config_file'][cfg_fl.name] = cfg_fl.file
890
+
830 891
                 view['region'][rg.id]['service_node'][srv_nd.id][
831 892
                     'service_component'][srv_cmp.id]['service'] = srv_id
832 893
                 view['region'][rg.id]['service_node'][srv_nd.id][

+ 24
- 0
namos/db/sqlalchemy/models.py View File

@@ -330,3 +330,27 @@ class OsloConfig(BASE,
330 330
         sqlalchemy.ForeignKey('service_worker.id'),
331 331
         nullable=False
332 332
     )
333
+
334
+
335
+class OsloConfigFile(BASE,
336
+                     NamosBase,
337
+                     SoftDelete,
338
+                     Extra):
339
+    __tablename__ = 'oslo_config_file'
340
+    __table_args__ = (
341
+        UniqueConstraint("name", "service_component_id"),
342
+    )
343
+
344
+    name = sqlalchemy.Column(sqlalchemy.String(255),
345
+                             # unique=True,
346
+                             nullable=False,
347
+                             default=lambda: str(uuid.uuid4()))
348
+
349
+    file = sqlalchemy.Column(
350
+        sqlalchemy.Text
351
+    )
352
+    service_component_id = sqlalchemy.Column(
353
+        Uuid,
354
+        sqlalchemy.ForeignKey('service_component.id'),
355
+        nullable=False
356
+    )

Loading…
Cancel
Save