Use allocateNextId when building new NextObjective

In order to avoid nextId collisions, all users of the flow objective
service should use the provided allocateNextId() method when
constructing new NextObjectives. I found one instance where this was not
the case: CordMcast.

Solution: removed private id generator from CordMacst and replaced it
with allocateNextId.

Change-Id: I134931b58c524291ae937dd6f0051ee549236734
This commit is contained in:
Zsolt Haraszti 2016-02-25 09:39:10 -08:00 committed by Gerrit Code Review
parent d5bf1069b9
commit 05a1ba1dc9

View File

@ -77,7 +77,6 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
@ -129,9 +128,6 @@ public class CordMcast {
//TODO: move this to a ec map //TODO: move this to a ec map
private Map<IpAddress, Integer> groups = Maps.newConcurrentMap(); private Map<IpAddress, Integer> groups = Maps.newConcurrentMap();
//TODO: move this to distributed atomic long
private AtomicInteger channels = new AtomicInteger(0);
private ApplicationId appId; private ApplicationId appId;
@Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN, @Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN,
@ -331,7 +327,7 @@ public class CordMcast {
final AtomicBoolean sync = new AtomicBoolean(false); final AtomicBoolean sync = new AtomicBoolean(false);
Integer nextId = groups.computeIfAbsent(route.group(), (g) -> { Integer nextId = groups.computeIfAbsent(route.group(), (g) -> {
Integer id = allocateId(); Integer id = flowObjectiveService.allocateNextId();
NextObjective next = DefaultNextObjective.builder() NextObjective next = DefaultNextObjective.builder()
.fromApp(appId) .fromApp(appId)
@ -497,10 +493,6 @@ public class CordMcast {
mcastRoutes.forEach(this::removeRemoteRoute); mcastRoutes.forEach(this::removeRemoteRoute);
} }
private Integer allocateId() {
return channels.getAndIncrement();
}
private WebResource.Builder getClientBuilder(String uri) { private WebResource.Builder getClientBuilder(String uri) {
Client client = Client.create(); Client client = Client.create();
client.setConnectTimeout(DEFAULT_REST_TIMEOUT_MS); client.setConnectTimeout(DEFAULT_REST_TIMEOUT_MS);