public HInvalidRequestException(String msg) { super(msg); setWhy(msg); } public HInvalidRequestException(Throwable t) {
/** * This method intentionally swallows ordered execution issues. For some reason, our Time UUID ordering does * not agree with the cassandra comparator as our micros get very close * @param query * @param <K> * @param <UUID> * @param <V> * @return */ protected static <K, UUID, V> List<HColumn<UUID, V>> swallowOrderedExecution( final SliceQuery<K, UUID, V> query ) { try { return query.execute().get().getColumns(); } catch ( HInvalidRequestException e ) { //invalid request. Occasionally we get order issues when there shouldn't be, disregard them. final Throwable invalidRequestException = e.getCause(); if ( invalidRequestException instanceof InvalidRequestException //we had a range error && ( ( InvalidRequestException ) invalidRequestException ).getWhy().contains( "range finish must come after start in the order of traversal" )) { return Collections.emptyList(); } throw e; } }
he = (HectorException) original; } else if (original instanceof TApplicationException) { he = new HCassandraInternalException(((TApplicationException)original).getType(), original.getMessage()); } else if (original instanceof TTransportException) { he = new HTimedOutException(original); } else { he = new HectorTransportException(original); he = new HTimedOutException(original); } else if (original instanceof org.apache.cassandra.thrift.InvalidRequestException) { he = new HUnavailableException(original); } else { HInvalidRequestException e = new HInvalidRequestException(original); e.setWhy(why); he = e; he = new HInvalidRequestException(original); } else if (original instanceof org.apache.cassandra.thrift.NotFoundException) { he = new HNotFoundException(original); } else if (original instanceof org.apache.cassandra.thrift.UnavailableException) { he = new HUnavailableException(original); } else if (original instanceof TException) { he = new HectorTransportException(original); } else if (original instanceof NoSuchElementException) { he = new HPoolExhaustedException(original); } else if (original instanceof IllegalStateException) { he = new PoolIllegalStateException(original);
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); }
@Override public HClient borrowClient() throws HectorException { if ( !active.get() ) { throw new HInactivePoolException("Attempt to borrow on in-active pool: " + getName()); throw new HectorException("HConnectionManager returned a null client after aquisition - are we shutting down?");
@Override public S fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasArray()) { return null; } bytes = bytes.duplicate(); bytes.rewind(); if (bytes.limit() < prefixBytes.remaining()) { log.error("Unprefixed value received, throwing exception..."); throw new HectorSerializationException("Unexpected prefix value"); } if (compareByteArrays(prefixBytes.array(), prefixBytes.arrayOffset() + prefixBytes.position(), prefixBytes.remaining(), bytes.array(), bytes.arrayOffset() + bytes.position(), prefixBytes.remaining()) != 0) { return null; // incorrect prefix, return nothing } bytes.position(prefixBytes.remaining()); S s = suffixSerializer.fromByteBuffer(bytes); return s; }
@Override public String execute(Client cassandra) throws HectorException { throw new HTimedOutException("fake timeout"); } }
socket = TSSLTransportFactory.getClientSocket(cassandraHost.getHost(), cassandraHost.getPort(), timeout, params); } catch (TTransportException e) { throw new HectorTransportException("Could not get client socket: ", e); socket.getSocket().setKeepAlive(true); } catch (SocketException se) { throw new HectorTransportException("Could not set SO_KEEPALIVE on socket: ", se); log.error("Kerberos login failed: ", e); close(); throw new HectorTransportException("Kerberos context couldn't be established with client: ", e); } catch (TTransportException e) { log.error("Failed to open Kerberos transport.", e); close(); throw new HectorTransportException("Kerberos context couldn't be established with client: ", e);
/** * {@inheritDoc} */ public Cassandra.Client getCassandra(String keyspaceNameArg) { getCassandra(); if ( keyspaceNameArg != null && !StringUtils.equals(keyspaceName, keyspaceNameArg)) { if ( log.isDebugEnabled() ) log.debug("keyspace reseting from {} to {}", keyspaceName, keyspaceNameArg); try { cassandraClient.set_keyspace(keyspaceNameArg); } catch (InvalidRequestException ire) { throw new HInvalidRequestException(ire); } catch (TException e) { throw exceptionsTranslator.translate(e); } keyspaceName = keyspaceNameArg; } return cassandraClient; }
cassandraClient = availableClientQueue.poll(maxWaitTimeWhenExhausted, TimeUnit.MILLISECONDS); if (cassandraClient == null) { throw new HPoolExhaustedException(String.format( "maxWaitTimeWhenExhausted exceeded for thread %s on host %s", new Object[] { Thread.currentThread().getName(), cassandraHost.getName() }));
private boolean verifyConnection(CassandraHost cassandraHost) { if ( cassandraHost == null ) { return false; } boolean found = false; HClient client = clientFactory.createClient(cassandraHost); try { client.open(); found = client.getCassandra().describe_cluster_name() != null; client.close(); } catch (HectorTransportException he) { log.warn("Downed {} host still appears to be down: {}", cassandraHost, he.getMessage()); } catch (Throwable t) { log.error("Downed Host retry failed attempt to verify CassandraHost", t); } return found; } }
@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); } }
@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); } } };
/** {@inheritDoc} */ @Override public ByteBuffer toByteBuffer(Object obj) { if (obj == null) { return null; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { XMLStreamWriter writer = createStreamWriter(buffer); marshaller.get().marshal(obj, writer); writer.flush(); writer.close(); } catch (JAXBException e) { throw new HectorSerializationException("Object to serialize " + obj + " does not seem compatible with the configured JaxbContext;" + " note this Serializer works only with JAXBable objects.", e); } catch (XMLStreamException e) { throw new HectorSerializationException( "Exception occurred writing XML stream.", e); } return ByteBuffer.wrap(buffer.toByteArray()); }
: TSSLTransportFactory.getClientSocket(cassandraHost.getHost(), cassandraHost.getPort(), timeout, params); } catch (TTransportException e) { throw new HectorTransportException("Could not get client socket: ", e); socket.getSocket().setKeepAlive(true); } catch (SocketException se) { throw new HectorTransportException("Could not set SO_KEEPALIVE on socket: ", se); throw new HectorTransportException("Unable to open transport to " + cassandraHost.getName() +" , " + e.getLocalizedMessage(), e);
@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); } } /**
/** * 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; }
/** {@inheritDoc} */ @Override public Object fromByteBuffer(ByteBuffer bytes) { if (bytes == null || !bytes.hasRemaining()) { return null; } int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); try { XMLStreamReader reader = createStreamReader(bais); Object ret = unmarshaller.get().unmarshal(reader); reader.close(); return ret; } catch (JAXBException e) { throw new HectorSerializationException( "Jaxb exception occurred during deserialization.", e); } catch (XMLStreamException e) { throw new HectorSerializationException("Exception reading XML stream.", 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");
@Override public Object fromByteBuffer(ByteBuffer bytes) { if ((bytes == null) || !bytes.hasRemaining()) { return null; } try { int l = bytes.remaining(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array(), bytes.arrayOffset() + bytes.position(), l); ObjectInputStream ois; if(classLoader == null) { ois = new ObjectInputStream(bais); } else { ois = new CustomClassLoaderObjectInputStream(classLoader, bais); } Object obj = ois.readObject(); bytes.position(bytes.position() + (l - ois.available())); ois.close(); return obj; } catch (Exception ex) { throw new HectorSerializationException(ex); } }