Remove networkmodel-blueprint.xml
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / NetworkModelProvider.java
1 /*
2  * Copyright © 2016 Orange 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.networkmodel;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.transportpce.common.InstanceIdentifiers;
17 import org.opendaylight.transportpce.common.NetworkUtils;
18 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
19 import org.opendaylight.transportpce.common.mapping.PortMapping;
20 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
21 import org.opendaylight.transportpce.networkmodel.listeners.PortMappingListener;
22 import org.opendaylight.transportpce.networkmodel.listeners.ServiceHandlerListener;
23 import org.opendaylight.transportpce.networkmodel.service.FrequenciesService;
24 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
25 import org.opendaylight.transportpce.networkmodel.util.TpceNetwork;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev220630.TransportpceNetworkutilsService;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.mapping.Mapping;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 import org.opendaylight.yangtools.concepts.Registration;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Deactivate;
37 import org.osgi.service.component.annotations.Reference;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 @Component
42 public class NetworkModelProvider {
43
44     private static final Logger LOG = LoggerFactory.getLogger(NetworkModelProvider.class);
45     private static final InstanceIdentifier<Mapping> MAPPING_II = InstanceIdentifier.create(Network.class)
46         .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.network
47                 .Nodes.class)
48         .child(Mapping.class);
49
50     private final DataBroker dataBroker;
51     private final RpcProviderService rpcProviderService;
52     private final TransportpceNetworkutilsService networkutilsService;
53     private final NetConfTopologyListener topologyListener;
54     private ListenerRegistration<NetConfTopologyListener> dataTreeChangeListenerRegistration;
55     private ListenerRegistration<PortMappingListener> mappingListenerRegistration;
56     private @NonNull Registration networkutilsServiceRpcRegistration;
57     private TpceNetwork tpceNetwork;
58     private ListenerRegistration<TransportpceServicehandlerListener> serviceHandlerListenerRegistration;
59     private NotificationService notificationService;
60     private FrequenciesService frequenciesService;
61     private PortMappingListener portMappingListener;
62
63     @Activate
64     public NetworkModelProvider(@Reference NetworkTransactionService networkTransactionService,
65             @Reference final DataBroker dataBroker,
66             @Reference final RpcProviderService rpcProviderService,
67             @Reference final NetworkModelService networkModelService,
68             @Reference DeviceTransactionManager deviceTransactionManager,
69             @Reference PortMapping portMapping,
70             @Reference NotificationService notificationService,
71             @Reference FrequenciesService frequenciesService) {
72         this.dataBroker = dataBroker;
73         this.rpcProviderService = rpcProviderService;
74         this.notificationService = notificationService;
75         this.frequenciesService = frequenciesService;
76         this.networkutilsService = new NetworkUtilsImpl(dataBroker);
77         this.topologyListener = new NetConfTopologyListener(networkModelService, dataBroker, deviceTransactionManager,
78             portMapping);
79         this.tpceNetwork = new TpceNetwork(networkTransactionService);
80         this.portMappingListener = new PortMappingListener(networkModelService);
81         this.init();
82     }
83
84     /**
85      * Method called when the blueprint container is created.
86      */
87     private void init() {
88         LOG.info("NetworkModelProvider Session Initiated");
89         tpceNetwork.createLayer(NetworkUtils.CLLI_NETWORK_ID);
90         tpceNetwork.createLayer(NetworkUtils.UNDERLAY_NETWORK_ID);
91         tpceNetwork.createLayer(NetworkUtils.OVERLAY_NETWORK_ID);
92         tpceNetwork.createLayer(NetworkUtils.OTN_NETWORK_ID);
93         dataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener(
94                 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
95                 InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), topologyListener);
96         mappingListenerRegistration = dataBroker.registerDataTreeChangeListener(
97                 DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, MAPPING_II), portMappingListener);
98         networkutilsServiceRpcRegistration = rpcProviderService
99             .registerRpcImplementation(TransportpceNetworkutilsService.class, networkutilsService);
100         TransportpceServicehandlerListener serviceHandlerListner = new ServiceHandlerListener(frequenciesService);
101         serviceHandlerListenerRegistration = notificationService.registerNotificationListener(serviceHandlerListner);
102     }
103
104         /**
105          * Method called when the blueprint container is destroyed.
106          */
107     @Deactivate
108     public void close() {
109         LOG.info("NetworkModelProvider Closed");
110         if (dataTreeChangeListenerRegistration != null) {
111             dataTreeChangeListenerRegistration.close();
112         }
113         if (mappingListenerRegistration != null) {
114             mappingListenerRegistration.close();
115         }
116         if (networkutilsServiceRpcRegistration != null) {
117             networkutilsServiceRpcRegistration.close();
118         }
119         serviceHandlerListenerRegistration.close();
120     }
121 }