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