Skip to content

Commit

Permalink
🔧 Add support for multiple configuration contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
helpermethod committed Aug 24, 2021
1 parent 127f250 commit 7c4ac6e
Show file tree
Hide file tree
Showing 30 changed files with 339 additions and 63 deletions.
10 changes: 0 additions & 10 deletions .github/dependabot.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/early-access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
${{ matrix.gu-binary }} install native-image
- name: 'Cache Maven packages'
uses: actions/cache@v2.1.6
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
distribution: 'zulu'

- name: 'Cache Maven packages'
uses: actions/cache@v2.1.6
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
distribution: 'zulu'

- name: 'Cache Maven packages'
uses: actions/cache@v2.1.6
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
distribution: 'zulu'

- name: 'Cache Maven packages'
uses: actions/cache@v2.1.6
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
${{ matrix.gu-binary }} install native-image
- name: 'Cache Maven packages'
uses: actions/cache@v2.1.6
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
distribution: 'zulu'

- name: 'Cache Maven packages'
uses: actions/cache@v2.1.6
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ It is recommended to install the bash/zsh completion script _kcctl_completion_:
. kcctl_completion
```

## Quickstart

Before you can start using _kcctl_ you need to create a configuration context.
A configuration context is a set of configuration parameters, grouped
by a name.
To create a configuration context named `local`, with the Kafka Connect cluster URL set to
`http://localhost:8083`, issue the following command

```shell script
kcctl set-context local --cluster http://localhost:8083
```

:exclamation: Note that certain commands will require additional parameters, like `bootstrap-servers` and
`offset-topic`.

Type `kcctl info` to display some information about the Kafka connect cluster.
The command will use the currently active context, `local` in this case, to
resolve the cluster URL.

## Usage

Display the help to learn about using _kcctl_:
Expand Down
10 changes: 8 additions & 2 deletions kcctl_completion
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,20 @@ function _picocli_kcctl_config_setcontext() {

local commands=""
local flag_opts=""
local arg_opts="--cluster"
local arg_opts="--cluster --bootstrap-servers --offset-topic"

compopt +o default

case ${prev_word} in
--cluster)
return
;;
--bootstrap-servers)
return
;;
--offset-topic)
return
;;
esac

if [[ "${curr_word}" == -* ]]; then
Expand Down Expand Up @@ -633,7 +639,7 @@ function _picocli_kcctl_restart_task() {
local commands=""
local flag_opts=""
local arg_opts=""
local NAME_pos_param_args=`kcctl task-name-completions` # 0-0 values
local NAME_pos_param_args=`kcctl task-name-completions # 0-0 values
if [[ "${curr_word}" == -* ]]; then
COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") )
Expand Down
21 changes: 16 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.1.3.Final</quarkus.platform.version>
<quarkus.platform.version>2.1.1.Final</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<artifactsDir>target</artifactsDir>
</properties>
Expand Down Expand Up @@ -97,6 +97,17 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-assertj</artifactId>
<version>2.27.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -113,12 +124,12 @@
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.1</version>
<version>4.0</version>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.16.0</version>
<version>2.15.0</version>
<configuration>
<configFile>etc/eclipse-formatter-config.xml</configFile>
</configuration>
Expand All @@ -127,7 +138,7 @@
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.0</version>
<configuration>
<groups>java.,javax.,org.,com.</groups>
<removeUnused>true</removeUnused>
Expand Down Expand Up @@ -219,7 +230,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<version>3.2.0</version>
<configuration>
<attach>false</attach>
<appendAssemblyId>false</appendAssemblyId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/morling/kccli/command/ApplyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ApplyCommand implements Callable<Integer> {
@Override
public Integer call() throws Exception {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

if (!file.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ConnectorNamesCompletionCandidateCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

List<String> connectors = kafkaConnectApi.getConnectors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DeleteConnectorCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

kafkaConnectApi.deleteConnector(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class DescribeConnectorCommand implements Callable<Integer> {
@Override
public Integer call() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

if (includeTasksConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GetConnectorsCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

List<String> connectors = kafkaConnectApi.getConnectors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GetContextCommand implements Runnable {

@Override
public void run() {
String clusterUri = context.getCluster().toASCIIString();
String clusterUri = context.getContext().getCluster().toASCIIString();
System.out.println("Current context is set to " + clusterUri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class GetLoggerCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

String[][] data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class GetLoggersCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

ObjectNode connectorLoggers = kafkaConnectApi.getLoggers("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class GetPluginsCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

List<ConnectorPlugin> connectorPlugins = kafkaConnectApi.getConnectorPlugins();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/morling/kccli/command/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class InfoCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

KafkaConnectInfo workerInfo = kafkaConnectApi.getWorkerInfo();
System.out.println("URL: " + context.getCluster());
System.out.println("URL: " + context.getContext().getCluster());
System.out.println("Version: " + workerInfo.version);
System.out.println("Commit: " + workerInfo.commit);
System.out.println("Kafka Cluster ID: " + workerInfo.kafka_cluster_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class LoggerNamesCompletionCandidateCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

ObjectNode connectorLoggers = kafkaConnectApi.getLoggers("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class PatchConnectorCommand implements Callable<Integer> {
public Integer call() throws JsonProcessingException {

KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

Map<String, String> connectorParameters = kafkaConnectApi.getConnectorConfig(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PatchLogLevelCommand implements Callable {
@Override
public Object call() throws Exception {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PauseConnectorCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

kafkaConnectApi.pauseConnector(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RestartConnectorCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

kafkaConnectApi.restartConnector(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RestartTaskCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

String[] parts = name.split("\\/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ResumeConnectorCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

kafkaConnectApi.resumeConnector(name);
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/dev/morling/kccli/command/SetContextCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,32 @@
*/
package dev.morling.kccli.command;

import java.net.URI;

import dev.morling.kccli.service.Context;
import dev.morling.kccli.util.ConfigurationContext;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

@Command(name = "set-context", description = "Set the context to cluster provided in arguments")
public class SetContextCommand implements Runnable {
@Parameters(index = "0", description = "Context name")
String contextName;

@Option(names = { "--cluster" }, description = "URL of the Kafka Connect cluster to connect to", required = true)
@Option(names = { "--cluster" }, defaultValue = "http://localhost:8083", description = "URL of the Kafka Connect cluster to connect to")
String cluster;

@Option(names = { "--bootstrap-servers" }, defaultValue = "localhost:9092", description = "Comma-separated list of Kafka broker URLs")
String bootstrapServers;

@Option(names = { "--offset-topic" }, description = "Name of the offset topic")
String offsetTopic;

@Override
public void run() {
ConfigurationContext context = new ConfigurationContext();
context.setConfiguration(cluster);
System.out.println("Successfully set context to " + cluster);
context.setContext(contextName, new Context(URI.create(cluster), bootstrapServers, offsetTopic));
System.out.println("Using context " + contextName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TaskNamesCompletionCandidateCommand implements Runnable {
@Override
public void run() {
KafkaConnectApi kafkaConnectApi = RestClientBuilder.newBuilder()
.baseUri(context.getCluster())
.baseUri(context.getContext().getCluster())
.build(KafkaConnectApi.class);

List<String> connectors = kafkaConnectApi.getConnectors();
Expand Down

0 comments on commit 7c4ac6e

Please sign in to comment.