Author: jbellis
Date: Mon Sep 27 21:02:32 2010
New Revision: 1001912

URL: http://svn.apache.org/viewvc?rev=1001912&view=rev
Log:
create EndpointSnitchInfo and MBean to expose rack and DC.
patch by Nirmal Ranganathan; reviewed by jbellis for CASSANDRA-1491

Added:
    
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java
    
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java
Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/conf/cassandra-rack.properties
    cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java

Modified: cassandra/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1001912&r1=1001911&r2=1001912&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Mon Sep 27 21:02:32 2010
@@ -1,3 +1,7 @@
+dev
+ * create EndpointSnitchInfo and MBean to expose rack and DC (CASSANDRA-1491)
+
+
 0.7-beta2
  * always use UTF-8 for hint keys (CASSANDRA-1439)
  * remove cassandra.yaml dependency from Hadoop and Pig (CASSADRA-1322)

Modified: cassandra/trunk/conf/cassandra-rack.properties
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/conf/cassandra-rack.properties?rev=1001912&r1=1001911&r2=1001912&view=diff
==============================================================================
--- cassandra/trunk/conf/cassandra-rack.properties (original)
+++ cassandra/trunk/conf/cassandra-rack.properties Mon Sep 27 21:02:32 2010
@@ -34,39 +34,4 @@
 
 # default for unknown nodes
 default=DC1:r1
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
-# Cassandra Node IP=Data Center:Rack
-192.168.1.200=DC1:RAC1
-192.168.2.300=DC2:RAC2
-
-10.0.0.10=DC1:RAC1
-10.0.0.11=DC1:RAC1
-10.0.0.12=DC1:RAC2
-
-10.20.114.10=DC2:RAC1
-10.20.114.11=DC2:RAC1
-
-10.21.119.13=DC3:RAC1
-10.21.119.10=DC3:RAC1
-
-10.0.0.13=DC1:RAC2
-10.21.119.14=DC3:RAC2
-10.20.114.15=DC2:RAC2
-
-# default for unknown nodes
-default=DC1:r1
\ No newline at end of file

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=1001912&r1=1001911&r2=1001912&view=diff
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java 
(original)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java 
Mon Sep 27 21:02:32 2010
@@ -45,6 +45,7 @@ import org.apache.cassandra.db.migration
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
+import org.apache.cassandra.locator.EndpointSnitchInfo;
 import org.apache.cassandra.locator.LocalStrategy;
 import org.apache.cassandra.locator.IEndpointSnitch;
 import org.apache.cassandra.scheduler.IRequestScheduler;
@@ -274,7 +275,8 @@ public class DatabaseDescriptor
                 throw new ConfigurationException("Missing endpoint_snitch 
directive");
             }
             snitch = createEndpointSnitch(conf.endpoint_snitch);
-            
+            EndpointSnitchInfo.create();
+
             /* Request Scheduler setup */
             requestSchedulerOptions = conf.request_scheduler_options;
             if (conf.request_scheduler != null)
@@ -392,7 +394,7 @@ public class DatabaseDescriptor
 
     private static IEndpointSnitch createEndpointSnitch(String 
endpointSnitchClassName) throws ConfigurationException
     {
-        IEndpointSnitch snitch = 
FBUtilities.<IEndpointSnitch>construct(endpointSnitchClassName, "snitch");
+        IEndpointSnitch snitch = 
FBUtilities.construct(endpointSnitchClassName, "snitch");
         return conf.dynamic_snitch ? new DynamicEndpointSnitch(snitch) : 
snitch;
     }
     

Added: 
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java?rev=1001912&view=auto
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java 
(added)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java 
Mon Sep 27 21:02:32 2010
@@ -0,0 +1,57 @@
+package org.apache.cassandra.locator;
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+import java.lang.management.ManagementFactory;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+
+public class EndpointSnitchInfo implements EndpointSnitchInfoMBean
+{
+    public static void create()
+    {
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        try
+        {
+            mbs.registerMBean(new EndpointSnitchInfo(), new 
ObjectName("org.apache.cassandra.locator:type=EndpointSnitchInfo"));
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public String getDatacenter(String host) throws UnknownHostException
+    {
+        return 
DatabaseDescriptor.getEndpointSnitch().getDatacenter(InetAddress.getByName(host));
+    }
+
+    public String getRack(String host) throws UnknownHostException
+    {
+        return 
DatabaseDescriptor.getEndpointSnitch().getRack(InetAddress.getByName(host));
+    }
+}

Added: 
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java?rev=1001912&view=auto
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java
 (added)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java
 Mon Sep 27 21:02:32 2010
@@ -0,0 +1,42 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.cassandra.locator;
+
+import java.net.UnknownHostException;
+
+/**
+ * MBean exposing standard Snitch info
+ */
+public interface EndpointSnitchInfoMBean
+{
+    /**
+     * Provides the Rack name depending on the respective snitch used, given 
the host name/ip 
+     * @param host
+     * @throws UnknownHostException
+     */
+    public String getRack(String host) throws UnknownHostException;
+
+    /**
+     * Provides the Datacenter name depending on the respective snitch used, 
given the hostname/ip
+     * @param host
+     * @throws UnknownHostException
+     */
+    public String getDatacenter(String host) throws UnknownHostException;
+}


Reply via email to