Skip to content

Commit 1568046

Browse files
authored
Merge pull request #25 from SourceLabOrg/sp/issue24
[ISSUE-24] Initial support for KIP-465
2 parents 7932d0e + c909904 commit 1568046

32 files changed

+1417
-60
lines changed

CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,57 @@
22
The format is based on [Keep a Changelog](http://keepachangelog.com/)
33
and this project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 2.1.0 (06/26/2019)
6+
7+
### New Features
8+
- Added support to retrieve information about the Kafka-Connect server being queried.
9+
10+
```java
11+
/**
12+
* Retrieve details about the Kafka-Connect service itself.
13+
* @return ConnectServerVersion
14+
*/
15+
public ConnectServerVersion getConnectServerVersion()
16+
```
17+
18+
- Added support for [Expanded Connectors API Endpoint KIP-465](https://cwiki.apache.org/confluence/display/KAFKA/KIP-465%3A+Add+Consolidated+Connector+Endpoint+to+Connect+REST+API).
19+
20+
Only supported by Kafka-Connect servers running version 2.3.0+ the following methods were added:
21+
22+
```java
23+
/**
24+
* Get a list of deployed connectors, including the status for each connector.
25+
* https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
26+
*
27+
* Requires Kafka-Connect 2.3.0+
28+
*
29+
* @return All deployed connectors, and their respective statuses.
30+
*/
31+
public ConnectorsWithExpandedStatus getConnectorsWithExpandedStatus()
32+
33+
/**
34+
* Get a list of deployed connectors, including the definition for each connector.
35+
* https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
36+
*
37+
* Requires Kafka-Connect 2.3.0+
38+
*
39+
* @return All deployed connectors, and their respective definition.
40+
*/
41+
public ConnectorsWithExpandedInfo getConnectorsWithExpandedInfo()
42+
43+
/**
44+
* Get a list of deployed connectors, including all metadata available.
45+
* Currently includes both 'info' {@see getConnectorsWithExpandedInfo} and 'status' {@see getConnectorsWithExpandedStatus}
46+
* metadata.
47+
* https://docs.confluent.io/current/connect/references/restapi.html#get--connectors
48+
*
49+
* Requires Kafka-Connect 2.3.0+
50+
*
51+
* @return All deployed connectors, and their respective metadata.
52+
*/
53+
public ConnectorsWithExpandedMetadata getConnectorsWithAllExpandedMetadata()
54+
```
55+
556
## 2.0.2 (06/06/2019)
657

758
### Internal Dependency Updates

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This client library is released on Maven Central. Add a new dependency to your
1212
<dependency>
1313
<groupId>org.sourcelab</groupId>
1414
<artifactId>kafka-connect-client</artifactId>
15-
<version>2.0.2</version>
15+
<version>2.1.0</version>
1616
</dependency>
1717
```
1818

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.sourcelab</groupId>
88
<artifactId>kafka-connect-client</artifactId>
9-
<version>2.0.2</version>
9+
<version>2.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<!-- Require Maven 3.3.9 -->

src/main/java/org/sourcelab/kafka/connect/apiclient/KafkaConnectClient.java

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,38 @@
1717

1818
package org.sourcelab.kafka.connect.apiclient;
1919

20+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
2021
import org.apache.http.HttpStatus;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
24+
import org.sourcelab.kafka.connect.apiclient.exception.ResponseParseException;
2325
import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory;
2426
import org.sourcelab.kafka.connect.apiclient.request.Request;
2527
import org.sourcelab.kafka.connect.apiclient.request.RequestErrorResponse;
2628
import org.sourcelab.kafka.connect.apiclient.request.delete.DeleteConnector;
29+
import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectServerVersion;
2730
import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition;
2831
import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPlugin;
2932
import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPluginConfigDefinition;
3033
import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPluginConfigValidationResults;
3134
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;
3238
import org.sourcelab.kafka.connect.apiclient.request.dto.NewConnectorDefinition;
3339
import org.sourcelab.kafka.connect.apiclient.request.dto.Task;
3440
import org.sourcelab.kafka.connect.apiclient.request.dto.TaskStatus;
41+
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectServerVersion;
3542
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnector;
3643
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorConfig;
3744
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorPlugins;
3845
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorStatus;
3946
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorTaskStatus;
4047
import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorTasks;
4148
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;
4252
import org.sourcelab.kafka.connect.apiclient.request.post.PostConnector;
4353
import org.sourcelab.kafka.connect.apiclient.request.post.PostConnectorRestart;
4454
import org.sourcelab.kafka.connect.apiclient.request.post.PostConnectorTaskRestart;
@@ -59,7 +69,7 @@
5969
/**
6070
* API Client for interacting with the Kafka-Connect Rest Endpoint.
6171
* 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
6373
*/
6474
public class KafkaConnectClient {
6575
private static final Logger logger = LoggerFactory.getLogger(KafkaConnectClient.class);
@@ -92,7 +102,7 @@ public KafkaConnectClient(final Configuration configuration) {
92102
/**
93103
* Constructor for injecting a RestClient implementation.
94104
* Typically only used in testing.
95-
* @param configuration Pardot Api Configuration.
105+
* @param configuration Api Client Configuration.
96106
* @param restClient RestClient implementation to use.
97107
*/
98108
public KafkaConnectClient(final Configuration configuration, final RestClient restClient) {
@@ -101,18 +111,64 @@ public KafkaConnectClient(final Configuration configuration, final RestClient re
101111
}
102112

103113
/**
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
106124
*
107125
* @return Collection of connector names currently deployed.
108126
*/
109127
public Collection<String> getConnectors() {
110128
return submitRequest(new GetConnectors());
111129
}
112130

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+
113169
/**
114170
* 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)
116172
* @param connectorName Name of connector.
117173
* @return Connector details.
118174
*/
@@ -122,7 +178,7 @@ public ConnectorDefinition getConnector(final String connectorName) {
122178

123179
/**
124180
* 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
126182
* @param connectorName Name of connector.
127183
* @return Configuration for connector.
128184
*/
@@ -132,7 +188,7 @@ public Map<String, String> getConnectorConfig(final String connectorName) {
132188

133189
/**
134190
* 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
136192
*
137193
* @param connectorName Name of connector.
138194
* @return Status details of the connector.
@@ -143,7 +199,7 @@ public ConnectorStatus getConnectorStatus(final String connectorName) {
143199

144200
/**
145201
* 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
147203
*
148204
* @param connectorDefinition Defines the new connector to deploy
149205
* @return connector info.
@@ -154,7 +210,7 @@ public ConnectorDefinition addConnector(final NewConnectorDefinition connectorDe
154210

155211
/**
156212
* 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
158214
*
159215
* @param connectorName Name of connector to update.
160216
* @param config Configuration values to set.
@@ -166,7 +222,7 @@ public ConnectorDefinition updateConnectorConfig(final String connectorName, fin
166222

167223
/**
168224
* 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
170226
*
171227
* @param connectorName Name of connector to restart.
172228
* @return Boolean true if success.
@@ -177,7 +233,7 @@ public Boolean restartConnector(final String connectorName) {
177233

178234
/**
179235
* 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
181237
*
182238
* @param connectorName Name of connector to pause.
183239
* @return Boolean true if success.
@@ -188,7 +244,7 @@ public Boolean pauseConnector(final String connectorName) {
188244

189245
/**
190246
* 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
192248
*
193249
* @param connectorName Name of connector to resume.
194250
* @return Boolean true if success.
@@ -199,7 +255,7 @@ public Boolean resumeConnector(final String connectorName) {
199255

200256
/**
201257
* 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
203259
*
204260
* @param connectorName Name of connector to resume.
205261
* @return Boolean true if success.
@@ -210,7 +266,7 @@ public Boolean deleteConnector(final String connectorName) {
210266

211267
/**
212268
* 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
214270
*
215271
* @param connectorName Name of connector to retrieve tasks for.
216272
* @return Collection of details about each task.
@@ -221,7 +277,7 @@ public Collection<Task> getConnectorTasks(final String connectorName) {
221277

222278
/**
223279
* 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
225281
*
226282
* @param connectorName Name of connector to retrieve tasks for.
227283
* @param taskId Id of task to get status for.
@@ -233,7 +289,7 @@ public TaskStatus getConnectorTaskStatus(final String connectorName, final int t
233289

234290
/**
235291
* 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
237293
*
238294
* @param connectorName Name of connector to restart tasks for.
239295
* @param taskId Id of task to restart
@@ -245,7 +301,7 @@ public Boolean restartConnectorTask(final String connectorName, final int taskId
245301

246302
/**
247303
* 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-
249305
*
250306
* @return Collection of available connector plugins.
251307
*/
@@ -256,7 +312,7 @@ public Collection<ConnectorPlugin> getConnectorPlugins() {
256312
/**
257313
* Validate the provided configuration values against the configuration definition. This API performs per config
258314
* 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
260316
*
261317
* @param configDefinition Defines the configuration to validate.
262318
* @return Results of the validation.
@@ -286,6 +342,8 @@ private <T> T submitRequest(final Request<T> request) {
286342

287343
try {
288344
return request.parseResponse(responseStr);
345+
} catch (final MismatchedInputException exception) {
346+
throw new ResponseParseException(exception.getMessage(), exception);
289347
} catch (final IOException exception) {
290348
throw new RuntimeException(exception.getMessage(), exception);
291349
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2018, 2019 SourceLab.org https://github.com/SourceLabOrg/kafka-connect-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package org.sourcelab.kafka.connect.apiclient.exception;
19+
20+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
21+
22+
/**
23+
* Thrown when the library is unable to properly parse the response from Kafka-Connect.
24+
*/
25+
public class ResponseParseException extends RuntimeException {
26+
/**
27+
* Constructor.
28+
* @param message error msg
29+
* @param exception underlying exception, if available.
30+
*/
31+
public ResponseParseException(final String message, final MismatchedInputException exception) {
32+
super(message, exception);
33+
}
34+
}

0 commit comments

Comments
 (0)