Update project version for Chlorine release train
[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.NetworkUtils;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
20 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
21 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
22 import org.opendaylight.transportpce.tapi.connectivity.TapiConnectivityImpl;
23 import org.opendaylight.transportpce.tapi.listeners.TapiNetworkModelListenerImpl;
24 import org.opendaylight.transportpce.tapi.listeners.TapiPceListenerImpl;
25 import org.opendaylight.transportpce.tapi.listeners.TapiRendererListenerImpl;
26 import org.opendaylight.transportpce.tapi.listeners.TapiServiceHandlerListenerImpl;
27 import org.opendaylight.transportpce.tapi.topology.TapiNetconfTopologyListener;
28 import org.opendaylight.transportpce.tapi.topology.TapiOrLinkListener;
29 import org.opendaylight.transportpce.tapi.topology.TapiPortMappingListener;
30 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
31 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
32 import org.opendaylight.transportpce.tapi.utils.TapiContext;
33 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
34 import org.opendaylight.transportpce.tapi.utils.TapiLink;
35 import org.opendaylight.transportpce.tapi.utils.TapiListener;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.TransportpcePceListener;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererListener;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.tapinetworkutils.rev210408.TransportpceTapinetworkutilsService;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.OrgOpenroadmServiceService;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TapiCommonService;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
53 import org.opendaylight.yangtools.concepts.ListenerRegistration;
54 import org.opendaylight.yangtools.concepts.ObjectRegistration;
55 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 /**
60  * Class to register TAPI interface Service and Notification.
61  *
62  * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
63  *
64  */
65 public class TapiProvider {
66
67     private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
68
69     private static final InstanceIdentifier<Nodes> MAPPING_II = InstanceIdentifier.create(Network.class)
70         .child(org.opendaylight.yang.gen.v1.http
71             .org.opendaylight.transportpce.portmapping.rev220316.network.Nodes.class);
72     private static final InstanceIdentifier<Link> LINK_II = InstanceIdentifier.create(Networks.class).child(
73         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network.class,
74             new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))).augmentation(Network1.class)
75         .child(Link.class);
76     private final DataBroker dataBroker;
77     private final RpcProviderService rpcProviderService;
78     private ObjectRegistration<TapiConnectivityService> rpcRegistration;
79     private ObjectRegistration<TransportpceTapinetworkutilsService> tapiNetworkutilsServiceRpcRegistration;
80     private ListenerRegistration<TapiNetconfTopologyListener> dataTreeChangeListenerRegistration;
81     private ListenerRegistration<TapiOrLinkListener> dataTreeChangeListenerRegistration1;
82     private ListenerRegistration<TapiPortMappingListener> mappingListenerListenerRegistration;
83     private ListenerRegistration<TransportpcePceListener> pcelistenerRegistration;
84     private ListenerRegistration<TransportpceRendererListener> rendererlistenerRegistration;
85     private ListenerRegistration<TransportpceServicehandlerListener> servicehandlerlistenerRegistration;
86     private ListenerRegistration<TapiNetworkModelListenerImpl> tapinetworkmodellistenerRegistration;
87     private final OrgOpenroadmServiceService serviceHandler;
88     private final ServiceDataStoreOperations serviceDataStoreOperations;
89     private final TapiListener tapiListener;
90     private final TapiNetconfTopologyListener topologyListener;
91     private final TapiOrLinkListener orLinkListener;
92     private TapiPortMappingListener tapiPortMappingListener;
93     private final NetworkTransactionService networkTransactionService;
94     private final TransportpceTapinetworkutilsService tapiNetworkUtils;
95     private TapiPceListenerImpl pceListenerImpl;
96     private TapiRendererListenerImpl rendererListenerImpl;
97     private TapiServiceHandlerListenerImpl serviceHandlerListenerImpl;
98     private final NotificationService notificationService;
99     private TapiNetworkModelListenerImpl tapiNetworkModelListenerImpl;
100
101     public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
102             OrgOpenroadmServiceService serviceHandler, ServiceDataStoreOperations serviceDataStoreOperations,
103             TapiListener tapiListener, NetworkTransactionService networkTransactionService,
104             TapiNetconfTopologyListener topologyListener, TapiPortMappingListener tapiPortMappingListener,
105             TransportpceTapinetworkutilsService tapiNetworkUtils, TapiPceListenerImpl pceListenerImpl,
106             TapiRendererListenerImpl rendererListenerImpl, TapiServiceHandlerListenerImpl serviceHandlerListenerImpl,
107             NotificationService notificationService, TapiOrLinkListener orLinkListener,
108                         TapiNetworkModelListenerImpl tapiNetworkModelListenerImpl) {
109         this.dataBroker = dataBroker;
110         this.rpcProviderService = rpcProviderService;
111         this.serviceHandler = serviceHandler;
112         this.serviceDataStoreOperations = serviceDataStoreOperations;
113         this.tapiListener = tapiListener;
114         this.networkTransactionService = networkTransactionService;
115         this.topologyListener = topologyListener;
116         this.tapiPortMappingListener = tapiPortMappingListener;
117         this.tapiNetworkUtils = tapiNetworkUtils;
118         this.pceListenerImpl = pceListenerImpl;
119         this.rendererListenerImpl = rendererListenerImpl;
120         this.serviceHandlerListenerImpl = serviceHandlerListenerImpl;
121         this.notificationService = notificationService;
122         this.orLinkListener = orLinkListener;
123         this.tapiNetworkModelListenerImpl = tapiNetworkModelListenerImpl;
124     }
125
126     /**
127      * Method called when the blueprint container is created.
128      */
129     public void init() {
130         LOG.info("TapiProvider Session Initiated");
131         TapiContext tapiContext = new TapiContext(this.networkTransactionService);
132         LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
133         TapiLink tapiLink = new TapiLink(this.networkTransactionService);
134         TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker, tapiLink);
135         ConnectivityUtils connectivityUtils = new ConnectivityUtils(this.serviceDataStoreOperations, new HashMap<>(),
136                 tapiContext, this.networkTransactionService);
137         TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
138                 tapiContext, this.serviceDataStoreOperations);
139         tapiInitialORMapping.performTopoInitialMapping();
140         tapiInitialORMapping.performServInitialMapping();
141
142         TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler, tapiContext, connectivityUtils,
143                 pceListenerImpl, rendererListenerImpl);
144         TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils, tapiLink);
145         rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
146         rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
147         rpcProviderService.registerRpcImplementation(TapiCommonService.class, topo);
148         dataTreeChangeListenerRegistration1 =
149             dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
150                 LINK_II), orLinkListener);
151         dataTreeChangeListenerRegistration =
152             dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
153                 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
154         mappingListenerListenerRegistration =
155             dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
156                 MAPPING_II), tapiPortMappingListener);
157         tapiNetworkutilsServiceRpcRegistration =
158                 rpcProviderService.registerRpcImplementation(TransportpceTapinetworkutilsService.class,
159                         this.tapiNetworkUtils);
160         @NonNull
161         InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
162         dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
163             LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
164         // Notification Listener
165         pcelistenerRegistration = notificationService.registerNotificationListener(pceListenerImpl);
166         rendererlistenerRegistration = notificationService.registerNotificationListener(rendererListenerImpl);
167         servicehandlerlistenerRegistration =
168                 notificationService.registerNotificationListener(serviceHandlerListenerImpl);
169         tapinetworkmodellistenerRegistration =
170                 notificationService.registerNotificationListener(tapiNetworkModelListenerImpl);
171     }
172
173     /**
174      * Method called when the blueprint container is destroyed.
175      */
176     public void close() {
177         LOG.info("TapiProvider Session Closed");
178         if (dataTreeChangeListenerRegistration != null) {
179             dataTreeChangeListenerRegistration.close();
180         }
181         if (mappingListenerListenerRegistration != null) {
182             mappingListenerListenerRegistration.close();
183         }
184         if (dataTreeChangeListenerRegistration1 != null) {
185             dataTreeChangeListenerRegistration1.close();
186         }
187         if (tapiNetworkutilsServiceRpcRegistration != null) {
188             tapiNetworkutilsServiceRpcRegistration.close();
189         }
190         pcelistenerRegistration.close();
191         rendererlistenerRegistration.close();
192         servicehandlerlistenerRegistration.close();
193         rpcRegistration.close();
194         tapinetworkmodellistenerRegistration.close();
195     }
196 }