You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gh...@apache.org on 2021/12/17 13:50:04 UTC

[felix-dev] branch master updated: FELIX-6345 Ensure gogo commands hc:[list|exec] work for health check names as well

This is an automated email from the ASF dual-hosted git repository.

ghenzler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new e796f65  FELIX-6345 Ensure gogo commands hc:[list|exec] work for health check names as well
e796f65 is described below

commit e796f65168ba2d85d2c0ab6b733f5f4ac8f1b58e
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Fri Dec 17 14:49:36 2021 +0100

    FELIX-6345 Ensure gogo commands hc:[list|exec] work for health check
    names as well
---
 .../hc/core/impl/commands/HealthCheckExecCommand.java  | 18 ++++++++++++------
 .../hc/core/impl/commands/HealthCheckListCommand.java  |  2 +-
 .../hc/core/impl/executor/HealthCheckExecutorImpl.java |  2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckExecCommand.java b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckExecCommand.java
index 8ac9e63..2b7b1e9 100644
--- a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckExecCommand.java
+++ b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckExecCommand.java
@@ -49,6 +49,7 @@ public class HealthCheckExecCommand {
 
         boolean isDebug = false;
         boolean combineWithOr = true;
+        boolean isName = false;
         HealthCheckSelector selector = HealthCheckSelector.empty();
         for (String param : params) {
             if(param.startsWith("-")) {
@@ -56,27 +57,32 @@ public class HealthCheckExecCommand {
                     isDebug = true;
                 } else if("-a".equals(param)) {
                     combineWithOr = false;
+                } else if("-n".equals(param)) {
+                    isName = true;
                 } else if("-h".equals(param)) {
                     return getHelpText();
                 } else {
                     System.out.println("unrecognized option: "+param);
                 }
             } else {
-                selector = HealthCheckSelector.tags(param.split(","));
+                if(isName) {
+                    selector = selector.withNames(param.split(","));
+                } else {
+                    selector = selector.withTags(param.split(","));
+                }
             }
         }
-        if(selector.tags() == null) {
-            return getHelpText();
-        }
         
+        boolean defaultTagUsed = selector.tags() == null && selector.names() == null;
+
         HealthCheckExecutionOptions options = new HealthCheckExecutionOptions();
         options.setCombineTagsWithOr(combineWithOr);
         List<HealthCheckExecutionResult> executionResult = healthCheckExecutor.execute(selector, options);
         String result = resultTxtVerboseSerializer.serialize(new CompositeResult(new FormattingResultLog(), executionResult), executionResult, isDebug);
-        return result;
+        return (defaultTagUsed ? "Configured default tag used for execution\n" : "") + result;
     }
 
     private String getHelpText() {
-        return "Usage: hc:exec [-v] [-a] tag1,tag2\n  -v verbose/debug\n  -a combine tags with and";
+        return "Usage:\n  hc:exec [-v] [-a] [tag1,tag2] [-n \"Name 1,Name 2\"]\n  -v verbose/debug\n  -a combine tags with 'and' logic\n  -n name(s) to be executed";
     }
 }
diff --git a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckListCommand.java b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckListCommand.java
index e0db165..407153d 100644
--- a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckListCommand.java
+++ b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/commands/HealthCheckListCommand.java
@@ -64,7 +64,7 @@ public class HealthCheckListCommand {
         }
 
         HealthCheckFilter hcFilter = new HealthCheckFilter(bundleContext);
-        HealthCheckSelector selector = HealthCheckSelector.tags("*");
+        HealthCheckSelector selector = HealthCheckSelector.empty();
 
         ServiceReference<HealthCheck>[] hcRefs = hcFilter.getHealthCheckServiceReferences(selector);
         Stream<ServiceReference<HealthCheck>> hcRefsStream = Arrays.asList(hcRefs).stream();
diff --git a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
index c509dda..9702626 100644
--- a/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
+++ b/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/executor/HealthCheckExecutorImpl.java
@@ -172,7 +172,7 @@ public class HealthCheckExecutorImpl implements ExtendedHealthCheckExecutor, Ser
     public List<HealthCheckExecutionResult> execute(HealthCheckSelector selector, HealthCheckExecutionOptions options) {
         logger.debug("Starting executing checks for filter selector {} and execution options {}", selector, options);
 
-        if (selector.tags() == null || selector.tags().length == 0) {
+        if ((selector.names() == null || selector.names().length == 0) && (selector.tags() == null || selector.tags().length == 0)) {
             logger.debug("Using default tags");
             selector.withTags(defaultTags);
         }