create EndpointSnitchInfo and MBean to expose rack and DC.

patch by Nirmal Ranganathan; reviewed by jbellis for CASSANDRA-1491

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1001912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2010-09-27 21:02:32 +00:00
parent c22eebc35e
commit 60e97bbfeb
5 changed files with 107 additions and 37 deletions

View File

@ -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)

View File

@ -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

View File

@ -45,6 +45,7 @@ import org.apache.cassandra.db.migration.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;
}

View File

@ -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));
}
}

View File

@ -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;
}