Initial OR-TAPI mapping: Topology
[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 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.RpcProviderService;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
16 import org.opendaylight.transportpce.tapi.connectivity.TapiConnectivityImpl;
17 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
18 import org.opendaylight.transportpce.tapi.topology.TopologyUtils;
19 import org.opendaylight.transportpce.tapi.utils.TapiContext;
20 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
21 import org.opendaylight.transportpce.tapi.utils.TapiListener;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
23 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
24 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
26 import org.opendaylight.yangtools.concepts.ObjectRegistration;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * Class to register TAPI interface Service and Notification.
33  *
34  * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
35  *
36  */
37 public class TapiProvider {
38
39     private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
40
41     private final DataBroker dataBroker;
42     private final RpcProviderService rpcProviderService;
43     private ObjectRegistration<TapiConnectivityService> rpcRegistration;
44     private final OrgOpenroadmServiceService serviceHandler;
45     private final TapiListener tapiListener;
46     private final NetworkTransactionService networkTransactionService;
47
48     public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
49             OrgOpenroadmServiceService serviceHandler, TapiListener tapiListener,
50             NetworkTransactionService networkTransactionService) {
51         this.dataBroker = dataBroker;
52         this.rpcProviderService = rpcProviderService;
53         this.serviceHandler = serviceHandler;
54         this.tapiListener = tapiListener;
55         this.networkTransactionService = networkTransactionService;
56     }
57
58     /**
59      * Method called when the blueprint container is created.
60      */
61     public void init() {
62         LOG.info("TapiProvider Session Initiated");
63         TapiContext tapiContext = new TapiContext(this.networkTransactionService);
64         LOG.info("Empty TAPI context created: {}", tapiContext.getTapiContext());
65
66         TopologyUtils topologyUtils = new TopologyUtils(this.networkTransactionService, this.dataBroker);
67         TapiInitialORMapping tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, tapiContext);
68         tapiInitialORMapping.performTopoInitialMapping();
69
70         TapiConnectivityImpl tapi = new TapiConnectivityImpl(this.serviceHandler);
71         TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker, tapiContext, topologyUtils);
72         rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
73         rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
74         @NonNull
75         InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
76         dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
77             LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
78     }
79
80     /**
81      * Method called when the blueprint container is destroyed.
82      */
83     public void close() {
84         LOG.info("TapiProvider Session Closed");
85         rpcRegistration.close();
86     }
87 }