1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	spring-cloud-alibaba-docs/src/main/asciidoc-zh/sentinel.adoc
#	spring-cloud-alibaba-docs/src/main/asciidoc/sentinel.adoc
This commit is contained in:
mercyblitz
2019-02-21 14:49:26 +08:00
97 changed files with 1617 additions and 1532 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.alibaba.nacos;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,6 +35,7 @@ public class NacosConfigBootstrapConfiguration {
}
@Bean
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
public NacosPropertySourceLocator nacosPropertySourceLocator(
NacosConfigProperties nacosConfigProperties) {
return new NacosPropertySourceLocator(nacosConfigProperties);

View File

@@ -18,8 +18,9 @@ package org.springframework.cloud.alibaba.nacos;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
@@ -49,9 +50,15 @@ import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
@ConfigurationProperties(NacosConfigProperties.PREFIX)
public class NacosConfigProperties {
static final String PREFIX = "spring.cloud.nacos.config";
public static final String PREFIX = "spring.cloud.nacos.config";
private static final Log log = LogFactory.getLog(NacosConfigProperties.class);
private static final Logger log = LoggerFactory
.getLogger(NacosConfigProperties.class);
/**
* whether to enable nacos config.
*/
private boolean enabled = true;
/**
* nacos config server address
@@ -145,6 +152,14 @@ public class NacosConfigProperties {
// todo sts support
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getServerAddr() {
return serverAddr;
}
@@ -322,16 +337,17 @@ public class NacosConfigProperties {
@Override
public String toString() {
return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\''
+ ", encode='" + encode + '\'' + ", group='" + group + '\''
+ ", sharedDataids='" + this.sharedDataids + '\''
+ ", refreshableDataids='" + this.refreshableDataids + '\'' + ", prefix='"
+ prefix + '\'' + ", fileExtension='" + fileExtension + '\''
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
+ '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
+ ", activeProfiles=" + Arrays.toString(activeProfiles) + '}';
return "NacosConfigProperties{" + "enabled=" + enabled + ", serverAddr='"
+ serverAddr + '\'' + ", encode='" + encode + '\'' + ", group='" + group
+ '\'' + ", prefix='" + prefix + '\'' + ", fileExtension='"
+ fileExtension + '\'' + ", timeout=" + timeout + ", endpoint='"
+ endpoint + '\'' + ", namespace='" + namespace + '\'' + ", accessKey='"
+ accessKey + '\'' + ", secretKey='" + secretKey + '\''
+ ", contextPath='" + contextPath + '\'' + ", clusterName='" + clusterName
+ '\'' + ", name='" + name + '\'' + ", activeProfiles="
+ Arrays.toString(activeProfiles) + ", sharedDataids='" + sharedDataids
+ '\'' + ", refreshableDataids='" + refreshableDataids + '\''
+ ", extConfig=" + extConfig + '}';
}
public ConfigService configServiceInstance() {
@@ -354,11 +370,8 @@ public class NacosConfigProperties {
return configService;
}
catch (Exception e) {
log.error(
"create config service error!properties=" + this.toString() + ",e=,",
e);
log.error("create config service error!properties={},e=,", this, e);
return null;
}
}
}

View File

@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* @author xiaojing
* @author pbting
*/
public class NacosPropertySourceRepository {
@@ -45,6 +46,7 @@ public class NacosPropertySourceRepository {
}
public static NacosPropertySource getNacosPropertySource(String dataId) {
return nacosPropertySourceRepository.get(dataId);
}
}

View File

@@ -18,8 +18,9 @@ package org.springframework.cloud.alibaba.nacos.client;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
import org.springframework.core.io.ByteArrayResource;
@@ -37,7 +38,8 @@ import java.util.Properties;
* @author pbting
*/
public class NacosPropertySourceBuilder {
private static final Log log = LogFactory.getLog(NacosPropertySourceBuilder.class);
private static final Logger log = LoggerFactory
.getLogger(NacosPropertySourceBuilder.class);
private static final Properties EMPTY_PROPERTIES = new Properties();
private ConfigService configService;
@@ -101,11 +103,10 @@ public class NacosPropertySourceBuilder {
}
}
catch (NacosException e) {
log.error("get data from Nacos error,dataId:" + dataId + ", ", e);
log.error("get data from Nacos error,dataId:{}, ", dataId, e);
}
catch (Exception e) {
log.error("parse data from Nacos error,dataId:" + dataId + ",data:" + data
+ ",", e);
log.error("parse data from Nacos error,dataId:{},data:{},", dataId, data, e);
}
return EMPTY_PROPERTIES;
}

View File

@@ -17,8 +17,9 @@
package org.springframework.cloud.alibaba.nacos.client;
import com.alibaba.nacos.api.config.ConfigService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
import org.springframework.cloud.alibaba.nacos.refresh.NacosContextRefresher;
@@ -39,7 +40,8 @@ import java.util.List;
@Order(0)
public class NacosPropertySourceLocator implements PropertySourceLocator {
private static final Log log = LogFactory.getLog(NacosPropertySourceLocator.class);
private static final Logger log = LoggerFactory
.getLogger(NacosPropertySourceLocator.class);
private static final String NACOS_PROPERTY_SOURCE_NAME = "NACOS";
private static final String SEP1 = "-";
private static final String DOT = ".";
@@ -182,19 +184,19 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
}
}
private static void checkDataIdFileExtension(String[] sharedDataIdArry) {
private static void checkDataIdFileExtension(String[] dataIdArray) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < sharedDataIdArry.length; i++) {
for (int i = 0; i < dataIdArray.length; i++) {
boolean isLegal = false;
for (String fileExtension : SUPPORT_FILE_EXTENSION) {
if (sharedDataIdArry[i].indexOf(fileExtension) > 0) {
if (dataIdArray[i].indexOf(fileExtension) > 0) {
isLegal = true;
break;
}
}
// add tips
if (!isLegal) {
stringBuilder.append(sharedDataIdArry[i] + ",");
stringBuilder.append(dataIdArray[i] + ",");
}
}

View File

@@ -19,8 +19,9 @@ package org.springframework.cloud.alibaba.nacos.refresh;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySource;
@@ -51,7 +52,8 @@ import java.util.concurrent.atomic.AtomicLong;
public class NacosContextRefresher
implements ApplicationListener<ApplicationReadyEvent>, ApplicationContextAware {
private final static Log log = LogFactory.getLog(NacosContextRefresher.class);
private final static Logger log = LoggerFactory
.getLogger(NacosContextRefresher.class);
private static final AtomicLong REFRESH_COUNT = new AtomicLong(0);