TAPI Connectivity service RPCs impl
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / impl / TapiProvider.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.impl;
9
10 import java.util.HashMap;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.mdsal.binding.api.NotificationService;
15 import org.opendaylight.mdsal.binding.api.RpcProviderService;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.transportpce.common.InstanceIdentifiers;
18 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
19 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
20 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
21 import org.opendaylight.transportpce.tapi.connectivity.TapiConnectivityImpl;
22 import org.opendaylight.transportpce.tapi.listeners.TapiPceListenerImpl;
23 import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl;
24 import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl;
25 import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener;
26 import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener;
27 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
28 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
29 import org.opendaylight.transportpce.tapi.utils.TapiContext;
30 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
31 import org.opendaylight.transportpce.tapi.utils.TapiListener;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceListener;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.Network;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.Nodes;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.TransportpceRendererListener;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
43 import org.opendaylight.yangtools.concepts.ListenerRegistration;
44 import org.opendaylight.yangtools.concepts.ObjectRegistration;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49 /**
50  * Class to register TAPI interface Service and Notification.
51  *
52  * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
53  *
54  */
55 public class TapiProvider {
56
57     private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
58
59     private static final InstanceIdentifier<Nodes> MAPPING_II = InstanceIdentifier.create(Network.class)
60         .child(org.opendaylight.yang.gen.v1.http
61             .org.opendaylight.transportpce.portmapping.rev210315.network.Nodes.class);
62     private final DataBroker dataBroker;
63     private final RpcProviderService rpcProviderService;
64     private ObjectRegistration<TapiConnectivityService> rpcRegistration;
65     private ObjectRegistration<TransportpceTapinetworkutilsService> tapiNetworkutilsServiceRpcRegistration;
66     private ListenerRegistration<TapiNetconfTopologyListener> dataTreeChangeListenerRegistration;
67     private ListenerRegistration<TapiPortMappingListener> mappingListenerListenerRegistration;
68     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
69     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
70     private ListenerRegistration<TransportpceServicehandlerListener> servicehandlerlistenerRegistration;
71     private final OrgOpenroadmServiceService serviceHandler;
72     private final ServiceDataStoreOperations serviceDataStoreOperations;
73     private final TapiListener tapiListener;
74     private final TapiNetconfTopologyListener topologyListener;
75     private TapiPortMappingListener tapiPortMappingListener;
76     private final NetworkTransactionService networkTransactionService;
77     private final TransportpceTapinetworkutilsService tapiNetworkUtils;
78     private TapiPceListenerImpl pceListenerImpl;
79     private TapiRendererListenerImpl rendererListenerImpl;
80     private TapiServiceHandlerListenerImpl serviceHandlerListenerImpl;
81     private final NotificationService notificationService;
82
83     public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
84             OrgOpenroadmServiceService serviceHandler, ServiceDataStoreOperations serviceDataStoreOperations,
85             TapiListener tapiListener, NetworkTransactionService networkTransactionService,
86             TapiNetconfTopologyListener topologyListener, TapiPortMappingListener tapiPortMappingListener,
87             TransportpceTapinetworkutilsService tapiNetworkUtils, TapiPceListenerImpl pceListenerImpl,
88             TapiRendererListenerImpl rendererListenerImpl, TapiServiceHandlerListenerImpl serviceHandlerListenerImpl,
89             NotificationService notificationService) {
90         this.dataBroker = dataBroker;
91         this.rpcProviderService = rpcProviderService;
92         this.serviceHandler = serviceHandler;
93         this.serviceDataStoreOperations = serviceDataStoreOperations;
94         this.tapiListener = tapiListener;
95         this.networkTransactionService = networkTransactionService;
96         this.topologyListener = topologyListener;
97         this.tapiPortMappingListener = tapiPortMappingListener;
98         this.tapiNetworkUtils = tapiNetworkUtils;
99         this.pceListenerImpl = pceListenerImpl;
100         this.rendererListenerImpl = rendererListenerImpl;
101         this.serviceHandlerListenerImpl = serviceHandlerListenerImpl;
102         this.notificationService = notificationService;
103     }
104
105     /**
106      * Method called when the blueprint container is created.
107      */
108     public void init() {
109         LOG.info("TapiProvider Session Initiated");
110         TapiContext tapiContext = new TapiContext(this.networkTransactionService);
111         LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
112
113         TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker);
114         ConnectivityUtils connectivityUtils = new ConnectivityUtils(this.serviceDataStoreOperations, new HashMap<>(),
115                 tapiContext);
116         TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
117                 tapiContext, this.serviceDataStoreOperations);
118         tapiInitialORMapping.performTopoInitialMapping();
119         tapiInitialORMapping.performServInitialMapping();
120
121         TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler, tapiContext, connectivityUtils,
122                 pceListenerImpl, rendererListenerImpl, serviceHandlerListenerImpl);
123         TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils);
124         rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
125         rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
126         dataTreeChangeListenerRegistration =
127             dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
128                 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
129         mappingListenerListenerRegistration =
130             dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
131                 MAPPING_II), tapiPortMappingListener);
132         tapiNetworkutilsServiceRpcRegistration =
133                 rpcProviderService.registerRpcImplementation(TransportpceTapinetworkutilsService.class,
134                         this.tapiNetworkUtils);
135         @NonNull
136         InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
137         dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
138             LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
139         // Notification Listener
140         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
141         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
142         servicehandlerlistenerRegistration =
143                 notificationService.registerNotificationListener(serviceHandlerListenerImpl);
144     }
145
146     /**
147      * Method called when the blueprint container is destroyed.
148      */
149     public void close() {
150         LOG.info("TapiProvider Session Closed");
151         if (dataTreeChangeListenerRegistration != null) {
152             dataTreeChangeListenerRegistration.close();
153         }
154         if (mappingListenerListenerRegistration != null) {
155             mappingListenerListenerRegistration.close();
156         }
157         if (tapiNetworkutilsServiceRpcRegistration != null) {
158             tapiNetworkutilsServiceRpcRegistration.close();
159         }
160         pcelistenerRegistration.close();
161         rendererlistenerRegistration.close();
162         servicehandlerlistenerRegistration.close();
163         rpcRegistration.close();
164     }
165 }