Skip to content

Commit 5e2f54e

Browse files
authored
MINOR: Cleanup Connect Module (5/n) (#20393)
This PR aims at cleaning up the`connect:runtime` module further by getting rid of some extra code which can be replaced by record and the relevant changes. Reviewers: Chia-Ping Tsai <[email protected]>
1 parent 9ba7dd6 commit 5e2f54e

19 files changed

+123
-817
lines changed

connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractHerder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ private static ConfigInfos mergeConfigInfos(String connType, ConfigInfos... conf
897897
for (ConfigInfos configInfos : configInfosList) {
898898
if (configInfos != null) {
899899
errorCount += configInfos.errorCount();
900-
configInfoList.addAll(configInfos.values());
900+
configInfoList.addAll(configInfos.configs());
901901
groups.addAll(configInfos.groups());
902902
}
903903
}
@@ -1073,7 +1073,7 @@ protected final boolean maybeAddConfigErrors(
10731073
StringBuilder messages = new StringBuilder();
10741074
messages.append("Connector configuration is invalid and contains the following ")
10751075
.append(errors).append(" error(s):");
1076-
for (ConfigInfo configInfo : configInfos.values()) {
1076+
for (ConfigInfo configInfo : configInfos.configs()) {
10771077
for (String msg : configInfo.configValue().errors()) {
10781078
messages.append('\n').append(msg);
10791079
}

connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/entities/ConfigInfo.java

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,10 @@
1616
*/
1717
package org.apache.kafka.connect.runtime.rest.entities;
1818

19-
import com.fasterxml.jackson.annotation.JsonCreator;
2019
import com.fasterxml.jackson.annotation.JsonProperty;
2120

22-
import java.util.Objects;
23-
24-
public class ConfigInfo {
25-
26-
private final ConfigKeyInfo configKey;
27-
private final ConfigValueInfo configValue;
28-
29-
@JsonCreator
30-
public ConfigInfo(
31-
@JsonProperty("definition") ConfigKeyInfo configKey,
32-
@JsonProperty("value") ConfigValueInfo configValue) {
33-
this.configKey = configKey;
34-
this.configValue = configValue;
35-
}
36-
37-
@JsonProperty("definition")
38-
public ConfigKeyInfo configKey() {
39-
return configKey;
40-
}
41-
42-
@JsonProperty("value")
43-
public ConfigValueInfo configValue() {
44-
return configValue;
45-
}
46-
47-
@Override
48-
public boolean equals(Object o) {
49-
if (this == o) return true;
50-
if (o == null || getClass() != o.getClass()) return false;
51-
ConfigInfo that = (ConfigInfo) o;
52-
return Objects.equals(configKey, that.configKey) &&
53-
Objects.equals(configValue, that.configValue);
54-
}
55-
56-
@Override
57-
public int hashCode() {
58-
return Objects.hash(configKey, configValue);
59-
}
60-
61-
@Override
62-
public String toString() {
63-
return "[" + configKey + "," + configValue + "]";
64-
}
21+
public record ConfigInfo(
22+
@JsonProperty("definition") ConfigKeyInfo configKey,
23+
@JsonProperty("value") ConfigValueInfo configValue
24+
) {
6525
}

connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/entities/ConfigInfos.java

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -16,84 +16,14 @@
1616
*/
1717
package org.apache.kafka.connect.runtime.rest.entities;
1818

19-
import com.fasterxml.jackson.annotation.JsonCreator;
2019
import com.fasterxml.jackson.annotation.JsonProperty;
2120

2221
import java.util.List;
23-
import java.util.Objects;
2422

25-
public class ConfigInfos {
26-
27-
@JsonProperty("name")
28-
private final String name;
29-
30-
@JsonProperty("error_count")
31-
private final int errorCount;
32-
33-
@JsonProperty("groups")
34-
private final List<String> groups;
35-
36-
@JsonProperty("configs")
37-
private final List<ConfigInfo> configs;
38-
39-
@JsonCreator
40-
public ConfigInfos(@JsonProperty("name") String name,
41-
@JsonProperty("error_count") int errorCount,
42-
@JsonProperty("groups") List<String> groups,
43-
@JsonProperty("configs") List<ConfigInfo> configs) {
44-
this.name = name;
45-
this.groups = groups;
46-
this.errorCount = errorCount;
47-
this.configs = configs;
48-
}
49-
50-
@JsonProperty
51-
public String name() {
52-
return name;
53-
}
54-
55-
@JsonProperty
56-
public List<String> groups() {
57-
return groups;
58-
}
59-
60-
@JsonProperty("error_count")
61-
public int errorCount() {
62-
return errorCount;
63-
}
64-
65-
@JsonProperty("configs")
66-
public List<ConfigInfo> values() {
67-
return configs;
68-
}
69-
70-
@Override
71-
public boolean equals(Object o) {
72-
if (this == o) return true;
73-
if (o == null || getClass() != o.getClass()) return false;
74-
ConfigInfos that = (ConfigInfos) o;
75-
return Objects.equals(name, that.name) &&
76-
Objects.equals(errorCount, that.errorCount) &&
77-
Objects.equals(groups, that.groups) &&
78-
Objects.equals(configs, that.configs);
79-
}
80-
81-
@Override
82-
public int hashCode() {
83-
return Objects.hash(name, errorCount, groups, configs);
84-
}
85-
86-
@Override
87-
public String toString() {
88-
return "[" +
89-
name +
90-
"," +
91-
errorCount +
92-
"," +
93-
groups +
94-
"," +
95-
configs +
96-
"]";
97-
}
98-
99-
}
23+
public record ConfigInfos(
24+
@JsonProperty("name") String name,
25+
@JsonProperty("error_count") int errorCount,
26+
@JsonProperty("groups") List<String> groups,
27+
@JsonProperty("configs") List<ConfigInfo> configs
28+
) {
29+
}

connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/entities/ConfigKeyInfo.java

Lines changed: 13 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -16,153 +16,21 @@
1616
*/
1717
package org.apache.kafka.connect.runtime.rest.entities;
1818

19-
import com.fasterxml.jackson.annotation.JsonCreator;
2019
import com.fasterxml.jackson.annotation.JsonProperty;
2120

2221
import java.util.List;
23-
import java.util.Objects;
2422

25-
public class ConfigKeyInfo {
26-
27-
private final String name;
28-
private final String type;
29-
private final boolean required;
30-
private final String defaultValue;
31-
private final String importance;
32-
private final String documentation;
33-
private final String group;
34-
private final int orderInGroup;
35-
private final String width;
36-
private final String displayName;
37-
private final List<String> dependents;
38-
39-
@JsonCreator
40-
public ConfigKeyInfo(@JsonProperty("name") String name,
41-
@JsonProperty("type") String type,
42-
@JsonProperty("required") boolean required,
43-
@JsonProperty("default_value") String defaultValue,
44-
@JsonProperty("importance") String importance,
45-
@JsonProperty("documentation") String documentation,
46-
@JsonProperty("group") String group,
47-
@JsonProperty("order_in_group") int orderInGroup,
48-
@JsonProperty("width") String width,
49-
@JsonProperty("display_name") String displayName,
50-
@JsonProperty("dependents") List<String> dependents) {
51-
this.name = name;
52-
this.type = type;
53-
this.required = required;
54-
this.defaultValue = defaultValue;
55-
this.importance = importance;
56-
this.documentation = documentation;
57-
this.group = group;
58-
this.orderInGroup = orderInGroup;
59-
this.width = width;
60-
this.displayName = displayName;
61-
this.dependents = dependents;
62-
}
63-
64-
@JsonProperty
65-
public String name() {
66-
return name;
67-
}
68-
69-
@JsonProperty
70-
public String type() {
71-
return type;
72-
}
73-
74-
@JsonProperty
75-
public boolean required() {
76-
return required;
77-
}
78-
79-
@JsonProperty("default_value")
80-
public String defaultValue() {
81-
return defaultValue;
82-
}
83-
84-
@JsonProperty
85-
public String documentation() {
86-
return documentation;
87-
}
88-
89-
@JsonProperty
90-
public String group() {
91-
return group;
92-
}
93-
94-
@JsonProperty("order")
95-
public int orderInGroup() {
96-
return orderInGroup;
97-
}
98-
99-
@JsonProperty
100-
public String width() {
101-
return width;
102-
}
103-
104-
@JsonProperty
105-
public String importance() {
106-
return importance;
107-
}
108-
109-
@JsonProperty("display_name")
110-
public String displayName() {
111-
return displayName;
112-
}
113-
114-
@JsonProperty
115-
public List<String> dependents() {
116-
return dependents;
117-
}
118-
119-
@Override
120-
public boolean equals(Object o) {
121-
if (this == o) return true;
122-
if (o == null || getClass() != o.getClass()) return false;
123-
ConfigKeyInfo that = (ConfigKeyInfo) o;
124-
return Objects.equals(name, that.name) &&
125-
Objects.equals(type, that.type) &&
126-
Objects.equals(required, that.required) &&
127-
Objects.equals(defaultValue, that.defaultValue) &&
128-
Objects.equals(importance, that.importance) &&
129-
Objects.equals(documentation, that.documentation) &&
130-
Objects.equals(group, that.group) &&
131-
Objects.equals(orderInGroup, that.orderInGroup) &&
132-
Objects.equals(width, that.width) &&
133-
Objects.equals(displayName, that.displayName) &&
134-
Objects.equals(dependents, that.dependents);
135-
}
136-
137-
@Override
138-
public int hashCode() {
139-
return Objects.hash(name, type, required, defaultValue, importance, documentation, group, orderInGroup, width, displayName, dependents);
140-
}
141-
142-
@Override
143-
public String toString() {
144-
return "[" +
145-
name +
146-
"," +
147-
type +
148-
"," +
149-
required +
150-
"," +
151-
defaultValue +
152-
"," +
153-
importance +
154-
"," +
155-
documentation +
156-
"," +
157-
group +
158-
"," +
159-
orderInGroup +
160-
"," +
161-
width +
162-
"," +
163-
displayName +
164-
"," +
165-
dependents +
166-
"]";
167-
}
23+
public record ConfigKeyInfo(
24+
@JsonProperty("name") String name,
25+
@JsonProperty("type") String type,
26+
@JsonProperty("required") boolean required,
27+
@JsonProperty("default_value") String defaultValue,
28+
@JsonProperty("importance") String importance,
29+
@JsonProperty("documentation") String documentation,
30+
@JsonProperty("group") String group,
31+
@JsonProperty("order_in_group") int orderInGroup,
32+
@JsonProperty("width") String width,
33+
@JsonProperty("display_name") String displayName,
34+
@JsonProperty("dependents") List<String> dependents
35+
) {
16836
}

0 commit comments

Comments
 (0)