Changes default HA status to false in OpenstackNetworking App.

Change-Id: Iaf34f97f90eb25cd6a8b2660e07e3390ca35c989
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
index 891b1ee..4110ac8 100644
--- a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/Constants.java
@@ -16,6 +16,7 @@
 package org.onosproject.openstacknetworking.api;
 
 import com.google.common.collect.ImmutableMap;
+import org.onlab.packet.IpAddress;
 import org.onlab.packet.MacAddress;
 
 import java.nio.charset.StandardCharsets;
@@ -143,4 +144,7 @@
         //Additional pci vendor information will be added
         return ImmutableMap.of(CAVIUM_PCI_VENDOR_INFO, PORT_NAME_PREFIX_CAVIUM);
     }
-}
\ No newline at end of file
+
+    public static final boolean DEFAULT_HA_STATUS = false;
+    public static final IpAddress DEFAULT_ACTIVE_IP_ADDRESS = IpAddress.valueOf("127.0.0.1");
+}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackHaManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackHaManager.java
index 7aed8c3..c5be523 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackHaManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackHaManager.java
@@ -26,6 +26,8 @@
 import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.slf4j.Logger;
 
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_HA_STATUS;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -39,9 +41,6 @@
 
     protected final Logger log = getLogger(getClass());
 
-    private static final boolean DEFAULT_ACTIVE_STATUS = true;
-    private static final IpAddress DEFAULT_ACTIVE_IP_ADDRESS = IpAddress.valueOf("127.0.0.1");
-
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected CoreService coreService;
 
@@ -51,7 +50,7 @@
     @Activate
     protected void activate() {
         coreService.registerApplication(Constants.OPENSTACK_NETWORKING_APP_ID);
-        activeFlag = DEFAULT_ACTIVE_STATUS;
+        activeFlag = DEFAULT_HA_STATUS;
         activeIpAddress = DEFAULT_ACTIVE_IP_ADDRESS;
         log.info("Started");
     }
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
index 68d0f64..d7fa91b 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
@@ -753,7 +753,7 @@
                     routerIfaceAdded(osRouter, iface);
                 });
             });
-            log.info("Reconfigure routers for {}", osNode.hostname());
+            log.debug("Reconfigure routers for {}", osNode.hostname());
         }
     }
 }
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
index 0406dea..d835cca 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
@@ -1501,7 +1501,7 @@
 
                 setStatefulDownstreamRules(osRouter, true);
             });
-            log.info("Reconfigure routers for {}", osNode.hostname());
+            log.debug("Reconfigure routers for {}", osNode.hostname());
         }
     }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingIcmpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingIcmpHandler.java
index e475b8d..b75e5fa 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingIcmpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingIcmpHandler.java
@@ -383,7 +383,7 @@
                 });
                 processRouteGatewayEvent(osRouter, true);
             });
-            log.info("Reconfigure routers for {}", osNode.hostname());
+            log.debug("Reconfigure routers for {}", osNode.hostname());
         }
     }
 }
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java
index 33a0fa6..ed8d465 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackFloatingIpWebResource.java
@@ -42,6 +42,7 @@
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
 import static javax.ws.rs.core.Response.status;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -82,7 +83,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, FLOATING_IPS, inputStr);
         }
 
@@ -117,7 +119,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, FLOATING_IPS, id, inputStr);
         }
 
@@ -141,7 +144,8 @@
     public Response deleteFloatingIp(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE, "DELETE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, FLOATING_IPS, id);
         }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java
index 208af92..b603315 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackNetworkWebResource.java
@@ -41,6 +41,7 @@
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
 import static javax.ws.rs.core.Response.status;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -81,7 +82,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, NETWORKS, inputStr);
         }
 
@@ -116,7 +118,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, NETWORKS, id, inputStr);
         }
 
@@ -141,7 +144,8 @@
     public Response deleteNetwork(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE, "DELETE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, NETWORKS, id);
         }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java
index c5b9b6e..3d69a47 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackPortWebResource.java
@@ -46,6 +46,7 @@
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
 import static javax.ws.rs.core.Response.status;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -90,7 +91,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, PORTS, inputStr);
         }
 
@@ -124,7 +126,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, PORTS, id, inputStr);
         }
 
@@ -166,7 +169,8 @@
     public Response deletePorts(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE, "DELETE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, PORTS, id);
         }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackRouterWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackRouterWebResource.java
index bdd4b60..fde4f66 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackRouterWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackRouterWebResource.java
@@ -42,6 +42,7 @@
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
 import static javax.ws.rs.core.Response.status;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -84,7 +85,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, ROUTERS, inputStr);
         }
 
@@ -119,7 +121,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, ROUTERS, id, inputStr);
         }
 
@@ -151,7 +154,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, ROUTERS, "add_router_interface", id, inputStr);
         }
 
@@ -182,7 +186,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, ROUTERS, "remove_router_interface", id, inputStr);
         }
 
@@ -206,7 +211,8 @@
     public Response deleteRouter(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE_ROUTER, "DELETE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, ROUTERS, id);
         }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupRuleWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupRuleWebResource.java
index 895d353..73f88b2 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupRuleWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupRuleWebResource.java
@@ -39,6 +39,7 @@
 
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -78,7 +79,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, SECURITY_GROUP_RULES, inputStr);
         }
 
@@ -106,7 +108,8 @@
     public Response deleteSecurityGroupRule(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE, "REMOVE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, SECURITY_GROUP_RULES, id);
         }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupWebResource.java
index 3c9c2b4..615ae51 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSecurityGroupWebResource.java
@@ -40,6 +40,7 @@
 
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -79,7 +80,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, SECURITY_GROUPS, inputStr);
         }
 
@@ -126,7 +128,8 @@
     public Response removeSecurityGroup(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE, "REMOVE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, SECURITY_GROUPS, id);
         }
 
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java
index 3f20c09..5e49999 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/web/OpenstackSubnetWebResource.java
@@ -41,6 +41,7 @@
 import static javax.ws.rs.core.Response.created;
 import static javax.ws.rs.core.Response.noContent;
 import static javax.ws.rs.core.Response.status;
+import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
 import static org.onosproject.openstacknetworking.api.Constants.REST_UTF8;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.jsonToModelEntity;
 import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.syncDelete;
@@ -81,7 +82,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPost(haService, SUBNETS, inputStr);
         }
 
@@ -116,7 +118,8 @@
 
         String inputStr = IOUtils.toString(input, REST_UTF8);
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncPut(haService, SUBNETS, id, inputStr);
         }
 
@@ -141,7 +144,8 @@
     public Response deleteSubnet(@PathParam("id") String id) {
         log.trace(String.format(MESSAGE, "DELETE " + id));
 
-        if (!haService.isActive()) {
+        if (!haService.isActive()
+                && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
             return syncDelete(haService, SUBNETS, id);
         }
 
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
index 5424f6f..61e2fac 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
@@ -259,6 +259,8 @@
         osNodeService.nodes().stream()
                 .filter(n -> n.state() != COMPLETE)
                 .forEach(n -> {
+                    log.info("Node {} isn't COMPLETE state so performs initialization again.",
+                            n.hostname());
                     OpenstackNode updated = n.updateState(NodeState.INIT);
                     osNodeAdminService.updateNode(updated);
                 });