19
19
import org .apache .kafka .clients .admin .DeleteShareGroupOffsetsOptions ;
20
20
import org .apache .kafka .clients .admin .KafkaAdminClient ;
21
21
import org .apache .kafka .common .Node ;
22
- import org .apache .kafka .common .TopicPartition ;
23
22
import org .apache .kafka .common .errors .ApiException ;
24
23
import org .apache .kafka .common .message .DeleteShareGroupOffsetsRequestData ;
25
24
import org .apache .kafka .common .protocol .Errors ;
38
37
import java .util .List ;
39
38
import java .util .Map ;
40
39
import java .util .Set ;
41
- import java .util .stream .Collectors ;
42
40
43
41
/**
44
42
* This class is the handler for {@link KafkaAdminClient#deleteShareGroupOffsets(String, Set, DeleteShareGroupOffsetsOptions)} call
45
43
*/
46
- public class DeleteShareGroupOffsetsHandler extends AdminApiHandler .Batched <CoordinatorKey , Map <TopicPartition , ApiException >> {
44
+ public class DeleteShareGroupOffsetsHandler extends AdminApiHandler .Batched <CoordinatorKey , Map <String , ApiException >> {
47
45
48
46
private final CoordinatorKey groupId ;
49
47
50
48
private final Logger log ;
51
49
52
- private final Set <TopicPartition > partitions ;
50
+ private final Set <String > topics ;
53
51
54
52
private final CoordinatorStrategy lookupStrategy ;
55
53
56
- public DeleteShareGroupOffsetsHandler (String groupId , Set <TopicPartition > partitions , LogContext logContext ) {
54
+ public DeleteShareGroupOffsetsHandler (String groupId , Set <String > topics , LogContext logContext ) {
57
55
this .groupId = CoordinatorKey .byGroupId (groupId );
58
- this .partitions = partitions ;
56
+ this .topics = topics ;
59
57
this .log = logContext .logger (DeleteShareGroupOffsetsHandler .class );
60
58
this .lookupStrategy = new CoordinatorStrategy (FindCoordinatorRequest .CoordinatorType .GROUP , logContext );
61
59
}
@@ -70,7 +68,7 @@ public AdminApiLookupStrategy<CoordinatorKey> lookupStrategy() {
70
68
return lookupStrategy ;
71
69
}
72
70
73
- public static AdminApiFuture .SimpleAdminApiFuture <CoordinatorKey , Map <TopicPartition , ApiException >> newFuture (String groupId ) {
71
+ public static AdminApiFuture .SimpleAdminApiFuture <CoordinatorKey , Map <String , ApiException >> newFuture (String groupId ) {
74
72
return AdminApiFuture .forKeys (Collections .singleton (CoordinatorKey .byGroupId (groupId )));
75
73
}
76
74
@@ -85,26 +83,22 @@ private void validateKeys(Set<CoordinatorKey> groupIds) {
85
83
DeleteShareGroupOffsetsRequest .Builder buildBatchedRequest (int brokerId , Set <CoordinatorKey > groupIds ) {
86
84
validateKeys (groupIds );
87
85
88
- final List <DeleteShareGroupOffsetsRequestData .DeleteShareGroupOffsetsRequestTopic > topics =
86
+ final List <DeleteShareGroupOffsetsRequestData .DeleteShareGroupOffsetsRequestTopic > requestTopics =
89
87
new ArrayList <>();
90
- partitions . stream (). collect ( Collectors . groupingBy ( TopicPartition :: topic )). forEach (( topic , topicPartitions ) -> topics .add (
88
+ topics . forEach (topic -> requestTopics .add (
91
89
new DeleteShareGroupOffsetsRequestData .DeleteShareGroupOffsetsRequestTopic ()
92
90
.setTopicName (topic )
93
- .setPartitions (topicPartitions .stream ()
94
- .map (TopicPartition ::partition )
95
- .collect (Collectors .toList ())
96
- )
97
91
));
98
92
99
93
return new DeleteShareGroupOffsetsRequest .Builder (
100
94
new DeleteShareGroupOffsetsRequestData ()
101
95
.setGroupId (groupId .idValue )
102
- .setTopics (topics )
96
+ .setTopics (requestTopics )
103
97
);
104
98
}
105
99
106
100
@ Override
107
- public ApiResult <CoordinatorKey , Map <TopicPartition , ApiException >> handleResponse (
101
+ public ApiResult <CoordinatorKey , Map <String , ApiException >> handleResponse (
108
102
Node coordinator ,
109
103
Set <CoordinatorKey > groupIds ,
110
104
AbstractResponse abstractResponse
@@ -123,23 +117,21 @@ public ApiResult<CoordinatorKey, Map<TopicPartition, ApiException>> handleRespon
123
117
124
118
return new ApiResult <>(Collections .emptyMap (), groupsFailed , new ArrayList <>(groupsToUnmap ));
125
119
} else {
126
- final Map <TopicPartition , ApiException > partitionResults = new HashMap <>();
127
- response .data ().responses ().forEach (topic ->
128
- topic .partitions ().forEach (partition -> {
129
- if (partition .errorCode () != Errors .NONE .code ()) {
130
- final Errors partitionError = Errors .forCode (partition .errorCode ());
131
- final String partitionErrorMessage = partition .errorMessage ();
132
- log .debug ("DeleteShareGroupOffsets request for group id {}, topic {} and partition {} failed and returned error {}." + partitionErrorMessage ,
133
- groupId .idValue , topic .topicName (), partition .partitionIndex (), partitionError );
134
- }
135
- partitionResults .put (
136
- new TopicPartition (topic .topicName (), partition .partitionIndex ()),
137
- Errors .forCode (partition .errorCode ()).exception (partition .errorMessage ())
138
- );
139
- })
140
- );
141
-
142
- return ApiResult .completed (groupId , partitionResults );
120
+ final Map <String , ApiException > topicResults = new HashMap <>();
121
+ response .data ().responses ().forEach (topic -> {
122
+ if (topic .errorCode () != Errors .NONE .code ()) {
123
+ final Errors topicError = Errors .forCode (topic .errorCode ());
124
+ final String topicErrorMessage = topic .errorMessage ();
125
+ log .debug ("DeleteShareGroupOffsets request for group id {} and topic {} failed and returned error {}." + topicErrorMessage ,
126
+ groupId .idValue , topic .topicName (), topicError );
127
+ }
128
+ topicResults .put (
129
+ topic .topicName (),
130
+ Errors .forCode (topic .errorCode ()).exception (topic .errorMessage ())
131
+ );
132
+ });
133
+
134
+ return ApiResult .completed (groupId , topicResults );
143
135
}
144
136
}
145
137
0 commit comments