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 2020/11/03 10:00:59 UTC
[camel] branch master updated: CAMEL-15795: camel-core - Reduce
tangle from impl engine to model
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 64c3637 CAMEL-15795: camel-core - Reduce tangle from impl engine to model
64c3637 is described below
commit 64c36378ea244963149fc53ad2427ecd4b73e293
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 3 11:00:36 2020 +0100
CAMEL-15795: camel-core - Reduce tangle from impl engine to model
---
.../org/apache/camel/main/BaseMainSupport.java | 54 +-----------
.../camel/main/MainSupportModelConfigurer.java | 96 ++++++++++++++++++++++
2 files changed, 100 insertions(+), 50 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 dd96566..87b0c8a 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
@@ -47,10 +47,6 @@ import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckConfiguration;
import org.apache.camel.health.HealthCheckRegistry;
import org.apache.camel.health.HealthCheckRepository;
-import org.apache.camel.model.FaultToleranceConfigurationDefinition;
-import org.apache.camel.model.HystrixConfigurationDefinition;
-import org.apache.camel.model.ModelCamelContext;
-import org.apache.camel.model.Resilience4jConfigurationDefinition;
import org.apache.camel.saga.CamelSagaService;
import org.apache.camel.spi.CamelBeanPostProcessor;
import org.apache.camel.spi.DataFormat;
@@ -208,7 +204,6 @@ public abstract class BaseMainSupport extends BaseService {
*
* @param key the property key
* @param value the property value
- *
* @see #addInitialProperty(String, String)
* @see #addOverrideProperty(String, String)
*/
@@ -702,8 +697,6 @@ public abstract class BaseMainSupport extends BaseService {
}
}
- ModelCamelContext model = camelContext.adapt(ModelCamelContext.class);
-
// create beans first as they may be used later
if (!beansProperties.isEmpty()) {
LOG.debug("Creating and binding beans to registry from loaded properties: {}", beansProperties.size());
@@ -716,49 +709,6 @@ public abstract class BaseMainSupport extends BaseService {
mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
}
- if (!hystrixProperties.isEmpty()) {
- HystrixConfigurationProperties hystrix = mainConfigurationProperties.hystrix();
- LOG.debug("Auto-configuring Hystrix Circuit Breaker EIP from loaded properties: {}", hystrixProperties.size());
- setPropertiesOnTarget(camelContext, hystrix, hystrixProperties, "camel.hystrix.",
- mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
- HystrixConfigurationDefinition hystrixModel = model.getHystrixConfiguration(null);
- if (hystrixModel == null) {
- hystrixModel = new HystrixConfigurationDefinition();
- model.setHystrixConfiguration(hystrixModel);
- }
- if (hystrix != null) {
- setPropertiesOnTarget(camelContext, hystrixModel, hystrix);
- }
- }
-
- if (!resilience4jProperties.isEmpty()) {
- Resilience4jConfigurationProperties resilience4j = mainConfigurationProperties.resilience4j();
- LOG.debug("Auto-configuring Resilience4j Circuit Breaker EIP from loaded properties: {}",
- resilience4jProperties.size());
- setPropertiesOnTarget(camelContext, resilience4j, resilience4jProperties, "camel.resilience4j.",
- mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
- Resilience4jConfigurationDefinition resilience4jModel = model.getResilience4jConfiguration(null);
- if (resilience4jModel == null) {
- resilience4jModel = new Resilience4jConfigurationDefinition();
- model.setResilience4jConfiguration(resilience4jModel);
- }
- setPropertiesOnTarget(camelContext, resilience4jModel, resilience4j);
- }
-
- if (!faultToleranceProperties.isEmpty()) {
- FaultToleranceConfigurationProperties faultTolerance = mainConfigurationProperties.faultTolerance();
- LOG.debug("Auto-configuring MicroProfile Fault Tolerance Circuit Breaker EIP from loaded properties: {}",
- faultToleranceProperties.size());
- setPropertiesOnTarget(camelContext, faultTolerance, faultToleranceProperties, "camel.faulttolerance.",
- mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
- FaultToleranceConfigurationDefinition faultToleranceModel = model.getFaultToleranceConfiguration(null);
- if (faultToleranceModel == null) {
- faultToleranceModel = new FaultToleranceConfigurationDefinition();
- model.setFaultToleranceConfiguration(faultToleranceModel);
- }
- setPropertiesOnTarget(camelContext, faultToleranceModel, faultTolerance);
- }
-
if (!restProperties.isEmpty()) {
RestConfigurationProperties rest = mainConfigurationProperties.rest();
LOG.debug("Auto-configuring Rest DSL from loaded properties: {}", restProperties.size());
@@ -788,6 +738,10 @@ public abstract class BaseMainSupport extends BaseService {
autoConfiguredProperties);
}
+ // configure which requires access to the model
+ MainSupportModelConfigurer.configureModelCamelContext(camelContext, mainConfigurationProperties,
+ autoConfiguredProperties, hystrixProperties, resilience4jProperties, faultToleranceProperties);
+
// log which options was not set
if (!beansProperties.isEmpty()) {
beansProperties.forEach((k, v) -> {
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java
new file mode 100644
index 0000000..d316909
--- /dev/null
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupportModelConfigurer.java
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.main;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.FaultToleranceConfigurationDefinition;
+import org.apache.camel.model.HystrixConfigurationDefinition;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.Resilience4jConfigurationDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.camel.main.MainHelper.setPropertiesOnTarget;
+
+/**
+ * Used for configuring that requires access to the model.
+ */
+public final class MainSupportModelConfigurer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MainSupportModelConfigurer.class);
+
+ private MainSupportModelConfigurer() {
+ }
+
+ static void configureModelCamelContext(
+ CamelContext camelContext,
+ MainConfigurationProperties mainConfigurationProperties,
+ Map<String, String> autoConfiguredProperties,
+ Map<String, Object> hystrixProperties,
+ Map<String, Object> resilience4jProperties,
+ Map<String, Object> faultToleranceProperties)
+ throws Exception {
+
+ ModelCamelContext model = camelContext.adapt(ModelCamelContext.class);
+
+ if (!hystrixProperties.isEmpty()) {
+ HystrixConfigurationProperties hystrix = mainConfigurationProperties.hystrix();
+ LOG.debug("Auto-configuring Hystrix Circuit Breaker EIP from loaded properties: {}", hystrixProperties.size());
+ setPropertiesOnTarget(camelContext, hystrix, hystrixProperties, "camel.hystrix.",
+ mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
+ HystrixConfigurationDefinition hystrixModel = model.getHystrixConfiguration(null);
+ if (hystrixModel == null) {
+ hystrixModel = new HystrixConfigurationDefinition();
+ model.setHystrixConfiguration(hystrixModel);
+ }
+ if (hystrix != null) {
+ setPropertiesOnTarget(camelContext, hystrixModel, hystrix);
+ }
+ }
+
+ if (!resilience4jProperties.isEmpty()) {
+ Resilience4jConfigurationProperties resilience4j = mainConfigurationProperties.resilience4j();
+ LOG.debug("Auto-configuring Resilience4j Circuit Breaker EIP from loaded properties: {}",
+ resilience4jProperties.size());
+ setPropertiesOnTarget(camelContext, resilience4j, resilience4jProperties, "camel.resilience4j.",
+ mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
+ Resilience4jConfigurationDefinition resilience4jModel = model.getResilience4jConfiguration(null);
+ if (resilience4jModel == null) {
+ resilience4jModel = new Resilience4jConfigurationDefinition();
+ model.setResilience4jConfiguration(resilience4jModel);
+ }
+ setPropertiesOnTarget(camelContext, resilience4jModel, resilience4j);
+ }
+
+ if (!faultToleranceProperties.isEmpty()) {
+ FaultToleranceConfigurationProperties faultTolerance = mainConfigurationProperties.faultTolerance();
+ LOG.debug("Auto-configuring MicroProfile Fault Tolerance Circuit Breaker EIP from loaded properties: {}",
+ faultToleranceProperties.size());
+ setPropertiesOnTarget(camelContext, faultTolerance, faultToleranceProperties, "camel.faulttolerance.",
+ mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
+ FaultToleranceConfigurationDefinition faultToleranceModel = model.getFaultToleranceConfiguration(null);
+ if (faultToleranceModel == null) {
+ faultToleranceModel = new FaultToleranceConfigurationDefinition();
+ model.setFaultToleranceConfiguration(faultToleranceModel);
+ }
+ setPropertiesOnTarget(camelContext, faultToleranceModel, faultTolerance);
+ }
+ }
+
+}