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