-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(WIP) KAFKA-18616; Refactor Tools's ApiMessageFormatter #18695
Open
dajac
wants to merge
2
commits into
apache:trunk
Choose a base branch
from
dajac:KAFKA-18616
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−160
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,50 +16,41 @@ | |
*/ | ||
package org.apache.kafka.tools.consumer; | ||
|
||
import org.apache.kafka.common.errors.UnsupportedVersionException; | ||
import org.apache.kafka.common.protocol.ByteBufferAccessor; | ||
import org.apache.kafka.common.protocol.ApiMessage; | ||
import org.apache.kafka.coordinator.common.runtime.CoordinatorRecord; | ||
import org.apache.kafka.coordinator.common.runtime.CoordinatorRecordSerde; | ||
import org.apache.kafka.coordinator.group.GroupCoordinatorRecordSerde; | ||
import org.apache.kafka.coordinator.group.generated.CoordinatorRecordJsonConverters; | ||
import org.apache.kafka.coordinator.group.generated.CoordinatorRecordType; | ||
import org.apache.kafka.coordinator.group.generated.OffsetCommitKey; | ||
import org.apache.kafka.coordinator.group.generated.OffsetCommitKeyJsonConverter; | ||
import org.apache.kafka.coordinator.group.generated.OffsetCommitValue; | ||
import org.apache.kafka.coordinator.group.generated.OffsetCommitValueJsonConverter; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.NullNode; | ||
import com.fasterxml.jackson.databind.node.TextNode; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Formatter for use with tools such as console consumer: Consumer should also set exclude.internal.topics to false. | ||
*/ | ||
public class OffsetsMessageFormatter extends ApiMessageFormatter { | ||
public class OffsetsMessageFormatter extends CoordinatorRecordMessageFormatter { | ||
private CoordinatorRecordSerde serde = new GroupCoordinatorRecordSerde(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can move |
||
|
||
@Override | ||
protected CoordinatorRecord deserialize(ByteBuffer key, ByteBuffer value) { | ||
return serde.deserialize(key, value); | ||
} | ||
|
||
@Override | ||
protected JsonNode readToKeyJson(ByteBuffer byteBuffer) { | ||
try { | ||
switch (CoordinatorRecordType.fromId(byteBuffer.getShort())) { | ||
// We can read both record types with the offset commit one. | ||
case LEGACY_OFFSET_COMMIT: | ||
case OFFSET_COMMIT: | ||
return OffsetCommitKeyJsonConverter.write( | ||
new OffsetCommitKey(new ByteBufferAccessor(byteBuffer), (short) 0), | ||
(short) 0 | ||
); | ||
protected boolean shouldPrint(short recordType) { | ||
return CoordinatorRecordType.OFFSET_COMMIT.id() == recordType || | ||
CoordinatorRecordType.LEGACY_OFFSET_COMMIT.id() == recordType; | ||
} | ||
|
||
default: | ||
return NullNode.getInstance(); | ||
} | ||
} catch (UnsupportedVersionException ex) { | ||
return NullNode.getInstance(); | ||
} | ||
@Override | ||
protected JsonNode keyAsJson(ApiMessage message) { | ||
return CoordinatorRecordJsonConverters.writeRecordKeyAsJson(message); | ||
} | ||
|
||
@Override | ||
protected JsonNode readToValueJson(ByteBuffer byteBuffer) { | ||
short version = byteBuffer.getShort(); | ||
if (version >= OffsetCommitValue.LOWEST_SUPPORTED_VERSION && version <= OffsetCommitValue.HIGHEST_SUPPORTED_VERSION) { | ||
return OffsetCommitValueJsonConverter.write(new OffsetCommitValue(new ByteBufferAccessor(byteBuffer), version), version); | ||
} | ||
return new TextNode(UNKNOWN); | ||
protected JsonNode valueAsJson(ApiMessage message, short version) { | ||
return CoordinatorRecordJsonConverters.writeRecordValueAsJson(message, version); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line#47 has checked the null, so this check is redundant.