Move adsal into its own subdirectory.
[controller.git] / opendaylight / adsal / clustering / services_implementation / src / main / java / org / opendaylight / controller / clustering / services_implementation / internal / ClusterManagerCLI.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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 package org.opendaylight.controller.clustering.services_implementation.internal;
9
10 import java.util.Dictionary;
11 import java.util.Hashtable;
12 import java.util.concurrent.ConcurrentMap;
13
14 import org.apache.felix.service.command.Descriptor;
15 import org.infinispan.AdvancedCache;
16 import org.infinispan.distribution.DistributionManager;
17 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
18 import org.opendaylight.controller.sal.utils.ServiceHelper;
19 import org.osgi.framework.ServiceRegistration;
20
21 public class ClusterManagerCLI {
22     @SuppressWarnings("rawtypes")
23     private ServiceRegistration sr = null;
24
25     public void init() {
26     }
27
28     public void destroy() {
29     }
30
31     public void start() {
32         final Dictionary<String, Object> props = new Hashtable<String, Object>();
33         props.put("osgi.command.scope", "odpcontroller");
34         props.put("osgi.command.function", new String[] { "getContainerAdvancedCacheInfo" });
35         this.sr = ServiceHelper.registerGlobalServiceWReg(ClusterManagerCLI.class, this, props);
36     }
37
38     public void stop() {
39         if (this.sr != null) {
40             this.sr.unregister();
41             this.sr = null;
42         }
43     }
44
45     @Descriptor("Get advanced cache infos")
46     public void getContainerAdvancedCacheInfo(@Descriptor("Container for the cache to be fetched") String container,
47             @Descriptor("cache to get information about") String cacheName) {
48         IClusterContainerServices s =
49                 (IClusterContainerServices) ServiceHelper.getInstance(IClusterContainerServices.class, container, this);
50         if (s == null) {
51             System.out.println("Could not get an handle to the container cluster service:" + container);
52             return;
53         }
54         if (!s.existCache(cacheName)) {
55             System.out.println("Could not get cache named:" + cacheName);
56         }
57         ConcurrentMap<?, ?> aC = s.getCache(cacheName);
58         if (aC == null) {
59             System.out.println("Could not get cache named:" + cacheName);
60             return;
61         }
62         if (aC instanceof AdvancedCache) {
63             @SuppressWarnings("rawtypes")
64             AdvancedCache advCache = (AdvancedCache) aC;
65             System.out.println("AdvancedCache retrieved!");
66             DistributionManager dMgr = advCache.getDistributionManager();
67             if (dMgr == null) {
68                 return;
69             }
70             System.out.println("Routing Table for the Hash:" + dMgr.getConsistentHash()
71                     .getRoutingTableAsString());
72             System.out.println("Get Members:" + dMgr.getConsistentHash()
73                     .getMembers());
74         }
75     }
76 }