summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKanagaraj Manickam <mkr1481@gmail.com>2016-03-23 18:06:57 +0530
committerKanagaraj Manickam <mkr1481@gmail.com>2016-03-23 18:06:57 +0530
commit72e7f2cd387e6ecaebf9ae36330fa823dfd9dfe2 (patch)
treea3fbf022d1697ba1c577433f28e0cce6cb97607e
parent0a765fe3ae8aed285dea9e96b21b0cf96b4b12f2 (diff)
Added support for OsloConfigFile
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:23 +0000 Reviewed-on: https://review.openstack.org/307063 Project: openstack/namos Branch: refs/heads/master
-rw-r--r--namos/common/exception.py5
-rw-r--r--namos/conductor/manager.py27
-rw-r--r--namos/db/api.py34
-rw-r--r--namos/db/sqlalchemy/alembic/versions/48ebec3cd6f6_initial_version.py1
-rw-r--r--namos/db/sqlalchemy/api.py61
-rw-r--r--namos/db/sqlalchemy/models.py24
6 files changed, 152 insertions, 0 deletions
diff --git a/namos/common/exception.py b/namos/common/exception.py
index 403bd0e..ddfc7a1 100644
--- a/namos/common/exception.py
+++ b/namos/common/exception.py
@@ -125,3 +125,8 @@ class ServiceWorkerNotFound(NotFound):
125class ConfigNotFound(NotFound): 125class ConfigNotFound(NotFound):
126 msg_fmt = ("Config %(config_id)s does not found") 126 msg_fmt = ("Config %(config_id)s does not found")
127 error_code = 0x0a001 127 error_code = 0x0a001
128
129
130class ConfigFileNotFound(NotFound):
131 msg_fmt = ("Config file %(config_file_id)s does not found")
132 error_code = 0x0b001
diff --git a/namos/conductor/manager.py b/namos/conductor/manager.py
index 559a0bb..39b0ccb 100644
--- a/namos/conductor/manager.py
+++ b/namos/conductor/manager.py
@@ -184,6 +184,33 @@ class ServiceProcessor(object):
184 service_component) 184 service_component)
185 # TODO(mrkanag) what to do when service_components size is > 1 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 # Service Worker 214 # Service Worker
188 try: 215 try:
189 service_worker = db_api.service_worker_create( 216 service_worker = db_api.service_worker_create(
diff --git a/namos/db/api.py b/namos/db/api.py
index 39c8553..589e08f 100644
--- a/namos/db/api.py
+++ b/namos/db/api.py
@@ -344,6 +344,40 @@ def config_delete(context, _id):
344 return IMPL.config_delete(context, _id) 344 return IMPL.config_delete(context, _id)
345 345
346 346
347def config_file_create(context, values):
348 return IMPL.config_file_create(context, values)
349
350
351def config_file_update(context, _id, values):
352 return IMPL.config_file_update(context, _id, values)
353
354
355def config_file_get(context, _id):
356 return IMPL.config_file_get(context, _id)
357
358
359def config_file_get_by_name(context, name):
360 return IMPL.config_file_get_by_name(context, name)
361
362
363def 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
373def config_file_get_all(context):
374 return IMPL.config_file_get_all(context)
375
376
377def config_file_delete(context, _id):
378 return IMPL.config_file_delete(context, _id)
379
380
347def service_perspective_get(context, service_id, 381def service_perspective_get(context, service_id,
348 include_details=False): 382 include_details=False):
349 return IMPL.service_perspective_get(context, 383 return IMPL.service_perspective_get(context,
diff --git a/namos/db/sqlalchemy/alembic/versions/48ebec3cd6f6_initial_version.py b/namos/db/sqlalchemy/alembic/versions/48ebec3cd6f6_initial_version.py
index a9e5d39..2dc8f2d 100644
--- a/namos/db/sqlalchemy/alembic/versions/48ebec3cd6f6_initial_version.py
+++ b/namos/db/sqlalchemy/alembic/versions/48ebec3cd6f6_initial_version.py
@@ -177,6 +177,7 @@ def upgrade():
177 177
178 178
179def downgrade(): 179def downgrade():
180 op.drop_table('oslo_config_file')
180 op.drop_table('oslo_config') 181 op.drop_table('oslo_config')
181 op.drop_table('device_driver') 182 op.drop_table('device_driver')
182 op.drop_table('service_worker') 183 op.drop_table('service_worker')
diff --git a/namos/db/sqlalchemy/api.py b/namos/db/sqlalchemy/api.py
index d9a5ad8..baf7433 100644
--- a/namos/db/sqlalchemy/api.py
+++ b/namos/db/sqlalchemy/api.py
@@ -548,6 +548,55 @@ def config_delete(context, _id):
548 return _delete(context, models.OsloConfig, _id) 548 return _delete(context, models.OsloConfig, _id)
549 549
550 550
551# Config file
552def config_file_create(context, values):
553 return _create(context, models.OsloConfigFile(), values)
554
555
556def config_file_update(context, _id, values):
557 return _update(context, models.OsloConfigFile, _id, values)
558
559
560def 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
568def 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
576def 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
588def config_file_get_all(context):
589 return _get_all(context, models.OsloConfigFile)
590
591
592def _config_file_get_all_by(context, **kwargs):
593 return _get_all_by(context, models.OsloConfigFile, **kwargs)
594
595
596def config_file_delete(context, _id):
597 return _delete(context, models.OsloConfigFile, _id)
598
599
551# REST-API 600# REST-API
552def service_perspective_get(context, service_id, include_details=False): 601def service_perspective_get(context, service_id, include_details=False):
553 # 1. itr over Service Components and find name vs set of components 602 # 1. itr over Service Components and find name vs set of components
@@ -828,6 +877,18 @@ def view_360(context):
828 view['region'][rg.id]['service_node'][srv_nd.id][ 877 view['region'][rg.id]['service_node'][srv_nd.id][
829 'service_component'][srv_cmp.id] = dict() 878 'service_component'][srv_cmp.id] = dict()
830 view['region'][rg.id]['service_node'][srv_nd.id][ 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
891 view['region'][rg.id]['service_node'][srv_nd.id][
831 'service_component'][srv_cmp.id]['service'] = srv_id 892 'service_component'][srv_cmp.id]['service'] = srv_id
832 view['region'][rg.id]['service_node'][srv_nd.id][ 893 view['region'][rg.id]['service_node'][srv_nd.id][
833 'service_component'][srv_cmp.id][ 894 'service_component'][srv_cmp.id][
diff --git a/namos/db/sqlalchemy/models.py b/namos/db/sqlalchemy/models.py
index 7483dfe..267aa97 100644
--- a/namos/db/sqlalchemy/models.py
+++ b/namos/db/sqlalchemy/models.py
@@ -330,3 +330,27 @@ class OsloConfig(BASE,
330 sqlalchemy.ForeignKey('service_worker.id'), 330 sqlalchemy.ForeignKey('service_worker.id'),
331 nullable=False 331 nullable=False
332 ) 332 )
333
334
335class 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 )