private HClientPool getClientFromLBPolicy(Set<CassandraHost> excludeHosts) { if ( hostPools.isEmpty() ) { throw new HectorException("All host pools marked down. Retry burden pushed out to client."); } return loadBalancingPolicy.getPool(hostPoolValues, excludeHosts); }
@Test public void testDescribeKeyspacesBadAuth() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1CredentialsBad); try { cassandraCluster.describeKeyspaces(); fail("Should have gotten a wrapped AuthenticationException"); } catch (HectorException he) { assertTrue(he.getCause() instanceof AuthenticationException); } }
he = new PoolIllegalStateException(original); } else { he = new HectorException(original); he.setHost(host); return he;
public static void main(String[] args) throws Exception { Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160"); Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster); try { Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer); mutator.insert("billing", "Super1", HFactory.createSuperColumn("jsmith", Arrays.asList(HFactory.createStringColumn("first", "John")), stringSerializer, stringSerializer, stringSerializer)); SuperColumnQuery<String, String, String, String> superColumnQuery = HFactory.createSuperColumnQuery(keyspaceOperator, stringSerializer, stringSerializer, stringSerializer, stringSerializer); superColumnQuery.setColumnFamily("Super1").setKey("billing").setSuperName("jsmith"); QueryResult<HSuperColumn<String, String, String>> result = superColumnQuery.execute(); System.out.println("Read HSuperColumn from cassandra: " + result.get()); System.out.println("Verify on CLI with: get Keyspace1.Super1['billing']['jsmith'] "); } catch (HectorException e) { e.printStackTrace(); } cluster.getConnectionManager().shutdown(); } }
public static void main(String[] args) throws Exception { Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160"); Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster); try { Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, StringSerializer.get()); mutator.insert("jsmith", "Standard1", HFactory.createStringColumn("first", "John")); ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(keyspaceOperator); columnQuery.setColumnFamily("Standard1").setKey("jsmith").setName("first"); QueryResult<HColumn<String, String>> result = columnQuery.execute(); System.out.println("Read HColumn from cassandra: " + result.get()); System.out.println("Verify on CLI with: get Keyspace1.Standard1['jsmith'] "); } catch (HectorException e) { e.printStackTrace(); } cluster.getConnectionManager().shutdown(); }
throw new HectorException("Failed to retrieve rows from Cassandra.",e); throw new HectorException("Failed to retrieve rows from Cassandra.",e);
he = new PoolIllegalStateException(original); } else { he = new HectorException(original); he.setHost(host); return he;
@Test public void testInsertAndGetAndRemoveBadAuth() throws IllegalArgumentException, NoSuchElementException, IllegalStateException, HNotFoundException, Exception { KeyspaceService keyspace = new KeyspaceServiceImpl("Keyspace1", new QuorumAllConsistencyLevelPolicy(), connectionManager, FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE, user1CredentialsBad); try { // insert value ColumnPath cp = new ColumnPath("Standard1"); cp.setColumn(bytes("testInsertAndGetAndRemove")); for (int i = 0; i < 100; i++) { keyspace.insert("testInsertAndGetAndRemove_" + i, cp, StringSerializer.get().toByteBuffer("testInsertAndGetAndRemove_value_" + i)); } fail("Should have gotten a wrapped AuthenticationException"); } catch (HectorException he) { assertTrue(he.getCause() instanceof AuthenticationException); } } /**
@Override public List<CounterColumn> execute(Cassandra.Client cassandra) throws HectorException { try { List<ColumnOrSuperColumn> cosclist = cassandra.get_slice(key, columnParent, predicate, getThriftCl(OperationType.READ)); if (cosclist == null) { return null; } ArrayList<CounterColumn> result = new ArrayList<CounterColumn>(cosclist.size()); for (ColumnOrSuperColumn cosc : cosclist) { if (cosc.isSetCounter_column()) { result.add(cosc.getCounter_column()); } else { // Inconsistency throw new HectorException("Regular Column is part of the set of Counter Column"); } } return result; } catch (Exception e) { throw xtrans.translate(e); } } };
throw new HectorException("Unable to clone row with null column family"); throw new HectorException("Unable to clone row with null row key"); throw new HectorException("Unable to clone row with null clone key");
throw new HectorException("HConnectionManager returned a null client after aquisition - are we shutting down?");
/** * Will throw a runtime exception if neither columnsNames nor count were set. * @return */ public SlicePredicate toThrift() { SlicePredicate pred = new SlicePredicate(); switch (predicateType) { case ColumnNames: if (columnNames == null ) { return null; } pred.setColumn_names(toThriftColumnNames(columnNames)); break; case Range: Assert.isTrue(countSet, "Count was not set, neither were column-names set, can't execute"); SliceRange range = new SliceRange(findBytes(start), findBytes(finish), reversed, count); pred.setSlice_range(range); break; case Unknown: default: throw new HectorException( "Neither column names nor range were set, this is an invalid slice predicate"); } return pred; }
private HClientPool getClientFromLBPolicy(Set<CassandraHost> excludeHosts) { if ( hostPools.isEmpty() ) { throw new HectorException("All host pools marked down. Retry burden pushed out to client."); } return loadBalancingPolicy.getPool(hostPoolValues, excludeHosts); }
private HClientPool getClientFromLBPolicy(Set<CassandraHost> excludeHosts) { if ( hostPools.isEmpty() ) { throw new HectorException("All host pools marked down. Retry burden pushed out to client."); } return loadBalancingPolicy.getPool(hostPoolValues, excludeHosts); }