org.apache.thrift.TException Java Examples

The following examples show how to use org.apache.thrift.TException. 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 check out the related API usage on the sidebar.
Example #1
Source File: PacketStreamer.java    From floodlight_with_topoguard with 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 #2
Source File: Ingress.java    From warp10-platform with 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 #3
Source File: TestWriteToken.java    From warp10-platform with 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 #4
Source File: Column.java    From stratio-cassandra with 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 #5
Source File: FieldDescriptor.java    From gemfirexd-oss with 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 #6
Source File: ThriftNativeCodec.java    From dubbo-2.6.5 with 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 #7
Source File: TListSentryPrivilegesForProviderResponse.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: BufferedProtocolReadToWrite.java    From parquet-mr with 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 #9
Source File: ThriftCallService.java    From armeria with 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 #10
Source File: ServiceHandler.java    From jstorm with 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 #11
Source File: AckResult.java    From DDMQ with 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 File: CatalogThriftHiveMetastore.java    From metacat with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public List<String> partition_name_to_vals(final String partName) throws TException {
    return requestWrapper("partition_name_to_vals", new Object[]{partName}, () -> {
        if (Strings.isNullOrEmpty(partName)) {
            return (List<String>) Collections.EMPTY_LIST;
        }

        final Map<String, String> spec = Warehouse.makeSpecFromName(partName);
        final List<String> vals = Lists.newArrayListWithCapacity(spec.size());
        vals.addAll(spec.values());
        return vals;
    });
}
 
Example #13
Source File: ThriftHBaseServiceHandler.java    From hbase with 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 #14
Source File: ComponentCommon.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, ComponentCommon struct) throws org.apache.thrift.TException {
  TTupleProtocol oprot = (TTupleProtocol) prot;
  {
    oprot.writeI32(struct.inputs.size());
    for (Map.Entry<GlobalStreamId, Grouping> _iter34 : struct.inputs.entrySet())
    {
      _iter34.getKey().write(oprot);
      _iter34.getValue().write(oprot);
    }
  }
  {
    oprot.writeI32(struct.streams.size());
    for (Map.Entry<String, StreamInfo> _iter35 : struct.streams.entrySet())
    {
      oprot.writeString(_iter35.getKey());
      _iter35.getValue().write(oprot);
    }
  }
  BitSet optionals = new BitSet();
  if (struct.is_set_parallelism_hint()) {
    optionals.set(0);
  }
  if (struct.is_set_json_conf()) {
    optionals.set(1);
  }
  oprot.writeBitSet(optionals, 2);
  if (struct.is_set_parallelism_hint()) {
    oprot.writeI32(struct.parallelism_hint);
  }
  if (struct.is_set_json_conf()) {
    oprot.writeString(struct.json_conf);
  }
}
 
Example #15
Source File: DefaultAWSGlueMetastore.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Override
public List<Partition> getPartitions(String dbName, String tableName, String expression,
                                     long max) throws TException {
    if (max == 0) {
        return Collections.emptyList();
    }
    if (max < 0 || max > GET_PARTITIONS_MAX_SIZE) {
        return getPartitionsParallel(dbName, tableName, expression, max);
    } else {
        // We don't need to get too many partitions, so just do it serially.
        return getCatalogPartitions(dbName, tableName, expression, max, null);
    }
}
 
Example #16
Source File: ThriftHiveMetastoreClient.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, List<ColumnStatisticsObj>> getPartitionColumnStatistics(String databaseName, String tableName, List<String> partitionNames, List<String> columnNames)
        throws TException
{
    PartitionsStatsRequest partitionsStatsRequest = new PartitionsStatsRequest(databaseName, tableName, columnNames, partitionNames);
    return client.get_partitions_statistics_req(partitionsStatsRequest).getPartStats();
}
 
Example #17
Source File: ThriftAdmin.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public TableName[] listTableNamesByNamespace(String name) throws IOException {
  try {
    List<TTableName> tTableNames = client.getTableNamesByNamespace(name);
    return ThriftUtilities.tableNamesArrayFromThrift(tTableNames);
  } catch (TException e) {
    throw new IOException(e);
  }
}
 
Example #18
Source File: Echo2.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, echo_result struct)
        throws TException {
    TTupleProtocol iprot = (TTupleProtocol) prot;
    BitSet incoming = iprot.readBitSet(1);
    if (incoming.get(0)) {
        struct.success = iprot.readString();
        struct.setSuccessIsSet(true);
    }
}
 
Example #19
Source File: AuthenticationException.java    From stratio-cassandra with 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 #20
Source File: DelayResult.java    From DDMQ with 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 #21
Source File: FederatedHMSHandlerTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void get_partition_names() throws TException {
  List<String> partitions = Lists.newArrayList();
  when(primaryMapping.transformInboundDatabaseName(DB_P)).thenReturn("inbound");
  when(primaryClient.get_partition_names("inbound", "table", (short) 10)).thenReturn(partitions);
  List<String> result = handler.get_partition_names(DB_P, "table", (short) 10);
  assertThat(result, is(partitions));
  verify(primaryMapping, never()).checkWritePermissions(DB_P);
}
 
Example #22
Source File: ByeService.java    From thrift-mock with Apache License 2.0 5 votes vote down vote up
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
  prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayBye", org.apache.thrift.protocol.TMessageType.CALL, 0));
  sayBye_args args = new sayBye_args();
  args.setRequest(request);
  args.write(prot);
  prot.writeMessageEnd();
}
 
Example #23
Source File: CursorRequestMessage.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
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 #24
Source File: TestThriftService.java    From thrift-client-pool-java with Artistic 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 #25
Source File: NimbusBlobStore.java    From jstorm with 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);
    }
}
 
Example #26
Source File: FederatedHMSHandlerTest.java    From waggle-dance with 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 #27
Source File: ChunkHeaderBufferedTBaseSerializer.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
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 #28
Source File: ServerSelectorTest.java    From das with 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 #29
Source File: TAlterSentryRoleGrantPrivilegeRequest.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: ReplicaTest.java    From circus-train with 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);
  }
}