You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2014/05/03 20:57:34 UTC
[01/13] git commit: Add Cloudstack snitch
Repository: cassandra
Updated Branches:
refs/heads/cassandra-1.2 837bded79 -> 6f4853e78
refs/heads/cassandra-2.0 02e0eb637 -> 3047ab638
refs/heads/cassandra-2.1 341153526 -> b53442b20
refs/heads/trunk 53c91426e -> 2b674656e
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6f4853e7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6f4853e7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6f4853e7
Branch: refs/heads/cassandra-1.2
Commit: 6f4853e78a289c5fd55c523290309b6e87f2014b
Parents: 837bded
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:43:40 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:43:40 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 299 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1c67331..484f4bd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
1.2.17
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
* Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..6d06556
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemTable;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[04/13] git commit: Add Cloudstack snitch
Posted by br...@apache.org.
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6f4853e7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6f4853e7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6f4853e7
Branch: refs/heads/cassandra-2.1
Commit: 6f4853e78a289c5fd55c523290309b6e87f2014b
Parents: 837bded
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:43:40 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:43:40 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 299 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1c67331..484f4bd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
1.2.17
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
* Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..6d06556
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemTable;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[11/13] git commit: Merge branch 'cassandra-2.0' into cassandra-2.1
Posted by br...@apache.org.
Merge branch 'cassandra-2.0' into cassandra-2.1
Conflicts:
CHANGES.txt
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b53442b2
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b53442b2
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b53442b2
Branch: refs/heads/cassandra-2.1
Commit: b53442b20cd0b74a84e88e1ba578621984eb1ecd
Parents: 3411535 3047ab6
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:51:13 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:53:28 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 112 +++++++++++
3 files changed, 301 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b53442b2/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 4afad9d,8570784..4b8dfe6
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,75 -1,40 +1,76 @@@
-2.0.8
+2.1.0-rc1
+ * Parallel streaming for sstableloader (CASSANDRA-3668)
+Merged from 2.0:
* Make batchlog replica selection rack-aware (CASSANDRA-6551)
- * Add Google Compute Engine snitch (CASSANDRA-7132)
- * Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
- * Set JMX RMI port to 7199 (CASSANDRA-7087)
- * Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
- * Log a warning for large batches (CASSANDRA-6487)
- * Queries on compact tables can return more rows that requested (CASSANDRA-7052)
- * USING TIMESTAMP for batches does not work (CASSANDRA-7053)
- * Fix performance regression from CASSANDRA-5614 (CASSANDRA-6949)
- * Merge groupable mutations in TriggerExecutor#execute() (CASSANDRA-7047)
- * Fix CFMetaData#getColumnDefinitionFromColumnName() (CASSANDRA-7074)
- * Plug holes in resource release when wiring up StreamSession (CASSANDRA-7073)
- * Re-add parameter columns to tracing session (CASSANDRA-6942)
- * Fix writetime/ttl functions for static columns (CASSANDRA-7081)
Merged from 1.2:
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
+ * Add Google Compute Engine snitch (CASSANDRA-7132)
- * Fix nodetool display with vnodes (CASSANDRA-7082)
- * Fix schema concurrency exceptions (CASSANDRA-6841)
- * Fix BatchlogManager#deleteBatch() use of millisecond timsestamps
- (CASSANDRA-6822)
- * Continue assassinating even if the endpoint vanishes (CASSANDRA-6787)
- * Schedule schema pulls on change (CASSANDRA-6971)
- * Non-droppable verbs shouldn't be dropped from OTC (CASSANDRA-6980)
- * Shutdown batchlog executor in SS#drain() (CASSANDRA-7025)
- * Fix batchlog to account for CF truncation records (CASSANDRA-6999)
- * Fix CQLSH parsing of functions and BLOB literals (CASSANDRA-7018)
- * Require nodetool rebuild_index to specify index names (CASSANDRA-7038)
- * Ensure that batchlog and hint timeouts do not produce hints (CASSANDRA-7058)
- * Always clean up references in SerializingCache (CASSANDRA-6994)
- * Don't shut MessagingService down when replacing a node (CASSANDRA-6476)
- * fix npe when doing -Dcassandra.fd_initial_value_ms (CASSANDRA-6751)
- * Preserves CQL metadata when updating table from thrift (CASSANDRA-6831)
-
-2.0.7
+2.1.0-beta2
+ * Increase default CL space to 8GB (CASSANDRA-7031)
+ * Add range tombstones to read repair digests (CASSANDRA-6863)
+ * Fix BTree.clear for large updates (CASSANDRA-6943)
+ * Fail write instead of logging a warning when unable to append to CL
+ (CASSANDRA-6764)
+ * Eliminate possibility of CL segment appearing twice in active list
+ (CASSANDRA-6557)
+ * Apply DONTNEED fadvise to commitlog segments (CASSANDRA-6759)
+ * Switch CRC component to Adler and include it for compressed sstables
+ (CASSANDRA-4165)
+ * Allow cassandra-stress to set compaction strategy options (CASSANDRA-6451)
+ * Add broadcast_rpc_address option to cassandra.yaml (CASSANDRA-5899)
+ * Auto reload GossipingPropertyFileSnitch config (CASSANDRA-5897)
+ * Fix overflow of memtable_total_space_in_mb (CASSANDRA-6573)
+ * Fix ABTC NPE and apply update function correctly (CASSANDRA-6692)
+ * Allow nodetool to use a file or prompt for password (CASSANDRA-6660)
+ * Fix AIOOBE when concurrently accessing ABSC (CASSANDRA-6742)
+ * Fix assertion error in ALTER TYPE RENAME (CASSANDRA-6705)
+ * Scrub should not always clear out repaired status (CASSANDRA-5351)
+ * Improve handling of range tombstone for wide partitions (CASSANDRA-6446)
+ * Fix ClassCastException for compact table with composites (CASSANDRA-6738)
+ * Fix potentially repairing with wrong nodes (CASSANDRA-6808)
+ * Change caching option syntax (CASSANDRA-6745)
+ * Fix stress to do proper counter reads (CASSANDRA-6835)
+ * Fix help message for stress counter_write (CASSANDRA-6824)
+ * Fix stress smart Thrift client to pick servers correctly (CASSANDRA-6848)
+ * Add logging levels (minimal, normal or verbose) to stress tool (CASSANDRA-6849)
+ * Fix race condition in Batch CLE (CASSANDRA-6860)
+ * Improve cleanup/scrub/upgradesstables failure handling (CASSANDRA-6774)
+ * ByteBuffer write() methods for serializing sstables (CASSANDRA-6781)
+ * Proper compare function for CollectionType (CASSANDRA-6783)
+ * Update native server to Netty 4 (CASSANDRA-6236)
+ * Fix off-by-one error in stress (CASSANDRA-6883)
+ * Make OpOrder AutoCloseable (CASSANDRA-6901)
+ * Remove sync repair JMX interface (CASSANDRA-6900)
+ * Add multiple memory allocation options for memtables (CASSANDRA-6689, 6694)
+ * Remove adjusted op rate from stress output (CASSANDRA-6921)
+ * Add optimized CF.hasColumns() implementations (CASSANDRA-6941)
+ * Serialize batchlog mutations with the version of the target node
+ (CASSANDRA-6931)
+ * Optimize CounterColumn#reconcile() (CASSANDRA-6953)
+ * Properly remove 1.2 sstable support in 2.1 (CASSANDRA-6869)
+ * Lock counter cells, not partitions (CASSANDRA-6880)
+ * Track presence of legacy counter shards in sstables (CASSANDRA-6888)
+ * Ensure safe resource cleanup when replacing sstables (CASSANDRA-6912)
+ * Add failure handler to async callback (CASSANDRA-6747)
+ * Fix AE when closing SSTable without releasing reference (CASSANDRA-7000)
+ * Clean up IndexInfo on keyspace/table drops (CASSANDRA-6924)
+ * Only snapshot relative SSTables when sequential repair (CASSANDRA-7024)
+ * Require nodetool rebuild_index to specify index names (CASSANDRA-7038)
+ * fix cassandra stress errors on reads with native protocol (CASSANDRA-7033)
+ * Use OpOrder to guard sstable references for reads (CASSANDRA-6919)
+ * Preemptive opening of compaction result (CASSANDRA-6916)
+ * Multi-threaded scrub/cleanup/upgradesstables (CASSANDRA-5547)
+ * Optimize cellname comparison (CASSANDRA-6934)
+ * Native protocol v3 (CASSANDRA-6855)
+ * Optimize Cell liveness checks and clean up Cell (CASSANDRA-7119)
+ * Support consistent range movements (CASSANDRA-2434)
+Merged from 2.0:
+ * Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
+ * Set JMX RMI port to 7199 (CASSANDRA-7087)
+ * Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
+ * Log a warning for large batches (CASSANDRA-6487)
* Put nodes in hibernate when join_ring is false (CASSANDRA-6961)
* Avoid early loading of non-system keyspaces before compaction-leftovers
cleanup at startup (CASSANDRA-6913)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b53442b2/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
index 0000000,7e483a9..714520e
mode 000000,100644..100644
--- a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@@ -1,0 -1,111 +1,112 @@@
+ /*
+ * 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.IOException;
+ import java.net.InetAddress;
+ import java.net.UnknownHostException;
+ import java.util.Map;
+
+ import org.junit.AfterClass;
+ import org.junit.Assert;
+ import org.junit.BeforeClass;
+ import org.junit.Test;
+
+ import org.apache.cassandra.SchemaLoader;
+ import org.apache.cassandra.exceptions.ConfigurationException;
+ import org.apache.cassandra.gms.ApplicationState;
+ import org.apache.cassandra.gms.Gossiper;
+ import org.apache.cassandra.gms.VersionedValue;
+ import org.apache.cassandra.net.MessagingService;
+ import org.apache.cassandra.net.OutboundTcpConnectionPool;
+ import org.apache.cassandra.service.StorageService;
++import org.apache.cassandra.db.Keyspace;
+
+ import static org.junit.Assert.assertEquals;
+
+ public class CloudstackSnitchTest
+ {
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
++ Keyspace.setInitialized();
+ StorageService.instance.initServer(0);
-
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+ }
[10/13] git commit: Add Cloudstack snitch
Posted by br...@apache.org.
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/3047ab63
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/3047ab63
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/3047ab63
Branch: refs/heads/cassandra-2.0
Commit: 3047ab63875b3ac5dd716bddd5eb3e321af09eaf
Parents: d3e7780
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:46:20 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:47:48 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 300 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5799659..8570784 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,5 @@
2.0.8
* Make batchlog replica selection rack-aware (CASSANDRA-6551)
- * Add Google Compute Engine snitch (CASSANDRA-7132)
* Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
* Set JMX RMI port to 7199 (CASSANDRA-7087)
* Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
@@ -14,7 +13,9 @@
* Re-add parameter columns to tracing session (CASSANDRA-6942)
* Fix writetime/ttl functions for static columns (CASSANDRA-7081)
Merged from 1.2:
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
+ * Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
* Fix schema concurrency exceptions (CASSANDRA-6841)
* Fix BatchlogManager#deleteBatch() use of millisecond timsestamps
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..ecf0f20
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemKeyspace.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemKeyspace.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[05/13] git commit: Merge branch 'cassandra-1.2' into cassandra-2.0
Posted by br...@apache.org.
Merge branch 'cassandra-1.2' into cassandra-2.0
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d3e77804
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d3e77804
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d3e77804
Branch: refs/heads/cassandra-2.1
Commit: d3e778041b988b386b55b0060830d88684e79de6
Parents: 02e0eb6 6f4853e
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:44:30 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:44:30 2014 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------
[08/13] git commit: Add Cloudstack snitch
Posted by br...@apache.org.
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/3047ab63
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/3047ab63
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/3047ab63
Branch: refs/heads/cassandra-2.1
Commit: 3047ab63875b3ac5dd716bddd5eb3e321af09eaf
Parents: d3e7780
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:46:20 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:47:48 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 300 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5799659..8570784 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,5 @@
2.0.8
* Make batchlog replica selection rack-aware (CASSANDRA-6551)
- * Add Google Compute Engine snitch (CASSANDRA-7132)
* Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
* Set JMX RMI port to 7199 (CASSANDRA-7087)
* Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
@@ -14,7 +13,9 @@
* Re-add parameter columns to tracing session (CASSANDRA-6942)
* Fix writetime/ttl functions for static columns (CASSANDRA-7081)
Merged from 1.2:
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
+ * Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
* Fix schema concurrency exceptions (CASSANDRA-6841)
* Fix BatchlogManager#deleteBatch() use of millisecond timsestamps
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..ecf0f20
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemKeyspace.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemKeyspace.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[06/13] git commit: Merge branch 'cassandra-1.2' into cassandra-2.0
Posted by br...@apache.org.
Merge branch 'cassandra-1.2' into cassandra-2.0
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d3e77804
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d3e77804
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d3e77804
Branch: refs/heads/trunk
Commit: d3e778041b988b386b55b0060830d88684e79de6
Parents: 02e0eb6 6f4853e
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:44:30 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:44:30 2014 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------
[07/13] git commit: Merge branch 'cassandra-1.2' into cassandra-2.0
Posted by br...@apache.org.
Merge branch 'cassandra-1.2' into cassandra-2.0
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d3e77804
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d3e77804
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d3e77804
Branch: refs/heads/cassandra-2.0
Commit: d3e778041b988b386b55b0060830d88684e79de6
Parents: 02e0eb6 6f4853e
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:44:30 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:44:30 2014 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------
[13/13] git commit: Merge branch 'cassandra-2.1' into trunk
Posted by br...@apache.org.
Merge branch 'cassandra-2.1' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2b674656
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2b674656
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2b674656
Branch: refs/heads/trunk
Commit: 2b674656e955ec466e5d1fb60d2d7d567c3d459b
Parents: 53c9142 b53442b
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:53:38 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:53:38 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 112 +++++++++++
3 files changed, 301 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/2b674656/CHANGES.txt
----------------------------------------------------------------------
[09/13] git commit: Add Cloudstack snitch
Posted by br...@apache.org.
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/3047ab63
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/3047ab63
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/3047ab63
Branch: refs/heads/trunk
Commit: 3047ab63875b3ac5dd716bddd5eb3e321af09eaf
Parents: d3e7780
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:46:20 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:47:48 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 300 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5799659..8570784 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,5 @@
2.0.8
* Make batchlog replica selection rack-aware (CASSANDRA-6551)
- * Add Google Compute Engine snitch (CASSANDRA-7132)
* Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
* Set JMX RMI port to 7199 (CASSANDRA-7087)
* Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
@@ -14,7 +13,9 @@
* Re-add parameter columns to tracing session (CASSANDRA-6942)
* Fix writetime/ttl functions for static columns (CASSANDRA-7081)
Merged from 1.2:
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
+ * Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
* Fix schema concurrency exceptions (CASSANDRA-6841)
* Fix BatchlogManager#deleteBatch() use of millisecond timsestamps
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..ecf0f20
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemKeyspace.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemKeyspace.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3047ab63/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[02/13] git commit: Add Cloudstack snitch
Posted by br...@apache.org.
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6f4853e7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6f4853e7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6f4853e7
Branch: refs/heads/trunk
Commit: 6f4853e78a289c5fd55c523290309b6e87f2014b
Parents: 837bded
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:43:40 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:43:40 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 299 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1c67331..484f4bd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
1.2.17
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
* Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..6d06556
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemTable;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[03/13] git commit: Add Cloudstack snitch
Posted by br...@apache.org.
Add Cloudstack snitch
Patch by Pierre-Yves Ritschard, reviewed by brandonwilliams for
CASSANDRA-7147
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6f4853e7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6f4853e7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6f4853e7
Branch: refs/heads/cassandra-2.0
Commit: 6f4853e78a289c5fd55c523290309b6e87f2014b
Parents: 837bded
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:43:40 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:43:40 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 111 +++++++++++
3 files changed, 299 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1c67331..484f4bd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
1.2.17
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
* Add Google Compute Engine snitch (CASSANDRA-7132)
* Fix nodetool display with vnodes (CASSANDRA-7082)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
new file mode 100644
index 0000000..6d06556
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -0,0 +1,187 @@
+/*
+ * 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.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.cassandra.db.SystemTable;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.FBUtilities;
+
+/**
+ * A snitch that assumes a Cloudstack Zone follows the typical convention
+ * <country>-<location>-<availability zone> and uses the country/location
+ * tuple as a datacenter and the availability zone as a rack
+ */
+
+public class CloudstackSnitch extends AbstractNetworkTopologySnitch
+{
+ protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
+ protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
+
+ private Map<InetAddress, Map<String, String>> savedEndpoints;
+
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+ private static final String[] LEASE_FILES = {
+ "file:///var/lib/dhcp/dhclient.eth0.leases",
+ "file:///var/lib/dhclient/dhclient.eth0.leases"
+ };
+
+ protected String csZoneDc;
+ protected String csZoneRack;
+
+ public CloudstackSnitch() throws IOException, ConfigurationException
+ {
+ String endpoint = csMetadataEndpoint();
+ String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
+ String zone_parts[] = zone.split("-");
+
+ if (zone_parts.length != 3) {
+ throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
+ }
+ csZoneDc = zone_parts[0] + "-" + zone_parts[1];
+ csZoneRack = zone_parts[2];
+ }
+
+ public String getRack(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneRack;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("rack");
+ return DEFAULT_RACK;
+ }
+ return state.getApplicationState(ApplicationState.RACK).value;
+ }
+
+ public String getDatacenter(InetAddress endpoint)
+ {
+ if (endpoint.equals(FBUtilities.getBroadcastAddress()))
+ return csZoneDc;
+ EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
+ if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+ if (savedEndpoints == null)
+ savedEndpoints = SystemTable.loadDcRackInfo();
+ if (savedEndpoints.containsKey(endpoint))
+ return savedEndpoints.get(endpoint).get("data_center");
+ return DEFAULT_DC;
+ }
+ return state.getApplicationState(ApplicationState.DC).value;
+ }
+
+ String csQueryMetadata(String url) throws ConfigurationException, IOException
+ {
+ HttpURLConnection conn = null;
+ BufferedInputStream is = null;
+
+ try {
+ conn = (HttpURLConnection) new URL(url).openConnection();
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
+ }
+ try {
+ conn.setRequestMethod("GET");
+ if (conn.getResponseCode() != 200) {
+ throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
+ }
+
+ int cl = conn.getContentLength();
+ byte[] b = new byte[cl];
+ is = new BufferedInputStream(conn.getInputStream());
+ is.read(b, 0, cl);
+ return new String(b, StandardCharsets.UTF_8);
+ } finally {
+ FileUtils.close(is);
+ conn.disconnect();
+ }
+
+ }
+
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ for (String lease_uri: LEASE_FILES) {
+ try {
+ File lease_file = new File(new URI(lease_uri));
+ if (lease_file.exists()) {
+ return csEndpointFromLease(lease_file);
+ }
+
+ } catch (Exception e) {
+ continue;
+ }
+
+
+ }
+
+ throw new ConfigurationException("No valid DHCP lease file could be found.");
+ }
+
+ String csEndpointFromLease(File lease) throws ConfigurationException, IOException
+ {
+ BufferedReader reader = null;
+
+ String line = null;
+ String endpoint = null;
+ Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
+
+ try {
+ reader = new BufferedReader(new FileReader(lease));
+ } catch (Exception e) {
+ throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+ }
+
+ while ((line = reader.readLine()) != null) {
+ Matcher matcher = identifierPattern.matcher(line);
+
+ if (matcher.find()) {
+ endpoint = matcher.group(1);
+ }
+ }
+
+ if (endpoint == null) {
+ throw new ConfigurationException("No metadata server could be found in lease file.");
+ }
+
+ return "http://" + endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/6f4853e7/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
new file mode 100644
index 0000000..7e483a9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.net.OutboundTcpConnectionPool;
+import org.apache.cassandra.service.StorageService;
+
+import static org.junit.Assert.assertEquals;
+
+public class CloudstackSnitchTest
+{
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
+ StorageService.instance.initServer(0);
+
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+}
[12/13] git commit: Merge branch 'cassandra-2.0' into cassandra-2.1
Posted by br...@apache.org.
Merge branch 'cassandra-2.0' into cassandra-2.1
Conflicts:
CHANGES.txt
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b53442b2
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b53442b2
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b53442b2
Branch: refs/heads/trunk
Commit: b53442b20cd0b74a84e88e1ba578621984eb1ecd
Parents: 3411535 3047ab6
Author: Brandon Williams <br...@apache.org>
Authored: Sat May 3 13:51:13 2014 -0500
Committer: Brandon Williams <br...@apache.org>
Committed: Sat May 3 13:53:28 2014 -0500
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../cassandra/locator/CloudstackSnitch.java | 187 +++++++++++++++++++
.../cassandra/locator/CloudstackSnitchTest.java | 112 +++++++++++
3 files changed, 301 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b53442b2/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 4afad9d,8570784..4b8dfe6
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,75 -1,40 +1,76 @@@
-2.0.8
+2.1.0-rc1
+ * Parallel streaming for sstableloader (CASSANDRA-3668)
+Merged from 2.0:
* Make batchlog replica selection rack-aware (CASSANDRA-6551)
- * Add Google Compute Engine snitch (CASSANDRA-7132)
- * Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
- * Set JMX RMI port to 7199 (CASSANDRA-7087)
- * Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
- * Log a warning for large batches (CASSANDRA-6487)
- * Queries on compact tables can return more rows that requested (CASSANDRA-7052)
- * USING TIMESTAMP for batches does not work (CASSANDRA-7053)
- * Fix performance regression from CASSANDRA-5614 (CASSANDRA-6949)
- * Merge groupable mutations in TriggerExecutor#execute() (CASSANDRA-7047)
- * Fix CFMetaData#getColumnDefinitionFromColumnName() (CASSANDRA-7074)
- * Plug holes in resource release when wiring up StreamSession (CASSANDRA-7073)
- * Re-add parameter columns to tracing session (CASSANDRA-6942)
- * Fix writetime/ttl functions for static columns (CASSANDRA-7081)
Merged from 1.2:
+ * Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)
+ * Add Google Compute Engine snitch (CASSANDRA-7132)
- * Fix nodetool display with vnodes (CASSANDRA-7082)
- * Fix schema concurrency exceptions (CASSANDRA-6841)
- * Fix BatchlogManager#deleteBatch() use of millisecond timsestamps
- (CASSANDRA-6822)
- * Continue assassinating even if the endpoint vanishes (CASSANDRA-6787)
- * Schedule schema pulls on change (CASSANDRA-6971)
- * Non-droppable verbs shouldn't be dropped from OTC (CASSANDRA-6980)
- * Shutdown batchlog executor in SS#drain() (CASSANDRA-7025)
- * Fix batchlog to account for CF truncation records (CASSANDRA-6999)
- * Fix CQLSH parsing of functions and BLOB literals (CASSANDRA-7018)
- * Require nodetool rebuild_index to specify index names (CASSANDRA-7038)
- * Ensure that batchlog and hint timeouts do not produce hints (CASSANDRA-7058)
- * Always clean up references in SerializingCache (CASSANDRA-6994)
- * Don't shut MessagingService down when replacing a node (CASSANDRA-6476)
- * fix npe when doing -Dcassandra.fd_initial_value_ms (CASSANDRA-6751)
- * Preserves CQL metadata when updating table from thrift (CASSANDRA-6831)
-
-2.0.7
+2.1.0-beta2
+ * Increase default CL space to 8GB (CASSANDRA-7031)
+ * Add range tombstones to read repair digests (CASSANDRA-6863)
+ * Fix BTree.clear for large updates (CASSANDRA-6943)
+ * Fail write instead of logging a warning when unable to append to CL
+ (CASSANDRA-6764)
+ * Eliminate possibility of CL segment appearing twice in active list
+ (CASSANDRA-6557)
+ * Apply DONTNEED fadvise to commitlog segments (CASSANDRA-6759)
+ * Switch CRC component to Adler and include it for compressed sstables
+ (CASSANDRA-4165)
+ * Allow cassandra-stress to set compaction strategy options (CASSANDRA-6451)
+ * Add broadcast_rpc_address option to cassandra.yaml (CASSANDRA-5899)
+ * Auto reload GossipingPropertyFileSnitch config (CASSANDRA-5897)
+ * Fix overflow of memtable_total_space_in_mb (CASSANDRA-6573)
+ * Fix ABTC NPE and apply update function correctly (CASSANDRA-6692)
+ * Allow nodetool to use a file or prompt for password (CASSANDRA-6660)
+ * Fix AIOOBE when concurrently accessing ABSC (CASSANDRA-6742)
+ * Fix assertion error in ALTER TYPE RENAME (CASSANDRA-6705)
+ * Scrub should not always clear out repaired status (CASSANDRA-5351)
+ * Improve handling of range tombstone for wide partitions (CASSANDRA-6446)
+ * Fix ClassCastException for compact table with composites (CASSANDRA-6738)
+ * Fix potentially repairing with wrong nodes (CASSANDRA-6808)
+ * Change caching option syntax (CASSANDRA-6745)
+ * Fix stress to do proper counter reads (CASSANDRA-6835)
+ * Fix help message for stress counter_write (CASSANDRA-6824)
+ * Fix stress smart Thrift client to pick servers correctly (CASSANDRA-6848)
+ * Add logging levels (minimal, normal or verbose) to stress tool (CASSANDRA-6849)
+ * Fix race condition in Batch CLE (CASSANDRA-6860)
+ * Improve cleanup/scrub/upgradesstables failure handling (CASSANDRA-6774)
+ * ByteBuffer write() methods for serializing sstables (CASSANDRA-6781)
+ * Proper compare function for CollectionType (CASSANDRA-6783)
+ * Update native server to Netty 4 (CASSANDRA-6236)
+ * Fix off-by-one error in stress (CASSANDRA-6883)
+ * Make OpOrder AutoCloseable (CASSANDRA-6901)
+ * Remove sync repair JMX interface (CASSANDRA-6900)
+ * Add multiple memory allocation options for memtables (CASSANDRA-6689, 6694)
+ * Remove adjusted op rate from stress output (CASSANDRA-6921)
+ * Add optimized CF.hasColumns() implementations (CASSANDRA-6941)
+ * Serialize batchlog mutations with the version of the target node
+ (CASSANDRA-6931)
+ * Optimize CounterColumn#reconcile() (CASSANDRA-6953)
+ * Properly remove 1.2 sstable support in 2.1 (CASSANDRA-6869)
+ * Lock counter cells, not partitions (CASSANDRA-6880)
+ * Track presence of legacy counter shards in sstables (CASSANDRA-6888)
+ * Ensure safe resource cleanup when replacing sstables (CASSANDRA-6912)
+ * Add failure handler to async callback (CASSANDRA-6747)
+ * Fix AE when closing SSTable without releasing reference (CASSANDRA-7000)
+ * Clean up IndexInfo on keyspace/table drops (CASSANDRA-6924)
+ * Only snapshot relative SSTables when sequential repair (CASSANDRA-7024)
+ * Require nodetool rebuild_index to specify index names (CASSANDRA-7038)
+ * fix cassandra stress errors on reads with native protocol (CASSANDRA-7033)
+ * Use OpOrder to guard sstable references for reads (CASSANDRA-6919)
+ * Preemptive opening of compaction result (CASSANDRA-6916)
+ * Multi-threaded scrub/cleanup/upgradesstables (CASSANDRA-5547)
+ * Optimize cellname comparison (CASSANDRA-6934)
+ * Native protocol v3 (CASSANDRA-6855)
+ * Optimize Cell liveness checks and clean up Cell (CASSANDRA-7119)
+ * Support consistent range movements (CASSANDRA-2434)
+Merged from 2.0:
+ * Allow overriding cassandra-rackdc.properties file (CASSANDRA-7072)
+ * Set JMX RMI port to 7199 (CASSANDRA-7087)
+ * Use LOCAL_QUORUM for data reads at LOCAL_SERIAL (CASSANDRA-6939)
+ * Log a warning for large batches (CASSANDRA-6487)
* Put nodes in hibernate when join_ring is false (CASSANDRA-6961)
* Avoid early loading of non-system keyspaces before compaction-leftovers
cleanup at startup (CASSANDRA-6913)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b53442b2/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
index 0000000,7e483a9..714520e
mode 000000,100644..100644
--- a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
+++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java
@@@ -1,0 -1,111 +1,112 @@@
+ /*
+ * 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.IOException;
+ import java.net.InetAddress;
+ import java.net.UnknownHostException;
+ import java.util.Map;
+
+ import org.junit.AfterClass;
+ import org.junit.Assert;
+ import org.junit.BeforeClass;
+ import org.junit.Test;
+
+ import org.apache.cassandra.SchemaLoader;
+ import org.apache.cassandra.exceptions.ConfigurationException;
+ import org.apache.cassandra.gms.ApplicationState;
+ import org.apache.cassandra.gms.Gossiper;
+ import org.apache.cassandra.gms.VersionedValue;
+ import org.apache.cassandra.net.MessagingService;
+ import org.apache.cassandra.net.OutboundTcpConnectionPool;
+ import org.apache.cassandra.service.StorageService;
++import org.apache.cassandra.db.Keyspace;
+
+ import static org.junit.Assert.assertEquals;
+
+ public class CloudstackSnitchTest
+ {
+ private static String az;
+
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ SchemaLoader.mkdirs();
+ SchemaLoader.cleanup();
++ Keyspace.setInitialized();
+ StorageService.instance.initServer(0);
-
+ }
+
+ private class TestCloudstackSnitch extends CloudstackSnitch
+ {
+ public TestCloudstackSnitch() throws IOException, ConfigurationException
+ {
+ super();
+ }
+
+ @Override
+ String csMetadataEndpoint() throws ConfigurationException
+ {
+ return "";
+ }
+
+ @Override
+ String csQueryMetadata(String endpoint) throws IOException, ConfigurationException
+ {
+ return az;
+ }
+ }
+
+ @Test
+ public void testRacks() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+ InetAddress nonlocal = InetAddress.getByName("127.0.0.7");
+
+ Gossiper.instance.addSavedEndpoint(nonlocal);
+ Map<ApplicationState,VersionedValue> stateMap = Gossiper.instance.getEndpointStateForEndpoint(nonlocal).getApplicationStateMap();
+ stateMap.put(ApplicationState.DC, StorageService.instance.valueFactory.datacenter("ch-zrh"));
+ stateMap.put(ApplicationState.RACK, StorageService.instance.valueFactory.rack("2"));
+
+ assertEquals("ch-zrh", snitch.getDatacenter(nonlocal));
+ assertEquals("2", snitch.getRack(nonlocal));
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+
+ }
+
+ @Test
+ public void testNewRegions() throws IOException, ConfigurationException
+ {
+ az = "ch-gva-1";
+ CloudstackSnitch snitch = new TestCloudstackSnitch();
+ InetAddress local = InetAddress.getByName("127.0.0.1");
+
+ assertEquals("ch-gva", snitch.getDatacenter(local));
+ assertEquals("1", snitch.getRack(local));
+ }
+
+ @AfterClass
+ public static void tearDown()
+ {
+ StorageService.instance.stopClient();
+ }
+ }