Merge "Set unable-to-connect(netconf node) if no sources are available"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / NetconfDevice.java
index b57a8912ccd1fe67875f6b6d37e571259b1c23f1..88dd0e55c596ca03e3b1c349ff2544aeeb22d18f 100644 (file)
@@ -176,6 +176,8 @@ public final class NetconfDevice implements RemoteDevice<NetconfSessionPreferenc
     }
 
     private void registerToBaseNetconfStream(final NetconfDeviceRpc deviceRpc, final NetconfDeviceCommunicator listener) {
+       // TODO check whether the model describing create subscription is present in schema
+        // Perhaps add a default schema context to support create-subscription if the model was not provided (same as what we do for base netconf operations in transformer)
        final CheckedFuture<DOMRpcResult, DOMRpcException> rpcResultListenableFuture =
                 deviceRpc.invokeRpc(NetconfMessageTransformUtil.toPath(NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME), NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT);
 
@@ -218,8 +220,9 @@ public final class NetconfDevice implements RemoteDevice<NetconfSessionPreferenc
         messageTransformer = new NetconfMessageTransformer(result);
 
         updateTransformer(messageTransformer);
-        notificationHandler.onRemoteSchemaUp(messageTransformer);
+        // salFacade.onDeviceConnected has to be called before the notification handler is initialized
         salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc);
+        notificationHandler.onRemoteSchemaUp(messageTransformer);
 
         logger.info("{}: Netconf connector initialized successfully", id);
     }
@@ -411,7 +414,9 @@ public final class NetconfDevice implements RemoteDevice<NetconfSessionPreferenc
 
             // If no more sources, fail
             if(requiredSources.isEmpty()) {
-                handleSalInitializationFailure(new IllegalStateException(id + ": No more sources for schema context"), listener);
+                final IllegalStateException cause = new IllegalStateException(id + ": No more sources for schema context");
+                handleSalInitializationFailure(cause, listener);
+                salFacade.onDeviceFailed(cause);
                 return;
             }