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-6591 - Allow the fallback only execution mode via config.
Date Sun, 08 Oct 2017 16:38:19 GMT
Repository: geronimo-safeguard
Updated Branches:
  refs/heads/master b70e077a2 -> a43eeec7d


GERONIMO-6591 - Allow the fallback only execution mode via config.

Made config an optional dependency, use Geronimo Config for testing.


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

Branch: refs/heads/master
Commit: a43eeec7d6facc6267bda529250a4bbb66ba8c49
Parents: b70e077
Author: John D. Ament <johndament@apache.org>
Authored: Sun Oct 8 12:38:14 2017 -0400
Committer: John D. Ament <johndament@apache.org>
Committed: Sun Oct 8 12:38:14 2017 -0400

----------------------------------------------------------------------
 pom.xml                                         | 12 +++++
 safeguard-impl/pom.xml                          |  8 +++
 .../impl/executionPlans/BasicExecutionPlan.java | 35 +++++++++++++
 .../impl/executionPlans/ExecutionPlan.java      |  2 +-
 .../executionPlans/ExecutionPlanFactory.java    | 55 ++++++++++++++------
 .../FallbackOnlyExecutionPlan.java              | 43 +++++++++++++++
 safeguard-tck-tests/pom.xml                     |  5 +-
 7 files changed, 142 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7829987..a3f1561 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,6 +92,18 @@
                 <scope>provided</scope>
             </dependency>
             <dependency>
+                <groupId>org.eclipse.microprofile.config</groupId>
+                <artifactId>microprofile-config-api</artifactId>
+                <version>1.1</version>
+                <optional>true</optional>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.geronimo.config</groupId>
+                <artifactId>geronimo-config-impl</artifactId>
+                <version>1.0</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
                 <groupId>org.eclipse.microprofile.fault-tolerance</groupId>
                 <artifactId>microprofile-fault-tolerance-api</artifactId>
                 <version>${microprofile-fault-tolerance.version}</version>

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/safeguard-impl/pom.xml
----------------------------------------------------------------------
diff --git a/safeguard-impl/pom.xml b/safeguard-impl/pom.xml
index ddeb37d..d55b2ef 100644
--- a/safeguard-impl/pom.xml
+++ b/safeguard-impl/pom.xml
@@ -60,6 +60,10 @@
             <artifactId>geronimo-interceptor_1.2_spec</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.eclipse.microprofile.config</groupId>
+            <artifactId>microprofile-config-api</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.testng</groupId>
             <artifactId>testng</artifactId>
         </dependency>
@@ -67,5 +71,9 @@
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.config</groupId>
+            <artifactId>geronimo-config-impl</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/BasicExecutionPlan.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/BasicExecutionPlan.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/BasicExecutionPlan.java
new file mode 100644
index 0000000..74881d4
--- /dev/null
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/BasicExecutionPlan.java
@@ -0,0 +1,35 @@
+/*
+ *  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 javax.interceptor.InvocationContext;
+import java.util.concurrent.Callable;
+
+public class BasicExecutionPlan implements ExecutionPlan {
+    @Override
+    public <T> T execute(Callable<T> callable, InvocationContext invocationContext)
{
+        try {
+            return callable.call();
+        }
+        catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlan.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlan.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlan.java
index f8092b8..590eaff 100644
--- a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlan.java
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/ExecutionPlan.java
@@ -23,5 +23,5 @@ import javax.interceptor.InvocationContext;
 import java.util.concurrent.Callable;
 
 public interface ExecutionPlan {
-    <T> T execute(Callable<T> function, InvocationContext invocationContext);
+    <T> T execute(Callable<T> callable, InvocationContext invocationContext);
 }

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/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 6c15bb0..3c11be5 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
@@ -28,6 +28,8 @@ import org.apache.safeguard.impl.retry.FailsafeRetryDefinition;
 import org.apache.safeguard.impl.retry.FailsafeRetryManager;
 import org.apache.safeguard.impl.util.AnnotationUtil;
 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;
@@ -38,8 +40,8 @@ import java.lang.reflect.Method;
 import java.time.Duration;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.Callable;
 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;
@@ -48,10 +50,12 @@ public class ExecutionPlanFactory {
     private final FailsafeCircuitBreakerManager circuitBreakerManager;
     private final FailsafeRetryManager retryManager;
     private Map<String, ExecutionPlan> executionPlanMap = new HashMap<>();
+    private boolean enableAllMicroProfileFeatures = false;
 
     public ExecutionPlanFactory(FailsafeCircuitBreakerManager circuitBreakerManager, FailsafeRetryManager
retryManager) {
         this.circuitBreakerManager = circuitBreakerManager;
         this.retryManager = retryManager;
+        this.enableAllMicroProfileFeatures = this.enableNonFallbacksForMicroProfile();
     }
 
     public ExecutionPlan locateExecutionPlan(String name, Duration timeout, boolean async)
{
@@ -80,28 +84,47 @@ public class ExecutionPlanFactory {
             boolean isAsync = isAsync(method);
             Duration timeout = readTimeout(method);
             FallbackRunner fallbackRunner = this.createFallback(method);
-            if(circuitBreaker == null && retryDefinition == null && isAsync)
{
-                if(timeout == null) {
-                    return new AsyncOnlyExecutionPlan(null);
-                }
-                else {
+            if(this.enableAllMicroProfileFeatures) {
+                if (circuitBreaker == null && retryDefinition == null &&
isAsync) {
+                    if (timeout == null) {
+                        return new AsyncOnlyExecutionPlan(null);
+                    } else {
+                        return new AsyncTimeoutExecutionPlan(timeout, Executors.newFixedThreadPool(5));
+                    }
+                } else if (circuitBreaker == null && retryDefinition == null &&
timeout != null) {
+                    // then its just timeout
                     return new AsyncTimeoutExecutionPlan(timeout, Executors.newFixedThreadPool(5));
-                }
-            }
-            else if(circuitBreaker == null && retryDefinition == null &&
timeout != null) {
-                // then its just timeout
-                return new AsyncTimeoutExecutionPlan(timeout, Executors.newFixedThreadPool(5));
-            }
-            else {
-                if (isAsync || timeout != null) {
-                    return new AsyncFailsafeExecutionPlan(retryDefinition, circuitBreaker,
fallbackRunner, Executors.newScheduledThreadPool(5), timeout);
                 } else {
-                    return new SyncFailsafeExecutionPlan(retryDefinition, circuitBreaker,
fallbackRunner);
+                    if (isAsync || timeout != null) {
+                        return new AsyncFailsafeExecutionPlan(retryDefinition, circuitBreaker,
fallbackRunner, Executors.newScheduledThreadPool(5), timeout);
+                    } else {
+                        return new SyncFailsafeExecutionPlan(retryDefinition, circuitBreaker,
fallbackRunner);
+                    }
+                }
+            }else {
+                if(fallbackRunner == null) {
+                    return new BasicExecutionPlan();
+                }
+                else {
+                    return new FallbackOnlyExecutionPlan(fallbackRunner);
                 }
             }
         });
     }
 
+    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;
+        }
+    }
+
     private FailsafeRetryDefinition createDefinition(String name, Method method) {
         Retry retry = AnnotationUtil.getAnnotation(method, Retry.class);
         if (retry == null) {

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/FallbackOnlyExecutionPlan.java
----------------------------------------------------------------------
diff --git a/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/FallbackOnlyExecutionPlan.java
b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/FallbackOnlyExecutionPlan.java
new file mode 100644
index 0000000..57f56e7
--- /dev/null
+++ b/safeguard-impl/src/main/java/org/apache/safeguard/impl/executionPlans/FallbackOnlyExecutionPlan.java
@@ -0,0 +1,43 @@
+/*
+ *  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.impl.fallback.FallbackRunner;
+
+import javax.interceptor.InvocationContext;
+import java.util.concurrent.Callable;
+
+public class FallbackOnlyExecutionPlan implements ExecutionPlan {
+    private final FallbackRunner fallbackRunner;
+
+    public FallbackOnlyExecutionPlan(FallbackRunner fallbackRunner) {
+        this.fallbackRunner = fallbackRunner;
+    }
+
+    @Override
+    public <T> T execute(Callable<T> callable, InvocationContext invocationContext)
{
+        try {
+            return callable.call();
+        }
+        catch (Exception e) {
+            return (T)fallbackRunner.executeFallback(invocationContext);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/geronimo-safeguard/blob/a43eeec7/safeguard-tck-tests/pom.xml
----------------------------------------------------------------------
diff --git a/safeguard-tck-tests/pom.xml b/safeguard-tck-tests/pom.xml
index 5479be5..dd51f13 100644
--- a/safeguard-tck-tests/pom.xml
+++ b/safeguard-tck-tests/pom.xml
@@ -56,6 +56,10 @@
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-interceptor_1.2_spec</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.config</groupId>
+            <artifactId>geronimo-config-impl</artifactId>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
@@ -73,7 +77,6 @@
                         <exclude>org.eclipse.microprofile.fault.tolerance.tck.bulkhead.BulkheadFutureTest</exclude>
                         <exclude>org.eclipse.microprofile.fault.tolerance.tck.bulkhead.BulkheadSynchRetryTest</exclude>
                         <exclude>org.eclipse.microprofile.fault.tolerance.tck.bulkhead.BulkheadSynchTest</exclude>
-                        <exclude>org.eclipse.microprofile.fault.tolerance.tck.disableEnv.DisableTest</exclude>
                         <exclude>org.eclipse.microprofile.fault.tolerance.tck.illegalConfig.IncompatibleFallbackMethodTest</exclude>
                         <exclude>org.eclipse.microprofile.fault.tolerance.tck.illegalConfig.IncompatibleFallbackMethodWithArgsTest</exclude>
                         <exclude>org.eclipse.microprofile.fault.tolerance.tck.illegalConfig.IncompatibleFallbackTest</exclude>


Mime
View raw message