├── .github └── workflows │ └── main.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build ├── LICENSE.txt └── checkstyle-v1.5.xml ├── pom.xml └── src ├── main └── java │ └── org │ └── sourcelab │ └── kafka │ └── connect │ └── apiclient │ ├── Configuration.java │ ├── KafkaConnectClient.java │ ├── exception │ └── ResponseParseException.java │ ├── request │ ├── JacksonFactory.java │ ├── Request.java │ ├── RequestErrorResponse.java │ ├── RequestMethod.java │ ├── delete │ │ ├── DeleteConnector.java │ │ └── DeleteRequest.java │ ├── dto │ │ ├── ConnectServerVersion.java │ │ ├── ConnectorDefinition.java │ │ ├── ConnectorPlugin.java │ │ ├── ConnectorPluginConfigDefinition.java │ │ ├── ConnectorPluginConfigValidationResults.java │ │ ├── ConnectorStatus.java │ │ ├── ConnectorTopics.java │ │ ├── ConnectorsWithExpandedInfo.java │ │ ├── ConnectorsWithExpandedMetadata.java │ │ ├── ConnectorsWithExpandedStatus.java │ │ ├── NewConnectorDefinition.java │ │ ├── Task.java │ │ └── TaskStatus.java │ ├── get │ │ ├── GetConnectServerVersion.java │ │ ├── GetConnector.java │ │ ├── GetConnectorConfig.java │ │ ├── GetConnectorPlugins.java │ │ ├── GetConnectorStatus.java │ │ ├── GetConnectorTaskStatus.java │ │ ├── GetConnectorTasks.java │ │ ├── GetConnectorTopics.java │ │ ├── GetConnectors.java │ │ ├── GetConnectorsExpandAllDetails.java │ │ ├── GetConnectorsExpandInfo.java │ │ ├── GetConnectorsExpandStatus.java │ │ └── GetRequest.java │ ├── post │ │ ├── PostConnector.java │ │ ├── PostConnectorRestart.java │ │ ├── PostConnectorTaskRestart.java │ │ └── PostRequest.java │ └── put │ │ ├── PutConnectorConfig.java │ │ ├── PutConnectorPause.java │ │ ├── PutConnectorPluginConfigValidate.java │ │ ├── PutConnectorResume.java │ │ ├── PutConnectorStop.java │ │ ├── PutConnectorTopicsReset.java │ │ └── PutRequest.java │ ├── rest │ ├── DefaultHttpClientConfigHooks.java │ ├── HttpClientConfigHooks.java │ ├── HttpClientRestClient.java │ ├── HttpsContextBuilder.java │ ├── MockRestClient.java │ ├── NoopTrustManager.java │ ├── RestClient.java │ ├── RestException.java │ ├── RestResponse.java │ ├── exceptions │ │ ├── ConcurrentConfigModificationException.java │ │ ├── ConnectionException.java │ │ ├── InvalidRequestException.java │ │ ├── ResourceNotFoundException.java │ │ ├── ResultParsingException.java │ │ └── UnauthorizedRequestException.java │ └── handlers │ │ ├── RestResponseHandler.java │ │ └── StringResponseHandler.java │ └── util │ └── UrlEscapingUtil.java └── test ├── java ├── BadLoggersTest.java ├── categories │ └── IntegrationTest.java ├── org │ └── sourcelab │ │ └── kafka │ │ └── connect │ │ └── apiclient │ │ ├── KafkaConnectClientTest.java │ │ ├── KafkaConnectClientUnitTest.java │ │ ├── request │ │ ├── AbstractRequestTest.java │ │ ├── get │ │ │ └── connector │ │ │ │ ├── GetConnectServerVersionTest.java │ │ │ │ ├── GetConnectorConfigTest.java │ │ │ │ ├── GetConnectorPluginsTest.java │ │ │ │ ├── GetConnectorStatusTest.java │ │ │ │ ├── GetConnectorTasksTest.java │ │ │ │ ├── GetConnectorTest.java │ │ │ │ ├── GetConnectorTopicsTest.java │ │ │ │ ├── GetConnectorsExpandAllDetailsTest.java │ │ │ │ ├── GetConnectorsTest.java │ │ │ │ ├── GetConnectorsWithExpandInfoTest.java │ │ │ │ └── GetConnectorsWithExpandStatusTest.java │ │ ├── post │ │ │ └── PostConnectorRestartTest.java │ │ └── put │ │ │ └── connector │ │ │ └── PutConnectorConfigTest.java │ │ ├── rest │ │ ├── DefaultHttpClientConfigHooksTest.java │ │ ├── HttpClientRestClientTest.java │ │ └── HttpsContextBuilderTest.java │ │ └── util │ │ └── UrlEscapingUtilTest.java └── testserver │ ├── RequestProperties.java │ └── TestHttpServer.java └── resources ├── certificates ├── DUMMY_CERTIFICATES_FOR_TESTS.txt ├── server.keystore.jks └── server.truststore.jks ├── log4j2.xml └── mockResponses ├── errorResourceNotFound.json ├── getConnectServerVersion.json ├── getConnector.json ├── getConnectorConfig.json ├── getConnectorPlugins.json ├── getConnectorStatus.json ├── getConnectorTaskStatus.json ├── getConnectorTasks.json ├── getConnectorTopics.json ├── getConnectorTopics_empty.json ├── getConnectors.json ├── getConnectorsWithAllExpandedMetadata.json ├── getConnectorsWithExpandedInfo.json ├── getConnectorsWithExpandedStatus.json ├── putConnector.json └── putConnectorPluginConfigValidate.json /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI Test Suite 2 | 3 | # Triggers the workflow on pull requests, manually, or pushes to master 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 12 | jobs: 13 | # This workflow contains a single job called "build" 14 | build: 15 | # The type of runner that the job will run on 16 | runs-on: ubuntu-latest 17 | 18 | # Steps represent a sequence of tasks that will be executed as part of the job 19 | steps: 20 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 21 | - uses: actions/checkout@v2 22 | 23 | ## Run tests against Open JDK8 24 | - uses: actions/setup-java@v2 25 | with: 26 | distribution: adopt 27 | java-version: 8 28 | 29 | ## Cache maven dependencies 30 | - name: Cache local Maven repository 31 | uses: actions/cache@v2 32 | with: 33 | path: ~/.m2/repository 34 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 35 | restore-keys: | 36 | ${{ runner.os }}-maven- 37 | ## Run CheckStyle and License Header checks, compile, and install locally 38 | - name: Run checkstyle, license check, compile and install locally 39 | run: mvn clean install -DskipTests=true -DskipCheckStyle=false -Dmaven.javadoc.skip=true -B -V 40 | 41 | ## Run test suite 42 | - name: Run test suite 43 | run: mvn test -B -DskipCheckStyle=true 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ 3 | *.iml 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018-2022 SourceLab.org https://github.com/SourceLabOrg/kafka-connect-client 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 6 | persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /build/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2018, 2019, 2020, 2021 SourceLab.org https://github.com/SourceLabOrg/kafka-connect-client 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 6 | persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/exception/ResponseParseException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/JacksonFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request; 19 | 20 | import com.fasterxml.jackson.databind.DeserializationFeature; 21 | import com.fasterxml.jackson.databind.ObjectMapper; 22 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; 23 | import com.fasterxml.jackson.databind.type.MapType; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Creates properly configured Jackson XML Mapper instances. 29 | */ 30 | public final class JacksonFactory { 31 | 32 | /** 33 | * Holds our jackson singleton mapper. ObjectMapper is defined as being 34 | * ThreadSafe so this should be OK to stash as a static and shared. 35 | */ 36 | private static final ObjectMapper mapper = new ObjectMapper(); 37 | 38 | /** 39 | * Defines a "type safe" Map[String, String] deserialization type for Jackson. 40 | */ 41 | public static final MapType mapTypeStringString = mapper.getTypeFactory() 42 | .constructMapType(Map.class, String.class, String.class); 43 | 44 | /* 45 | * Statically configure the instance. 46 | */ 47 | static { 48 | // Configure mapper 49 | mapper 50 | .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) 51 | .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); 52 | } 53 | 54 | /** 55 | * Creates properly configured Jackson Object Mapper instances. 56 | * @return ObjectMapper instance. 57 | */ 58 | public static ObjectMapper newInstance() { 59 | return mapper; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/Request.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * Interface for all Requests to implement. 24 | * @param return type of request. 25 | */ 26 | public interface Request { 27 | 28 | /** 29 | * The name of the API end point to issue a request against. This is appended to the API Hostname. 30 | * @return The name of the end point this request uses. 31 | */ 32 | String getApiEndpoint(); 33 | 34 | /** 35 | * Request Method, IE POST, GET, etc.. 36 | * @return The type of HTTP Request. 37 | */ 38 | RequestMethod getRequestMethod(); 39 | 40 | /** 41 | * Object to be submitted as the body of the request. It will be serialized to JSON using Jackson. 42 | * @return Object representing request body content. 43 | */ 44 | Object getRequestBody(); 45 | 46 | /** 47 | * Parse the rest service's response into a concrete object. 48 | * @param responseStr The servers response in string format. 49 | * @return A concrete object representing the result. 50 | * @throws IOException on parsing errors. 51 | */ 52 | T parseResponse(final String responseStr) throws IOException; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/RequestErrorResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request; 19 | 20 | /** 21 | * Represents an error response from the rest service. 22 | */ 23 | public final class RequestErrorResponse { 24 | private int errorCode = 0; 25 | private String message; 26 | 27 | public int getErrorCode() { 28 | return errorCode; 29 | } 30 | 31 | public String getMessage() { 32 | return message; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "RequestErrorResponse{" 38 | + "errorCode=" + errorCode 39 | + ", message='" + message + '\'' 40 | + '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/RequestMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request; 19 | 20 | /** 21 | * Represents the possible request types. 22 | */ 23 | public enum RequestMethod { 24 | DELETE, 25 | GET, 26 | POST, 27 | PUT 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/delete/DeleteConnector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.delete; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 21 | 22 | import java.io.IOException; 23 | import java.util.Objects; 24 | 25 | /** 26 | * Defines a request to delete a connector. 27 | */ 28 | public final class DeleteConnector implements DeleteRequest { 29 | private final String connectorName; 30 | 31 | /** 32 | * Constructor. 33 | * @param connectorName Name of the connector. 34 | */ 35 | public DeleteConnector(final String connectorName) { 36 | Objects.requireNonNull(connectorName); 37 | this.connectorName = connectorName; 38 | } 39 | 40 | @Override 41 | public String getApiEndpoint() { 42 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName); 43 | } 44 | 45 | @Override 46 | public Object getRequestBody() { 47 | return ""; 48 | } 49 | 50 | @Override 51 | public Boolean parseResponse(final String responseStr) throws IOException { 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/delete/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.delete; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.Request; 21 | import org.sourcelab.kafka.connect.apiclient.request.RequestMethod; 22 | 23 | /** 24 | * Defines interface for DELETE requests. 25 | * @param Defines the return type of the request. 26 | */ 27 | public interface DeleteRequest extends Request { 28 | @Override 29 | default RequestMethod getRequestMethod() { 30 | return RequestMethod.DELETE; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectServerVersion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | /** 21 | * Represents details about the kafka-connect server. 22 | */ 23 | public class ConnectServerVersion { 24 | private String version; 25 | private String commit; 26 | private String kafkaClusterId; 27 | 28 | /** 29 | * Default Constructor. 30 | */ 31 | public ConnectServerVersion() 32 | { 33 | } 34 | 35 | /** 36 | * Constructor. 37 | */ 38 | public ConnectServerVersion(final String version, final String commit, final String kafkaClusterId) { 39 | this.version = version; 40 | this.commit = commit; 41 | this.kafkaClusterId = kafkaClusterId; 42 | } 43 | 44 | /** 45 | * Version of running Kafka-Connect server. 46 | * @return Version of running Kafka-Connect server. 47 | */ 48 | public String getVersion() { 49 | return version; 50 | } 51 | 52 | /** 53 | * Commit hash of running Kafka-Connect server. 54 | * @return Commit hash of running Kafka-Connect server. 55 | */ 56 | public String getCommit() { 57 | return commit; 58 | } 59 | 60 | /** 61 | * Kafka Cluster Identifier. 62 | * @return Kafka Cluster Identifier. 63 | */ 64 | public String getKafkaClusterId() { 65 | return kafkaClusterId; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "ConnectServerVersion{" 71 | + "version='" + version + '\'' 72 | + ", commit='" + commit + '\'' 73 | + ", kafkaClusterId='" + kafkaClusterId + '\'' 74 | + '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorDefinition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.ArrayList; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * Represents a Connector. 27 | */ 28 | public final class ConnectorDefinition { 29 | private String name; 30 | private String type; 31 | private Map config; 32 | private List tasks; 33 | 34 | /** 35 | * Default constructor. 36 | */ 37 | public ConnectorDefinition() 38 | { 39 | } 40 | 41 | /** 42 | * Constructor. 43 | */ 44 | public ConnectorDefinition(final String name, final String type, final Map config, final List tasks) { 45 | this.name = name; 46 | this.type = type; 47 | this.config = new HashMap<>(config); 48 | this.tasks = new ArrayList<>(tasks); 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | public String getType() { 56 | return type; 57 | } 58 | 59 | public Map getConfig() { 60 | return config; 61 | } 62 | 63 | public List getTasks() { 64 | return tasks; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "ConnectorDefinition{" 70 | + "name='" + name + '\'' 71 | + ", type='" + type + '\'' 72 | + ", config=" + config 73 | + ", tasks=" + tasks 74 | + '}'; 75 | } 76 | 77 | /** 78 | * Represents a Task. 79 | */ 80 | public static final class TaskDefinition { 81 | private String connector; 82 | private int task; 83 | 84 | /** 85 | * Default Constructor. 86 | */ 87 | public TaskDefinition() { 88 | } 89 | 90 | /** 91 | * Constructor. 92 | */ 93 | public TaskDefinition(final String connector, final int task) { 94 | this.connector = connector; 95 | this.task = task; 96 | } 97 | 98 | public String getConnector() { 99 | return connector; 100 | } 101 | 102 | public int getTask() { 103 | return task; 104 | } 105 | 106 | @Override 107 | public String toString() { 108 | return "TaskDefinition{" 109 | + "connector='" + connector + '\'' 110 | + ", task=" + task 111 | + '}'; 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import com.fasterxml.jackson.annotation.JsonAlias; 21 | 22 | /** 23 | * Represents details about a Connector Plugin. 24 | */ 25 | public final class ConnectorPlugin { 26 | @JsonAlias("class") 27 | private String className; 28 | private String type; 29 | private String version; 30 | 31 | /** 32 | * Default constructor. 33 | */ 34 | public ConnectorPlugin() { 35 | } 36 | 37 | /** 38 | * Constructor. 39 | */ 40 | public ConnectorPlugin(final String className, final String type, final String version) { 41 | this.className = className; 42 | this.type = type; 43 | this.version = version; 44 | } 45 | 46 | public String getClassName() { 47 | return className; 48 | } 49 | 50 | public String getType() { 51 | return type; 52 | } 53 | 54 | public String getVersion() { 55 | return version; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "ConnectorPlugin{" 61 | + "className='" + className + '\'' 62 | + ", type='" + type + '\'' 63 | + ", version='" + version + '\'' 64 | + '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorPluginConfigDefinition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.Collections; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * Defines a Connector Plugin Configuration. 26 | */ 27 | public final class ConnectorPluginConfigDefinition { 28 | private final String name; 29 | private final Map config; 30 | 31 | /** 32 | * Create new Builder instance for ConnectorPluginConfigDefinition. 33 | * @return Builder instance for ConnectorPluginConfigDefinition. 34 | */ 35 | public static ConnectorPluginConfigDefinition.Builder newBuilder() { 36 | return new ConnectorPluginConfigDefinition.Builder(); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * @param connectorPluginName Name of Connector Plugin. 42 | * @param config Configuration values for connector. 43 | */ 44 | public ConnectorPluginConfigDefinition(final String connectorPluginName, final Map config) { 45 | this.name = connectorPluginName; 46 | this.config = Collections.unmodifiableMap(new HashMap<>(config)); 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public Map getConfig() { 54 | return config; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "ConnectorPluginConfigDefinition{" 60 | + "name='" + name + '\'' 61 | + ", config=" + config 62 | + '}'; 63 | } 64 | 65 | /** 66 | * Builder for ConnectorPluginConfigDefinition. 67 | */ 68 | public static final class Builder { 69 | private String name; 70 | private Map config = new HashMap<>(); 71 | 72 | private Builder() { 73 | } 74 | 75 | public ConnectorPluginConfigDefinition.Builder withName(final String name) { 76 | this.name = name; 77 | return this; 78 | } 79 | 80 | public ConnectorPluginConfigDefinition.Builder withConfig(final Map config) { 81 | this.config = new HashMap<>(config); 82 | return this; 83 | } 84 | 85 | public ConnectorPluginConfigDefinition.Builder withConfig(final String key, final String value) { 86 | this.config.put(key, value); 87 | return this; 88 | } 89 | 90 | public ConnectorPluginConfigDefinition.Builder withConfig(final String key, final Object value) { 91 | this.config.put(key, value.toString()); 92 | return this; 93 | } 94 | 95 | public ConnectorPluginConfigDefinition build() { 96 | return new ConnectorPluginConfigDefinition(name, config); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Collections; 22 | import java.util.HashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * Represents the status of a deployed connector. 28 | */ 29 | public class ConnectorStatus { 30 | private String name; 31 | private String type; 32 | private Map connector; 33 | private List tasks; 34 | 35 | /** 36 | * Default constructor. 37 | */ 38 | public ConnectorStatus() { 39 | } 40 | 41 | /** 42 | * Constructor. 43 | */ 44 | public ConnectorStatus(final String name, final String type, final Map connector, final List tasks) { 45 | this.name = name; 46 | this.type = type; 47 | this.connector = new HashMap<>(connector); 48 | this.tasks = new ArrayList<>(tasks); 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | public Map getConnector() { 56 | return Collections.unmodifiableMap(connector); 57 | } 58 | 59 | public List getTasks() { 60 | return Collections.unmodifiableList(tasks); 61 | } 62 | 63 | public String getType() { 64 | return type; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "ConnectorStatus{" 70 | + "name='" + name + '\'' 71 | + ", connector=" + connector 72 | + ", tasks=" + tasks 73 | + ", type=" + type 74 | + '}'; 75 | } 76 | 77 | /** 78 | * Defines the status of a Task. 79 | */ 80 | public static class TaskStatus { 81 | private int id; 82 | private String state; 83 | private String workerId; 84 | private String trace; 85 | 86 | /** 87 | * Default constructor. 88 | */ 89 | public TaskStatus() { 90 | } 91 | 92 | /** 93 | * Constructor. 94 | */ 95 | public TaskStatus(final int id, final String state, final String workerId, final String trace) { 96 | this.id = id; 97 | this.state = state; 98 | this.workerId = workerId; 99 | this.trace = trace; 100 | } 101 | 102 | public int getId() { 103 | return id; 104 | } 105 | 106 | public String getState() { 107 | return state; 108 | } 109 | 110 | public String getWorkerId() { 111 | return workerId; 112 | } 113 | 114 | public String getTrace() { 115 | return trace; 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return "TaskStatus{" 121 | + "id=" + id 122 | + ", state='" + state + '\'' 123 | + ", workerId='" + workerId + '\'' 124 | + ", trace='" + trace + '\'' 125 | + '}'; 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorTopics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import com.fasterxml.jackson.core.JsonParseException; 21 | import com.fasterxml.jackson.core.JsonParser; 22 | import com.fasterxml.jackson.core.JsonProcessingException; 23 | import com.fasterxml.jackson.databind.DeserializationContext; 24 | import com.fasterxml.jackson.databind.JsonNode; 25 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 26 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 27 | import com.fasterxml.jackson.databind.node.JsonNodeType; 28 | 29 | import java.io.IOException; 30 | import java.util.ArrayList; 31 | import java.util.Collections; 32 | import java.util.Iterator; 33 | import java.util.List; 34 | import java.util.Map; 35 | import java.util.Objects; 36 | import java.util.stream.Collectors; 37 | 38 | /** 39 | * Represents result from /connectors/[topic-name]/topics REST end point. 40 | */ 41 | @JsonDeserialize(using = ConnectorTopics.Deserializer.class) 42 | public class ConnectorTopics { 43 | private final String name; 44 | private final List topics; 45 | 46 | /** 47 | * Constructor. 48 | * @param name Name of the connector. 49 | * @param topics List of topics. 50 | */ 51 | public ConnectorTopics(final String name, final List topics) { 52 | this.name = Objects.requireNonNull(name); 53 | Objects.requireNonNull(topics); 54 | this.topics = Collections.unmodifiableList(topics.stream().sorted().collect(Collectors.toList())); 55 | } 56 | 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | public List getTopics() { 62 | return topics; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "ConnectorTopics{" 68 | + "name='" + name + '\'' 69 | + ", topics=" + topics 70 | + '}'; 71 | } 72 | 73 | /** 74 | * Deserializer for ConnectorTopics. 75 | */ 76 | public static class Deserializer extends StdDeserializer { 77 | 78 | /** 79 | * Constructor. 80 | */ 81 | public Deserializer() { 82 | this(null); 83 | } 84 | 85 | /** 86 | * Constructor. 87 | */ 88 | public Deserializer(final Class vc) { 89 | super(vc); 90 | } 91 | 92 | @Override 93 | public ConnectorTopics deserialize(final JsonParser jsonParser, final DeserializationContext ctxt) throws IOException, JsonProcessingException { 94 | final JsonNode node = jsonParser.getCodec().readTree(jsonParser); 95 | final Iterator> children = node.fields(); 96 | 97 | while (children.hasNext()) { 98 | final Map.Entry child = children.next(); 99 | final String name = child.getKey(); 100 | final JsonNode childNode = child.getValue(); 101 | 102 | // Skip unknown entries 103 | if (JsonNodeType.OBJECT != childNode.getNodeType()) { 104 | continue; 105 | } 106 | 107 | // If has no topics key 108 | if (!childNode.has("topics") || JsonNodeType.ARRAY != childNode.get("topics").getNodeType()) { 109 | // Skip? 110 | continue; 111 | } 112 | final List topicNames = new ArrayList<>(); 113 | if (!childNode.get("topics").isEmpty()) { 114 | // Parse topic name values out 115 | childNode.get("topics").forEach((entry) -> topicNames.add(entry.textValue())); 116 | } 117 | return new ConnectorTopics(name, topicNames); 118 | } 119 | throw new JsonParseException(jsonParser, "Unable to parse response JSON"); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorsWithExpandedInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.Collection; 21 | import java.util.Map; 22 | 23 | /** 24 | * Deployed Connectors extended with their associated ConnectorDefinitions. 25 | * 26 | * Requires Kafka-Connect server 2.3.0+ 27 | */ 28 | public interface ConnectorsWithExpandedInfo { 29 | 30 | /** 31 | * Names for all deployed connectors. 32 | * @return Names of all deployed connectors. 33 | */ 34 | Collection getConnectorNames(); 35 | 36 | /** 37 | * Given a connector name, return the definition for the connector. 38 | * @param connectorName name of connector to return definition for. 39 | * @return ConnectorDefinition for the given connector name. 40 | * @throws IllegalArgumentException if passed a connector name not included in the results. 41 | */ 42 | ConnectorDefinition getDefinitionForConnector(final String connectorName) throws IllegalArgumentException; 43 | 44 | /** 45 | * All ConnectorDefinitions. 46 | * @return all ConnectorDefinitions. 47 | */ 48 | Collection getAllDefinitions(); 49 | 50 | /** 51 | * Map of ConnectorName to its respective ConnectorDefinition. 52 | * @return Map of ConnectorName to its respective ConnectorDefinition. 53 | */ 54 | Map getMappedDefinitions(); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/ConnectorsWithExpandedStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.Collection; 21 | import java.util.Map; 22 | 23 | /** 24 | * Deployed Connectors extended with their associated ConnectorDefinitions. 25 | * 26 | * Requires Kafka-Connect server 2.3.0+ 27 | */ 28 | public interface ConnectorsWithExpandedStatus { 29 | 30 | /** 31 | * Names for all deployed connectors. 32 | * @return Names of all deployed connectors. 33 | */ 34 | Collection getConnectorNames(); 35 | 36 | /** 37 | * Given a connector name, return the status for the connector. 38 | * @param connectorName name of connector to return status for. 39 | * @return ConnectorStatus for the given connector name. 40 | * @throws IllegalArgumentException if passed a connector name not included in the results. 41 | */ 42 | ConnectorStatus getStatusForConnector(final String connectorName); 43 | 44 | /** 45 | * All connector statuses. 46 | * @return All connector statuses. 47 | */ 48 | Collection getAllStatuses(); 49 | 50 | /** 51 | * Map of ConnectorName to its respective Status. 52 | * @return Map of ConnectorName to its respective Status. 53 | */ 54 | Map getMappedStatuses(); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/NewConnectorDefinition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.Collections; 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * Defines a new Connector and its configuration to be deployed. 26 | */ 27 | public final class NewConnectorDefinition { 28 | private final String name; 29 | private final Map config; 30 | 31 | /** 32 | * Create new Builder instance for NewConnectorDefinition. 33 | * @return new Builder instance for NewConnectorDefinition. 34 | */ 35 | public static Builder newBuilder() { 36 | return new Builder(); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * @param name Name of Connector. 42 | * @param config Configuration values for connector. 43 | */ 44 | public NewConnectorDefinition(final String name, final Map config) { 45 | this.name = name; 46 | this.config = Collections.unmodifiableMap(new HashMap<>(config)); 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public Map getConfig() { 54 | return config; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "NewConnectorDefinition{" 60 | + "name='" + name + '\'' 61 | + ", config=" + config 62 | + '}'; 63 | } 64 | 65 | /** 66 | * Builder for NewConnectorDefinition. 67 | */ 68 | public static final class Builder { 69 | private String name; 70 | private Map config = new HashMap<>(); 71 | 72 | private Builder() { 73 | } 74 | 75 | public Builder withName(final String name) { 76 | this.name = name; 77 | return this; 78 | } 79 | 80 | public Builder withConfig(final Map config) { 81 | this.config = new HashMap<>(config); 82 | return this; 83 | } 84 | 85 | public Builder withConfig(final String key, final String value) { 86 | this.config.put(key, value); 87 | return this; 88 | } 89 | 90 | public Builder withConfig(final String key, final Object value) { 91 | this.config.put(key, value.toString()); 92 | return this; 93 | } 94 | 95 | public NewConnectorDefinition build() { 96 | return new NewConnectorDefinition(name, config); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/Task.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * Represents Details about a Task. 25 | */ 26 | public final class Task { 27 | private TaskId id; 28 | private Map config; 29 | 30 | /** 31 | * Default constructor. 32 | */ 33 | public Task() { 34 | } 35 | 36 | /** 37 | * Constructor. 38 | */ 39 | public Task(final TaskId id, final Map config) 40 | { 41 | this.id = id; 42 | this.config = new HashMap<>(config); 43 | } 44 | 45 | public TaskId getId() { 46 | return id; 47 | } 48 | 49 | public Map getConfig() { 50 | return config; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Task{" 56 | + "id=" + id 57 | + ", config=" + config 58 | + '}'; 59 | } 60 | 61 | /** 62 | * Defines a Task Id. 63 | */ 64 | public static class TaskId { 65 | private String connector; 66 | private int task; 67 | 68 | /** 69 | * Default constructor. 70 | */ 71 | public TaskId() 72 | { 73 | } 74 | 75 | /** 76 | * Constructor. 77 | */ 78 | public TaskId(final String connector, final int task) { 79 | this.connector = connector; 80 | this.task = task; 81 | } 82 | 83 | public String getConnector() { 84 | return connector; 85 | } 86 | 87 | public int getTask() { 88 | return task; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "TaskId{" 94 | + "connector='" + connector + '\'' 95 | + ", task=" + task 96 | + '}'; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/dto/TaskStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.dto; 19 | 20 | /** 21 | * Represents the Status of a Task. 22 | */ 23 | public final class TaskStatus { 24 | private int id = -1; 25 | private String state; 26 | private String trace; 27 | private String workerId; 28 | 29 | /** 30 | * Default constructor. 31 | */ 32 | public TaskStatus() { 33 | } 34 | 35 | /** 36 | * Constructor. 37 | */ 38 | public TaskStatus(final int id, final String state, final String trace, final String workerId) { 39 | this.id = id; 40 | this.state = state; 41 | this.trace = trace; 42 | this.workerId = workerId; 43 | } 44 | 45 | public int getId() { 46 | return id; 47 | } 48 | 49 | public String getState() { 50 | return state; 51 | } 52 | 53 | public String getTrace() { 54 | return trace; 55 | } 56 | 57 | public String getWorkerId() { 58 | return workerId; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "TaskStatus{" 64 | + "id=" + id 65 | + ", state='" + state + '\'' 66 | + ", trace='" + trace + '\'' 67 | + ", workerId='" + workerId + '\'' 68 | + '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectServerVersion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectServerVersion; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * Defines a request for getting details about the Kafka-Connect service being queried. 27 | */ 28 | public class GetConnectServerVersion implements GetRequest { 29 | @Override 30 | public String getApiEndpoint() { 31 | return "/"; 32 | } 33 | 34 | @Override 35 | public ConnectServerVersion parseResponse(final String responseStr) throws IOException { 36 | return JacksonFactory.newInstance().readValue(responseStr, ConnectServerVersion.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Objects; 26 | 27 | /** 28 | * Defines request to get details about a deployed connector. 29 | */ 30 | public final class GetConnector implements GetRequest { 31 | 32 | private final String connectorName; 33 | 34 | /** 35 | * Constructor. 36 | * @param connectorName Name of the connector. 37 | */ 38 | public GetConnector(final String connectorName) { 39 | Objects.requireNonNull(connectorName); 40 | this.connectorName = connectorName; 41 | } 42 | 43 | @Override 44 | public String getApiEndpoint() { 45 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName); 46 | } 47 | 48 | @Override 49 | public ConnectorDefinition parseResponse(final String responseStr) throws IOException { 50 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorDefinition.class); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 22 | 23 | import java.io.IOException; 24 | import java.util.Map; 25 | import java.util.Objects; 26 | 27 | /** 28 | * Defines a request for getting the configuration for a connector. 29 | */ 30 | public final class GetConnectorConfig implements GetRequest> { 31 | 32 | private final String connectorName; 33 | 34 | /** 35 | * Constructor. 36 | * @param connectorName Name of the connector. 37 | */ 38 | public GetConnectorConfig(final String connectorName) { 39 | Objects.requireNonNull(connectorName); 40 | this.connectorName = connectorName; 41 | } 42 | 43 | @Override 44 | public String getApiEndpoint() { 45 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/config"; 46 | } 47 | 48 | @Override 49 | public Map parseResponse(final String responseStr) throws IOException { 50 | return JacksonFactory.newInstance().readValue(responseStr, JacksonFactory.mapTypeStringString); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorPlugins.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPlugin; 22 | 23 | import java.io.IOException; 24 | import java.util.Arrays; 25 | import java.util.Collection; 26 | 27 | /** 28 | * Defines request to get a list of connector plugins. 29 | */ 30 | public final class GetConnectorPlugins implements GetRequest> { 31 | 32 | @Override 33 | public String getApiEndpoint() { 34 | return "/connector-plugins"; 35 | } 36 | 37 | @Override 38 | public Collection parseResponse(final String responseStr) throws IOException { 39 | return Arrays.asList(JacksonFactory.newInstance().readValue(responseStr, ConnectorPlugin[].class)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorStatus; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Objects; 26 | 27 | /** 28 | * Defines request to get the status of a connector. 29 | */ 30 | public final class GetConnectorStatus implements GetRequest { 31 | 32 | private final String connectorName; 33 | 34 | /** 35 | * Constructor. 36 | * @param connectorName Name of connector. 37 | */ 38 | public GetConnectorStatus(final String connectorName) { 39 | Objects.requireNonNull(connectorName); 40 | this.connectorName = connectorName; 41 | } 42 | 43 | @Override 44 | public String getApiEndpoint() { 45 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/status"; 46 | } 47 | 48 | @Override 49 | public ConnectorStatus parseResponse(final String responseStr) throws IOException { 50 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorStatus.class); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorTaskStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.TaskStatus; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Objects; 26 | 27 | /** 28 | * Defines a request to get the status of a connector's task. 29 | */ 30 | public final class GetConnectorTaskStatus implements GetRequest { 31 | 32 | private final String connectorName; 33 | private final int taskId; 34 | 35 | /** 36 | * Constructor. 37 | * @param connectorName Name of the connector. 38 | * @param taskId Task id. 39 | */ 40 | public GetConnectorTaskStatus(final String connectorName, final int taskId) { 41 | Objects.requireNonNull(connectorName); 42 | this.connectorName = connectorName; 43 | this.taskId = taskId; 44 | } 45 | 46 | @Override 47 | public String getApiEndpoint() { 48 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/tasks/" + taskId + "/status"; 49 | } 50 | 51 | @Override 52 | public TaskStatus parseResponse(final String responseStr) throws IOException { 53 | return JacksonFactory.newInstance().readValue(responseStr, TaskStatus.class); 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorTasks.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.Task; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Arrays; 26 | import java.util.Collection; 27 | import java.util.Objects; 28 | 29 | /** 30 | * Defines request to get tasks for a connector. 31 | */ 32 | public final class GetConnectorTasks implements GetRequest> { 33 | 34 | private final String connectorName; 35 | 36 | /** 37 | * Constructor. 38 | * @param connectorName name of the connector. 39 | */ 40 | public GetConnectorTasks(final String connectorName) { 41 | Objects.requireNonNull(connectorName); 42 | this.connectorName = connectorName; 43 | } 44 | 45 | @Override 46 | public String getApiEndpoint() { 47 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/tasks"; 48 | } 49 | 50 | @Override 51 | public Collection parseResponse(final String responseStr) throws IOException { 52 | return Arrays.asList(JacksonFactory.newInstance().readValue(responseStr, Task[].class)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorTopics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorTopics; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Objects; 26 | 27 | /** 28 | * Returns a list of connector topic names. 29 | * There is no defined order in which the topics are returned and consecutive calls may return the same topic names 30 | * but in different order. This request is independent of whether a connector is running, and will return an empty set 31 | * of topics, both for connectors that don’t have active topics as well as non-existent connectors. 32 | * 33 | * https://docs.confluent.io/current/connect/references/restapi.html#get--connectors-(string-name)-topics 34 | */ 35 | public class GetConnectorTopics implements GetRequest { 36 | private final String connectorName; 37 | 38 | /** 39 | * Constructor. 40 | * @param connectorName Name of connector. 41 | */ 42 | public GetConnectorTopics(final String connectorName) { 43 | Objects.requireNonNull(connectorName); 44 | this.connectorName = connectorName; 45 | } 46 | 47 | @Override 48 | public String getApiEndpoint() { 49 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/topics"; 50 | } 51 | 52 | @Override 53 | public ConnectorTopics parseResponse(final String responseStr) throws IOException { 54 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorTopics.class); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectors.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | 22 | import java.io.IOException; 23 | import java.util.Arrays; 24 | import java.util.Collection; 25 | 26 | /** 27 | * Defines request to get list of deployed connectors. 28 | */ 29 | public final class GetConnectors implements GetRequest> { 30 | @Override 31 | public String getApiEndpoint() { 32 | return "/connectors"; 33 | } 34 | 35 | @Override 36 | public Collection parseResponse(final String responseStr) throws IOException { 37 | return Arrays.asList(JacksonFactory.newInstance().readValue(responseStr, String[].class)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorsExpandAllDetails.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import com.fasterxml.jackson.databind.exc.MismatchedInputException; 21 | import org.sourcelab.kafka.connect.apiclient.exception.ResponseParseException; 22 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 23 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorsWithExpandedMetadata; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * Defines a request to retrieve all deployed Connectors extended with all available associated metadata. 29 | * 30 | * Currently this includes both 'info' and 'status' metadata. 31 | * 32 | * Requires Kafka-Connect server 2.3.0+ 33 | */ 34 | public class GetConnectorsExpandAllDetails implements GetRequest { 35 | 36 | @Override 37 | public String getApiEndpoint() { 38 | return "/connectors?expand=info&expand=status"; 39 | } 40 | 41 | @Override 42 | public ConnectorsWithExpandedMetadata parseResponse(final String responseStr) throws IOException { 43 | try { 44 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorsWithExpandedMetadata.class); 45 | } catch (final MismatchedInputException exception) { 46 | throw new ResponseParseException( 47 | "Failed to parse response. The end point you requested requires Kafka-Connect 2.3.0+..." 48 | + "are you sure you're querying against the right version?", 49 | exception 50 | ); 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorsExpandInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import com.fasterxml.jackson.databind.exc.MismatchedInputException; 21 | import org.sourcelab.kafka.connect.apiclient.exception.ResponseParseException; 22 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 23 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorsWithExpandedInfo; 24 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorsWithExpandedMetadata; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * Defines a request to retrieve all deployed Connectors extended with 'info' metadata. 30 | * 31 | * Requires Kafka-Connect server 2.3.0+ 32 | */ 33 | public class GetConnectorsExpandInfo implements GetRequest { 34 | 35 | @Override 36 | public String getApiEndpoint() { 37 | return "/connectors?expand=info"; 38 | } 39 | 40 | @Override 41 | public ConnectorsWithExpandedInfo parseResponse(final String responseStr) throws IOException { 42 | try { 43 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorsWithExpandedMetadata.class); 44 | } catch (final MismatchedInputException exception) { 45 | throw new ResponseParseException( 46 | "Failed to parse response. The end point you requested requires Kafka-Connect 2.3.0+..." 47 | + "are you sure you're querying against the right version?", 48 | exception 49 | ); 50 | } 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetConnectorsExpandStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import com.fasterxml.jackson.databind.exc.MismatchedInputException; 21 | import org.sourcelab.kafka.connect.apiclient.exception.ResponseParseException; 22 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 23 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorsWithExpandedMetadata; 24 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorsWithExpandedStatus; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * Defines a request to retrieve all deployed Connectors extended 'status' metadata. 30 | * 31 | * Requires Kafka-Connect server 2.3.0+ 32 | */ 33 | public class GetConnectorsExpandStatus implements GetRequest { 34 | 35 | @Override 36 | public String getApiEndpoint() { 37 | return "/connectors?expand=status"; 38 | } 39 | 40 | @Override 41 | public ConnectorsWithExpandedStatus parseResponse(final String responseStr) throws IOException { 42 | try { 43 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorsWithExpandedMetadata.class); 44 | } catch (final MismatchedInputException exception) { 45 | throw new ResponseParseException( 46 | "Failed to parse response. The end point you requested requires Kafka-Connect 2.3.0+..." 47 | + "are you sure you're querying against the right version?", 48 | exception 49 | ); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/get/GetRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.Request; 21 | import org.sourcelab.kafka.connect.apiclient.request.RequestMethod; 22 | 23 | /** 24 | * Defines interface for GET requests. 25 | * @param Defines the return type of the request. 26 | */ 27 | public interface GetRequest extends Request { 28 | 29 | /** 30 | * All GET requests use GET. 31 | * @return RequestMethod.GET 32 | */ 33 | @Override 34 | default RequestMethod getRequestMethod() { 35 | return RequestMethod.GET; 36 | } 37 | 38 | /** 39 | * Not used in GET requests. 40 | * @return null. 41 | */ 42 | @Override 43 | default Object getRequestBody() { 44 | return null; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/post/PostConnector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.post; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition; 22 | import org.sourcelab.kafka.connect.apiclient.request.dto.NewConnectorDefinition; 23 | 24 | import java.io.IOException; 25 | import java.util.Objects; 26 | 27 | /** 28 | * Defines request to deploy a new connector. 29 | */ 30 | public final class PostConnector implements PostRequest { 31 | private final NewConnectorDefinition connectorDefinition; 32 | 33 | /** 34 | * Constructor. 35 | * @param connectorDefinition Defines the new connector to be deployed. 36 | */ 37 | public PostConnector(final NewConnectorDefinition connectorDefinition) { 38 | Objects.requireNonNull(connectorDefinition); 39 | this.connectorDefinition = connectorDefinition; 40 | } 41 | 42 | @Override 43 | public String getApiEndpoint() { 44 | return "/connectors"; 45 | } 46 | 47 | @Override 48 | public Object getRequestBody() { 49 | return connectorDefinition; 50 | } 51 | 52 | @Override 53 | public ConnectorDefinition parseResponse(final String responseStr) throws IOException { 54 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorDefinition.class); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/post/PostConnectorRestart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.post; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 21 | 22 | import java.io.IOException; 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.Objects; 28 | 29 | /** 30 | * Defines a request to restart a connector. 31 | */ 32 | public final class PostConnectorRestart implements PostRequest { 33 | /** 34 | * Defines the name of the connector to restart. 35 | */ 36 | private final String connectorName; 37 | 38 | /** 39 | * Additional options to pass with the request. 40 | */ 41 | private Map options = new HashMap<>(); 42 | 43 | /** 44 | * Constructor. 45 | * @param connectorName Name of connector to restart 46 | */ 47 | public PostConnectorRestart(final String connectorName) { 48 | Objects.requireNonNull(connectorName); 49 | this.connectorName = connectorName; 50 | } 51 | 52 | /** 53 | * Only available from Kafka Connect version 3.0.0 and up. 54 | * @param includeTasks Specifies whether to restart the connector instance and task instances (includeTasks=true`) or 55 | * just the connector instance (includeTasks=false). 56 | * @return self reference for method chaining. 57 | */ 58 | public PostConnectorRestart withIncludeTasks(final boolean includeTasks) 59 | { 60 | options.put("includeTasks", includeTasks); 61 | return this; 62 | } 63 | 64 | /** 65 | * Only available from Kafka Connect version 3.0.0 and up. 66 | * @param onlyFailed specifies whether to restart just the instances with a FAILED status (onlyFailed=true) 67 | * or all instances (onlyFailed=false). 68 | * @return self reference for method chaining. 69 | */ 70 | public PostConnectorRestart withOnlyFailed(final boolean onlyFailed) 71 | { 72 | options.put("onlyFailed", onlyFailed); 73 | return this; 74 | } 75 | 76 | @Override 77 | public String getApiEndpoint() { 78 | // Define base URL 79 | String url = "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/restart"; 80 | 81 | // Optionally add additional request parameters if explicitly defined. 82 | final List params = new ArrayList<>(); 83 | for (final Map.Entry option : options.entrySet()) { 84 | // skip null 85 | if (option.getValue() == null) { 86 | continue; 87 | } 88 | params.add(option.getKey() + "=" + (option.getValue() ? "true" : "false")); 89 | } 90 | if (params.size() > 0) { 91 | url = url + "?" + String.join("&", params); 92 | } 93 | return url; 94 | } 95 | 96 | @Override 97 | public Object getRequestBody() { 98 | return ""; 99 | } 100 | 101 | @Override 102 | public Boolean parseResponse(final String responseStr) throws IOException { 103 | // Note: this doesn't currently support 202 responses which would normally contain a response body :/ 104 | return true; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/post/PostConnectorTaskRestart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.post; 19 | 20 | 21 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 22 | 23 | import java.io.IOException; 24 | import java.util.Objects; 25 | 26 | /** 27 | * Defines request to restart a connector's task. 28 | */ 29 | public final class PostConnectorTaskRestart implements PostRequest { 30 | private final String connectorName; 31 | private final int taskId; 32 | 33 | /** 34 | * Constructor. 35 | * @param connectorName Name of connector. 36 | * @param taskId Id of the task. 37 | */ 38 | public PostConnectorTaskRestart(final String connectorName, final int taskId) { 39 | Objects.requireNonNull(connectorName); 40 | this.connectorName = connectorName; 41 | this.taskId = taskId; 42 | } 43 | 44 | @Override 45 | public String getApiEndpoint() { 46 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/tasks/" + taskId + "/restart"; 47 | } 48 | 49 | @Override 50 | public Object getRequestBody() { 51 | return ""; 52 | } 53 | 54 | @Override 55 | public Boolean parseResponse(final String responseStr) throws IOException { 56 | return true; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/post/PostRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.post; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.Request; 21 | import org.sourcelab.kafka.connect.apiclient.request.RequestMethod; 22 | 23 | /** 24 | * Defines interface for POST requests. 25 | * @param Defines the return type of the request. 26 | */ 27 | public interface PostRequest extends Request { 28 | @Override 29 | default RequestMethod getRequestMethod() { 30 | return RequestMethod.POST; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutConnectorConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Collections; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | import java.util.Objects; 29 | 30 | /** 31 | * Defines request to update a connectors configuration. 32 | */ 33 | public final class PutConnectorConfig implements PutRequest { 34 | private final String connectorName; 35 | private final Map config; 36 | 37 | /** 38 | * Constructor. 39 | * @param connectorName Name of connector 40 | * @param config Map of configuration items. 41 | */ 42 | public PutConnectorConfig(final String connectorName, final Map config) { 43 | Objects.requireNonNull(connectorName); 44 | Objects.requireNonNull(config); 45 | this.connectorName = connectorName; 46 | this.config = Collections.unmodifiableMap(new HashMap<>(config)); 47 | } 48 | 49 | @Override 50 | public String getApiEndpoint() { 51 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/config"; 52 | } 53 | 54 | @Override 55 | public Object getRequestBody() { 56 | return config; 57 | } 58 | 59 | @Override 60 | public ConnectorDefinition parseResponse(final String responseStr) throws IOException { 61 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorDefinition.class); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutConnectorPause.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 21 | 22 | import java.io.IOException; 23 | import java.util.Objects; 24 | 25 | /** 26 | * Defines request to pause a connector. 27 | */ 28 | public final class PutConnectorPause implements PutRequest { 29 | private final String connectorName; 30 | 31 | /** 32 | * Constructor. 33 | * @param connectorName Name of connector 34 | */ 35 | public PutConnectorPause(final String connectorName) { 36 | Objects.requireNonNull(connectorName); 37 | this.connectorName = connectorName; 38 | } 39 | 40 | @Override 41 | public String getApiEndpoint() { 42 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/pause"; 43 | } 44 | 45 | @Override 46 | public Object getRequestBody() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public Boolean parseResponse(final String responseStr) throws IOException { 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutConnectorPluginConfigValidate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.JacksonFactory; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPluginConfigValidationResults; 22 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 23 | 24 | import java.io.IOException; 25 | import java.util.Collections; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | import java.util.Objects; 29 | 30 | /** 31 | * Defines request to validate a connector plugin's configuration. 32 | */ 33 | public final class PutConnectorPluginConfigValidate implements PutRequest { 34 | private final String connectorPluginName; 35 | private final Map config; 36 | 37 | /** 38 | * Constructor. 39 | * @param connectorPluginName Name of the class for the connector plugin. 40 | * @param config Configuration entries to validate. 41 | */ 42 | public PutConnectorPluginConfigValidate(final String connectorPluginName, final Map config) { 43 | Objects.requireNonNull(connectorPluginName); 44 | Objects.requireNonNull(config); 45 | this.connectorPluginName = connectorPluginName; 46 | this.config = Collections.unmodifiableMap(new HashMap<>(config)); 47 | } 48 | 49 | @Override 50 | public String getApiEndpoint() { 51 | return "/connector-plugins/" + UrlEscapingUtil.escapePath(connectorPluginName) + "/config/validate"; 52 | } 53 | 54 | @Override 55 | public Object getRequestBody() { 56 | return config; 57 | } 58 | 59 | @Override 60 | public ConnectorPluginConfigValidationResults parseResponse(final String responseStr) throws IOException { 61 | return JacksonFactory.newInstance().readValue(responseStr, ConnectorPluginConfigValidationResults.class); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutConnectorResume.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 21 | 22 | import java.io.IOException; 23 | import java.util.Objects; 24 | 25 | /** 26 | * Defines request to resume a connector. 27 | */ 28 | public final class PutConnectorResume implements PutRequest { 29 | private final String connectorName; 30 | 31 | /** 32 | * Constructor. 33 | * @param connectorName Name of connector 34 | */ 35 | public PutConnectorResume(final String connectorName) { 36 | Objects.requireNonNull(connectorName); 37 | this.connectorName = connectorName; 38 | } 39 | 40 | @Override 41 | public String getApiEndpoint() { 42 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/resume"; 43 | } 44 | 45 | @Override 46 | public Object getRequestBody() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public Boolean parseResponse(final String responseStr) throws IOException { 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutConnectorStop.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 21 | 22 | import java.io.IOException; 23 | import java.util.Objects; 24 | 25 | /** 26 | * Defines request to stop a connector. 27 | */ 28 | public final class PutConnectorStop implements PutRequest { 29 | private final String connectorName; 30 | 31 | /** 32 | * Constructor. 33 | * @param connectorName Name of connector 34 | */ 35 | public PutConnectorStop(final String connectorName) { 36 | Objects.requireNonNull(connectorName); 37 | this.connectorName = connectorName; 38 | } 39 | 40 | @Override 41 | public String getApiEndpoint() { 42 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/stop"; 43 | } 44 | 45 | @Override 46 | public Object getRequestBody() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public Boolean parseResponse(final String responseStr) throws IOException { 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutConnectorTopicsReset.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.util.UrlEscapingUtil; 21 | 22 | import java.io.IOException; 23 | import java.util.Objects; 24 | 25 | /** 26 | * Send a request to empty the set of active topics of a connector. 27 | * https://docs.confluent.io/current/connect/references/restapi.html#put--connectors-(string-name)-topics-reset 28 | */ 29 | public class PutConnectorTopicsReset implements PutRequest { 30 | private final String connectorName; 31 | 32 | /** 33 | * Constructor. 34 | * @param connectorName Name of connector 35 | */ 36 | public PutConnectorTopicsReset(final String connectorName) { 37 | Objects.requireNonNull(connectorName); 38 | this.connectorName = connectorName; 39 | } 40 | 41 | @Override 42 | public String getApiEndpoint() { 43 | return "/connectors/" + UrlEscapingUtil.escapePath(connectorName) + "/topics/reset"; 44 | } 45 | 46 | @Override 47 | public Object getRequestBody() { 48 | return null; 49 | } 50 | 51 | @Override 52 | public Boolean parseResponse(final String responseStr) throws IOException { 53 | return true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/request/put/PutRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.Request; 21 | import org.sourcelab.kafka.connect.apiclient.request.RequestMethod; 22 | 23 | /** 24 | * Defines interface for PUT requests. 25 | * @param Defines the return type of the request. 26 | */ 27 | public interface PutRequest extends Request { 28 | @Override 29 | default RequestMethod getRequestMethod() { 30 | return RequestMethod.PUT; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/DefaultHttpClientConfigHooks.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | /** 21 | * Default implementation makes no modifications. 22 | */ 23 | public class DefaultHttpClientConfigHooks implements HttpClientConfigHooks { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/MockRestClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.Configuration; 21 | import org.sourcelab.kafka.connect.apiclient.request.Request; 22 | 23 | /** 24 | * A Mock Rest Client for testing. 25 | */ 26 | public class MockRestClient implements RestClient { 27 | 28 | public void init(final Configuration configuration) { 29 | // Noop. 30 | } 31 | 32 | public RestResponse submitRequest(final Request request) throws RestException { 33 | // Not implemented yet. 34 | return null; 35 | } 36 | 37 | public void close() { 38 | // Noop. 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/NoopTrustManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | import javax.net.ssl.X509TrustManager; 21 | import java.security.cert.X509Certificate; 22 | 23 | /** 24 | * Implementation of TrustManager that blindly trusts all certificates with no validation or verification. 25 | */ 26 | class NoopTrustManager implements X509TrustManager { 27 | @Override 28 | public void checkClientTrusted(final X509Certificate[] x509Certificates, final String input) { 29 | } 30 | 31 | @Override 32 | public void checkServerTrusted(final X509Certificate[] x509Certificates, final String input) { 33 | } 34 | 35 | @Override 36 | public X509Certificate[] getAcceptedIssuers() { 37 | return new X509Certificate[0]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/RestClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | 21 | import org.sourcelab.kafka.connect.apiclient.Configuration; 22 | import org.sourcelab.kafka.connect.apiclient.request.Request; 23 | 24 | /** 25 | * Interface for making HTTP calls. 26 | */ 27 | public interface RestClient { 28 | /** 29 | * Initializes the RestClient implementation. 30 | * Any setup or resource allocation should happen here. 31 | * @param configuration Pardot Api Configuration. 32 | */ 33 | void init(final Configuration configuration); 34 | 35 | /** 36 | * Make a request against the Pardot API. 37 | * @param request The request to submit. 38 | * @return The response, in UTF-8 String format. 39 | * @throws RestException When something goes wrong in an underlying implementation. 40 | */ 41 | RestResponse submitRequest(final Request request) throws RestException; 42 | 43 | /** 44 | * Called to release any internally held resources. 45 | */ 46 | void close(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/RestException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | /** 21 | * Exception when an underlying error occurs in a RestClient implementation. 22 | */ 23 | public class RestException extends RuntimeException { 24 | public RestException() { 25 | } 26 | 27 | public RestException(final String message) { 28 | super(message); 29 | } 30 | 31 | public RestException(final String message, final Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public RestException(final Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public RestException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/RestResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | /** 21 | * Represents the response from the API. 22 | */ 23 | public final class RestResponse { 24 | private final String responseStr; 25 | private final int httpCode; 26 | 27 | /** 28 | * Constructor. 29 | * @param responseStr The http response body, in string format. 30 | * @param httpCode The http status code from the response. 31 | */ 32 | public RestResponse(final String responseStr, final int httpCode) { 33 | this.responseStr = responseStr; 34 | this.httpCode = httpCode; 35 | } 36 | 37 | public String getResponseStr() { 38 | return responseStr; 39 | } 40 | 41 | public int getHttpCode() { 42 | return httpCode; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "RestResponse{" 48 | + "responseStr='" + responseStr + '\'' 49 | + ", httpCode=" + httpCode 50 | + '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/exceptions/ConcurrentConfigModificationException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.exceptions; 19 | 20 | /** 21 | * Represents when a request is rejected due to concurrent configuration modification. 22 | */ 23 | public class ConcurrentConfigModificationException extends InvalidRequestException { 24 | 25 | /** 26 | * Contructor. 27 | * @param message Error message. 28 | */ 29 | public ConcurrentConfigModificationException(String message) { 30 | super(message, 409); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/exceptions/ConnectionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.exceptions; 19 | 20 | /** 21 | * Thrown for underlying connection issues. 22 | */ 23 | public class ConnectionException extends InvalidRequestException { 24 | /** 25 | * Constructor. 26 | * 27 | * @param message Error message. 28 | * @param cause Originating exception. 29 | */ 30 | public ConnectionException(final String message, final Throwable cause) { 31 | super(message, cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/exceptions/InvalidRequestException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.exceptions; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.RequestErrorResponse; 21 | 22 | import java.util.Objects; 23 | 24 | /** 25 | * Represents when a request is invalid. 26 | */ 27 | public class InvalidRequestException extends RuntimeException { 28 | private final int errorCode; 29 | 30 | /** 31 | * Constructor. 32 | * @param message Error message. 33 | * @param errorCode Http Error Code. 34 | */ 35 | public InvalidRequestException(final String message, final int errorCode) { 36 | super(message); 37 | this.errorCode = errorCode; 38 | } 39 | 40 | /** 41 | * Constructor. 42 | * @param message Error message. 43 | * @param cause Originating exception. 44 | */ 45 | public InvalidRequestException(final String message, final Throwable cause) { 46 | super(message, cause); 47 | this.errorCode = -1; 48 | } 49 | 50 | /** 51 | * Resulting HTTP Status code. 52 | * @return Http Status Code. 53 | */ 54 | public int getErrorCode() { 55 | return errorCode; 56 | } 57 | 58 | /** 59 | * Factory method to create proper exception class based on the error. 60 | * @param errorResponse Parsed error response from server. 61 | * @return Appropriate Exception class. 62 | */ 63 | public static InvalidRequestException factory(final RequestErrorResponse errorResponse) { 64 | Objects.requireNonNull(errorResponse, "Invalid RequestErrorResponse parameter, must not be null"); 65 | 66 | switch (errorResponse.getErrorCode()) { 67 | case 401: 68 | return new UnauthorizedRequestException(errorResponse.getMessage(), errorResponse.getErrorCode()); 69 | case 404: 70 | return new ResourceNotFoundException(errorResponse.getMessage()); 71 | case 409: 72 | return new ConcurrentConfigModificationException(errorResponse.getMessage()); 73 | default: 74 | return new InvalidRequestException(errorResponse.getMessage(), errorResponse.getErrorCode()); 75 | 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/exceptions/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.exceptions; 19 | 20 | /** 21 | * Represents when a request is rejected due because the resource is unable to be located. 22 | */ 23 | public class ResourceNotFoundException extends InvalidRequestException { 24 | 25 | /** 26 | * Constructor. 27 | * @param message Error message. 28 | */ 29 | public ResourceNotFoundException(String message) { 30 | super(message, 404); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/exceptions/ResultParsingException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.exceptions; 19 | 20 | /** 21 | * Thrown when failure to parse result. 22 | */ 23 | public class ResultParsingException extends InvalidRequestException { 24 | /** 25 | * Constructor. 26 | * @param message Error message. 27 | * @param cause Originating cause. 28 | */ 29 | public ResultParsingException(final String message, final Throwable cause) { 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/exceptions/UnauthorizedRequestException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.exceptions; 19 | 20 | /** 21 | * Thrown if the server required Authentication, but the client was either not configured to provide credentials, 22 | * or those credentials were rejected/invalid. 23 | */ 24 | public class UnauthorizedRequestException extends InvalidRequestException { 25 | 26 | /** 27 | * Constructor. 28 | * @param message Error message. 29 | * @param errorCode Error code. 30 | */ 31 | public UnauthorizedRequestException(final String message, final int errorCode) { 32 | super(message, errorCode); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/handlers/RestResponseHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.handlers; 19 | 20 | import org.apache.http.HttpEntity; 21 | import org.apache.http.HttpResponse; 22 | import org.apache.http.client.ResponseHandler; 23 | import org.apache.http.util.EntityUtils; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | import org.sourcelab.kafka.connect.apiclient.rest.RestResponse; 27 | 28 | import java.io.IOException; 29 | 30 | /** 31 | * Handles parsing a response to RestResponse object. 32 | */ 33 | public final class RestResponseHandler implements ResponseHandler { 34 | private static final Logger logger = LoggerFactory.getLogger(RestResponseHandler.class); 35 | 36 | @Override 37 | public RestResponse handleResponse(final HttpResponse response) { 38 | final int statusCode = response.getStatusLine().getStatusCode(); 39 | 40 | try { 41 | final HttpEntity entity = response.getEntity(); 42 | final String responseStr = entity != null ? EntityUtils.toString(entity) : null; 43 | 44 | // Fully consume entity. 45 | EntityUtils.consume(entity); 46 | 47 | // Construct return object 48 | return new RestResponse(responseStr, statusCode); 49 | } catch (final IOException exception) { 50 | logger.error("Failed to read entity: {}", exception.getMessage(), exception); 51 | // TODO throw exceptions 52 | return null; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/rest/handlers/StringResponseHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest.handlers; 19 | 20 | import org.apache.http.HttpEntity; 21 | import org.apache.http.HttpResponse; 22 | import org.apache.http.client.ResponseHandler; 23 | import org.apache.http.util.EntityUtils; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * Returns response as a string. 29 | */ 30 | public final class StringResponseHandler implements ResponseHandler { 31 | @Override 32 | public String handleResponse(final HttpResponse response) throws IOException { 33 | 34 | final HttpEntity entity = response.getEntity(); 35 | final String responseStr = entity != null ? EntityUtils.toString(entity) : null; 36 | 37 | // Fully consume entity. 38 | EntityUtils.consume(entity); 39 | 40 | // Construct return object 41 | return responseStr; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/sourcelab/kafka/connect/apiclient/util/UrlEscapingUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.util; 19 | 20 | import org.apache.http.client.utils.URLEncodedUtils; 21 | import java.util.Objects; 22 | 23 | /** 24 | * Intended to provide a shim between Guava so that dependency can be removed in a future release. 25 | */ 26 | public class UrlEscapingUtil { 27 | /** 28 | * Returns the escaped form of a given literal string. 29 | * 30 | * @param input the literal string to be escaped. 31 | * @return the escaped form of string. 32 | * @throws NullPointerException if input string is null. 33 | * @throws IllegalArgumentException if string contains badly formed UTF-16 or cannot be escaped for any other reason 34 | */ 35 | public static String escapePath(final String input) { 36 | Objects.requireNonNull(input); 37 | final String result = URLEncodedUtils.formatSegments(input); 38 | // Strip prepended slash 39 | if (result.length() > 0) { 40 | return result.substring(1); 41 | } 42 | return ""; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/BadLoggersTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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 | import org.junit.Test; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.io.File; 23 | import java.io.FileNotFoundException; 24 | import java.util.Scanner; 25 | import java.util.regex.Matcher; 26 | import java.util.regex.Pattern; 27 | 28 | import static org.junit.Assert.assertFalse; 29 | 30 | /** 31 | * Look for LoggerFactory.getLogger(classname) where classname doesn't match the class its part of. 32 | * This is kind of a half assed way to do this. 33 | */ 34 | public class BadLoggersTest { 35 | private static final Logger logger = LoggerFactory.getLogger(BadLoggersTest.class); 36 | 37 | // Weak attempt 38 | private static final Pattern regexPattern = Pattern.compile("LoggerFactory.getLogger\\((.*)\\.class\\)"); 39 | 40 | @Test 41 | public void doTest() throws FileNotFoundException { 42 | // Hacky way to determine root path 43 | final File currentPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); 44 | final File projectRootPath = currentPath.getParentFile().getParentFile(); 45 | logger.info("Root Path: {}", projectRootPath); 46 | 47 | // Walk all the files in the path 48 | walk(projectRootPath); 49 | } 50 | 51 | private void walk(final File root) throws FileNotFoundException { 52 | final File[] list = root.listFiles(); 53 | 54 | if (list == null) return; 55 | 56 | for (final File f : list) { 57 | if (f.isDirectory()) { 58 | walk(f); 59 | } else { 60 | // Skip non java source files 61 | if (!f.getAbsoluteFile().getPath().endsWith(".java")) { 62 | continue; 63 | } 64 | testFile(f); 65 | } 66 | } 67 | } 68 | 69 | private void testFile(final File myFile) throws FileNotFoundException { 70 | final String fileData = new Scanner(myFile).useDelimiter("\\Z").next(); 71 | 72 | // Look for our pattern 73 | final Matcher matches = regexPattern.matcher(fileData); 74 | 75 | // If we didn't find a match 76 | if (!matches.find()) { 77 | return; 78 | } 79 | 80 | // Grab out the Class name 81 | final String loggerClassName = matches.group(1); 82 | if (loggerClassName == null) { 83 | return; 84 | } 85 | 86 | // Get class name from the file name 87 | // I bet this will be completely broken for inner classes... 88 | // if you run into that, just exclude it? or figure out a better solution to this :p 89 | final String className = myFile.getName().replace(".java", ""); 90 | if (!className.equals(loggerClassName)) { 91 | logger.info("Class {} ClassNameUsedByLogger {} ", className, loggerClassName); 92 | assertFalse("Found instance of logger using wrong class? " + myFile.getPath() + " Using " + loggerClassName, true); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/categories/IntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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 categories; 19 | 20 | /** 21 | * Used to Mark tests as integration tests. 22 | */ 23 | public interface IntegrationTest { 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/KafkaConnectClientUnitTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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; 19 | 20 | import org.apache.http.HttpStatus; 21 | import org.junit.Test; 22 | import org.sourcelab.kafka.connect.apiclient.rest.RestClient; 23 | import org.sourcelab.kafka.connect.apiclient.rest.RestResponse; 24 | import org.sourcelab.kafka.connect.apiclient.rest.exceptions.ConcurrentConfigModificationException; 25 | import org.sourcelab.kafka.connect.apiclient.rest.exceptions.ResourceNotFoundException; 26 | import org.sourcelab.kafka.connect.apiclient.rest.exceptions.UnauthorizedRequestException; 27 | 28 | import static org.mockito.ArgumentMatchers.any; 29 | import static org.mockito.Mockito.mock; 30 | import static org.mockito.Mockito.when; 31 | 32 | /** 33 | * Unit tests over KafkaConnectClient. 34 | */ 35 | public class KafkaConnectClientUnitTest { 36 | 37 | private final Configuration configuration = new Configuration("http://localhost:9092"); 38 | 39 | /** 40 | * This test verifies that if the underlying RestClient returns a response with Http Status Code 401, 41 | * then KafkaConnectClient will throw an UnauthorizedRequestException. 42 | */ 43 | @Test(expected = UnauthorizedRequestException.class) 44 | public void unAuthorizedException() { 45 | // Create mock RestResponse 46 | final RestResponse restResponse = new RestResponse("Invalid credentials.", HttpStatus.SC_UNAUTHORIZED); 47 | 48 | // Create mock RestClient 49 | final RestClient mockRestClient = mock(RestClient.class); 50 | when(mockRestClient.submitRequest(any())) 51 | .thenReturn(restResponse); 52 | 53 | // Create client 54 | final KafkaConnectClient client = new KafkaConnectClient(configuration, mockRestClient); 55 | 56 | // Call any method that makes a request via RestClient. 57 | client.getConnectors(); 58 | } 59 | 60 | /** 61 | * This test verifies that if the underlying RestClient returns a response with Http Status Code 404, 62 | * then KafkaConnectClient will throw a ResourceNotFoundException. 63 | */ 64 | @Test(expected = ResourceNotFoundException.class) 65 | public void on404_resourceNotFoundException() { 66 | // Create mock RestResponse 67 | final String connectorName = "DoesNotExist"; 68 | final String result = "{\"error_code\":404,\"message\":\"Connector " + connectorName + " not found\"}"; 69 | 70 | final RestResponse restResponse = new RestResponse(result, HttpStatus.SC_NOT_FOUND); 71 | 72 | // Create mock RestClient 73 | final RestClient mockRestClient = mock(RestClient.class); 74 | when(mockRestClient.submitRequest(any())) 75 | .thenReturn(restResponse); 76 | 77 | // Create client 78 | final KafkaConnectClient client = new KafkaConnectClient(configuration, mockRestClient); 79 | 80 | // Call any method that makes a request via RestClient. 81 | client.getConnector(connectorName); 82 | } 83 | 84 | /** 85 | * This test verifies that if the underlying RestClient returns a response with Http Status Code 409, 86 | * then KafkaConnectClient will throw a ConcurrentConfigModificationException. 87 | */ 88 | @Test(expected = ConcurrentConfigModificationException.class) 89 | public void on409_concurrentConfigModificationException() { 90 | // Create mock RestResponse 91 | final String connectorName = "DoesNotExist"; 92 | final String result = "{\"error_code\":409,\"message\":\"Rebalance in progress.\"}"; 93 | 94 | final RestResponse restResponse = new RestResponse(result, HttpStatus.SC_CONFLICT); 95 | 96 | // Create mock RestClient 97 | final RestClient mockRestClient = mock(RestClient.class); 98 | when(mockRestClient.submitRequest(any())) 99 | .thenReturn(restResponse); 100 | 101 | // Create client 102 | final KafkaConnectClient client = new KafkaConnectClient(configuration, mockRestClient); 103 | 104 | // Call any method that makes a request via RestClient. 105 | client.getConnector(connectorName); 106 | } 107 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/AbstractRequestTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request; 19 | 20 | import org.apache.commons.io.IOUtils; 21 | import org.junit.Test; 22 | 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.charset.StandardCharsets; 26 | 27 | /** 28 | * Abstract / Base Request Test Class. 29 | */ 30 | abstract public class AbstractRequestTest { 31 | 32 | /** 33 | * Test Parsing response. 34 | */ 35 | @Test 36 | public abstract void testParseResponse() throws Exception; 37 | 38 | /** 39 | * Verifies the behavior of the getApiEndPoint to properly return an escaped URL 40 | * when the connector name requires escaping. 41 | */ 42 | @Test 43 | public abstract void getApiEndpoint(); 44 | 45 | /** 46 | * Utility method to help load mock responses from resources. 47 | * @param fileName file name to load from resources 48 | * @return The contents of the file, as a UTF-8 string. 49 | * @throws IOException on error reading from resource file. 50 | */ 51 | protected String readFile(final String fileName) throws IOException { 52 | final URL inputFile = getClass().getClassLoader().getResource("mockResponses/" + fileName); 53 | return IOUtils.toString(inputFile, StandardCharsets.UTF_8); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectServerVersionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.junit.Test; 21 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 22 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectServerVersion; 23 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectServerVersion; 24 | 25 | import java.io.IOException; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | import static org.junit.Assert.assertNotNull; 29 | 30 | public class GetConnectServerVersionTest extends AbstractRequestTest { 31 | /** 32 | * Test Parsing GET / response. 33 | */ 34 | @Test 35 | public void testParseResponse() throws IOException { 36 | final String mockResponse = readFile("getConnectServerVersion.json"); 37 | final ConnectServerVersion result = new GetConnectServerVersion().parseResponse(mockResponse); 38 | 39 | // Validate 40 | assertNotNull("Should not be null", result); 41 | assertEquals("2.1.1", result.getVersion()); 42 | assertEquals("21234bee31165527", result.getCommit()); 43 | assertEquals("Fo2ySm4CT1Wvz4Kvm2jIhw", result.getKafkaClusterId()); 44 | } 45 | 46 | @Override 47 | public void getApiEndpoint() { 48 | final String expectedUrl = "/"; 49 | final String result = new GetConnectServerVersion().getApiEndpoint(); 50 | assertEquals("Unexpected URL returned!", expectedUrl, result); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorConfigTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 21 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorConfig; 22 | 23 | import java.util.Map; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.junit.Assert.assertNotNull; 27 | 28 | public class GetConnectorConfigTest extends AbstractRequestTest { 29 | 30 | @Override 31 | public void testParseResponse() throws Exception { 32 | final String mockResponse = readFile("getConnectorConfig.json"); 33 | final Map result = new GetConnectorConfig("Test Name").parseResponse(mockResponse); 34 | 35 | // validate config 36 | assertNotNull("Should not be null", result); 37 | assertEquals("Should have 4 entries", 4, result.size()); 38 | assertEquals("org.apache.kafka.connect.tools.MockConnector", result.get("connector.class")); 39 | assertEquals("10", result.get("tasks.max")); 40 | assertEquals("test-topic", result.get("topics")); 41 | assertEquals("My Test Connector", result.get("name")); 42 | } 43 | 44 | @Override 45 | public void getApiEndpoint() { 46 | final String inputName = "My Test Connector"; 47 | final String expectedUrl = "/connectors/My%20Test%20Connector/config"; 48 | final String result = new GetConnectorConfig(inputName).getApiEndpoint(); 49 | assertEquals("Unexpected URL returned!", expectedUrl, result); 50 | } 51 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorPluginsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.junit.Test; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 24 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPlugin; 25 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorPlugins; 26 | 27 | import java.io.IOException; 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | import static org.junit.Assert.assertEquals; 32 | import static org.junit.Assert.assertNotNull; 33 | 34 | public class GetConnectorPluginsTest extends AbstractRequestTest { 35 | private static final Logger logger = LoggerFactory.getLogger(GetConnectorPluginsTest.class); 36 | 37 | /** 38 | * Test Parsing GET /connectors response. 39 | */ 40 | @Test 41 | public void testParseResponse() throws IOException { 42 | final String mockResponse = readFile("getConnectorPlugins.json"); 43 | final List result = new ArrayList<>(new GetConnectorPlugins().parseResponse(mockResponse)); 44 | 45 | // Validate 46 | assertNotNull("Should not be null", result); 47 | assertEquals("Should have two entries", 2, result.size()); 48 | 49 | assertEquals("Should have connector", result.get(0).getClassName(), "org.apache.kafka.connect.file.FileStreamSinkConnector"); 50 | assertEquals("Should have type", result.get(0).getType(), "sink"); 51 | assertEquals("Should have version", result.get(0).getVersion(), "1.0.0-cp1"); 52 | 53 | assertEquals("Should have connector", result.get(1).getClassName(), "org.apache.kafka.connect.file.FileStreamSourceConnector"); 54 | assertEquals("Should have type", result.get(1).getType(), "source"); 55 | assertEquals("Should have version", result.get(1).getVersion(), "1.0.0-cp1"); 56 | } 57 | 58 | @Override 59 | public void getApiEndpoint() { 60 | final String expectedUrl = "/connector-plugins"; 61 | final String result = new GetConnectorPlugins().getApiEndpoint(); 62 | assertEquals("Unexpected URL returned!", expectedUrl, result); 63 | } 64 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorStatusTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition; 22 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnector; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertNull; 27 | import static org.junit.Assert.assertTrue; 28 | 29 | public class GetConnectorStatusTest extends AbstractRequestTest { 30 | 31 | @Override 32 | public void testParseResponse() throws Exception { 33 | final String mockResponse = readFile("getConnectorStatus.json"); 34 | final ConnectorDefinition result = new GetConnector("My Test Connector").parseResponse(mockResponse); 35 | 36 | // Validate 37 | assertNotNull("Should not be null", result); 38 | assertEquals("My Test Connector", result.getName()); 39 | assertEquals("unknown", result.getType()); 40 | 41 | // validate config 42 | assertNull("Should be null", result.getConfig()); 43 | 44 | // Validate tasks 45 | assertNotNull("Should not be null", result.getTasks()); 46 | assertTrue("Should be empty", result.getTasks().isEmpty()); 47 | } 48 | 49 | @Override 50 | public void getApiEndpoint() { 51 | final String inputName = "My Test Connector"; 52 | final String expectedUrl = "/connectors/My%20Test%20Connector"; 53 | final String result = new GetConnector(inputName).getApiEndpoint(); 54 | assertEquals("Unexpected URL returned!", expectedUrl, result); 55 | } 56 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorTasksTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.junit.Test; 21 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 22 | import org.sourcelab.kafka.connect.apiclient.request.dto.Task; 23 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorTasks; 24 | 25 | import java.io.IOException; 26 | import java.util.ArrayList; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import static org.junit.Assert.assertEquals; 32 | import static org.junit.Assert.assertNotNull; 33 | 34 | public class GetConnectorTasksTest extends AbstractRequestTest { 35 | /** 36 | * Test Parsing GET /connectors response. 37 | */ 38 | @Test 39 | public void testParseResponse() throws IOException { 40 | final String mockResponse = readFile("getConnectorTasks.json"); 41 | final List result = new ArrayList<>(new GetConnectorTasks("MyTestConnector").parseResponse(mockResponse)); 42 | 43 | // Validate 44 | assertNotNull("Should not be null", result); 45 | assertEquals("Should have one entry", 1, result.size()); 46 | 47 | assertEquals("Should have connector", result.get(0).getId().getConnector(), "MyTestConnector"); 48 | assertEquals("Should have task id", result.get(0).getId().getTask(), 0); 49 | 50 | // Define our expected result. 51 | final Map expectedMap = new HashMap<>(); 52 | expectedMap.put("connector.class", "org.apache.kafka.connect.tools.VerifiableSourceConnector"); 53 | expectedMap.put("task.class", "org.apache.kafka.connect.tools.VerifiableSourceTask"); 54 | expectedMap.put("tasks.max", "1"); 55 | expectedMap.put("topics", "test-topic"); 56 | expectedMap.put("name", "MyTestConnector"); 57 | expectedMap.put("id", "0"); 58 | 59 | // Assert it contains the expected values. 60 | assertEquals("Should have configs", result.get(0).getConfig(), expectedMap); 61 | } 62 | 63 | @Override 64 | public void getApiEndpoint() { 65 | final String inputName = "My Test Connector"; 66 | final String expectedUrl = "/connectors/My%20Test%20Connector/tasks"; 67 | final String result = new GetConnectorTasks(inputName).getApiEndpoint(); 68 | assertEquals("Unexpected URL returned!", expectedUrl, result); 69 | } 70 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition; 22 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnector; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertTrue; 27 | 28 | public class GetConnectorTest extends AbstractRequestTest { 29 | 30 | @Override 31 | public void testParseResponse() throws Exception { 32 | final String mockResponse = readFile("getConnector.json"); 33 | final ConnectorDefinition result = new GetConnector("My Test Connector").parseResponse(mockResponse); 34 | 35 | // Validate 36 | assertNotNull("Should not be null", result); 37 | assertEquals("My Test Connector", result.getName()); 38 | assertEquals("unknown", result.getType()); 39 | 40 | // validate config 41 | assertNotNull("Should not be null", result.getConfig()); 42 | assertEquals("Should have 4 entries", 4, result.getConfig().size()); 43 | assertEquals("org.apache.kafka.connect.tools.MockConnector", result.getConfig().get("connector.class")); 44 | assertEquals("10", result.getConfig().get("tasks.max")); 45 | assertEquals("test-topic", result.getConfig().get("topics")); 46 | assertEquals("My Test Connector", result.getConfig().get("name")); 47 | 48 | // Validate tasks 49 | assertNotNull("Should not be null", result.getTasks()); 50 | assertTrue("Should be empty", result.getTasks().isEmpty()); 51 | } 52 | 53 | @Override 54 | public void getApiEndpoint() { 55 | final String inputName = "My Test Connector"; 56 | final String expectedUrl = "/connectors/My%20Test%20Connector"; 57 | final String result = new GetConnector(inputName).getApiEndpoint(); 58 | assertEquals("Unexpected URL returned!", expectedUrl, result); 59 | } 60 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorTopicsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.junit.Test; 21 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 22 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorTopics; 23 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectorTopics; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.junit.Assert.assertFalse; 27 | import static org.junit.Assert.assertNotNull; 28 | import static org.junit.Assert.assertTrue; 29 | 30 | public class GetConnectorTopicsTest extends AbstractRequestTest { 31 | 32 | @Override 33 | public void getApiEndpoint() { 34 | final String name = "This is My Connector name"; 35 | final String expectedResult = "/connectors/This%20is%20My%20Connector%20name/topics"; 36 | final String result = new GetConnectorTopics(name).getApiEndpoint(); 37 | assertEquals(expectedResult, result); 38 | } 39 | 40 | @Test 41 | @Override 42 | public void testParseResponse() throws Exception { 43 | final String mockResponse = readFile("getConnectorTopics.json"); 44 | final ConnectorTopics result = new GetConnectorTopics("MyTestConnector").parseResponse(mockResponse); 45 | assertNotNull(result); 46 | assertEquals("MyTestConnector", result.getName()); 47 | assertNotNull(result.getTopics()); 48 | assertFalse("Should NOT be empty", result.getTopics().isEmpty()); 49 | assertEquals("test-topic-1", result.getTopics().get(0)); 50 | assertEquals("test-topic-2", result.getTopics().get(1)); 51 | assertEquals("test-topic-3", result.getTopics().get(2)); 52 | } 53 | 54 | @Test 55 | public void testParseResponse_emptyTopics() throws Exception { 56 | final String mockResponse = readFile("getConnectorTopics_empty.json"); 57 | final ConnectorTopics result = new GetConnectorTopics("MyTestConnector").parseResponse(mockResponse); 58 | assertNotNull(result); 59 | assertEquals("MyTestConnector", result.getName()); 60 | assertNotNull(result.getTopics()); 61 | assertTrue("Should be empty", result.getTopics().isEmpty()); 62 | } 63 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/get/connector/GetConnectorsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.get.connector; 19 | 20 | import org.junit.Test; 21 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 22 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnectors; 23 | 24 | import java.io.IOException; 25 | import java.util.Collection; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | import static org.junit.Assert.assertNotNull; 29 | import static org.junit.Assert.assertTrue; 30 | 31 | public class GetConnectorsTest extends AbstractRequestTest { 32 | 33 | /** 34 | * Test Parsing GET /connectors response. 35 | */ 36 | @Test 37 | public void testParseResponse() throws IOException { 38 | final String mockResponse = readFile("getConnectors.json"); 39 | final Collection result = new GetConnectors().parseResponse(mockResponse); 40 | 41 | // Validate 42 | assertNotNull("Should not be null", result); 43 | assertEquals("Should have two entries", 2, result.size()); 44 | assertTrue("Should have connector", result.contains("My Test Connector")); 45 | assertTrue("Should have connector", result.contains("My Other Test Connector")); 46 | } 47 | 48 | @Override 49 | public void getApiEndpoint() { 50 | final String expectedUrl = "/connectors"; 51 | final String result = new GetConnectors().getApiEndpoint(); 52 | assertEquals("Unexpected URL returned!", expectedUrl, result); 53 | } 54 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/post/PostConnectorRestartTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.post; 19 | 20 | import org.junit.Test; 21 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | 25 | public class PostConnectorRestartTest extends AbstractRequestTest { 26 | @Override 27 | public void testParseResponse() throws Exception { 28 | 29 | } 30 | 31 | /** 32 | * With no optional parameters. 33 | */ 34 | @Override 35 | public void getApiEndpoint() { 36 | final String inputName = "My Test Connector"; 37 | final String expectedUrl = "/connectors/My%20Test%20Connector/restart"; 38 | final String result = new PostConnectorRestart(inputName).getApiEndpoint(); 39 | assertEquals("Unexpected URL returned!", expectedUrl, result); 40 | } 41 | 42 | /** 43 | * Verify with various optional parameters specified. 44 | */ 45 | @Test 46 | public void getApiEndpoint_includeTasks_true() { 47 | final String inputName = "My Test Connector"; 48 | final String expectedUrl = "/connectors/My%20Test%20Connector/restart?includeTasks=true"; 49 | final String result = new PostConnectorRestart(inputName) 50 | .withIncludeTasks(true) 51 | .getApiEndpoint(); 52 | 53 | assertEquals("Unexpected URL returned!", expectedUrl, result); 54 | } 55 | 56 | /** 57 | * Verify with various optional parameters specified. 58 | */ 59 | @Test 60 | public void getApiEndpoint_includeTasks_false() { 61 | final String inputName = "My Test Connector"; 62 | final String expectedUrl = "/connectors/My%20Test%20Connector/restart?includeTasks=false"; 63 | final String result = new PostConnectorRestart(inputName) 64 | .withIncludeTasks(false) 65 | .getApiEndpoint(); 66 | 67 | assertEquals("Unexpected URL returned!", expectedUrl, result); 68 | } 69 | 70 | /** 71 | * Verify with various optional parameters specified. 72 | */ 73 | @Test 74 | public void getApiEndpoint_onlyFailed_true() { 75 | final String inputName = "My Test Connector"; 76 | final String expectedUrl = "/connectors/My%20Test%20Connector/restart?onlyFailed=true"; 77 | final String result = new PostConnectorRestart(inputName) 78 | .withOnlyFailed(true) 79 | .getApiEndpoint(); 80 | 81 | assertEquals("Unexpected URL returned!", expectedUrl, result); 82 | } 83 | 84 | /** 85 | * Verify with various optional parameters specified. 86 | */ 87 | @Test 88 | public void getApiEndpoint_onlyFailed_false() { 89 | final String inputName = "My Test Connector"; 90 | final String expectedUrl = "/connectors/My%20Test%20Connector/restart?onlyFailed=false"; 91 | final String result = new PostConnectorRestart(inputName) 92 | .withOnlyFailed(false) 93 | .getApiEndpoint(); 94 | 95 | assertEquals("Unexpected URL returned!", expectedUrl, result); 96 | } 97 | 98 | /** 99 | * Verify with various optional parameters specified. 100 | */ 101 | @Test 102 | public void getApiEndpoint_onlyFailed_includeTasks_true() { 103 | final String inputName = "My Test Connector"; 104 | final String expectedUrl = "/connectors/My%20Test%20Connector/restart?includeTasks=true&onlyFailed=true"; 105 | final String result = new PostConnectorRestart(inputName) 106 | .withOnlyFailed(true) 107 | .withIncludeTasks(true) 108 | .getApiEndpoint(); 109 | 110 | assertEquals("Unexpected URL returned!", expectedUrl, result); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/request/put/connector/PutConnectorConfigTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.request.put.connector; 19 | 20 | import org.sourcelab.kafka.connect.apiclient.request.AbstractRequestTest; 21 | import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorDefinition; 22 | import org.sourcelab.kafka.connect.apiclient.request.get.GetConnector; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertTrue; 27 | 28 | public class PutConnectorConfigTest extends AbstractRequestTest { 29 | 30 | @Override 31 | public void testParseResponse() throws Exception { 32 | final String mockResponse = readFile("putConnector.json"); 33 | final ConnectorDefinition result = new GetConnector("My Test Connector").parseResponse(mockResponse); 34 | 35 | // Validate 36 | assertNotNull("Should not be null", result); 37 | assertEquals("My Test Connector", result.getName()); 38 | assertEquals("unknown", result.getType()); 39 | 40 | // validate config 41 | assertNotNull("Should not be null", result.getConfig()); 42 | assertEquals("Should have 4 entries", 4, result.getConfig().size()); 43 | assertEquals("org.apache.kafka.connect.tools.MockConnector", result.getConfig().get("connector.class")); 44 | assertEquals("10", result.getConfig().get("tasks.max")); 45 | assertEquals("test-topic", result.getConfig().get("topics")); 46 | assertEquals("My Test Connector", result.getConfig().get("name")); 47 | 48 | // Validate tasks 49 | assertNotNull("Should not be null", result.getTasks()); 50 | assertTrue("Should be empty", result.getTasks().isEmpty()); 51 | } 52 | 53 | @Override 54 | public void getApiEndpoint() { 55 | final String inputName = "My Test Connector"; 56 | final String expectedUrl = "/connectors/My%20Test%20Connector"; 57 | final String result = new GetConnector(inputName).getApiEndpoint(); 58 | assertEquals("Unexpected URL returned!", expectedUrl, result); 59 | } 60 | } -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/rest/HttpsContextBuilderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.rest; 19 | 20 | import org.apache.http.conn.ssl.NoopHostnameVerifier; 21 | import org.junit.Test; 22 | import org.sourcelab.kafka.connect.apiclient.Configuration; 23 | 24 | import javax.net.ssl.HostnameVerifier; 25 | 26 | import static org.junit.Assert.assertFalse; 27 | import static org.junit.Assert.assertNotNull; 28 | import static org.junit.Assert.assertTrue; 29 | 30 | public class HttpsContextBuilderTest { 31 | 32 | /** 33 | * Constructor should require non-null arguments. 34 | */ 35 | @Test(expected = NullPointerException.class) 36 | public void testConstructorNullArguments() { 37 | new HttpsContextBuilder(null); 38 | } 39 | 40 | /** 41 | * When configured to validate SSL certificates, should not get NoopHostnameVerifier back. 42 | */ 43 | @Test 44 | public void getHostnameVerifier_validateSslCertificates() { 45 | final HttpsContextBuilder builder = new HttpsContextBuilder(new Configuration("http://localhost")); 46 | 47 | final HostnameVerifier verifier = builder.getHostnameVerifier(); 48 | assertNotNull(verifier); 49 | assertFalse("Should not be an instance of NoopHostnameVerifier", verifier instanceof NoopHostnameVerifier); 50 | } 51 | 52 | /** 53 | * When configured to skip validating SSL certificates, should get NoopHostnameVerifier back. 54 | */ 55 | @Test 56 | public void getHostnameVerifier_acceptInvalidSslCertificates() { 57 | final HttpsContextBuilder builder = new HttpsContextBuilder( 58 | new Configuration("http://localhost").useInsecureSslCertificates() 59 | ); 60 | 61 | final HostnameVerifier verifier = builder.getHostnameVerifier(); 62 | assertNotNull(verifier); 63 | assertTrue("Should be an instance of NoopHostnameVerifier", verifier instanceof NoopHostnameVerifier); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/sourcelab/kafka/connect/apiclient/util/UrlEscapingUtilTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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.util; 19 | 20 | import com.tngtech.java.junit.dataprovider.DataProvider; 21 | import com.tngtech.java.junit.dataprovider.DataProviderRunner; 22 | import com.tngtech.java.junit.dataprovider.UseDataProvider; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | 28 | @RunWith(DataProviderRunner.class) 29 | public class UrlEscapingUtilTest { 30 | 31 | /** 32 | * Validate escaping works as expected. 33 | */ 34 | @Test 35 | @UseDataProvider("provideTestCases") 36 | public void doTest(final String input, final String expectedResult) { 37 | final String result = UrlEscapingUtil.escapePath(input); 38 | assertEquals("Unexpected result!", expectedResult, result); 39 | } 40 | 41 | /** 42 | * To be honest I'm not entirely sure if this is the appropriate escaping for paths, 43 | * but aiming for backwards compatibility, and until someone complains and provides a test case 44 | * that is incorrect, I'm just going with the below sample values. 45 | */ 46 | @DataProvider 47 | public static Object[][] provideTestCases() { 48 | return new Object[][] { 49 | // The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same. 50 | { "easyInput", "easyInput" }, 51 | { "123", "123" }, 52 | { "abC123zxY", "abC123zxY" }, 53 | 54 | // The unreserved characters ".", "-", "~", and "_" remain the same. 55 | { "easy-input", "easy-input" }, 56 | { "easy.input", "easy.input" }, 57 | { "easy~input", "easy~input" }, 58 | { "easy_input", "easy_input" }, 59 | 60 | // The general delimiters "@" and ":" remain the same. 61 | 62 | { "easy@input", "easy@input" }, 63 | { "easy:input", "easy:input" }, 64 | 65 | // The subdelimiters "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", and "=" remain the same. 66 | { "easy!input", "easy!input" }, 67 | { "easy$input", "easy$input" }, 68 | { "easy&input", "easy&input" }, 69 | { "easy'input", "easy'input" }, 70 | { "easy(input)", "easy(input)" }, 71 | { "easy*input", "easy*input" }, 72 | { "easy+input", "easy+input" }, 73 | { "easy,input", "easy,input" }, 74 | { "easy;input", "easy;input" }, 75 | { "easy=input", "easy=input" }, 76 | 77 | // The space character " " is converted into %20. 78 | { "123 456", "123%20456" }, 79 | { "123 456", "123%20%20456" }, 80 | { " 123 456", "%20123%20%20456" }, 81 | { " 123 456 ", "%20%20123%20%20456%20" }, 82 | 83 | // Others 84 | { "12\\3", "12%5C3" }, 85 | { "12/3/4", "12%2F3%2F4" }, 86 | { "?easy=input&other=value", "%3Feasy=input&other=value" }, 87 | 88 | // All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then 89 | // represented by the 3-character string "%XY", where "XY" is the two-digit, uppercase, hexadecimal representation of the byte value. 90 | { "しんちゃん", "%E3%81%97%E3%82%93%E3%81%A1%E3%82%83%E3%82%93" }, 91 | { "無料", "%E7%84%A1%E6%96%99" }, 92 | { "abcdÈfghí", "abcd%C3%88fgh%C3%AD" }, 93 | }; 94 | } 95 | } -------------------------------------------------------------------------------- /src/test/java/testserver/RequestProperties.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018, 2019, 2020, 2021 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 testserver; 19 | 20 | /** 21 | * Defines properties about a Request to TestHttpServer. 22 | */ 23 | public class RequestProperties { 24 | private final String url; 25 | private final String requestBody; 26 | private final String requestMethod; 27 | 28 | public RequestProperties( 29 | final String url, 30 | final String requestBody, 31 | final String requestMethod 32 | ) { 33 | this.url = url; 34 | this.requestBody = requestBody; 35 | this.requestMethod = requestMethod; 36 | } 37 | 38 | public String getUrl() { 39 | return url; 40 | } 41 | 42 | public String getRequestBody() { 43 | return requestBody; 44 | } 45 | 46 | public String getRequestMethod() { 47 | return requestMethod; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/resources/certificates/DUMMY_CERTIFICATES_FOR_TESTS.txt: -------------------------------------------------------------------------------- 1 | These are just dummy certificates used for tests. -------------------------------------------------------------------------------- /src/test/resources/certificates/server.keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SourceLabOrg/kafka-connect-client/bd3b919ff50587feaf7ceecaa1eb792693808e24/src/test/resources/certificates/server.keystore.jks -------------------------------------------------------------------------------- /src/test/resources/certificates/server.truststore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SourceLabOrg/kafka-connect-client/bd3b919ff50587feaf7ceecaa1eb792693808e24/src/test/resources/certificates/server.truststore.jks -------------------------------------------------------------------------------- /src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/test/resources/mockResponses/errorResourceNotFound.json: -------------------------------------------------------------------------------- 1 | {"error_code":404,"message":"Connector DoesNotExist not found"} -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectServerVersion.json: -------------------------------------------------------------------------------- 1 | {"version":"2.1.1","commit":"21234bee31165527","kafka_cluster_id":"Fo2ySm4CT1Wvz4Kvm2jIhw"} -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnector.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "My Test Connector", 3 | "config": { 4 | "connector.class": "org.apache.kafka.connect.tools.MockConnector", 5 | "tasks.max": "10", 6 | "topics": "test-topic", 7 | "name": "My Test Connector" 8 | }, 9 | "tasks": [], 10 | "type": "unknown" 11 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "connector.class": "org.apache.kafka.connect.tools.MockConnector", 3 | "tasks.max": "10", 4 | "topics": "test-topic", 5 | "name": "My Test Connector" 6 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorPlugins.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "class": "org.apache.kafka.connect.file.FileStreamSinkConnector", 3 | "type": "sink", 4 | "version": "1.0.0-cp1" 5 | }, { 6 | "class": "org.apache.kafka.connect.file.FileStreamSourceConnector", 7 | "type": "source", 8 | "version": "1.0.0-cp1" 9 | }] -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorStatus.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "My Test Connector", 3 | "connector": { 4 | "state": "RUNNING", 5 | "worker_id": "192.168.86.201:8083" 6 | }, 7 | "tasks": [], 8 | "type": "unknown" 9 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorTaskStatus.json: -------------------------------------------------------------------------------- 1 | { 2 | "state": "FAILED", 3 | "trace": "org.apache.kafka.connect.errors.ConnectException: Invalid VerifiableSourceTask configuration\n\tat org.apache.kafka.connect.tools.VerifiableSourceTask.start(VerifiableSourceTask.java:79)\n\tat org.apache.kafka.connect.runtime.WorkerSourceTask.execute(WorkerSourceTask.java:157)\n\tat org.apache.kafka.connect.runtime.WorkerTask.doRun(WorkerTask.java:170)\n\tat org.apache.kafka.connect.runtime.WorkerTask.run(WorkerTask.java:214)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat java.lang.Thread.run(Thread.java:748)\nCaused by: java.lang.NumberFormatException: null\n\tat java.lang.Long.parseLong(Long.java:552)\n\tat java.lang.Long.parseLong(Long.java:631)\n\tat org.apache.kafka.connect.tools.VerifiableSourceTask.start(VerifiableSourceTask.java:77)\n\t... 8 more\n", 4 | "id": 0, 5 | "worker_id": "192.168.86.201:8083" 6 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorTasks.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": { 3 | "connector": "MyTestConnector", 4 | "task": 0 5 | }, 6 | "config": { 7 | "connector.class": "org.apache.kafka.connect.tools.VerifiableSourceConnector", 8 | "task.class": "org.apache.kafka.connect.tools.VerifiableSourceTask", 9 | "tasks.max": "1", 10 | "topics": "test-topic", 11 | "name": "MyTestConnector", 12 | "id": "0" 13 | } 14 | }] -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorTopics.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyTestConnector": { 3 | "topics": [ 4 | "test-topic-1", 5 | "test-topic-2", 6 | "test-topic-3" 7 | ] 8 | } 9 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorTopics_empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyTestConnector": { 3 | "topics": [] 4 | } 5 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectors.json: -------------------------------------------------------------------------------- 1 | ["My Test Connector", "My Other Test Connector"] -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorsWithAllExpandedMetadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyTestConnector": { 3 | "info": { 4 | "name": "MyTestConnector", 5 | "config": { 6 | "connector.class": "org.apache.kafka.connect.tools.VerifiableSourceConnector", 7 | "tasks.max": "3", 8 | "topics": "test-topic", 9 | "name": "MyTestConnector" 10 | }, 11 | "tasks": [ 12 | { 13 | "connector": "MyTestConnector", 14 | "task": 0 15 | }, 16 | { 17 | "connector": "MyTestConnector", 18 | "task": 1 19 | }, 20 | { 21 | "connector": "MyTestConnector", 22 | "task": 2 23 | } 24 | ], 25 | "type": "source" 26 | }, 27 | "status": { 28 | "name": "MyTestConnector", 29 | "connector": { 30 | "state": "RUNNING", 31 | "worker_id": "127.0.0.1:8083" 32 | }, 33 | "tasks": [ 34 | { 35 | "id": 0, 36 | "state": "FAILED", 37 | "worker_id": "127.0.0.1:8083", 38 | "trace": "trace0" 39 | }, 40 | { 41 | "id": 1, 42 | "state": "RUNNING", 43 | "worker_id": "127.0.0.1:8083", 44 | "trace": "trace1" 45 | }, 46 | { 47 | "id": 2, 48 | "state": "PAUSED", 49 | "worker_id": "127.0.0.1:8083", 50 | "trace": "trace2" 51 | } 52 | ], 53 | "type": "source" 54 | } 55 | }, 56 | "MyTestConnector2": { 57 | "info": { 58 | "name": "MyTestConnector2", 59 | "config": { 60 | "connector.class": "org.apache.kafka.connect.tools.SomeOtherConnectorClass", 61 | "tasks.max": "1", 62 | "topics": "another-topic", 63 | "name": "MyTestConnector2" 64 | }, 65 | "tasks": [ 66 | { 67 | "connector": "MyTestConnector2", 68 | "task": 0 69 | } 70 | ], 71 | "type": "source" 72 | }, 73 | "status": { 74 | "name": "MyTestConnector2", 75 | "connector": { 76 | "state": "RUNNING", 77 | "worker_id": "127.0.0.1:8083" 78 | }, 79 | "tasks": [ 80 | { 81 | "id": 0, 82 | "state": "RUNNING", 83 | "worker_id": "127.0.0.1:8083", 84 | "trace": "trace0" 85 | } 86 | ], 87 | "type": "source" 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorsWithExpandedInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyTestConnector": { 3 | "info": { 4 | "name": "MyTestConnector", 5 | "config": { 6 | "connector.class": "org.apache.kafka.connect.tools.VerifiableSourceConnector", 7 | "tasks.max": "3", 8 | "topics": "test-topic", 9 | "name": "MyTestConnector" 10 | }, 11 | "tasks": [ 12 | { 13 | "connector": "MyTestConnector", 14 | "task": 0 15 | }, 16 | { 17 | "connector": "MyTestConnector", 18 | "task": 1 19 | }, 20 | { 21 | "connector": "MyTestConnector", 22 | "task": 2 23 | } 24 | ], 25 | "type": "source" 26 | } 27 | }, 28 | "MyTestConnector2": { 29 | "info": { 30 | "name": "MyTestConnector2", 31 | "config": { 32 | "connector.class": "org.apache.kafka.connect.tools.SomeOtherConnectorClass", 33 | "tasks.max": "1", 34 | "topics": "another-topic", 35 | "name": "MyTestConnector2" 36 | }, 37 | "tasks": [ 38 | { 39 | "connector": "MyTestConnector2", 40 | "task": 0 41 | } 42 | ], 43 | "type": "source" 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/resources/mockResponses/getConnectorsWithExpandedStatus.json: -------------------------------------------------------------------------------- 1 | { 2 | "MyTestConnector": { 3 | "status": { 4 | "name": "MyTestConnector", 5 | "connector": { 6 | "state": "RUNNING", 7 | "worker_id": "127.0.0.1:8083" 8 | }, 9 | "tasks": [ 10 | { 11 | "id": 0, 12 | "state": "FAILED", 13 | "worker_id": "127.0.0.1:8083", 14 | "trace": "trace0" 15 | }, 16 | { 17 | "id": 1, 18 | "state": "RUNNING", 19 | "worker_id": "127.0.0.1:8083", 20 | "trace": "trace1" 21 | }, 22 | { 23 | "id": 2, 24 | "state": "PAUSED", 25 | "worker_id": "127.0.0.1:8083", 26 | "trace": "trace2" 27 | } 28 | ], 29 | "type": "source" 30 | } 31 | }, 32 | "MyTestConnector2": { 33 | "status": { 34 | "name": "MyTestConnector2", 35 | "connector": { 36 | "state": "RUNNING", 37 | "worker_id": "127.0.0.1:8083" 38 | }, 39 | "tasks": [ 40 | { 41 | "id": 0, 42 | "state": "RUNNING", 43 | "worker_id": "127.0.0.1:8083", 44 | "trace": "trace0" 45 | } 46 | ], 47 | "type": "source" 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/putConnector.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "My Test Connector", 3 | "config": { 4 | "connector.class": "org.apache.kafka.connect.tools.MockConnector", 5 | "tasks.max": "10", 6 | "topics": "test-topic", 7 | "name": "My Test Connector" 8 | }, 9 | "tasks": [], 10 | "type": "unknown" 11 | } -------------------------------------------------------------------------------- /src/test/resources/mockResponses/putConnectorPluginConfigValidate.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "org.apache.kafka.connect.tools.VerifiableSourceConnector", 3 | "error_count": 1, 4 | "groups": ["Common", "Transforms"], 5 | "configs": [{ 6 | "definition": { 7 | "name": "name", 8 | "type": "STRING", 9 | "required": true, 10 | "default_value": null, 11 | "importance": "HIGH", 12 | "documentation": "Globally unique name to use for this connector.", 13 | "group": "Common", 14 | "width": "MEDIUM", 15 | "display_name": "Connector name", 16 | "dependents": [], 17 | "order": 1 18 | }, 19 | "value": { 20 | "name": "name", 21 | "value": null, 22 | "recommended_values": [], 23 | "errors": ["Missing required configuration \"name\" which has no default value."], 24 | "visible": true 25 | } 26 | }, { 27 | "definition": { 28 | "name": "connector.class", 29 | "type": "STRING", 30 | "required": true, 31 | "default_value": null, 32 | "importance": "HIGH", 33 | "documentation": "Name or alias of the class for this connector. Must be a subclass of org.apache.kafka.connect.connector.Connector. If the connector is org.apache.kafka.connect.file.FileStreamSinkConnector, you can either specify this full name, or use \"FileStreamSink\" or \"FileStreamSinkConnector\" to make the configuration a bit shorter", 34 | "group": "Common", 35 | "width": "LONG", 36 | "display_name": "Connector class", 37 | "dependents": [], 38 | "order": 2 39 | }, 40 | "value": { 41 | "name": "connector.class", 42 | "value": "org.apache.kafka.connect.tools.VerifiableSourceConnector", 43 | "recommended_values": [], 44 | "errors": [], 45 | "visible": true 46 | } 47 | }, { 48 | "definition": { 49 | "name": "tasks.max", 50 | "type": "INT", 51 | "required": false, 52 | "default_value": "1", 53 | "importance": "HIGH", 54 | "documentation": "Maximum number of tasks to use for this connector.", 55 | "group": "Common", 56 | "width": "SHORT", 57 | "display_name": "Tasks max", 58 | "dependents": [], 59 | "order": 3 60 | }, 61 | "value": { 62 | "name": "tasks.max", 63 | "value": "3", 64 | "recommended_values": [], 65 | "errors": [], 66 | "visible": true 67 | } 68 | }, { 69 | "definition": { 70 | "name": "key.converter", 71 | "type": "CLASS", 72 | "required": false, 73 | "default_value": null, 74 | "importance": "LOW", 75 | "documentation": "Converter class used to convert between Kafka Connect format and the serialized form that is written to Kafka. This controls the format of the keys in messages written to or read from Kafka, and since this is independent of connectors it allows any connector to work with any serialization format. Examples of common formats include JSON and Avro.", 76 | "group": "Common", 77 | "width": "SHORT", 78 | "display_name": "Key converter class", 79 | "dependents": [], 80 | "order": 4 81 | }, 82 | "value": { 83 | "name": "key.converter", 84 | "value": null, 85 | "recommended_values": [], 86 | "errors": [], 87 | "visible": true 88 | } 89 | }, { 90 | "definition": { 91 | "name": "value.converter", 92 | "type": "CLASS", 93 | "required": false, 94 | "default_value": null, 95 | "importance": "LOW", 96 | "documentation": "Converter class used to convert between Kafka Connect format and the serialized form that is written to Kafka. This controls the format of the values in messages written to or read from Kafka, and since this is independent of connectors it allows any connector to work with any serialization format. Examples of common formats include JSON and Avro.", 97 | "group": "Common", 98 | "width": "SHORT", 99 | "display_name": "Value converter class", 100 | "dependents": [], 101 | "order": 5 102 | }, 103 | "value": { 104 | "name": "value.converter", 105 | "value": null, 106 | "recommended_values": [], 107 | "errors": [], 108 | "visible": true 109 | } 110 | }, { 111 | "definition": { 112 | "name": "transforms", 113 | "type": "LIST", 114 | "required": false, 115 | "default_value": null, 116 | "importance": "LOW", 117 | "documentation": "Aliases for the transformations to be applied to records.", 118 | "group": "Transforms", 119 | "width": "LONG", 120 | "display_name": "Transforms", 121 | "dependents": [], 122 | "order": 6 123 | }, 124 | "value": { 125 | "name": "transforms", 126 | "value": null, 127 | "recommended_values": [], 128 | "errors": [], 129 | "visible": true 130 | } 131 | }] 132 | } --------------------------------------------------------------------------------