aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/store
diff options
context:
space:
mode:
authorAshlee Young <ashlee@wildernessvoice.com>2015-11-11 14:39:51 -0800
committerAshlee Young <ashlee@wildernessvoice.com>2015-11-11 14:40:00 -0800
commitbaac58c7c50e6f89eb0520e3f5b0e83a69839bd3 (patch)
tree9c5a149ee6cdf345fed7dfe8c97fcaac8959a70d /framework/src/onos/core/store
parent8f92448e4f2f5d9c98036097bdabd1c40166908a (diff)
Updating onos src to commit id ec0425c18cbe49d368c600160f033acf9fe344ca
Change-Id: Iec2815bf7771080f25272842b852bd9d33f908ff Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/core/store')
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java91
-rw-r--r--framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java7
2 files changed, 36 insertions, 62 deletions
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java
index f9c96891..391a88f7 100644
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java
+++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java
@@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkState;
import static org.onosproject.net.DefaultAnnotations.merge;
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
-import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED;
import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED;
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
@@ -28,9 +27,10 @@ import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -56,7 +56,6 @@ import org.onosproject.net.host.HostDescription;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.HostStoreDelegate;
-import org.onosproject.net.host.HostEvent.Type;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.AbstractStore;
import org.onosproject.store.serializers.KryoNamespaces;
@@ -67,10 +66,7 @@ import org.onosproject.store.service.LogicalClockService;
import org.onosproject.store.service.StorageService;
import org.slf4j.Logger;
-import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
/**
@@ -90,13 +86,11 @@ public class ECHostStore
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LogicalClockService clockService;
- // Hosts tracked by their location
- private final SetMultimap<ConnectPoint, Host> locations =
- Multimaps.synchronizedSetMultimap(
- HashMultimap.<ConnectPoint, Host>create());
-
private EventuallyConsistentMap<HostId, DefaultHost> hosts;
+ private final ConcurrentHashMap<HostId, HostLocation> locations =
+ new ConcurrentHashMap<>();
+
private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker =
new HostLocationTracker();
@@ -125,6 +119,7 @@ public class ECHostStore
log.info("Stopped");
}
+ // TODO No longer need to return HostEvent
@Override
public HostEvent createOrUpdateHost(ProviderId providerId,
HostId hostId,
@@ -133,18 +128,7 @@ public class ECHostStore
// TODO: We need a way to detect conflicting changes and abort update.
// (BOC) Compute might do this for us.
- final AtomicReference<Type> eventType = new AtomicReference<>();
- final AtomicReference<DefaultHost> oldHost = new AtomicReference<>();
- DefaultHost host = hosts.compute(hostId, (id, existingHost) -> {
- if (existingHost != null) {
- oldHost.set(existingHost);
- checkState(Objects.equals(hostDescription.hwAddress(), existingHost.mac()),
- "Existing and new MAC addresses differ.");
- checkState(Objects.equals(hostDescription.vlan(), existingHost.vlan()),
- "Existing and new VLANs differ.");
- }
-
- // TODO do we ever want the existing location?
+ hosts.compute(hostId, (id, existingHost) -> {
HostLocation location = hostDescription.location();
final Set<IpAddress> addresses;
@@ -163,15 +147,6 @@ public class ECHostStore
annotations = hostDescription.annotations();
}
- if (existingHost == null) {
- eventType.set(HOST_ADDED);
- } else if (!Objects.equals(existingHost.location(), hostDescription.location())) {
- eventType.set(HOST_MOVED);
- } else if (!existingHost.ipAddresses().containsAll(hostDescription.ipAddress()) ||
- !hostDescription.annotations().keys().isEmpty()) {
- eventType.set(HOST_UPDATED);
- } // else, eventType == null; this means we don't send an event
-
return new DefaultHost(providerId,
hostId,
hostDescription.hwAddress(),
@@ -181,24 +156,20 @@ public class ECHostStore
annotations);
});
- if (oldHost.get() != null) {
- DefaultHost old = oldHost.get();
- locations.remove(old.location(), old);
- }
- locations.put(host.location(), host);
-
- return eventType.get() != null ? new HostEvent(eventType.get(), host) : null;
+ return null;
}
+ // TODO No longer need to return HostEvent
@Override
public HostEvent removeHost(HostId hostId) {
- Host host = hosts.remove(hostId);
- return host != null ? new HostEvent(HOST_REMOVED, host) : null;
+ hosts.remove(hostId);
+ return null;
}
+ // TODO No longer need to return HostEvent
@Override
public HostEvent removeIp(HostId hostId, IpAddress ipAddress) {
- DefaultHost host = hosts.compute(hostId, (id, existingHost) -> {
+ hosts.compute(hostId, (id, existingHost) -> {
if (existingHost != null) {
checkState(Objects.equals(hostId.mac(), existingHost.mac()),
"Existing and new MAC addresses differ.");
@@ -222,7 +193,7 @@ public class ECHostStore
}
return null;
});
- return host != null ? new HostEvent(HOST_UPDATED, host) : null;
+ return null;
}
@Override
@@ -257,22 +228,19 @@ public class ECHostStore
@Override
public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
- synchronized (locations) {
- return ImmutableSet.copyOf(locations.get(connectPoint));
- }
+ Set<Host> filtered = hosts.entrySet().stream()
+ .filter(entry -> entry.getValue().location().equals(connectPoint))
+ .map(Map.Entry::getValue)
+ .collect(Collectors.toSet());
+ return ImmutableSet.copyOf(filtered);
}
@Override
public Set<Host> getConnectedHosts(DeviceId deviceId) {
- Set<Host> filtered;
- synchronized (locations) {
- filtered = locations
- .entries()
- .stream()
- .filter(entry -> entry.getKey().deviceId().equals(deviceId))
- .map(entry -> entry.getValue())
- .collect(Collectors.toSet());
- }
+ Set<Host> filtered = hosts.entrySet().stream()
+ .filter(entry -> entry.getValue().location().deviceId().equals(deviceId))
+ .map(Map.Entry::getValue)
+ .collect(Collectors.toSet());
return ImmutableSet.copyOf(filtered);
}
@@ -285,13 +253,18 @@ public class ECHostStore
public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) {
DefaultHost host = checkNotNull(event.value());
if (event.type() == PUT) {
- boolean isNew = locations.put(host.location(), host);
- notifyDelegate(new HostEvent(isNew ? HOST_ADDED : HOST_UPDATED, host));
+ HostLocation prevLocation = locations.put(host.id(), host.location());
+ if (prevLocation == null) {
+ notifyDelegate(new HostEvent(HOST_ADDED, host));
+ } else if (!Objects.equals(prevLocation, host.location())) {
+ notifyDelegate(new HostEvent(host, prevLocation));
+ } else {
+ notifyDelegate(new HostEvent(HOST_UPDATED, host));
+ }
} else if (event.type() == REMOVE) {
- if (locations.remove(host.location(), host)) {
+ if (locations.remove(host.id()) != null) {
notifyDelegate(new HostEvent(HOST_REMOVED, host));
}
-
}
}
}
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index 82dfe32f..4d9e3cbf 100644
--- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -292,9 +292,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
* @return true if the operation succeeds, false otherwise.
*/
private <K, V> boolean appendValues(TransactionalMap<K, List<V>> map, K key, List<V> values) {
- List<V> oldValues = map.get(key);
+ List<V> oldValues = map.putIfAbsent(key, new ArrayList<>(values));
if (oldValues == null) {
- return map.replace(key, oldValues, new ArrayList<>(values));
+ return true;
}
LinkedHashSet<V> oldSet = new LinkedHashSet<>(oldValues);
@@ -321,7 +321,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
private <K, V> boolean removeValues(TransactionalMap<K, List<V>> map, K key, List<V> values) {
List<V> oldValues = map.get(key);
if (oldValues == null) {
- return map.replace(key, oldValues, new ArrayList<>());
+ map.put(key, new ArrayList<>());
+ return true;
}
LinkedHashSet<V> oldSet = new LinkedHashSet<>(oldValues);