mirror of https://github.com/apache/cassandra
Make-Ec2Region-s-datacenter-name-configurable
patch by Jason Brown; reviewed by Vijay for CASSANDRA-5155
This commit is contained in:
parent
233ea266c8
commit
993945833c
|
|
@ -14,7 +14,11 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This file is specifically for the GossipingPropertyFileSnitch and will
|
||||
# These properties are used with GossipingPropertyFileSnitch and will
|
||||
# indicate the rack and dc for this node
|
||||
dc=DC1
|
||||
rack=RAC1
|
||||
|
||||
# Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch
|
||||
# to append a string to the EC2 region name.
|
||||
#dc_suffix=
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
|
|||
ec2region = az.substring(0, az.length() - 1);
|
||||
if (ec2region.endsWith("1"))
|
||||
ec2region = az.substring(0, az.length() - 3);
|
||||
|
||||
String datacenterSuffix = SnitchProperties.get("dc_suffix", "");
|
||||
ec2region = ec2region.concat(datacenterSuffix);
|
||||
logger.info("EC2Snitch using region: " + ec2region + ", zone: " + ec2zone + ".");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,21 +36,16 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
|
|||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(GossipingPropertyFileSnitch.class);
|
||||
|
||||
public static final String RACKDC_PROPERTY_FILENAME = "cassandra-rackdc.properties";
|
||||
private PropertyFileSnitch psnitch;
|
||||
private String myDC;
|
||||
private String myRack;
|
||||
|
||||
public GossipingPropertyFileSnitch() throws ConfigurationException
|
||||
{
|
||||
try
|
||||
{
|
||||
loadConfiguration();
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to load " + RACKDC_PROPERTY_FILENAME + " : ", e);
|
||||
}
|
||||
myDC = SnitchProperties.get("dc", null);
|
||||
myRack = SnitchProperties.get("rack", null);
|
||||
if (myDC == null || myRack == null)
|
||||
throw new ConfigurationException("DC or rack not found in snitch properties");
|
||||
try
|
||||
{
|
||||
psnitch = new PropertyFileSnitch();
|
||||
|
|
@ -62,35 +57,6 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
|
|||
}
|
||||
}
|
||||
|
||||
private void loadConfiguration() throws ConfigurationException
|
||||
{
|
||||
InputStream stream = GossipingPropertyFileSnitch.class.getClassLoader().getResourceAsStream(RACKDC_PROPERTY_FILENAME);
|
||||
Properties properties = new Properties();
|
||||
try
|
||||
{
|
||||
properties.load(stream);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ConfigurationException("Unable to read " + RACKDC_PROPERTY_FILENAME, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
FileUtils.closeQuietly(stream);
|
||||
}
|
||||
for (Map.Entry<Object, Object> entry : properties.entrySet())
|
||||
{
|
||||
String key = (String) entry.getKey();
|
||||
String value = (String) entry.getValue();
|
||||
if (key.equals("dc"))
|
||||
myDC = value;
|
||||
else if (key.equals("rack"))
|
||||
myRack = value;
|
||||
}
|
||||
if (myDC == null || myRack == null)
|
||||
throw new ConfigurationException("DC or rack not found in " + RACKDC_PROPERTY_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data center for which an endpoint resides in
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.cassandra.io.util.FileUtils;
|
||||
|
||||
public class SnitchProperties
|
||||
{
|
||||
public static final String RACKDC_PROPERTY_FILENAME = "cassandra-rackdc.properties";
|
||||
private static Properties properties = new Properties();
|
||||
|
||||
static
|
||||
{
|
||||
InputStream stream = SnitchProperties.class.getClassLoader().getResourceAsStream(RACKDC_PROPERTY_FILENAME);
|
||||
try
|
||||
{
|
||||
properties.load(stream);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("Unable to read " + RACKDC_PROPERTY_FILENAME, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
FileUtils.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a snitch property value or return null if not defined.
|
||||
*/
|
||||
public static String get(String propertyName, String defaultValue)
|
||||
{
|
||||
return properties.getProperty(propertyName, defaultValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# 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.
|
||||
|
||||
# These properties are used with GossipingPropertyFileSnitch and will
|
||||
# indicate the rack and dc for this node
|
||||
dc=DC1
|
||||
rack=RAC1
|
||||
|
||||
# Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch
|
||||
# to append a string to the EC2 region name.
|
||||
#dc_suffix=
|
||||
Loading…
Reference in New Issue