Search in sources :

Example 11 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class CreateTopicsResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.CREATE_TOPICS.responseSchema(version));
    List<Struct> topicErrorsStructs = new ArrayList<>(errors.size());
    for (Map.Entry<String, Error> topicError : errors.entrySet()) {
        Struct topicErrorsStruct = struct.instance(TOPIC_ERRORS_KEY_NAME);
        topicErrorsStruct.set(TOPIC_KEY_NAME, topicError.getKey());
        Error error = topicError.getValue();
        topicErrorsStruct.set(ERROR_CODE_KEY_NAME, error.error.code());
        if (version >= 1)
            topicErrorsStruct.set(ERROR_MESSAGE_KEY_NAME, error.message());
        topicErrorsStructs.add(topicErrorsStruct);
    }
    struct.set(TOPIC_ERRORS_KEY_NAME, topicErrorsStructs.toArray());
    return struct;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 12 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class DeleteTopicsResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.DELETE_TOPICS.responseSchema(version));
    List<Struct> topicErrorCodeStructs = new ArrayList<>(errors.size());
    for (Map.Entry<String, Errors> topicError : errors.entrySet()) {
        Struct topicErrorCodeStruct = struct.instance(TOPIC_ERROR_CODES_KEY_NAME);
        topicErrorCodeStruct.set(TOPIC_KEY_NAME, topicError.getKey());
        topicErrorCodeStruct.set(ERROR_CODE_KEY_NAME, topicError.getValue().code());
        topicErrorCodeStructs.add(topicErrorCodeStruct);
    }
    struct.set(TOPIC_ERROR_CODES_KEY_NAME, topicErrorCodeStructs.toArray());
    return struct;
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 13 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class DescribeGroupsRequest method toStruct.

@Override
protected Struct toStruct() {
    Struct struct = new Struct(ApiKeys.DESCRIBE_GROUPS.requestSchema(version()));
    struct.set(GROUP_IDS_KEY_NAME, groupIds.toArray());
    return struct;
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct)

Example 14 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class FetchResponse method addTopicData.

private static void addTopicData(String dest, List<Send> sends, Struct topicData) {
    String topic = topicData.getString(TOPIC_KEY_NAME);
    Object[] allPartitionData = topicData.getArray(PARTITIONS_KEY_NAME);
    // include the topic header and the count for the number of partitions
    ByteBuffer buffer = ByteBuffer.allocate(Type.STRING.sizeOf(topic) + 4);
    Type.STRING.write(buffer, topic);
    buffer.putInt(allPartitionData.length);
    buffer.rewind();
    sends.add(new ByteBufferSend(dest, buffer));
    for (Object partitionData : allPartitionData) addPartitionData(dest, sends, (Struct) partitionData);
}
Also used : ByteBufferSend(org.apache.kafka.common.network.ByteBufferSend) ByteBuffer(java.nio.ByteBuffer) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 15 with Struct

use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.

the class FetchResponse method toStruct.

private static Struct toStruct(short version, LinkedHashMap<TopicPartition, PartitionData> responseData, int throttleTime) {
    Struct struct = new Struct(ApiKeys.FETCH.responseSchema(version));
    List<FetchRequest.TopicAndPartitionData<PartitionData>> topicsData = FetchRequest.TopicAndPartitionData.batchByTopic(responseData);
    List<Struct> topicArray = new ArrayList<>();
    for (FetchRequest.TopicAndPartitionData<PartitionData> topicEntry : topicsData) {
        Struct topicData = struct.instance(RESPONSES_KEY_NAME);
        topicData.set(TOPIC_KEY_NAME, topicEntry.topic);
        List<Struct> partitionArray = new ArrayList<>();
        for (Map.Entry<Integer, PartitionData> partitionEntry : topicEntry.partitions.entrySet()) {
            PartitionData fetchPartitionData = partitionEntry.getValue();
            Struct partitionData = topicData.instance(PARTITIONS_KEY_NAME);
            Struct partitionDataHeader = partitionData.instance(PARTITION_HEADER_KEY_NAME);
            partitionDataHeader.set(PARTITION_KEY_NAME, partitionEntry.getKey());
            partitionDataHeader.set(ERROR_CODE_KEY_NAME, fetchPartitionData.error.code());
            partitionDataHeader.set(HIGH_WATERMARK_KEY_NAME, fetchPartitionData.highWatermark);
            partitionData.set(PARTITION_HEADER_KEY_NAME, partitionDataHeader);
            partitionData.set(RECORD_SET_KEY_NAME, fetchPartitionData.records);
            partitionArray.add(partitionData);
        }
        topicData.set(PARTITIONS_KEY_NAME, partitionArray.toArray());
        topicArray.add(topicData);
    }
    struct.set(RESPONSES_KEY_NAME, topicArray.toArray());
    if (version >= 1)
        struct.set(THROTTLE_TIME_KEY_NAME, throttleTime);
    return struct;
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Struct(org.apache.kafka.common.protocol.types.Struct)

Aggregations

Struct (org.apache.kafka.common.protocol.types.Struct)63 ArrayList (java.util.ArrayList)32 Map (java.util.Map)22 HashMap (java.util.HashMap)19 ByteBuffer (java.nio.ByteBuffer)18 TopicPartition (org.apache.kafka.common.TopicPartition)10 Test (org.junit.Test)5 List (java.util.List)4 ByteBufferSend (org.apache.kafka.common.network.ByteBufferSend)4 Errors (org.apache.kafka.common.protocol.Errors)4 LinkedHashMap (java.util.LinkedHashMap)3 Node (org.apache.kafka.common.Node)2 Send (org.apache.kafka.common.network.Send)2 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)2 ArrayOf (org.apache.kafka.common.protocol.types.ArrayOf)2 Field (org.apache.kafka.common.protocol.types.Field)2 Schema (org.apache.kafka.common.protocol.types.Schema)2 ResponseHeader (org.apache.kafka.common.requests.ResponseHeader)2 Subscription (org.apache.kafka.clients.consumer.internals.PartitionAssignor.Subscription)1 MultiSend (org.apache.kafka.common.network.MultiSend)1