Browse Source

view 360

Change-Id: Ibb645261bdc9af1a582ad4102c69340c49916d4e
Kanagaraj Manickam 3 years ago
parent
commit
eca5fb1b5c
4 changed files with 150 additions and 2 deletions
  1. 5
    0
      namos/conductor/manager.py
  2. 11
    2
      namos/conductor/rpcapi.py
  3. 4
    0
      namos/db/api.py
  4. 130
    0
      namos/db/sqlalchemy/api.py

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

@@ -106,6 +106,10 @@ class ConductorManager(object):
106 106
     def infra_perspective_get(self, context):
107 107
         return db_api.infra_perspective_get(context)
108 108
 
109
+    @request_context
110
+    def view_360(self, context):
111
+        return db_api.view_360(context)
112
+
109 113
     @request_context
110 114
     def config_get_by_name_for_service_worker(self,
111 115
                                               context,
@@ -117,6 +121,7 @@ class ConductorManager(object):
117 121
                                                             name,
118 122
                                                             only_configured)
119 123
 
124
+
120 125
 class ServiceProcessor(object):
121 126
     def __init__(self, registration_info):
122 127
         self.registration_info = registration_info

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

@@ -96,6 +96,11 @@ class ConductorAPI(object):
96 96
         return self.client.call(context,
97 97
                                 'infra_perspective_get')
98 98
 
99
+    @wrapper_function
100
+    def view_360(self, context):
101
+        return self.client.call(context,
102
+                                'view_360')
103
+
99 104
     @wrapper_function
100 105
     def config_get_by_name_for_service_worker(self,
101 106
                                               context,
@@ -128,10 +133,14 @@ if __name__ == '__main__':
128 133
     def print_infra():
129 134
         print (json.dumps(c.infra_perspective_get(context.RequestContext())))
130 135
 
136
+    def print_view_360():
137
+        print (json.dumps(c.view_360(context.RequestContext())))
138
+
131 139
     def print_sample_conf():
132 140
         for cf in c.config_get_by_name_for_service_worker(
133 141
             context.RequestContext(),
134
-            service_worker_id='fc88fd41-7e9c-42c9-891d-3823efd4824e'):
142
+            service_worker_id='06e64e74-09b3-4721-8e5d-39ae40ed34f3'):
135 143
             print ('%s %s' % (cf['name'], cf['value']))
136 144
 
137
-    print_sample_conf()
145
+    print_view_360()
146
+    # print_sample_conf()

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

@@ -367,3 +367,7 @@ def region_perspective_get(context, region_id,
367 367
 
368 368
 def infra_perspective_get(context):
369 369
     return IMPL.infra_perspective_get(context)
370
+
371
+
372
+def view_360(context):
373
+    return IMPL.view_360(context)

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

@@ -772,6 +772,133 @@ def infra_perspective_get(context):
772 772
 
773 773
     return infra_perspective
774 774
 
775
+
776
+def view_360(context):
777
+    view = dict()
778
+
779
+    view['region'] = dict()
780
+    view['service_node'] = dict()
781
+    view['service_component'] = dict()
782
+    view['service'] = dict()
783
+    view['service_worker'] = dict()
784
+    view['device_driver'] = dict()
785
+    view['device_driver_class'] = dict()
786
+    view['device_endpoint'] = dict()
787
+    view['device'] = dict()
788
+
789
+    region_list = region_get_all(context)
790
+    for rg in region_list:
791
+        # region
792
+        view['region'][rg.id] = region_get(context, rg.id).to_dict()
793
+
794
+        view['region'][rg.id]['service_node'] = dict()
795
+        srv_nd_lst = _service_node_get_all_by(context,
796
+                                              region_id=rg.id)
797
+        for srv_nd in srv_nd_lst:
798
+            # service node
799
+            view['service_node'][srv_nd.id] = service_node_get(
800
+                context,
801
+                srv_nd.id
802
+            ).to_dict()
803
+
804
+            view['region'][rg.id]['service_node'][srv_nd.id] = dict()
805
+            view['region'][rg.id]['service_node'][srv_nd.id][
806
+                'service_component'] = dict()
807
+            srv_cmp_lst = service_component_get_all_by_node_for_service(
808
+                context,
809
+                srv_nd.id
810
+            )
811
+            for srv_cmp in srv_cmp_lst:
812
+                # service component
813
+                view['service_component'][
814
+                    srv_cmp.id] = service_component_get(context,
815
+                                                        srv_cmp.id).to_dict()
816
+
817
+                # service
818
+                srv_id = view['service_component'][srv_cmp.id]['service_id']
819
+                if srv_id not in view['service']:
820
+                    view['service'][srv_id] = service_get(context,
821
+                                                          srv_id).to_dict()
822
+
823
+                view['region'][rg.id]['service_node'][srv_nd.id][
824
+                    'service_component'][srv_cmp.id] = dict()
825
+                view['region'][rg.id]['service_node'][srv_nd.id][
826
+                    'service_component'][srv_cmp.id]['service'] = srv_id
827
+                view['region'][rg.id]['service_node'][srv_nd.id][
828
+                    'service_component'][srv_cmp.id][
829
+                    'service_worker'] = dict()
830
+                srv_wkr_lst = service_worker_get_by_host_for_service_component(
831
+                    context,
832
+                    srv_cmp.id
833
+                )
834
+                for srv_wkr in srv_wkr_lst:
835
+                    # service worker
836
+                    view['service_worker'][
837
+                        srv_wkr.id] = service_worker_get(context,
838
+                                                         srv_wkr.id).to_dict()
839
+
840
+                    view['region'][rg.id]['service_node'][srv_nd.id][
841
+                        'service_component'][srv_cmp.id][
842
+                        'service_worker'][srv_wkr.id] = dict()
843
+                    view['region'][rg.id]['service_node'][srv_nd.id][
844
+                        'service_component'][srv_cmp.id][
845
+                        'service_worker'][srv_wkr.id]['device_driver'] = dict()
846
+                    dvc_drv_list = _device_driver_get_all_by(
847
+                        context,
848
+                        service_worker_id=srv_wkr.id
849
+                    )
850
+                    for dvc_drv in dvc_drv_list:
851
+                        # device driver
852
+                        view['device_driver'][
853
+                            dvc_drv.id] = device_driver_get(
854
+                            context,
855
+                            dvc_drv.id).to_dict()
856
+
857
+                        view['region'][rg.id]['service_node'][srv_nd.id][
858
+                            'service_component'][srv_cmp.id][
859
+                            'service_worker'][srv_wkr.id]['device_driver'][
860
+                            dvc_drv.id] = dict()
861
+
862
+                        # device driver class
863
+                        dvc_drv_cls_id = view['device_driver'][
864
+                            dvc_drv.id]['device_driver_class_id']
865
+                        if dvc_drv_cls_id not in view['device_driver_class']:
866
+                            view['device_driver_class'][
867
+                                dvc_drv_cls_id] = device_driver_class_get(
868
+                                context,
869
+                                dvc_drv_cls_id).to_dict()
870
+                        view['region'][rg.id]['service_node'][srv_nd.id][
871
+                            'service_component'][srv_cmp.id][
872
+                            'service_worker'][srv_wkr.id]['device_driver'][
873
+                            dvc_drv.id]['device_driver_class'] = dvc_drv_cls_id
874
+
875
+                        # device endpoint
876
+                        dvc_endp_id = view['device_driver'][
877
+                            dvc_drv.id]['endpoint_id']
878
+                        view['device_endpoint'][
879
+                            dvc_endp_id] = device_endpoint_get(
880
+                            context,
881
+                            dvc_endp_id).to_dict()
882
+                        view['region'][rg.id]['service_node'][srv_nd.id][
883
+                            'service_component'][srv_cmp.id][
884
+                            'service_worker'][srv_wkr.id]['device_driver'][
885
+                            dvc_drv.id]['device_endpoint'] = dvc_endp_id
886
+
887
+                        # device
888
+                        dvc_id = view['device_driver'][
889
+                            dvc_drv.id]['device_id']
890
+                        if dvc_id not in view['device']:
891
+                            view['device'][
892
+                                dvc_id] = device_get(
893
+                                context,
894
+                                dvc_id).to_dict()
895
+                            view['region'][rg.id]['service_node'][srv_nd.id][
896
+                                'service_component'][srv_cmp.id][
897
+                                'service_worker'][srv_wkr.id]['device_driver'][
898
+                                dvc_drv.id]['device'] = dvc_id
899
+
900
+    return view
901
+
775 902
 if __name__ == '__main__':
776 903
     from namos.common import config
777 904
 
@@ -796,3 +923,6 @@ if __name__ == '__main__':
796 923
     # import json
797 924
     # perp_json = json.dumps(persp, indent=4)
798 925
     # print perp_json
926
+
927
+    import json
928
+    print (json.dumps(view_360(None)))

Loading…
Cancel
Save