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