Skip to content

Commit 9109340

Browse files
committed
feat: add support for multiple providers
Adds support to configure multiple configuration for a same provider type. Adds --provider option to CLI
1 parent d5ff48d commit 9109340

81 files changed

Lines changed: 2459 additions & 340 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/src/main/java/io/streamthoughts/jikkou/client/command/DiffCommand.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import picocli.CommandLine.Option;
3131

3232
@Command(name = "diff",
33-
header = "Show resource changes required by the current resource definitions.",
34-
description = """
35-
Generates a speculative reconciliation plan, showing the resource changes Jikkou would apply to reconcile the resource definitions.
36-
This command does not actually perform the reconciliation actions.
37-
""")
33+
header = "Show resource changes required by the current resource definitions.",
34+
description = """
35+
Generates a speculative reconciliation plan, showing the resource changes Jikkou would apply to reconcile the resource definitions.
36+
This command does not actually perform the reconciliation actions.
37+
""")
3838
@Singleton
3939
public class DiffCommand extends CLIBaseCommand implements Callable<Integer> {
4040

@@ -47,22 +47,24 @@ public class DiffCommand extends CLIBaseCommand implements Callable<Integer> {
4747
FormatOptionsMixin formatOptions;
4848
@Mixin
4949
ConfigOptionsMixin configOptionsMixin;
50+
@Mixin
51+
ProviderOptionMixin providerOptionMixin;
5052

5153
@Option(names = {"--" + SimpleResourceChangeFilter.FILTER_RESOURCE_OPS_NAME},
52-
split = ",",
53-
description = "Filter out all resources except those corresponding to given operations. Valid values: ${COMPLETION-CANDIDATES}."
54+
split = ",",
55+
description = "Filter out all resources except those corresponding to given operations. Valid values: ${COMPLETION-CANDIDATES}."
5456
)
5557
Set<Operation> filterOutAllResourcesExcept = new HashSet<>();
5658

5759
@Option(names = {"--" + SimpleResourceChangeFilter.FILTER_CHANGE_OP_NAME},
58-
split = ",",
59-
description = "Filter out all state-changes except those corresponding to given operations. Valid values: ${COMPLETION-CANDIDATES}."
60+
split = ",",
61+
description = "Filter out all state-changes except those corresponding to given operations. Valid values: ${COMPLETION-CANDIDATES}."
6062
)
6163
Set<Operation> filterOutAllChangesExcept = new HashSet<>();
6264

6365
@Option(names = {"--list"},
64-
defaultValue = "false",
65-
description = "Get resources as ApiResourceChangeList (default: ${DEFAULT-VALUE})."
66+
defaultValue = "false",
67+
description = "Get resources as ApiResourceChangeList (default: ${DEFAULT-VALUE})."
6668
)
6769
private boolean list;
6870

@@ -82,11 +84,11 @@ public Integer call() throws IOException {
8284

8385
try {
8486
ApiResourceChangeList result = api.getDiff(
85-
getResources(),
86-
new SimpleResourceChangeFilter()
87-
.filterOutAllResourcesExcept(filterOutAllResourcesExcept)
88-
.filterOutAllChangesExcept(filterOutAllChangesExcept),
89-
getReconciliationContext()
87+
getResources(),
88+
new SimpleResourceChangeFilter()
89+
.filterOutAllResourcesExcept(filterOutAllResourcesExcept)
90+
.filterOutAllChangesExcept(filterOutAllChangesExcept),
91+
getReconciliationContext()
9092
);
9193
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
9294
if (list) {
@@ -111,12 +113,13 @@ private HasItems getResources() {
111113
@NotNull
112114
private ReconciliationContext getReconciliationContext() {
113115
return ReconciliationContext
114-
.builder()
115-
.dryRun(true)
116-
.configuration(configOptionsMixin.getConfiguration())
117-
.selector(selectorOptions.getResourceSelector())
118-
.labels(fileOptions.getLabels())
119-
.annotations(fileOptions.getAnnotations())
120-
.build();
116+
.builder()
117+
.dryRun(true)
118+
.configuration(configOptionsMixin.getConfiguration())
119+
.selector(selectorOptions.getResourceSelector())
120+
.labels(fileOptions.getLabels())
121+
.annotations(fileOptions.getAnnotations())
122+
.providerName(providerOptionMixin.getProvider())
123+
.build();
121124
}
122125
}

cli/src/main/java/io/streamthoughts/jikkou/client/command/PrepareCommand.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import picocli.CommandLine.Mixin;
2525

2626
@Command(name = "prepare",
27-
header = "Prepare the resource definition files for validation.",
28-
description = """
29-
Prepare the resource definition files specified through the command line arguments for validation.
30-
"""
27+
header = "Prepare the resource definition files for validation.",
28+
description = """
29+
Prepare the resource definition files specified through the command line arguments for validation.
30+
"""
3131
)
3232
@Singleton
3333
public class PrepareCommand extends CLIBaseCommand implements Callable<Integer> {
@@ -41,7 +41,8 @@ public class PrepareCommand extends CLIBaseCommand implements Callable<Integer>
4141
FormatOptionsMixin formatOptions;
4242
@Mixin
4343
ConfigOptionsMixin configOptionsMixin;
44-
44+
@Mixin
45+
ProviderOptionMixin providerOptionMixin;
4546
// API
4647
@Inject
4748
JikkouApi api;
@@ -58,8 +59,8 @@ public Integer call() throws IOException {
5859

5960
try {
6061
HasItems result = api.prepare(
61-
getResources(),
62-
getReconciliationContext()
62+
getResources(),
63+
getReconciliationContext()
6364
);
6465
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
6566
writer.write(formatOptions.format, result.getItems(), baos);
@@ -80,12 +81,13 @@ private HasItems getResources() {
8081
@NotNull
8182
private ReconciliationContext getReconciliationContext() {
8283
return ReconciliationContext
83-
.builder()
84-
.dryRun(true)
85-
.configuration(configOptionsMixin.getConfiguration())
86-
.selector(selectorOptions.getResourceSelector())
87-
.labels(fileOptions.getLabels())
88-
.annotations(fileOptions.getAnnotations())
89-
.build();
84+
.builder()
85+
.dryRun(true)
86+
.configuration(configOptionsMixin.getConfiguration())
87+
.selector(selectorOptions.getResourceSelector())
88+
.labels(fileOptions.getLabels())
89+
.annotations(fileOptions.getAnnotations())
90+
.providerName(providerOptionMixin.getProvider())
91+
.build();
9092
}
9193
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) The original authors
4+
*
5+
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
6+
*/
7+
package io.streamthoughts.jikkou.client.command;
8+
9+
import picocli.CommandLine.Option;
10+
11+
/**
12+
* Mixin class for the --provider CLI option.
13+
* Use this mixin to add provider selection support to commands that need
14+
* to target a specific provider instance when multiple providers of the
15+
* same type are configured.
16+
*/
17+
public final class ProviderOptionMixin {
18+
19+
@Option(
20+
names = {"--provider"},
21+
description = "Select a specific provider instance when multiple providers of the same type are configured (e.g., kafka-prod, kafka-dev)"
22+
)
23+
public String provider;
24+
25+
/**
26+
* Gets the provider name.
27+
*
28+
* @return the provider name, or null if not specified.
29+
*/
30+
public String getProvider() {
31+
return provider;
32+
}
33+
}

cli/src/main/java/io/streamthoughts/jikkou/client/command/action/ExecuteActionCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import io.micronaut.context.annotation.Prototype;
1010
import io.streamthoughts.jikkou.client.command.AbstractApiCommand;
11+
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
1112
import io.streamthoughts.jikkou.core.JikkouApi;
1213
import io.streamthoughts.jikkou.core.config.Configuration;
1314
import io.streamthoughts.jikkou.core.io.Jackson;
@@ -41,9 +42,11 @@ enum Format {
4142
defaultValue = "YAML",
4243
description = "Prints the output in the specified format. Allowed values: ${COMPLETION-CANDIDATES} (default YAML)."
4344
)
44-
4545
private Format format;
4646

47+
@CommandLine.Mixin
48+
ProviderOptionMixin providerMixin;
49+
4750
// Picocli require an empty constructor to generate the completion file
4851
public ExecuteActionCommand() {
4952
}
@@ -53,7 +56,7 @@ public ExecuteActionCommand() {
5356
**/
5457
@Override
5558
public Integer call() throws Exception {
56-
ApiActionResultSet<?> results = api.execute(name, Configuration.from(options()));
59+
ApiActionResultSet<?> results = api.execute(name, Configuration.from(options()), providerMixin.getProvider());
5760
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
5861
switch (format) {
5962
case JSON -> Jackson.JSON_OBJECT_MAPPER

cli/src/main/java/io/streamthoughts/jikkou/client/command/config/SetContextCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Integer call() throws IOException {
5959

6060
if (this.clientConfigPropertiesFile != null) {
6161
for (final String propertiesFile : clientConfigPropertiesFile) {
62-
if (!Strings.isBlank(propertiesFile)) {
62+
if (!Strings.isNullOrEmpty(propertiesFile)) {
6363
final String expandedPath = Paths.get(propertiesFile).toAbsolutePath().toString();
6464
try (var reader = new FileReader(expandedPath)) {
6565
clientConfigProps.load(reader);

cli/src/main/java/io/streamthoughts/jikkou/client/command/extension/ListExtensionCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class ListExtensionCommand extends CLIBaseCommand implements Runnable {
5252
@Override
5353
public void run() {
5454

55-
ApiExtensionList apiExtensions = Strings.isBlank(kind) ?
55+
ApiExtensionList apiExtensions = Strings.isNullOrEmpty(kind) ?
5656
api.getApiExtensions() : api.getApiExtensions(kind);
5757

5858
Predicate<ApiExtensionSummary> predicate = Stream.<Predicate<ApiExtensionSummary>>of(

cli/src/main/java/io/streamthoughts/jikkou/client/command/get/GetResourceCommand.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
import io.micronaut.context.annotation.Prototype;
1010
import io.streamthoughts.jikkou.client.command.AbstractApiCommand;
1111
import io.streamthoughts.jikkou.client.command.FormatOptionsMixin;
12+
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
1213
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
1314
import io.streamthoughts.jikkou.common.utils.Strings;
15+
import io.streamthoughts.jikkou.core.GetContext;
1416
import io.streamthoughts.jikkou.core.JikkouApi;
17+
import io.streamthoughts.jikkou.core.ListContext;
1518
import io.streamthoughts.jikkou.core.config.Configuration;
1619
import io.streamthoughts.jikkou.core.io.writer.ResourceWriter;
1720
import io.streamthoughts.jikkou.core.models.HasMetadata;
@@ -36,6 +39,8 @@ public class GetResourceCommand extends AbstractApiCommand {
3639
SelectorOptionsMixin selectorOptions;
3740
@Mixin
3841
FormatOptionsMixin formatOptions;
42+
@Mixin
43+
ProviderOptionMixin providerOptions;
3944
@Option(names = {"--list"},
4045
defaultValue = "false",
4146
description = "Get resources as ResourceListObject (default: ${DEFAULT-VALUE})."
@@ -68,18 +73,19 @@ public GetResourceCommand() {
6873
@Override
6974
public Integer call() throws Exception {
7075
ResourceList<HasMetadata> resources;
71-
if (Strings.isBlank(name)) {
72-
resources = api.listResources(
73-
type,
74-
selectorOptions.getResourceSelector(),
75-
Configuration.from(options())
76-
);
76+
if (Strings.isNullOrEmpty(name)) {
77+
ListContext context = ListContext.builder()
78+
.selector(selectorOptions.getResourceSelector())
79+
.configuration(Configuration.from(options()))
80+
.providerName(providerOptions.getProvider())
81+
.build();
82+
resources = api.listResources(type, context);
7783
} else {
78-
HasMetadata resource = api.getResource(
79-
type,
80-
name,
81-
Configuration.from(options())
82-
);
84+
GetContext getContext = GetContext.builder()
85+
.configuration(Configuration.from(options()))
86+
.providerName(providerOptions.getProvider())
87+
.build();
88+
HasMetadata resource = api.getResource(type, name, getContext);
8389
resources = ResourceList.of(resource);
8490
}
8591
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {

cli/src/main/java/io/streamthoughts/jikkou/client/command/health/GetHealthCommand.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package io.streamthoughts.jikkou.client.command.health;
88

99
import io.streamthoughts.jikkou.client.command.CLIBaseCommand;
10+
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
1011
import io.streamthoughts.jikkou.core.JikkouApi;
1112
import io.streamthoughts.jikkou.core.health.HealthStatus;
1213
import io.streamthoughts.jikkou.core.io.Jackson;
@@ -44,6 +45,9 @@ enum Formats { JSON, YAML }
4445
description = "Timeout in milliseconds for retrieving health indicators (default: ${DEFAULT-VALUE}).")
4546
long timeoutMs;
4647

48+
@CommandLine.Mixin
49+
ProviderOptionMixin providerMixin;
50+
4751
@Parameters(
4852
paramLabel = "HEALTH_INDICATOR",
4953
description = "Name of the health indicator (use 'all' to get all indicators).")
@@ -60,9 +64,9 @@ public Integer call() throws IOException {
6064
Duration timeout = Duration.ofMillis(timeoutMs);
6165
ApiHealthResult result;
6266
if (indicator.equalsIgnoreCase(HEALTH_INDICATOR_ALL)) {
63-
result = api.getApiHealth(timeout);
67+
result = api.getApiHealth(timeout, providerMixin.getProvider());
6468
} else {
65-
result = api.getApiHealth(indicator, timeout);
69+
result = api.getApiHealth(indicator, timeout, providerMixin.getProvider());
6670
}
6771

6872
if (result != null) {

cli/src/main/java/io/streamthoughts/jikkou/client/command/reconcile/BaseResourceCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.streamthoughts.jikkou.client.command.ConfigOptionsMixin;
1212
import io.streamthoughts.jikkou.client.command.ExecOptionsMixin;
1313
import io.streamthoughts.jikkou.client.command.FileOptionsMixin;
14+
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
1415
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
1516
import io.streamthoughts.jikkou.client.command.validate.ValidationErrorsWriter;
1617
import io.streamthoughts.jikkou.client.printer.Printers;
@@ -39,7 +40,8 @@ public abstract class BaseResourceCommand extends CLIBaseCommand implements Call
3940
SelectorOptionsMixin selectorOptions;
4041
@Mixin
4142
ConfigOptionsMixin configOptionsMixin;
42-
43+
@Mixin
44+
ProviderOptionMixin providerOptionMixin;
4345
// SERVICES
4446
@Inject
4547
JikkouApi api;
@@ -73,6 +75,7 @@ public Integer call() throws IOException {
7375
.selector(selectorOptions.getResourceSelector())
7476
.labels(fileOptions.getLabels())
7577
.annotations(fileOptions.getAnnotations())
78+
.providerName(providerOptionMixin.getProvider())
7679
.build();
7780
}
7881

cli/src/main/java/io/streamthoughts/jikkou/client/command/reconcile/PatchResourceCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.streamthoughts.jikkou.client.command.ConfigOptionsMixin;
1212
import io.streamthoughts.jikkou.client.command.ExecOptionsMixin;
1313
import io.streamthoughts.jikkou.client.command.FileOptionsMixin;
14+
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
1415
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
1516
import io.streamthoughts.jikkou.client.command.validate.ValidationErrorsWriter;
1617
import io.streamthoughts.jikkou.core.JikkouApi;
@@ -46,6 +47,8 @@ public final class PatchResourceCommand extends CLIBaseCommand implements Callab
4647
SelectorOptionsMixin selectorOptions;
4748
@Mixin
4849
ConfigOptionsMixin configOptionsMixin;
50+
@Mixin
51+
ProviderOptionMixin providerOptionMixin;
4952

5053
@Option(names = {"--mode"},
5154
required = true,
@@ -86,6 +89,7 @@ public Integer call() throws IOException {
8689
.selector(selectorOptions.getResourceSelector())
8790
.labels(fileOptions.getLabels())
8891
.annotations(fileOptions.getAnnotations())
92+
.providerName(providerOptionMixin.getProvider())
8993
.build();
9094
}
9195

0 commit comments

Comments
 (0)