You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/07/14 09:48:53 UTC

[camel] branch main updated (ec2269d7e56 -> 38b76ffda14)

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

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from ec2269d7e56 (chores) camel-core: file test fixes and cleanups
     new 4c412ddbf27 CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang.
     new 38b76ffda14 CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/main/BaseMainSupport.java     | 32 +--------
 .../camel/main/DefaultConfigurationConfigurer.java | 77 +++++++++++++++++++++-
 2 files changed, 77 insertions(+), 32 deletions(-)


[camel] 01/02: CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 4c412ddbf27a707cf04192143768617b02ee2816
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 14 11:11:44 2023 +0200

    CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang.
---
 .../org/apache/camel/main/BaseMainSupport.java     | 24 --------
 .../camel/main/DefaultConfigurationConfigurer.java | 72 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 24 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 300d10a29a4..79b4804d40f 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -384,28 +384,6 @@ public abstract class BaseMainSupport extends BaseService {
     protected void configureLifecycle(CamelContext camelContext) throws Exception {
     }
 
-    /**
-     * Configures security vaults such as AWS, Azure, Google and Hashicorp.
-     */
-    protected void configureVault(CamelContext camelContext) throws Exception {
-        VaultConfiguration vc = camelContext.getVaultConfiguration();
-        if (vc == null) {
-            return;
-        }
-
-        if (vc.aws().isRefreshEnabled()) {
-            scheduleRefresh(camelContext, "aws-secret-refresh", vc.aws().getRefreshPeriod());
-        }
-
-        if (vc.gcp().isRefreshEnabled()) {
-            scheduleRefresh(camelContext, "gcp-secret-refresh", vc.gcp().getRefreshPeriod());
-        }
-
-        if (vc.azure().isRefreshEnabled()) {
-            scheduleRefresh(camelContext, "azure-secret-refresh", vc.azure().getRefreshPeriod());
-        }
-    }
-
     private void scheduleRefresh(CamelContext camelContext, String key, long period) throws Exception {
         final Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext)
                 .newInstance(key, Runnable.class);
@@ -643,8 +621,6 @@ public abstract class BaseMainSupport extends BaseService {
 
         configureLifecycle(camelContext);
 
-        configureVault(camelContext);
-
         if (standalone) {
             step = recorder.beginStep(BaseMainSupport.class, "configureRoutes", "Collect Routes");
             configureRoutes(camelContext);
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index 753971d76c8..d8fc0d5f117 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -19,6 +19,7 @@ package org.apache.camel.main;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.function.Predicate;
@@ -62,6 +63,7 @@ import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.MessageHistoryFactory;
 import org.apache.camel.spi.ModelJAXBContextFactory;
 import org.apache.camel.spi.NodeIdFactory;
+import org.apache.camel.spi.PeriodTaskScheduler;
 import org.apache.camel.spi.ProcessorFactory;
 import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.ReactiveExecutor;
@@ -88,6 +90,7 @@ import org.apache.camel.support.SimpleUuidGenerator;
 import org.apache.camel.support.jsse.GlobalSSLContextParametersSupplier;
 import org.apache.camel.support.startup.LoggingStartupStepRecorder;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.TimeUtils;
 import org.apache.camel.vault.AwsVaultConfiguration;
 import org.apache.camel.vault.AzureVaultConfiguration;
 import org.apache.camel.vault.GcpVaultConfiguration;
@@ -598,10 +601,79 @@ public final class DefaultConfigurationConfigurer {
             VaultConfiguration vault = camelContext.getVaultConfiguration();
             vault.setHashicorpVaultConfiguration(hashicorp);
         }
+        configureVault(camelContext);
+
         // set the default thread pool profile if defined
         initThreadPoolProfiles(registry, camelContext);
     }
 
+    /**
+     * Configures security vaults such as AWS, Azure, Google and Hashicorp.
+     */
+    protected static void configureVault(CamelContext camelContext) throws Exception {
+        VaultConfiguration vc = camelContext.getVaultConfiguration();
+        if (vc == null) {
+            return;
+        }
+
+        if (vc.aws().isRefreshEnabled()) {
+            Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext)
+                    .newInstance("aws-secret-refresh", Runnable.class);
+            if (task.isPresent()) {
+                long period = vc.aws().getRefreshPeriod();
+                Runnable r = task.get();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false));
+                }
+                if (camelContext.hasService(ContextReloadStrategy.class) == null) {
+                    // refresh is enabled then we need to automatically enable context-reload as well
+                    ContextReloadStrategy reloader = new DefaultContextReloadStrategy();
+                    camelContext.addService(reloader);
+                }
+                PeriodTaskScheduler scheduler = PluginHelper.getPeriodTaskScheduler(camelContext);
+                scheduler.schedulePeriodTask(r, period);
+            }
+        }
+
+        if (vc.gcp().isRefreshEnabled()) {
+            Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext)
+                    .newInstance("gcp-secret-refresh", Runnable.class);
+            if (task.isPresent()) {
+                long period = vc.gcp().getRefreshPeriod();
+                Runnable r = task.get();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false));
+                }
+                if (camelContext.hasService(ContextReloadStrategy.class) == null) {
+                    // refresh is enabled then we need to automatically enable context-reload as well
+                    ContextReloadStrategy reloader = new DefaultContextReloadStrategy();
+                    camelContext.addService(reloader);
+                }
+                PeriodTaskScheduler scheduler = PluginHelper.getPeriodTaskScheduler(camelContext);
+                scheduler.schedulePeriodTask(r, period);
+            }
+        }
+
+        if (vc.azure().isRefreshEnabled()) {
+            Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext)
+                    .newInstance("azure-secret-refresh", Runnable.class);
+            if (task.isPresent()) {
+                long period = vc.azure().getRefreshPeriod();
+                Runnable r = task.get();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false));
+                }
+                if (camelContext.hasService(ContextReloadStrategy.class) == null) {
+                    // refresh is enabled then we need to automatically enable context-reload as well
+                    ContextReloadStrategy reloader = new DefaultContextReloadStrategy();
+                    camelContext.addService(reloader);
+                }
+                PeriodTaskScheduler scheduler = PluginHelper.getPeriodTaskScheduler(camelContext);
+                scheduler.schedulePeriodTask(r, period);
+            }
+        }
+    }
+
     public static void afterPropertiesSet(final CamelContext camelContext) throws Exception {
         // additional configuration
     }


[camel] 02/02: CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 38b76ffda147c8f5dc769f471db86591cf98a436
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 14 11:48:10 2023 +0200

    CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang.
---
 .../src/main/java/org/apache/camel/main/BaseMainSupport.java      | 8 ++------
 .../org/apache/camel/main/DefaultConfigurationConfigurer.java     | 7 ++++---
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 79b4804d40f..4e215c46c54 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -1132,14 +1132,13 @@ public abstract class BaseMainSupport extends BaseService {
 
         // and call after all properties are set
         DefaultConfigurationConfigurer.afterPropertiesSet(camelContext);
+        // and configure vault
+        DefaultConfigurationConfigurer.configureVault(camelContext);
     }
 
     /**
      * Main implementation may do some additional configuration of the {@link Registry} before it's used to
      * (re)configure Camel context.
-     *
-     * @param camelContext
-     * @param config
      */
     protected void preProcessCamelRegistry(CamelContext camelContext, MainConfigurationProperties config) {
     }
@@ -1147,9 +1146,6 @@ public abstract class BaseMainSupport extends BaseService {
     /**
      * Main implementation may do some additional configuration of the {@link Registry} after loading the routes, but
      * before the routes are started.
-     *
-     * @param camelContext
-     * @param config
      */
     protected void postProcessCamelRegistry(CamelContext camelContext, MainConfigurationProperties config) {
     }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index d8fc0d5f117..28e9254e496 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -580,6 +580,10 @@ public final class DefaultConfigurationConfigurer {
                 devConsoleRegistry.register(console);
             }
         }
+
+        // set the default thread pool profile if defined
+        initThreadPoolProfiles(registry, camelContext);
+
         // vaults
         AwsVaultConfiguration aws = getSingleBeanOfType(registry, AwsVaultConfiguration.class);
         if (aws != null) {
@@ -602,9 +606,6 @@ public final class DefaultConfigurationConfigurer {
             vault.setHashicorpVaultConfiguration(hashicorp);
         }
         configureVault(camelContext);
-
-        // set the default thread pool profile if defined
-        initThreadPoolProfiles(registry, camelContext);
     }
 
     /**