blob: 862e27e202fbc89ba20b124c25dad79da601b110 [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
41 @Argument(index = 1, name = "name", description = "Application name",
42 required = true, multiValued = false)
43 String name = null;
44
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 {
52 ApplicationId appId = service.getId(name);
53 if (appId == null) {
54 print("No such application: %s", name);
55 return;
56 }
57
58 if (command.equals(UNINSTALL)) {
59 service.uninstall(appId);
60 } else if (command.equals(ACTIVATE)) {
61 service.activate(appId);
62 } else if (command.equals(DEACTIVATE)) {
63 service.deactivate(appId);
64 }
65 }
66 }
67
68}