Brian O'Connor
Committed by Gerrit Code Review

Adding purge-intents command

Change-Id: I991084aa610cdeb9fb43082ed1e9888b781897ce
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cli.net;
17 +
18 +import org.apache.karaf.shell.commands.Command;
19 +import org.onosproject.cli.AbstractShellCommand;
20 +import org.onosproject.net.intent.Intent;
21 +import org.onosproject.net.intent.IntentService;
22 +
23 +import static org.onosproject.net.intent.IntentState.WITHDRAWN;
24 +
25 +/**
26 + * Purges all WITHDRAWN intents.
27 + */
28 +@Command(scope = "onos", name = "purge-intents",
29 + description = "Purges all WITHDRAWN intents")
30 +public class IntentPurgeCommand extends AbstractShellCommand {
31 + @Override
32 + protected void execute() {
33 + IntentService intentService = get(IntentService.class);
34 + for (Intent intent: intentService.getIntents()) {
35 + if (intentService.getIntentState(intent.key()) == WITHDRAWN) {
36 + intentService.purge(intent);
37 + }
38 + }
39 + }
40 +}
...@@ -137,6 +137,9 @@ ...@@ -137,6 +137,9 @@
137 </completers> 137 </completers>
138 </command> 138 </command>
139 <command> 139 <command>
140 + <action class="org.onosproject.cli.net.IntentPurgeCommand"/>
141 + </command>
142 + <command>
140 <action class="org.onosproject.cli.net.AddHostToHostIntentCommand"/> 143 <action class="org.onosproject.cli.net.AddHostToHostIntentCommand"/>
141 <completers> 144 <completers>
142 <ref component-id="hostIdCompleter"/> 145 <ref component-id="hostIdCompleter"/>
......