cherry pick [ONOS-4986] [ONOS-4985] Json defect fix to master

Change-Id: Ia9ead1babf3de43e6f492f4f3b6f4d6b9377b042
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
index 4a0b3ac..c622f0e 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
@@ -509,7 +509,7 @@
             }
 
             if (existingBwValue != null) {
-                if (bwConstraintValue == 0 && bwConstraint != null) {
+                if (bwConstraint == null) {
                     bwConstraintValue = existingBwValue.bps();
                 }
                 //If bandwidth constraints not specified , take existing bandwidth for shared bandwidth calculation
@@ -526,6 +526,11 @@
         constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspSigType)));
         if (costConstraint != null) {
             constraints.add(costConstraint);
+        } else {
+            //Take cost constraint from old tunnel if it is not specified in update flow
+            costType = tunnel.annotations().value(COST_TYPE);
+            costConstraint = CostConstraint.of(CostConstraint.Type.valueOf(costType));
+            constraints.add(costConstraint);
         }
 
         computedPathSet = computePath(links.get(0).src().deviceId(), links.get(links.size() - 1).dst().deviceId(),
@@ -845,6 +850,10 @@
             return;
         }
 
+        if (pceStore.getTunnelInfo(tunnel.tunnelId()) == null) {
+            //If bandwidth for old tunnel is not allocated i,e 0 then no need to release
+            return;
+        }
         resourceService.release(pceStore.getTunnelInfo(tunnel.tunnelId()).tunnelConsumerId());
         return;
 
@@ -1211,7 +1220,7 @@
                     localLspIdFreeList.add(Short.valueOf(tunnel.annotations().value(LOCAL_LSP_ID)));
                 }
                 // If not zero bandwidth, and delegated (initiated LSPs will also be delegated).
-                if (Float.parseFloat(tunnel.annotations().value(BANDWIDTH)) != 0
+                if (bwConstraintValue != 0
                         && mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
                     releaseBandwidth(tunnel);
                 }