Committed by
Ray Milkey
Implement toString()
- add more debug logs Change-Id: I1541d66f24d2dde0712a4daef081ca1f49951ef8
Showing
6 changed files
with
57 additions
and
0 deletions
... | @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; |
25 | 25 | ||
26 | import com.fasterxml.jackson.databind.JsonNode; | 26 | import com.fasterxml.jackson.databind.JsonNode; |
27 | import com.google.common.annotations.Beta; | 27 | import com.google.common.annotations.Beta; |
28 | +import com.google.common.base.MoreObjects; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Configuration to specify maximum available bandwidth resource (Capacity) on a port. | 31 | * Configuration to specify maximum available bandwidth resource (Capacity) on a port. |
... | @@ -82,4 +83,11 @@ public class BandwidthCapacity extends Config<ConnectPoint> { | ... | @@ -82,4 +83,11 @@ public class BandwidthCapacity extends Config<ConnectPoint> { |
82 | return Bandwidth.mbps(v.asDouble()); | 83 | return Bandwidth.mbps(v.asDouble()); |
83 | } | 84 | } |
84 | } | 85 | } |
86 | + | ||
87 | + @Override | ||
88 | + public String toString() { | ||
89 | + return MoreObjects.toStringHelper(this) | ||
90 | + .add("capacity", capacity()) | ||
91 | + .toString(); | ||
92 | + } | ||
85 | } | 93 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.store.primitives; | 16 | package org.onosproject.store.primitives; |
17 | 17 | ||
18 | import java.util.Collection; | 18 | import java.util.Collection; |
19 | +import java.util.Iterator; | ||
19 | import java.util.Map; | 20 | import java.util.Map; |
20 | import java.util.Set; | 21 | import java.util.Set; |
21 | import java.util.function.BiConsumer; | 22 | import java.util.function.BiConsumer; |
... | @@ -149,6 +150,23 @@ public final class ConsistentMapBackedJavaMap<K, V> implements Map<K, V> { | ... | @@ -149,6 +150,23 @@ public final class ConsistentMapBackedJavaMap<K, V> implements Map<K, V> { |
149 | } | 150 | } |
150 | 151 | ||
151 | @Override | 152 | @Override |
153 | + public String toString() { | ||
154 | + // Map like output | ||
155 | + StringBuilder sb = new StringBuilder(); | ||
156 | + sb.append('{'); | ||
157 | + Iterator<Entry<K, Versioned<V>>> it = backingMap.entrySet().iterator(); | ||
158 | + while (it.hasNext()) { | ||
159 | + Entry<K, Versioned<V>> entry = it.next(); | ||
160 | + sb.append(entry.getKey()).append('=').append(entry.getValue().value()); | ||
161 | + if (it.hasNext()) { | ||
162 | + sb.append(',').append(' '); | ||
163 | + } | ||
164 | + } | ||
165 | + sb.append('}'); | ||
166 | + return sb.toString(); | ||
167 | + } | ||
168 | + | ||
169 | + @Override | ||
152 | public void forEach(BiConsumer<? super K, ? super V> action) { | 170 | public void forEach(BiConsumer<? super K, ? super V> action) { |
153 | entrySet().forEach(e -> action.accept(e.getKey(), e.getValue())); | 171 | entrySet().forEach(e -> action.accept(e.getKey(), e.getValue())); |
154 | } | 172 | } | ... | ... |
... | @@ -505,11 +505,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -505,11 +505,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
505 | private <K, V> boolean removeValues(TransactionalMap<K, Set<V>> map, K key, List<? extends V> values) { | 505 | private <K, V> boolean removeValues(TransactionalMap<K, Set<V>> map, K key, List<? extends V> values) { |
506 | Set<V> oldValues = map.putIfAbsent(key, new LinkedHashSet<>()); | 506 | Set<V> oldValues = map.putIfAbsent(key, new LinkedHashSet<>()); |
507 | if (oldValues == null) { | 507 | if (oldValues == null) { |
508 | + log.trace("No-Op removing values. key {} did not exist", key); | ||
508 | return true; | 509 | return true; |
509 | } | 510 | } |
510 | 511 | ||
511 | if (values.stream().allMatch(x -> !oldValues.contains(x))) { | 512 | if (values.stream().allMatch(x -> !oldValues.contains(x))) { |
512 | // don't write map because none of the values are stored | 513 | // don't write map because none of the values are stored |
514 | + log.trace("No-Op removing values. key {} did not contain {}", key, values); | ||
513 | return true; | 515 | return true; |
514 | } | 516 | } |
515 | 517 | ... | ... |
... | @@ -189,6 +189,11 @@ public class DefaultConsistentMap<K, V> extends Synchronous<AsyncConsistentMap<K | ... | @@ -189,6 +189,11 @@ public class DefaultConsistentMap<K, V> extends Synchronous<AsyncConsistentMap<K |
189 | return javaMap; | 189 | return javaMap; |
190 | } | 190 | } |
191 | 191 | ||
192 | + @Override | ||
193 | + public String toString() { | ||
194 | + return asJavaMap().toString(); | ||
195 | + } | ||
196 | + | ||
192 | private static <T> T complete(CompletableFuture<T> future) { | 197 | private static <T> T complete(CompletableFuture<T> future) { |
193 | try { | 198 | try { |
194 | return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); | 199 | return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); | ... | ... |
... | @@ -29,6 +29,8 @@ import org.onosproject.store.service.Transaction; | ... | @@ -29,6 +29,8 @@ import org.onosproject.store.service.Transaction; |
29 | import org.onosproject.store.service.TransactionContext; | 29 | import org.onosproject.store.service.TransactionContext; |
30 | import org.onosproject.store.service.TransactionalMap; | 30 | import org.onosproject.store.service.TransactionalMap; |
31 | 31 | ||
32 | +import com.google.common.base.MoreObjects; | ||
33 | +import com.google.common.base.MoreObjects.ToStringHelper; | ||
32 | import com.google.common.collect.Lists; | 34 | import com.google.common.collect.Lists; |
33 | import com.google.common.collect.Maps; | 35 | import com.google.common.collect.Maps; |
34 | import com.google.common.util.concurrent.Futures; | 36 | import com.google.common.util.concurrent.Futures; |
... | @@ -114,4 +116,16 @@ public class DefaultTransactionContext implements TransactionContext { | ... | @@ -114,4 +116,16 @@ public class DefaultTransactionContext implements TransactionContext { |
114 | } | 116 | } |
115 | } | 117 | } |
116 | } | 118 | } |
119 | + | ||
120 | + @Override | ||
121 | + public String toString() { | ||
122 | + ToStringHelper s = MoreObjects.toStringHelper(this) | ||
123 | + .add("transactionId", transactionId) | ||
124 | + .add("isOpen", isOpen); | ||
125 | + | ||
126 | + txMaps.entrySet().forEach(e -> { | ||
127 | + s.add(e.getKey(), e.getValue()); | ||
128 | + }); | ||
129 | + return s.toString(); | ||
130 | + } | ||
117 | } | 131 | } | ... | ... |
... | @@ -30,6 +30,7 @@ import org.onosproject.store.service.Versioned; | ... | @@ -30,6 +30,7 @@ import org.onosproject.store.service.Versioned; |
30 | 30 | ||
31 | import static com.google.common.base.Preconditions.*; | 31 | import static com.google.common.base.Preconditions.*; |
32 | 32 | ||
33 | +import com.google.common.base.MoreObjects; | ||
33 | import com.google.common.base.Objects; | 34 | import com.google.common.base.Objects; |
34 | import com.google.common.cache.CacheBuilder; | 35 | import com.google.common.cache.CacheBuilder; |
35 | import com.google.common.cache.CacheLoader; | 36 | import com.google.common.cache.CacheLoader; |
... | @@ -193,6 +194,15 @@ public class DefaultTransactionalMap<K, V> implements TransactionalMap<K, V> { | ... | @@ -193,6 +194,15 @@ public class DefaultTransactionalMap<K, V> implements TransactionalMap<K, V> { |
193 | return updates; | 194 | return updates; |
194 | } | 195 | } |
195 | 196 | ||
197 | + // TODO: build expected result Map processing DB updates? | ||
198 | + @Override | ||
199 | + public String toString() { | ||
200 | + return MoreObjects.toStringHelper(this) | ||
201 | + .add("backingMap", backingMap) | ||
202 | + .add("updates", prepareDatabaseUpdates()) | ||
203 | + .toString(); | ||
204 | + } | ||
205 | + | ||
196 | /** | 206 | /** |
197 | * Discards all changes made to this transactional map. | 207 | * Discards all changes made to this transactional map. |
198 | */ | 208 | */ | ... | ... |
-
Please register or login to post a comment