2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.genius.idmanager.shell;
12 import org.apache.karaf.shell.commands.Command;
13 import org.apache.karaf.shell.commands.Option;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.genius.idmanager.api.IdManagerMonitor;
17 @Command(scope = "idmanager", name = "show", description = "display local pool id cache")
18 public class IdManagerCacheCli extends OsgiCommandSupport {
19 private static final String DEMARCATION = "=================================";
21 @Option(name = "-pool", aliases = {"--pool"}, description = "pool name",
22 required = false, multiValued = false)
25 private IdManagerMonitor idManagerMonitor;
27 public void setIdManagerMonitor(IdManagerMonitor idManagerMonitor) {
28 this.idManagerMonitor = idManagerMonitor;
32 protected Object doExecute() throws Exception {
33 if (idManagerMonitor == null) {
34 session.getConsole().println("No IdManagerMonitor service available");
37 Map<String, String> cache = idManagerMonitor.getLocalPoolsDetails();
38 session.getConsole().println("No of pools in cluster " + cache.keySet().size());
39 session.getConsole().println(DEMARCATION);
40 if (poolName == null) {
41 cache.keySet().stream().forEach(idPoolName -> {
42 print(idPoolName, cache.get(idPoolName));
43 session.getConsole().println(DEMARCATION);
44 session.getConsole().println(DEMARCATION);
47 Object idPool = cache.get(poolName);
49 session.getConsole().println("Local Id pool not found for " + poolName);
51 print(poolName, idPool);
57 private void print(String idPoolName, Object idPool) {
58 session.getConsole().println("Pool name: " + idPoolName);
59 session.getConsole().println("IdPool: " + idPool);