Skip to content

Commit

Permalink
slight changes to use Cluster class and definitions already defined to
Browse files Browse the repository at this point in the history
check for new nodes.  Originally causing a problem when Cassandra
security it turned on.
  • Loading branch information
nneuberger1 committed May 5, 2011
1 parent f24fd8d commit 41eb445
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

import me.prettyprint.cassandra.service.CassandraHost;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;

import org.apache.cassandra.thrift.AuthenticationRequest;
import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.KsDef;
import org.apache.cassandra.thrift.TokenRange;
import org.slf4j.Logger;
Expand Down Expand Up @@ -77,14 +83,17 @@ public Set<CassandraHost> discoverNodes() {
Set<CassandraHost> existingHosts = connectionManager.getHosts();
Set<CassandraHost> foundHosts = new HashSet<CassandraHost>();

HThriftClient thriftClient = null;
log.info("using existing hosts {}", existingHosts);
try {
thriftClient = connectionManager.borrowClient();

for (KsDef keyspace : thriftClient.getCassandra().describe_keyspaces()) {
if (!keyspace.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
List<TokenRange> tokenRanges = thriftClient.getCassandra().describe_ring(keyspace.getName());

String clusterName = connectionManager.getClusterName();

//this could be suspect, but we need this
ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(clusterName);

for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) {
if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());
for (TokenRange tokenRange : tokenRanges) {
for (String host : tokenRange.getEndpoints()) {
CassandraHost foundHost = new CassandraHost(host,cassandraHostConfigurator.getPort());
Expand All @@ -99,9 +108,10 @@ public Set<CassandraHost> discoverNodes() {
}
} catch (Exception e) {
log.error("Discovery Service failed attempt to connect CassandraHost", e);
} finally {
connectionManager.releaseClient(thriftClient);
}
// } finally {
// connectionManager.releaseClient(thriftClient);
// }
return foundHosts;
}

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/me/prettyprint/hector/api/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Map;
import java.util.Set;

import org.apache.cassandra.thrift.TokenRange;

import me.prettyprint.cassandra.connection.HConnectionManager;
import me.prettyprint.cassandra.service.CassandraHost;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
Expand Down Expand Up @@ -47,6 +49,8 @@ public interface Cluster {
KeyspaceDefinition describeKeyspace(final String keyspace) throws HectorException;

List<KeyspaceDefinition> describeKeyspaces() throws HectorException;

List<TokenRange> describeRing(final String keyspace) throws HectorException;

/**
* Drops the Keyspace from the cluster. Equivalent of 'drop database' in SQL terms
Expand Down

0 comments on commit 41eb445

Please sign in to comment.