blob: 955bbc200598281fbfe407d099da9386c2d76827 [file] [log] [blame]
Jonathan Hart054da972015-02-18 17:30: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.net;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.store.service.PartitionInfo;
21import org.onosproject.store.service.StorageAdminService;
22
23import java.util.List;
24
25/**
26 * Command to list the database partitions in the system.
27 */
28@Command(scope = "onos", name = "partitions",
29 description = "Lists information about partitions in the system")
30public class PartitionsListCommand extends AbstractShellCommand {
31
32 private static final String FMT = "%-20s %8s %25s %s";
33
34 @Override
35 protected void execute() {
36 StorageAdminService storageAdminService = get(StorageAdminService.class);
37 List<PartitionInfo> partitionInfo = storageAdminService.getPartitionInfo();
38
39 print(FMT, "Name", "Term", "Members", "");
40
41 for (PartitionInfo info : partitionInfo) {
42 boolean first = true;
43 for (String member : info.members()) {
44 if (first) {
45 print(FMT, info.name(), info.term(), member,
46 member.equals(info.leader()) ? "*" : "");
47 first = false;
48 } else {
49 print(FMT, "", "", member,
50 member.equals(info.leader()) ? "*" : "");
51 }
52 }
53 }
54 }
55}