Move registration API to configuration
[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 List, 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
30 from o2ims.service.command import notify_handler, registration_handler
31 from o2ims.service.event import ocloud_event, resource_event, \
32     resource_pool_event, configuration_event
33
34 # if TYPE_CHECKING:
35 #     from . import unit_of_work
36
37
38 class InvalidResourceType(Exception):
39     pass
40
41
42 EVENT_HANDLERS = {
43     o2dms_events.NfDeploymentStateChanged: [
44         nfdeployment_handler.publish_nfdeployment_state_change
45     ],
46     # o2dms_events.NfDeploymentCreated: [
47     #     nfdeployment_handler.publish_nfdeployment_created],
48     # o2dms_events.NfDeploymentInstalled: [
49     #     nfdeployment_handler.publish_nfdeployment_installed],
50     # o2dms_events.NfDeploymentUninstalling: [
51     #     nfdeployment_handler.publish_nfdeployment_uninstalling],
52     # o2dms_events.NfDeploymentUninstalled: [
53     #     nfdeployment_handler.publish_nfdeployment_uninstalled]
54     events.OcloudChanged: [ocloud_event.notify_ocloud_update],
55     events.ResourceChanged: [resource_event.notify_resource_change],
56     events.ResourcePoolChanged: [resource_pool_event.\
57                                  notify_resourcepool_change],
58     events.ConfigurationChanged: [configuration_event.\
59                                   notify_configuration_change],
60 }  # type: Dict[Type[events.Event], Callable]
61
62
63 COMMAND_HANDLERS = {
64     commands.UpdateOCloud: ocloud_handler.update_ocloud,
65     commands.UpdateDms: dms_handler.update_dms,
66     commands.UpdateResourcePool: resourcepool_handler.update_resourcepool,
67     commands.UpdatePserver: pserver_handler.update_pserver,
68     commands.UpdatePserverCpu: pserver_cpu_handler.update_pserver_cpu,
69     commands.UpdatePserverMem: pserver_mem_handler.update_pserver_mem,
70     commands.UpdatePserverIf: pserver_if_handler.update_pserver_if,
71     commands.UpdatePserverIfPort: pserver_port_handler.update_pserver_port,
72     commands.UpdatePserverEth: pserver_eth_handler.update_pserver_eth,
73     o2dms_cmmands.HandleNfDeploymentStateChanged:
74     nfdeployment_handler.handle_nfdeployment_statechanged,
75     o2dms_cmmands.InstallNfDeployment:
76     nfdeployment_handler.install_nfdeployment,
77     o2dms_cmmands.UninstallNfDeployment:
78     nfdeployment_handler.uninstall_nfdeployment,
79     o2dms_cmmands.DeleteNfDeployment:
80     nfdeployment_handler.delete_nfdeployment,
81     commands.PubMessage2SMO: notify_handler.notify_change_to_smo,
82     commands.Register2SMO: registration_handler.registry_to_smo,
83 }  # type: Dict[Type[commands.Command], Callable]