Satish K
Committed by Gerrit Code Review

Bug Fix - Tunnel subsystem 1. After delete the tunnel and then query the tunnel …

…and call provider. Query will always return null. Null Pointer exception.
2. In Borrow Tunnel, Order relationship is added even if the there is no tunnel to borrow. Note only where tunnel manger do not initiate the tunnel creation through provider.
3. In ConsistancyMap when the key (the set) is empty still the map hold the key with empty list and never deleted. Memory leak.

Change-Id: Iff8ba662f4828324c0588a9dfc494a2b158bcfce
...@@ -93,8 +93,9 @@ public class TunnelManager ...@@ -93,8 +93,9 @@ public class TunnelManager
93 @Override 93 @Override
94 public void removeTunnel(TunnelId tunnelId) { 94 public void removeTunnel(TunnelId tunnelId) {
95 checkNotNull(tunnelId, TUNNNEL_ID_NULL); 95 checkNotNull(tunnelId, TUNNNEL_ID_NULL);
96 - store.deleteTunnel(tunnelId);
97 Tunnel tunnel = store.queryTunnel(tunnelId); 96 Tunnel tunnel = store.queryTunnel(tunnelId);
97 + if (tunnel != null) {
98 + store.deleteTunnel(tunnelId);
98 if (tunnel.providerId() != null) { 99 if (tunnel.providerId() != null) {
99 TunnelProvider provider = getProvider(tunnel.providerId()); 100 TunnelProvider provider = getProvider(tunnel.providerId());
100 if (provider != null) { 101 if (provider != null) {
...@@ -108,6 +109,7 @@ public class TunnelManager ...@@ -108,6 +109,7 @@ public class TunnelManager
108 } 109 }
109 } 110 }
110 } 111 }
112 + }
111 113
112 @Override 114 @Override
113 public void updateTunnel(Tunnel tunnel, Path path) { 115 public void updateTunnel(Tunnel tunnel, Path path) {
...@@ -129,8 +131,9 @@ public class TunnelManager ...@@ -129,8 +131,9 @@ public class TunnelManager
129 @Override 131 @Override
130 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, 132 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst,
131 ProviderId producerName) { 133 ProviderId producerName) {
132 - store.deleteTunnel(src, dst, producerName);
133 Collection<Tunnel> setTunnels = store.queryTunnel(src, dst); 134 Collection<Tunnel> setTunnels = store.queryTunnel(src, dst);
135 + if (!setTunnels.isEmpty()) {
136 + store.deleteTunnel(src, dst, producerName);
134 for (Tunnel tunnel : setTunnels) { 137 for (Tunnel tunnel : setTunnels) {
135 if (producerName != null 138 if (producerName != null
136 && !tunnel.providerId().equals(producerName)) { 139 && !tunnel.providerId().equals(producerName)) {
...@@ -150,12 +153,14 @@ public class TunnelManager ...@@ -150,12 +153,14 @@ public class TunnelManager
150 } 153 }
151 } 154 }
152 } 155 }
156 + }
153 157
154 @Override 158 @Override
155 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, 159 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type,
156 ProviderId producerName) { 160 ProviderId producerName) {
157 - store.deleteTunnel(src, dst, type, producerName);
158 Collection<Tunnel> setTunnels = store.queryTunnel(src, dst); 161 Collection<Tunnel> setTunnels = store.queryTunnel(src, dst);
162 + if (!setTunnels.isEmpty()) {
163 + store.deleteTunnel(src, dst, type, producerName);
159 for (Tunnel tunnel : setTunnels) { 164 for (Tunnel tunnel : setTunnels) {
160 if (producerName != null 165 if (producerName != null
161 && !tunnel.providerId().equals(producerName) 166 && !tunnel.providerId().equals(producerName)
...@@ -176,6 +181,7 @@ public class TunnelManager ...@@ -176,6 +181,7 @@ public class TunnelManager
176 } 181 }
177 } 182 }
178 } 183 }
184 + }
179 185
180 @Override 186 @Override
181 public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId, 187 public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
......