suibin zhang
Committed by Gerrit Code Review

Fix NullPointerException with -s flag; add -s message

Change-Id: I6bc1e2326d0d260a0469e64b8d0ec2937694534c
...@@ -22,13 +22,14 @@ import org.onosproject.cli.AbstractShellCommand; ...@@ -22,13 +22,14 @@ import org.onosproject.cli.AbstractShellCommand;
22 import org.onosproject.core.ApplicationId; 22 import org.onosproject.core.ApplicationId;
23 import org.onosproject.core.CoreService; 23 import org.onosproject.core.CoreService;
24 import org.onosproject.net.intent.Intent; 24 import org.onosproject.net.intent.Intent;
25 -import org.onosproject.net.intent.IntentEvent;
26 -import org.onosproject.net.intent.IntentListener;
27 -import org.onosproject.net.intent.IntentService;
28 import org.onosproject.net.intent.IntentState; 25 import org.onosproject.net.intent.IntentState;
26 +import org.onosproject.net.intent.IntentService;
27 +import org.onosproject.net.intent.IntentListener;
28 +import org.onosproject.net.intent.IntentEvent;
29 import org.onosproject.net.intent.Key; 29 import org.onosproject.net.intent.Key;
30 30
31 import java.math.BigInteger; 31 import java.math.BigInteger;
32 +import java.util.EnumSet;
32 import java.util.Objects; 33 import java.util.Objects;
33 import java.util.concurrent.CountDownLatch; 34 import java.util.concurrent.CountDownLatch;
34 import java.util.concurrent.TimeUnit; 35 import java.util.concurrent.TimeUnit;
...@@ -64,11 +65,18 @@ public class IntentRemoveCommand extends AbstractShellCommand { ...@@ -64,11 +65,18 @@ public class IntentRemoveCommand extends AbstractShellCommand {
64 required = false, multiValued = false) 65 required = false, multiValued = false)
65 private boolean sync = false; 66 private boolean sync = false;
66 67
68 + private static final EnumSet<IntentState> CAN_PURGE = EnumSet.of(WITHDRAWN, FAILED);
69 +
67 @Override 70 @Override
68 protected void execute() { 71 protected void execute() {
69 IntentService intentService = get(IntentService.class); 72 IntentService intentService = get(IntentService.class);
70 CoreService coreService = get(CoreService.class); 73 CoreService coreService = get(CoreService.class);
71 74
75 + if (sync) {
76 + print("Use Sync to remove intents - this may take a while...");
77 + print("Check \"summary\" to see remove progress.");
78 + }
79 +
72 ApplicationId appId = appId(); 80 ApplicationId appId = appId();
73 if (!isNullOrEmpty(applicationIdString)) { 81 if (!isNullOrEmpty(applicationIdString)) {
74 appId = coreService.getAppId(applicationIdString); 82 appId = coreService.getAppId(applicationIdString);
...@@ -137,21 +145,19 @@ public class IntentRemoveCommand extends AbstractShellCommand { ...@@ -137,21 +145,19 @@ public class IntentRemoveCommand extends AbstractShellCommand {
137 } catch (InterruptedException e) { 145 } catch (InterruptedException e) {
138 print("Timed out waiting for intent {} withdraw", key); 146 print("Timed out waiting for intent {} withdraw", key);
139 } 147 }
140 - // double check the state 148 + if (purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
141 - IntentState state = intentService.getIntentState(key);
142 - if (purgeAfterRemove && (state == WITHDRAWN || state == FAILED)) {
143 intentService.purge(intent); 149 intentService.purge(intent);
144 - } 150 + if (sync) { // wait for purge event
145 - if (sync) { // wait for purge event
146 /* TODO 151 /* TODO
147 Technically, the event comes before map.remove() is called. 152 Technically, the event comes before map.remove() is called.
148 If we depend on sync and purge working together, we will 153 If we depend on sync and purge working together, we will
149 need to address this. 154 need to address this.
150 */ 155 */
151 - try { 156 + try {
152 - purgeLatch.await(5, TimeUnit.SECONDS); 157 + purgeLatch.await(5, TimeUnit.SECONDS);
153 - } catch (InterruptedException e) { 158 + } catch (InterruptedException e) {
154 - print("Timed out waiting for intent {} purge", key); 159 + print("Timed out waiting for intent {} purge", key);
160 + }
155 } 161 }
156 } 162 }
157 } 163 }
......