idmanager remove usage of @deprecated CacheUtil
[genius.git] / idmanager / idmanager-shell / src / main / java / org / opendaylight / genius / idmanager / shell / IdManagerCacheCli.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.genius.idmanager.shell;
10
11 import java.util.Map;
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;
16
17 @Command(scope = "idmanager", name = "show", description = "display local pool id cache")
18 public class IdManagerCacheCli extends OsgiCommandSupport {
19     private static final String DEMARCATION = "=================================";
20
21     @Option(name = "-pool", aliases = {"--pool"}, description = "pool name",
22             required = false, multiValued = false)
23     String poolName;
24
25     private IdManagerMonitor idManagerMonitor;
26
27     public void setIdManagerMonitor(IdManagerMonitor idManagerMonitor) {
28         this.idManagerMonitor = idManagerMonitor;
29     }
30
31     @Override
32     protected Object doExecute() throws Exception {
33         if (idManagerMonitor == null) {
34             session.getConsole().println("No IdManagerMonitor service available");
35             return null;
36         }
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);
45             });
46         } else {
47             Object idPool = cache.get(poolName);
48             if (idPool == null) {
49                 session.getConsole().println("Local Id pool not found for " + poolName);
50             } else {
51                 print(poolName, idPool);
52             }
53         }
54         return null;
55     }
56
57     private void print(String idPoolName, Object idPool) {
58         session.getConsole().println("Pool name: " + idPoolName);
59         session.getConsole().println("IdPool: " + idPool);
60     }
61 }