exchanging new version yang models on firmware upgrade
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / rpc / CreateSubscription.java
index ebb2074..a5ac333 100644 (file)
@@ -18,9 +18,6 @@
 \r
 package org.commscope.tr069adapter.netconf.rpc;\r
 \r
-import com.google.common.base.Preconditions;\r
-import com.google.common.collect.Maps;\r
-\r
 import java.io.File;\r
 import java.io.IOException;\r
 import java.text.SimpleDateFormat;\r
@@ -34,12 +31,11 @@ import java.util.Optional;
 import java.util.concurrent.Executors;\r
 import java.util.concurrent.ScheduledExecutorService;\r
 import java.util.concurrent.TimeUnit;\r
-\r
 import javax.xml.bind.JAXBContext;\r
 import javax.xml.bind.JAXBException;\r
 import javax.xml.bind.Unmarshaller;\r
 import javax.xml.bind.annotation.XmlRootElement;\r
-\r
+import org.commscope.tr069adapter.netconf.error.NetconfNotificationException;\r
 import org.opendaylight.netconf.api.NetconfMessage;\r
 import org.opendaylight.netconf.api.xml.XmlElement;\r
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;\r
@@ -52,6 +48,8 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
 import org.xml.sax.SAXException;\r
+import com.google.common.base.Preconditions;\r
+import com.google.common.collect.Maps;\r
 \r
 public class CreateSubscription extends AbstractLastNetconfOperation\r
     implements DefaultNetconfOperation {\r
@@ -163,17 +161,26 @@ public class CreateSubscription extends AbstractLastNetconfOperation
     netconfServerSessionMap.put(deviceID, newSession);\r
   }\r
 \r
-  public static void sendNotification(NetconfMessage netconfMessage, String deviceID) {\r
+  public static void sendNotification(NetconfMessage netconfMessage, String deviceID)\r
+      throws NetconfNotificationException {\r
     logger.debug("Request to send notification. NetConfMessage : {}", netconfMessage);\r
     NetconfServerSession session = netconfServerSessionMap.get(deviceID);\r
     if (session != null && session.isUp()) {\r
-      session.sendMessage(netconfMessage);\r
-      logger.debug("Successfully send notification for deviceID: {}", deviceID);\r
+      try {\r
+        session.sendMessage(netconfMessage);\r
+        logger.debug("Successfully send notification for deviceID: {}", deviceID);\r
+      } catch (Exception e) {\r
+        logger.error("Failed to send notification. while posting got error. {}", e.toString());\r
+        throw new NetconfNotificationException("Exception while posting the netconf message", e);\r
+      }\r
+\r
     } else {\r
-      logger.debug("Failed to send notification. None of valid netconf session is available.");\r
+      logger.debug(\r
+          "Failed to send notification. None of valid netconf session is available for {}.",\r
+          deviceID);\r
+      logger.debug("Available netconf sessions : {}", netconfServerSessionMap);\r
+      throw new NetconfNotificationException("NetConf active session deosn't not exist");\r
     }\r
-    logger.debug("Available netconf sessions : {}", netconfServerSessionMap);\r
-\r
   }\r
 \r
   @XmlRootElement(name = "notifications")\r