List of usage examples for org.apache.thrift TApplicationException UNKNOWN_METHOD
int UNKNOWN_METHOD
To view the source code for org.apache.thrift TApplicationException UNKNOWN_METHOD.
Click Source Link
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 {// w w w. j a v a 2s . c o m 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 w w. java 2 s.co m 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.it.thrift.TMultiplexedProtocolIntegrationTest.java
License:Apache License
@Test public void test() throws Exception { assertThat(client("").hello("a")).isEqualTo("none:a"); assertThat(client("foo").hello("b")).isEqualTo("foo:b"); assertThat(client("bar").hello("c")).isEqualTo("bar:c"); assertThatThrownBy(() -> client("baz").hello("d")).isInstanceOf(TApplicationException.class) .hasFieldOrPropertyWithValue("type", TApplicationException.UNKNOWN_METHOD); assertThat(methodNames).containsExactly("hello", "foo:hello", "bar:hello"); }
From source file:com.linecorp.armeria.server.thrift.ThriftCallService.java
License:Apache License
@Override public RpcResponse serve(ServiceRequestContext ctx, RpcRequest call) throws Exception { final int colonPos = call.method().indexOf(':'); final String method; final String serviceName; if (colonPos < 0) { serviceName = ""; method = call.method();/*from w w w. j a va2s . c o m*/ } else { serviceName = call.method().substring(0, colonPos); method = call.method().substring(colonPos + 1); } // Ensure that such a service exists. final ThriftServiceEntry e = entries.get(serviceName); if (e != null) { // Ensure that such a method exists. final ThriftFunction f = e.metadata.function(method); if (f != null) { final DefaultRpcResponse reply = new DefaultRpcResponse(); invoke(ctx, e.implementation, f, call.params(), reply); return reply; } } return new DefaultRpcResponse(new TApplicationException(TApplicationException.UNKNOWN_METHOD, "unknown method: " + call.method())); }
From source file:com.linecorp.armeria.server.thrift.ThriftServiceCodec.java
License:Apache License
@Override public DecodeResult decodeRequest(Channel ch, SessionProtocol sessionProtocol, String hostname, String path, String mappedPath, ByteBuf in, Object originalRequest, Promise<Object> promise) throws Exception { if (originalRequest instanceof HttpRequest) { if (((HttpRequest) originalRequest).method() != HttpMethod.POST) { return new DefaultDecodeResult( new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.METHOD_NOT_ALLOWED), HTTP_METHOD_NOT_ALLOWED_EXCEPTION); }// www .j a va2 s. co m } final TProtocol inProto = this.inProto.get(); final TByteBufTransport inTransport = (TByteBufTransport) inProto.getTransport(); inTransport.reset(in); try { final TMessage header = inProto.readMessageBegin(); final byte typeValue = header.type; final int seqId = header.seqid; final String methodName = header.name; // Basic sanity check. We usually should never fail here. if (typeValue != TMessageType.CALL && typeValue != TMessageType.ONEWAY) { final TApplicationException cause = new TApplicationException( TApplicationException.INVALID_MESSAGE_TYPE, "unexpected " + "TMessageType: " + typeString(typeValue)); return new ThriftDecodeFailureResult(serializationFormat, encodeException(ch.alloc(), methodName, seqId, cause), cause, seqId, methodName, null); } // Ensure that such a method exists. final ThriftFunction f = functions.get(methodName); if (f == null) { final TApplicationException cause = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "unknown method: " + methodName); return new ThriftDecodeFailureResult(serializationFormat, encodeException(ch.alloc(), methodName, seqId, cause), cause, seqId, methodName, null); } // Decode the invocation parameters. final TBase<TBase<?, ?>, TFieldIdEnum> args; try { if (f.isAsync()) { AsyncProcessFunction<Object, TBase<TBase<?, ?>, TFieldIdEnum>, Object> asyncFunc = f .asyncFunc(); args = asyncFunc.getEmptyArgsInstance(); args.read(inProto); inProto.readMessageEnd(); } else { ProcessFunction<Object, TBase<TBase<?, ?>, TFieldIdEnum>> syncFunc = f.syncFunc(); args = syncFunc.getEmptyArgsInstance(); args.read(inProto); inProto.readMessageEnd(); } } catch (Exception e) { // Failed to decode the invocation parameters. final TApplicationException cause = new TApplicationException(TApplicationException.PROTOCOL_ERROR, "argument decode failure: " + e); return new ThriftDecodeFailureResult(serializationFormat, encodeException(ch.alloc(), methodName, seqId, cause), cause, seqId, methodName, null); } return new ThriftServiceInvocationContext(ch, Scheme.of(serializationFormat, sessionProtocol), hostname, path, mappedPath, serviceLoggerName, originalRequest, f, seqId, args); } finally { inTransport.clear(); } }
From source file:com.linecorp.armeria.server.thrift.THttpService.java
License:Apache License
private void decodeAndInvoke(ServiceRequestContext ctx, AggregatedHttpMessage req, SerializationFormat serializationFormat, HttpResponseWriter res) { final TProtocol inProto = FORMAT_TO_THREAD_LOCAL_INPUT_PROTOCOL.get(serializationFormat).get(); inProto.reset();/*from w ww.ja v a 2 s .c om*/ final TMemoryInputTransport inTransport = (TMemoryInputTransport) inProto.getTransport(); final HttpData content = req.content(); inTransport.reset(content.array(), content.offset(), content.length()); final int seqId; final ThriftFunction f; final RpcRequest decodedReq; try { final TMessage header; final TBase<TBase<?, ?>, TFieldIdEnum> args; try { header = inProto.readMessageBegin(); } catch (Exception e) { logger.debug("{} Failed to decode Thrift header:", ctx, e); res.respond(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8, "Failed to decode Thrift header: " + Throwables.getStackTraceAsString(e)); return; } seqId = header.seqid; final byte typeValue = header.type; final int colonIdx = header.name.indexOf(':'); final String serviceName; final String methodName; if (colonIdx < 0) { serviceName = ""; methodName = header.name; } else { serviceName = header.name.substring(0, colonIdx); methodName = header.name.substring(colonIdx + 1); } // Basic sanity check. We usually should never fail here. if (typeValue != TMessageType.CALL && typeValue != TMessageType.ONEWAY) { final TApplicationException cause = new TApplicationException( TApplicationException.INVALID_MESSAGE_TYPE, "unexpected TMessageType: " + typeString(typeValue)); handlePreDecodeException(ctx, res, cause, serializationFormat, seqId, methodName); return; } // Ensure that such a method exists. final ThriftServiceEntry entry = entries().get(serviceName); f = entry != null ? entry.metadata.function(methodName) : null; if (f == null) { final TApplicationException cause = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "unknown method: " + header.name); handlePreDecodeException(ctx, res, cause, serializationFormat, seqId, methodName); return; } // Decode the invocation parameters. try { if (f.isAsync()) { AsyncProcessFunction<Object, TBase<TBase<?, ?>, TFieldIdEnum>, Object> asyncFunc = f .asyncFunc(); args = asyncFunc.getEmptyArgsInstance(); args.read(inProto); inProto.readMessageEnd(); } else { ProcessFunction<Object, TBase<TBase<?, ?>, TFieldIdEnum>> syncFunc = f.syncFunc(); args = syncFunc.getEmptyArgsInstance(); args.read(inProto); inProto.readMessageEnd(); } decodedReq = toRpcRequest(f.serviceType(), header.name, args); ctx.logBuilder().requestContent(decodedReq, new ThriftCall(header, args)); } catch (Exception e) { // Failed to decode the invocation parameters. logger.debug("{} Failed to decode Thrift arguments:", ctx, e); final TApplicationException cause = new TApplicationException(TApplicationException.PROTOCOL_ERROR, "failed to decode arguments: " + e); handlePreDecodeException(ctx, res, cause, serializationFormat, seqId, methodName); return; } } finally { inTransport.clear(); ctx.logBuilder().requestContent(null, null); } invoke(ctx, serializationFormat, seqId, f, decodedReq, res); }
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 w w. ja v a 2 s . c om*/ 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 {//from w w w . java2 s . c om 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 av a2 s. co 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 w w w. ja v a 2 s . 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, ",")); }