Integration with MDSAL Util
[vpnservice.git] / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / vpnservice / VpnserviceProvider.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice;
9
10 import java.util.Collections;
11
12 import org.opendaylight.bgpmanager.api.IBgpManager;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
16 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
17 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class VpnserviceProvider implements BindingAwareProvider,
22                                                        AutoCloseable {
23
24     private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class);
25     private VpnInterfaceManager vpnInterfaceManager;
26     private VpnManager vpnManager;
27     private IBgpManager bgpManager;
28     private IMdsalApiManager mdsalManager;
29     private IInterfaceManager interfaceManager;
30
31     @Override
32     public void onSessionInitiated(ProviderContext session) {
33         LOG.info("VpnserviceProvider Session Initiated");
34         try {
35             final  DataBroker dataBroker = session.getSALService(DataBroker.class);
36             vpnManager = new VpnManager(dataBroker, bgpManager);
37             vpnInterfaceManager = new VpnInterfaceManager(dataBroker, bgpManager);
38             vpnInterfaceManager.setMdsalManager(mdsalManager);
39         } catch (Exception e) {
40             LOG.error("Error initializing services", e);
41         }
42     }
43
44     public void setBgpManager(IBgpManager bgpManager) {
45         LOG.debug("BGP Manager reference initialized");
46         this.bgpManager = bgpManager;
47     }
48
49     public void setMdsalManager(IMdsalApiManager mdsalManager) {
50         this.mdsalManager = mdsalManager;
51     }
52
53     public void setInterfaceManager(IInterfaceManager interfaceManager) {
54         this.interfaceManager = interfaceManager;
55     }
56
57     @Override
58     public void close() throws Exception {
59         vpnManager.close();
60         vpnInterfaceManager.close();
61     }
62 }