X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDevice.java;h=94beaed0dfc61aeb0c5f260c24a1a689ec9fd7a1;hp=2ed941851bb71852f06d8d1c0aa7d921e44937bb;hb=74826747264952efec288fa37788a989458e364e;hpb=36c417d74537e04bd918212b4e7465d1f80d7eb6 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java index 2ed941851b..94beaed0df 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java @@ -21,6 +21,7 @@ import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.toF import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.toRpcMessage; import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.wrap; +import com.google.common.base.Preconditions; import java.io.InputStream; import java.net.InetSocketAddress; import java.net.URI; @@ -38,6 +39,9 @@ import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler; import org.opendaylight.controller.md.sal.common.api.data.DataModification; import org.opendaylight.controller.md.sal.common.api.data.DataReader; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration; +import org.opendaylight.controller.sal.binding.api.data.DataProviderService; import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration; import org.opendaylight.controller.sal.core.api.Provider; @@ -47,6 +51,8 @@ import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance; import org.opendaylight.controller.sal.core.api.mount.MountProvisionService; import org.opendaylight.protocol.framework.ReconnectStrategy; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.inventory.rev140108.NetconfNode; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -115,12 +121,14 @@ public class NetconfDevice implements Provider, // SchemaSourceProvider remoteSourceProvider; - DataBrokerService dataBroker; + private volatile DataBrokerService dataBroker; NetconfDeviceListener listener; private boolean rollbackSupported; + private NetconfReconnectingClientConfiguration clientConfig; + private volatile DataProviderService dataProviderService; public NetconfDevice(String name) { this.name = name; @@ -134,11 +142,12 @@ public class NetconfDevice implements Provider, // checkState(schemaSourceProvider != null, "Schema Source Provider must be set."); checkState(eventExecutor != null, "Event executor must be set."); - listener = new NetconfDeviceListener(this); + Preconditions.checkArgument(clientConfig.getSessionListener() instanceof NetconfDeviceListener); + listener = (NetconfDeviceListener) clientConfig.getSessionListener(); logger.info("Starting NETCONF Client {} for address {}", name, socketAddress); - dispatcher.createClient(socketAddress, listener, reconnectStrategy); + dispatcher.createReconnectingClient(clientConfig); } Optional getSchemaContext() { @@ -213,6 +222,8 @@ public class NetconfDevice implements Provider, // } private void updateDeviceState(boolean up, Set capabilities) { + checkDataStoreState(); + DataModificationTransaction transaction = dataBroker.beginTransaction(); CompositeNodeBuilder it = ImmutableCompositeNode.builder(); @@ -301,6 +312,22 @@ public class NetconfDevice implements Provider, // public void onSessionInitiated(ProviderSession session) { dataBroker = session.getService(DataBrokerService.class); + processingExecutor.submit(new Runnable() { + @Override + public void run() { + updateInitialState(); + } + }); + + mountService = session.getService(MountProvisionService.class); + if (mountService != null) { + mountInstance = mountService.createOrGetMountPoint(path); + } + } + + private void updateInitialState() { + checkDataStoreState(); + DataModificationTransaction transaction = dataBroker.beginTransaction(); if (operationalNodeNotExisting(transaction)) { transaction.putOperationalData(path, getNodeWithId()); @@ -316,13 +343,13 @@ public class NetconfDevice implements Provider, // } catch (ExecutionException e) { throw new RuntimeException("Read configuration data " + path + " failed", e); } - - mountService = session.getService(MountProvisionService.class); - if (mountService != null) { - mountInstance = mountService.createOrGetMountPoint(path); - } } + private void checkDataStoreState() { + // read data from Nodes/Node in order to wait with write until schema for Nodes/Node is present in datastore + dataProviderService.readOperationalData(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.builder( + Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class).augmentation(NetconfNode.class).build()); } + CompositeNode getNodeWithId() { SimpleNodeTOImpl id = new SimpleNodeTOImpl(INVENTORY_ID, null, name); return new CompositeNodeTOImpl(INVENTORY_NODE, null, Collections.> singletonList(id)); @@ -464,6 +491,14 @@ public class NetconfDevice implements Provider, // public void setDispatcher(final NetconfClientDispatcher dispatcher) { this.dispatcher = dispatcher; } + + public void setClientConfig(final NetconfReconnectingClientConfiguration clientConfig) { + this.clientConfig = clientConfig; + } + + public void setDataProviderService(final DataProviderService dataProviderService) { + this.dataProviderService = dataProviderService; + } } class NetconfDeviceSchemaContextProvider {