blob: cf7300d6a8feb08002c2e4beb3968cba5e34f0fd [file] [log] [blame]
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -07003 *
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
17package org.onosproject.cli.net;
18
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.ui.UiTopoLayoutService;
24import org.onosproject.ui.model.topo.UiTopoLayout;
25import org.onosproject.ui.model.topo.UiTopoLayoutId;
26import org.onosproject.utils.Comparators;
27
28import java.util.Collections;
29import java.util.List;
30
31import static com.google.common.collect.Lists.newArrayList;
32
33/**
34 * List layout details.
35 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070036@Service
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -070037@Command(scope = "onos", name = "layouts",
38 description = "List layout details")
39public class LayoutListCommand extends AbstractShellCommand {
40
Simon Huntbc30e682017-02-15 18:39:23 -080041 private static final String FMT = "id=%s, bgref=%s, region=%s, parent=%s";
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -070042
43 @Argument(index = 0, name = "id", description = "Layout ID",
44 required = false, multiValued = false)
45 String id = null;
46
47 private UiTopoLayoutService layoutService;
48
49 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070050 protected void doExecute() {
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -070051 layoutService = get(UiTopoLayoutService.class);
52 if (id == null) {
53 for (UiTopoLayout layout : getSortedLayouts(layoutService)) {
54 printLayout(layout);
55 }
56 } else {
57 UiTopoLayout layout = layoutService.getLayout(UiTopoLayoutId.layoutId(id));
58 if (layout == null) {
59 error("No such region %s", id);
60 } else {
61 printLayout(layout);
62 }
63 }
64 }
65
66 private List<UiTopoLayout> getSortedLayouts(UiTopoLayoutService service) {
67 List<UiTopoLayout> layouts = newArrayList(service.getLayouts());
68 Collections.sort(layouts, Comparators.LAYOUT_COMPARATOR);
69 return layouts;
70 }
71
72 private void printLayout(UiTopoLayout layout) {
Simon Huntbc30e682017-02-15 18:39:23 -080073 String map = layout.geomap();
74 String spr = layout.sprites();
75 String bgRef = ".";
76 if (map != null) {
77 bgRef = "@" + map;
78 } else if (spr != null) {
79 bgRef = "+" + spr;
80 }
81
82 String pid = layout.parent() != null ? layout.parent().id() : "(none)";
83
84 print(FMT, layout.id(), bgRef, layout.regionId(), pid);
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -070085 }
86}