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

#734 -> update maven coordinates

This commit is contained in:
fangjian0423
2019-07-08 11:38:27 +08:00
parent 3998ea23f7
commit aa03ddbbe2
498 changed files with 1208 additions and 1203 deletions

View File

@@ -0,0 +1,39 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author xiaolongzuo
*/
@Configuration
@EnableConfigurationProperties({ AliCloudProperties.class, InetUtilsProperties.class })
public class AliCloudContextAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public InetUtils inetUtils(InetUtilsProperties inetUtilsProperties) {
return new InetUtils(inetUtilsProperties);
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.alibaba.cloud.context.AliCloudConfiguration;
/**
* @author xiaolongzuo
*/
@ConfigurationProperties("spring.cloud.alicloud")
public class AliCloudProperties implements AliCloudConfiguration {
/**
* alibaba cloud access key.
*/
private String accessKey;
/**
* alibaba cloud secret key.
*/
private String secretKey;
@Override
public String getAccessKey() {
return accessKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
@Override
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
}

View File

@@ -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
*
* 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 org.springframework.cloud.alicloud.context;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
public interface Constants {
interface Sentinel {
String PROPERTY_PREFIX = "spring.cloud.sentinel";
String NACOS_DATASOURCE_AK = PROPERTY_PREFIX + ".nacos.config.access-key";
String NACOS_DATASOURCE_SK = PROPERTY_PREFIX + ".nacos.config.secret-key";
String NACOS_DATASOURCE_NAMESPACE = PROPERTY_PREFIX + ".nacos.config.namespace";
String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX + ".nacos.config.endpoint";
String PROJECT_NAME = PROPERTY_PREFIX + ".nacos.config.project-name";
}
}

View File

@@ -0,0 +1,77 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.acm;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alicloud.context.AliCloudProperties;
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.alibaba.cloud.context.acm.AliCloudAcmInitializer;
/**
* @author xiaolongzuo
*/
@Configuration
@EnableConfigurationProperties(AcmProperties.class)
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.acm.AcmAutoConfiguration")
@ImportAutoConfiguration(EdasContextAutoConfiguration.class)
public class AcmContextBootstrapConfiguration {
@Autowired
private AcmProperties acmProperties;
@Autowired
private EdasProperties edasProperties;
@Autowired
private AliCloudProperties aliCloudProperties;
@Autowired
private Environment environment;
@PostConstruct
public void initAcmProperties() {
AliCloudAcmInitializer.initialize(aliCloudProperties, edasProperties,
acmProperties);
}
@Bean
public AcmIntegrationProperties acmIntegrationProperties() {
AcmIntegrationProperties acmIntegrationProperties = new AcmIntegrationProperties();
String applicationName = environment.getProperty("spring.application.name");
String applicationGroup = environment.getProperty("spring.application.group");
Assert.isTrue(!StringUtils.isEmpty(applicationName),
"'spring.application.name' must be configured in bootstrap.properties or bootstrap.yml/yaml...");
acmIntegrationProperties.setApplicationName(applicationName);
acmIntegrationProperties.setApplicationGroup(applicationGroup);
acmIntegrationProperties.setActiveProfiles(environment.getActiveProfiles());
acmIntegrationProperties.setAcmProperties(acmProperties);
return acmIntegrationProperties;
}
}

View File

@@ -0,0 +1,102 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.acm;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.StringUtils;
/**
* @author xiaolongzuo
*/
public class AcmIntegrationProperties {
private String applicationName;
private String applicationGroup;
private String[] activeProfiles = new String[0];
private AcmProperties acmProperties;
public String getApplicationConfigurationDataIdWithoutGroup() {
return applicationName + "." + acmProperties.getFileExtension();
}
public List<String> getGroupConfigurationDataIds() {
List<String> groupConfigurationDataIds = new ArrayList<>();
if (StringUtils.isEmpty(applicationGroup)) {
return groupConfigurationDataIds;
}
String[] parts = applicationGroup.split("\\.");
for (int i = 1; i < parts.length; i++) {
StringBuilder subGroup = new StringBuilder(parts[0]);
for (int j = 1; j <= i; j++) {
subGroup.append(".").append(parts[j]);
}
groupConfigurationDataIds
.add(subGroup + ":application." + acmProperties.getFileExtension());
}
return groupConfigurationDataIds;
}
public List<String> getApplicationConfigurationDataIds() {
List<String> applicationConfigurationDataIds = new ArrayList<>();
if (!StringUtils.isEmpty(applicationGroup)) {
applicationConfigurationDataIds.add(applicationGroup + ":" + applicationName
+ "." + acmProperties.getFileExtension());
for (String profile : activeProfiles) {
applicationConfigurationDataIds
.add(applicationGroup + ":" + applicationName + "-" + profile
+ "." + acmProperties.getFileExtension());
}
}
applicationConfigurationDataIds
.add(applicationName + "." + acmProperties.getFileExtension());
for (String profile : activeProfiles) {
applicationConfigurationDataIds.add(applicationName + "-" + profile + "."
+ acmProperties.getFileExtension());
}
return applicationConfigurationDataIds;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
public void setApplicationGroup(String applicationGroup) {
this.applicationGroup = applicationGroup;
}
public void setActiveProfiles(String[] activeProfiles) {
this.activeProfiles = activeProfiles;
}
public String[] getActiveProfiles() {
return activeProfiles;
}
public void setAcmProperties(AcmProperties acmProperties) {
this.acmProperties = acmProperties;
}
public AcmProperties getAcmProperties() {
return acmProperties;
}
}

View File

@@ -0,0 +1,156 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.acm;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.alibaba.cloud.context.AliCloudServerMode;
import com.alibaba.cloud.context.acm.AcmConfiguration;
/**
* acm properties
*
* @author leijuan
* @author xiaolongzuo
*/
@ConfigurationProperties(prefix = "spring.cloud.alicloud.acm")
public class AcmProperties implements AcmConfiguration {
private AliCloudServerMode serverMode = AliCloudServerMode.LOCAL;
private String serverList = "127.0.0.1";
private String serverPort = "8080";
/**
* diamond group
*/
private String group = "DEFAULT_GROUP";
/**
* timeout to get configuration
*/
private int timeout = 3000;
/**
* the AliYun endpoint for ACM
*/
private String endpoint;
/**
* ACM namespace
*/
private String namespace;
/**
* name of ram role granted to ECS
*/
private String ramRoleName;
private String fileExtension = "properties";
private boolean refreshEnabled = true;
public String getFileExtension() {
return fileExtension;
}
public void setFileExtension(String fileExtension) {
this.fileExtension = fileExtension;
}
@Override
public String getServerList() {
return serverList;
}
public void setServerList(String serverList) {
this.serverList = serverList;
}
@Override
public String getServerPort() {
return serverPort;
}
public void setServerPort(String serverPort) {
this.serverPort = serverPort;
}
@Override
public boolean isRefreshEnabled() {
return refreshEnabled;
}
public void setRefreshEnabled(boolean refreshEnabled) {
this.refreshEnabled = refreshEnabled;
}
@Override
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
@Override
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
@Override
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
@Override
public String getNamespace() {
return namespace;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
@Override
public String getRamRoleName() {
return ramRoleName;
}
public void setRamRoleName(String ramRoleName) {
this.ramRoleName = ramRoleName;
}
@Override
public AliCloudServerMode getServerMode() {
return serverMode;
}
public void setServerMode(AliCloudServerMode serverMode) {
this.serverMode = serverMode;
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.ans;
import org.springframework.cloud.alicloud.context.AliCloudProperties;
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
import com.alibaba.cloud.context.edas.AliCloudEdasSdk;
/**
* Init {@link com.alibaba.ans.core.NamingService} properties.
*
* @author xiaolongzuo
*/
public class AnsContextApplicationListener
extends AbstractOnceApplicationListener<ContextRefreshedEvent> {
@Override
protected String conditionalOnClass() {
return "org.springframework.cloud.alicloud.ans.AnsAutoConfiguration";
}
@Override
public void handleEvent(ContextRefreshedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
AliCloudProperties aliCloudProperties = applicationContext
.getBean(AliCloudProperties.class);
EdasProperties edasProperties = applicationContext.getBean(EdasProperties.class);
AnsProperties ansProperties = applicationContext.getBean(AnsProperties.class);
AliCloudEdasSdk aliCloudEdasSdk = applicationContext
.getBean(AliCloudEdasSdk.class);
AliCloudAnsInitializer.initialize(aliCloudProperties, edasProperties,
ansProperties, aliCloudEdasSdk);
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.ans;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
import org.springframework.context.annotation.Configuration;
/**
* @author xiaolongzuo
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.ans.AnsAutoConfiguration")
@EnableConfigurationProperties(AnsProperties.class)
@ImportAutoConfiguration(EdasContextAutoConfiguration.class)
public class AnsContextAutoConfiguration {
}

View File

@@ -0,0 +1,343 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.ans;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.util.StringUtils;
import com.alibaba.cloud.context.AliCloudServerMode;
import com.alibaba.cloud.context.ans.AnsConfiguration;
/**
* @author xiaolongzuo
*/
@ConfigurationProperties("spring.cloud.alicloud.ans")
public class AnsProperties implements AnsConfiguration {
/**
* Server side modethe default is LOCAL.
*/
private AliCloudServerMode serverMode = AliCloudServerMode.LOCAL;
/**
* Server list.
*/
private String serverList = "127.0.0.1";
/**
* Server port.
*/
private String serverPort = "8080";
/**
* Service namesdefault value is ${spring.cloud.alicloud.ans.doms}. When not
* configured, use ${spring.application.name}.
*/
@Value("${spring.cloud.alicloud.ans.client-domains:${spring.application.name:}}")
private String clientDomains;
/**
* The weight of the registration service, obtained from the configuration
* ${spring.cloud.alicloud.ans.weight}, the default is 1.
*/
private float clientWeight = 1;
/**
* When there are multiple doms and need to correspond to different weights, configure
* them by spring.cloud.alicloud.ans.weight.dom1=weight1.
*/
private Map<String, Float> clientWeights = new HashMap<String, Float>();
/**
* The token of the registration service, obtained from
* ${spring.cloud.alicloud.ans.token}.
*/
private String clientToken;
/**
* When there are multiple doms and need to correspond to different tokens, configure
* them by spring.cloud.alicloud.ans.tokens.dom1=token1.
*/
private Map<String, String> clientTokens = new HashMap<String, String>();
/**
* Configure which cluster to register with, obtained from
* ${spring.cloud.alicloud.ans.cluster}, defaults to DEFAULT.
*/
private String clientCluster = "DEFAULT";
/**
* Temporarily not supported, reserved fields.
*/
private Map<String, String> clientMetadata = new HashMap<>();
/**
* Registration is turned on by default, and registration can be turned off by the
* configuration of spring.cloud.alicloud.ans.register-enabled=false.
*/
private boolean registerEnabled = true;
/**
* The ip of the service you want to publish, obtained from
* ${spring.cloud.alicloud.ans.client-ip}.
*/
private String clientIp;
/**
* Configure which NIC the ip of the service you want to publish is obtained from.
*/
private String clientInterfaceName;
/**
* The port of the service you want to publish.
*/
private int clientPort = -1;
/**
* The environment isolation configuration under the tenant, the services in the same
* environment of the same tenant can discover each other.
*/
@Value("${spring.cloud.alicloud.ans.env:${env.id:DEFAULT}}")
private String env;
/**
* Whether to register as https, configured by ${spring.cloud.alicloud.ans.secure},
* default is false.
*/
private boolean secure = false;
@Autowired
private InetUtils inetUtils;
private Map<String, String> tags = new HashMap<>();
@PostConstruct
public void init() throws SocketException {
// Marked as spring cloud application
tags.put("ANS_SERVICE_TYPE", "SPRING_CLOUD");
if (StringUtils.isEmpty(clientIp)) {
if (StringUtils.isEmpty(clientInterfaceName)) {
clientIp = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
}
else {
NetworkInterface networkInterface = NetworkInterface
.getByName(clientInterfaceName);
if (null == networkInterface) {
throw new RuntimeException(
"no such network interface " + clientInterfaceName);
}
Enumeration<InetAddress> inetAddress = networkInterface
.getInetAddresses();
while (inetAddress.hasMoreElements()) {
InetAddress currentAddress = inetAddress.nextElement();
if (currentAddress instanceof Inet4Address
&& !currentAddress.isLoopbackAddress()) {
clientIp = currentAddress.getHostAddress();
break;
}
}
if (StringUtils.isEmpty(clientIp)) {
throw new RuntimeException(
"cannot find available ip from network interface "
+ clientInterfaceName);
}
}
}
}
@Override
public String getServerPort() {
return serverPort;
}
public void setServerPort(String serverPort) {
this.serverPort = serverPort;
}
@Override
public String getServerList() {
return serverList;
}
public void setServerList(String serverList) {
this.serverList = serverList;
}
@Override
public boolean isRegisterEnabled() {
return registerEnabled;
}
public void setRegisterEnabled(boolean registerEnabled) {
this.registerEnabled = registerEnabled;
}
@Override
public boolean isSecure() {
return secure;
}
public void setSecure(boolean secure) {
this.secure = secure;
}
@Override
public String getEnv() {
return env;
}
public void setEnv(String env) {
this.env = env;
}
@Override
public Map<String, String> getTags() {
return tags;
}
public void setTags(Map<String, String> tags) {
this.tags = tags;
}
@Override
public AliCloudServerMode getServerMode() {
return serverMode;
}
public void setServerMode(AliCloudServerMode serverMode) {
this.serverMode = serverMode;
}
@Override
public String getClientDomains() {
return clientDomains;
}
public void setClientDomains(String clientDomains) {
this.clientDomains = clientDomains;
}
@Override
public float getClientWeight() {
return clientWeight;
}
public void setClientWeight(float clientWeight) {
this.clientWeight = clientWeight;
}
@Override
public Map<String, Float> getClientWeights() {
return clientWeights;
}
public void setClientWeights(Map<String, Float> clientWeights) {
this.clientWeights = clientWeights;
}
@Override
public String getClientToken() {
return clientToken;
}
public void setClientToken(String clientToken) {
this.clientToken = clientToken;
}
@Override
public Map<String, String> getClientTokens() {
return clientTokens;
}
public void setClientTokens(Map<String, String> clientTokens) {
this.clientTokens = clientTokens;
}
@Override
public String getClientCluster() {
return clientCluster;
}
public void setClientCluster(String clientCluster) {
this.clientCluster = clientCluster;
}
@Override
public Map<String, String> getClientMetadata() {
return clientMetadata;
}
public void setClientMetadata(Map<String, String> clientMetadata) {
this.clientMetadata = clientMetadata;
}
@Override
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
@Override
public String getClientInterfaceName() {
return clientInterfaceName;
}
public void setClientInterfaceName(String clientInterfaceName) {
this.clientInterfaceName = clientInterfaceName;
}
@Override
public int getClientPort() {
return clientPort;
}
public void setClientPort(int clientPort) {
this.clientPort = clientPort;
}
@Override
public String toString() {
return "AnsProperties{" + "doms='" + clientDomains + '\'' + ", weight="
+ clientWeight + ", weights=" + clientWeights + ", token='" + clientToken
+ '\'' + ", tokens=" + clientTokens + ", cluster='" + clientCluster + '\''
+ ", metadata=" + clientMetadata + ", registerEnabled=" + registerEnabled
+ ", ip='" + clientIp + '\'' + ", interfaceName='" + clientInterfaceName
+ '\'' + ", port=" + clientPort + ", env='" + env + '\'' + ", secure="
+ secure + ", tags=" + tags + '}';
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.edas;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.AliCloudProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.cloud.context.edas.AliCloudEdasSdk;
import com.alibaba.cloud.context.edas.AliCloudEdasSdkFactory;
/**
* @author xiaolongzuo
*/
@Configuration
@EnableConfigurationProperties(EdasProperties.class)
@ImportAutoConfiguration(AliCloudContextAutoConfiguration.class)
public class EdasContextAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "com.aliyuncs.edas.model.v20170801.GetSecureTokenRequest")
public AliCloudEdasSdk aliCloudEdasSdk(AliCloudProperties aliCloudProperties,
EdasProperties edasProperties) {
return AliCloudEdasSdkFactory.getDefaultAliCloudEdasSdk(aliCloudProperties,
edasProperties.getRegionId());
}
}

View File

@@ -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
*
* 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 org.springframework.cloud.alicloud.context.edas;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.alibaba.cloud.context.edas.EdasConfiguration;
/**
* @author xiaolongzuo
*/
@ConfigurationProperties("spring.cloud.alicloud.edas")
public class EdasProperties implements EdasConfiguration {
private static final String DEFAULT_APPLICATION_NAME = "";
/**
* edas application name.
*/
@Value("${spring.application.name:${spring.cloud.alicloud.edas.application.name:}}")
private String applicationName;
/**
* edas namespace
*/
private String namespace;
/**
* whether or not connect edas.
*/
private boolean enabled;
@Override
public String getRegionId() {
if (namespace == null) {
return null;
}
return namespace.contains(":") ? namespace.split(":")[0] : namespace;
}
@Override
public boolean isApplicationNameValid() {
return !DEFAULT_APPLICATION_NAME.equals(applicationName);
}
@Override
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
@Override
public String getNamespace() {
return namespace;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
@Override
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.listener;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;
/**
* @author xiaolongzuo
*/
public abstract class AbstractOnceApplicationListener<T extends ApplicationEvent>
implements ApplicationListener<T> {
private static final String BOOTSTRAP_CONFIG_NAME_VALUE = "bootstrap";
private static final String BOOTSTRAP_CONFIG_NAME_KEY = "spring.config.name";
private static ConcurrentHashMap<Class<?>, AtomicBoolean> lockMap = new ConcurrentHashMap<>();
@Override
public void onApplicationEvent(T event) {
if (event instanceof ApplicationContextEvent) {
ApplicationContext applicationContext = ((ApplicationContextEvent) event)
.getApplicationContext();
// skip bootstrap context or super parent context.
if (BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext.getEnvironment()
.getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
return;
}
}
Class<?> clazz = getClass();
lockMap.putIfAbsent(clazz, new AtomicBoolean(false));
AtomicBoolean handled = lockMap.get(clazz);
// only execute once.
if (!handled.compareAndSet(false, true)) {
return;
}
if (conditionalOnClass() != null) {
try {
Class.forName(conditionalOnClass());
}
catch (ClassNotFoundException e) {
// ignored
return;
}
}
handleEvent(event);
}
/**
* handle event.
*
* @param event
*/
protected abstract void handleEvent(T event);
/**
* condition on class.
*
* @return
*/
protected String conditionalOnClass() {
return null;
}
}

View File

@@ -0,0 +1,55 @@
package org.springframework.cloud.alicloud.context.nacos;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
/**
* @author pbting
*/
public class NacosConfigParameterInitListener
extends AbstractOnceApplicationListener<ApplicationEnvironmentPreparedEvent> {
private static final Logger log = LoggerFactory
.getLogger(NacosConfigParameterInitListener.class);
@Override
protected String conditionalOnClass() {
return "org.springframework.cloud.alibaba.nacos.NacosConfigAutoConfiguration";
}
@Override
protected void handleEvent(ApplicationEnvironmentPreparedEvent event) {
preparedNacosConfiguration();
}
private void preparedNacosConfiguration() {
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
.getEdasChangeOrderConfiguration();
if (log.isDebugEnabled()) {
log.debug("Initialize Nacos Config Parameter ,is managed {}.",
edasChangeOrderConfiguration.isEdasManaged());
}
if (!edasChangeOrderConfiguration.isEdasManaged()) {
return;
}
System.getProperties().setProperty("spring.cloud.nacos.config.server-mode",
"EDAS");
// initialize nacos configuration
System.getProperties().setProperty("spring.cloud.nacos.config.server-addr", "");
System.getProperties().setProperty("spring.cloud.nacos.config.endpoint",
edasChangeOrderConfiguration.getAddressServerDomain());
System.getProperties().setProperty("spring.cloud.nacos.config.namespace",
edasChangeOrderConfiguration.getTenantId());
System.getProperties().setProperty("spring.cloud.nacos.config.access-key",
edasChangeOrderConfiguration.getDauthAccessKey());
System.getProperties().setProperty("spring.cloud.nacos.config.secret-key",
edasChangeOrderConfiguration.getDauthSecretKey());
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2019 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
*
* 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 org.springframework.cloud.alicloud.context.nacos;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
/**
* @author pbting
* @date 2019-02-14 11:12 AM
*/
public class NacosDiscoveryParameterInitListener
extends AbstractOnceApplicationListener<ApplicationEnvironmentPreparedEvent> {
private static final Logger log = LoggerFactory
.getLogger(NacosDiscoveryParameterInitListener.class);
@Override
protected String conditionalOnClass() {
return "org.springframework.cloud.alibaba.nacos.NacosDiscoveryAutoConfiguration";
}
@Override
protected void handleEvent(ApplicationEnvironmentPreparedEvent event) {
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
.getEdasChangeOrderConfiguration();
if (log.isDebugEnabled()) {
log.debug("Initialize Nacos Discovery Parameter ,is managed {}.",
edasChangeOrderConfiguration.isEdasManaged());
}
if (!edasChangeOrderConfiguration.isEdasManaged()) {
return;
}
// initialize nacos configuration
Properties properties = System.getProperties();
properties.setProperty("spring.cloud.nacos.discovery.server-mode", "EDAS");
// step 1: set some properties for spring cloud alibaba nacos discovery
properties.setProperty("spring.cloud.nacos.discovery.server-addr", "");
properties.setProperty("spring.cloud.nacos.discovery.endpoint",
edasChangeOrderConfiguration.getAddressServerDomain());
properties.setProperty("spring.cloud.nacos.discovery.namespace",
edasChangeOrderConfiguration.getTenantId());
properties.setProperty("spring.cloud.nacos.discovery.access-key",
edasChangeOrderConfiguration.getDauthAccessKey());
properties.setProperty("spring.cloud.nacos.discovery.secret-key",
edasChangeOrderConfiguration.getDauthSecretKey());
// step 2: set these properties for nacos client
properties.setProperty("nacos.naming.web.context", "/vipserver");
properties.setProperty("nacos.naming.exposed.port", "80");
}
}

View File

@@ -0,0 +1,82 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.oss;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
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.alicloud.context.AliCloudContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.AliCloudProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.alibaba.cloud.context.AliCloudAuthorizationMode;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
/**
* OSS Auto {@link Configuration}
*
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
* @author xiaolongzuo
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.oss.OssAutoConfiguration")
@ConditionalOnProperty(name = "spring.cloud.alicloud.oss.enabled", matchIfMissing = true)
@EnableConfigurationProperties(OssProperties.class)
@ImportAutoConfiguration(AliCloudContextAutoConfiguration.class)
public class OssContextAutoConfiguration {
@ConditionalOnMissingBean
@Bean
public OSS ossClient(AliCloudProperties aliCloudProperties,
OssProperties ossProperties) {
if (ossProperties.getAuthorizationMode() == AliCloudAuthorizationMode.AK_SK) {
Assert.isTrue(!StringUtils.isEmpty(ossProperties.getEndpoint()),
"Oss endpoint can't be empty.");
Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getAccessKey()),
"${spring.cloud.alicloud.access-key} can't be empty.");
Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getSecretKey()),
"${spring.cloud.alicloud.secret-key} can't be empty.");
return new OSSClientBuilder().build(ossProperties.getEndpoint(),
aliCloudProperties.getAccessKey(), aliCloudProperties.getSecretKey(),
ossProperties.getConfig());
}
else if (ossProperties.getAuthorizationMode() == AliCloudAuthorizationMode.STS) {
Assert.isTrue(!StringUtils.isEmpty(ossProperties.getEndpoint()),
"Oss endpoint can't be empty.");
Assert.isTrue(!StringUtils.isEmpty(ossProperties.getSts().getAccessKey()),
"Access key can't be empty.");
Assert.isTrue(!StringUtils.isEmpty(ossProperties.getSts().getSecretKey()),
"Secret key can't be empty.");
Assert.isTrue(!StringUtils.isEmpty(ossProperties.getSts().getSecurityToken()),
"Security Token can't be empty.");
return new OSSClientBuilder().build(ossProperties.getEndpoint(),
ossProperties.getSts().getAccessKey(),
ossProperties.getSts().getSecretKey(),
ossProperties.getSts().getSecurityToken(), ossProperties.getConfig());
}
else {
throw new IllegalArgumentException("Unknown auth mode.");
}
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.oss;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.alibaba.cloud.context.AliCloudAuthorizationMode;
import com.aliyun.oss.ClientBuilderConfiguration;
/**
* {@link ConfigurationProperties} for configuring OSS.
*
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
* @author xiaolongzuo
*/
@ConfigurationProperties("spring.cloud.alicloud.oss")
public class OssProperties {
/**
* Authorization Mode, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
@Value("${spring.cloud.alicloud.oss.authorization-mode:AK_SK}")
private AliCloudAuthorizationMode authorizationMode;
/**
* Endpoint, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
private String endpoint;
/**
* Sts token, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
private StsToken sts;
/**
* Client Configuration, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
private ClientBuilderConfiguration config;
public AliCloudAuthorizationMode getAuthorizationMode() {
return authorizationMode;
}
public void setAuthorizationMode(AliCloudAuthorizationMode authorizationMode) {
this.authorizationMode = authorizationMode;
}
public ClientBuilderConfiguration getConfig() {
return config;
}
public void setConfig(ClientBuilderConfiguration config) {
this.config = config;
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public StsToken getSts() {
return sts;
}
public void setSts(StsToken sts) {
this.sts = sts;
}
public static class StsToken {
private String accessKey;
private String secretKey;
private String securityToken;
public String getAccessKey() {
return accessKey;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public String getSecretKey() {
return secretKey;
}
public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public String getSecurityToken() {
return securityToken;
}
public void setSecurityToken(String securityToken) {
this.securityToken = securityToken;
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.scx;
import com.alibaba.cloud.context.edas.AliCloudEdasSdk;
import com.alibaba.cloud.context.scx.AliCloudScxInitializer;
import com.alibaba.edas.schedulerx.SchedulerXClient;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
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.alicloud.context.AliCloudProperties;
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author xiaolongzuo
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.scx.ScxAutoConfiguration")
@ConditionalOnProperty(name = "spring.cloud.alicloud.scx.enabled", matchIfMissing = true)
@EnableConfigurationProperties(ScxProperties.class)
@ImportAutoConfiguration(EdasContextAutoConfiguration.class)
public class ScxContextAutoConfiguration {
@Bean(initMethod = "init")
@ConditionalOnMissingBean
public SchedulerXClient schedulerXClient(AliCloudProperties aliCloudProperties,
EdasProperties edasProperties, ScxProperties scxProperties,
AliCloudEdasSdk aliCloudEdasSdk) {
return AliCloudScxInitializer.initialize(aliCloudProperties, edasProperties,
scxProperties, aliCloudEdasSdk);
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.scx;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.alibaba.cloud.context.scx.ScxConfiguration;
/**
* @author xiaolongzuo
*/
@ConfigurationProperties("spring.cloud.alicloud.scx")
public class ScxProperties implements ScxConfiguration {
/**
* Group id, please see <a href=
* "https://help.aliyun.com/document_detail/35359.html?spm=a2c4g.11186623.6.721.69ca5763p9IJly">scx
* docs</a>.
*/
private String groupId;
/**
* Domain name, please see <a href=
* "https://help.aliyun.com/document_detail/35359.html?spm=a2c4g.11186623.6.721.69ca5763p9IJly">scx
* docs</a>.
*/
private String domainName;
@Override
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
@Override
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.sentinel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.cloud.alicloud.context.Constants;
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
public class SentinelAliCloudListener
extends AbstractOnceApplicationListener<ApplicationEnvironmentPreparedEvent> {
private static final Logger logger = LoggerFactory
.getLogger(SentinelAliCloudListener.class);
@Override
protected void handleEvent(ApplicationEnvironmentPreparedEvent event) {
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
.getEdasChangeOrderConfiguration();
logger.info("Sentinel Nacos datasource will"
+ (edasChangeOrderConfiguration.isEdasManaged() ? " be " : " not be ")
+ "changed by edas change order.");
if (!edasChangeOrderConfiguration.isEdasManaged()) {
return;
}
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_ENDPOINT,
edasChangeOrderConfiguration.getAddressServerDomain());
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_NAMESPACE,
edasChangeOrderConfiguration.getTenantId());
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_AK,
edasChangeOrderConfiguration.getDauthAccessKey());
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_SK,
edasChangeOrderConfiguration.getDauthSecretKey());
System.getProperties().setProperty(Constants.Sentinel.PROJECT_NAME,
edasChangeOrderConfiguration.getProjectName());
}
@Override
protected String conditionalOnClass() {
return "com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource";
}
}

View File

@@ -0,0 +1,18 @@
package org.springframework.cloud.alicloud.context.sms;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author pbting
* @author xiaolongzuo
*/
@Configuration
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnClass(name = "com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest")
@ConditionalOnProperty(value = "spring.cloud.alibaba.deshao.enable.sms", matchIfMissing = true)
public class SmsContextAutoConfiguration {
}

View File

@@ -0,0 +1,74 @@
package org.springframework.cloud.alicloud.context.sms;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author pbting
* @author xiaolongzuo
*/
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
public class SmsProperties {
/**
* Product name.
*/
public static final String SMS_PRODUCT = "Dysmsapi";
/**
* Product domain.
*/
public static final String SMS_DOMAIN = "dysmsapi.aliyuncs.com";
/**
* Report queue name.
*/
private String reportQueueName;
/**
* Up queue name.
*/
private String upQueueName;
/**
* Connect timeout.
*/
private String connectTimeout = "10000";
/**
* Read timeout.
*/
private String readTimeout = "10000";
public String getConnectTimeout() {
return connectTimeout;
}
public void setConnectTimeout(String connectTimeout) {
this.connectTimeout = connectTimeout;
}
public String getReadTimeout() {
return readTimeout;
}
public void setReadTimeout(String readTimeout) {
this.readTimeout = readTimeout;
}
public String getReportQueueName() {
return reportQueueName;
}
public void setReportQueueName(String reportQueueName) {
this.reportQueueName = reportQueueName;
}
public String getUpQueueName() {
return upQueueName;
}
public void setUpQueueName(String upQueueName) {
this.upQueueName = upQueueName;
}
}

View File

@@ -0,0 +1,122 @@
/*
* 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
*
* 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 org.springframework.cloud.alicloud.context.statistics;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.cloud.alicloud.context.acm.AcmContextBootstrapConfiguration;
import org.springframework.cloud.alicloud.context.acm.AcmProperties;
import org.springframework.cloud.alicloud.context.ans.AnsContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.ans.AnsProperties;
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
import org.springframework.cloud.alicloud.context.oss.OssContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.oss.OssProperties;
import org.springframework.cloud.alicloud.context.scx.ScxContextAutoConfiguration;
import org.springframework.cloud.alicloud.context.scx.ScxProperties;
import org.springframework.context.annotation.Configuration;
import com.alibaba.cloud.context.AliCloudServerMode;
import com.alibaba.cloud.context.edas.AliCloudEdasSdk;
import com.alibaba.cloud.context.statistics.StatisticsTask;
/**
* @author xiaolongzuo
*/
@Configuration
@AutoConfigureAfter({ ScxContextAutoConfiguration.class,
OssContextAutoConfiguration.class, AnsContextAutoConfiguration.class,
AcmContextBootstrapConfiguration.class })
public class StatisticsTaskStarter implements InitializingBean {
private static final String NACOS_CONFIG_SERVER_MODE_KEY = "spring.cloud.nacos.config.server-mode";
private static final String NACOS_DISCOVERY_SERVER_MODE_KEY = "spring.cloud.nacos.discovery.server-mode";
private static final String NACOS_SERVER_MODE_VALUE = "EDAS";
@Autowired(required = false)
private AliCloudEdasSdk aliCloudEdasSdk;
@Autowired(required = false)
private EdasProperties edasProperties;
@Autowired(required = false)
private ScxProperties scxProperties;
@Autowired(required = false)
private OssProperties ossProperties;
@Autowired(required = false)
private AnsProperties ansProperties;
@Autowired(required = false)
private AcmProperties acmProperties;
@Autowired(required = false)
private ScxContextAutoConfiguration scxContextAutoConfiguration;
@Autowired(required = false)
private OssContextAutoConfiguration ossContextAutoConfiguration;
@Autowired(required = false)
private AnsContextAutoConfiguration ansContextAutoConfiguration;
@Autowired(required = false)
private AcmContextBootstrapConfiguration acmContextBootstrapConfiguration;
@Override
public void afterPropertiesSet() {
StatisticsTask statisticsTask = new StatisticsTask(aliCloudEdasSdk,
edasProperties, getComponents());
statisticsTask.start();
}
private List<String> getComponents() {
List<String> components = new ArrayList<>();
if (scxContextAutoConfiguration != null && scxProperties != null) {
components.add("SC-SCX");
}
if (ossContextAutoConfiguration != null && ossProperties != null) {
components.add("SC-OSS");
}
boolean edasEnabled = edasProperties != null && edasProperties.isEnabled();
boolean ansEnableEdas = edasEnabled || (ansProperties != null
&& ansProperties.getServerMode() == AliCloudServerMode.EDAS);
if (ansContextAutoConfiguration != null && ansEnableEdas) {
components.add("SC-ANS");
}
boolean acmEnableEdas = edasEnabled || (acmProperties != null
&& acmProperties.getServerMode() == AliCloudServerMode.EDAS);
if (acmContextBootstrapConfiguration != null && acmEnableEdas) {
components.add("SC-ACM");
}
if (NACOS_SERVER_MODE_VALUE
.equals(System.getProperty(NACOS_CONFIG_SERVER_MODE_KEY))) {
components.add("SC-NACOS-CONFIG");
}
if (NACOS_SERVER_MODE_VALUE
.equals(System.getProperty(NACOS_DISCOVERY_SERVER_MODE_KEY))) {
components.add("SC-NACOS-DISCOVERY");
}
return components;
}
}

View File

@@ -0,0 +1,16 @@
{
"properties": [
{
"name": "spring.cloud.alicloud.ans.client-domains",
"type": "java.lang.String",
"defaultValue": "",
"description": "Service name list, default value is ${spring.application.name}."
},
{
"name": "spring.cloud.alicloud.ans.env",
"type": "java.lang.String",
"defaultValue": "DEFAULT",
"description": "The env for ans, default value is DEFAULT."
}
]
}

View File

@@ -0,0 +1,15 @@
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.alicloud.context.acm.AcmContextBootstrapConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration,\
org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration,\
org.springframework.cloud.alicloud.context.ans.AnsContextAutoConfiguration,\
org.springframework.cloud.alicloud.context.oss.OssContextAutoConfiguration,\
org.springframework.cloud.alicloud.context.scx.ScxContextAutoConfiguration,\
org.springframework.cloud.alicloud.context.statistics.StatisticsTaskStarter,\
org.springframework.cloud.alicloud.context.sms.SmsContextAutoConfiguration
org.springframework.context.ApplicationListener=\
org.springframework.cloud.alicloud.context.ans.AnsContextApplicationListener,\
org.springframework.cloud.alicloud.context.nacos.NacosConfigParameterInitListener,\
org.springframework.cloud.alicloud.context.nacos.NacosDiscoveryParameterInitListener,\
org.springframework.cloud.alicloud.context.sentinel.SentinelAliCloudListener