diff --git a/CHANGES.txt b/CHANGES.txt index 69e2ae2c52..8d74be0f7f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) diff --git a/conf/cassandra-rack.properties b/conf/cassandra-rack.properties index 7caa24d508..718eb5d4db 100644 --- a/conf/cassandra-rack.properties +++ b/conf/cassandra-rack.properties @@ -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 diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index 78c7fb4ec1..138593be97 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -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.construct(endpointSnitchClassName, "snitch"); + IEndpointSnitch snitch = FBUtilities.construct(endpointSnitchClassName, "snitch"); return conf.dynamic_snitch ? new DynamicEndpointSnitch(snitch) : snitch; } diff --git a/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java b/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java new file mode 100644 index 0000000000..9866fe8758 --- /dev/null +++ b/src/java/org/apache/cassandra/locator/EndpointSnitchInfo.java @@ -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)); + } +} diff --git a/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java b/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java new file mode 100644 index 0000000000..c733ffbd18 --- /dev/null +++ b/src/java/org/apache/cassandra/locator/EndpointSnitchInfoMBean.java @@ -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; +}