Support mTLS (Mutual TLS) with O2 API
[pti/o2.git] / o2app / service / handlers.py
1 # Copyright (C) 2021 Wind River Systems, Inc.
2 #
3 #  Licensed under the Apache License, Version 2.0 (the "License");
4 #  you may not use this file except in compliance with the License.
5 #  You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS,
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #  See the License for the specific language governing permissions and
13 #  limitations under the License.
14
15 # pylint: disable=unused-argument
16 from __future__ import annotations
17
18 from o2dms.service import nfdeployment_handler
19 # from dataclasses import asdict
20 from typing import Dict, Callable, Type
21 # TYPE_CHECKING
22 from o2ims.domain import commands, events
23
24 from o2dms.domain import commands as o2dms_cmmands
25 from o2dms.domain import events as o2dms_events
26 from o2ims.service.auditor import ocloud_handler, dms_handler, \
27     resourcepool_handler, pserver_handler, pserver_cpu_handler, \
28     pserver_mem_handler, pserver_port_handler, pserver_if_handler,\
29     pserver_eth_handler, pserver_acc_handler, alarm_handler, \
30     pserver_dev_handler, agg_compute_handler, agg_network_handler,\
31     agg_storage_handler, agg_undefined_handler
32 from o2ims.service.command import notify_handler, registration_handler,\
33     notify_alarm_handler
34 from o2ims.service.event import ocloud_event, resource_event, \
35     resource_pool_event, alarm_event, dms_event, resource_type_event
36
37 # if TYPE_CHECKING:
38 #     from . import unit_of_work
39
40
41 class InvalidResourceType(Exception):
42     pass
43
44
45 EVENT_HANDLERS = {
46     o2dms_events.NfDeploymentStateChanged: [
47         nfdeployment_handler.publish_nfdeployment_state_change
48     ],
49     # o2dms_events.NfDeploymentCreated: [
50     #     nfdeployment_handler.publish_nfdeployment_created],
51     # o2dms_events.NfDeploymentInstalled: [
52     #     nfdeployment_handler.publish_nfdeployment_installed],
53     # o2dms_events.NfDeploymentUninstalling: [
54     #     nfdeployment_handler.publish_nfdeployment_uninstalling],
55     # o2dms_events.NfDeploymentUninstalled: [
56     #     nfdeployment_handler.publish_nfdeployment_uninstalled]
57     events.OcloudChanged: [ocloud_event.notify_ocloud_update],
58     events.ResourceTypeChanged: [resource_type_event.\
59                                  notify_resourcetype_change],
60     events.DmsChanged: [dms_event.notify_dms_change],
61     events.ResourceChanged: [resource_event.notify_resource_change],
62     events.ResourcePoolChanged: [resource_pool_event.\
63                                  notify_resourcepool_change],
64     events.AlarmEventChanged: [alarm_event.\
65                                notify_alarm_event_change],
66 }  # type: Dict[Type[events.Event], Callable]
67
68
69 COMMAND_HANDLERS = {
70     commands.UpdateOCloud: ocloud_handler.update_ocloud,
71     commands.UpdateDms: dms_handler.update_dms,
72     commands.UpdateAlarm: alarm_handler.update_alarm,
73     commands.UpdateResourcePool: resourcepool_handler.update_resourcepool,
74     commands.UpdateComputeAgg: agg_compute_handler.update_compute_aggregate,
75     commands.UpdateNetworkAgg: agg_network_handler.update_network_aggregate,
76     commands.UpdateStorageAgg: agg_storage_handler.update_storage_aggregate,
77     commands.UpdateUndefinedAgg:
78     agg_undefined_handler.update_undefined_aggregate,
79     commands.UpdatePserver: pserver_handler.update_pserver,
80     commands.UpdatePserverCpu: pserver_cpu_handler.update_pserver_cpu,
81     commands.UpdatePserverMem: pserver_mem_handler.update_pserver_mem,
82     commands.UpdatePserverIf: pserver_if_handler.update_pserver_if,
83     commands.UpdatePserverIfPort: pserver_port_handler.update_pserver_port,
84     commands.UpdatePserverEth: pserver_eth_handler.update_pserver_eth,
85     commands.UpdatePserverDev: pserver_dev_handler.update_pserver_dev,
86     commands.UpdatePserverAcc: pserver_acc_handler.update_pserver_acc,
87     o2dms_cmmands.HandleNfDeploymentStateChanged:
88     nfdeployment_handler.handle_nfdeployment_statechanged,
89     o2dms_cmmands.InstallNfDeployment:
90     nfdeployment_handler.install_nfdeployment,
91     o2dms_cmmands.UninstallNfDeployment:
92     nfdeployment_handler.uninstall_nfdeployment,
93     o2dms_cmmands.DeleteNfDeployment:
94     nfdeployment_handler.delete_nfdeployment,
95     commands.PubMessage2SMO: notify_handler.notify_change_to_smo,
96     commands.PubAlarm2SMO: notify_alarm_handler.notify_alarm_to_smo,
97     commands.Register2SMO: registration_handler.registry_to_smo,
98 }  # type: Dict[Type[commands.Command], Callable]