Skip to content

Commit

Permalink
Set default rack/dc in ec2snitch to avoid NPEs.
Browse files Browse the repository at this point in the history
Patch by Alex Araujo, reviewed by brandonwilliams for CASSANDRA-3186.

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.8@1202892 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
driftx committed Nov 16, 2011
1 parent 9976ae4 commit 46e61bf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/java/org/apache/cassandra/locator/Ec2Snitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
{
protected static Logger logger = LoggerFactory.getLogger(Ec2Snitch.class);
protected static final String ZONE_NAME_QUERY_URL = "http://169.254.169.254/latest/meta-data/placement/availability-zone";
private static final String DEFAULT_DC = "UNKNOWN-DC";
private static final String DEFAULT_RACK = "UNKNOWN-RACK";
protected String ec2zone;
protected String ec2region;

Expand Down Expand Up @@ -83,14 +85,20 @@ public String getRack(InetAddress endpoint)
{
if (endpoint.equals(FBUtilities.getLocalAddress()))
return ec2zone;
return Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.RACK).value;
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
if (null == state || null == state.getApplicationState(ApplicationState.RACK))
return DEFAULT_RACK;
return state.getApplicationState(ApplicationState.RACK).value;
}

public String getDatacenter(InetAddress endpoint)
{
if (endpoint.equals(FBUtilities.getLocalAddress()))
return ec2region;
return Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState(ApplicationState.DC).value;
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
if (null == state || null == state.getApplicationState(ApplicationState.DC))
return DEFAULT_DC;
return state.getApplicationState(ApplicationState.DC).value;
}

@Override
Expand Down

0 comments on commit 46e61bf

Please sign in to comment.