Example #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();
 }
Example #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);
 }
Example #3
0
 @Override
 public List<String> getKnownHosts() {
   List<String> hosts = new ArrayList<String>();
   for (CassandraHost cassandraHost : connectionManager.getHosts()) {
     hosts.add(cassandraHost.toString());
   }
   return hosts;
 }
Example #4
0
 @Override
 public Set<String> getExhaustedPoolNames() {
   Set<String> ret = new HashSet<String>();
   for (CassandraHost host : connectionManager.getDownedHosts()) {
     ret.add(host.toString());
   }
   return ret;
 }
Example #5
0
 @Override
 public int getNumIdleConnections() {
   int ret = 0;
   Collection<HClientPool> pools = connectionManager.getActivePools();
   for (HClientPool concurrentHClientPool : pools) {
     ret += concurrentHClientPool.getNumIdle();
   }
   return ret;
 }
Example #6
0
 @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;
 }
Example #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;
 }
Example #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();
 }
Example #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();
 }
Example #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();
 }
Example #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();
 }
Example #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();
 }
Example #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);
 }
Example #14
0
 @Override
 public int getNumExhaustedPools() {
   return connectionManager.getDownedHosts().size();
 }
Example #15
0
 @Override
 public boolean unsuspendCassandraHost(String hostStr) {
   return connectionManager.unsuspendCassandraHost(new CassandraHost(hostStr));
 }
Example #16
0
 @Override
 public boolean removeCassandraHost(String hostStr) {
   return connectionManager.removeCassandraHost(new CassandraHost(hostStr));
 }
Example #17
0
 @Override
 public List<String> getStatisticsPerPool() {
   return connectionManager.getStatusPerPool();
 }
Example #18
0
 @Override
 public int getNumPools() {
   return connectionManager.getHosts().size();
 }