List of usage examples for org.apache.thrift TApplicationException getType
public int getType()
From source file:com.facebook.presto.cassandra.CassandraThriftClient.java
License:Apache License
public List<CfSplit> getSubSplits(String keyspace, String columnFamily, TokenRange range, int splitSize) { Client client = connectionFactory.create(); try {//from w ww . j av a2 s . com client.set_keyspace(keyspace); try { return client.describe_splits_ex(columnFamily, range.start_token, range.end_token, splitSize); } catch (TApplicationException e) { // fallback to guessing split size if talking to a server without describe_splits_ex method if (e.getType() == TApplicationException.UNKNOWN_METHOD) { List<String> splitPoints = client.describe_splits(columnFamily, range.start_token, range.end_token, splitSize); return tokenListToSplits(splitPoints, splitSize); } throw e; } } catch (TException e) { throw new RuntimeException(e); } finally { closeQuietly(client); } }
From source file:com.facebook.swift.service.exceptions.ExceptionTest.java
License:Apache License
@Test public void testMissingMethod() { try {/*from w ww . j av a2 s . com*/ getClient().missingMethod(); fail("Expected TApplicationException of type UNKNOWN_METHOD"); } catch (TApplicationException e) { assertEquals(e.getType(), TApplicationException.UNKNOWN_METHOD, "Expected TApplicationException of type UNKNOWN_METHOD"); } }
From source file:com.linecorp.armeria.common.thrift.text.TTextProtocolTest.java
License:Apache License
@Test public void rpcTApplicationException() throws Exception { String request = "{\n" + " \"method\" : \"doDebug\",\n" + " \"type\" : \"EXCEPTION\",\n" + " \"seqid\" : 101,\n" + " \"args\" : {\n" + " \"type\" : 4,\n" + " \"message\" : \"bad_seq_id\"\n" + " }\n" + " }\n" + '}'; TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); TMessage header = prot.readMessageBegin(); TApplicationException result = TApplicationException.read(prot); prot.readMessageEnd();/*from www .j av a 2 s . c o m*/ assertEquals("doDebug", header.name); assertEquals(TMessageType.EXCEPTION, header.type); assertEquals(101, header.seqid); assertEquals(TApplicationException.BAD_SEQUENCE_ID, result.getType()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); prot = new TTextProtocol(new TIOStreamTransport(outputStream)); prot.writeMessageBegin(header); new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "bad_seq_id").write(prot); prot.writeMessageEnd(); assertJsonEquals(request, new String(outputStream.toByteArray(), StandardCharsets.UTF_8)); }
From source file:com.linecorp.armeria.server.thrift.ThriftServiceTest.java
License:Apache License
@Test public void testSync_FileService_create_exception() throws Exception { FileService.Client client = new FileService.Client.Factory().getClient(inProto, outProto); client.send_create(BAZ);/*from w w w . j a va2 s . com*/ assertThat(out.length(), is(greaterThan(0))); RuntimeException exception = Exceptions.clearTrace(new RuntimeException()); THttpService service = THttpService.of((FileService.Iface) path -> { throw exception; }, defaultSerializationFormat); invoke(service); try { client.recv_create(); fail(TApplicationException.class.getSimpleName() + " not raised."); } catch (TApplicationException e) { assertThat(e.getType(), is(TApplicationException.INTERNAL_ERROR)); assertThat(e.getMessage(), containsString(exception.toString())); } }
From source file:com.linecorp.armeria.server.thrift.ThriftServiceTest.java
License:Apache License
@Test public void testAsync_FileService_create_exception() throws Exception { FileService.Client client = new FileService.Client.Factory().getClient(inProto, outProto); client.send_create(BAZ);/*from w w w. j av a 2 s . c om*/ assertThat(out.length(), is(greaterThan(0))); RuntimeException exception = Exceptions.clearTrace(new RuntimeException()); THttpService service = THttpService.of( (FileService.AsyncIface) (path, resultHandler) -> resultHandler.onError(exception), defaultSerializationFormat); invoke(service); try { client.recv_create(); fail(TApplicationException.class.getSimpleName() + " not raised."); } catch (TApplicationException e) { assertThat(e.getType(), is(TApplicationException.INTERNAL_ERROR)); assertThat(e.getMessage(), containsString(exception.toString())); } }
From source file:com.stratio.deep.cassandra.thrift.ThriftRangeUtils.java
License:Apache License
/** * Returns the token ranges of the Cassandra ring that will be mapped to Spark partitions. * The returned ranges are the Cassandra's physical ones, without any splitting. * * @return the list of Cassandra ring token ranges. *///from w ww. ja v a 2s .c o m public List<DeepTokenRange> getRanges() { try { List<TokenRange> tokenRanges; ThriftClient client = ThriftClient.build(host, rpcPort); try { tokenRanges = client.describe_local_ring(keyspace); } catch (TApplicationException e) { if (e.getType() == TApplicationException.UNKNOWN_METHOD) { tokenRanges = client.describe_ring(keyspace); } else { throw new DeepGenericException("Unknown server error", e); } } client.close(); List<DeepTokenRange> deepTokenRanges = new ArrayList<>(tokenRanges.size()); for (TokenRange tokenRange : tokenRanges) { Comparable start = tokenAsComparable(tokenRange.getStart_token()); Comparable end = tokenAsComparable(tokenRange.getEnd_token()); deepTokenRanges.add(new DeepTokenRange(start, end, tokenRange.getEndpoints())); } return deepTokenRanges; } catch (TException e) { throw new DeepGenericException("No available replicas for get ring token ranges", e); } }
From source file:com.tuplejump.calliope.hadoop.AbstractColumnFamilyInputFormat.java
License:Apache License
private List<CfSplit> getSubSplits(String keyspace, String cfName, TokenRange range, Configuration conf) throws IOException { int splitsize = ConfigHelper.getInputSplitSize(conf); for (int i = 0; i < range.rpc_endpoints.size(); i++) { String host = range.rpc_endpoints.get(i); if (host == null || host.equals("0.0.0.0")) host = range.endpoints.get(i); //System.out.println(String.format("RANGE: %s - %s ON %s", range.start_token, range.end_token, range.endpoints)); try {//w w w .j a v a 2 s.c o m Cassandra.Client client = ConfigHelper.createConnection(conf, host, ConfigHelper.getInputRpcPort(conf)); client.set_keyspace(keyspace); try { List<CfSplit> cfs = client.describe_splits_ex(cfName, range.start_token, range.end_token, splitsize); return cfs; } catch (TApplicationException e) { // fallback to guessing split size if talking to a server without describe_splits_ex method if (e.getType() == TApplicationException.UNKNOWN_METHOD) { List<String> splitPoints = client.describe_splits(cfName, range.start_token, range.end_token, splitsize); return tokenListToSplits(splitPoints, splitsize); } throw e; } } catch (IOException e) { logger.debug("failed connect to endpoint " + host, e); } catch (InvalidRequestException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } } throw new IOException("failed connecting to all endpoints " + StringUtils.join(range.endpoints, ",")); }
From source file:com.twitter.distributedlog.client.DistributedLogClientImpl.java
License:Apache License
void handleTApplicationException(Throwable cause, Optional<StreamOp> op, SocketAddress addr, ProxyClient sc) { TApplicationException ex = (TApplicationException) cause; if (ex.getType() == TApplicationException.UNKNOWN_METHOD) { // if we encountered unknown method exception on thrift server, it means this proxy // has problem. we should remove it from routing service, clean up ownerships routingService.removeHost(addr, cause); onServerLeft(addr, sc);// ww w .j a v a2 s .c o m if (op.isPresent()) { ownershipCache.removeOwnerFromStream(op.get().stream, addr, cause.getMessage()); doSend(op.get(), addr); } } else { handleException(cause, op, addr); } }
From source file:org.apache.cassandra.hadoop.AbstractColumnFamilyInputFormat.java
License:Apache License
private List<CfSplit> getSubSplits(String keyspace, String cfName, TokenRange range, Configuration conf) throws IOException { int splitsize = ConfigHelper.getInputSplitSize(conf); for (int i = 0; i < range.rpc_endpoints.size(); i++) { String host = range.rpc_endpoints.get(i); if (host == null || host.equals("0.0.0.0")) host = range.endpoints.get(i); try {//from ww w . j av a2s. c o m Cassandra.Client client = ConfigHelper.createConnection(conf, host, ConfigHelper.getInputRpcPort(conf)); client.set_keyspace(keyspace); try { return client.describe_splits_ex(cfName, range.start_token, range.end_token, splitsize); } catch (TApplicationException e) { // fallback to guessing split size if talking to a server without describe_splits_ex method if (e.getType() == TApplicationException.UNKNOWN_METHOD) { List<String> splitPoints = client.describe_splits(cfName, range.start_token, range.end_token, splitsize); return tokenListToSplits(splitPoints, splitsize); } throw e; } } catch (IOException e) { logger.debug("failed connect to endpoint {}", host, e); } catch (InvalidRequestException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } } throw new IOException("failed connecting to all endpoints " + StringUtils.join(range.endpoints, ",")); }
From source file:org.apache.hadoop.hive.metastore.HiveMetaStoreClientPreCatalog.java
License:Apache License
@Override public boolean listPartitionsByExpr(String db_name, String tbl_name, byte[] expr, String default_partition_name, short max_parts, List<Partition> result) throws TException { assert result != null; PartitionsByExprRequest req = new PartitionsByExprRequest(db_name, tbl_name, ByteBuffer.wrap(expr)); if (default_partition_name != null) { req.setDefaultPartitionName(default_partition_name); }//from w ww . j a va 2 s . c om if (max_parts >= 0) { req.setMaxParts(max_parts); } PartitionsByExprResult r; try { r = client.get_partitions_by_expr(req); } catch (TApplicationException te) { // TODO: backward compat for Hive <= 0.12. Can be removed later. if (te.getType() != TApplicationException.UNKNOWN_METHOD && te.getType() != TApplicationException.WRONG_METHOD_NAME) { throw te; } throw new IncompatibleMetastoreException( "Metastore doesn't support listPartitionsByExpr: " + te.getMessage()); } if (fastpath) { result.addAll(r.getPartitions()); } else { r.setPartitions(filterHook.filterPartitions(r.getPartitions())); // TODO: in these methods, do we really need to deepcopy? deepCopyPartitions(r.getPartitions(), result); } return !r.isSetHasUnknownPartitions() || r.isHasUnknownPartitions(); // Assume the worst. }