blob: c46c421a811faae006a8cf39f372e7541e7fefd9 [file] [log] [blame]
Yuta HIGUCHIf0f2dfc2014-11-26 13:59:07 -08001/*
2 * Copyright 2014 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli;
Yuta HIGUCHIf0f2dfc2014-11-26 13:59:07 -080017
18import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.cluster.ControllerNode;
20import org.onosproject.store.service.DatabaseAdminService;
Yuta HIGUCHIf0f2dfc2014-11-26 13:59:07 -080021
22import java.util.Optional;
23
24/**
25 * Lists mastership roles of nodes for each device.
26 */
27@Command(scope = "onos", name = "tablet-leader",
28 description = "Prints the current leader of a tablet.")
29public class TabletLeaderCommand extends AbstractShellCommand {
30
31 @Override
32 protected void execute() {
33 final DatabaseAdminService dbAdminService = get(DatabaseAdminService.class);
34
35 Optional<ControllerNode> leader = dbAdminService.leader();
36 if (leader.isPresent()) {
37 print("Leader: %s", leader.get());
38 } else {
39 print("No Leader");
40 }
41 }
42}