Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import picocli.CommandLine.Option;

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

Expand All @@ -47,22 +47,24 @@ public class DiffCommand extends CLIBaseCommand implements Callable<Integer> {
FormatOptionsMixin formatOptions;
@Mixin
ConfigOptionsMixin configOptionsMixin;
@Mixin
ProviderOptionMixin providerOptionMixin;

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

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

@Option(names = {"--list"},
defaultValue = "false",
description = "Get resources as ApiResourceChangeList (default: ${DEFAULT-VALUE})."
defaultValue = "false",
description = "Get resources as ApiResourceChangeList (default: ${DEFAULT-VALUE})."
)
private boolean list;

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

try {
ApiResourceChangeList result = api.getDiff(
getResources(),
new SimpleResourceChangeFilter()
.filterOutAllResourcesExcept(filterOutAllResourcesExcept)
.filterOutAllChangesExcept(filterOutAllChangesExcept),
getReconciliationContext()
getResources(),
new SimpleResourceChangeFilter()
.filterOutAllResourcesExcept(filterOutAllResourcesExcept)
.filterOutAllChangesExcept(filterOutAllChangesExcept),
getReconciliationContext()
);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
if (list) {
Expand All @@ -111,12 +113,13 @@ private HasItems getResources() {
@NotNull
private ReconciliationContext getReconciliationContext() {
return ReconciliationContext
.builder()
.dryRun(true)
.configuration(configOptionsMixin.getConfiguration())
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.build();
.builder()
.dryRun(true)
.configuration(configOptionsMixin.getConfiguration())
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.providerName(providerOptionMixin.getProvider())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import picocli.CommandLine.Mixin;

@Command(name = "prepare",
header = "Prepare the resource definition files for validation.",
description = """
Prepare the resource definition files specified through the command line arguments for validation.
"""
header = "Prepare the resource definition files for validation.",
description = """
Prepare the resource definition files specified through the command line arguments for validation.
"""
)
@Singleton
public class PrepareCommand extends CLIBaseCommand implements Callable<Integer> {
Expand All @@ -41,7 +41,8 @@ public class PrepareCommand extends CLIBaseCommand implements Callable<Integer>
FormatOptionsMixin formatOptions;
@Mixin
ConfigOptionsMixin configOptionsMixin;

@Mixin
ProviderOptionMixin providerOptionMixin;
// API
@Inject
JikkouApi api;
Expand All @@ -58,8 +59,8 @@ public Integer call() throws IOException {

try {
HasItems result = api.prepare(
getResources(),
getReconciliationContext()
getResources(),
getReconciliationContext()
);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
writer.write(formatOptions.format, result.getItems(), baos);
Expand All @@ -80,12 +81,13 @@ private HasItems getResources() {
@NotNull
private ReconciliationContext getReconciliationContext() {
return ReconciliationContext
.builder()
.dryRun(true)
.configuration(configOptionsMixin.getConfiguration())
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.build();
.builder()
.dryRun(true)
.configuration(configOptionsMixin.getConfiguration())
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.providerName(providerOptionMixin.getProvider())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) The original authors
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.streamthoughts.jikkou.client.command;

import picocli.CommandLine.Option;

/**
* Mixin class for the --provider CLI option.
* Use this mixin to add provider selection support to commands that need
* to target a specific provider instance when multiple providers of the
* same type are configured.
*/
public final class ProviderOptionMixin {

@Option(
names = {"--provider"},
description = "Select a specific provider instance when multiple providers of the same type are configured (e.g., kafka-prod, kafka-dev)"
)
public String provider;

/**
* Gets the provider name.
*
* @return the provider name, or null if not specified.
*/
public String getProvider() {
return provider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import io.micronaut.context.annotation.Prototype;
import io.streamthoughts.jikkou.client.command.AbstractApiCommand;
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
import io.streamthoughts.jikkou.core.JikkouApi;
import io.streamthoughts.jikkou.core.config.Configuration;
import io.streamthoughts.jikkou.core.io.Jackson;
Expand Down Expand Up @@ -41,9 +42,11 @@ enum Format {
defaultValue = "YAML",
description = "Prints the output in the specified format. Allowed values: ${COMPLETION-CANDIDATES} (default YAML)."
)

private Format format;

@CommandLine.Mixin
ProviderOptionMixin providerMixin;

// Picocli require an empty constructor to generate the completion file
public ExecuteActionCommand() {
}
Expand All @@ -53,7 +56,7 @@ public ExecuteActionCommand() {
**/
@Override
public Integer call() throws Exception {
ApiActionResultSet<?> results = api.execute(name, Configuration.from(options()));
ApiActionResultSet<?> results = api.execute(name, Configuration.from(options()), providerMixin.getProvider());
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
switch (format) {
case JSON -> Jackson.JSON_OBJECT_MAPPER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Integer call() throws IOException {

if (this.clientConfigPropertiesFile != null) {
for (final String propertiesFile : clientConfigPropertiesFile) {
if (!Strings.isBlank(propertiesFile)) {
if (!Strings.isNullOrEmpty(propertiesFile)) {
final String expandedPath = Paths.get(propertiesFile).toAbsolutePath().toString();
try (var reader = new FileReader(expandedPath)) {
clientConfigProps.load(reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ListExtensionCommand extends CLIBaseCommand implements Runnable {
@Override
public void run() {

ApiExtensionList apiExtensions = Strings.isBlank(kind) ?
ApiExtensionList apiExtensions = Strings.isNullOrEmpty(kind) ?
api.getApiExtensions() : api.getApiExtensions(kind);

Predicate<ApiExtensionSummary> predicate = Stream.<Predicate<ApiExtensionSummary>>of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import io.micronaut.context.annotation.Prototype;
import io.streamthoughts.jikkou.client.command.AbstractApiCommand;
import io.streamthoughts.jikkou.client.command.FormatOptionsMixin;
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
import io.streamthoughts.jikkou.common.utils.Strings;
import io.streamthoughts.jikkou.core.GetContext;
import io.streamthoughts.jikkou.core.JikkouApi;
import io.streamthoughts.jikkou.core.ListContext;
import io.streamthoughts.jikkou.core.config.Configuration;
import io.streamthoughts.jikkou.core.io.writer.ResourceWriter;
import io.streamthoughts.jikkou.core.models.HasMetadata;
Expand All @@ -36,6 +39,8 @@ public class GetResourceCommand extends AbstractApiCommand {
SelectorOptionsMixin selectorOptions;
@Mixin
FormatOptionsMixin formatOptions;
@Mixin
ProviderOptionMixin providerOptions;
@Option(names = {"--list"},
defaultValue = "false",
description = "Get resources as ResourceListObject (default: ${DEFAULT-VALUE})."
Expand Down Expand Up @@ -68,18 +73,19 @@ public GetResourceCommand() {
@Override
public Integer call() throws Exception {
ResourceList<HasMetadata> resources;
if (Strings.isBlank(name)) {
resources = api.listResources(
type,
selectorOptions.getResourceSelector(),
Configuration.from(options())
);
if (Strings.isNullOrEmpty(name)) {
ListContext context = ListContext.builder()
.selector(selectorOptions.getResourceSelector())
.configuration(Configuration.from(options()))
.providerName(providerOptions.getProvider())
.build();
resources = api.listResources(type, context);
} else {
HasMetadata resource = api.getResource(
type,
name,
Configuration.from(options())
);
GetContext getContext = GetContext.builder()
.configuration(Configuration.from(options()))
.providerName(providerOptions.getProvider())
.build();
HasMetadata resource = api.getResource(type, name, getContext);
resources = ResourceList.of(resource);
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package io.streamthoughts.jikkou.client.command.health;

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

@CommandLine.Mixin
ProviderOptionMixin providerMixin;

@Parameters(
paramLabel = "HEALTH_INDICATOR",
description = "Name of the health indicator (use 'all' to get all indicators).")
Expand All @@ -60,9 +64,9 @@ public Integer call() throws IOException {
Duration timeout = Duration.ofMillis(timeoutMs);
ApiHealthResult result;
if (indicator.equalsIgnoreCase(HEALTH_INDICATOR_ALL)) {
result = api.getApiHealth(timeout);
result = api.getApiHealth(timeout, providerMixin.getProvider());
} else {
result = api.getApiHealth(indicator, timeout);
result = api.getApiHealth(indicator, timeout, providerMixin.getProvider());
}

if (result != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.streamthoughts.jikkou.client.command.ConfigOptionsMixin;
import io.streamthoughts.jikkou.client.command.ExecOptionsMixin;
import io.streamthoughts.jikkou.client.command.FileOptionsMixin;
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
import io.streamthoughts.jikkou.client.command.validate.ValidationErrorsWriter;
import io.streamthoughts.jikkou.client.printer.Printers;
Expand Down Expand Up @@ -39,7 +40,8 @@ public abstract class BaseResourceCommand extends CLIBaseCommand implements Call
SelectorOptionsMixin selectorOptions;
@Mixin
ConfigOptionsMixin configOptionsMixin;

@Mixin
ProviderOptionMixin providerOptionMixin;
// SERVICES
@Inject
JikkouApi api;
Expand Down Expand Up @@ -73,6 +75,7 @@ public Integer call() throws IOException {
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.providerName(providerOptionMixin.getProvider())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.streamthoughts.jikkou.client.command.ConfigOptionsMixin;
import io.streamthoughts.jikkou.client.command.ExecOptionsMixin;
import io.streamthoughts.jikkou.client.command.FileOptionsMixin;
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
import io.streamthoughts.jikkou.client.command.validate.ValidationErrorsWriter;
import io.streamthoughts.jikkou.core.JikkouApi;
Expand Down Expand Up @@ -46,6 +47,8 @@ public final class PatchResourceCommand extends CLIBaseCommand implements Callab
SelectorOptionsMixin selectorOptions;
@Mixin
ConfigOptionsMixin configOptionsMixin;
@Mixin
ProviderOptionMixin providerOptionMixin;

@Option(names = {"--mode"},
required = true,
Expand Down Expand Up @@ -86,6 +89,7 @@ public Integer call() throws IOException {
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.providerName(providerOptionMixin.getProvider())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.streamthoughts.jikkou.client.command.ConfigOptionsMixin;
import io.streamthoughts.jikkou.client.command.ExecOptionsMixin;
import io.streamthoughts.jikkou.client.command.FileOptionsMixin;
import io.streamthoughts.jikkou.client.command.ProviderOptionMixin;
import io.streamthoughts.jikkou.client.command.SelectorOptionsMixin;
import io.streamthoughts.jikkou.client.command.validate.ValidationErrorsWriter;
import io.streamthoughts.jikkou.core.JikkouApi;
Expand Down Expand Up @@ -45,7 +46,8 @@ public final class ReplaceResourceCommand extends CLIBaseCommand implements Call
SelectorOptionsMixin selectorOptions;
@Mixin
ConfigOptionsMixin configOptionsMixin;

@Mixin
ProviderOptionMixin providerOptionMixin;
// SERVICES
@Inject
JikkouApi api;
Expand Down Expand Up @@ -76,6 +78,7 @@ public Integer call() throws IOException {
.selector(selectorOptions.getResourceSelector())
.labels(fileOptions.getLabels())
.annotations(fileOptions.getAnnotations())
.providerName(providerOptionMixin.getProvider())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setVerbs(List<String> verbs) {
**/
@Override
public void run() {
List<ApiResourceList> apiResourceLists = Strings.isBlank(group) ?
List<ApiResourceList> apiResourceLists = Strings.isNullOrEmpty(group) ?
api.listApiResources() :
api.listApiResources(group);

Expand Down
Loading
Loading