X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDevice.xtend;h=49d9757f421058cb05ffed90f81922f6509ff688;hb=1306d0ed4b53625a1ba83e6aa5d693cd12ce7001;hp=0171c1f9e312b5020f26ee4dec1d0b23a8f34cf2;hpb=a5df932662bbaec4caeee5478d3003615ed3566b;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend index 0171c1f9e3..49d9757f42 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend @@ -14,8 +14,16 @@ import org.opendaylight.yangtools.yang.common.QName import java.util.Collections import org.opendaylight.controller.netconf.client.NetconfClientDispatcher import org.opendaylight.yangtools.concepts.Registration +import org.opendaylight.controller.sal.core.api.Provider +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession +import org.opendaylight.controller.sal.core.api.mount.MountProvisionService +import static org.opendaylight.controller.sal.connect.netconf.InventoryUtils.*; +import org.opendaylight.controller.sal.core.api.data.DataBrokerService +import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction +import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl +import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl -class NetconfDevice implements DataReader, RpcImplementation { +class NetconfDevice implements Provider, DataReader, RpcImplementation, AutoCloseable { var NetconfClient client; @@ -23,25 +31,29 @@ class NetconfDevice implements DataReader, Rp var InetSocketAddress socketAddress; @Property - val MountProvisionInstance mountInstance; + var MountProvisionInstance mountInstance; @Property - val InstanceIdentifier path; - - Registration> operReaderReg - - Registration> confReaderReg - - public new(MountProvisionInstance mount,InstanceIdentifier path) { - _mountInstance = mount; - _path = path; + var InstanceIdentifier path; + + Registration> operReaderReg + + Registration> confReaderReg + + String name + + MountProvisionService mountService + + public new(String name) { + this.name = name; + this.path = InstanceIdentifier.builder(INVENTORY_PATH).nodeWithKey(INVENTORY_NODE, + Collections.singletonMap(INVENTORY_ID, name)).toInstance; } def start(NetconfClientDispatcher dispatcher) { - client = new NetconfClient("sal-netconf-connector", socketAddress, dispatcher); - - confReaderReg = mountInstance.registerConfigurationReader(path,this); - operReaderReg = mountInstance.registerOperationalReader(path,this); + client = new NetconfClient(name, socketAddress, dispatcher); + confReaderReg = mountInstance.registerConfigurationReader(path, this); + operReaderReg = mountInstance.registerOperationalReader(path, this); } override readConfigurationData(InstanceIdentifier path) { @@ -66,6 +78,40 @@ class NetconfDevice implements DataReader, Rp return result.toRpcResult(); } + override getProviderFunctionality() { + Collections.emptySet + } + + override onSessionInitiated(ProviderSession session) { + val dataBroker = session.getService(DataBrokerService); + + + + val transaction = dataBroker.beginTransaction + if(transaction.operationalNodeNotExisting) { + transaction.putOperationalData(path,nodeWithId) + } + if(transaction.configurationNodeNotExisting) { + transaction.putConfigurationData(path,nodeWithId) + } + transaction.commit().get(); + mountService = session.getService(MountProvisionService); + mountInstance = mountService.createOrGetMountPoint(path); + } + + def getNodeWithId() { + val id = new SimpleNodeTOImpl(INVENTORY_ID,null,name); + return new CompositeNodeTOImpl(INVENTORY_NODE,null,Collections.singletonList(id)); + } + + def boolean configurationNodeNotExisting(DataModificationTransaction transaction) { + return null === transaction.readConfigurationData(path); + } + + def boolean operationalNodeNotExisting(DataModificationTransaction transaction) { + return null === transaction.readOperationalData(path); + } + def Node findNode(CompositeNode node, InstanceIdentifier identifier) { var Node current = node; @@ -86,10 +132,11 @@ class NetconfDevice implements DataReader, Rp } return current; } - - public def stop() { + + override close() { confReaderReg?.close() operReaderReg?.close() + client?.close() } }