X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=elanmanager%2Felanmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Felan%2Fcli%2Fl2gw%2FL2GwUtilsCacheCli.java;fp=elanmanager%2Felanmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Felan%2Fcli%2Fl2gw%2FL2GwUtilsCacheCli.java;h=f9954043b0f33105a9acfe2b8db1ae9e68ab34ee;hb=00790a95c5e403cb62d2cc544af55e8ab3fef03b;hp=0000000000000000000000000000000000000000;hpb=4110307879cad1aa54943aedbf937b2f21575b4c;p=vpnservice.git diff --git a/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/cli/l2gw/L2GwUtilsCacheCli.java b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/cli/l2gw/L2GwUtilsCacheCli.java new file mode 100644 index 00000000..f9954043 --- /dev/null +++ b/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/vpnservice/elan/cli/l2gw/L2GwUtilsCacheCli.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.vpnservice.elan.cli.l2gw; + +import java.util.concurrent.ConcurrentMap; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.opendaylight.elanmanager.utils.ElanL2GwCacheUtils; +import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice; +import org.opendaylight.vpnservice.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils; +import org.opendaylight.vpnservice.utils.cache.CacheUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(scope = "l2gw", name = "show-cache", description = "display l2gateways cache") +public class L2GwUtilsCacheCli extends OsgiCommandSupport { + private static final Logger logger = LoggerFactory.getLogger(L2GwUtilsCacheCli.class); + + private static final String DEMARCATION = "================================="; + + @Option(name = "-cache", aliases = {"--cache"}, description = "cache name", + required = false, multiValued = false) + String cacheName = null; + + @Option(name = "-elan", aliases = {"--elan"}, description = "elan name", + required = false, multiValued = false) + String elanName; + + @Override + protected Object doExecute() { + try { + if (cacheName == null) { + System.out.println("Available caches"); + System.out.println(ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME); + System.out.println(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME); + return null; + } + switch (cacheName) { + case ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME: + dumpElanL2GwCache(); + break; + case L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME: + dumpL2GwCache(); + break; + } + } catch (Exception e) { + } + + return null; + } + + private void dumpL2GwCache() { + ConcurrentMap devices = (ConcurrentMap) CacheUtil + .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME); + if (devices == null) { + System.out.println("no devices are present in cache"); + return; + } + for (String deviceName : devices.keySet()) { + System.out.println("device "+ devices.get(deviceName)); + } + } + + private void dumpElanL2GwCache() { + if (elanName == null) { + ConcurrentMap> cache = + (ConcurrentMap>) CacheUtil.getCache( + cacheName); + if (cache == null) { + System.out.println("no devices are present in elan cache"); + } + for (String elan : cache.keySet()) { + print(elan, cache.get(elan)); + System.out.println(DEMARCATION); + System.out.println(DEMARCATION); + } + return; + } + ConcurrentMap elanDevices = ElanL2GwCacheUtils + .getAllElanL2GatewayDevicesFromCache(elanName); + print(elanName, elanDevices); + } + + private void print(String elan, + ConcurrentMap devices) { + System.out.println("Elan name : "+elan); + System.out.println("No of devices in elan "+devices.keySet().size()); + for (String deviceName : devices.keySet()) { + System.out.println("device "+ devices.get(deviceName)); + } + } +}