geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johndam...@apache.org
Subject geronimo-safeguard git commit: GERONIMO-6582 Adding support for configuration of MicroProfile annotations.
Date Mon, 01 Jan 2018 15:16:28 GMT
Repository: geronimo-safeguard
Updated Branches:
  refs/heads/master 27626ffdf -> 7bff61c41


GERONIMO-6582 Adding support for configuration of MicroProfile annotations.


Project: http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/repo
Commit: http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/commit/7bff61c4
Tree: http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/tree/7bff61c4
Diff: http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/diff/7bff61c4

Branch: refs/heads/master
Commit: 7bff61c41832b63c07fcfd9efc0f101c85e04379
Parents: 27626ff
Author: John D. Ament <johndament@apache.org>
Authored: Mon Jan 1 10:16:22 2018 -0500
Committer: John D. Ament <johndament@apache.org>
Committed: Mon Jan 1 10:16:22 2018 -0500

----------------------------------------------------------------------
 pom.xml                                         |   6 +-
 safeguard-api/pom.xml                           |   4 +
 .../safeguard/api/config/ConfigFacade.java      |  61 ++++++
 .../impl/FailsafeExecutionManager.java          |  39 +++-
 .../impl/config/MicroProfileConfigFacade.java   |  70 +++++++
 .../config/MicroprofileAnnotationMapper.java    | 204 +++++++++++++++++++
 .../executionPlans/ExecutionPlanFactory.java    |  30 ++-
 .../MicroprofileAnnotationMapper.java           |  66 ------
 ...org.apache.safeguard.api.config.ConfigFacade |  20 ++
 .../circuitbreaker/test/CDICircuitTest.java     |   6 +-
 .../circuitbreaker/test/CircuitTest.java        |   6 +-
 .../circuitretry/test/CDIRetryCircuitTest.java  |   4 +-
 .../circuitretry/test/RetryCircuitTest.java     |   4 +-
 .../safeguard/ft/tck/ArchiveAppender.java       |   2 +
 14 files changed, 414 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 816ee06..89be167 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,8 @@
         <arquillian-weld-embedded.version>2.0.0.Final</arquillian-weld-embedded.version>
         <cdi2-api.version>2.0</cdi2-api.version>
         <weld.version>3.0.1.Final</weld.version>
+        <geronimo-config-impl.version>1.1-SNAPSHOT</geronimo-config-impl.version>
+        <microprofile-config-api.version>1.2</microprofile-config-api.version>
     </properties>
 
     <dependencyManagement>
@@ -94,13 +96,13 @@
             <dependency>
                 <groupId>org.eclipse.microprofile.config</groupId>
                 <artifactId>microprofile-config-api</artifactId>
-                <version>1.1</version>
+                <version>${microprofile-config-api.version}</version>
                 <optional>true</optional>
             </dependency>
             <dependency>
                 <groupId>org.apache.geronimo.config</groupId>
                 <artifactId>geronimo-config-impl</artifactId>
-                <version>1.0</version>
+                <version>${geronimo-config-impl.version}</version>
                 <scope>test</scope>
             </dependency>
             <dependency>

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-api/pom.xml
----------------------------------------------------------------------
diff --git a/safeguard-api/pom.xml b/safeguard-api/pom.xml
index 2f240f6..de15959 100644
--- a/safeguard-api/pom.xml
+++ b/safeguard-api/pom.xml
@@ -37,6 +37,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-annotation_1.3_spec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-interceptor_1.2_spec</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-api/src/main/java/org/apache/safeguard/api/config/ConfigFacade.java
----------------------------------------------------------------------
diff --git a/safeguard-api/src/main/java/org/apache/safeguard/api/config/ConfigFacade.java
b/safeguard-api/src/main/java/org/apache/safeguard/api/config/ConfigFacade.java
new file mode 100644
index 0000000..a0af320
--- /dev/null
+++ b/safeguard-api/src/main/java/org/apache/safeguard/api/config/ConfigFacade.java
@@ -0,0 +1,61 @@
+/*
+ *  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.safeguard.api.config;
+
+import javax.annotation.Priority;
+import java.time.temporal.ChronoUnit;
+import java.util.Comparator;
+import java.util.ServiceLoader;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public abstract class ConfigFacade {
+    private static ConfigFacade INSTANCE;
+
+    public abstract boolean getBoolean(String name, boolean defaultValue);
+    public abstract long getLong(String name, long defaultValue);
+    public abstract int getInt(String name, int defaultValue);
+    public abstract double getDouble(String name, double defaultValue);
+    public abstract ChronoUnit getChronoUnit(String name, ChronoUnit defaultValue);
+    public abstract Class<? extends Throwable>[] getThrowableClasses(String name, Class<?
extends Throwable>[] defaultValue);
+
+    public static ConfigFacade getInstance() {
+        if (INSTANCE == null) {
+            INSTANCE = load();
+        }
+        return INSTANCE;
+    }
+
+    public static void setInstance(ConfigFacade configFacade) {
+        INSTANCE = configFacade;
+    }
+
+    private static ConfigFacade load() {
+        ServiceLoader<ConfigFacade> configFacades = ServiceLoader.load(ConfigFacade.class);
+        SortedSet<ConfigFacade> configFacedSet = new TreeSet<>(Comparator.comparingInt(c
-> {
+            Priority p = c.getClass().getAnnotation(Priority.class);
+            return p == null ? 1 : p.value();
+        }));
+        for(ConfigFacade facade : configFacades) {
+            configFacedSet.add(facade);
+        }
+        return configFacedSet.first();
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/main/java/org/apache/safeguard/impl/FailsafeExecutionManager.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/FailsafeExecutionManager.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/FailsafeExecutionManager.java
index eab9231..178a381 100644
--- a/safeguard-impl/src/main/java/org/apache/safeguard/impl/FailsafeExecutionManager.java
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/FailsafeExecutionManager.java
@@ -21,8 +21,11 @@ package org.apache.safeguard.impl;
 
 import org.apache.safeguard.api.ExecutionManager;
 import org.apache.safeguard.api.bulkhead.BulkheadManager;
+import org.apache.safeguard.api.circuitbreaker.CircuitBreakerManager;
+import org.apache.safeguard.api.retry.RetryManager;
 import org.apache.safeguard.impl.bulkhead.BulkheadManagerImpl;
 import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerManager;
+import org.apache.safeguard.impl.config.MicroprofileAnnotationMapper;
 import org.apache.safeguard.impl.executionPlans.ExecutionPlanFactory;
 import org.apache.safeguard.impl.retry.FailsafeRetryManager;
 
@@ -34,17 +37,31 @@ import java.util.concurrent.Callable;
 
 @Vetoed
 public class FailsafeExecutionManager implements ExecutionManager {
-    private BulkheadManagerImpl bulkheadManager;
-    private FailsafeCircuitBreakerManager circuitBreakerManager;
-    private FailsafeRetryManager retryManager;
-    private ExecutionPlanFactory executionPlanFactory;
+    private final MicroprofileAnnotationMapper mapper;
+    private final BulkheadManager bulkheadManager;
+    private final CircuitBreakerManager circuitBreakerManager;
+    private final RetryManager retryManager;
+    private final ExecutionPlanFactory executionPlanFactory;
 
     public FailsafeExecutionManager() {
-        this.circuitBreakerManager = new FailsafeCircuitBreakerManager();
-        this.retryManager = new FailsafeRetryManager();
-        this.bulkheadManager = new BulkheadManagerImpl();
-        this.executionPlanFactory = new ExecutionPlanFactory(this.circuitBreakerManager,
this.retryManager,
-                this.bulkheadManager);
+        FailsafeCircuitBreakerManager circuitBreakerManager = new FailsafeCircuitBreakerManager();
+        FailsafeRetryManager retryManager = new FailsafeRetryManager();
+        BulkheadManagerImpl bulkheadManager = new BulkheadManagerImpl();
+        this.mapper = MicroprofileAnnotationMapper.getInstance();
+        this.executionPlanFactory = new ExecutionPlanFactory(circuitBreakerManager, retryManager,
bulkheadManager, mapper);
+        this.circuitBreakerManager = circuitBreakerManager;
+        this.retryManager = retryManager;
+        this.bulkheadManager = bulkheadManager;
+    }
+
+    public FailsafeExecutionManager(MicroprofileAnnotationMapper mapper, BulkheadManagerImpl
bulkheadManager,
+                                    FailsafeCircuitBreakerManager circuitBreakerManager,
FailsafeRetryManager retryManager,
+                                    ExecutionPlanFactory executionPlanFactory) {
+        this.mapper = mapper;
+        this.bulkheadManager = bulkheadManager;
+        this.circuitBreakerManager = circuitBreakerManager;
+        this.retryManager = retryManager;
+        this.executionPlanFactory = executionPlanFactory;
     }
 
     public Object execute(InvocationContext invocationContext) {
@@ -70,12 +87,12 @@ public class FailsafeExecutionManager implements ExecutionManager {
     }
 
     @Override
-    public FailsafeCircuitBreakerManager getCircuitBreakerManager() {
+    public CircuitBreakerManager getCircuitBreakerManager() {
         return circuitBreakerManager;
     }
 
     @Override
-    public FailsafeRetryManager getRetryManager() {
+    public RetryManager getRetryManager() {
         return retryManager;
     }
 

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroProfileConfigFacade.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroProfileConfigFacade.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroProfileConfigFacade.java
new file mode 100644
index 0000000..af58a51
--- /dev/null
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroProfileConfigFacade.java
@@ -0,0 +1,70 @@
+/*
+ *  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.safeguard.impl.config;
+
+import org.apache.safeguard.api.config.ConfigFacade;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.ConfigProvider;
+
+import javax.annotation.Priority;
+import java.time.temporal.ChronoUnit;
+
+@Priority(1)
+public class MicroProfileConfigFacade extends ConfigFacade {
+    private final Config config;
+
+    public MicroProfileConfigFacade() {
+        this(ConfigProvider.getConfig());
+    }
+
+    public MicroProfileConfigFacade(Config config) {
+        this.config = config;
+    }
+
+    @Override
+    public boolean getBoolean(String name, boolean defaultValue) {
+        return config.getOptionalValue(name, Boolean.class).orElse(defaultValue);
+    }
+
+    @Override
+    public long getLong(String name, long defaultValue) {
+        return config.getOptionalValue(name, Long.class).orElse(defaultValue);
+    }
+
+    @Override
+    public int getInt(String name, int defaultValue) {
+        return config.getOptionalValue(name, Integer.class).orElse(defaultValue);
+    }
+
+    @Override
+    public double getDouble(String name, double defaultValue) {
+        return config.getOptionalValue(name, Double.class).orElse(defaultValue);
+    }
+
+    @Override
+    public ChronoUnit getChronoUnit(String name, ChronoUnit defaultValue) {
+        return config.getOptionalValue(name, ChronoUnit.class).orElse(defaultValue);
+    }
+
+    @Override
+    public Class<? extends Throwable>[] getThrowableClasses(String name, Class<?
extends Throwable>[] defaultValue) {
+        return config.getOptionalValue(name, Class[].class).orElse(defaultValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroprofileAnnotationMapper.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroprofileAnnotationMapper.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroprofileAnnotationMapper.java
new file mode 100644
index 0000000..4387095
--- /dev/null
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/config/MicroprofileAnnotationMapper.java
@@ -0,0 +1,204 @@
+/*
+ *  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.safeguard.impl.config;
+
+import org.apache.safeguard.api.config.ConfigFacade;
+import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerBuilder;
+import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerDefinition;
+import org.apache.safeguard.impl.retry.FailsafeRetryBuilder;
+import org.apache.safeguard.impl.retry.FailsafeRetryDefinition;
+import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
+import org.eclipse.microprofile.faulttolerance.Retry;
+
+import javax.enterprise.inject.Vetoed;
+import java.lang.reflect.Method;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.util.concurrent.TimeoutException;
+
+@Vetoed
+public class MicroprofileAnnotationMapper {
+    private static MicroprofileAnnotationMapper INSTANCE = new MicroprofileAnnotationMapper();
+    private final ConfigFacade configFacade;
+
+    private MicroprofileAnnotationMapper() {
+        this(ConfigFacade.getInstance());
+    }
+    public MicroprofileAnnotationMapper(ConfigFacade configFacade) {
+        this.configFacade = configFacade;
+    }
+
+    private static final String RETRY_CLASS_FORMAT = "%s/Retry/%s";
+    private static final String RETRY_METHOD_FORMAT = "%s/%s/Retry/%s";
+    private static final String CIRCUIT_BREAKER_CLASS_FORMAT = "%s/CircuitBreaker/%s";
+    private static final String CIRCUIT_BREAKER_METHOD_FORMAT = "%s/%s/CircuitBreaker/%s";
+    public FailsafeRetryDefinition mapRetry(Method method, Retry retry, FailsafeRetryBuilder
retryBuilder) {
+        boolean methodLevel = method.isAnnotationPresent(Retry.class);
+        int maxRetries = getRetryValue(method, "maxRetries", methodLevel, retry.maxRetries());
+        Class[] retryOn = getRetryValue(method, "retryOn", methodLevel, retry.retryOn());
+        Class[] abortOn = getRetryValue(method, "abortOn", methodLevel, retry.abortOn());
+
+        long delay = getRetryValue(method, "delay", methodLevel, retry.delay());
+        ChronoUnit delayUnit = getRetryValue(method, "delayUnit", methodLevel, retry.delayUnit());
+
+        long jitter = getRetryValue(method, "jitter", methodLevel, retry.jitter());
+        ChronoUnit jitterUnit = getRetryValue(method, "jitterDelayUnit", methodLevel, retry.jitterDelayUnit());
+
+        long maxDuration = getRetryValue(method, "maxDuration", methodLevel, retry.maxDuration());
+        ChronoUnit maxDurationUnit = getRetryValue(method, "durationUnit", methodLevel, retry.durationUnit());
+
+        retryBuilder.withMaxRetries(maxRetries)
+                .withRetryOn(retryOn)
+                .withRetryOn(TimeoutException.class, org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException.class)
+                .withAbortOn(abortOn);
+        if (delay > 0L) {
+            retryBuilder.withDelay(Duration.of(delay, delayUnit));
+        }
+        if (jitter > 0L) {
+            retryBuilder.withJitter(Duration.of(jitter, jitterUnit));
+        }
+        if (maxDuration > 0L) {
+            retryBuilder.withMaxDuration(Duration.of(maxDuration, maxDurationUnit));
+        }
+        return retryBuilder.build();
+    }
+
+    public FailsafeCircuitBreakerDefinition mapCircuitBreaker(Method method, CircuitBreaker
circuitBreaker,
+                                                              FailsafeCircuitBreakerBuilder
builder) {
+        boolean methodLevel = method.isAnnotationPresent(CircuitBreaker.class);
+
+        double failureRatio = getCBValue(method, "failureRatio", methodLevel, circuitBreaker.failureRatio());
+        int requestVolumeThreshold = getCBValue(method, "requestVolumeThreshold", methodLevel,
circuitBreaker.requestVolumeThreshold());
+        Class[] failOn = getCBValue(method, "failOn", methodLevel, circuitBreaker.failOn());
+        long delay = getCBValue(method, "delay", methodLevel, circuitBreaker.delay());
+        ChronoUnit delayUnit = getCBValue(method, "delayUnit", methodLevel, circuitBreaker.delayUnit());
+        int successThreshold = getCBValue(method, "successThreshold", methodLevel, circuitBreaker.successThreshold());
+
+        int failureCount = (int) (failureRatio * requestVolumeThreshold);
+        FailsafeCircuitBreakerBuilder failsafeCircuitBreakerBuilder = builder
+                .withFailOn(failOn)
+                .withFailOn(TimeoutException.class, org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException.class)
+                .withDelay(Duration.of(delay, delayUnit))
+                .withSuccessCount(successThreshold);
+        if (failureCount > 0) {
+            failsafeCircuitBreakerBuilder.withFailures(failureCount, requestVolumeThreshold);
+        }
+        return failsafeCircuitBreakerBuilder.build();
+    }
+
+    public static MicroprofileAnnotationMapper getInstance() {
+        return INSTANCE;
+    }
+
+    public static void setInstance(MicroprofileAnnotationMapper microprofileAnnotationMapper)
{
+        INSTANCE = microprofileAnnotationMapper;
+    }
+
+    // retry config
+    private int getRetryValue(Method method, String name, boolean isMethod, int defaultValue)
{
+        String methodKey = String.format(RETRY_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        int value = configFacade.getInt(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(RETRY_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getInt(classKey, defaultValue);
+    }
+
+    private long getRetryValue(Method method, String name, boolean isMethod, long defaultValue)
{
+        String methodKey = String.format(RETRY_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        long value = configFacade.getLong(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(RETRY_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getLong(classKey, defaultValue);
+    }
+
+    private ChronoUnit getRetryValue(Method method, String name, boolean isMethod, ChronoUnit
defaultValue) {
+        String methodKey = String.format(RETRY_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        ChronoUnit value = configFacade.getChronoUnit(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(RETRY_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getChronoUnit(classKey, defaultValue);
+    }
+
+    private Class[] getRetryValue(Method method, String name, boolean isMethod, Class[] defaultValue)
{
+        String methodKey = String.format(RETRY_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        Class[] value = configFacade.getThrowableClasses(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(RETRY_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getThrowableClasses(classKey, defaultValue);
+    }
+    // circuit breaker config
+    private int getCBValue(Method method, String name, boolean isMethod, int defaultValue)
{
+        String methodKey = String.format(CIRCUIT_BREAKER_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        int value = configFacade.getInt(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(CIRCUIT_BREAKER_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getInt(classKey, defaultValue);
+    }
+
+    private long getCBValue(Method method, String name, boolean isMethod, long defaultValue)
{
+        String methodKey = String.format(CIRCUIT_BREAKER_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        long value = configFacade.getLong(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(CIRCUIT_BREAKER_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getLong(classKey, defaultValue);
+    }
+
+    private double getCBValue(Method method, String name, boolean isMethod, double defaultValue)
{
+        String methodKey = String.format(CIRCUIT_BREAKER_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        double value = configFacade.getDouble(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(CIRCUIT_BREAKER_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getDouble(classKey, defaultValue);
+    }
+
+    private ChronoUnit getCBValue(Method method, String name, boolean isMethod, ChronoUnit
defaultValue) {
+        String methodKey = String.format(CIRCUIT_BREAKER_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        ChronoUnit value = configFacade.getChronoUnit(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(CIRCUIT_BREAKER_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getChronoUnit(classKey, defaultValue);
+    }
+
+    private Class[] getCBValue(Method method, String name, boolean isMethod, Class[] defaultValue)
{
+        String methodKey = String.format(CIRCUIT_BREAKER_METHOD_FORMAT, method.getDeclaringClass().getName(),
method.getName(), name);
+        Class[] value = configFacade.getThrowableClasses(methodKey, defaultValue);
+        if(value != defaultValue || isMethod) {
+            return value;
+        }
+        String classKey = String.format(CIRCUIT_BREAKER_CLASS_FORMAT, method.getDeclaringClass().getName(),
name);
+        return configFacade.getThrowableClasses(classKey, defaultValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlanFactory.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlanFactory.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlanFactory.java
index c6515d1..5c7dd5f 100644
--- a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlanFactory.java
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlanFactory.java
@@ -24,14 +24,15 @@ import org.apache.safeguard.api.bulkhead.BulkheadBuilder;
 import org.apache.safeguard.api.bulkhead.BulkheadManager;
 import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreaker;
 import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerBuilder;
+import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerDefinition;
 import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerManager;
+import org.apache.safeguard.api.config.ConfigFacade;
+import org.apache.safeguard.impl.config.MicroprofileAnnotationMapper;
 import org.apache.safeguard.impl.fallback.FallbackRunner;
 import org.apache.safeguard.impl.retry.FailsafeRetryBuilder;
 import org.apache.safeguard.impl.retry.FailsafeRetryDefinition;
 import org.apache.safeguard.impl.retry.FailsafeRetryManager;
 import org.apache.safeguard.impl.util.NamingUtil;
-import org.eclipse.microprofile.config.Config;
-import org.eclipse.microprofile.config.ConfigProvider;
 import org.eclipse.microprofile.faulttolerance.Asynchronous;
 import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
 import org.eclipse.microprofile.faulttolerance.Fallback;
@@ -43,25 +44,25 @@ import java.time.Duration;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
 
-import static org.apache.safeguard.impl.executionPlans.MicroprofileAnnotationMapper.mapCircuitBreaker;
-import static org.apache.safeguard.impl.executionPlans.MicroprofileAnnotationMapper.mapRetry;
 import static org.apache.safeguard.impl.util.AnnotationUtil.getAnnotation;
 
 public class ExecutionPlanFactory {
     private final FailsafeCircuitBreakerManager circuitBreakerManager;
     private final FailsafeRetryManager retryManager;
     private final BulkheadManager bulkheadManager;
+    private final MicroprofileAnnotationMapper microprofileAnnotationMapper;
     private ConcurrentMap<String, ExecutionPlan> executionPlanMap = new ConcurrentHashMap<>();
     private final boolean enableAllMicroProfileFeatures;
 
     public ExecutionPlanFactory(FailsafeCircuitBreakerManager circuitBreakerManager,
                                 FailsafeRetryManager retryManager,
-                                BulkheadManager bulkheadManager) {
+                                BulkheadManager bulkheadManager,
+                                MicroprofileAnnotationMapper microprofileAnnotationMapper)
{
         this.circuitBreakerManager = circuitBreakerManager;
         this.retryManager = retryManager;
         this.bulkheadManager = bulkheadManager;
+        this.microprofileAnnotationMapper = microprofileAnnotationMapper;
         this.enableAllMicroProfileFeatures = this.enableNonFallbacksForMicroProfile();
     }
 
@@ -131,16 +132,7 @@ public class ExecutionPlanFactory {
     }
 
     private boolean enableNonFallbacksForMicroProfile() {
-        try {
-            Class.forName("org.eclipse.microprofile.config.Config");
-            Config config = ConfigProvider.getConfig();
-            AtomicBoolean disableExecutions = new AtomicBoolean(true);
-            config.getOptionalValue("MP_Fault_Tolerance_NonFallback_Enabled", Boolean.class)
-                    .ifPresent(disableExecutions::set);
-            return disableExecutions.get();
-        } catch (ClassNotFoundException e) {
-            return true;
-        }
+        return ConfigFacade.getInstance().getBoolean("MP_Fault_Tolerance_NonFallback_Enabled",
true);
     }
 
     private FailsafeRetryDefinition createDefinition(String name, Method method) {
@@ -149,7 +141,7 @@ public class ExecutionPlanFactory {
             return null;
         }
         FailsafeRetryBuilder retryBuilder = retryManager.newRetryDefinition(name);
-        return mapRetry(retry, retryBuilder);
+        return microprofileAnnotationMapper.mapRetry(method, retry, retryBuilder);
     }
 
     private FailsafeCircuitBreaker createCBDefinition(String name, Method method) {
@@ -158,7 +150,9 @@ public class ExecutionPlanFactory {
             return null;
         }
         FailsafeCircuitBreakerBuilder circuitBreakerBuilder = this.circuitBreakerManager.newCircuitBreaker(name);
-        return new FailsafeCircuitBreaker(mapCircuitBreaker(circuitBreaker, circuitBreakerBuilder));
+        FailsafeCircuitBreakerDefinition circuitBreakerDefinition = microprofileAnnotationMapper.mapCircuitBreaker(method,
+                circuitBreaker, circuitBreakerBuilder);
+        return new FailsafeCircuitBreaker(circuitBreakerDefinition);
     }
 
     private Bulkhead createBulkhead(String name, Method method) {

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/MicroprofileAnnotationMapper.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/MicroprofileAnnotationMapper.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/MicroprofileAnnotationMapper.java
deleted file mode 100644
index 41921c5..0000000
--- a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/MicroprofileAnnotationMapper.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *  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.safeguard.impl.executionPlans;
-
-import org.apache.safeguard.exception.SafeguardException;
-import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerBuilder;
-import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreakerDefinition;
-import org.apache.safeguard.impl.retry.FailsafeRetryBuilder;
-import org.apache.safeguard.impl.retry.FailsafeRetryDefinition;
-import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
-import org.eclipse.microprofile.faulttolerance.Retry;
-
-import java.time.Duration;
-import java.util.concurrent.TimeoutException;
-
-class MicroprofileAnnotationMapper {
-    private static final String RETRY_FORMAT = "%s/Retry/%s";
-    private static final String CIRCUIT_BREAKER_FORMAT = "%s/CircuitBreaker/%s";
-    static FailsafeRetryDefinition mapRetry(Retry retry, FailsafeRetryBuilder retryBuilder)
{
-        retryBuilder.withMaxRetries(retry.maxRetries())
-                .withRetryOn(retry.retryOn())
-                .withRetryOn(TimeoutException.class, org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException.class)
-                .withAbortOn(retry.abortOn());
-        if (retry.delay() > 0L) {
-            retryBuilder.withDelay(Duration.of(retry.delay(), retry.delayUnit()));
-        }
-        if (retry.jitter() > 0L) {
-            retryBuilder.withJitter(Duration.of(retry.jitter(), retry.jitterDelayUnit()));
-        }
-        if (retry.maxDuration() > 0L) {
-            retryBuilder.withMaxDuration(Duration.of(retry.maxDuration(), retry.durationUnit()));
-        }
-        return retryBuilder.build();
-    }
-
-    static FailsafeCircuitBreakerDefinition mapCircuitBreaker(CircuitBreaker circuitBreaker,
-                                                              FailsafeCircuitBreakerBuilder
builder) {
-        int failureCount = (int) (circuitBreaker.failureRatio() * circuitBreaker.requestVolumeThreshold());
-        FailsafeCircuitBreakerBuilder failsafeCircuitBreakerBuilder = builder
-                .withFailOn(circuitBreaker.failOn())
-                .withFailOn(TimeoutException.class, org.eclipse.microprofile.faulttolerance.exceptions.TimeoutException.class)
-                .withDelay(Duration.of(circuitBreaker.delay(), circuitBreaker.delayUnit()))
-                .withSuccessCount(circuitBreaker.successThreshold());
-        if (failureCount > 0) {
-            failsafeCircuitBreakerBuilder.withFailures(failureCount, circuitBreaker.requestVolumeThreshold());
-        }
-        return failsafeCircuitBreakerBuilder.build();
-    }
-}

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/main/resources/META-INF/services/org.apache.safeguard.api.config.ConfigFacade
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/resources/META-INF/services/org.apache.safeguard.api.config.ConfigFacade
b/safeguard-impl/src/main/resources/META-INF/services/org.apache.safeguard.api.config.ConfigFacade
new file mode 100644
index 0000000..a4f092e
--- /dev/null
+++ b/safeguard-impl/src/main/resources/META-INF/services/org.apache.safeguard.api.config.ConfigFacade
@@ -0,0 +1,20 @@
+#
+#  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.
+#
+
+org.apache.safeguard.impl.config.MicroProfileConfigFacade
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CDICircuitTest.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CDICircuitTest.java
b/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CDICircuitTest.java
index 33bd304..f6bd311 100644
--- a/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CDICircuitTest.java
+++ b/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CDICircuitTest.java
@@ -20,9 +20,9 @@
 package org.apache.safeguard.circuitbreaker.test;
 
 import org.apache.safeguard.SafeguardCDITest;
+import org.apache.safeguard.api.circuitbreaker.CircuitBreaker;
 import org.apache.safeguard.api.circuitbreaker.CircuitBreakerState;
 import org.apache.safeguard.impl.FailsafeExecutionManager;
-import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreaker;
 import org.apache.safeguard.impl.util.NamingUtil;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.shrinkwrap.api.Archive;
@@ -53,7 +53,7 @@ public class CDICircuitTest extends SafeguardCDITest{
         for(int i = 0;i<5;i++) {
             try {
                 cdiCircuitBean.sayHello();
-                FailsafeCircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
+                CircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
                 if (i < 4) {
                     assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreakerState.CLOSED);
                 }
@@ -64,7 +64,7 @@ public class CDICircuitTest extends SafeguardCDITest{
             catch (Exception e){ }
         }
 
-        FailsafeCircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
+        CircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
         assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreakerState.OPEN);
     }
 }

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CircuitTest.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CircuitTest.java
b/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CircuitTest.java
index 5854b2f..00efc30 100644
--- a/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CircuitTest.java
+++ b/safeguard-impl/src/test/java/org/apache/safeguard/circuitbreaker/test/CircuitTest.java
@@ -19,14 +19,12 @@
 
 package org.apache.safeguard.circuitbreaker.test;
 
+import org.apache.safeguard.api.circuitbreaker.CircuitBreaker;
 import org.apache.safeguard.api.circuitbreaker.CircuitBreakerState;
 import org.apache.safeguard.impl.FailsafeExecutionManager;
-import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreaker;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
-import java.util.concurrent.Callable;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class CircuitTest {
@@ -45,7 +43,7 @@ public class CircuitTest {
                 .withFailureCount(failureCount)
                 .withFailOn(Exception.class)
                 .build();
-        FailsafeCircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
+        CircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
         assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreakerState.CLOSED);
         for(int i = 0; i<failureCount;i++) {
             try {

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/CDIRetryCircuitTest.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/CDIRetryCircuitTest.java
b/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/CDIRetryCircuitTest.java
index d0f8a26..27013e7 100644
--- a/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/CDIRetryCircuitTest.java
+++ b/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/CDIRetryCircuitTest.java
@@ -20,9 +20,9 @@
 package org.apache.safeguard.circuitretry.test;
 
 import org.apache.safeguard.SafeguardCDITest;
+import org.apache.safeguard.api.circuitbreaker.CircuitBreaker;
 import org.apache.safeguard.api.circuitbreaker.CircuitBreakerState;
 import org.apache.safeguard.impl.FailsafeExecutionManager;
-import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreaker;
 import org.apache.safeguard.impl.util.NamingUtil;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.shrinkwrap.api.Archive;
@@ -55,7 +55,7 @@ public class CDIRetryCircuitTest extends SafeguardCDITest{
 
         Method method = CDISimpleCallable.class.getMethod("call");
         String name = NamingUtil.createName(method);
-        FailsafeCircuitBreaker circuitBreaker = executionManager.getCircuitBreakerManager().getCircuitBreaker(name);
+        CircuitBreaker circuitBreaker = executionManager.getCircuitBreakerManager().getCircuitBreaker(name);
 
         assertThat(circuitBreaker.getState()).isEqualTo(CircuitBreakerState.OPEN);
         assertThat(simpleCallable.getCounter()).isEqualTo(4);

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/RetryCircuitTest.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/RetryCircuitTest.java
b/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/RetryCircuitTest.java
index a176b80..5c6b5e0 100644
--- a/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/RetryCircuitTest.java
+++ b/safeguard-impl/src/test/java/org/apache/safeguard/circuitretry/test/RetryCircuitTest.java
@@ -19,9 +19,9 @@
 
 package org.apache.safeguard.circuitretry.test;
 
+import org.apache.safeguard.api.circuitbreaker.CircuitBreaker;
 import org.apache.safeguard.api.circuitbreaker.CircuitBreakerState;
 import org.apache.safeguard.impl.FailsafeExecutionManager;
-import org.apache.safeguard.impl.circuitbreaker.FailsafeCircuitBreaker;
 import org.testng.annotations.Test;
 
 import java.time.Duration;
@@ -46,7 +46,7 @@ public class RetryCircuitTest {
                 .withDelay(Duration.ofMillis(5000))
                 .withFailOn(RuntimeException.class)
                 .build();
-        FailsafeCircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
+        CircuitBreaker circuitBreaker = failsafeExecutionManager.getCircuitBreakerManager().getCircuitBreaker(name);
 
         SimpleCallable simpleCallable = new SimpleCallable();
         try {

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/7bff61c4/safeguard-tck-tests/src/test/java/org/apache/safeguard/ft/tck/ArchiveAppender.java
----------------------------------------------------------------------
diff --git a/safeguard-tck-tests/src/test/java/org/apache/safeguard/ft/tck/ArchiveAppender.java
b/safeguard-tck-tests/src/test/java/org/apache/safeguard/ft/tck/ArchiveAppender.java
index 4a50bba..28b2f58 100644
--- a/safeguard-tck-tests/src/test/java/org/apache/safeguard/ft/tck/ArchiveAppender.java
+++ b/safeguard-tck-tests/src/test/java/org/apache/safeguard/ft/tck/ArchiveAppender.java
@@ -20,6 +20,7 @@
 package org.apache.safeguard.ft.tck;
 
 import org.apache.safeguard.api.SafeguardEnabled;
+import org.apache.safeguard.api.config.ConfigFacade;
 import org.apache.safeguard.impl.cdi.FailsafeExecutionManagerProvider;
 import org.apache.safeguard.impl.cdi.SafeguardExtension;
 import org.apache.safeguard.impl.cdi.SafeguardInterceptor;
@@ -38,6 +39,7 @@ public class ArchiveAppender implements ApplicationArchiveProcessor {
 
     @Override
     public void process(Archive<?> archive, TestClass testClass) {
+        ConfigFacade.setInstance(null);
         JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "safeguard.jar")
                 .addClasses(SafeguardEnabled.class, SafeguardExtension.class, FailsafeExecutionManagerProvider.class,
SafeguardInterceptor.class)
                 .addAsServiceProvider(Extension.class, SafeguardExtension.class)


Mime
View raw message