17
17
18
18
package org .sourcelab .kafka .connect .apiclient ;
19
19
20
+ import com .fasterxml .jackson .databind .exc .MismatchedInputException ;
20
21
import org .apache .http .HttpStatus ;
21
22
import org .slf4j .Logger ;
22
23
import org .slf4j .LoggerFactory ;
24
+ import org .sourcelab .kafka .connect .apiclient .exception .ResponseParseException ;
23
25
import org .sourcelab .kafka .connect .apiclient .request .JacksonFactory ;
24
26
import org .sourcelab .kafka .connect .apiclient .request .Request ;
25
27
import org .sourcelab .kafka .connect .apiclient .request .RequestErrorResponse ;
26
28
import org .sourcelab .kafka .connect .apiclient .request .delete .DeleteConnector ;
29
+ import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectServerVersion ;
27
30
import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorDefinition ;
28
31
import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorPlugin ;
29
32
import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorPluginConfigDefinition ;
30
33
import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorPluginConfigValidationResults ;
31
34
import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorStatus ;
35
+ import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorsWithExpandedInfo ;
36
+ import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorsWithExpandedMetadata ;
37
+ import org .sourcelab .kafka .connect .apiclient .request .dto .ConnectorsWithExpandedStatus ;
32
38
import org .sourcelab .kafka .connect .apiclient .request .dto .NewConnectorDefinition ;
33
39
import org .sourcelab .kafka .connect .apiclient .request .dto .Task ;
34
40
import org .sourcelab .kafka .connect .apiclient .request .dto .TaskStatus ;
41
+ import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectServerVersion ;
35
42
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnector ;
36
43
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorConfig ;
37
44
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorPlugins ;
38
45
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorStatus ;
39
46
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorTaskStatus ;
40
47
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorTasks ;
41
48
import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectors ;
49
+ import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorsExpandAllDetails ;
50
+ import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorsExpandInfo ;
51
+ import org .sourcelab .kafka .connect .apiclient .request .get .GetConnectorsExpandStatus ;
42
52
import org .sourcelab .kafka .connect .apiclient .request .post .PostConnector ;
43
53
import org .sourcelab .kafka .connect .apiclient .request .post .PostConnectorRestart ;
44
54
import org .sourcelab .kafka .connect .apiclient .request .post .PostConnectorTaskRestart ;
59
69
/**
60
70
* API Client for interacting with the Kafka-Connect Rest Endpoint.
61
71
* Official Rest Endpoint documentation can be found here:
62
- * https://docs.confluent.io/current/connect/restapi.html
72
+ * https://docs.confluent.io/current/connect/references/ restapi.html
63
73
*/
64
74
public class KafkaConnectClient {
65
75
private static final Logger logger = LoggerFactory .getLogger (KafkaConnectClient .class );
@@ -92,7 +102,7 @@ public KafkaConnectClient(final Configuration configuration) {
92
102
/**
93
103
* Constructor for injecting a RestClient implementation.
94
104
* Typically only used in testing.
95
- * @param configuration Pardot Api Configuration.
105
+ * @param configuration Api Client Configuration.
96
106
* @param restClient RestClient implementation to use.
97
107
*/
98
108
public KafkaConnectClient (final Configuration configuration , final RestClient restClient ) {
@@ -101,18 +111,64 @@ public KafkaConnectClient(final Configuration configuration, final RestClient re
101
111
}
102
112
103
113
/**
104
- * Get a list of active connectors.
105
- * https://docs.confluent.io/current/connect/restapi.html#get--connectors
114
+ * Retrieve details about the Kafka-Connect service itself.
115
+ * @return ConnectServerVersion
116
+ */
117
+ public ConnectServerVersion getConnectServerVersion () {
118
+ return submitRequest (new GetConnectServerVersion ());
119
+ }
120
+
121
+ /**
122
+ * Get a list of deployed connectors.
123
+ * https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
106
124
*
107
125
* @return Collection of connector names currently deployed.
108
126
*/
109
127
public Collection <String > getConnectors () {
110
128
return submitRequest (new GetConnectors ());
111
129
}
112
130
131
+ /**
132
+ * Get a list of deployed connectors, including the status for each connector.
133
+ * https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
134
+ *
135
+ * Requires Kafka-Connect 2.3.0+
136
+ *
137
+ * @return All deployed connectors, and their respective statuses.
138
+ */
139
+ public ConnectorsWithExpandedStatus getConnectorsWithExpandedStatus () {
140
+ return submitRequest (new GetConnectorsExpandStatus ());
141
+ }
142
+
143
+ /**
144
+ * Get a list of deployed connectors, including the definition for each connector.
145
+ * https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
146
+ *
147
+ * Requires Kafka-Connect 2.3.0+
148
+ *
149
+ * @return All deployed connectors, and their respective definition.
150
+ */
151
+ public ConnectorsWithExpandedInfo getConnectorsWithExpandedInfo () {
152
+ return submitRequest (new GetConnectorsExpandInfo ());
153
+ }
154
+
155
+ /**
156
+ * Get a list of deployed connectors, including all metadata available.
157
+ * Currently includes both 'info' {@see getConnectorsWithExpandedInfo} and 'status' {@see getConnectorsWithExpandedStatus}
158
+ * metadata.
159
+ * https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
160
+ *
161
+ * Requires Kafka-Connect 2.3.0+
162
+ *
163
+ * @return All deployed connectors, and their respective metadata.
164
+ */
165
+ public ConnectorsWithExpandedMetadata getConnectorsWithAllExpandedMetadata () {
166
+ return submitRequest (new GetConnectorsExpandAllDetails ());
167
+ }
168
+
113
169
/**
114
170
* Get information about the connector.
115
- * https://docs.confluent.io/current/connect/restapi.html#get--connectors-(string-name)
171
+ * https://docs.confluent.io/current/connect/references/ restapi.html#get--connectors-(string-name)
116
172
* @param connectorName Name of connector.
117
173
* @return Connector details.
118
174
*/
@@ -122,7 +178,7 @@ public ConnectorDefinition getConnector(final String connectorName) {
122
178
123
179
/**
124
180
* Get the configuration for the connector.
125
- * https://docs.confluent.io/current/connect/restapi.html#get--connectors-(string-name)-config
181
+ * https://docs.confluent.io/current/connect/references/ restapi.html#get--connectors-(string-name)-config
126
182
* @param connectorName Name of connector.
127
183
* @return Configuration for connector.
128
184
*/
@@ -132,7 +188,7 @@ public Map<String, String> getConnectorConfig(final String connectorName) {
132
188
133
189
/**
134
190
* Get the status of specified connector by name.
135
- * https://docs.confluent.io/current/connect/restapi.html#get--connectors-(string-name)-config
191
+ * https://docs.confluent.io/current/connect/references/ restapi.html#get--connectors-(string-name)-config
136
192
*
137
193
* @param connectorName Name of connector.
138
194
* @return Status details of the connector.
@@ -143,7 +199,7 @@ public ConnectorStatus getConnectorStatus(final String connectorName) {
143
199
144
200
/**
145
201
* Create a new connector, returning the current connector info if successful.
146
- * https://docs.confluent.io/current/connect/restapi.html#post--connectors
202
+ * https://docs.confluent.io/current/connect/references/ restapi.html#post--connectors
147
203
*
148
204
* @param connectorDefinition Defines the new connector to deploy
149
205
* @return connector info.
@@ -154,7 +210,7 @@ public ConnectorDefinition addConnector(final NewConnectorDefinition connectorDe
154
210
155
211
/**
156
212
* Update a connector's configuration.
157
- * https://docs.confluent.io/current/connect/restapi.html#put--connectors-(string-name)-config
213
+ * https://docs.confluent.io/current/connect/references/ restapi.html#put--connectors-(string-name)-config
158
214
*
159
215
* @param connectorName Name of connector to update.
160
216
* @param config Configuration values to set.
@@ -166,7 +222,7 @@ public ConnectorDefinition updateConnectorConfig(final String connectorName, fin
166
222
167
223
/**
168
224
* Restart a connector.
169
- * https://docs.confluent.io/current/connect/restapi.html#post--connectors-(string-name)-restart
225
+ * https://docs.confluent.io/current/connect/references/ restapi.html#post--connectors-(string-name)-restart
170
226
*
171
227
* @param connectorName Name of connector to restart.
172
228
* @return Boolean true if success.
@@ -177,7 +233,7 @@ public Boolean restartConnector(final String connectorName) {
177
233
178
234
/**
179
235
* Pause a connector.
180
- * https://docs.confluent.io/current/connect/restapi.html#put--connectors-(string-name)-pause
236
+ * https://docs.confluent.io/current/connect/references/ restapi.html#put--connectors-(string-name)-pause
181
237
*
182
238
* @param connectorName Name of connector to pause.
183
239
* @return Boolean true if success.
@@ -188,7 +244,7 @@ public Boolean pauseConnector(final String connectorName) {
188
244
189
245
/**
190
246
* Resume a connector.
191
- * https://docs.confluent.io/current/connect/restapi.html#put--connectors-(string-name)-resume
247
+ * https://docs.confluent.io/current/connect/references/ restapi.html#put--connectors-(string-name)-resume
192
248
*
193
249
* @param connectorName Name of connector to resume.
194
250
* @return Boolean true if success.
@@ -199,7 +255,7 @@ public Boolean resumeConnector(final String connectorName) {
199
255
200
256
/**
201
257
* Resume a connector.
202
- * https://docs.confluent.io/current/connect/restapi.html#put--connectors-(string-name)-resume
258
+ * https://docs.confluent.io/current/connect/references/ restapi.html#put--connectors-(string-name)-resume
203
259
*
204
260
* @param connectorName Name of connector to resume.
205
261
* @return Boolean true if success.
@@ -210,7 +266,7 @@ public Boolean deleteConnector(final String connectorName) {
210
266
211
267
/**
212
268
* Get a list of tasks currently running for the connector.
213
- * https://docs.confluent.io/current/connect/restapi.html#get--connectors-(string-name)-tasks
269
+ * https://docs.confluent.io/current/connect/references/ restapi.html#get--connectors-(string-name)-tasks
214
270
*
215
271
* @param connectorName Name of connector to retrieve tasks for.
216
272
* @return Collection of details about each task.
@@ -221,7 +277,7 @@ public Collection<Task> getConnectorTasks(final String connectorName) {
221
277
222
278
/**
223
279
* Get a task’s status.
224
- * https://docs.confluent.io/current/connect/restapi.html#get--connectors-(string-name)-tasks-(int-taskid)-status
280
+ * https://docs.confluent.io/current/connect/references/ restapi.html#get--connectors-(string-name)-tasks-(int-taskid)-status
225
281
*
226
282
* @param connectorName Name of connector to retrieve tasks for.
227
283
* @param taskId Id of task to get status for.
@@ -233,7 +289,7 @@ public TaskStatus getConnectorTaskStatus(final String connectorName, final int t
233
289
234
290
/**
235
291
* Restart an individual task.
236
- * https://docs.confluent.io/current/connect/restapi.html#post--connectors-(string-name)-tasks-(int-taskid)-restart
292
+ * https://docs.confluent.io/current/connect/references/ restapi.html#post--connectors-(string-name)-tasks-(int-taskid)-restart
237
293
*
238
294
* @param connectorName Name of connector to restart tasks for.
239
295
* @param taskId Id of task to restart
@@ -245,7 +301,7 @@ public Boolean restartConnectorTask(final String connectorName, final int taskId
245
301
246
302
/**
247
303
* Return a list of connector plugins installed in the Kafka Connect cluster.
248
- * https://docs.confluent.io/current/connect/restapi.html#get--connector-plugins-
304
+ * https://docs.confluent.io/current/connect/references/ restapi.html#get--connector-plugins-
249
305
*
250
306
* @return Collection of available connector plugins.
251
307
*/
@@ -256,7 +312,7 @@ public Collection<ConnectorPlugin> getConnectorPlugins() {
256
312
/**
257
313
* Validate the provided configuration values against the configuration definition. This API performs per config
258
314
* validation, returns suggested values and error messages during validation.
259
- * https://docs.confluent.io/current/connect/restapi.html#put--connector-plugins-(string-name)-config-validate
315
+ * https://docs.confluent.io/current/connect/references/ restapi.html#put--connector-plugins-(string-name)-config-validate
260
316
*
261
317
* @param configDefinition Defines the configuration to validate.
262
318
* @return Results of the validation.
@@ -286,6 +342,8 @@ private <T> T submitRequest(final Request<T> request) {
286
342
287
343
try {
288
344
return request .parseResponse (responseStr );
345
+ } catch (final MismatchedInputException exception ) {
346
+ throw new ResponseParseException (exception .getMessage (), exception );
289
347
} catch (final IOException exception ) {
290
348
throw new RuntimeException (exception .getMessage (), exception );
291
349
}
0 commit comments