Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmallRye Fault Tolerance 4.x #6300

Merged
merged 2 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<smallrye-metrics.version>2.3.2</smallrye-metrics.version>
<smallrye-open-api.version>1.1.20</smallrye-open-api.version>
<smallrye-opentracing.version>1.3.2</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>2.1.3</smallrye-fault-tolerance.version>
<smallrye-fault-tolerance.version>4.0.0</smallrye-fault-tolerance.version>
<smallrye-jwt.version>2.0.10</smallrye-jwt.version>
<smallrye-context-propagation.version>1.0.11</smallrye-context-propagation.version>
<smallrye-reactive-streams-operators.version>1.0.10</smallrye-reactive-streams-operators.version>
Expand Down Expand Up @@ -1239,6 +1239,11 @@
<artifactId>smallrye-fault-tolerance</artifactId>
<version>${smallrye-fault-tolerance.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-fault-tolerance-context-propagation</artifactId>
<version>${smallrye-fault-tolerance.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-context-propagation</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<microprofile-health-api.version>2.1</microprofile-health-api.version>
<microprofile-config-api.version>1.3</microprofile-config-api.version>
<microprofile-metrics-api.version>2.2.1</microprofile-metrics-api.version>
<microprofile-fault-tolerance-api.version>2.0.2</microprofile-fault-tolerance-api.version>
<microprofile-fault-tolerance-api.version>2.0.3</microprofile-fault-tolerance-api.version>
<microprofile-reactive-messaging-api.version>1.0</microprofile-reactive-messaging-api.version>
<microprofile-rest-client-api.version>1.3.4</microprofile-rest-client-api.version>
<microprofile-open-api.version>1.1.2</microprofile-open-api.version>
Expand Down
6 changes: 3 additions & 3 deletions docs/src/main/asciidoc/microprofile-fault-tolerance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ Check the server output to see that fallback is really happening:

[source]
----
2019-03-06 13:21:54,170 INFO [org.acm.fau.CoffeeResource] (pool-15-thread-3) CoffeeResource#recommendations() invocation #2 returning successfully
2019-03-06 13:21:55,159 ERROR [org.acm.fau.CoffeeResource] (pool-15-thread-4) CoffeeResource#recommendations() invocation #3 timed out after 248 ms
2019-03-06 13:21:55,161 INFO [org.acm.fau.CoffeeResource] (HystrixTimer-1) Falling back to RecommendationResource#fallbackRecommendations()
2020-01-09 13:21:34,250 INFO [org.acm.fau.CoffeeResource] (executor-thread-1) CoffeeResource#recommendations() invocation #1 returning successfully
2020-01-09 13:21:36,354 ERROR [org.acm.fau.CoffeeResource] (executor-thread-1) CoffeeResource#recommendations() invocation #2 timed out after 250 ms
2020-01-09 13:21:36,355 INFO [org.acm.fau.CoffeeResource] (executor-thread-1) Falling back to RecommendationResource#fallbackRecommendations()
----

NOTE: The fallback method is required to have the same parameters as the original method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,20 @@
import org.eclipse.microprofile.faulttolerance.FallbackHandler;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.faulttolerance.Timeout;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Type;

import com.netflix.hystrix.HystrixCircuitBreaker;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem;
import io.quarkus.arc.deployment.ObserverTransformerBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
import io.quarkus.arc.processor.Annotations;
import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.arc.processor.BeanInfo;
import io.quarkus.arc.processor.BuiltinScope;
import io.quarkus.arc.processor.DotNames;
import io.quarkus.arc.processor.ObserverTransformer;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -52,27 +42,24 @@
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ConfigurationTypeBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.logging.LogCleanupFilterBuildItem;
import io.quarkus.smallrye.faulttolerance.runtime.HystrixInitializerStarter;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.smallrye.faulttolerance.runtime.NoopMetricRegistry;
import io.quarkus.smallrye.faulttolerance.runtime.QuarkusFallbackHandlerProvider;
import io.quarkus.smallrye.faulttolerance.runtime.QuarkusFaultToleranceOperationProvider;
import io.quarkus.smallrye.faulttolerance.runtime.SmallryeFaultToleranceRecorder;
import io.smallrye.faulttolerance.DefaultCommandListenersProvider;
import io.smallrye.faulttolerance.DefaultHystrixConcurrencyStrategy;
import io.smallrye.faulttolerance.HystrixCommandBinding;
import io.smallrye.faulttolerance.HystrixCommandInterceptor;
import io.smallrye.faulttolerance.HystrixInitializer;
import io.smallrye.faulttolerance.ExecutorFactory;
import io.smallrye.faulttolerance.ExecutorProvider;
import io.smallrye.faulttolerance.FaultToleranceBinding;
import io.smallrye.faulttolerance.FaultToleranceInterceptor;
import io.smallrye.faulttolerance.internal.StrategyCache;
import io.smallrye.faulttolerance.metrics.MetricsCollectorFactory;
import io.smallrye.faulttolerance.propagation.ContextPropagationExecutorFactory;

public class SmallRyeFaultToleranceProcessor {

static final DotName HYSTRIX_INITIALIZER_NAME = DotName.createSimple(HystrixInitializer.class.getName());

@Inject
BuildProducer<ReflectiveClassBuildItem> reflectiveClass;

Expand All @@ -82,19 +69,19 @@ public class SmallRyeFaultToleranceProcessor {
@Inject
CombinedIndexBuildItem combinedIndexBuildItem;

NativeImageSystemPropertyBuildItem disableJmx() {
return new NativeImageSystemPropertyBuildItem("archaius.dynamicPropertyFactory.registerConfigWithJMX", "false");
}

@BuildStep
public void build(BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformer,
BuildProducer<FeatureBuildItem> feature, BuildProducer<AdditionalBeanBuildItem> additionalBean,
BuildProducer<ServiceProviderBuildItem> serviceProvider,
BuildProducer<BeanDefiningAnnotationBuildItem> additionalBda,
Capabilities capabilities,
BuildProducer<SystemPropertyBuildItem> systemProperty) throws Exception {
BuildProducer<SystemPropertyBuildItem> systemProperty) {

feature.produce(new FeatureBuildItem(FeatureBuildItem.SMALLRYE_FAULT_TOLERANCE));

serviceProvider.produce(new ServiceProviderBuildItem(ExecutorFactory.class.getName(),
ContextPropagationExecutorFactory.class.getName()));

Set<DotName> ftAnnotations = new HashSet<>();
ftAnnotations.add(DotName.createSimple(Asynchronous.class.getName()));
ftAnnotations.add(DotName.createSimple(Bulkhead.class.getName()));
Expand Down Expand Up @@ -124,7 +111,6 @@ public void build(BuildProducer<AnnotationsTransformerBuildItem> annotationsTran
additionalBean.produce(fallbackHandlersBeans.build());
}

reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, HystrixCircuitBreaker.Factory.class.getName()));
for (DotName annotation : ftAnnotations) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, annotation.toString()));
// also make them bean defining annotations
Expand All @@ -141,7 +127,7 @@ public boolean appliesTo(Kind kind) {
@Override
public void transform(TransformationContext context) {
if (ftAnnotations.contains(context.getTarget().asClass().name())) {
context.transform().add(HystrixCommandBinding.class).done();
context.transform().add(FaultToleranceBinding.class).done();
}
}
}));
Expand All @@ -153,12 +139,12 @@ public void transform(TransformationContext context) {
for (DotName ftAnnotation : ftAnnotations) {
builder.addBeanClass(ftAnnotation.toString());
}
builder.addBeanClasses(HystrixCommandInterceptor.class, HystrixInitializer.class,
DefaultHystrixConcurrencyStrategy.class,
QuarkusFaultToleranceOperationProvider.class, QuarkusFallbackHandlerProvider.class,
DefaultCommandListenersProvider.class,
MetricsCollectorFactory.class,
HystrixInitializerStarter.class);
builder.addBeanClasses(FaultToleranceInterceptor.class,
ExecutorProvider.class,
StrategyCache.class,
QuarkusFaultToleranceOperationProvider.class,
QuarkusFallbackHandlerProvider.class,
MetricsCollectorFactory.class);
additionalBean.produce(builder.build());

if (!capabilities.isCapabilityPresent(Capabilities.METRICS)) {
Expand All @@ -173,15 +159,15 @@ public void transform(TransformationContext context) {
AnnotationsTransformerBuildItem transformInterceptorPriority(BeanArchiveIndexBuildItem index) {
return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return kind == org.jboss.jandex.AnnotationTarget.Kind.CLASS;
public boolean appliesTo(Kind kind) {
return kind == Kind.CLASS;
}

@Override
public void transform(TransformationContext ctx) {
if (ctx.isClass()) {
if (!ctx.getTarget().asClass().name().toString()
.equals("io.smallrye.faulttolerance.HystrixCommandInterceptor")) {
.equals("io.smallrye.faulttolerance.FaultToleranceInterceptor")) {
return;
}
final Config config = ConfigProvider.getConfig();
Expand Down Expand Up @@ -214,52 +200,4 @@ void validateFaultToleranceAnnotations(
public ConfigurationTypeBuildItem registerTypes() {
return new ConfigurationTypeBuildItem(ChronoUnit.class);
}

@BuildStep
public void logCleanup(BuildProducer<LogCleanupFilterBuildItem> logCleanupFilter) {
logCleanupFilter.produce(new LogCleanupFilterBuildItem("io.smallrye.faulttolerance.HystrixInitializer",
"### Init Hystrix ###",
"### Reset Hystrix ###",
// no need to log the strategy if it is the default
"Hystrix concurrency strategy used: DefaultHystrixConcurrencyStrategy"));
logCleanupFilter.produce(new LogCleanupFilterBuildItem("io.smallrye.faulttolerance.DefaultHystrixConcurrencyStrategy",
"### Privilleged Thread Factory used ###"));

logCleanupFilter.produce(new LogCleanupFilterBuildItem("com.netflix.config.sources.URLConfigurationSource",
"No URLs will be polled as dynamic configuration sources.",
"To enable URLs as dynamic configuration sources"));
logCleanupFilter.produce(new LogCleanupFilterBuildItem("com.netflix.config.DynamicPropertyFactory",
"DynamicPropertyFactory is initialized with configuration sources"));
}

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
public void clearStatic(SmallryeFaultToleranceRecorder recorder, ShutdownContextBuildItem context,
BeanContainerBuildItem beanContainer) {
// impl note - we depend on BeanContainerBuildItem to make sure Arc registers before SR FT
// this is needed so that shutdown context of FT is executed before Arc container shuts down
recorder.resetCommandContextOnUndeploy(context);
}

@BuildStep
ObserverTransformerBuildItem vetoHystrixInitializerObserver() {
return new ObserverTransformerBuildItem(new ObserverTransformer() {

@Override
public boolean appliesTo(Type observedType, Set<AnnotationInstance> qualifiers) {
AnnotationInstance initialized = Annotations.find(Annotations.getParameterAnnotations(qualifiers),
DotNames.INITIALIZED);
return initialized != null ? initialized.value().asClass().name().equals(BuiltinScope.APPLICATION.getName())
: false;
}

@Override
public void transform(TransformationContext context) {
if (context.getMethod().declaringClass().name().equals(HYSTRIX_INITIALIZER_NAME)) {
context.veto();
}
}

});
}
}

This file was deleted.

8 changes: 2 additions & 6 deletions extensions/smallrye-fault-tolerance/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-context-propagation-propagators-rxjava1</artifactId>
</dependency>
<!-- to avoid dependency divergence between Hystrix and SR Context Propagation-->
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
<artifactId>smallrye-fault-tolerance-context-propagation</artifactId>
</dependency>

</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,12 @@

import org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException;

import com.netflix.hystrix.Hystrix;
import com.netflix.hystrix.metric.HystrixCollapserEventStream;
import com.netflix.hystrix.metric.HystrixCommandCompletionStream;
import com.netflix.hystrix.metric.HystrixCommandStartStream;
import com.netflix.hystrix.metric.HystrixThreadEventStream;
import com.netflix.hystrix.metric.HystrixThreadPoolCompletionStream;

import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.smallrye.faulttolerance.config.FaultToleranceOperation;

@Recorder
public class SmallryeFaultToleranceRecorder {

public void resetCommandContextOnUndeploy(ShutdownContext context) {
context.addShutdownTask(new Runnable() {
@Override
public void run() {
HystrixCommandCompletionStream.reset();
HystrixCollapserEventStream.reset();
HystrixCommandStartStream.reset();
HystrixThreadPoolCompletionStream.reset();
HystrixCommandStartStream.reset();
HystrixThreadEventStream.getInstance().shutdown();
Hystrix.reset();
}
});
}

public void validate(List<String> beanNames) {
List<Throwable> allExceptions = new ArrayList<>();
for (String beanName : beanNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,12 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.configuration.AbstractConfiguration;

import com.netflix.config.jmx.ConfigMBean;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

public class FaultToleranceSubstitutions {
}

@TargetClass(className = "com.netflix.config.jmx.ConfigJMXManager")
final class Target_com_netflix_config_jmx_ConfigJMXManager {

@Substitute
public static ConfigMBean registerConfigMbean(AbstractConfiguration config) {
return null;
}

@Substitute
public static void unRegisterConfigMBean(AbstractConfiguration config, ConfigMBean mbean) {

}
}

@TargetClass(className = "io.smallrye.faulttolerance.DefaultMethodFallbackProvider")
final class Target_io_smallrye_faulttolerance_DefaultMethodFallbackProvider {

Expand Down
6 changes: 0 additions & 6 deletions tcks/microprofile-fault-tolerance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<systemPropertyVariables>
<!-- Disable quarkus optimization -->
<quarkus.arc.remove-unused-beans>false</quarkus.arc.remove-unused-beans>
<io_smallrye_faulttolerance_asyncTimeout>true</io_smallrye_faulttolerance_asyncTimeout>
</systemPropertyVariables>
<!-- This workaround allows us to run a single test using
the "test" system property -->
Expand All @@ -33,11 +32,6 @@
<excludes>
<!-- We do not support enablement via beans.xml -->
<exclude>org.eclipse.microprofile.fault.tolerance.tck.interceptor.xmlInterceptorEnabling.FaultToleranceInterceptorEnableByXmlTest</exclude>

<!-- https://github.com/eclipse/microprofile-fault-tolerance/issues/408 -->
<!-- Hystrix is unable to interrupt the calling thread, as it didn't create it. -->
<!-- We have a custom version of this TCK class that excludes TimeoutUninterruptableTest.testTimeout() as all the other methods pass -->
<exclude>org.eclipse.microprofile.fault.tolerance.tck.TimeoutUninterruptableTest</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.quarkus.smallrye.faulttolerance;

// We need this class so that target/test-classes is added to the class path?
public class Dummy {

}
Loading