mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
sync code in edgware
This commit is contained in:
parent
9aaa0f91fd
commit
2dc4061c58
@ -16,7 +16,7 @@
|
||||
<description>Spring Cloud Alibaba Dependencies</description>
|
||||
|
||||
<properties>
|
||||
<sentinel.version>1.6.0</sentinel.version>
|
||||
<sentinel.version>1.6.1</sentinel.version>
|
||||
<oss.version>3.1.0</oss.version>
|
||||
<nacos.version>1.0.0</nacos.version>
|
||||
<fescar.version>0.4.2</fescar.version>
|
||||
|
@ -40,7 +40,12 @@ public class NacosConfigEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
private final NacosRefreshHistory refreshHistory;
|
||||
|
||||
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>(){
|
||||
@Override
|
||||
protected DateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
public NacosConfigEndpoint(NacosConfigProperties properties,
|
||||
NacosRefreshHistory refreshHistory) {
|
||||
@ -60,7 +65,7 @@ public class NacosConfigEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
for (NacosPropertySource ps : all) {
|
||||
Map<String, Object> source = new HashMap<>(16);
|
||||
source.put("dataId", ps.getDataId());
|
||||
source.put("lastSynced", dateFormat.format(ps.getTimestamp()));
|
||||
source.put("lastSynced", dateFormat.get().format(ps.getTimestamp()));
|
||||
sources.add(source);
|
||||
}
|
||||
result.put("Sources", sources);
|
||||
|
@ -27,10 +27,15 @@ public class NacosRefreshHistory {
|
||||
|
||||
private LinkedList<Record> records = new LinkedList<>();
|
||||
|
||||
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>(){
|
||||
@Override
|
||||
protected DateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
public void add(String dataId, String md5) {
|
||||
records.addFirst(new Record(dateFormat.format(new Date()), dataId, md5));
|
||||
records.addFirst(new Record(dateFormat.get().format(new Date()), dataId, md5));
|
||||
if (records.size() > MAX_SIZE) {
|
||||
records.removeLast();
|
||||
}
|
||||
|
@ -16,17 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.alibaba.nacos;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alibaba.nacos.discovery.NacosDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.alibaba.nacos.registry.NacosAutoServiceRegistration;
|
||||
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration;
|
||||
import org.springframework.cloud.alibaba.nacos.registry.NacosServiceRegistry;
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cloud.alibaba.sentinel.zuul;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public interface ConfigConstants {
|
||||
|
||||
String APP_TYPE_ZUUL_GATEWAY = "12";
|
||||
|
||||
String ZUUl_PREFIX = "spring.cloud.sentinel.zuul";
|
||||
|
||||
String GATEWAY_PREFIX = "spring.cloud.sentinel.scg";
|
||||
|
||||
String FALLBACK_MSG_RESPONSE = "response";
|
||||
String FALLBACK_REDIRECT = "redirect";
|
||||
|
||||
}
|
@ -23,19 +23,20 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alibaba.sentinel.zuul.handler.FallBackProviderHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.ZuulGatewayCallbackManager;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter;
|
||||
import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||
|
||||
import com.netflix.zuul.ZuulFilter;
|
||||
import com.netflix.zuul.http.ZuulServlet;
|
||||
|
||||
/**
|
||||
@ -45,16 +46,15 @@ import com.netflix.zuul.http.ZuulServlet;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(ZuulServlet.class)
|
||||
@ConditionalOnProperty(prefix = SentinelZuulAutoConfiguration.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = ConfigConstants.ZUUl_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(SentinelZuulProperties.class)
|
||||
public class SentinelZuulAutoConfiguration {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(SentinelZuulAutoConfiguration.class);
|
||||
|
||||
public static final String PREFIX = "spring.cloud.sentinel.zuul";
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
private SentinelZuulProperties zuulProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private RequestOriginParser requestOriginParser;
|
||||
@ -64,48 +64,32 @@ public class SentinelZuulAutoConfiguration {
|
||||
if (requestOriginParser != null) {
|
||||
ZuulGatewayCallbackManager.setOriginParser(requestOriginParser);
|
||||
}
|
||||
System.setProperty(SentinelConfig.APP_TYPE,
|
||||
String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ZuulFilter sentinelZuulPreFilter() {
|
||||
String preOrderStr = environment.getProperty(PREFIX + "." + "order.pre");
|
||||
int order = 10000;
|
||||
try {
|
||||
order = Integer.parseInt(preOrderStr);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
logger.info("[Sentinel Zuul] register SentinelZuulPreFilter {}", order);
|
||||
return new SentinelZuulPreFilter(order);
|
||||
@ConditionalOnMissingBean
|
||||
public SentinelZuulPreFilter sentinelZuulPreFilter() {
|
||||
logger.info("[Sentinel Zuul] register SentinelZuulPreFilter {}",
|
||||
zuulProperties.getOrder().getPre());
|
||||
return new SentinelZuulPreFilter(zuulProperties.getOrder().getPre());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ZuulFilter sentinelZuulPostFilter() {
|
||||
String postOrderStr = environment.getProperty(PREFIX + "." + "order.post");
|
||||
int order = 1000;
|
||||
try {
|
||||
order = Integer.parseInt(postOrderStr);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
logger.info("[Sentinel Zuul] register SentinelZuulPostFilter {}", order);
|
||||
return new SentinelZuulPostFilter(order);
|
||||
@ConditionalOnMissingBean
|
||||
public SentinelZuulPostFilter sentinelZuulPostFilter() {
|
||||
logger.info("[Sentinel Zuul] register SentinelZuulPostFilter {}",
|
||||
zuulProperties.getOrder().getPost());
|
||||
return new SentinelZuulPostFilter(zuulProperties.getOrder().getPost());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ZuulFilter sentinelZuulErrorFilter() {
|
||||
String errorOrderStr = environment.getProperty(PREFIX + "." + "order.error");
|
||||
int order = -1;
|
||||
try {
|
||||
order = Integer.parseInt(errorOrderStr);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
logger.info("[Sentinel Zuul] register SentinelZuulErrorFilter {}", order);
|
||||
return new SentinelZuulErrorFilter(order);
|
||||
@ConditionalOnMissingBean
|
||||
public SentinelZuulErrorFilter sentinelZuulErrorFilter() {
|
||||
logger.info("[Sentinel Zuul] register SentinelZuulErrorFilter {}",
|
||||
zuulProperties.getOrder().getError());
|
||||
return new SentinelZuulErrorFilter(zuulProperties.getOrder().getError());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cloud.alibaba.sentinel.zuul;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.constants.ZuulConstant;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@ConfigurationProperties(prefix = ConfigConstants.ZUUl_PREFIX)
|
||||
public class SentinelZuulProperties {
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private SentinelZuulProperties.Order order;
|
||||
|
||||
public Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public SentinelZuulProperties setOrder(Order order) {
|
||||
this.order = order;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Order {
|
||||
|
||||
/**
|
||||
* The order of {@link SentinelZuulPreFilter}.
|
||||
*/
|
||||
private int pre = 10000;
|
||||
|
||||
/**
|
||||
* The order of {@link SentinelZuulPostFilter}.
|
||||
*/
|
||||
private int post = ZuulConstant.SEND_RESPONSE_FILTER_ORDER;
|
||||
|
||||
/**
|
||||
* The order of {@link SentinelZuulErrorFilter}.
|
||||
*/
|
||||
private int error = -1;
|
||||
|
||||
public int getPre() {
|
||||
return pre;
|
||||
}
|
||||
|
||||
public void setPre(int pre) {
|
||||
this.pre = pre;
|
||||
}
|
||||
|
||||
public int getPost() {
|
||||
return post;
|
||||
}
|
||||
|
||||
public void setPost(int post) {
|
||||
this.post = post;
|
||||
}
|
||||
|
||||
public int getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(int error) {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -42,7 +42,12 @@ public class AcmEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
private final AcmPropertySourceRepository propertySourceRepository;
|
||||
|
||||
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>(){
|
||||
@Override
|
||||
protected DateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
public AcmEndpoint(AcmProperties properties, AcmRefreshHistory refreshHistory,
|
||||
AcmPropertySourceRepository propertySourceRepository) {
|
||||
@ -64,7 +69,7 @@ public class AcmEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
for (AcmPropertySource ps : all) {
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put("dataId", ps.getDataId());
|
||||
source.put("lastSynced", dateFormat.format(ps.getTimestamp()));
|
||||
source.put("lastSynced", dateFormat.get().format(ps.getTimestamp()));
|
||||
sources.add(source);
|
||||
}
|
||||
runtime.put("sources", sources);
|
||||
|
@ -30,10 +30,15 @@ public class AcmRefreshHistory {
|
||||
|
||||
private LinkedList<Record> records = new LinkedList<>();
|
||||
|
||||
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private ThreadLocal<DateFormat> dateFormat = new ThreadLocal<DateFormat>(){
|
||||
@Override
|
||||
protected DateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
public void add(String dataId, String md5) {
|
||||
records.addFirst(new Record(dateFormat.format(new Date()), dataId, md5));
|
||||
records.addFirst(new Record(dateFormat.get().format(new Date()), dataId, md5));
|
||||
if (records.size() > MAX_SIZE) {
|
||||
records.removeLast();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user