BUG-625: convert TopologyMapping
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / topology / TopologyProvider.xtend
1 /*
2  * Copyright (c) 2014 Cisco Systems, 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.controller.sal.compatibility.topology
9
10 import org.opendaylight.controller.sal.binding.api.data.DataProviderService
11 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
16 import org.opendaylight.yangtools.yang.binding.DataObject
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
19 import org.slf4j.LoggerFactory
20 import org.opendaylight.yangtools.concepts.ListenerRegistration
21 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener
22
23 class TopologyProvider implements AutoCloseable{
24     static val LOG = LoggerFactory.getLogger(TopologyProvider);
25     TopologyCommitHandler commitHandler
26     
27     @Property
28     IPluginOutTopologyService topologyPublisher;
29     
30     @Property
31     DataProviderService dataService;
32     
33     ListenerRegistration<DataChangeListener> listenerRegistration
34     
35     
36     def void start() {
37
38     }
39     def void startAdapter() {
40         if(dataService == null){
41             LOG.error("dataService not set");
42             return;
43         }
44         commitHandler = new TopologyCommitHandler(dataService,topologyPublisher);
45         val InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(NetworkTopology)
46             .child(Topology,new TopologyKey(new TopologyId("flow:1")))
47             .child(Link)
48             .toInstance();
49         listenerRegistration = dataService.registerDataChangeListener(path,commitHandler);
50         LOG.info("TopologyProvider started")
51     }
52     
53     override close() throws Exception {
54         listenerRegistration.close
55     }
56     
57     def setTopologyPublisher(IPluginOutTopologyService topologyPublisher) {
58         _topologyPublisher = topologyPublisher;
59         if(commitHandler != null){
60             commitHandler.setTopologyPublisher(topologyPublisher);
61         }
62     }
63     
64 }