This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch unomi-3-dev
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/unomi-3-dev by this push:
new 8c4058f09 UNOMI-919 Enhance Unomi setup command and distribution
management
8c4058f09 is described below
commit 8c4058f0914685bff5b60bd7985bd992eb278260
Author: Serge Huber <[email protected]>
AuthorDate: Thu Jan 15 18:21:53 2026 +0100
UNOMI-919 Enhance Unomi setup command and distribution management
- Updated the `setup` command to allow optional distribution configuration
and added a `--show` flag to display the currently configured distribution.
- Introduced a new `DistributionCompleter` to provide auto-completion for
available distribution features.
- Added a method in `UnomiManagementService` to retrieve the currently
configured distribution.
- Modified `build.sh` to ensure `UNOMI_DISTRIBUTION` is only initialized if
not already set.
---
build.sh | 6 +-
.../java/org/apache/unomi/shell/actions/Setup.java | 27 ++++++-
.../shell/completers/DistributionCompleter.java | 86 ++++++++++++++++++++++
.../shell/services/UnomiManagementService.java | 7 ++
.../internal/UnomiManagementServiceImpl.java | 6 ++
5 files changed, 129 insertions(+), 3 deletions(-)
diff --git a/build.sh b/build.sh
index 0cfdc7df3..bf0d372fb 100755
--- a/build.sh
+++ b/build.sh
@@ -254,7 +254,11 @@ KARAF_DEBUG_SUSPEND=n
USE_OPENSEARCH=false
NO_KARAF=false
AUTO_START=""
-UNOMI_DISTRIBUTION=""
+# Only initialize UNOMI_DISTRIBUTION if not already set (e.g., by
setup-opensearch.sh or setup-elasticsearch.sh)
+# This preserves the environment variable if it was set by the setup scripts
+if [ -z "${UNOMI_DISTRIBUTION+x}" ]; then
+ UNOMI_DISTRIBUTION=""
+fi
SINGLE_TEST=""
IT_DEBUG=false
IT_DEBUG_PORT=5006
diff --git
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/actions/Setup.java
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/actions/Setup.java
index 9d4c3acd8..1c3c43ab9 100644
---
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/actions/Setup.java
+++
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/actions/Setup.java
@@ -18,9 +18,11 @@ package org.apache.unomi.shell.actions;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.unomi.shell.completers.DistributionCompleter;
import org.apache.unomi.shell.services.UnomiManagementService;
@Command(scope = "unomi", name = "setup", description = "This will setup some
Apache Unomi runtime options")
@@ -30,13 +32,34 @@ public class Setup implements Action {
@Reference
UnomiManagementService unomiManagementService;
- @Option(name = "-d", aliases = "--distribution", description = "Unomi
Distribution feature to configure", required = true, multiValued = false)
- String distribution = "unomi-distribution-elasticsearch";
+ @Option(name = "-d", aliases = "--distribution", description = "Unomi
Distribution feature to configure", required = false, valueToShowInHelp =
"unomi-distribution-elasticsearch")
+ @Completion(DistributionCompleter.class)
+ String distribution;
@Option(name = "-f", aliases = "--force", description = "Force setting up
distribution feature name even if already exists (use with caution)", required
= false, multiValued = false)
boolean force = false;
+ @Option(name = "-s", aliases = "--show", description = "Show the currently
configured distribution", required = false, multiValued = false)
+ boolean show = false;
+
public Object execute() throws Exception {
+ if (show) {
+ String currentDistribution =
unomiManagementService.getCurrentDistribution();
+ if (currentDistribution != null) {
+ System.out.println("Currently configured distribution: " +
currentDistribution);
+ } else {
+ System.out.println("No distribution is currently configured.");
+ }
+ return null;
+ }
+
+ if (distribution == null || distribution.isEmpty()) {
+ System.err.println("Error: Distribution option is required when
not using --show flag.");
+ System.err.println("Usage: unomi:setup -d <distribution> [-f]");
+ System.err.println(" or: unomi:setup --show");
+ return null;
+ }
+
System.out.println("Setting up Apache Unomi distribution: " +
distribution);
unomiManagementService.setupUnomiDistribution(distribution, force);
return null;
diff --git
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/completers/DistributionCompleter.java
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/completers/DistributionCompleter.java
new file mode 100644
index 000000000..8ec62e95a
--- /dev/null
+++
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/completers/DistributionCompleter.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.completers;
+
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.features.Repository;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+import java.util.Arrays;
+import java.util.List;
+
+@Service
+public class DistributionCompleter implements Completer {
+
+ @Reference
+ private FeaturesService featuresService;
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String>
candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+
+ try {
+ // Get all repositories and their features
+ Repository[] repositories = featuresService.listRepositories();
+ for (Repository repository : repositories) {
+ try {
+ Feature[] features = repository.getFeatures();
+ for (Feature feature : features) {
+ String featureName = feature.getName();
+ // Filter features starting with unomi-distribution-*
+ if (featureName != null &&
featureName.startsWith("unomi-distribution-")) {
+ delegate.getStrings().add(featureName);
+ }
+ }
+ } catch (Exception e) {
+ // Skip repositories that can't be accessed
+ // This is normal for some repositories
+ }
+ }
+
+ // If no features found from repositories, try to get known
distributions by name
+ if (delegate.getStrings().isEmpty()) {
+ String[] knownDistributions = {
+ "unomi-distribution-elasticsearch",
+ "unomi-distribution-opensearch"
+ };
+ for (String dist : knownDistributions) {
+ try {
+ Feature feature = featuresService.getFeature(dist);
+ if (feature != null) {
+ delegate.getStrings().add(dist);
+ }
+ } catch (Exception e) {
+ // Feature doesn't exist, skip it
+ }
+ }
+ }
+ } catch (Exception e) {
+ // If we can't list repositories, fall back to common distribution
names
+ delegate.getStrings().add("unomi-distribution-elasticsearch");
+ delegate.getStrings().add("unomi-distribution-opensearch");
+ }
+
+ return delegate.complete(session, commandLine, candidates);
+ }
+}
diff --git
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/UnomiManagementService.java
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/UnomiManagementService.java
index de7635153..4204b0f44 100644
---
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/UnomiManagementService.java
+++
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/UnomiManagementService.java
@@ -60,4 +60,11 @@ public interface UnomiManagementService {
* @throws Exception if there was an error stopping Unomi's bundles
*/
void stopUnomi(boolean waitForCompletion) throws Exception;
+
+ /**
+ * This method will get the currently configured distribution
+ * @return the distribution feature name, or null if no distribution is
configured
+ * @throws Exception if there was an error retrieving the distribution
+ */
+ String getCurrentDistribution() throws Exception;
}
diff --git
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
index 5c94eef60..85eeefe32 100644
---
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
+++
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/services/internal/UnomiManagementServiceImpl.java
@@ -333,6 +333,12 @@ public class UnomiManagementServiceImpl implements
UnomiManagementService {
}
}
+ @Override
+ public String getCurrentDistribution() throws Exception {
+ UnomiSetup setup = getUnomiSetup();
+ return setup != null ? setup.getDistribution() : null;
+ }
+
@Deactivate
public void deactivate() {
executor.shutdown();