Support control plane recovery from failure for kubevirt networking

Change-Id: I8ac901cde85321f20b95f0d144a21d1a69d8026b
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
index 93a3504..bae08bc 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
@@ -293,35 +293,39 @@
                                 IpAddress.valueOf(start), IpAddress.valueOf(end)));
                     }
 
-                    JSONArray routesJson = configJson.getJSONArray(HOST_ROUTES);
-                    Set<KubevirtHostRoute> hostRoutes = new HashSet<>();
-                    if (routesJson != null) {
-                        for (int i = 0; i < routesJson.length(); i++) {
-                            JSONObject route = routesJson.getJSONObject(i);
-                            String destinationStr = route.getString(DESTINATION);
-                            String nexthopStr = route.getString(NEXTHOP);
+                    if (configJson.has(HOST_ROUTES)) {
+                        JSONArray routesJson = configJson.getJSONArray(HOST_ROUTES);
+                        Set<KubevirtHostRoute> hostRoutes = new HashSet<>();
+                        if (routesJson != null) {
+                            for (int i = 0; i < routesJson.length(); i++) {
+                                JSONObject route = routesJson.getJSONObject(i);
+                                String destinationStr = route.getString(DESTINATION);
+                                String nexthopStr = route.getString(NEXTHOP);
 
-                            if (StringUtils.isNotEmpty(destinationStr) &&
-                                    StringUtils.isNotEmpty(nexthopStr)) {
-                                hostRoutes.add(new KubevirtHostRoute(
-                                        IpPrefix.valueOf(destinationStr),
-                                        IpAddress.valueOf(nexthopStr)));
+                                if (StringUtils.isNotEmpty(destinationStr) &&
+                                        StringUtils.isNotEmpty(nexthopStr)) {
+                                    hostRoutes.add(new KubevirtHostRoute(
+                                            IpPrefix.valueOf(destinationStr),
+                                            IpAddress.valueOf(nexthopStr)));
+                                }
                             }
                         }
+                        builder.hostRoutes(hostRoutes);
                     }
-                    builder.hostRoutes(hostRoutes);
 
-                    JSONArray dnsesJson = configJson.getJSONArray(DNSES);
-                    Set<IpAddress> dnses = new HashSet<>();
-                    if (dnsesJson != null) {
-                        for (int i = 0; i < dnsesJson.length(); i++) {
-                             String dns = dnsesJson.getString(i);
-                             if (StringUtils.isNotEmpty(dns)) {
-                                 dnses.add(IpAddress.valueOf(dns));
-                             }
+                    if (configJson.has(DNSES)) {
+                        JSONArray dnsesJson = configJson.getJSONArray(DNSES);
+                        Set<IpAddress> dnses = new HashSet<>();
+                        if (dnsesJson != null) {
+                            for (int i = 0; i < dnsesJson.length(); i++) {
+                                String dns = dnsesJson.getString(i);
+                                if (StringUtils.isNotEmpty(dns)) {
+                                    dnses.add(IpAddress.valueOf(dns));
+                                }
+                            }
                         }
+                        builder.dnses(dnses);
                     }
-                    builder.dnses(dnses);
 
                     builder.networkId(name).name(name).type(Type.valueOf(type))
                             .mtu(mtu).gatewayIp(IpAddress.valueOf(gatewayIp)).cidr(cidr);