blob: 68a195724e1fe2d2726aa544ef83e5e365fce27c [file] [log] [blame]
Thomas Vachuska1dcb0482015-02-18 18:21:28 -08001/*
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 */
16package org.onosproject.cli.app;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.app.ApplicationAdminService;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.core.ApplicationId;
23
24/**
25 * Manages application inventory.
26 */
27@Command(scope = "onos", name = "app",
28 description = "Manages application inventory")
29public class ApplicationCommand extends AbstractShellCommand {
30
31 static final String INSTALL = "install";
32 static final String UNINSTALL = "uninstall";
33 static final String ACTIVATE = "activate";
34 static final String DEACTIVATE = "deactivate";
35
36 @Argument(index = 0, name = "command",
37 description = "Command name (activate|deactivate|uninstall)",
38 required = true, multiValued = false)
39 String command = null;
40
Thomas Vachuskafba28572015-03-25 18:48:59 -070041 @Argument(index = 1, name = "names", description = "Application name(s)",
42 required = true, multiValued = true)
43 String[] names = null;
Thomas Vachuska1dcb0482015-02-18 18:21:28 -080044
45 @Override
46 protected void execute() {
47 ApplicationAdminService service = get(ApplicationAdminService.class);
48 if (command.equals(INSTALL)) {
49 print("Not supported via CLI yet.");
50
51 } else {
Thomas Vachuskafba28572015-03-25 18:48:59 -070052 for (String name : names) {
53 ApplicationId appId = service.getId(name);
54 if (appId == null) {
55 print("No such application: %s", name);
56 return;
57 }
Thomas Vachuska1dcb0482015-02-18 18:21:28 -080058
Thomas Vachuskafba28572015-03-25 18:48:59 -070059 if (command.equals(UNINSTALL)) {
60 service.uninstall(appId);
61 } else if (command.equals(ACTIVATE)) {
62 service.activate(appId);
63 } else if (command.equals(DEACTIVATE)) {
64 service.deactivate(appId);
65 } else {
66 print("Unsupported command: %s", command);
67 }
Thomas Vachuska1dcb0482015-02-18 18:21:28 -080068 }
69 }
70 }
71
72}