Skip to content

Commit 19da45f

Browse files
authored
Merge pull request #1 from Crim/sp/renameClient
rename ApiClient to KafkaConnectClient
2 parents 74d4119 + 094d493 commit 19da45f

File tree

11 files changed

+78
-83
lines changed

11 files changed

+78
-83
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,30 @@ Example Code:
3030
final Configuration configuration = new Configuration("hostname.for.kafka-connect.service.com:8083");
3131

3232
/*
33-
* Create an instance of ApiClient, passing your configuration.
33+
* Create an instance of KafkaConnectClient, passing your configuration.
3434
*/
35-
final ApiClient client = new ApiClient(configuration);
35+
final KafkaConnectClient client = new KafkaConnectClient(configuration);
3636

3737
/*
3838
* Making requests by calling the public methods available on ApiClient.
39+
*
40+
* For example, get a list of deployed connectors:
3941
*/
42+
final Collection<String> connectorList = client.getConnectors();
43+
44+
/*
45+
* Or to deploy a new connector:
46+
*/
47+
final ConnectorDefinition connectorDefition = client.addConnector(NewConnectorDefinition.newBuilder()
48+
.withName("MyNewConnector")
49+
.withConfig("connector.class", "org.apache.kafka.connect.tools.VerifiableSourceConnector")
50+
.withConfig("tasks.max", 3)
51+
.withConfig("topics", "test-topic")
52+
.build()
53+
));
4054
```
4155

42-
Public methods available on ApiClient can be [found here](src/main/java/org/sourcelab/kafka/connect/apiclient/ApiClient.java#L101-L266)
56+
Public methods available on KafkaConnectClient can be [found here](src/main/java/org/sourcelab/kafka/connect/apiclient/ApiClient.java#L101-L266)
4357

4458
## Changelog
4559

pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@
4646
<properties>
4747
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4848

49+
<!-- guava version -->
50+
<guava.version>24.0-jre</guava.version>
51+
52+
<!-- Http Components version -->
53+
<http-components.version>4.5.5</http-components.version>
54+
4955
<!-- Jackson version -->
50-
<jackson.version>2.9.3</jackson.version>
56+
<jackson.version>2.9.4</jackson.version>
5157

5258
<!-- Define which version of junit you'll be running -->
5359
<junit.version>4.12</junit.version>
@@ -75,14 +81,14 @@
7581
<dependency>
7682
<groupId>org.apache.httpcomponents</groupId>
7783
<artifactId>httpclient</artifactId>
78-
<version>4.5.4</version>
84+
<version>${http-components.version}</version>
7985
</dependency>
8086

8187
<!-- Guava for Preconditions and URI Escaping -->
8288
<dependency>
8389
<groupId>com.google.guava</groupId>
8490
<artifactId>guava</artifactId>
85-
<version>24.0-jre</version>
91+
<version>${guava.version}</version>
8692
</dependency>
8793

8894
<!-- For parsing XML responses to POJOs -->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* Also allows for configuring an optional proxy with or without authentication.
2424
*/
25-
public class Configuration {
25+
public final class Configuration {
2626
// Defines the URL/Hostname of Kafka-Connect
2727
private final String apiHost;
2828

src/main/java/org/sourcelab/kafka/connect/apiclient/ApiClient.java renamed to src/main/java/org/sourcelab/kafka/connect/apiclient/KafkaConnectClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
* Official Rest Endpoint documentation can be found here:
6060
* https://docs.confluent.io/current/connect/restapi.html
6161
*/
62-
public class ApiClient {
63-
private static final Logger logger = LoggerFactory.getLogger(ApiClient.class);
62+
public class KafkaConnectClient {
63+
private static final Logger logger = LoggerFactory.getLogger(KafkaConnectClient.class);
6464

6565
/**
6666
* Our API Configuration.
@@ -82,7 +82,7 @@ public class ApiClient {
8282
* Default Constructor.
8383
* @param configuration Api Client Configuration.
8484
*/
85-
public ApiClient(final Configuration configuration) {
85+
public KafkaConnectClient(final Configuration configuration) {
8686
this.configuration = configuration;
8787
this.restClient = new HttpClientRestClient();
8888
}
@@ -93,7 +93,7 @@ public ApiClient(final Configuration configuration) {
9393
* @param configuration Pardot Api Configuration.
9494
* @param restClient RestClient implementation to use.
9595
*/
96-
public ApiClient(final Configuration configuration, final RestClient restClient) {
96+
public KafkaConnectClient(final Configuration configuration, final RestClient restClient) {
9797
this.configuration = configuration;
9898
this.restClient = restClient;
9999
}
@@ -293,7 +293,7 @@ private <T> T submitRequest(final Request<T> request) {
293293
try {
294294
final RequestErrorResponse errorResponse = JacksonFactory.newInstance().readValue(responseStr, RequestErrorResponse.class);
295295
throw new InvalidRequestException(errorResponse.getMessage(), errorResponse.getErrorCode());
296-
} catch (IOException e) {
296+
} catch (final IOException e) {
297297
// swallow
298298
}
299299
throw new InvalidRequestException("Invalid response from server: " + responseStr, restResponse.getHttpCode());

src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorPluginConfigValidation.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/org/sourcelab/kafka/connect/apiclient/rest/HttpClientRestClient.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void close() {
147147
if (httpClient != null) {
148148
try {
149149
httpClient.close();
150-
} catch (IOException e) {
150+
} catch (final IOException e) {
151151
logger.error("Error closing: {}", e.getMessage(), e);
152152
}
153153
}
@@ -178,7 +178,7 @@ public RestResponse submitRequest(final Request request) throws RestException {
178178
default:
179179
throw new IllegalArgumentException("Unknown Request Method: " + request.getRequestMethod());
180180
}
181-
} catch (IOException exception) {
181+
} catch (final IOException exception) {
182182
throw new RestException(exception.getMessage(), exception);
183183
}
184184
}
@@ -198,7 +198,7 @@ private <T> T submitGetRequest(final String url, final Map<String, String> getPa
198198
.setCharset(StandardCharsets.UTF_8);
199199

200200
// Attach submitRequest params
201-
for (Map.Entry<String, String> entry : getParams.entrySet()) {
201+
for (final Map.Entry<String, String> entry : getParams.entrySet()) {
202202
uriBuilder.setParameter(entry.getKey(), entry.getValue());
203203
}
204204

@@ -215,12 +215,12 @@ private <T> T submitGetRequest(final String url, final Map<String, String> getPa
215215

216216
// Execute and return
217217
return httpClient.execute(get, responseHandler);
218-
} catch (ClientProtocolException e) {
218+
} catch (final ClientProtocolException e) {
219219
e.printStackTrace();
220-
} catch (IOException e) {
220+
} catch (final IOException e) {
221221
// Typically this is a parse error.
222222
e.printStackTrace();
223-
} catch (URISyntaxException e) {
223+
} catch (final URISyntaxException e) {
224224
// Bad URI building
225225
e.printStackTrace();
226226
}
@@ -257,9 +257,9 @@ private <T> T submitPostRequest(final String url, final Object requestBody, fina
257257

258258
// Execute and return
259259
return httpClient.execute(post, responseHandler);
260-
} catch (ClientProtocolException e) {
260+
} catch (final ClientProtocolException e) {
261261
e.printStackTrace();
262-
} catch (IOException e) {
262+
} catch (final IOException e) {
263263
// Typically this is a parse error.
264264
e.printStackTrace();
265265
}
@@ -296,12 +296,12 @@ private <T> T submitPutRequest(final String url, final Object requestBody, final
296296

297297
// Execute and return
298298
return httpClient.execute(put, responseHandler);
299-
} catch (ClientProtocolException e) {
299+
} catch (final ClientProtocolException e) {
300300
e.printStackTrace();
301-
} catch (IOException e) {
301+
} catch (final IOException e) {
302302
// Typically this is a parse error.
303303
e.printStackTrace();
304-
} catch (URISyntaxException e) {
304+
} catch (final URISyntaxException e) {
305305
// Bad URI building
306306
e.printStackTrace();
307307
}
@@ -340,12 +340,12 @@ private <T> T submitDeleteRequest(final String url, final Object requestBody, fi
340340

341341
// Execute and return
342342
return httpClient.execute(delete, responseHandler);
343-
} catch (ClientProtocolException e) {
343+
} catch (final ClientProtocolException e) {
344344
e.printStackTrace();
345-
} catch (IOException e) {
345+
} catch (final IOException e) {
346346
// Typically this is a parse error.
347347
e.printStackTrace();
348-
} catch (URISyntaxException e) {
348+
} catch (final URISyntaxException e) {
349349
// Bad URI building
350350
e.printStackTrace();
351351
}

src/main/java/org/sourcelab/kafka/connect/apiclient/rest/RestResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Represents the response from the API.
2222
*/
23-
public class RestResponse {
23+
public final class RestResponse {
2424
private final String responseStr;
2525
private final int httpCode;
2626

src/main/java/org/sourcelab/kafka/connect/apiclient/rest/handlers/RestResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Handles parsing a response to RestResponse object.
3232
*/
33-
public class RestResponseHandler implements ResponseHandler<RestResponse> {
33+
public final class RestResponseHandler implements ResponseHandler<RestResponse> {
3434
private static final Logger logger = LoggerFactory.getLogger(RestResponseHandler.class);
3535

3636
@Override
@@ -46,7 +46,7 @@ public RestResponse handleResponse(final HttpResponse response) {
4646

4747
// Construct return object
4848
return new RestResponse(responseStr, statusCode);
49-
} catch (IOException exception) {
49+
} catch (final IOException exception) {
5050
logger.error("Failed to read entity: {}", exception.getMessage(), exception);
5151
// TODO throw exception
5252
return null;

src/main/java/org/sourcelab/kafka/connect/apiclient/rest/handlers/StringResponseHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Returns response as a string.
2929
*/
30-
public class StringResponseHandler implements ResponseHandler<String> {
30+
public final class StringResponseHandler implements ResponseHandler<String> {
3131
@Override
3232
public String handleResponse(final HttpResponse response) throws IOException {
3333

src/test/java/BadLoggersTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public void doTest() throws FileNotFoundException {
4848
walk(projectRootPath);
4949
}
5050

51-
private void walk(File root) throws FileNotFoundException {
52-
File[] list = root.listFiles();
51+
private void walk(final File root) throws FileNotFoundException {
52+
final File[] list = root.listFiles();
5353

5454
if (list == null) return;
5555

56-
for (File f : list) {
56+
for (final File f : list) {
5757
if (f.isDirectory()) {
5858
walk(f);
5959
} else {
@@ -66,27 +66,27 @@ private void walk(File root) throws FileNotFoundException {
6666
}
6767
}
6868

69-
private void testFile(File myFile) throws FileNotFoundException {
70-
String fileData = new Scanner(myFile).useDelimiter("\\Z").next();
69+
private void testFile(final File myFile) throws FileNotFoundException {
70+
final String fileData = new Scanner(myFile).useDelimiter("\\Z").next();
7171

7272
// Look for our pattern
73-
Matcher matches = regexPattern.matcher(fileData);
73+
final Matcher matches = regexPattern.matcher(fileData);
7474

7575
// If we didn't find a match
7676
if (!matches.find()) {
7777
return;
7878
}
7979

8080
// Grab out the Class name
81-
String loggerClassName = matches.group(1);
81+
final String loggerClassName = matches.group(1);
8282
if (loggerClassName == null) {
8383
return;
8484
}
8585

8686
// Get class name from the file name
8787
// I bet this will be completely broken for inner classes...
8888
// if you run into that, just exclude it? or figure out a better solution to this :p
89-
String className = myFile.getName().replace(".java", "");
89+
final String className = myFile.getName().replace(".java", "");
9090
if (!className.equals(loggerClassName)) {
9191
logger.info("Class {} ClassNameUsedByLogger {} ", className, loggerClassName);
9292
assertFalse("Found instance of logger using wrong class? " + myFile.getPath() + " Using " + loggerClassName, true);

0 commit comments

Comments
 (0)