use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class RequestResponseTest method checkResponse.
private void checkResponse(AbstractResponse response, int version) throws Exception {
// Check that we can serialize, deserialize and serialize again
// We don't check for equality or hashCode because it is likely to fail for any response containing a HashMap
Struct struct = response.toStruct((short) version);
AbstractResponse deserialized = (AbstractResponse) deserialize(response, struct, (short) version);
deserialized.toStruct((short) version);
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class RequestResponseTest method testControlledShutdownResponse.
@Test
public void testControlledShutdownResponse() {
ControlledShutdownResponse response = createControlledShutdownResponse();
short version = ApiKeys.CONTROLLED_SHUTDOWN_KEY.latestVersion();
Struct struct = response.toStruct(version);
ByteBuffer buffer = toBuffer(struct);
ControlledShutdownResponse deserialized = ControlledShutdownResponse.parse(buffer, version);
assertEquals(response.error(), deserialized.error());
assertEquals(response.partitionsRemaining(), deserialized.partitionsRemaining());
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class SyncGroupRequest method toStruct.
@Override
protected Struct toStruct() {
Struct struct = new Struct(ApiKeys.SYNC_GROUP.requestSchema(version()));
struct.set(GROUP_ID_KEY_NAME, groupId);
struct.set(GENERATION_ID_KEY_NAME, generationId);
struct.set(MEMBER_ID_KEY_NAME, memberId);
List<Struct> memberArray = new ArrayList<>();
for (Map.Entry<String, ByteBuffer> entries : groupAssignment.entrySet()) {
Struct memberData = struct.instance(GROUP_ASSIGNMENT_KEY_NAME);
memberData.set(MEMBER_ID_KEY_NAME, entries.getKey());
memberData.set(MEMBER_ASSIGNMENT_KEY_NAME, entries.getValue());
memberArray.add(memberData);
}
struct.set(GROUP_ASSIGNMENT_KEY_NAME, memberArray.toArray());
return struct;
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class SyncGroupResponse method toStruct.
@Override
protected Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.SYNC_GROUP.responseSchema(version));
struct.set(ERROR_CODE_KEY_NAME, error.code());
struct.set(MEMBER_ASSIGNMENT_KEY_NAME, memberState);
return struct;
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class UpdateMetadataRequest method toStruct.
@Override
protected Struct toStruct() {
short version = version();
Struct struct = new Struct(ApiKeys.UPDATE_METADATA_KEY.requestSchema(version));
struct.set(CONTROLLER_ID_KEY_NAME, controllerId);
struct.set(CONTROLLER_EPOCH_KEY_NAME, controllerEpoch);
List<Struct> partitionStatesData = new ArrayList<>(partitionStates.size());
for (Map.Entry<TopicPartition, PartitionState> entry : partitionStates.entrySet()) {
Struct partitionStateData = struct.instance(PARTITION_STATES_KEY_NAME);
TopicPartition topicPartition = entry.getKey();
partitionStateData.set(TOPIC_KEY_NAME, topicPartition.topic());
partitionStateData.set(PARTITION_KEY_NAME, topicPartition.partition());
PartitionState partitionState = entry.getValue();
partitionStateData.set(CONTROLLER_EPOCH_KEY_NAME, partitionState.controllerEpoch);
partitionStateData.set(LEADER_KEY_NAME, partitionState.leader);
partitionStateData.set(LEADER_EPOCH_KEY_NAME, partitionState.leaderEpoch);
partitionStateData.set(ISR_KEY_NAME, partitionState.isr.toArray());
partitionStateData.set(ZK_VERSION_KEY_NAME, partitionState.zkVersion);
partitionStateData.set(REPLICAS_KEY_NAME, partitionState.replicas.toArray());
partitionStatesData.add(partitionStateData);
}
struct.set(PARTITION_STATES_KEY_NAME, partitionStatesData.toArray());
List<Struct> brokersData = new ArrayList<>(liveBrokers.size());
for (Broker broker : liveBrokers) {
Struct brokerData = struct.instance(LIVE_BROKERS_KEY_NAME);
brokerData.set(BROKER_ID_KEY_NAME, broker.id);
if (version == 0) {
EndPoint endPoint = broker.endPoints.get(0);
brokerData.set(HOST_KEY_NAME, endPoint.host);
brokerData.set(PORT_KEY_NAME, endPoint.port);
} else {
List<Struct> endPointsData = new ArrayList<>(broker.endPoints.size());
for (EndPoint endPoint : broker.endPoints) {
Struct endPointData = brokerData.instance(ENDPOINTS_KEY_NAME);
endPointData.set(PORT_KEY_NAME, endPoint.port);
endPointData.set(HOST_KEY_NAME, endPoint.host);
endPointData.set(SECURITY_PROTOCOL_TYPE_KEY_NAME, endPoint.securityProtocol.id);
if (version >= 3)
endPointData.set(LISTENER_NAME_KEY_NAME, endPoint.listenerName.value());
endPointsData.add(endPointData);
}
brokerData.set(ENDPOINTS_KEY_NAME, endPointsData.toArray());
if (version >= 2) {
brokerData.set(RACK_KEY_NAME, broker.rack);
}
}
brokersData.add(brokerData);
}
struct.set(LIVE_BROKERS_KEY_NAME, brokersData.toArray());
return struct;
}
Aggregations