diff --git a/sentinel-adapter/pom.xml b/sentinel-adapter/pom.xml index 4b419af6..b239b04f 100755 --- a/sentinel-adapter/pom.xml +++ b/sentinel-adapter/pom.xml @@ -18,7 +18,6 @@ sentinel-web-servlet sentinel-dubbo-adapter sentinel-grpc-adapter - sentinel-spring-boot-starter diff --git a/sentinel-adapter/sentinel-spring-boot-starter/README.md b/sentinel-adapter/sentinel-spring-boot-starter/README.md deleted file mode 100755 index 83560f54..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Sentinel Spring Boot Starter - -Sentinel Spring Boot Starter provides out-of-box integration with Spring Boot applications -(e.g. web applications, Dubbo services). - -## Web Servlet - -Web servlet integration is enabled by default. You need to configure URL patterns in your config file (e.g. properties file): - -``` -spring.sentinel.servletFilter.urlPatterns=/* -``` - -By default the URL pattern is `/*`. - -## Dubbo - -Dubbo integration is enabled by default. You need to disable the filters manually if you don't want them. \ No newline at end of file diff --git a/sentinel-adapter/sentinel-spring-boot-starter/pom.xml b/sentinel-adapter/sentinel-spring-boot-starter/pom.xml deleted file mode 100755 index 5a592a26..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - sentinel-adapter - com.alibaba.csp - 0.1.1-SNAPSHOT - - 4.0.0 - jar - - sentinel-spring-boot-starter - - - 1.5.14.RELEASE - - - - - com.alibaba.csp - sentinel-core - ${project.version} - - - com.alibaba.csp - sentinel-transport-simple-http - ${project.version} - - - com.alibaba.csp - sentinel-web-servlet - ${project.version} - - - com.alibaba.csp - sentinel-dubbo-adapter - ${project.version} - - - - org.slf4j - slf4j-api - 1.7.25 - compile - - - - org.springframework.boot - spring-boot-starter - ${spring.boot.version} - compile - - - org.springframework.boot - spring-boot-autoconfigure - ${spring.boot.version} - compile - - - org.springframework.boot - spring-boot-configuration-processor - ${spring.boot.version} - compile - true - - - org.springframework.boot - spring-boot-starter-web - ${spring.boot.version} - provided - true - - - org.springframework.boot - spring-boot-actuator - ${spring.boot.version} - compile - true - - - - org.springframework.boot - spring-boot-starter-test - ${spring.boot.version} - test - - - junit - junit - ${junit.version} - test - - - \ No newline at end of file diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/Constants.java b/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/Constants.java deleted file mode 100755 index bfb98e05..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/Constants.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 1999-2018 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.boot.sentinel; - -/** - * @author Eric Zhao - */ -public final class Constants { - - /** - * Property prefix in application.properties. - */ - public static final String PREFIX = "spring.sentinel"; - public static final String SENTINEL_SERVLET_ENABLED = "spring.sentinel.servletFilter.enabled"; - public static final String SENTINEL_ENABLED = "spring.sentinel.enabled"; - - private Constants() {} -} diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/config/SentinelWebServletAutoConfiguration.java b/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/config/SentinelWebServletAutoConfiguration.java deleted file mode 100755 index f996fbeb..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/config/SentinelWebServletAutoConfiguration.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 1999-2018 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.boot.sentinel.config; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.Filter; - -import com.alibaba.boot.sentinel.Constants; -import com.alibaba.boot.sentinel.property.SentinelProperties; -import com.alibaba.boot.sentinel.property.SentinelProperties.ServletFilterConfig; -import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.CollectionUtils; - -/** - * Auto configuration for Sentinel web servlet filter. - * - * @author Eric Zhao - */ -@Configuration -@ConditionalOnWebApplication -@ConditionalOnProperty(name = {Constants.SENTINEL_ENABLED, Constants.SENTINEL_SERVLET_ENABLED}, matchIfMissing = true) -@EnableConfigurationProperties(SentinelProperties.class) -public class SentinelWebServletAutoConfiguration { - - private final Logger logger = LoggerFactory.getLogger(SentinelWebServletAutoConfiguration.class); - - @Autowired - private SentinelProperties properties; - - @Bean - @ConditionalOnWebApplication - public FilterRegistrationBean sentinelFilterRegistrationBean() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean(); - if (!properties.isEnabled()) { - return registrationBean; - } - - ServletFilterConfig filterConfig = properties.getServletFilter(); - if (null == filterConfig) { - filterConfig = new ServletFilterConfig(); - properties.setServletFilter(filterConfig); - } - - if (CollectionUtils.isEmpty(filterConfig.getUrlPatterns())) { - List defaultPatterns = new ArrayList(); - defaultPatterns.add("/*"); - filterConfig.setUrlPatterns(defaultPatterns); - logger.info("[Sentinel Starter] Using default patterns for web servlet filter: {}", defaultPatterns); - } - registrationBean.addUrlPatterns(filterConfig.getUrlPatterns().toArray(new String[0])); - - Filter filter = new CommonFilter(); - registrationBean.setFilter(filter); - registrationBean.setOrder(filterConfig.getOrder()); - - logger.info("[Sentinel Starter] Web servlet filter registered with urlPatterns: {}", - filterConfig.getUrlPatterns()); - return registrationBean; - } -} diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/endpoint/SentinelActuatorEndpoint.java b/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/endpoint/SentinelActuatorEndpoint.java deleted file mode 100755 index 7dd14ae5..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/endpoint/SentinelActuatorEndpoint.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 1999-2018 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.boot.sentinel.endpoint; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.alibaba.boot.sentinel.property.SentinelProperties; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; -import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; -import com.alibaba.csp.sentinel.slots.system.SystemRule; -import com.alibaba.csp.sentinel.slots.system.SystemRuleManager; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -/** - * @author duanling - * @author Eric Zhao - */ -@ConfigurationProperties("endpoints.sentinel") -public class SentinelActuatorEndpoint extends AbstractMvcEndpoint { - - @Autowired - private SentinelProperties sentinelProperties; - - public SentinelActuatorEndpoint() { - super("/sentinel", false); - } - - @RequestMapping - @ResponseBody - public Map invoke() { - Map result = new HashMap(); - - result.put("version", this.getClass().getPackage().getImplementationVersion()); - result.put("properties", sentinelProperties); - - List flowRules = FlowRuleManager.getRules(); - List degradeRules = DegradeRuleManager.getRules(); - List systemRules = SystemRuleManager.getRules(); - - result.put("flowRules", flowRules); - result.put("degradeRules", degradeRules); - result.put("systemRules", systemRules); - - return result; - } -} diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/endpoint/SentinelEndpointManagementContextConfiguration.java b/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/endpoint/SentinelEndpointManagementContextConfiguration.java deleted file mode 100755 index 3f1054ae..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/endpoint/SentinelEndpointManagementContextConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 1999-2018 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.boot.sentinel.endpoint; - -import com.alibaba.boot.sentinel.property.SentinelProperties; - -import org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration; -import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; - -/** - * @author duanling - */ -@ManagementContextConfiguration -@EnableConfigurationProperties({SentinelProperties.class}) -public class SentinelEndpointManagementContextConfiguration { - - @Bean - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint("sentinel") - public SentinelActuatorEndpoint sentinelEndPoint() { - return new SentinelActuatorEndpoint(); - } -} diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/property/SentinelProperties.java b/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/property/SentinelProperties.java deleted file mode 100755 index bdd281d2..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/java/com/alibaba/boot/sentinel/property/SentinelProperties.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 1999-2018 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.boot.sentinel.property; - -import java.util.List; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.core.Ordered; - -/** - * @author Eric Zhao - */ -@ConfigurationProperties(prefix = "spring.sentinel") -public class SentinelProperties { - - private boolean enabled = true; - - private ServletFilterConfig servletFilter; - - public boolean isEnabled() { - return enabled; - } - - public SentinelProperties setEnabled(boolean enabled) { - this.enabled = enabled; - return this; - } - - public ServletFilterConfig getServletFilter() { - return servletFilter; - } - - public SentinelProperties setServletFilter( - ServletFilterConfig servletFilter) { - this.servletFilter = servletFilter; - return this; - } - - public static class DubboFilterConfig {} - - public static class ServletFilterConfig { - - private boolean enabled = true; - - /** - * Chain order for Sentinel servlet filter. - */ - private int order = Ordered.HIGHEST_PRECEDENCE; - - /** - * URL pattern for Sentinel servlet filter. - */ - private List urlPatterns; - - public int getOrder() { - return this.order; - } - - public void setOrder(int order) { - this.order = order; - } - - public List getUrlPatterns() { - return urlPatterns; - } - - public void setUrlPatterns(List urlPatterns) { - this.urlPatterns = urlPatterns; - } - - public boolean isEnabled() { - return enabled; - } - - public ServletFilterConfig setEnabled(boolean enabled) { - this.enabled = enabled; - return this; - } - } -} diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/resources/META-INF/spring.factories b/sentinel-adapter/sentinel-spring-boot-starter/src/main/resources/META-INF/spring.factories deleted file mode 100755 index 15992e33..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,5 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.alibaba.boot.sentinel.config.SentinelWebServletAutoConfiguration - -org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=\ -com.alibaba.boot.sentinel.endpoint.SentinelEndpointManagementContextConfiguration \ No newline at end of file diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/main/resources/META-INF/spring.provides b/sentinel-adapter/sentinel-spring-boot-starter/src/main/resources/META-INF/spring.provides deleted file mode 100755 index 10a1f7ae..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/main/resources/META-INF/spring.provides +++ /dev/null @@ -1 +0,0 @@ -provides: sentinel-core \ No newline at end of file diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/test/java/com/alibaba/boot/sentinel/SimpleWebApplication.java b/sentinel-adapter/sentinel-spring-boot-starter/src/test/java/com/alibaba/boot/sentinel/SimpleWebApplication.java deleted file mode 100755 index 572b02c2..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/test/java/com/alibaba/boot/sentinel/SimpleWebApplication.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 1999-2018 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.boot.sentinel; - -import com.alibaba.csp.sentinel.node.ClusterNode; -import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author Eric Zhao - */ -@SpringBootApplication -@RestController -@PropertySource("classpath:web-servlet.properties") -public class SimpleWebApplication { - - @RequestMapping("/foo") - public String foo() { - return "Hello!"; - } - - @RequestMapping("/baz") - public String baz() { - ClusterNode node = ClusterBuilderSlot.getClusterNode("/foo"); - if (node == null) { - return "/foo has not been called!"; - } else { - return "/foo total request in metrics: " + node.totalRequest(); - } - } - - public static void main(String[] args) { - SpringApplication.run(SimpleWebApplication.class, args); - } -} diff --git a/sentinel-adapter/sentinel-spring-boot-starter/src/test/resources/web-servlet.properties b/sentinel-adapter/sentinel-spring-boot-starter/src/test/resources/web-servlet.properties deleted file mode 100755 index 41eb21a2..00000000 --- a/sentinel-adapter/sentinel-spring-boot-starter/src/test/resources/web-servlet.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.sentinel.enabled=true -spring.sentinel.servletFilter.enabled=true -spring.sentinel.servletFilter.urlPatterns=/foo \ No newline at end of file