Java Code Examples for org.apache.thrift.TException

The following examples show how to use org.apache.thrift.TException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jstorm   Source File: ServiceHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Map<Integer, String> getTopologyTasksToSupervisorIds(String topologyName)
        throws TException {
    StormClusterState stormClusterState = data.getStormClusterState();
    String topologyId = getTopologyId(topologyName);
    Map<Integer, String> ret = new HashMap<>();
    try {
        Assignment assignment = stormClusterState.assignment_info(topologyId, null);
        Set<ResourceWorkerSlot> workers = assignment.getWorkers();
        for (ResourceWorkerSlot worker : workers) {
            String supervisorId = worker.getNodeId();
            for (Integer task : worker.getTasks()) {
                ret.put(task, supervisorId);
            }
        }
    } catch (Exception ex) {
        LOG.error("Error:", ex);
    }
    return ret;
}
 
Example 2
Source Project: parquet-mr   Source File: BufferedProtocolReadToWrite.java    License: Apache License 2.0 6 votes vote down vote up
private boolean readOneList(TProtocol in, List<Action> buffer, ListType expectedType) throws TException {
  final TList list = in.readListBegin();
  buffer.add(new Action() {
    @Override
    public void write(TProtocol out) throws TException {
      out.writeListBegin(list);
    }

    @Override
    public String toDebugString() {
      return "<e=" + list.elemType + ", s=" + list.size + ">{";
    }
  });
  boolean hasFieldsIgnored = readCollectionElements(in, list.size, list.elemType, buffer, expectedType.getValues().getType());
  in.readListEnd();
  buffer.add(LIST_END);
  return hasFieldsIgnored;
}
 
Example 3
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, TListSentryPrivilegesForProviderResponse struct) throws org.apache.thrift.TException {
  TTupleProtocol iprot = (TTupleProtocol) prot;
  struct.status = new org.apache.sentry.service.thrift.TSentryResponseStatus();
  struct.status.read(iprot);
  struct.setStatusIsSet(true);
  {
    org.apache.thrift.protocol.TSet _set101 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRING, iprot.readI32());
    struct.privileges = new HashSet<String>(2*_set101.size);
    for (int _i102 = 0; _i102 < _set101.size; ++_i102)
    {
      String _elem103; // required
      _elem103 = iprot.readString();
      struct.privileges.add(_elem103);
    }
  }
  struct.setPrivilegesIsSet(true);
}
 
Example 4
Source Project: gemfirexd-oss   Source File: FieldDescriptor.java    License: Apache License 2.0 6 votes vote down vote up
public void write(org.apache.thrift.protocol.TProtocol oprot, FieldDescriptor struct) throws org.apache.thrift.TException {
  struct.validate();

  oprot.writeStructBegin(STRUCT_DESC);
  if (struct.name != null) {
    oprot.writeFieldBegin(NAME_FIELD_DESC);
    oprot.writeString(struct.name);
    oprot.writeFieldEnd();
  }
  if (struct.type != null) {
    oprot.writeFieldBegin(TYPE_FIELD_DESC);
    oprot.writeI32(struct.type.getValue());
    oprot.writeFieldEnd();
  }
  if (struct.isSetIdentity()) {
    oprot.writeFieldBegin(IDENTITY_FIELD_DESC);
    oprot.writeBool(struct.identity);
    oprot.writeFieldEnd();
  }
  oprot.writeFieldStop();
  oprot.writeStructEnd();
}
 
Example 5
Source Project: warp10-platform   Source File: Ingress.java    License: Apache License 2.0 6 votes vote down vote up
void pushMetadataMessage(Metadata metadata) throws IOException {
  
  if (null == metadata) {
    pushMetadataMessage(null, null);
    return;
  }
  
  //
  // Compute class/labels Id
  //
  // 128bits
  metadata.setClassId(GTSHelper.classId(this.classKey, metadata.getName()));
  metadata.setLabelsId(GTSHelper.labelsId(this.labelsKey, metadata.getLabels()));
  
  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  try {
    byte[] bytes = new byte[16];
    GTSHelper.fillGTSIds(bytes, 0, metadata.getClassId(), metadata.getLabelsId());
    pushMetadataMessage(bytes, serializer.serialize(metadata));
  } catch (TException te) {
    throw new IOException("Unable to push metadata.");
  }
}
 
Example 6
Source Project: armeria   Source File: ThriftCallService.java    License: Apache License 2.0 6 votes vote down vote up
private static void invokeAsynchronously(Object impl, ThriftFunction func, TBase<?, ?> args,
                                         CompletableRpcResponse reply) throws TException {

    final AsyncProcessFunction<Object, TBase<?, ?>, Object> f = func.asyncFunc();
    if (func.isOneWay()) {
        f.start(impl, args, ONEWAY_CALLBACK);
        reply.complete(null);
    } else {
        f.start(impl, args, new AsyncMethodCallback<Object>() {
            @Override
            public void onComplete(Object response) {
                reply.complete(response);
            }

            @Override
            public void onError(Exception e) {
                reply.completeExceptionally(e);
            }
        });
    }
}
 
Example 7
Source Project: warp10-platform   Source File: TestWriteToken.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTokenAESCorrupted() throws TException {
  // generate a token
  String uuid = UUID.randomUUID().toString();
  String writeToken = tokenEncoder.deliverWriteToken("app", uuid, 32478, getKeyStore());

  // corrupt the token (pick a random character and decrement it)
  int corruptedIndex = new Random().nextInt(60);
  writeToken = writeToken.substring(0, corruptedIndex) + (writeToken.charAt(corruptedIndex) - 1) + writeToken.substring(corruptedIndex + 1);

  final QuasarTokenFilter tokenFilter = new QuasarTokenFilter(getConfig(), getKeyStore());

  try {
    tokenFilter.getWriteToken(writeToken);
    assert false;
  } catch (QuasarTokenException qte) {
    assert qte instanceof QuasarTokenInvalid;
  }
}
 
Example 8
Source Project: stratio-cassandra   Source File: Column.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, Column struct) throws org.apache.thrift.TException {
  TTupleProtocol oprot = (TTupleProtocol) prot;
  oprot.writeBinary(struct.name);
  BitSet optionals = new BitSet();
  if (struct.isSetValue()) {
    optionals.set(0);
  }
  if (struct.isSetTimestamp()) {
    optionals.set(1);
  }
  if (struct.isSetTtl()) {
    optionals.set(2);
  }
  oprot.writeBitSet(optionals, 3);
  if (struct.isSetValue()) {
    oprot.writeBinary(struct.value);
  }
  if (struct.isSetTimestamp()) {
    oprot.writeI64(struct.timestamp);
  }
  if (struct.isSetTtl()) {
    oprot.writeI32(struct.ttl);
  }
}
 
Example 9
Source Project: floodlight_with_topoguard   Source File: PacketStreamer.java    License: Apache License 2.0 6 votes vote down vote up
public void write(org.apache.thrift.protocol.TProtocol oprot, getPackets_result struct) throws org.apache.thrift.TException {
  struct.validate();

  oprot.writeStructBegin(STRUCT_DESC);
  if (struct.success != null) {
    oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
    {
      oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.success.size()));
      for (ByteBuffer _iter11 : struct.success)
      {
        oprot.writeBinary(_iter11);
      }
      oprot.writeListEnd();
    }
    oprot.writeFieldEnd();
  }
  oprot.writeFieldStop();
  oprot.writeStructEnd();
}
 
Example 10
Source Project: dubbo-2.6.5   Source File: ThriftNativeCodec.java    License: Apache License 2.0 6 votes vote down vote up
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
        throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(
                invocation.getMethodName(), TMessageType.CALL,
                thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for (int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];

        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }

}
 
Example 11
Source Project: DDMQ   Source File: AckResult.java    License: Apache License 2.0 6 votes vote down vote up
public void validate() throws org.apache.thrift.TException {
  // check for required fields
  if (consumerId == null) {
    throw new org.apache.thrift.protocol.TProtocolException("Required field 'consumerId' was not present! Struct: " + toString());
  }
  if (groupId == null) {
    throw new org.apache.thrift.protocol.TProtocolException("Required field 'groupId' was not present! Struct: " + toString());
  }
  if (cluster == null) {
    throw new org.apache.thrift.protocol.TProtocolException("Required field 'cluster' was not present! Struct: " + toString());
  }
  if (offsets == null) {
    throw new org.apache.thrift.protocol.TProtocolException("Required field 'offsets' was not present! Struct: " + toString());
  }
  // check for sub-struct validity
}
 
Example 12
Source Project: hbase   Source File: ThriftHBaseServiceHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<TResult> getMultiple(ByteBuffer table, List<TGet> gets) throws TIOError, TException {
  Table htable = getTable(table);
  try {
    return resultsFromHBase(htable.get(getsFromThrift(gets)));
  } catch (IOException e) {
    throw getTIOError(e);
  } finally {
    closeTable(htable);
  }
}
 
Example 13
Source Project: easy-mapper   Source File: MyQueryService.java    License: Apache License 2.0 5 votes vote down vote up
public void validate() throws TException {
  // check for required fields
  // check for sub-struct validity
  if (query != null) {
    query.validate();
  }
}
 
Example 14
Source Project: xio   Source File: ConfigurationService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, removeIpRule_args struct)
    throws org.apache.thrift.TException {
  TTupleProtocol iprot = (TTupleProtocol) prot;
  BitSet incoming = iprot.readBitSet(1);
  if (incoming.get(0)) {
    struct.ipRule = new IpRule();
    struct.ipRule.read(iprot);
    struct.setIpRuleIsSet(true);
  }
}
 
Example 15
Source Project: luxun   Source File: QueueService.java    License: Apache License 2.0 5 votes vote down vote up
public ProduceResponse recv_produce() throws org.apache.thrift.TException
{
  produce_result result = new produce_result();
  receiveBase(result, "produce");
  if (result.isSetSuccess()) {
    return result.success;
  }
  throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "produce failed: unknown result");
}
 
Example 16
Source Project: gemfirexd-oss   Source File: Timestamp.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
  try {
    write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
  } catch (org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 
Example 17
Source Project: incubator-sentry   Source File: SentryHDFSService.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
  try {
    write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
  } catch (org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 
Example 18
Source Project: armeria   Source File: TTextProtocol.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Write out the given value, either as a JSON name (meaning it's
 * escaped by quotes), or a value. The TypedParser knows how to
 * handle the writing.
 */
private <T> void writeNameOrValue(TypedParser<T> helper, T val)
        throws TException {
    getCurrentContext().write();
    try {
        if (getCurrentContext().isMapKey()) {
            getCurrentWriter().writeFieldName(val.toString());
        } else {
            helper.writeValue(getCurrentWriter(), val);
        }
    } catch (IOException ex) {
        throw new TException(ex);
    }
}
 
Example 19
Source Project: gemfirexd-oss   Source File: FieldValue.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
  try {
    write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
  } catch (org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 
Example 20
Source Project: luxun   Source File: QueueService.java    License: Apache License 2.0 5 votes vote down vote up
public void read(org.apache.thrift.protocol.TProtocol iprot, consume_args 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: // CONSUME_REQUEST
        if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
          struct.consumeRequest = new ConsumeRequest();
          struct.consumeRequest.read(iprot);
          struct.setConsumeRequestIsSet(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();
}
 
Example 21
Source Project: DDMQ   Source File: ConsumeResult.java    License: Apache License 2.0 5 votes vote down vote up
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  } catch (org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 
Example 22
Source Project: hbase   Source File: ThriftConnection.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getClusterId() {
  try {
    Pair<THBaseService.Client, TTransport> client = clientBuilder.getClient();
    return client.getFirst().getClusterId();
  } catch (TException | IOException e) {
    LOG.error("Error fetching cluster ID: ", e);
  }
  return null;
}
 
Example 23
Source Project: jstorm   Source File: SubmitOptions.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
  try {
    write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
  } catch (org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 
Example 24
Source Project: thrift-mock   Source File: HelloService.java    License: Apache License 2.0 5 votes vote down vote up
public void validate() throws org.apache.thrift.TException {
  // check for required fields
  // check for sub-struct validity
  if (success != null) {
    success.validate();
  }
}
 
Example 25
Source Project: circus-train   Source File: ReplicaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void validateReplicaTableOnAMirroredTableFails() throws TException, IOException {
  try {
    existingReplicaTable.putToParameters(REPLICATION_EVENT.parameterName(), "previousEventId");
    existingReplicaTable.putToParameters(REPLICATION_MODE.parameterName(), ReplicationMode.METADATA_MIRROR.name());
    replica.validateReplicaTable(DB_NAME, TABLE_NAME);
    fail("Should have thrown InvalidReplicationModeException");
  } catch (InvalidReplicationModeException e) {
    // Check that nothing was written to the metastore
    verify(mockMetaStoreClient).getTable(DB_NAME, TABLE_NAME);
    verify(mockMetaStoreClient).close();
    verifyNoMoreInteractions(mockMetaStoreClient);
  }
}
 
Example 26
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
  try {
    // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
    __isset_bitfield = 0;
    read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
  } catch (org.apache.thrift.TException te) {
    throw new java.io.IOException(te);
  }
}
 
Example 27
Source Project: das   Source File: ServerSelectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testNoAvailableInstance() throws TException {
    ServerSelector serverSelector = new ServerSelector(
            "appId", Arrays.asList(NO_AVAILABLE_INSTANCE_1, NO_AVAILABLE_INSTANCE_2), "dasClientVersion", "ppdaiClientVersion", "clientAddress"
    );
    serverSelector.execute(REQUEST);
    fail();
}
 
Example 28
public void flush() throws TException {
    synchronized (transport) {
        if (flushHandler != null && transport.getBufferPosition() > Header.HEADER_PREFIX_SIZE) {
            flushHandler.handle(transport.getBuffer(), 0, transport.getBufferPosition());
        }
        transport.flush();
        writeChunkHeader = false;
    }
}
 
Example 29
Source Project: waggle-dance   Source File: FederatedHMSHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void create_table() throws TException {
  Table table = new Table();
  table.setDbName(DB_P);
  Table inboundTable = new Table();
  inboundTable.setDbName("inbound");
  when(primaryMapping.transformInboundTable(table)).thenReturn(inboundTable);
  handler.create_table(table);
  verify(primaryMapping).checkWritePermissions(DB_P);
  verify(primaryClient).create_table(inboundTable);
}
 
Example 30
Source Project: jstorm   Source File: NimbusBlobStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int updateBlobReplication(String key, int replication) throws KeyNotFoundException {
    try {
        return client.getClient().updateBlobReplication(key, replication);
    } catch (KeyNotFoundException exp) {
        throw exp;
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}