Beispiel #1
0
 @Override
 public String dropColumnFamily(
     final String keyspaceName, final String columnFamily, final boolean blockUntilComplete)
     throws HectorException {
   Operation<String> op =
       new Operation<String>(
           OperationType.META_WRITE,
           FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE,
           keyspaceName,
           getCredentials()) {
         @Override
         public String execute(Cassandra.Client cassandra) throws HectorException {
           try {
             String schemaId = cassandra.system_drop_column_family(columnFamily);
             if (blockUntilComplete) {
               waitForSchemaAgreement(cassandra);
             }
             return schemaId;
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
         }
       };
   connectionManager.operateWithFailover(op);
   return op.getResult();
 }
Beispiel #2
0
 /* (non-Javadoc)
  * @see me.prettyprint.cassandra.service.Cluster#addHost(me.prettyprint.cassandra.service.CassandraHost, boolean)
  */
 @Override
 public void addHost(CassandraHost cassandraHost, boolean skipApplyConfig) {
   if (!skipApplyConfig && configurator != null) {
     configurator.applyConfig(cassandraHost);
   }
   connectionManager.addCassandraHost(cassandraHost);
 }
 @Override
 public List<String> getKnownHosts() {
   List<String> hosts = new ArrayList<String>();
   for (CassandraHost cassandraHost : connectionManager.getHosts()) {
     hosts.add(cassandraHost.toString());
   }
   return hosts;
 }
 @Override
 public Set<String> getExhaustedPoolNames() {
   Set<String> ret = new HashSet<String>();
   for (CassandraHost host : connectionManager.getDownedHosts()) {
     ret.add(host.toString());
   }
   return ret;
 }
 @Override
 public int getNumIdleConnections() {
   int ret = 0;
   Collection<HClientPool> pools = connectionManager.getActivePools();
   for (HClientPool concurrentHClientPool : pools) {
     ret += concurrentHClientPool.getNumIdle();
   }
   return ret;
 }
 @Override
 public Set<String> getSuspendedCassandraHosts() {
   Set<CassandraHost> hosts = connectionManager.getSuspendedCassandraHosts();
   Set<String> hostsStr = new HashSet<String>();
   for (CassandraHost host : hosts) {
     hostsStr.add(host.getName());
   }
   return hostsStr;
 }
Beispiel #7
0
 /* (non-Javadoc)
  * @see me.prettyprint.cassandra.service.Cluster#getKnownPoolHosts(boolean)
  */
 @Override
 public Set<CassandraHost> getKnownPoolHosts(boolean refresh) {
   if (refresh || knownPoolHosts == null) {
     knownPoolHosts = connectionManager.getHosts();
     if (log.isInfoEnabled()) {
       log.info("found knownPoolHosts: {}", knownPoolHosts);
     }
   }
   return knownPoolHosts;
 }
Beispiel #8
0
 /* (non-Javadoc)
  * @see me.prettyprint.cassandra.service.Cluster#describeThriftVersion()
  */
 @Override
 public String describeThriftVersion() throws HectorException {
   Operation<String> op =
       new Operation<String>(OperationType.META_READ, getCredentials()) {
         @Override
         public String execute(Cassandra.Client cassandra) throws HectorException {
           try {
             return cassandra.describe_version();
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
         }
       };
   connectionManager.operateWithFailover(op);
   return op.getResult();
 }
Beispiel #9
0
 /* (non-Javadoc)
  * @see me.prettyprint.cassandra.service.Cluster#describeKeyspaces()
  */
 @Override
 public List<KeyspaceDefinition> describeKeyspaces() throws HectorException {
   Operation<List<KeyspaceDefinition>> op =
       new Operation<List<KeyspaceDefinition>>(OperationType.META_READ, getCredentials()) {
         @Override
         public List<KeyspaceDefinition> execute(Cassandra.Client cassandra)
             throws HectorException {
           try {
             return ThriftKsDef.fromThriftList(cassandra.describe_keyspaces());
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
         }
       };
   connectionManager.operateWithFailover(op);
   return op.getResult();
 }
Beispiel #10
0
 @Override
 public String describePartitioner() throws HectorException {
   Operation<String> op =
       new Operation<String>(OperationType.META_READ, getCredentials()) {
         @Override
         public String execute(Cassandra.Client cassandra) throws HectorException {
           try {
             if (log.isInfoEnabled()) {
               log.info("in execute with client {}", cassandra);
             }
             return cassandra.describe_partitioner();
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
         }
       };
   connectionManager.operateWithFailover(op);
   return op.getResult();
 }
Beispiel #11
0
 /* (non-Javadoc)
  * @see me.prettyprint.cassandra.service.Cluster#describeKeyspace(java.lang.String)
  */
 @Override
 public KeyspaceDefinition describeKeyspace(final String keyspace) throws HectorException {
   Operation<KeyspaceDefinition> op =
       new Operation<KeyspaceDefinition>(OperationType.META_READ, getCredentials()) {
         @Override
         public KeyspaceDefinition execute(Cassandra.Client cassandra) throws HectorException {
           try {
             return new ThriftKsDef(cassandra.describe_keyspace(keyspace));
           } catch (org.apache.cassandra.thrift.NotFoundException nfe) {
             setException(xtrans.translate(nfe));
             return null;
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
         }
       };
   connectionManager.operateWithFailover(op);
   return op.getResult();
 }
Beispiel #12
0
 @Override
 public String dropKeyspace(final String keyspace, final boolean blockUntilComplete)
     throws HectorException {
   Operation<String> op =
       new Operation<String>(OperationType.META_WRITE, getCredentials()) {
         @Override
         public String execute(Cassandra.Client cassandra) throws HectorException {
           try {
             String schemaId = cassandra.system_drop_keyspace(keyspace);
             if (blockUntilComplete) {
               waitForSchemaAgreement(cassandra);
             }
             return schemaId;
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
         }
       };
   connectionManager.operateWithFailover(op);
   return op.getResult();
 }
Beispiel #13
0
 @Override
 public void truncate(final String keyspaceName, final String columnFamily)
     throws HectorException {
   Operation<Void> op =
       new Operation<Void>(
           OperationType.META_WRITE,
           FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE,
           keyspaceName,
           getCredentials()) {
         @Override
         public Void execute(Cassandra.Client cassandra) throws HectorException {
           try {
             cassandra.truncate(columnFamily);
           } catch (Exception e) {
             throw xtrans.translate(e);
           }
           return null;
         }
       };
   connectionManager.operateWithFailover(op);
 }
 @Override
 public int getNumExhaustedPools() {
   return connectionManager.getDownedHosts().size();
 }
 @Override
 public boolean unsuspendCassandraHost(String hostStr) {
   return connectionManager.unsuspendCassandraHost(new CassandraHost(hostStr));
 }
 @Override
 public boolean removeCassandraHost(String hostStr) {
   return connectionManager.removeCassandraHost(new CassandraHost(hostStr));
 }
 @Override
 public List<String> getStatisticsPerPool() {
   return connectionManager.getStatusPerPool();
 }
 @Override
 public int getNumPools() {
   return connectionManager.getHosts().size();
 }