blob: de6984f994e068c75a30c412ea297e770017a3f9 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Brian O'Connora4cab072014-10-03 18:46:39 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cli.AbstractShellCommand;
Ray Milkey02479862015-02-17 17:02:19 -080021import org.onosproject.core.ApplicationId;
22import org.onosproject.core.CoreService;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.intent.Intent;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.intent.IntentService;
Ray Milkeyf9af43c2015-02-09 16:45:48 -080025import org.onosproject.net.intent.Key;
Brian O'Connora4cab072014-10-03 18:46:39 -070026
Thomas Vachuska4926c1b2014-10-21 00:44:10 -070027import java.math.BigInteger;
28
Brian O'Connora4cab072014-10-03 18:46:39 -070029/**
Ray Milkey02479862015-02-17 17:02:19 -080030 * Removes an intent.
Brian O'Connora4cab072014-10-03 18:46:39 -070031 */
tom6db1f0a2014-10-07 09:12:29 -070032@Command(scope = "onos", name = "remove-intent",
33 description = "Removes the specified intent")
34public class IntentRemoveCommand extends AbstractShellCommand {
Brian O'Connora4cab072014-10-03 18:46:39 -070035
Ray Milkey02479862015-02-17 17:02:19 -080036 @Argument(index = 0, name = "app",
37 description = "Application ID",
38 required = true, multiValued = false)
39 String applicationIdString = null;
40
41 @Argument(index = 1, name = "id",
42 description = "Intent ID",
Brian O'Connora4cab072014-10-03 18:46:39 -070043 required = true, multiValued = false)
44 String id = null;
45
46 @Override
47 protected void execute() {
Ray Milkey02479862015-02-17 17:02:19 -080048 IntentService intentService = get(IntentService.class);
49 CoreService coreService = get(CoreService.class);
50
51 ApplicationId appId = appId();
52 if (applicationIdString != null) {
53 appId = coreService.getAppId(applicationIdString);
54 if (appId == null) {
55 print("Cannot find application Id %s", applicationIdString);
56 return;
57 }
58 }
Brian O'Connora4cab072014-10-03 18:46:39 -070059
Thomas Vachuska4926c1b2014-10-21 00:44:10 -070060 if (id.startsWith("0x")) {
Brian O'Connora4cab072014-10-03 18:46:39 -070061 id = id.replaceFirst("0x", "");
62 }
Brian O'Connora4cab072014-10-03 18:46:39 -070063
Ray Milkey02479862015-02-17 17:02:19 -080064 Key key = Key.of(new BigInteger(id, 16).longValue(), appId);
65 Intent intent = intentService.getIntent(key);
Brian O'Connora4cab072014-10-03 18:46:39 -070066 if (intent != null) {
Ray Milkey02479862015-02-17 17:02:19 -080067 intentService.withdraw(intent);
Brian O'Connora4cab072014-10-03 18:46:39 -070068 }
69 }
70}