Quellcode durchsuchen

sentinel-1.8.6源码改造上传
改造内容查看 SOURCE_MODIFICATION.md

lengfaqiang vor 2 Jahren
Ursprung
Commit
6db628e888
11 geänderte Dateien mit 710 neuen und 0 gelöschten Zeilen
  1. 72 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/pom.xml
  2. 46 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/main/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/SentinelAnnotationQuarkusAdapterProcessor.java
  3. 84 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/test/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/FooService.java
  4. 37 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/test/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/FooUtil.java
  5. 195 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/test/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/SentinelAnnotationQuarkusAdapterTest.java
  6. 63 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-runtime/pom.xml
  7. 73 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-deployment/src/main/java/com/alibaba/csp/sentinel/adapter/quarkus/nativeimage/SentinelNativeImageProcessor.java
  8. 75 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-runtime/pom.xml
  9. 52 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-runtime/src/main/java/com/alibaba/csp/sentinel/adapter/quarkus/nativeimage/SentinelRecorder.java
  10. 13 0
      sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-runtime/src/main/resources/META-INF/quarkus-extension.yaml
  11. BIN
      sentinel-demo/sentinel-demo-quarkus/.mvn/wrapper/maven-wrapper.jar

+ 72 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/pom.xml

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.alibaba.csp</groupId>
+        <artifactId>sentinel-quarkus-adapter-parent</artifactId>
+        <version>1.8.6</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>sentinel-annotation-quarkus-adapter-deployment</artifactId>
+    <name>sentinel-annotation-quarkus-adapter-deployment</name>
+
+    <properties>
+        <java.source.version>1.8</java.source.version>
+        <java.target.version>1.8</java.target.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-core-deployment</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-arc-deployment</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-annotation-quarkus-adapter</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Test dependencies -->
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit5-internal</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-arc-deployment</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            <artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 46 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/main/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/SentinelAnnotationQuarkusAdapterProcessor.java

@@ -0,0 +1,46 @@
+/*
+ * Copyright 1999-2020 Alibaba Group Holding Ltd.
+ *
+ * Licensed 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
+ *
+ *      https://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 com.alibaba.csp.sentinel.adapter.quarkus.annotation.deployment;
+
+import com.alibaba.csp.sentinel.annotation.cdi.interceptor.SentinelResourceInterceptor;
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author sea
+ */
+class SentinelAnnotationQuarkusAdapterProcessor {
+
+    private static final String FEATURE_ANNOTATION = "sentinel-annotation";
+
+    @BuildStep
+    void feature(BuildProducer<FeatureBuildItem> featureProducer) {
+        featureProducer.produce(new FeatureBuildItem(FEATURE_ANNOTATION));
+    }
+
+    @BuildStep
+    List<AdditionalBeanBuildItem> additionalBeans() {
+        return Arrays.asList(
+                new AdditionalBeanBuildItem(SentinelResourceInterceptor.class)
+        );
+    }
+
+}

+ 84 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/test/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/FooService.java

@@ -0,0 +1,84 @@
+/*
+ * Copyright 1999-2020 Alibaba Group Holding Ltd.
+ *
+ * Licensed 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 com.alibaba.csp.sentinel.adapter.quarkus.annotation.deployment;
+import com.alibaba.csp.sentinel.annotation.cdi.interceptor.SentinelResourceBinding;
+import com.alibaba.csp.sentinel.slots.block.BlockException;
+
+import javax.enterprise.context.ApplicationScoped;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * @author Eric Zhao
+ * @author sea
+ */
+@ApplicationScoped
+public class FooService {
+
+    @SentinelResourceBinding(value = "apiFoo", blockHandler = "fooBlockHandler",
+        exceptionsToTrace = {IllegalArgumentException.class})
+    public String foo(int i) throws Exception {
+        if (i == 5758) {
+            throw new IllegalAccessException();
+        }
+        if (i == 5763) {
+            throw new IllegalArgumentException();
+        }
+        return "Hello for " + i;
+    }
+
+    @SentinelResourceBinding(value = "apiFooWithFallback", blockHandler = "fooBlockHandler", fallback = "fooFallbackFunc",
+        exceptionsToTrace = {IllegalArgumentException.class})
+    public String fooWithFallback(int i) throws Exception {
+        if (i == 5758) {
+            throw new IllegalAccessException();
+        }
+        if (i == 5763) {
+            throw new IllegalArgumentException();
+        }
+        return "Hello for " + i;
+    }
+
+    @SentinelResourceBinding(value = "apiAnotherFooWithDefaultFallback", defaultFallback = "globalDefaultFallback",
+        fallbackClass = {FooUtil.class})
+    public String anotherFoo(int i) {
+        if (i == 5758) {
+            throw new IllegalArgumentException("oops");
+        }
+        return "Hello for " + i;
+    }
+
+    @SentinelResourceBinding(blockHandler = "globalBlockHandler", blockHandlerClass = FooUtil.class)
+    public int random() {
+        return ThreadLocalRandom.current().nextInt(0, 30000);
+    }
+
+    @SentinelResourceBinding(value = "apiBaz", blockHandler = "bazBlockHandler",
+            exceptionsToIgnore = {IllegalMonitorStateException.class})
+    public String baz(String name) {
+        if (name.equals("fail")) {
+            throw new IllegalMonitorStateException("boom!");
+        }
+        return "cheers, " + name;
+    }
+
+    public String fooBlockHandler(int i, BlockException ex) {
+        return "Oops, " + i;
+    }
+
+    public String fooFallbackFunc(int i) {
+        return "eee...";
+    }
+}

+ 37 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/test/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/FooUtil.java

@@ -0,0 +1,37 @@
+/*
+ * Copyright 1999-2020 Alibaba Group Holding Ltd.
+ *
+ * Licensed 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 com.alibaba.csp.sentinel.adapter.quarkus.annotation.deployment;
+
+import com.alibaba.csp.sentinel.slots.block.BlockException;
+
+/**
+ * @author Eric Zhao
+ */
+public class FooUtil {
+
+    public static final int BLOCK_FLAG = 88888;
+    public static final String FALLBACK_DEFAULT_RESULT = "fallback";
+
+    public static int globalBlockHandler(BlockException ex) {
+        System.out.println("Oops: " + ex.getClass().getSimpleName());
+        return BLOCK_FLAG;
+    }
+
+    public static String globalDefaultFallback(Throwable t) {
+        System.out.println("Fallback caught: " + t.getClass().getSimpleName());
+        return FALLBACK_DEFAULT_RESULT;
+    }
+}

+ 195 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-deployment/src/test/java/com/alibaba/csp/sentinel/adapter/quarkus/annotation/deployment/SentinelAnnotationQuarkusAdapterTest.java

@@ -0,0 +1,195 @@
+/*
+ * Copyright 1999-2020 Alibaba Group Holding Ltd.
+ *
+ * Licensed 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
+ *
+ *      https://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 com.alibaba.csp.sentinel.adapter.quarkus.annotation.deployment;
+
+import com.alibaba.csp.sentinel.node.ClusterNode;
+import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
+import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
+import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot;
+import com.alibaba.csp.sentinel.util.MethodUtil;
+import io.quarkus.arc.ArcUndeclaredThrowableException;
+import io.quarkus.test.QuarkusUnitTest;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * @author sea
+ */
+public class SentinelAnnotationQuarkusAdapterTest {
+
+    @RegisterExtension
+    static final QuarkusUnitTest TEST = new QuarkusUnitTest()
+            .setArchiveProducer(() -> ShrinkWrap
+                    .create(JavaArchive.class)
+                    .addClasses(FooService.class, FooUtil.class)
+                    .addPackage("com.alibaba.csp.sentinel.annotation.cdi.interceptor")
+            );
+
+    @Inject
+    FooService fooService;
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        FlowRuleManager.loadRules(new ArrayList<FlowRule>());
+        ClusterBuilderSlot.resetClusterNodes();
+    }
+
+    @AfterEach
+    public void tearDown() throws Exception {
+        FlowRuleManager.loadRules(new ArrayList<FlowRule>());
+        ClusterBuilderSlot.resetClusterNodes();
+    }
+
+    @Test
+    public void testForeignBlockHandlerClass() throws Exception {
+        assertThat(fooService.random()).isNotEqualTo(FooUtil.BLOCK_FLAG);
+        String resourceName = MethodUtil.resolveMethodName(FooService.class.getDeclaredMethod("random"));
+        ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
+        assertThat(cn).isNotNull();
+        assertThat(cn.passQps()).isPositive();
+
+        FlowRuleManager.loadRules(Collections.singletonList(
+                new FlowRule(resourceName).setCount(0)
+        ));
+        assertThat(fooService.random()).isEqualTo(FooUtil.BLOCK_FLAG);
+        assertThat(cn.blockQps()).isPositive();
+    }
+
+    @Test
+    public void testBlockHandlerNotFound() {
+        assertThat(fooService.baz("Sentinel")).isEqualTo("cheers, Sentinel");
+        String resourceName = "apiBaz";
+        ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
+        assertThat(cn).isNotNull();
+        assertThat(cn.passQps()).isPositive();
+
+        FlowRuleManager.loadRules(Collections.singletonList(
+                new FlowRule(resourceName).setCount(0)
+        ));
+
+        assertThrows(ArcUndeclaredThrowableException.class, () -> {
+            fooService.baz("Sentinel");
+        });
+    }
+
+    @Test
+    public void testAnnotationExceptionsToIgnore() {
+        assertThat(fooService.baz("Sentinel")).isEqualTo("cheers, Sentinel");
+        String resourceName = "apiBaz";
+        ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
+        assertThat(cn).isNotNull();
+        assertThat(cn.passQps()).isPositive();
+        assertThrows(IllegalMonitorStateException.class, () -> {
+            fooService.baz("fail");
+        });
+        assertThat(cn.exceptionQps()).isZero();
+    }
+
+    @Test
+    public void testFallbackWithNoParams() throws Exception {
+        assertThat(fooService.fooWithFallback(1)).isEqualTo("Hello for 1");
+        String resourceName = "apiFooWithFallback";
+        ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
+        assertThat(cn).isNotNull();
+        assertThat(cn.passQps()).isPositive();
+
+        // Fallback should be ignored for this.
+        try {
+            fooService.fooWithFallback(5758);
+            fail("should not reach here");
+        } catch (IllegalAccessException e) {
+            assertThat(cn.exceptionQps()).isZero();
+        }
+
+        // Fallback should take effect.
+        assertThat(fooService.fooWithFallback(5763)).isEqualTo("eee...");
+        assertThat(cn.exceptionQps()).isPositive();
+        assertThat(cn.blockQps()).isZero();
+
+        FlowRuleManager.loadRules(Collections.singletonList(
+                new FlowRule(resourceName).setCount(0)
+        ));
+        // Fallback should not take effect for BlockException, as blockHandler is configured.
+        assertThat(fooService.fooWithFallback(2221)).isEqualTo("Oops, 2221");
+        assertThat(cn.blockQps()).isPositive();
+    }
+
+    @Test
+    public void testDefaultFallbackWithSingleParam() {
+        assertThat(fooService.anotherFoo(1)).isEqualTo("Hello for 1");
+        String resourceName = "apiAnotherFooWithDefaultFallback";
+        ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
+        assertThat(cn).isNotNull();
+        assertThat(cn.passQps()).isPositive();
+
+        // Default fallback should take effect.
+        assertThat(fooService.anotherFoo(5758)).isEqualTo(FooUtil.FALLBACK_DEFAULT_RESULT);
+        assertThat(cn.exceptionQps()).isPositive();
+        assertThat(cn.blockQps()).isZero();
+
+        FlowRuleManager.loadRules(Collections.singletonList(
+                new FlowRule(resourceName).setCount(0)
+        ));
+        // Default fallback should also take effect for BlockException.
+        assertThat(fooService.anotherFoo(5758)).isEqualTo(FooUtil.FALLBACK_DEFAULT_RESULT);
+        assertThat(cn.blockQps()).isPositive();
+    }
+
+    @Test
+    public void testNormalBlockHandlerAndFallback() throws Exception {
+        assertThat(fooService.foo(1)).isEqualTo("Hello for 1");
+        String resourceName = "apiFoo";
+        ClusterNode cn = ClusterBuilderSlot.getClusterNode(resourceName);
+        assertThat(cn).isNotNull();
+        assertThat(cn.passQps()).isPositive();
+
+        // Test for biz exception.
+        try {
+            fooService.foo(5758);
+            fail("should not reach here");
+        } catch (Exception ex) {
+            // Should not be traced.
+            assertThat(cn.exceptionQps()).isZero();
+        }
+
+        try {
+            fooService.foo(5763);
+            fail("should not reach here");
+        } catch (Exception ex) {
+            assertThat(cn.exceptionQps()).isPositive();
+        }
+
+        // Test for blockHandler
+        FlowRuleManager.loadRules(Collections.singletonList(
+                new FlowRule(resourceName).setCount(0)
+        ));
+        assertThat(fooService.foo(1121)).isEqualTo("Oops, 1121");
+        assertThat(cn.blockQps()).isPositive();
+    }
+}

+ 63 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-annotation-quarkus-adapter-runtime/pom.xml

@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.alibaba.csp</groupId>
+        <artifactId>sentinel-quarkus-adapter-parent</artifactId>
+        <version>1.8.6</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>sentinel-annotation-quarkus-adapter</artifactId>
+    <name>sentinel-annotation-quarkus-adapter</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-core</artifactId>
+            <version>${quarkus.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-annotation-cdi-interceptor</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>io.quarkus</groupId>
+                <artifactId>quarkus-bootstrap-maven-plugin</artifactId>
+                <version>${quarkus.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>extension-descriptor</goal>
+                        </goals>
+                        <phase>compile</phase>
+                        <configuration>
+                            <deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
+                            </deployment>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            <artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 73 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-deployment/src/main/java/com/alibaba/csp/sentinel/adapter/quarkus/nativeimage/SentinelNativeImageProcessor.java

@@ -0,0 +1,73 @@
+/*
+ * Copyright 1999-2020 Alibaba Group Holding Ltd.
+ *
+ * Licensed 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
+ *
+ *      https://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 com.alibaba.csp.sentinel.adapter.quarkus.nativeimage;
+
+import com.alibaba.csp.sentinel.slots.DefaultSlotChainBuilder;
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.annotations.ExecutionTime;
+import io.quarkus.deployment.annotations.Record;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author sea
+ */
+class SentinelNativeImageProcessor {
+
+    private static final String FEATURE_NATIVE_IMAGE = "sentinel-native-image";
+
+    @BuildStep
+    void feature(BuildProducer<FeatureBuildItem> featureProducer) {
+        featureProducer.produce(new FeatureBuildItem(FEATURE_NATIVE_IMAGE));
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    List<RuntimeInitializedClassBuildItem> runtimeInitializedClasses() {
+        return Arrays.asList(
+                new RuntimeInitializedClassBuildItem("com.alibaba.fastjson.serializer.JodaCodec"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.fastjson.serializer.GuavaCodec"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.fastjson.support.moneta.MonetaCodec"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.Env"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.init.InitExecutor"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.cluster.ClusterStateManager"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.node.metric.MetricTimerListener"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.node.metric.MetricWriter"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.util.TimeUtil"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.eagleeye.StatLogController"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.slots.logger.EagleEyeLogUtil"),
+                new RuntimeInitializedClassBuildItem("com.alibaba.csp.sentinel.eagleeye.EagleEye"));
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    ReflectiveClassBuildItem setupSentinelReflectiveClasses() {
+        return new ReflectiveClassBuildItem(true, true, true,
+                DefaultSlotChainBuilder.class.getName());
+    }
+
+    @BuildStep(onlyIf = NativeBuild.class)
+    @Record(ExecutionTime.STATIC_INIT)
+    void record(SentinelRecorder recorder) {
+        recorder.init();
+    }
+}

+ 75 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-runtime/pom.xml

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.alibaba.csp</groupId>
+        <artifactId>sentinel-quarkus-adapter-parent</artifactId>
+        <version>1.8.6</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>sentinel-native-image-quarkus-adapter</artifactId>
+    <name>sentinel-native-image-quarkus-adapter</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-core</artifactId>
+            <version>${quarkus.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.graalvm.nativeimage</groupId>
+            <artifactId>svm</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-transport-simple-http</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-parameter-flow-control</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.csp</groupId>
+            <artifactId>sentinel-logging-slf4j</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>io.quarkus</groupId>
+                <artifactId>quarkus-bootstrap-maven-plugin</artifactId>
+                <version>${quarkus.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>extension-descriptor</goal>
+                        </goals>
+                        <phase>compile</phase>
+                        <configuration>
+                            <deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
+                            </deployment>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <annotationProcessorPaths>
+                        <path>
+                            <groupId>io.quarkus</groupId>
+                            <artifactId>quarkus-extension-processor</artifactId>
+                            <version>${quarkus.version}</version>
+                        </path>
+                    </annotationProcessorPaths>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 52 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-runtime/src/main/java/com/alibaba/csp/sentinel/adapter/quarkus/nativeimage/SentinelRecorder.java

@@ -0,0 +1,52 @@
+/*
+ * Copyright 1999-2020 Alibaba Group Holding Ltd.
+ *
+ * Licensed 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
+ *
+ *      https://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 com.alibaba.csp.sentinel.adapter.quarkus.nativeimage;
+
+import com.alibaba.csp.sentinel.command.vo.NodeVo;
+import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
+import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
+import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
+import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
+import com.alibaba.csp.sentinel.slots.system.SystemRule;
+import com.alibaba.fastjson.parser.ParserConfig;
+import com.alibaba.fastjson.serializer.SerializeConfig;
+import io.quarkus.runtime.annotations.Recorder;
+
+/**
+ * @author sea
+ */
+@Recorder
+public class SentinelRecorder {
+
+    /**
+     * register fastjson serializer deserializer class info
+     */
+    public void init() {
+        SerializeConfig.getGlobalInstance().getObjectWriter(NodeVo.class);
+        SerializeConfig.getGlobalInstance().getObjectWriter(FlowRule.class);
+        SerializeConfig.getGlobalInstance().getObjectWriter(SystemRule.class);
+        SerializeConfig.getGlobalInstance().getObjectWriter(DegradeRule.class);
+        SerializeConfig.getGlobalInstance().getObjectWriter(AuthorityRule.class);
+        SerializeConfig.getGlobalInstance().getObjectWriter(ParamFlowRule.class);
+
+        ParserConfig.getGlobalInstance().getDeserializer(NodeVo.class);
+        ParserConfig.getGlobalInstance().getDeserializer(FlowRule.class);
+        ParserConfig.getGlobalInstance().getDeserializer(SystemRule.class);
+        ParserConfig.getGlobalInstance().getDeserializer(DegradeRule.class);
+        ParserConfig.getGlobalInstance().getDeserializer(AuthorityRule.class);
+        ParserConfig.getGlobalInstance().getDeserializer(ParamFlowRule.class);
+    }
+}

+ 13 - 0
sentinel-adapter/sentinel-quarkus-adapter/sentinel-native-image-quarkus-adapter-runtime/src/main/resources/META-INF/quarkus-extension.yaml

@@ -0,0 +1,13 @@
+---
+name: "Sentinel native image extension"
+metadata:
+  keywords:
+    - "sentinel"
+    - "rate-limiting"
+    - "circuit-breaker"
+    - "native-image"
+    - "fault-tolerance"
+  categories:
+    - "cloud"
+    - "fault-tolerance"
+  status: "preview"

BIN
sentinel-demo/sentinel-demo-quarkus/.mvn/wrapper/maven-wrapper.jar