Jonathan Hart

Add intents -p commmand to have some visibility into the pending map

Change-Id: Ic29460d8bf78f185bbfa426bc0aeef309b22cf7f
...@@ -56,6 +56,11 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -56,6 +56,11 @@ public class IntentsListCommand extends AbstractShellCommand {
56 required = false, multiValued = false) 56 required = false, multiValued = false)
57 private boolean intentsSummary = false; 57 private boolean intentsSummary = false;
58 58
59 + @Option(name = "-p", aliases = "--pending",
60 + description = "Show inforamtion about pending intents",
61 + required = false, multiValued = false)
62 + private boolean pending = false;
63 +
59 @Override 64 @Override
60 protected void execute() { 65 protected void execute() {
61 IntentService service = get(IntentService.class); 66 IntentService service = get(IntentService.class);
...@@ -70,6 +75,14 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -70,6 +75,14 @@ public class IntentsListCommand extends AbstractShellCommand {
70 intentSummaries.printSummary(); 75 intentSummaries.printSummary();
71 } 76 }
72 return; 77 return;
78 + } else if (pending) {
79 + service.getPending().forEach(intent ->
80 + print("id=%s, key=%s, type=%s, appId=%s",
81 + intent.id(), intent.key(),
82 + intent.getClass().getSimpleName(),
83 + intent.appId().name())
84 + );
85 + return;
73 } 86 }
74 87
75 if (outputJson()) { 88 if (outputJson()) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.intent; 16 package org.onosproject.net.intent;
17 17
18 18
19 +import java.util.Collections;
19 import java.util.List; 20 import java.util.List;
20 21
21 /** 22 /**
...@@ -82,11 +83,21 @@ public interface IntentService { ...@@ -82,11 +83,21 @@ public interface IntentService {
82 */ 83 */
83 List<Intent> getInstallableIntents(Key intentKey); 84 List<Intent> getInstallableIntents(Key intentKey);
84 85
86 + // TODO remove defaults
85 default boolean isLocal(Key intentKey) { 87 default boolean isLocal(Key intentKey) {
86 return true; 88 return true;
87 } 89 }
88 90
89 /** 91 /**
92 + * Returns the list of intent requests pending processing.
93 + *
94 + * @return intents pending processing
95 + */
96 + default Iterable<Intent> getPending() {
97 + return Collections.emptyList();
98 + }
99 +
100 + /**
90 * Adds the specified listener for intent events. 101 * Adds the specified listener for intent events.
91 * 102 *
92 * @param listener listener to be added 103 * @param listener listener to be added
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.intent; ...@@ -17,6 +17,7 @@ package org.onosproject.net.intent;
17 17
18 import org.onosproject.store.Store; 18 import org.onosproject.store.Store;
19 19
20 +import java.util.Collections;
20 import java.util.List; 21 import java.util.List;
21 22
22 /** 23 /**
...@@ -113,4 +114,14 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { ...@@ -113,4 +114,14 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
113 default boolean isMaster(Key intentKey) { //FIXME remove default when impl. 114 default boolean isMaster(Key intentKey) { //FIXME remove default when impl.
114 return true; 115 return true;
115 } 116 }
117 +
118 + /**
119 + * Returns the intent requests pending processing.
120 + *
121 + * @return pending intents
122 + */
123 + // FIXME remove default
124 + default Iterable<Intent> getPending() {
125 + return Collections.emptyList();
126 + }
116 } 127 }
......
...@@ -222,6 +222,11 @@ public class IntentManager ...@@ -222,6 +222,11 @@ public class IntentManager
222 return installerRegistry.getInstallers(); 222 return installerRegistry.getInstallers();
223 } 223 }
224 224
225 + @Override
226 + public Iterable<Intent> getPending() {
227 + return store.getPending();
228 + }
229 +
225 // Store delegate to re-post events emitted from the store. 230 // Store delegate to re-post events emitted from the store.
226 private class InternalStoreDelegate implements IntentStoreDelegate { 231 private class InternalStoreDelegate implements IntentStoreDelegate {
227 @Override 232 @Override
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.store.ecmap; 16 package org.onosproject.store.ecmap;
17 17
18 +import com.google.common.base.MoreObjects;
18 import org.onosproject.cluster.NodeId; 19 import org.onosproject.cluster.NodeId;
19 import org.onosproject.store.Timestamp; 20 import org.onosproject.store.Timestamp;
20 21
...@@ -80,4 +81,12 @@ public class AntiEntropyAdvertisement<K> { ...@@ -80,4 +81,12 @@ public class AntiEntropyAdvertisement<K> {
80 this.timestamps = null; 81 this.timestamps = null;
81 this.tombstones = null; 82 this.tombstones = null;
82 } 83 }
84 +
85 + @Override
86 + public String toString() {
87 + return MoreObjects.toStringHelper(getClass())
88 + .add("timestampsSize", timestamps.size())
89 + .add("tombstonesSize", tombstones.size())
90 + .toString();
91 + }
83 } 92 }
......
...@@ -32,12 +32,12 @@ import org.onosproject.net.intent.IntentStoreDelegate; ...@@ -32,12 +32,12 @@ import org.onosproject.net.intent.IntentStoreDelegate;
32 import org.onosproject.net.intent.Key; 32 import org.onosproject.net.intent.Key;
33 import org.onosproject.store.AbstractStore; 33 import org.onosproject.store.AbstractStore;
34 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 34 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
35 -import org.onosproject.store.impl.MultiValuedTimestamp;
36 -import org.onosproject.store.impl.SystemClockTimestamp;
37 import org.onosproject.store.ecmap.EventuallyConsistentMap; 35 import org.onosproject.store.ecmap.EventuallyConsistentMap;
38 import org.onosproject.store.ecmap.EventuallyConsistentMapEvent; 36 import org.onosproject.store.ecmap.EventuallyConsistentMapEvent;
39 import org.onosproject.store.ecmap.EventuallyConsistentMapImpl; 37 import org.onosproject.store.ecmap.EventuallyConsistentMapImpl;
40 import org.onosproject.store.ecmap.EventuallyConsistentMapListener; 38 import org.onosproject.store.ecmap.EventuallyConsistentMapListener;
39 +import org.onosproject.store.impl.MultiValuedTimestamp;
40 +import org.onosproject.store.impl.SystemClockTimestamp;
41 import org.onosproject.store.serializers.KryoNamespaces; 41 import org.onosproject.store.serializers.KryoNamespaces;
42 import org.slf4j.Logger; 42 import org.slf4j.Logger;
43 43
...@@ -237,7 +237,7 @@ public class GossipIntentStore ...@@ -237,7 +237,7 @@ public class GossipIntentStore
237 // if current.put succeeded 237 // if current.put succeeded
238 pending.remove(newData.key(), newData); 238 pending.remove(newData.key(), newData);
239 } else { 239 } else {
240 - log.debug("not writing update: {}", newData); 240 + log.debug("not writing update: current {}, new {}", currentData, newData);
241 } 241 }
242 /*try { 242 /*try {
243 notifyDelegate(IntentEvent.getEvent(newData)); 243 notifyDelegate(IntentEvent.getEvent(newData));
...@@ -280,6 +280,13 @@ public class GossipIntentStore ...@@ -280,6 +280,13 @@ public class GossipIntentStore
280 return partitionService.isMine(intentKey); 280 return partitionService.isMine(intentKey);
281 } 281 }
282 282
283 + @Override
284 + public Iterable<Intent> getPending() {
285 + return pending.values().stream()
286 + .map(IntentData::intent)
287 + .collect(Collectors.toList());
288 + }
289 +
283 private void notifyDelegateIfNotNull(IntentEvent event) { 290 private void notifyDelegateIfNotNull(IntentEvent event) {
284 if (event != null) { 291 if (event != null) {
285 notifyDelegate(event); 292 notifyDelegate(event);
...@@ -310,6 +317,7 @@ public class GossipIntentStore ...@@ -310,6 +317,7 @@ public class GossipIntentStore
310 // some work. 317 // some work.
311 if (isMaster(event.value().intent().key())) { 318 if (isMaster(event.value().intent().key())) {
312 if (delegate != null) { 319 if (delegate != null) {
320 + log.debug("processing {}", event.key());
313 delegate.process(copyData(event.value())); 321 delegate.process(copyData(event.value()));
314 } 322 }
315 } 323 }
......