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=7c4bf5facad6a3dd94b0f1bd6a73e301a7820143;hb=e59d772d406a22ad256695e4a23f469b256837fd;hp=0171c1f9e312b5020f26ee4dec1d0b23a8f34cf2;hpb=05d3c60109c1d0fc24f0f1ffa3e5aeed929e3c24;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..7c4bf5faca 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,24 @@ 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 +import org.opendaylight.protocol.framework.ReconnectStrategy +import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler +import org.opendaylight.controller.md.sal.common.api.data.DataModification -class NetconfDevice implements DataReader, RpcImplementation { +class NetconfDevice implements + Provider, // + DataReader, // + DataCommitHandler, // + RpcImplementation, // + AutoCloseable { var NetconfClient client; @@ -23,29 +39,37 @@ class NetconfDevice implements DataReader, Rp var InetSocketAddress socketAddress; @Property - val MountProvisionInstance mountInstance; + var MountProvisionInstance mountInstance; @Property - val InstanceIdentifier path; + var InstanceIdentifier path; + + @Property + var ReconnectStrategy strategy; + + Registration> operReaderReg + Registration> confReaderReg + Registration> commitHandlerReg - Registration> operReaderReg + val String name + MountProvisionService mountService - Registration> confReaderReg - public new(MountProvisionInstance mount,InstanceIdentifier path) { - _mountInstance = mount; - _path = path; + 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 = NetconfClient.clientFor(name, socketAddress, strategy, dispatcher); + confReaderReg = mountInstance.registerConfigurationReader(path, this); + operReaderReg = mountInstance.registerOperationalReader(path, this); + //commitHandlerReg = mountInstance.registerCommitHandler(path,this); } override readConfigurationData(InstanceIdentifier path) { - val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, path.toFilterStructure())); + val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, CONFIG_SOURCE_RUNNING, path.toFilterStructure())); val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME); return data?.findNode(path) as CompositeNode; } @@ -66,6 +90,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 +144,15 @@ class NetconfDevice implements DataReader, Rp } return current; } - - public def stop() { + + override requestCommit(DataModification modification) { + throw new UnsupportedOperationException("TODO: auto-generated method stub") + } + + override close() { confReaderReg?.close() operReaderReg?.close() + client?.close() } }