@Override public Response toResponse(DRPCExecutionException ex) { ResponseBuilder builder = Response.status(500); switch (ex.get_type()) { case FAILED_REQUEST: builder.status(400); break; case SERVER_SHUTDOWN: builder.status(503); //Not available break; case SERVER_TIMEOUT: builder.status(504); //proxy timeout break; case INTERNAL_ERROR: //fall throw on purpose default: //Empty (Still 500) break; } Map<String, String> body = new HashMap<>(); //TODO I would love to standardize this... body.put("error", ex.is_set_type() ? ex.get_type().toString() : "Internal Error"); body.put("errorMessage", ex.get_msg()); return builder.entity(JSONValue.toJSONString(body)).type("application/json").build(); }
@Override public void read(org.apache.storm.thrift.protocol.TProtocol prot, failRequestV2_args struct) throws org.apache.storm.thrift.TException { org.apache.storm.thrift.protocol.TTupleProtocol iprot = (org.apache.storm.thrift.protocol.TTupleProtocol) prot; java.util.BitSet incoming = iprot.readBitSet(2); if (incoming.get(0)) { struct.id = iprot.readString(); struct.set_id_isSet(true); } if (incoming.get(1)) { struct.e = new DRPCExecutionException(); struct.e.read(iprot); struct.set_e_isSet(true); } } }
@Override public boolean equals(java.lang.Object that) { if (that == null) return false; if (that instanceof DRPCExecutionException) return this.equals((DRPCExecutionException)that); return false; }
/** * Performs a deep copy on <i>other</i>. */ public DRPCExecutionException(DRPCExecutionException other) { if (other.is_set_msg()) { this.msg = other.msg; } if (other.is_set_type()) { this.type = other.type; } }
public void setFieldValue(_Fields field, java.lang.Object value) { switch (field) { case MSG: if (value == null) { unset_msg(); } else { set_msg((java.lang.String)value); } break; case TYPE: if (value == null) { unset_type(); } else { set_type((DRPCExceptionType)value); } break; } }
public void validate() throws org.apache.storm.thrift.TException { // check for required fields if (!is_set_msg()) { throw new org.apache.storm.thrift.protocol.TProtocolException("Required field 'msg' is unset! Struct:" + toString()); } // check for sub-struct validity }
@Test public void testFailedThrift() throws Exception { Map<String, Object> conf = getConf(0, 0, null); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort()); DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.failRequest(request.get_request_id()); try { found.get(1000, TimeUnit.MILLISECONDS); fail("exec did not throw an exception"); } catch (ExecutionException e) { Throwable t = e.getCause(); assertEquals(t.getClass(), DRPCExecutionException.class); //Don't know a better way to validate that it failed. assertEquals("Request failed", ((DRPCExecutionException)t).get_msg()); } } } }
if (schemeField.type == org.apache.storm.thrift.protocol.TType.STRING) { struct.msg = iprot.readString(); struct.set_msg_isSet(true); } else { org.apache.storm.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); if (schemeField.type == org.apache.storm.thrift.protocol.TType.I32) { struct.type = org.apache.storm.generated.DRPCExceptionType.findByValue(iprot.readI32()); struct.set_type_isSet(true); } else { org.apache.storm.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); struct.validate();
public DRPCExecutionException deepCopy() { return new DRPCExecutionException(this); }
/** * Performs a deep copy on <i>other</i>. */ public DRPCExecutionException(DRPCExecutionException other) { if (other.is_set_msg()) { this.msg = other.msg; } }
public void write(org.apache.storm.thrift.protocol.TProtocol oprot, DRPCExecutionException struct) throws org.apache.storm.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); if (struct.msg != null) { oprot.writeFieldBegin(MSG_FIELD_DESC); oprot.writeString(struct.msg); oprot.writeFieldEnd(); } if (struct.type != null) { if (struct.is_set_type()) { oprot.writeFieldBegin(TYPE_FIELD_DESC); oprot.writeI32(struct.type.getValue()); oprot.writeFieldEnd(); } } oprot.writeFieldStop(); oprot.writeStructEnd(); }
@Test public void testFailedBlocking() throws Exception { try (DRPC server = new DRPC(new StormMetricsRegistry(), null, 100)) { Future<String> found = exec.submit(() -> server.executeBlocking("testing", "test")); DRPCRequest request = getNextAvailableRequest(server, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); server.failRequest(request.get_request_id(), null); try { found.get(100, TimeUnit.MILLISECONDS); fail("exec did not throw an exception"); } catch (ExecutionException e) { Throwable t = e.getCause(); assertTrue(t instanceof DRPCExecutionException); //Don't know a better way to validate that it failed. assertEquals(DRPCExceptionType.FAILED_REQUEST, ((DRPCExecutionException) t).get_type()); } } }
public void read(org.apache.thrift.protocol.TProtocol iprot, DRPCExecutionException struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) { schemeField = iprot.readFieldBegin(); if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { break; } switch (schemeField.id) { case 1: // MSG if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.msg = iprot.readString(); struct.set_msg_isSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); struct.validate(); }
@Override public void read(org.apache.storm.thrift.protocol.TProtocol prot, DRPCExecutionException struct) throws org.apache.storm.thrift.TException { org.apache.storm.thrift.protocol.TTupleProtocol iprot = (org.apache.storm.thrift.protocol.TTupleProtocol) prot; struct.msg = iprot.readString(); struct.set_msg_isSet(true); java.util.BitSet incoming = iprot.readBitSet(1); if (incoming.get(0)) { struct.type = org.apache.storm.generated.DRPCExceptionType.findByValue(iprot.readI32()); struct.set_type_isSet(true); } } }
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { try { read(new org.apache.storm.thrift.protocol.TCompactProtocol(new org.apache.storm.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.storm.thrift.TException te) { throw new java.io.IOException(te); } }
@Override public java.lang.String toString() { java.lang.StringBuilder sb = new java.lang.StringBuilder("DRPCExecutionException("); boolean first = true; sb.append("msg:"); if (this.msg == null) { sb.append("null"); } else { sb.append(this.msg); } first = false; if (is_set_type()) { if (!first) sb.append(", "); sb.append("type:"); if (this.type == null) { sb.append("null"); } else { sb.append(this.type); } first = false; } sb.append(")"); return sb.toString(); }
public String getResult() throws DRPCExecutionException { try { _sem.acquire(); } catch (InterruptedException e) { //Ignored } if (_result != null) { return _result; } if (_e == null) { _e = new WrappedDRPCExecutionException("Internal Error: No Result and No Exception"); _e.set_type(DRPCExceptionType.INTERNAL_ERROR); } throw _e; }
@Override public void read(org.apache.thrift.protocol.TProtocol prot, DRPCExecutionException struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; struct.msg = iprot.readString(); struct.set_msg_isSet(true); } }