diff --git a/pom.xml b/pom.xml index ac929206..723a0a22 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,6 @@ spring-cloud-alibaba-examples spring-cloud-alibaba-docs spring-cloud-starter-alibaba - spring-cloud-starter-alicloud spring-cloud-alibaba-coverage diff --git a/spring-cloud-starter-alicloud/pom.xml b/spring-cloud-starter-alicloud/pom.xml deleted file mode 100644 index 06313076..00000000 --- a/spring-cloud-starter-alicloud/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - 4.0.0 - - - com.alibaba.cloud - spring-cloud-alibaba - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - spring-cloud-starter-alicloud - pom - Spring Cloud Alibaba Cloud Starters - Spring Cloud Alibaba Cloud Starters - - spring-cloud-alicloud-context - spring-cloud-starter-alicloud-oss - spring-cloud-starter-alicloud-acm - spring-cloud-starter-alicloud-ans - spring-cloud-starter-alicloud-schedulerx - spring-cloud-starter-alicloud-sms - - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - - jacoco-initialize - - prepare-agent - - - - jacoco-site - test - - report - - - - - - - \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/pom.xml b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/pom.xml deleted file mode 100644 index 2f7aee35..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/pom.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - com.alibaba.cloud - spring-cloud-starter-alicloud - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - 4.0.0 - - spring-cloud-alicloud-context - Spring Cloud AliCloud Context - - - - - com.aliyun - aliyun-java-sdk-edas - provided - - - com.aliyun - aliyun-java-sdk-core - - - - - - com.alibaba.cloud - alicloud-context - - - - com.aliyun - aliyun-java-sdk-core - provided - - - - com.alibaba.edas - schedulerX-client - provided - - - - com.alibaba.ans - ans-sdk - provided - - - - com.aliyun.oss - aliyun-sdk-oss - provided - - - - com.alibaba.edas.acm - acm-sdk - provided - - - - org.springframework.cloud - spring-cloud-commons - true - - - - org.springframework.boot - spring-boot-starter-logging - true - - - - org.springframework.boot - spring-boot - true - - - - org.springframework.boot - spring-boot-autoconfigure - true - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.boot - spring-boot-starter-web - test - - - - org.powermock - powermock-module-junit4 - 2.0.0 - test - - - - org.powermock - powermock-api-mockito2 - 2.0.0 - test - - - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - - jacoco-initialize - - prepare-agent - - - - jacoco-site - test - - report - - - - - - - diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java deleted file mode 100644 index e364fc53..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudContextAutoConfiguration.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context; - -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.commons.util.InetUtils; -import org.springframework.cloud.commons.util.InetUtilsProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - * @author theonefx - */ -@Configuration(proxyBeanMethods = false) -public class AliCloudContextAutoConfiguration { - - @Configuration(proxyBeanMethods = false) - @EnableConfigurationProperties(AliCloudProperties.class) - static class AliCloudPropertiesConfiguration { - - } - - @Configuration(proxyBeanMethods = false) - @EnableConfigurationProperties(InetUtilsProperties.class) - @ConditionalOnClass(InetUtilsProperties.class) - static class InetUtilsConfiguration { - - @Bean - @ConditionalOnMissingBean - public InetUtils inetUtils(InetUtilsProperties inetUtilsProperties) { - return new InetUtils(inetUtilsProperties); - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java deleted file mode 100644 index 43af7e1e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/AliCloudProperties.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context; - -import com.alibaba.cloud.context.AliCloudConfiguration; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * @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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java deleted file mode 100644 index 36aadc0f..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/Constants.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context; - -/** - * @author Jim - */ -public final class Constants { - - private Constants() { - throw new AssertionError("Must not instantiate constant utility class"); - } - - public final class Sentinel { - - /** - * prefix of sentinel. - */ - public static final String PROPERTY_PREFIX = "spring.cloud.sentinel"; - - /** - * nacos access key. - */ - public static final String NACOS_DATASOURCE_AK = PROPERTY_PREFIX - + ".nacos.config.access-key"; - - /** - * nacos secret key. - */ - public static final String NACOS_DATASOURCE_SK = PROPERTY_PREFIX - + ".nacos.config.secret-key"; - - /** - * nacos namespace. - */ - public static final String NACOS_DATASOURCE_NAMESPACE = PROPERTY_PREFIX - + ".nacos.config.namespace"; - - /** - * nacos endpoint. - */ - public static final String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX - + ".nacos.config.endpoint"; - - /** - * nacos project name. - */ - public static final String PROJECT_NAME = PROPERTY_PREFIX - + ".nacos.config.project-name"; - - private Sentinel() { - throw new AssertionError("Must not instantiate constant utility class"); - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java deleted file mode 100644 index bbf74c7c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmContextBootstrapConfiguration.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.acm; - -import javax.annotation.PostConstruct; - -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.cloud.context.acm.AliCloudAcmInitializer; - -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.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; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(AcmProperties.class) -@ConditionalOnClass(name = "com.alibaba.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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java deleted file mode 100644 index 88d35579..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmIntegrationProperties.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.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 getGroupConfigurationDataIds() { - List 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 getApplicationConfigurationDataIds() { - List 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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java deleted file mode 100644 index dea83224..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/acm/AcmProperties.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.acm; - -import com.alibaba.cloud.context.AliCloudServerMode; -import com.alibaba.cloud.context.acm.AcmConfiguration; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * 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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java deleted file mode 100644 index 2100b5fb..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.ans; - -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; -import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; -import com.alibaba.cloud.context.edas.AliCloudEdasSdk; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.event.ContextRefreshedEvent; - -/** - * Init {@link com.alibaba.ans.core.NamingService} properties. - * - * @author xiaolongzuo - */ -public class AnsContextApplicationListener - extends AbstractOnceApplicationListener { - - @Override - protected String conditionalOnClass() { - return "com.alibaba.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); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java deleted file mode 100644 index 32c4a602..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsContextAutoConfiguration.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.ans; - -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; - -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(name = "com.alibaba.alicloud.ans.AnsAutoConfiguration") -@EnableConfigurationProperties(AnsProperties.class) -@ImportAutoConfiguration(EdasContextAutoConfiguration.class) -public class AnsContextAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java deleted file mode 100644 index cf5592e0..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/ans/AnsProperties.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.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 com.alibaba.cloud.context.AliCloudServerMode; -import com.alibaba.cloud.context.ans.AnsConfiguration; - -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; - -/** - * @author xiaolongzuo - */ -@ConfigurationProperties("spring.cloud.alicloud.ans") -public class AnsProperties implements AnsConfiguration { - - /** - * Server side mode,the default is LOCAL. - */ - private AliCloudServerMode serverMode = AliCloudServerMode.LOCAL; - - /** - * Server list. - */ - private String serverList = "127.0.0.1"; - - /** - * Server port. - */ - private String serverPort = "8080"; - - /** - * Service names,default 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 clientWeights = new HashMap(); - - /** - * 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 clientTokens = new HashMap(); - - /** - * 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 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 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 = 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 getTags() { - return tags; - } - - public void setTags(Map 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 getClientWeights() { - return clientWeights; - } - - public void setClientWeights(Map clientWeights) { - this.clientWeights = clientWeights; - } - - @Override - public String getClientToken() { - return clientToken; - } - - public void setClientToken(String clientToken) { - this.clientToken = clientToken; - } - - @Override - public Map getClientTokens() { - return clientTokens; - } - - public void setClientTokens(Map clientTokens) { - this.clientTokens = clientTokens; - } - - @Override - public String getClientCluster() { - return clientCluster; - } - - public void setClientCluster(String clientCluster) { - this.clientCluster = clientCluster; - } - - @Override - public Map getClientMetadata() { - return clientMetadata; - } - - public void setClientMetadata(Map 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 + '}'; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java deleted file mode 100644 index badb7ee6..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasContextAutoConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.edas; - -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.cloud.context.edas.AliCloudEdasSdk; -import com.alibaba.cloud.context.edas.AliCloudEdasSdkFactory; - -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.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@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()); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java deleted file mode 100644 index 8cc4ffe9..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/edas/EdasProperties.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.edas; - -import com.alibaba.cloud.context.edas.EdasConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * @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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java deleted file mode 100644 index bff31292..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/listener/AbstractOnceApplicationListener.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.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 - implements ApplicationListener { - - private static final String BOOTSTRAP_CONFIG_NAME_VALUE = "bootstrap"; - - private static final String BOOTSTRAP_CONFIG_NAME_KEY = "spring.config.name"; - - private static ConcurrentHashMap, 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 event - */ - protected abstract void handleEvent(T event); - - /** - * condition on class. - * @return class name - */ - protected String conditionalOnClass() { - return null; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListener.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListener.java deleted file mode 100644 index a6585a1c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.nacos; - -import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; -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; - -/** - * @author pbting - */ -public class NacosConfigParameterInitListener - extends AbstractOnceApplicationListener { - - private static final Logger log = LoggerFactory - .getLogger(NacosConfigParameterInitListener.class); - - @Override - protected String conditionalOnClass() { - return "com.alibaba.cloud.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()); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java deleted file mode 100644 index 145605e3..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.nacos; - -import java.util.Properties; - -import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; -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; - -/** - * @author pbting - * @date 2019-02-14 11:12 AM - */ -public class NacosDiscoveryParameterInitListener - extends AbstractOnceApplicationListener { - - private static final Logger log = LoggerFactory - .getLogger(NacosDiscoveryParameterInitListener.class); - - @Override - protected String conditionalOnClass() { - return "com.alibaba.cloud.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"); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java deleted file mode 100644 index a50e6d03..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.oss; - -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.cloud.context.AliCloudAuthorizationMode; -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSClientBuilder; - -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.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * OSS Auto {@link Configuration}. - * - * @author Jim - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(name = "com.alibaba.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."); - } - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java deleted file mode 100644 index 468a485e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/oss/OssProperties.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.oss; - -import com.alibaba.cloud.context.AliCloudAuthorizationMode; -import com.aliyun.oss.ClientBuilderConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring OSS. - * - * @author Jim - * @author xiaolongzuo - */ -@ConfigurationProperties("spring.cloud.alicloud.oss") -public class OssProperties { - - /** - * Authorization Mode, please see oss - * docs. - */ - @Value("${spring.cloud.alicloud.oss.authorization-mode:AK_SK}") - private AliCloudAuthorizationMode authorizationMode; - - /** - * Endpoint, please see oss - * docs. - */ - private String endpoint; - - /** - * Sts token, please see oss - * docs. - */ - private StsToken sts; - - /** - * Client Configuration, please see oss - * docs. - */ - 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; - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java deleted file mode 100644 index 62cc85ea..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxContextAutoConfiguration.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.scx; - -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasProperties; -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.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(name = "com.alibaba.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); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java deleted file mode 100644 index 1fdce76d..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/scx/ScxProperties.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.scx; - -import com.alibaba.cloud.context.scx.ScxConfiguration; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * @author xiaolongzuo - */ -@ConfigurationProperties("spring.cloud.alicloud.scx") -public class ScxProperties implements ScxConfiguration { - - /** - * Group id, please see scx - * docs. - */ - private String groupId; - - /** - * Domain name, please see scx - * docs. - */ - 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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java deleted file mode 100644 index 29dc9637..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListener.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.sentinel; - -import com.alibaba.alicloud.context.Constants; -import com.alibaba.alicloud.context.listener.AbstractOnceApplicationListener; -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; - -/** - * @author Jim - */ -public class SentinelAliCloudListener - extends AbstractOnceApplicationListener { - - 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"; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java deleted file mode 100644 index dd49c578..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsContextAutoConfiguration.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.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(proxyBeanMethods = false) -@EnableConfigurationProperties(SmsProperties.class) -@ConditionalOnClass(name = "com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest") -@ConditionalOnProperty(name = "spring.cloud.alicloud.sms.enabled", matchIfMissing = true) -public class SmsContextAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java deleted file mode 100644 index 3f1fc961..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/sms/SmsProperties.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java deleted file mode 100644 index 412f8c11..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/java/com/alibaba/alicloud/context/statistics/StatisticsTaskStarter.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.statistics; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.alicloud.context.acm.AcmProperties; -import com.alibaba.alicloud.context.ans.AnsContextAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.alicloud.context.oss.OssContextAutoConfiguration; -import com.alibaba.alicloud.context.oss.OssProperties; -import com.alibaba.alicloud.context.scx.ScxContextAutoConfiguration; -import com.alibaba.alicloud.context.scx.ScxProperties; -import com.alibaba.cloud.context.AliCloudServerMode; -import com.alibaba.cloud.context.edas.AliCloudEdasSdk; -import com.alibaba.cloud.context.statistics.StatisticsTask; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@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 getComponents() { - List 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; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 2b81aad2..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "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." - } - ] -} \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 8c6c9957..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,15 +0,0 @@ -org.springframework.cloud.bootstrap.BootstrapConfiguration=\ - com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.alibaba.alicloud.context.AliCloudContextAutoConfiguration,\ - com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration,\ - com.alibaba.alicloud.context.ans.AnsContextAutoConfiguration,\ - com.alibaba.alicloud.context.oss.OssContextAutoConfiguration,\ - com.alibaba.alicloud.context.scx.ScxContextAutoConfiguration,\ - com.alibaba.alicloud.context.statistics.StatisticsTaskStarter,\ - com.alibaba.alicloud.context.sms.SmsContextAutoConfiguration -org.springframework.context.ApplicationListener=\ - com.alibaba.alicloud.context.ans.AnsContextApplicationListener,\ - com.alibaba.alicloud.context.nacos.NacosConfigParameterInitListener,\ - com.alibaba.alicloud.context.nacos.NacosDiscoveryParameterInitListener,\ - com.alibaba.alicloud.context.sentinel.SentinelAliCloudListener \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java deleted file mode 100644 index 93810221..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm; - -/** - * @author xiaolongzuo - */ -public class AcmAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java deleted file mode 100644 index 9f472639..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -/** - * @author xiaolongzuo - */ -public class AnsAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java deleted file mode 100644 index e2b1d51c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/AliCloudPropertiesTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context; - -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author xiaolongzuo - */ -public class AliCloudPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration( - AutoConfigurations.of(AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.run(context -> { - AliCloudProperties aliCloudProperties = context - .getBean(AliCloudProperties.class); - assertThat(aliCloudProperties.getAccessKey()).isNull(); - assertThat(aliCloudProperties.getSecretKey()).isNull(); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded() { - this.contextRunner.withPropertyValues("spring.cloud.alicloud.access-key=123", - "spring.cloud.alicloud.secret-key=123456").run(context -> { - AliCloudProperties aliCloudProperties = context - .getBean(AliCloudProperties.class); - assertThat(aliCloudProperties.getAccessKey()).isEqualTo("123"); - assertThat(aliCloudProperties.getSecretKey()).isEqualTo("123456"); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java deleted file mode 100644 index 9634b647..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/BaseAliCloudSpringApplication.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context; - -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * @author xiaolongzuo - */ -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore("javax.management.*") -@SpringBootTest(classes = BaseAliCloudSpringApplication.AliCloudApplication.class, - properties = { "spring.application.name=myapp", - "spring.cloud.alicloud.edas.application.name=myapp", - "spring.cloud.alicloud.access-key=ak", - "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.oss.endpoint=test", - "spring.cloud.alicloud.scx.group-id=1-2-3-4", - "spring.cloud.alicloud.edas.namespace=cn-test", - "spring.cloud.alicloud.ans.server-list=192.168.1.100", - "spring.cloud.alicloud.ans.server-port=8888", - "spring.cloud.alicloud.oss.enabled=false", - "spring.cloud.alicloud.scx.enabled=false" }) -public abstract class BaseAliCloudSpringApplication { - - @SpringBootApplication - public static class AliCloudApplication { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java deleted file mode 100644 index 55339edb..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/acm/AcmPropertiesTests.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.acm; - -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.cloud.context.AliCloudServerMode; -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -/** - * @author xiaolongzuo - */ -public class AcmPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration( - AutoConfigurations.of(AcmContextBootstrapConfiguration.class, - EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.withPropertyValues("spring.application.name=myapp") - .run(context -> { - AcmProperties config = context.getBean(AcmProperties.class); - assertThat(config.getServerMode()) - .isEqualTo(AliCloudServerMode.LOCAL); - assertThat(config.getServerList()).isEqualTo("127.0.0.1"); - assertThat(config.getServerPort()).isEqualTo("8080"); - assertThat(config.getEndpoint()).isNull(); - assertThat(config.getFileExtension()).isEqualTo("properties"); - assertThat(config.getGroup()).isEqualTo("DEFAULT_GROUP"); - assertThat(config.getNamespace()).isNull(); - assertThat(config.getRamRoleName()).isNull(); - assertThat(config.getTimeout()).isEqualTo(3000); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded() { - this.contextRunner.withPropertyValues("spring.application.name=myapp", - "spring.cloud.alicloud.access-key=ak", - "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.acm.server-mode=EDAS", - "spring.cloud.alicloud.acm.server-port=11111", - "spring.cloud.alicloud.acm.server-list=10.10.10.10", - "spring.cloud.alicloud.acm.namespace=testNamespace", - "spring.cloud.alicloud.acm.endpoint=testDomain", - "spring.cloud.alicloud.acm.group=testGroup", - "spring.cloud.alicloud.acm.file-extension=yaml").run(context -> { - AcmProperties acmProperties = context.getBean(AcmProperties.class); - assertThat(acmProperties.getServerMode()) - .isEqualTo(AliCloudServerMode.EDAS); - assertThat(acmProperties.getServerList()).isEqualTo("10.10.10.10"); - assertThat(acmProperties.getServerPort()).isEqualTo("11111"); - assertThat(acmProperties.getEndpoint()).isEqualTo("testDomain"); - assertThat(acmProperties.getGroup()).isEqualTo("testGroup"); - assertThat(acmProperties.getFileExtension()).isEqualTo("yaml"); - assertThat(acmProperties.getNamespace()).isEqualTo("testNamespace"); - }); - } - - @Test - public void testAcmIntegrationConfigurationValuesAreCorrectlyLoaded() { - this.contextRunner.withPropertyValues("spring.application.name=myapp", - "spring.application.group=com.alicloud.test", - "spring.cloud.alicloud.access-key=ak", - "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.acm.server-mode=EDAS", - "spring.cloud.alicloud.acm.server-port=11111", - "spring.cloud.alicloud.acm.server-list=10.10.10.10", - "spring.cloud.alicloud.acm.namespace=testNamespace", - "spring.cloud.alicloud.acm.endpoint=testDomain", - "spring.cloud.alicloud.acm.group=testGroup", - "spring.cloud.alicloud.acm.file-extension=yaml").run(context -> { - AcmIntegrationProperties acmIntegrationProperties = context - .getBean(AcmIntegrationProperties.class); - assertThat(acmIntegrationProperties.getGroupConfigurationDataIds() - .size()).isEqualTo(2); - assertThat(acmIntegrationProperties - .getApplicationConfigurationDataIds().size()).isEqualTo(2); - }); - } - - @Test - public void testAcmIntegrationConfigurationValuesAreCorrectlyLoaded2() { - this.contextRunner.withPropertyValues("spring.application.name=myapp", - "spring.application.group=com.alicloud.test", - "spring.profiles.active=profile1,profile2", - "spring.cloud.alicloud.access-key=ak", - "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.acm.server-mode=EDAS", - "spring.cloud.alicloud.acm.server-port=11111", - "spring.cloud.alicloud.acm.server-list=10.10.10.10", - "spring.cloud.alicloud.acm.namespace=testNamespace", - "spring.cloud.alicloud.acm.endpoint=testDomain", - "spring.cloud.alicloud.acm.group=testGroup", - "spring.cloud.alicloud.acm.file-extension=yaml").run(context -> { - AcmIntegrationProperties acmIntegrationProperties = context - .getBean(AcmIntegrationProperties.class); - assertThat(acmIntegrationProperties.getGroupConfigurationDataIds() - .size()).isEqualTo(2); - assertThat(acmIntegrationProperties - .getApplicationConfigurationDataIds().size()).isEqualTo(6); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java deleted file mode 100644 index f39f2ff6..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsContextApplicationListenerTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.ans; - -import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; -import org.junit.Test; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -/** - * @author xiaolongzuo - */ -public class AnsContextApplicationListenerTests extends BaseAliCloudSpringApplication { - - @Test - public void testAnsContextApplicationListenerDefault() { - assertThat(System - .getProperty("com.alibaba.ans.shaded.com.taobao.vipserver.serverlist")) - .isEqualTo("192.168.1.100"); - assertThat(System.getProperty("vipserver.server.port")).isEqualTo("8888"); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java deleted file mode 100644 index 3b7859e2..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/ans/AnsPropertiesTests.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.ans; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Vector; - -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import com.alibaba.cloud.context.AliCloudServerMode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -/** - * @author xiaolongzuo - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({ NetworkInterface.class, AnsProperties.class }) -public class AnsPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AnsContextAutoConfiguration.class, - EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.withPropertyValues().run(context -> { - AnsProperties ansProperties = context.getBean(AnsProperties.class); - assertThat(ansProperties.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL); - assertThat(ansProperties.getServerList()).isEqualTo("127.0.0.1"); - assertThat(ansProperties.getServerPort()).isEqualTo("8080"); - assertThat(ansProperties.getClientDomains()).isEqualTo(""); - assertThat(ansProperties.getClientWeight()).isEqualTo(1.0F); - assertThat(ansProperties.getClientWeights().size()).isEqualTo(0); - assertThat(ansProperties.getClientTokens().size()).isEqualTo(0); - assertThat(ansProperties.getClientMetadata().size()).isEqualTo(0); - assertThat(ansProperties.getClientToken()).isNull(); - assertThat(ansProperties.getClientCluster()).isEqualTo("DEFAULT"); - assertThat(ansProperties.isRegisterEnabled()).isTrue(); - assertThat(ansProperties.getClientInterfaceName()).isNull(); - assertThat(ansProperties.getClientPort()).isEqualTo(-1); - assertThat(ansProperties.getEnv()).isEqualTo("DEFAULT"); - assertThat(ansProperties.isSecure()).isFalse(); - assertThat(ansProperties.getTags().size()).isEqualTo(1); - assertThat(ansProperties.getTags().keySet().iterator().next()) - .isEqualTo("ANS_SERVICE_TYPE"); - assertThat(ansProperties.getTags().get("ANS_SERVICE_TYPE")) - .isEqualTo("SPRING_CLOUD"); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded1() { - this.contextRunner - .withPropertyValues("spring.cloud.alicloud.ans.server-mode=EDAS", - "spring.cloud.alicloud.ans.server-port=11111", - "spring.cloud.alicloud.ans.server-list=10.10.10.10", - "spring.cloud.alicloud.ans.client-domains=testDomain", - "spring.cloud.alicloud.ans.client-weight=0.9", - "spring.cloud.alicloud.ans.client-weights.testDomain=0.9") - .run(context -> { - AnsProperties ansProperties = context.getBean(AnsProperties.class); - assertThat(ansProperties.getServerMode()) - .isEqualTo(AliCloudServerMode.EDAS); - assertThat(ansProperties.getServerList()).isEqualTo("10.10.10.10"); - assertThat(ansProperties.getServerPort()).isEqualTo("11111"); - assertThat(ansProperties.getClientDomains()).isEqualTo("testDomain"); - assertThat(ansProperties.getClientWeight()).isEqualTo(0.9F); - assertThat(ansProperties.getClientWeights().size()).isEqualTo(1); - assertThat(ansProperties.getClientTokens().size()).isEqualTo(0); - assertThat(ansProperties.getClientMetadata().size()).isEqualTo(0); - assertThat(ansProperties.getClientToken()).isNull(); - assertThat(ansProperties.getClientCluster()).isEqualTo("DEFAULT"); - assertThat(ansProperties.isRegisterEnabled()).isTrue(); - assertThat(ansProperties.getClientInterfaceName()).isNull(); - assertThat(ansProperties.getClientPort()).isEqualTo(-1); - assertThat(ansProperties.getEnv()).isEqualTo("DEFAULT"); - assertThat(ansProperties.isSecure()).isFalse(); - assertThat(ansProperties.getTags().size()).isEqualTo(1); - assertThat(ansProperties.getTags().keySet().iterator().next()) - .isEqualTo("ANS_SERVICE_TYPE"); - assertThat(ansProperties.getTags().get("ANS_SERVICE_TYPE")) - .isEqualTo("SPRING_CLOUD"); - }); - } - - @Test(expected = RuntimeException.class) - public void testConfigurationValuesAreCorrectlyLoaded2() { - this.contextRunner.withPropertyValues( - "spring.cloud.alicloud.ans.client-interface-name=noneinterfacename") - .run(context -> { - AnsProperties ansProperties = context.getBean(AnsProperties.class); - assertThat(ansProperties.getClientInterfaceName()) - .isEqualTo("noneinterfacename"); - }); - } - - // @Test - public void testConfigurationValuesAreCorrectlyLoaded3() throws SocketException { - NetworkInterface networkInterface = PowerMockito.mock(NetworkInterface.class); - Vector inetAddressList = new Vector<>(); - Inet4Address inetAddress = PowerMockito.mock(Inet4Address.class); - PowerMockito.when(inetAddress.getHostAddress()).thenReturn("192.168.1.100"); - inetAddressList.add(inetAddress); - PowerMockito.when(networkInterface.getInetAddresses()) - .thenReturn(inetAddressList.elements()); - PowerMockito.mockStatic(NetworkInterface.class); - PowerMockito.when(NetworkInterface.getByName("eth0")) - .thenReturn(networkInterface); - this.contextRunner - .withPropertyValues( - "spring.cloud.alicloud.ans.client-interface-name=eth0") - .run(context -> { - AnsProperties ansProperties = context.getBean(AnsProperties.class); - assertThat(ansProperties.getClientInterfaceName()).isEqualTo("eth0"); - assertThat(ansProperties.getClientIp()).isEqualTo("192.168.1.100"); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java deleted file mode 100644 index bc338033..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/edas/EdasPropertiesTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.edas; - -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author xiaolongzuo - */ -public class EdasPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.withPropertyValues().run(context -> { - EdasProperties edasProperties = context.getBean(EdasProperties.class); - assertThat(edasProperties.getNamespace()).isNull(); - assertThat(edasProperties.isApplicationNameValid()).isFalse(); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded1() { - this.contextRunner - .withPropertyValues("spring.cloud.alicloud.edas.namespace=testns", - "spring.application.name=myapps") - .run(context -> { - EdasProperties edasProperties = context.getBean(EdasProperties.class); - assertThat(edasProperties.getNamespace()).isEqualTo("testns"); - assertThat(edasProperties.getApplicationName()).isEqualTo("myapps"); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded2() { - this.contextRunner - .withPropertyValues("spring.cloud.alicloud.edas.namespace=testns", - "spring.cloud.alicloud.edas.application.name=myapps") - .run(context -> { - EdasProperties edasProperties = context.getBean(EdasProperties.class); - assertThat(edasProperties.getNamespace()).isEqualTo("testns"); - assertThat(edasProperties.getApplicationName()).isEqualTo("myapps"); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java deleted file mode 100644 index 221e1ff2..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosConfigParameterInitListenerTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.nacos; - -import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; -import com.alibaba.alicloud.utils.ChangeOrderUtils; -import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author xiaolongzuo - */ -@PrepareForTest({ EdasChangeOrderConfigurationFactory.class, - NacosConfigParameterInitListener.class, AliCloudAnsInitializer.class }) -public class NacosConfigParameterInitListenerTests extends BaseAliCloudSpringApplication { - - @BeforeClass - public static void setUp() { - ChangeOrderUtils.mockChangeOrder(); - } - - @Test - public void testNacosParameterInitListener() { - assertThat(System.getProperty("spring.cloud.nacos.config.server-mode")) - .isEqualTo("EDAS"); - assertThat(System.getProperty("spring.cloud.nacos.config.server-addr")) - .isEqualTo(""); - assertThat(System.getProperty("spring.cloud.nacos.config.endpoint")) - .isEqualTo("testDomain"); - assertThat(System.getProperty("spring.cloud.nacos.config.namespace")) - .isEqualTo("testTenantId"); - assertThat(System.getProperty("spring.cloud.nacos.config.access-key")) - .isEqualTo("testAK"); - assertThat(System.getProperty("spring.cloud.nacos.config.secret-key")) - .isEqualTo("testSK"); - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java deleted file mode 100644 index 35d1489e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.nacos; - -import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; -import com.alibaba.alicloud.utils.ChangeOrderUtils; -import com.alibaba.cloud.context.ans.AliCloudAnsInitializer; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author xiaolongzuo - */ -@PrepareForTest({ EdasChangeOrderConfigurationFactory.class, - NacosDiscoveryParameterInitListener.class, AliCloudAnsInitializer.class }) -public class NacosDiscoveryParameterInitListenerTests - extends BaseAliCloudSpringApplication { - - @BeforeClass - public static void setUp() { - ChangeOrderUtils.mockChangeOrder(); - } - - @Test - public void testNacosParameterInitListener() { - assertThat(System.getProperty("spring.cloud.nacos.discovery.server-mode")) - .isEqualTo("EDAS"); - assertThat(System.getProperty("spring.cloud.nacos.discovery.server-addr")) - .isEqualTo(""); - assertThat(System.getProperty("spring.cloud.nacos.discovery.endpoint")) - .isEqualTo("testDomain"); - assertThat(System.getProperty("spring.cloud.nacos.discovery.namespace")) - .isEqualTo("testTenantId"); - assertThat(System.getProperty("spring.cloud.nacos.discovery.access-key")) - .isEqualTo("testAK"); - assertThat(System.getProperty("spring.cloud.nacos.discovery.secret-key")) - .isEqualTo("testSK"); - assertThat(System.getProperties().getProperty("nacos.naming.web.context")) - .isEqualTo("/vipserver"); - assertThat(System.getProperties().getProperty("nacos.naming.exposed.port")) - .isEqualTo("80"); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java deleted file mode 100644 index 0772e30e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/oss/OssAutoConfigurationTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.oss; - -import com.alibaba.alicloud.context.AliCloudProperties; -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSClient; -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * {@link OSS} {@link OssProperties} Test. - * - * @author Jim - */ -public class OssAutoConfigurationTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(OssContextAutoConfiguration.class)) - .withPropertyValues("spring.cloud.alicloud.accessKey=your-ak", - "spring.cloud.alicloud.secretKey=your-sk", - "spring.cloud.alicloud.oss.endpoint=http://oss-cn-beijing.aliyuncs.com", - "spring.cloud.alicloud.oss.config.userAgent=alibaba", - "spring.cloud.alicloud.oss.sts.access-key=your-sts-ak", - "spring.cloud.alicloud.oss.sts.secret-key=your-sts-sk", - "spring.cloud.alicloud.oss.sts.security-token=your-sts-token"); - - @Test - public void testOSSProperties() { - this.contextRunner.run(context -> { - assertThat(context.getBeansOfType(OssProperties.class).size() == 1).isTrue(); - AliCloudProperties aliCloudProperties = context - .getBean(AliCloudProperties.class); - OssProperties ossProperties = context.getBean(OssProperties.class); - assertThat(aliCloudProperties.getAccessKey()).isEqualTo("your-ak"); - assertThat(aliCloudProperties.getSecretKey()).isEqualTo("your-sk"); - assertThat(ossProperties.getEndpoint()) - .isEqualTo("http://oss-cn-beijing.aliyuncs.com"); - assertThat(ossProperties.getConfig().getUserAgent()).isEqualTo("alibaba"); - assertThat(ossProperties.getSts().getAccessKey()).isEqualTo("your-sts-ak"); - assertThat(ossProperties.getSts().getSecretKey()).isEqualTo("your-sts-sk"); - assertThat(ossProperties.getSts().getSecurityToken()) - .isEqualTo("your-sts-token"); - }); - } - - @Test - public void testOSSClient1() { - this.contextRunner.run(context -> { - assertThat(context.getBeansOfType(OSS.class).size() == 1).isTrue(); - assertThat(context.getBeanNamesForType(OSS.class)[0]).isEqualTo("ossClient"); - OSSClient ossClient = (OSSClient) context.getBean(OSS.class); - assertThat(ossClient.getEndpoint().toString()) - .isEqualTo("http://oss-cn-beijing.aliyuncs.com"); - assertThat(ossClient.getClientConfiguration().getUserAgent()) - .isEqualTo("alibaba"); - assertThat( - ossClient.getCredentialsProvider().getCredentials().getAccessKeyId()) - .isEqualTo("your-ak"); - assertThat(ossClient.getCredentialsProvider().getCredentials() - .getSecretAccessKey()).isEqualTo("your-sk"); - }); - } - - @Test - public void testOSSClient2() { - this.contextRunner - .withPropertyValues("spring.cloud.alicloud.oss.authorization-mode=STS") - .run(context -> { - assertThat(context.getBeansOfType(OSS.class).size() == 1).isTrue(); - assertThat(context.getBeanNamesForType(OSS.class)[0]) - .isEqualTo("ossClient"); - OSSClient ossClient = (OSSClient) context.getBean(OSS.class); - assertThat(ossClient.getEndpoint().toString()) - .isEqualTo("http://oss-cn-beijing.aliyuncs.com"); - assertThat(ossClient.getClientConfiguration().getUserAgent()) - .isEqualTo("alibaba"); - assertThat(ossClient.getCredentialsProvider().getCredentials() - .getAccessKeyId()).isEqualTo("your-sts-ak"); - assertThat(ossClient.getCredentialsProvider().getCredentials() - .getSecretAccessKey()).isEqualTo("your-sts-sk"); - assertThat(ossClient.getCredentialsProvider().getCredentials() - .getSecurityToken()).isEqualTo("your-sts-token"); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java deleted file mode 100644 index ce3f78ac..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/scx/ScxAutoConfigurationTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.scx; - -import com.alibaba.alicloud.context.edas.EdasProperties; -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author xiaolongzuo - */ -public class ScxAutoConfigurationTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(ScxContextAutoConfiguration.class)) - .withPropertyValues("spring.cloud.alicloud.scx.group-id=1-2-3-4") - .withPropertyValues("spring.cloud.alicloud.edas.namespace=cn-test"); - - @Test - public void testSxcProperties() { - this.contextRunner.run(context -> { - assertThat(context.getBeansOfType(ScxProperties.class).size() == 1).isTrue(); - EdasProperties edasProperties = context.getBean(EdasProperties.class); - ScxProperties scxProperties = context.getBean(ScxProperties.class); - assertThat(scxProperties.getGroupId()).isEqualTo("1-2-3-4"); - assertThat(edasProperties.getNamespace()).isEqualTo("cn-test"); - assertThat(scxProperties.getDomainName()).isNull(); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java deleted file mode 100644 index 389361d6..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sentinel/SentinelAliCloudListenerTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.sentinel; - -import com.alibaba.alicloud.context.BaseAliCloudSpringApplication; -import com.alibaba.alicloud.context.Constants; -import com.alibaba.alicloud.utils.ChangeOrderUtils; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * @author xiaolongzuo - */ -@PrepareForTest({ EdasChangeOrderConfigurationFactory.class, - SentinelAliCloudListener.class }) -public class SentinelAliCloudListenerTests extends BaseAliCloudSpringApplication { - - @BeforeClass - public static void setUp() { - ChangeOrderUtils.mockChangeOrder(); - } - - @Test - public void testNacosParameterInitListener() { - assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_ENDPOINT)) - .isEqualTo("testDomain"); - assertThat(System.getProperty(Constants.Sentinel.PROJECT_NAME)) - .isEqualTo("testProjectName"); - assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_NAMESPACE)) - .isEqualTo("testTenantId"); - assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_AK)) - .isEqualTo("testAK"); - assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_SK)) - .isEqualTo("testSK"); - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java deleted file mode 100644 index b3c674e6..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/context/sms/SmsPropertiesTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.context.sms; - -import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration; -import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration; -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -/** - * @author xiaolongzuo - */ -public class SmsPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SmsContextAutoConfiguration.class, - EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.run(context -> { - SmsProperties config = context.getBean(SmsProperties.class); - assertThat(config.getReportQueueName()).isNull(); - assertThat(config.getUpQueueName()).isNull(); - assertThat(config.getConnectTimeout()).isEqualTo("10000"); - assertThat(config.getReadTimeout()).isEqualTo("10000"); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded() { - this.contextRunner - .withPropertyValues("spring.cloud.alicloud.sms.reportQueueName=q1", - "spring.cloud.alicloud.sms.upQueueName=q2", - "spring.cloud.alicloud.sms.connect-timeout=20", - "spring.cloud.alicloud.sms.read-timeout=30") - .run(context -> { - SmsProperties config = context.getBean(SmsProperties.class); - assertThat(config.getReportQueueName()).isEqualTo("q1"); - assertThat(config.getUpQueueName()).isEqualTo("q2"); - assertThat(config.getConnectTimeout()).isEqualTo("20"); - assertThat(config.getReadTimeout()).isEqualTo("30"); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java deleted file mode 100644 index 568d475c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss; - -/** - * @author xiaolongzuo - */ -public class OssAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java deleted file mode 100644 index 80e81031..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.scx; - -/** - * @author xiaolongzuo - */ -public class ScxAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java deleted file mode 100644 index 2c5b0fe5..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/alicloud/utils/ChangeOrderUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.utils; - -import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration; -import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory; -import org.powermock.api.mockito.PowerMockito; - -/** - * @author xiaolongzuo - */ -public final class ChangeOrderUtils { - - private ChangeOrderUtils() { - } - - public static void mockChangeOrder() { - EdasChangeOrderConfiguration edasChangeOrderConfiguration = PowerMockito - .mock(EdasChangeOrderConfiguration.class); - PowerMockito.when(edasChangeOrderConfiguration.isEdasManaged()).thenReturn(true); - PowerMockito.when(edasChangeOrderConfiguration.getAddressServerDomain()) - .thenReturn("testDomain"); - PowerMockito.when(edasChangeOrderConfiguration.getTenantId()) - .thenReturn("testTenantId"); - PowerMockito.when(edasChangeOrderConfiguration.getDauthAccessKey()) - .thenReturn("testAK"); - PowerMockito.when(edasChangeOrderConfiguration.getDauthSecretKey()) - .thenReturn("testSK"); - PowerMockito.when(edasChangeOrderConfiguration.getProjectName()) - .thenReturn("testProjectName"); - PowerMockito.when(edasChangeOrderConfiguration.getAddressServerPort()) - .thenReturn("8080"); - PowerMockito.mockStatic(EdasChangeOrderConfigurationFactory.class); - PowerMockito - .when(EdasChangeOrderConfigurationFactory - .getEdasChangeOrderConfiguration()) - .thenReturn(edasChangeOrderConfiguration); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java deleted file mode 100644 index b39d75ec..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosConfigAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.cloud.nacos; - -/** - * @author xiaolongzuo - */ -public class NacosConfigAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java deleted file mode 100644 index 4b584239..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.cloud.nacos; - -/** - * @author xiaolongzuo - */ -public class NacosDiscoveryAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java deleted file mode 100644 index 3ea26682..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/alibaba/csp/sentinel/datasource/nacos/NacosDataSource.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.csp.sentinel.datasource.nacos; - -/** - * @author xiaolongzuo - */ -public class NacosDataSource { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java b/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java deleted file mode 100644 index 5f943018..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-alicloud-context/src/test/java/com/aliyuncs/dysmsapi/model/v20170525/SendSmsRequest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.aliyuncs.dysmsapi.model.v20170525; - -/** - * @author xiaolongzuo - */ -public class SendSmsRequest { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/pom.xml b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/pom.xml deleted file mode 100644 index 0ba4cd28..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/pom.xml +++ /dev/null @@ -1,87 +0,0 @@ - - 4.0.0 - - - com.alibaba.cloud - spring-cloud-starter-alicloud - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - spring-cloud-starter-alicloud-acm - Spring Cloud Starter Alibaba Cloud ACM - - - - org.springframework.boot - spring-boot-starter - - - - com.alibaba.cloud - spring-cloud-alicloud-context - - - - com.aliyun - aliyun-java-sdk-core - - - - com.aliyun - aliyun-java-sdk-edas - - - - com.alibaba.edas.acm - acm-sdk - - - - org.springframework.boot - spring-boot-autoconfigure - true - - - - org.springframework.boot - spring-boot-starter-actuator - true - - - - - org.springframework.cloud - spring-cloud-context - - - org.springframework.cloud - spring-cloud-commons - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.powermock - powermock-module-junit4 - 2.0.0 - test - - - org.powermock - powermock-api-mockito2 - 2.0.0 - test - - - - diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java deleted file mode 100644 index ac4065b9..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm; - -import com.alibaba.alicloud.acm.refresh.AcmContextRefresher; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; -import com.taobao.diamond.client.Diamond; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.context.refresh.ContextRefresher; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Created on 01/10/2017. - * - * @author juven.xuxb - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ Diamond.class }) -@ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) -public class AcmAutoConfiguration { - - @Bean - public AcmRefreshHistory acmRefreshHistory() { - return new AcmRefreshHistory(); - } - - @Bean - public AcmContextRefresher acmContextRefresher( - AcmIntegrationProperties acmIntegrationProperties, - ContextRefresher contextRefresher, AcmRefreshHistory refreshHistory, - AcmPropertySourceRepository acmPropertySourceRepository) { - return new AcmContextRefresher(contextRefresher, acmIntegrationProperties, - refreshHistory, acmPropertySourceRepository); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java deleted file mode 100644 index 4604ae6c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmPropertySourceRepository.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; - -import org.springframework.core.env.PropertySource; - -/** - * @author juven.xuxb, 5/17/16. - * @author yuhuangbin - */ -public class AcmPropertySourceRepository { - - private Map acmPropertySourceMap = new ConcurrentHashMap<>(); - - /** - * get all acm properties from AcmPropertySourceRepository. - * @return list of acm propertysource - */ - public List allAcmPropertySource() { - List result = new ArrayList<>(); - result.addAll(this.acmPropertySourceMap.values()); - return result; - } - - public void collectAcmPropertySource( - Collection> acmPropertySources) { - acmPropertySources.forEach(propertySource -> { - if (propertySource.getClass().isAssignableFrom(AcmPropertySource.class)) { - AcmPropertySource acmPropertySource = (AcmPropertySource) propertySource; - this.acmPropertySourceMap.put(getMapKey(acmPropertySource.getDataId(), - acmPropertySource.getGroup()), acmPropertySource); - } - }); - } - - public String getMapKey(String dataId, String group) { - return String.join(",", dataId, group); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmConfigBootStrapConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmConfigBootStrapConfiguration.java deleted file mode 100644 index 91bb484a..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmConfigBootStrapConfiguration.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.bootstrap; - -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; -import com.taobao.diamond.client.Diamond; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author yuhuangbin - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ Diamond.class }) -@ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) -public class AcmConfigBootStrapConfiguration { - - @Bean - public AcmPropertySourceRepository acmPropertySourceRepository() { - return new AcmPropertySourceRepository(); - } - - @Bean - public AcmPropertySourceLocator acmPropertySourceLocator( - AcmPropertySourceRepository acmPropertySourceRepository, - AcmIntegrationProperties acmIntegrationProperties) { - return new AcmPropertySourceLocator(acmIntegrationProperties, - acmPropertySourceRepository); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java deleted file mode 100644 index 5fc7020a..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySource.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.bootstrap; - -import java.util.Date; -import java.util.Map; - -import org.springframework.core.env.MapPropertySource; - -/** - * @author juven.xuxb - * @author xiaolongzuo - */ -public class AcmPropertySource extends MapPropertySource { - - private final String dataId; - - private final String group; - - private final Date timestamp; - - private final boolean groupLevel; - - AcmPropertySource(String dataId, String group, Map source, - Date timestamp, boolean groupLevel) { - super(dataId, source); - this.dataId = dataId; - this.group = group; - this.timestamp = timestamp; - this.groupLevel = groupLevel; - } - - public String getDataId() { - return dataId; - } - - public Date getTimestamp() { - return timestamp; - } - - public String getGroup() { - return group; - } - - public boolean isGroupLevel() { - return groupLevel; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java deleted file mode 100644 index be5130bb..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.bootstrap; - -import java.io.StringReader; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import com.alibaba.edas.acm.ConfigService; -import com.alibaba.edas.acm.exception.ConfigException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.util.StringUtils; - -/** - * @author juven.xuxb - * @author xiaolongzuo - */ -class AcmPropertySourceBuilder { - - private Logger log = LoggerFactory.getLogger(AcmPropertySourceBuilder.class); - - /** - * 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象. - * @param dataId dataid of diamond - * @param diamondGroup group of diamond - * @param groupLevel group level of diamond - * @return acm property source - */ - AcmPropertySource build(String dataId, String diamondGroup, boolean groupLevel) { - Properties properties = loadDiamondData(dataId, diamondGroup); - if (properties == null) { - return null; - } - return new AcmPropertySource(dataId, diamondGroup, toMap(properties), new Date(), - groupLevel); - } - - private Properties loadDiamondData(String dataId, String diamondGroup) { - try { - String data = ConfigService.getConfig(dataId, diamondGroup, 3000L); - if (StringUtils.isEmpty(data)) { - return null; - } - if (dataId.endsWith(".properties")) { - Properties properties = new Properties(); - log.info(String.format("Loading acm data, dataId: '%s', group: '%s'", - dataId, diamondGroup)); - properties.load(new StringReader(data)); - return properties; - } - else if (dataId.endsWith(".yaml") || dataId.endsWith(".yml")) { - YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean(); - yamlFactory.setResources(new ByteArrayResource(data.getBytes())); - return yamlFactory.getObject(); - } - } - catch (Exception e) { - if (e instanceof ConfigException) { - log.error("DIAMOND-100500:" + dataId + ", " + e.toString(), e); - } - else { - log.error("DIAMOND-100500:" + dataId, e); - } - } - return null; - } - - @SuppressWarnings("unchecked") - private Map toMap(Properties properties) { - Map result = new HashMap<>(); - Enumeration keys = (Enumeration) properties.propertyNames(); - while (keys.hasMoreElements()) { - String key = keys.nextElement(); - Object value = properties.getProperty(key); - if (value != null) { - result.put(key, ((String) value).trim()); - } - else { - result.put(key, null); - } - } - return result; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java deleted file mode 100644 index 4c983c80..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.bootstrap; - -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; - -import org.springframework.cloud.bootstrap.config.PropertySourceLocator; -import org.springframework.core.env.CompositePropertySource; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertySource; - -/** - * @author juven.xuxb - * @author xiaolongzuo - * @author yuhuangbin - */ -public class AcmPropertySourceLocator implements PropertySourceLocator { - - private static final String DIAMOND_PROPERTY_SOURCE_NAME = "diamond"; - - private AcmPropertySourceBuilder acmPropertySourceBuilder = new AcmPropertySourceBuilder(); - - private AcmIntegrationProperties acmIntegrationProperties; - - private AcmPropertySourceRepository acmPropertySourceRepository; - - public AcmPropertySourceLocator(AcmIntegrationProperties acmIntegrationProperties, - AcmPropertySourceRepository acmPropertySourceRepository) { - this.acmIntegrationProperties = acmIntegrationProperties; - this.acmPropertySourceRepository = acmPropertySourceRepository; - } - - @Override - public PropertySource locate(Environment environment) { - - CompositePropertySource compositePropertySource = new CompositePropertySource( - DIAMOND_PROPERTY_SOURCE_NAME); - - acmIntegrationProperties.setActiveProfiles(environment.getActiveProfiles()); - - for (String dataId : acmIntegrationProperties.getGroupConfigurationDataIds()) { - loadDiamondDataIfPresent(compositePropertySource, dataId, - acmIntegrationProperties.getAcmProperties().getGroup(), true); - } - - for (String dataId : acmIntegrationProperties - .getApplicationConfigurationDataIds()) { - loadDiamondDataIfPresent(compositePropertySource, dataId, - acmIntegrationProperties.getAcmProperties().getGroup(), false); - } - acmPropertySourceRepository - .collectAcmPropertySource(compositePropertySource.getPropertySources()); - return compositePropertySource; - } - - private void loadDiamondDataIfPresent(final CompositePropertySource composite, - final String dataId, final String diamondGroup, final boolean groupLevel) { - AcmPropertySource ps = acmPropertySourceBuilder.build(dataId, diamondGroup, - groupLevel); - if (ps != null) { - composite.addFirstPropertySource(ps); - } - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java deleted file mode 100644 index 6a84b844..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpoint.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.endpoint; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmProperties; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - -/** - * Created on 01/10/2017. - * - * @author juven.xuxb - */ -@Endpoint(id = "acm") -public class AcmEndpoint { - - private final AcmProperties properties; - - private final AcmRefreshHistory refreshHistory; - - private final AcmPropertySourceRepository acmPropertySourceRepository; - - private ThreadLocal dateFormat = new ThreadLocal() { - @Override - protected DateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - } - }; - - public AcmEndpoint(AcmProperties properties, AcmRefreshHistory refreshHistory, - AcmPropertySourceRepository acmPropertySourceRepository) { - this.properties = properties; - this.refreshHistory = refreshHistory; - this.acmPropertySourceRepository = acmPropertySourceRepository; - } - - @ReadOperation - public Map invoke() { - Map result = new HashMap<>(); - result.put("config", properties); - - Map runtime = new HashMap<>(); - List all = acmPropertySourceRepository.allAcmPropertySource(); - - List> sources = new ArrayList<>(); - for (AcmPropertySource ps : all) { - Map source = new HashMap<>(); - source.put("dataId", ps.getDataId()); - source.put("lastSynced", dateFormat.get().format(ps.getTimestamp())); - sources.add(source); - } - runtime.put("sources", sources); - runtime.put("refreshHistory", refreshHistory.getRecords()); - - result.put("runtime", runtime); - return result; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java deleted file mode 100644 index a835c045..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.endpoint; - -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmProperties; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; -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.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; - -/** - * @author xiaojing - */ -@ConditionalOnWebApplication -@ConditionalOnClass( - name = "org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration") -@ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) -public class AcmEndpointAutoConfiguration { - - @Autowired - private AcmProperties acmProperties; - - @Autowired - private AcmRefreshHistory acmRefreshHistory; - - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint - @Bean - public AcmEndpoint acmEndpoint( - AcmPropertySourceRepository acmPropertySourceRepository) { - return new AcmEndpoint(acmProperties, acmRefreshHistory, - acmPropertySourceRepository); - } - - @Bean - @ConditionalOnMissingBean - public AcmHealthIndicator acmHealthIndicator(AcmProperties acmProperties, - AcmPropertySourceRepository acmPropertySourceRepository) { - return new AcmHealthIndicator(acmProperties, acmPropertySourceRepository); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java deleted file mode 100644 index b2197e27..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmHealthIndicator.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.endpoint; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.acm.bootstrap.AcmPropertySource; -import com.alibaba.alicloud.context.acm.AcmProperties; -import com.alibaba.edas.acm.ConfigService; - -import org.springframework.boot.actuate.health.AbstractHealthIndicator; -import org.springframework.boot.actuate.health.Health; -import org.springframework.util.StringUtils; - -/** - * @author leijuan - * @author juven - */ -public class AcmHealthIndicator extends AbstractHealthIndicator { - - private final AcmProperties acmProperties; - - private final List dataIds; - - private final AcmPropertySourceRepository acmPropertySourceRepository; - - public AcmHealthIndicator(AcmProperties acmProperties, - AcmPropertySourceRepository acmPropertySourceRepository) { - this.acmProperties = acmProperties; - this.acmPropertySourceRepository = acmPropertySourceRepository; - - this.dataIds = new ArrayList<>(); - for (AcmPropertySource acmPropertySource : this.acmPropertySourceRepository - .allAcmPropertySource()) { - this.dataIds.add(acmPropertySource.getDataId()); - } - } - - @Override - protected void doHealthCheck(Health.Builder builder) throws Exception { - for (String dataId : dataIds) { - try { - String config = ConfigService.getConfig(dataId, acmProperties.getGroup(), - acmProperties.getTimeout()); - if (StringUtils.isEmpty(config)) { - builder.down().withDetail(String.format("dataId: '%s', group: '%s'", - dataId, acmProperties.getGroup()), "config is empty"); - } - } - catch (Exception e) { - builder.down().withDetail(String.format("dataId: '%s', group: '%s'", - dataId, acmProperties.getGroup()), e.getMessage()); - } - } - builder.up().withDetail("dataIds", dataIds); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java deleted file mode 100644 index bd570034..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmContextRefresher.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.refresh; - -import java.io.UnsupportedEncodingException; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; -import com.alibaba.edas.acm.ConfigService; -import com.alibaba.edas.acm.listener.ConfigChangeListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.BeansException; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.cloud.context.refresh.ContextRefresher; -import org.springframework.cloud.endpoint.event.RefreshEvent; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationListener; -import org.springframework.util.StringUtils; - -/** - * On application start up, AcmContextRefresher add diamond listeners to all application - * level dataIds, when there is a change in the data, listeners will refresh - * configurations. - * - * @author juven.xuxb, 5/13/16. - */ -public class AcmContextRefresher - implements ApplicationListener, ApplicationContextAware { - - private Logger log = LoggerFactory.getLogger(AcmContextRefresher.class); - - private final ContextRefresher contextRefresher; - - private final AcmIntegrationProperties acmIntegrationProperties; - - private final AcmRefreshHistory refreshHistory; - - private AcmPropertySourceRepository acmPropertySourceRepository; - - private ApplicationContext applicationContext; - - private Map listenerMap = new ConcurrentHashMap<>(16); - - public AcmContextRefresher(ContextRefresher contextRefresher, - AcmIntegrationProperties acmIntegrationProperties, - AcmRefreshHistory refreshHistory, - AcmPropertySourceRepository acmPropertySourceRepository) { - this.contextRefresher = contextRefresher; - this.acmIntegrationProperties = acmIntegrationProperties; - this.refreshHistory = refreshHistory; - this.acmPropertySourceRepository = acmPropertySourceRepository; - } - - @Override - public void onApplicationEvent(ApplicationReadyEvent event) { - this.registerDiamondListenersForApplications(); - } - - private void registerDiamondListenersForApplications() { - if (acmIntegrationProperties.getAcmProperties().isRefreshEnabled()) { - for (String dataId : acmIntegrationProperties - .getApplicationConfigurationDataIds()) { - registerDiamondListener(dataId, - acmIntegrationProperties.getAcmProperties().getGroup()); - } - } - } - - private void registerDiamondListener(final String dataId, final String group) { - String key = acmPropertySourceRepository.getMapKey(dataId, group); - ConfigChangeListener listener = listenerMap.computeIfAbsent(key, - i -> new ConfigChangeListener() { - @Override - public void receiveConfigInfo(String configInfo) { - String md5 = ""; - if (!StringUtils.isEmpty(configInfo)) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - md5 = new BigInteger(1, - md.digest(configInfo.getBytes("UTF-8"))) - .toString(16); - } - catch (NoSuchAlgorithmException - | UnsupportedEncodingException e) { - log.warn("unable to get md5 for dataId: " + dataId, e); - } - } - refreshHistory.add(dataId, md5); - applicationContext.publishEvent(new RefreshEvent(this, md5, - "ACM Refresh, dataId=" + dataId)); - } - }); - ConfigService.addListener(dataId, group, listener); - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) - throws BeansException { - this.applicationContext = applicationContext; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java deleted file mode 100644 index cf6d44f6..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/refresh/AcmRefreshHistory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.refresh; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.LinkedList; - -/** - * @author juven.xuxb, 5/16/16. - */ -public class AcmRefreshHistory { - - private static final int MAX_SIZE = 20; - - private LinkedList records = new LinkedList<>(); - - private ThreadLocal dateFormat = new ThreadLocal() { - @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.get().format(new Date()), dataId, md5)); - if (records.size() > MAX_SIZE) { - records.removeLast(); - } - } - - public LinkedList getRecords() { - return records; - } - -} - -class Record { - - private final String timestamp; - - private final String dataId; - - private final String md5; - - Record(String timestamp, String dataId, String md5) { - this.timestamp = timestamp; - this.dataId = dataId; - this.md5 = md5; - } - - public String getTimestamp() { - return timestamp; - } - - public String getDataId() { - return dataId; - } - - public String getMd5() { - return md5; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 34d3e4f9..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "properties": [ - { - "name": "spring.application.group", - "type": "java.lang.String", - "description": "spring application group." - }, - { - "name": "spring.cloud.alicloud.acm.enabled", - "type": "java.lang.Boolean", - "defaultValue": true, - "description": "enable acm or not." - } - ] -} \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 25af6663..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,6 +0,0 @@ -org.springframework.cloud.bootstrap.BootstrapConfiguration=\ -com.alibaba.alicloud.acm.bootstrap.AcmConfigBootStrapConfiguration - -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.alibaba.alicloud.acm.AcmAutoConfiguration,\ -com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java deleted file mode 100644 index c529a079..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmConfigurationTests.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -import com.alibaba.alicloud.acm.bootstrap.AcmPropertySourceLocator; -import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; -import com.alibaba.alicloud.context.acm.AcmProperties; -import com.alibaba.edas.acm.ConfigService; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.MethodProxy; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - -/** - * @author xiaojing - */ - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmConfigurationTests.TestConfig.class, - properties = { "spring.application.name=test-name", - "spring.profiles.active=dev,test", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8848", - "spring.cloud.alicloud.acm.endpoint=test-endpoint", - "spring.cloud.alicloud.acm.namespace=test-namespace", - "spring.cloud.alicloud.acm.timeout=1000", - "spring.cloud.alicloud.acm.group=test-group", - "spring.cloud.alicloud.acm.refresh-enabled=false", - "spring.cloud.alicloud.acm.file-extension=properties" }, - webEnvironment = NONE) -public class AcmConfigurationTests { - - static { - - try { - - Method method = PowerMockito.method(ConfigService.class, "getConfig", - String.class, String.class, long.class); - MethodProxy.proxy(method, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - if ("test-name.properties".equals(args[0]) - && "test-group".equals(args[1])) { - return "user.name=hello\nuser.age=12"; - } - - if ("test-name-dev.properties".equals(args[0]) - && "test-group".equals(args[1])) { - return "user.name=dev"; - } - return ""; - } - }); - - } - catch (Exception ignore) { - ignore.printStackTrace(); - - } - } - - @Autowired - private Environment environment; - - @Autowired - private AcmPropertySourceLocator locator; - - @Autowired - private AcmIntegrationProperties integrationProperties; - - @Autowired - private AcmProperties properties; - - @Test - public void contextLoads() throws Exception { - - assertThat(locator).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(integrationProperties).isNotNull(); - - checkoutAcmServerAddr(); - checkoutAcmServerPort(); - checkoutAcmEndpoint(); - checkoutAcmNamespace(); - checkoutAcmGroup(); - checkoutAcmFileExtension(); - checkoutAcmTimeout(); - checkoutAcmProfiles(); - checkoutAcmRefreshEnabled(); - checkoutDataLoad(); - checkoutProfileDataLoad(); - } - - private void checkoutAcmServerAddr() { - assertThat(properties.getServerList()).isEqualTo("127.0.0.1"); - } - - private void checkoutAcmServerPort() { - assertThat(properties.getServerPort()).isEqualTo("8848"); - } - - private void checkoutAcmEndpoint() { - assertThat(properties.getEndpoint()).isEqualTo("test-endpoint"); - } - - private void checkoutAcmNamespace() { - assertThat(properties.getNamespace()).isEqualTo("test-namespace"); - } - - private void checkoutAcmGroup() { - assertThat(properties.getGroup()).isEqualTo("test-group"); - } - - private void checkoutAcmFileExtension() { - assertThat(properties.getFileExtension()).isEqualTo("properties"); - } - - private void checkoutAcmTimeout() { - assertThat(properties.getTimeout()).isEqualTo(1000); - } - - private void checkoutAcmRefreshEnabled() { - assertThat(properties.isRefreshEnabled()).isEqualTo(false); - } - - private void checkoutAcmProfiles() { - assertThat(integrationProperties.getActiveProfiles()) - .isEqualTo(new String[] { "dev", "test" }); - } - - private void checkoutDataLoad() { - assertThat(environment.getProperty("user.age")).isEqualTo("12"); - } - - private void checkoutProfileDataLoad() { - assertThat(environment.getProperty("user.name")).isEqualTo("dev"); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, - AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java deleted file mode 100644 index cfaca532..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmFileExtensionTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.edas.acm.ConfigService; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.MethodProxy; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - -/** - * @author xiaojing - */ - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmFileExtensionTest.TestConfig.class, - properties = { "spring.application.name=test-name", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8080", - "spring.cloud.alicloud.acm.file-extension=yaml" }, - webEnvironment = NONE) -public class AcmFileExtensionTest { - - static { - - try { - Method method = PowerMockito.method(ConfigService.class, "getConfig", - String.class, String.class, long.class); - MethodProxy.proxy(method, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - if ("test-name.yaml".equals(args[0]) - && "DEFAULT_GROUP".equals(args[1])) { - return "user:\n name: hello\n age: 12"; - } - return ""; - } - }); - - } - catch (Exception ignore) { - ignore.printStackTrace(); - - } - } - - @Autowired - private Environment environment; - - @Test - public void contextLoads() throws Exception { - - Assert.assertEquals(environment.getProperty("user.name"), "hello"); - Assert.assertEquals(environment.getProperty("user.age"), "12"); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, - AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java deleted file mode 100644 index 087703d4..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/AcmGroupConfigurationTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -import com.alibaba.alicloud.acm.endpoint.AcmEndpointAutoConfiguration; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.edas.acm.ConfigService; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.MethodProxy; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - -/** - * @author xiaojing - */ - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmGroupConfigurationTest.TestConfig.class, - properties = { "spring.application.name=test-name", - "spring.application.group=com.test.hello", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8080", - "spring.cloud.alicloud.acm.timeout=1000", - "spring.cloud.alicloud.acm.group=test-group" }, - webEnvironment = NONE) -public class AcmGroupConfigurationTest { - - static { - - try { - Method method = PowerMockito.method(ConfigService.class, "getConfig", - String.class, String.class, long.class); - MethodProxy.proxy(method, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - if ("com.test:application.properties".equals(args[0]) - && "test-group".equals(args[1])) { - return "com.test.value=com.test\ntest.priority=1"; - } - if ("com.test.hello:application.properties".equals(args[0]) - && "test-group".equals(args[1])) { - return "com.test.hello.value=com.test.hello\ntest.priority=2"; - } - return ""; - } - }); - - } - catch (Exception ignore) { - ignore.printStackTrace(); - - } - } - - @Autowired - private Environment environment; - - @Test - public void contextLoads() throws Exception { - - Assert.assertEquals(environment.getProperty("com.test.value"), "com.test"); - Assert.assertEquals(environment.getProperty("test.priority"), "2"); - Assert.assertEquals(environment.getProperty("com.test.hello.value"), - "com.test.hello"); - - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, - AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java deleted file mode 100644 index 442d2002..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-acm/src/test/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointTests.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.acm.endpoint; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import com.alibaba.alicloud.acm.AcmAutoConfiguration; -import com.alibaba.alicloud.acm.AcmPropertySourceRepository; -import com.alibaba.alicloud.acm.refresh.AcmRefreshHistory; -import com.alibaba.alicloud.context.acm.AcmContextBootstrapConfiguration; -import com.alibaba.alicloud.context.acm.AcmProperties; -import com.alibaba.edas.acm.ConfigService; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.MethodProxy; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.health.Health.Builder; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE; - -/** - * @author xiaojing - */ - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ ConfigService.class }) -@SpringBootTest(classes = AcmEndpointTests.TestConfig.class, - properties = { "spring.application.name=test-name", - "spring.cloud.alicloud.acm.server-list=127.0.0.1", - "spring.cloud.alicloud.acm.server-port=8848", - "spring.cloud.alicloud.acm.file-extension=properties" }, - webEnvironment = NONE) -public class AcmEndpointTests { - - static { - - try { - - Method method = PowerMockito.method(ConfigService.class, "getConfig", - String.class, String.class, long.class); - MethodProxy.proxy(method, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - if ("test-name.properties".equals(args[0]) - && "DEFAULT_GROUP".equals(args[1])) { - return "user.name=hello\nuser.age=12"; - } - return ""; - } - }); - - } - catch (Exception ignore) { - ignore.printStackTrace(); - - } - } - - @Autowired - private AcmProperties properties; - - @Autowired - private AcmRefreshHistory refreshHistory; - - @Autowired - private AcmPropertySourceRepository acmPropertySourceRepository; - - @Test - public void contextLoads() throws Exception { - - checkoutEndpoint(); - checkoutAcmHealthIndicator(); - - } - - private void checkoutAcmHealthIndicator() { - try { - Builder builder = new Builder(); - - AcmHealthIndicator healthIndicator = new AcmHealthIndicator(properties, - acmPropertySourceRepository); - healthIndicator.doHealthCheck(builder); - - Builder builder1 = new Builder(); - List dataIds = new ArrayList<>(); - dataIds.add("test-name.properties"); - builder1.up().withDetail("dataIds", dataIds); - - Assert.assertTrue(builder.build().equals(builder1.build())); - - } - catch (Exception ignoreE) { - - } - - } - - private void checkoutEndpoint() throws Exception { - AcmEndpoint acmEndpoint = new AcmEndpoint(properties, refreshHistory, - acmPropertySourceRepository); - Map map = acmEndpoint.invoke(); - assertThat(properties).isEqualTo(map.get("config")); - assertThat(refreshHistory.getRecords()) - .isEqualTo(((Map) map.get("runtime")).get("refreshHistory")); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AcmEndpointAutoConfiguration.class, - AcmAutoConfiguration.class, AcmContextBootstrapConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/pom.xml b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/pom.xml deleted file mode 100644 index 0f50827d..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/pom.xml +++ /dev/null @@ -1,132 +0,0 @@ - - - 4.0.0 - - - com.alibaba.cloud - spring-cloud-starter-alicloud - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - spring-cloud-starter-alicloud-ans - Spring Cloud Starter Alibaba Cloud ANS - - - - - org.springframework.boot - spring-boot-starter - - - - com.alibaba.ans - ans-sdk - - - - com.aliyun - aliyun-java-sdk-core - - - - com.aliyun - aliyun-java-sdk-edas - - - - com.alibaba.cloud - spring-cloud-alicloud-context - - - - org.springframework - spring-context - - - org.springframework.cloud - spring-cloud-commons - - - - org.slf4j - slf4j-api - - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - - org.springframework.boot - spring-boot-starter - - - - - - org.springframework.boot - spring-boot-actuator - true - - - - org.springframework.boot - spring-boot-actuator-autoconfigure - true - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-autoconfigure - true - - - - - org.springframework.boot - spring-boot-starter-web - test - - - - org.springframework.boot - spring-boot-starter-actuator - test - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.cloud - spring-cloud-test-support - test - - - - org.powermock - powermock-module-junit4 - 2.0.0 - test - - - - org.powermock - powermock-api-mockito2 - 2.0.0 - test - - - - \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java deleted file mode 100644 index b017421a..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsAutoConfiguration.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -import com.alibaba.alicloud.ans.registry.AnsAutoServiceRegistration; -import com.alibaba.alicloud.ans.registry.AnsRegistration; -import com.alibaba.alicloud.ans.registry.AnsServiceRegistry; -import com.alibaba.alicloud.context.ans.AnsProperties; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnClass( - name = "org.springframework.boot.web.context.WebServerInitializedEvent") -@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", - matchIfMissing = true) -@ConditionalOnAnsEnabled -@AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class, - AutoServiceRegistrationAutoConfiguration.class }) -public class AnsAutoConfiguration { - - @Bean - public AnsServiceRegistry ansServiceRegistry() { - return new AnsServiceRegistry(); - } - - @Bean - @ConditionalOnBean(AutoServiceRegistrationProperties.class) - @ConditionalOnProperty( - value = "spring.cloud.service-registry.auto-registration.enabled", - matchIfMissing = true) - public AnsRegistration ansRegistration(AnsProperties ansProperties, - ApplicationContext applicationContext) { - return new AnsRegistration(ansProperties, applicationContext); - } - - @Bean - @ConditionalOnBean(AutoServiceRegistrationProperties.class) - @ConditionalOnProperty( - value = "spring.cloud.service-registry.auto-registration.enabled", - matchIfMissing = true) - public AnsAutoServiceRegistration ansAutoServiceRegistration( - AnsServiceRegistry registry, - AutoServiceRegistrationProperties autoServiceRegistrationProperties, - AnsRegistration registration) { - return new AnsAutoServiceRegistration(registry, autoServiceRegistrationProperties, - registration); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java deleted file mode 100644 index 420342f0..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClient.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; - -/** - * @author xiaolongzuo - * @author pbting - */ -public class AnsDiscoveryClient implements DiscoveryClient { - - /** - * Description of Ans Discovery. - */ - public static final String DESCRIPTION = "Spring Cloud ANS Discovery Client"; - - @Override - public String description() { - return DESCRIPTION; - } - - @Override - public List getInstances(String serviceId) { - try { - List hosts = NamingService.getHosts(serviceId); - return hostToServiceInstanceList(hosts, serviceId); - } - catch (Exception e) { - throw new RuntimeException( - "Can not get hosts from ans server. serviceId: " + serviceId, e); - } - } - - private static ServiceInstance hostToServiceInstance(Host host, String serviceId) { - AnsServiceInstance ansServiceInstance = new AnsServiceInstance(); - ansServiceInstance.setHost(host.getIp()); - ansServiceInstance.setPort(host.getPort()); - ansServiceInstance.setServiceId(serviceId); - Map metadata = new HashMap(5); - metadata.put("appUseType", host.getAppUseType()); - metadata.put("site", host.getSite()); - metadata.put("unit", host.getUnit()); - metadata.put("doubleWeight", "" + host.getDoubleWeight()); - metadata.put("weight", "" + host.getWeight()); - ansServiceInstance.setMetadata(metadata); - - return ansServiceInstance; - } - - private static List hostToServiceInstanceList(List hosts, - String serviceId) { - List result = new ArrayList(hosts.size()); - for (Host host : hosts) { - result.add(hostToServiceInstance(host, serviceId)); - } - return result; - } - - @Override - public List getServices() { - Set publishers = NamingService.getPublishes(); - Set doms = NamingService.getDomsSubscribed(); - doms.addAll(publishers); - List result = new LinkedList<>(); - for (String service : doms) { - result.add(service); - } - return result; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java deleted file mode 100644 index 5467ce73..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - * @author pbting - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnMissingBean(DiscoveryClient.class) -@EnableConfigurationProperties -@AutoConfigureBefore(SimpleDiscoveryClientAutoConfiguration.class) -public class AnsDiscoveryClientAutoConfiguration { - - @Bean - public DiscoveryClient ansDiscoveryClient() { - return new AnsDiscoveryClient(); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java deleted file mode 100644 index aa912392..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/AnsServiceInstance.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -import java.net.URI; -import java.util.Map; - -import org.springframework.cloud.client.DefaultServiceInstance; -import org.springframework.cloud.client.ServiceInstance; - -/** - * @author xiaolongzuo - */ -public class AnsServiceInstance implements ServiceInstance { - - private String serviceId; - - private String host; - - private int port; - - private boolean secure; - - private Map metadata; - - @Override - public String getServiceId() { - return serviceId; - } - - @Override - public String getHost() { - return host; - } - - @Override - public int getPort() { - return port; - } - - @Override - public boolean isSecure() { - return secure; - } - - @Override - public URI getUri() { - return DefaultServiceInstance.getUri(this); - } - - @Override - public Map getMetadata() { - return metadata; - } - - public void setServiceId(String serviceId) { - this.serviceId = serviceId; - } - - public void setHost(String host) { - this.host = host; - } - - public void setPort(int port) { - this.port = port; - } - - public void setSecure(boolean secure) { - this.secure = secure; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java deleted file mode 100644 index 0633c691..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ConditionalOnAnsEnabled.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; - -/** - * @author xiaolongzuo - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD }) -@ConditionalOnProperty(value = "spring.cloud.ans.enabled", matchIfMissing = true) -public @interface ConditionalOnAnsEnabled { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java deleted file mode 100644 index a7def20f..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpoint.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.endpoint; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.alibaba.alicloud.context.ans.AnsProperties; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - -/** - * @author xiaolongzuo - * @author pbting - */ -@Endpoint(id = "ans") -public class AnsEndpoint { - - private static final Logger log = LoggerFactory.getLogger(AnsEndpoint.class); - - private AnsProperties ansProperties; - - public AnsEndpoint(AnsProperties ansProperties) { - this.ansProperties = ansProperties; - } - - /** - * @return ans endpoint - */ - @ReadOperation - public Map invoke() { - Map ansEndpoint = new HashMap<>(); - log.info("ANS endpoint invoke, ansProperties is " + ansProperties); - ansEndpoint.put("ansProperties", ansProperties); - - Map subscribes = new HashMap<>(); - Set subscribeServices = NamingService.getDomsSubscribed(); - for (String service : subscribeServices) { - try { - List hosts = NamingService.getHosts(service); - subscribes.put(service, hosts); - } - catch (Exception ignoreException) { - - } - } - ansEndpoint.put("subscribes", subscribes); - log.info("ANS endpoint invoke, subscribes is " + subscribes); - return ansEndpoint; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java deleted file mode 100644 index 552dd7d5..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/endpoint/AnsEndpointAutoConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.endpoint; - -import com.alibaba.alicloud.context.ans.AnsProperties; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; - -/** - * @author xiaolongzuo - */ -@ConditionalOnWebApplication -@ConditionalOnClass(Endpoint.class) -public class AnsEndpointAutoConfiguration { - - @Bean - public AnsEndpoint ansEndpoint(AnsProperties ansProperties) { - return new AnsEndpoint(ansProperties); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java deleted file mode 100644 index 1d5b4cf4..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistration.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; -import org.springframework.cloud.client.serviceregistry.ServiceRegistry; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * @author xiaolongzuo - * @author pbting - */ -public class AnsAutoServiceRegistration - extends AbstractAutoServiceRegistration { - - private static final Logger log = LoggerFactory - .getLogger(AnsAutoServiceRegistration.class); - - private AnsRegistration registration; - - public AnsAutoServiceRegistration(ServiceRegistry serviceRegistry, - AutoServiceRegistrationProperties autoServiceRegistrationProperties, - AnsRegistration registration) { - super(serviceRegistry, autoServiceRegistrationProperties); - this.registration = registration; - } - - @Deprecated - public void setPort(int port) { - getPort().set(port); - } - - @Override - protected AnsRegistration getRegistration() { - if (this.registration.getPort() < 0 && this.getPort().get() > 0) { - this.registration.setPort(this.getPort().get()); - } - Assert.isTrue(this.registration.getPort() > 0, "service.port has not been set"); - return this.registration; - } - - @Override - protected AnsRegistration getManagementRegistration() { - return null; - } - - @Override - protected void register() { - if (!this.registration.getAnsProperties().isRegisterEnabled()) { - log.debug("Registration disabled."); - return; - } - if (this.registration.getPort() < 0) { - this.registration.setPort(getPort().get()); - } - super.register(); - } - - @Override - protected void registerManagement() { - if (!this.registration.getAnsProperties().isRegisterEnabled()) { - return; - } - super.registerManagement(); - - } - - @Override - protected Object getConfiguration() { - return this.registration.getAnsProperties(); - } - - @Override - protected boolean isEnabled() { - return this.registration.getAnsProperties().isRegisterEnabled(); - } - - @Override - @SuppressWarnings("deprecation") - protected String getAppName() { - String appName = registration.getServiceId(); - return StringUtils.isEmpty(appName) ? super.getAppName() : appName; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java deleted file mode 100644 index 142cd990..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsRegistration.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import java.net.URI; -import java.util.Map; - -import javax.annotation.PostConstruct; - -import com.alibaba.alicloud.context.ans.AnsProperties; - -import org.springframework.cloud.client.DefaultServiceInstance; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.ManagementServerPortUtils; -import org.springframework.cloud.client.serviceregistry.Registration; -import org.springframework.context.ApplicationContext; -import org.springframework.core.env.Environment; -import org.springframework.util.StringUtils; - -/** - * @author xiaolongzuo - */ -public class AnsRegistration implements Registration, ServiceInstance { - - static final String MANAGEMENT_PORT = "management.port"; - static final String MANAGEMENT_CONTEXT_PATH = "management.context-path"; - static final String MANAGEMENT_ADDRESS = "management.address"; - static final String MANAGEMENT_ENDPOINT_BASE_PATH = "management.endpoints.web.base-path"; - - private AnsProperties ansProperties; - - private ApplicationContext context; - - public AnsRegistration(AnsProperties ansProperties, ApplicationContext context) { - this.ansProperties = ansProperties; - this.context = context; - } - - @PostConstruct - public void init() { - - Map metadata = ansProperties.getClientMetadata(); - Environment env = context.getEnvironment(); - - String endpointBasePath = env.getProperty(MANAGEMENT_ENDPOINT_BASE_PATH); - if (!StringUtils.isEmpty(endpointBasePath)) { - metadata.put(MANAGEMENT_ENDPOINT_BASE_PATH, endpointBasePath); - } - - Integer managementPort = ManagementServerPortUtils.getPort(context); - if (null != managementPort) { - metadata.put(MANAGEMENT_PORT, managementPort.toString()); - String contextPath = env - .getProperty("management.server.servlet.context-path"); - String address = env.getProperty("management.server.address"); - if (!StringUtils.isEmpty(contextPath)) { - metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath); - } - if (!StringUtils.isEmpty(address)) { - metadata.put(MANAGEMENT_ADDRESS, address); - } - } - } - - @Override - public String getServiceId() { - return ansProperties.getClientDomains(); - } - - @Override - public String getHost() { - return ansProperties.getClientIp(); - } - - @Override - public int getPort() { - return ansProperties.getClientPort(); - } - - public void setPort(int port) { - // if spring.cloud.ans.port is not set,use the port detected from context - if (ansProperties.getClientPort() < 0) { - this.ansProperties.setClientPort(port); - } - } - - @Override - public boolean isSecure() { - return ansProperties.isSecure(); - } - - @Override - public URI getUri() { - return DefaultServiceInstance.getUri(this); - } - - @Override - public Map getMetadata() { - return ansProperties.getClientMetadata(); - } - - public boolean isRegisterEnabled() { - return ansProperties.isRegisterEnabled(); - } - - public String getCluster() { - return ansProperties.getClientCluster(); - } - - public float getRegisterWeight(String dom) { - if (null != ansProperties.getClientWeights().get(dom) - && ansProperties.getClientWeights().get(dom) > 0) { - return ansProperties.getClientWeights().get(dom); - } - return ansProperties.getClientWeight(); - } - - public AnsProperties getAnsProperties() { - return ansProperties; - } - - @Override - public String toString() { - return "AnsRegistration{" + "ansProperties=" + ansProperties + '}'; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java deleted file mode 100644 index afcd5dba..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/registry/AnsServiceRegistry.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.ipms.NodeReactor; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.cloud.client.serviceregistry.ServiceRegistry; - -/** - * @author xiaolongzuo - */ -public class AnsServiceRegistry implements ServiceRegistry { - - private static final Logger log = LoggerFactory.getLogger(AnsServiceRegistry.class); - - private static final String SEPARATOR = ","; - - @Override - public void register(AnsRegistration registration) { - - if (!registration.isRegisterEnabled()) { - log.warn("Registration is disabled..."); - return; - } - if (StringUtils.isEmpty(registration.getServiceId())) { - log.warn("No service to register for client..."); - return; - } - - List tags = new ArrayList<>(); - for (Map.Entry entry : registration.getAnsProperties().getTags() - .entrySet()) { - NodeReactor.Tag tag = new NodeReactor.Tag(); - tag.setName(entry.getKey()); - tag.setValue(entry.getValue()); - tags.add(tag); - } - - for (String dom : registration.getServiceId().split(SEPARATOR)) { - try { - NamingService.regDom(dom, registration.getHost(), registration.getPort(), - registration.getRegisterWeight(dom), registration.getCluster(), - tags); - log.info("INFO_ANS_REGISTER, {} {}:{} register finished", dom, - registration.getAnsProperties().getClientIp(), - registration.getAnsProperties().getClientPort()); - } - catch (Exception e) { - log.error("ERR_ANS_REGISTER, {} register failed...{},", dom, - registration.toString(), e); - } - } - } - - @Override - public void deregister(AnsRegistration registration) { - - log.info("De-registering from ANSServer now..."); - - if (StringUtils.isEmpty(registration.getServiceId())) { - log.warn("No dom to de-register for client..."); - return; - } - - try { - NamingService.deRegDom(registration.getServiceId(), registration.getHost(), - registration.getPort(), registration.getCluster()); - } - catch (Exception e) { - log.error("ERR_ANS_DEREGISTER, de-register failed...{},", - registration.toString(), e); - } - - log.info("De-registration finished."); - } - - @Override - public void close() { - - } - - @Override - public void setStatus(AnsRegistration registration, String status) { - - } - - @Override - public T getStatus(AnsRegistration registration) { - return null; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java deleted file mode 100644 index ca082a49..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ServerList; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - * @author pbting - */ -@Configuration(proxyBeanMethods = false) -public class AnsRibbonClientConfiguration { - - @Bean - @ConditionalOnMissingBean - public ServerList ansRibbonServerList(IClientConfig config) { - AnsServerList serverList = new AnsServerList(config.getClientName()); - return serverList; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java deleted file mode 100644 index e335642e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServer.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import java.util.Collections; -import java.util.Map; - -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import com.netflix.loadbalancer.Server; - -/** - * @author xiaolongzuo - */ -public class AnsServer extends Server { - - private final MetaInfo metaInfo; - - private final Host host; - - private final Map metadata; - - public AnsServer(final Host host, final String dom) { - super(host.getIp(), host.getPort()); - this.host = host; - this.metadata = Collections.emptyMap(); - metaInfo = new MetaInfo() { - @Override - public String getAppName() { - return dom; - } - - @Override - public String getServerGroup() { - return getMetadata().get("group"); - } - - @Override - public String getServiceIdForDiscovery() { - return dom; - } - - @Override - public String getInstanceId() { - return AnsServer.this.host.getIp() + ":" + dom + ":" - + AnsServer.this.host.getPort(); - } - }; - } - - @Override - public MetaInfo getMetaInfo() { - return metaInfo; - } - - public Host getHealthService() { - return this.host; - } - - public Map getMetadata() { - return metadata; - } - - @Override - public String toString() { - return "AnsServer{" + "metaInfo=" + metaInfo + ", host=" + host + ", metadata=" - + metadata + '}'; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java deleted file mode 100644 index 1ae1d9fd..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/AnsServerList.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AbstractServerList; - -/** - * @author xiaolongzuo - */ -public class AnsServerList extends AbstractServerList { - - private String dom; - - public AnsServerList(String dom) { - this.dom = dom; - } - - @Override - public List getInitialListOfServers() { - try { - List hosts = NamingService.getHosts(getDom()); - return hostsToServerList(hosts); - } - catch (Exception e) { - throw new IllegalStateException("Can not get ans hosts, dom=" + getDom(), e); - } - } - - @Override - public List getUpdatedListOfServers() { - return getInitialListOfServers(); - } - - private AnsServer hostToServer(Host host) { - AnsServer server = new AnsServer(host, getDom()); - return server; - } - - private List hostsToServerList(List hosts) { - List result = new ArrayList(hosts.size()); - for (Host host : hosts) { - if (host.isValid()) { - result.add(hostToServer(host)); - } - } - - return result; - } - - public String getDom() { - return dom; - } - - @Override - public void initWithNiwsConfig(IClientConfig iClientConfig) { - this.dom = iClientConfig.getClientName(); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java deleted file mode 100644 index f404fbe1..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/ConditionalOnRibbonAns.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; - -/** - * @author xiaolongzuo - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD }) -@ConditionalOnProperty(value = "ribbon.ans.enabled", matchIfMissing = true) -public @interface ConditionalOnRibbonAns { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java deleted file mode 100644 index 95e15c15..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/java/com/alibaba/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import com.alibaba.alicloud.ans.ConditionalOnAnsEnabled; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; -import org.springframework.cloud.netflix.ribbon.RibbonClients; -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnAnsEnabled -@ConditionalOnBean(SpringClientFactory.class) -@ConditionalOnRibbonAns -@AutoConfigureAfter(RibbonAutoConfiguration.class) -@RibbonClients(defaultConfiguration = AnsRibbonClientConfiguration.class) -public class RibbonAnsAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/resources/META-INF/spring.factories deleted file mode 100644 index c297fef7..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,5 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.alibaba.alicloud.ans.endpoint.AnsEndpointAutoConfiguration,\ - com.alibaba.alicloud.ans.ribbon.RibbonAnsAutoConfiguration,\ - com.alibaba.alicloud.ans.AnsAutoConfiguration,\ - com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java deleted file mode 100644 index 67bfb692..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/AnsDiscoveryClientTests.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import com.alibaba.alicloud.ans.test.AnsMockTest; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import org.springframework.cloud.client.ServiceInstance; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - -/** - * @author xiaojing - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(NamingService.class) -public class AnsDiscoveryClientTests { - - private String host = "123.123.123.123"; - - private int port = 8888; - - private String serviceName = "test-service"; - - @Test - public void testGetServers() throws Exception { - - ArrayList hosts = new ArrayList<>(); - - HashMap map = new HashMap<>(); - map.put("test-key", "test-value"); - map.put("secure", "true"); - - hosts.add(AnsMockTest.hostInstance(serviceName, false, host, port, map)); - - PowerMockito.mockStatic(NamingService.class); - when(NamingService.getHosts(eq(serviceName))).thenReturn(hosts); - - AnsDiscoveryClient discoveryClient = new AnsDiscoveryClient(); - - List serviceInstances = discoveryClient - .getInstances(serviceName); - - assertThat(serviceInstances.size()).isEqualTo(1); - - ServiceInstance serviceInstance = serviceInstances.get(0); - - assertThat(serviceInstance.getServiceId()).isEqualTo(serviceName); - assertThat(serviceInstance.getHost()).isEqualTo(host); - assertThat(serviceInstance.getPort()).isEqualTo(port); - // assertThat(serviceInstance.isSecure()).isEqualTo(true); - // ans doesn't support metadata - assertThat(serviceInstance.getUri().toString()) - .isEqualTo(getUri(serviceInstance)); - // assertThat(serviceInstance.getMetadata().get("test-key")).isEqualTo("test-value"); - // ans doesn't support metadata - - } - - @Test - public void testGetAllService() throws Exception { - - Set subscribedServices = new HashSet<>(); - - subscribedServices.add(serviceName + "1"); - subscribedServices.add(serviceName + "2"); - subscribedServices.add(serviceName + "3"); - - PowerMockito.mockStatic(NamingService.class); - when(NamingService.getDomsSubscribed()).thenReturn(subscribedServices); - - AnsDiscoveryClient discoveryClient = new AnsDiscoveryClient(); - List services = discoveryClient.getServices(); - - assertThat(services.size()).isEqualTo(3); - assertThat(services.contains(serviceName + "1")); - assertThat(services.contains(serviceName + "2")); - assertThat(services.contains(serviceName + "3")); - - } - - private String getUri(ServiceInstance instance) { - - if (instance.isSecure()) { - return "https://" + host + ":" + port; - } - - return "http://" + host + ":" + port; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java deleted file mode 100644 index 3763449d..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationEnabledTests.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationEnabledTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.register-enabled=false" }, - webEnvironment = RANDOM_PORT) -public class AnsAutoServiceRegistrationEnabledTests { - - @Autowired - private AnsRegistration registration; - - @Autowired - private AnsAutoServiceRegistration ansAutoServiceRegistration; - - @Autowired - private AnsProperties properties; - - @Test - public void contextLoads() throws Exception { - assertThat(registration).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(ansAutoServiceRegistration).isNotNull(); - - checkEnabled(); - - } - - private void checkEnabled() { - assertThat(ansAutoServiceRegistration.isEnabled()).isEqualTo(Boolean.FALSE); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java deleted file mode 100644 index 90867ea2..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpNetworkInterfaceTests.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.util.Enumeration; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.cloud.commons.util.InetUtils; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ - -@RunWith(SpringRunner.class) -@SpringBootTest( - classes = AnsAutoServiceRegistrationIpNetworkInterfaceTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080" }, - webEnvironment = RANDOM_PORT) -public class AnsAutoServiceRegistrationIpNetworkInterfaceTests { - - @Autowired - private AnsRegistration registration; - - @Autowired - private AnsAutoServiceRegistration ansAutoServiceRegistration; - - @Autowired - private AnsProperties properties; - - @Autowired - private InetUtils inetUtils; - - @Test - public void contextLoads() throws Exception { - - assertThat(registration).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(ansAutoServiceRegistration).isNotNull(); - - checkoutAnsDiscoveryServiceIP(); - - } - - private void checkoutAnsDiscoveryServiceIP() { - assertThat(registration.getHost()) - .isEqualTo(getIPFromNetworkInterface(TestConfig.netWorkInterfaceName)); - } - - private String getIPFromNetworkInterface(String networkInterface) { - - if (!TestConfig.hasValidNetworkInterface) { - return inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); - } - - try { - NetworkInterface netInterface = NetworkInterface.getByName(networkInterface); - - Enumeration inetAddress = netInterface.getInetAddresses(); - while (inetAddress.hasMoreElements()) { - InetAddress currentAddress = inetAddress.nextElement(); - if (currentAddress instanceof Inet4Address - && !currentAddress.isLoopbackAddress()) { - return currentAddress.getHostAddress(); - } - } - return networkInterface; - } - catch (Exception e) { - return networkInterface; - } - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) - public static class TestConfig { - - static boolean hasValidNetworkInterface = false; - static String netWorkInterfaceName; - - static { - - try { - Enumeration enumeration = NetworkInterface - .getNetworkInterfaces(); - while (enumeration.hasMoreElements() && !hasValidNetworkInterface) { - NetworkInterface networkInterface = enumeration.nextElement(); - Enumeration inetAddress = networkInterface - .getInetAddresses(); - while (inetAddress.hasMoreElements()) { - InetAddress currentAddress = inetAddress.nextElement(); - if (currentAddress instanceof Inet4Address - && !currentAddress.isLoopbackAddress()) { - hasValidNetworkInterface = true; - netWorkInterfaceName = networkInterface.getName(); - System.setProperty( - "spring.cloud.alicloud.ans.client-interface-name", - networkInterface.getName()); - break; - } - } - } - - } - catch (Exception e) { - - } - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java deleted file mode 100644 index 036a7ffa..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationIpTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationIpTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.client-domains=myTestService2", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.client-weight=2", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.client-ip=123.123.123.123" }, - webEnvironment = RANDOM_PORT) -public class AnsAutoServiceRegistrationIpTests { - - @Autowired - private AnsRegistration registration; - - @Autowired - private AnsAutoServiceRegistration ansAutoServiceRegistration; - - @Autowired - private AnsProperties properties; - - @Test - public void contextLoads() throws Exception { - - assertThat(registration).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(ansAutoServiceRegistration).isNotNull(); - - checkoutAnsDiscoveryServiceIP(); - checkoutAnsDiscoveryServiceName(); - checkoutAnsDiscoveryWeight(); - } - - private void checkoutAnsDiscoveryServiceIP() { - assertThat(registration.getHost()).isEqualTo("123.123.123.123"); - } - - private void checkoutAnsDiscoveryServiceName() { - assertThat(properties.getClientDomains()).isEqualTo("myTestService2"); - } - - private void checkoutAnsDiscoveryWeight() { - assertThat(properties.getClientWeight()).isEqualTo(2L); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java deleted file mode 100644 index e8a1846c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationManagementPortTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationManagementPortTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "management.server.port=8888", - "management.server.servlet.context-path=/test-context-path", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080" }, - webEnvironment = RANDOM_PORT) -public class AnsAutoServiceRegistrationManagementPortTests { - - @Autowired - private AnsRegistration registration; - - @Autowired - private AnsAutoServiceRegistration ansAutoServiceRegistration; - - @Autowired - private AnsProperties properties; - - @Test - public void contextLoads() throws Exception { - - assertThat(registration).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(ansAutoServiceRegistration).isNotNull(); - - checkoutNacosDiscoveryManagementData(); - - } - - private void checkoutNacosDiscoveryManagementData() { - assertThat(properties.getClientMetadata().get(AnsRegistration.MANAGEMENT_PORT)) - .isEqualTo("8888"); - assertThat(properties.getClientMetadata() - .get(AnsRegistration.MANAGEMENT_CONTEXT_PATH)) - .isEqualTo("/test-context-path"); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java deleted file mode 100644 index 7e997b6c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationPortTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.context.ans.AnsProperties; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationPortTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.client-port=8888" }, - webEnvironment = RANDOM_PORT) -public class AnsAutoServiceRegistrationPortTests { - - @Autowired - private AnsRegistration registration; - - @Autowired - private AnsAutoServiceRegistration ansAutoServiceRegistration; - - @Autowired - private AnsProperties properties; - - @Test - public void contextLoads() throws Exception { - - assertThat(registration).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(ansAutoServiceRegistration).isNotNull(); - - checkoutAnsDiscoveryServicePort(); - - } - - private void checkoutAnsDiscoveryServicePort() { - assertThat(registration.getPort()).isEqualTo(8888); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java deleted file mode 100644 index b9782373..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/registry/AnsAutoServiceRegistrationTests.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.registry; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.alibaba.alicloud.ans.endpoint.AnsEndpoint; -import com.alibaba.alicloud.context.ans.AnsProperties; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.cloud.commons.util.InetUtils; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsAutoServiceRegistrationTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.secure=true", - "spring.cloud.alicloud.ans.endpoint=test-endpoint" }, - webEnvironment = RANDOM_PORT) -public class AnsAutoServiceRegistrationTests { - - @Autowired - private AnsRegistration registration; - - @Autowired - private AnsAutoServiceRegistration ansAutoServiceRegistration; - - @LocalServerPort - private int port; - - @Autowired - private AnsProperties properties; - - @Autowired - private InetUtils inetUtils; - - @Test - public void contextLoads() throws Exception { - - assertThat(registration).isNotNull(); - assertThat(properties).isNotNull(); - assertThat(ansAutoServiceRegistration).isNotNull(); - - checkoutAnsDiscoveryServerList(); - checkoutAnsDiscoveryServerPort(); - - checkoutAnsDiscoveryServiceName(); - checkoutAnsDiscoveryServiceIP(); - checkoutAnsDiscoveryServicePort(); - checkoutAnsDiscoverySecure(); - - checkAutoRegister(); - - checkoutEndpoint(); - - } - - private void checkAutoRegister() { - assertThat(ansAutoServiceRegistration.isRunning()).isEqualTo(Boolean.TRUE); - } - - private void checkoutAnsDiscoveryServerList() { - assertThat(properties.getServerList()).isEqualTo("127.0.0.1"); - } - - private void checkoutAnsDiscoveryServerPort() { - assertThat(properties.getServerPort()).isEqualTo("8080"); - } - - private void checkoutAnsDiscoveryServiceName() { - assertThat(properties.getClientDomains()).isEqualTo("myTestService1"); - } - - private void checkoutAnsDiscoveryServiceIP() { - assertThat(registration.getHost()) - .isEqualTo(inetUtils.findFirstNonLoopbackHostInfo().getIpAddress()); - } - - private void checkoutAnsDiscoveryServicePort() { - assertThat(registration.getPort()).isEqualTo(port); - } - - private void checkoutAnsDiscoverySecure() { - assertThat(properties.isSecure()).isEqualTo(Boolean.TRUE); - - } - - private void checkoutEndpoint() throws Exception { - AnsEndpoint ansEndpoint = new AnsEndpoint(properties); - Map map = ansEndpoint.invoke(); - assertThat(properties).isEqualTo(map.get("ansProperties")); - - Map subscribes = new HashMap<>(); - Set subscribeServices = NamingService.getDomsSubscribed(); - for (String service : subscribeServices) { - try { - List hosts = NamingService.getHosts(service); - subscribes.put(service, hosts); - } - catch (Exception ignoreException) { - - } - } - - assertThat(subscribes).isEqualTo(map.get("subscribes")); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java deleted file mode 100644 index e5710e1e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsRibbonClientConfigurationTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import com.alibaba.alicloud.ans.AnsAutoConfiguration; -import com.alibaba.alicloud.ans.AnsDiscoveryClientAutoConfiguration; -import com.netflix.client.config.DefaultClientConfigImpl; -import com.netflix.client.config.IClientConfig; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author xiaojing - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AnsRibbonClientConfigurationTests.TestConfig.class, - properties = { "spring.application.name=myTestService1", - "spring.cloud.alicloud.ans.server-list=127.0.0.1", - "spring.cloud.alicloud.ans.server-port=8080", - "spring.cloud.alicloud.ans.endpoint=test-endpoint" }, - webEnvironment = RANDOM_PORT) -public class AnsRibbonClientConfigurationTests { - - @Autowired - private AnsServerList serverList; - - @Test - public void contextLoads() throws Exception { - assertThat(serverList.getDom()).isEqualTo("myapp"); - } - - @Configuration - public static class AnsRibbonTestConfiguration { - - @Bean - IClientConfig iClientConfig() { - DefaultClientConfigImpl config = new DefaultClientConfigImpl(); - config.setClientName("myapp"); - return config; - } - - @Bean - @LoadBalanced - RestTemplate restTemplate() { - return new RestTemplate(); - } - - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, - AnsDiscoveryClientAutoConfiguration.class, AnsAutoConfiguration.class, - AnsRibbonTestConfiguration.class, RibbonAnsAutoConfiguration.class, - AnsRibbonClientConfiguration.class }) - public static class TestConfig { - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java deleted file mode 100644 index 344792a7..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServerListTests.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.stream.Collectors; - -import com.alibaba.alicloud.ans.test.AnsMockTest; -import com.alibaba.ans.core.NamingService; -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import com.netflix.client.config.IClientConfig; -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author xiaojing - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({ NamingService.class, AnsServer.class }) -public class AnsServerListTests { - - @Test - @SuppressWarnings("unchecked") - public void testEmptyInstancesReturnsEmptyList() throws Exception { - - PowerMockito.mockStatic(NamingService.class); - when(NamingService.getHosts(anyString())).thenReturn(Collections.EMPTY_LIST); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - AnsServerList serverList = new AnsServerList("test-service"); - serverList.initWithNiwsConfig(clientConfig); - List servers = serverList.getInitialListOfServers(); - Assertions.assertThat(servers).isEmpty(); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetServers() throws Exception { - - ArrayList hosts = new ArrayList<>(); - hosts.add(AnsMockTest.hostInstance("test-service", true, Collections.emptyMap())); - - PowerMockito.mockStatic(NamingService.class); - when(NamingService.getHosts(anyString())).thenReturn(hosts); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - AnsServerList serverList = new AnsServerList("test-service"); - serverList.initWithNiwsConfig(clientConfig); - List servers = serverList.getInitialListOfServers(); - Assertions.assertThat(servers).hasSize(1); - - servers = serverList.getUpdatedListOfServers(); - Assertions.assertThat(servers).hasSize(1); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetServersWithInstanceStatus() throws Exception { - ArrayList hosts = new ArrayList<>(); - - HashMap map1 = new HashMap<>(); - map1.put("instanceNum", "1"); - HashMap map2 = new HashMap<>(); - map2.put("instanceNum", "2"); - hosts.add(AnsMockTest.hostInstance("test-service", false, map1)); - hosts.add(AnsMockTest.hostInstance("test-service", true, map2)); - - PowerMockito.mockStatic(NamingService.class); - when(NamingService.getHosts(eq("test-service"))).thenReturn( - hosts.stream().filter(Host::isValid).collect(Collectors.toList())); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - AnsServerList serverList = new AnsServerList("test-service"); - serverList.initWithNiwsConfig(clientConfig); - List servers = serverList.getInitialListOfServers(); - Assertions.assertThat(servers).hasSize(1); - - AnsServer ansServer = servers.get(0); - Host host = ansServer.getHealthService(); - - assertThat(ansServer.getMetaInfo().getInstanceId()).isEqualTo( - host.getIp() + ":" + host.getHostname() + ":" + host.getPort()); - assertThat(ansServer.getHealthService().isValid()).isEqualTo(true); - assertThat(ansServer.getHealthService().getHostname()).isEqualTo("test-service"); - - } - - @Test - public void testUpdateServers() throws Exception { - ArrayList hosts = new ArrayList<>(); - - HashMap map = new HashMap<>(); - map.put("instanceNum", "1"); - hosts.add(AnsMockTest.hostInstance("test-service", true, map)); - - PowerMockito.mockStatic(NamingService.class); - when(NamingService.getHosts(eq("test-service"))).thenReturn( - hosts.stream().filter(Host::isValid).collect(Collectors.toList())); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - AnsServerList serverList = new AnsServerList("test-service"); - serverList.initWithNiwsConfig(clientConfig); - - List servers = serverList.getUpdatedListOfServers(); - Assertions.assertThat(servers).hasSize(1); - - assertThat(servers.get(0).getHealthService().isValid()).isEqualTo(true); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java deleted file mode 100644 index 57d6faa2..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/ribbon/AnsServiceListTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.ribbon; - -import java.util.Arrays; -import java.util.List; - -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import com.netflix.loadbalancer.Server; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * @author xiaolongzuo - */ -public class AnsServiceListTests { - - static final String IP_ADDR = "10.0.0.2"; - - static final int PORT = 8080; - - @Test - public void testAnsServer() { - AnsServerList serverList = getAnsServerList(); - List servers = serverList.getInitialListOfServers(); - assertThat(servers).isNotNull(); - assertThat(servers.size()).isEqualTo(1); - Server des = assertAnsServer(servers); - assertThat(des.getHostPort()).isEqualTo(IP_ADDR + ":" + PORT); - } - - protected Server assertAnsServer(List servers) { - Server actualServer = servers.get(0); - assertThat(actualServer instanceof AnsServer).isEqualTo(Boolean.TRUE); - AnsServer des = AnsServer.class.cast(actualServer); - assertThat(des.getHealthService()).isNotNull(); - assertThat(des.getHealthService().getUnit()).isEqualTo("DEFAULT"); - return des; - } - - protected AnsServerList getAnsServerList() { - Host host = mock(Host.class); - given(host.getIp()).willReturn(IP_ADDR); - given(host.getDoubleWeight()).willReturn(1.0); - given(host.getPort()).willReturn(PORT); - given(host.getWeight()).willReturn(1); - given(host.getUnit()).willReturn("DEFAULT"); - - AnsServer server = new AnsServer(host, "testDom"); - @SuppressWarnings("unchecked") - AnsServerList originalServerList = mock(AnsServerList.class); - given(originalServerList.getInitialListOfServers()) - .willReturn(Arrays.asList(server)); - return originalServerList; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java deleted file mode 100644 index 0b18f41e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-ans/src/test/java/com/alibaba/alicloud/ans/test/AnsMockTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.ans.test; - -import java.util.Map; - -import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - -/** - * @author xiaojing - */ -public final class AnsMockTest { - - private AnsMockTest() { - - } - - public static Host hostInstance(String serviceName, boolean valid, - Map metadata) { - Host host = new Host(); - host.setHostname(serviceName); - host.setValid(valid); - return host; - } - - public static Host hostInstance(String serviceName, boolean valid, String ip, - int port, Map metadata) { - Host host = new Host(); - host.setIp(ip); - host.setPort(port); - host.setValid(valid); - host.setHostname(serviceName); - return host; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/pom.xml b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/pom.xml deleted file mode 100644 index 1c38c12f..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - 4.0.0 - - - com.alibaba.cloud - spring-cloud-starter-alicloud - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - spring-cloud-starter-alicloud-oss - Spring Cloud Starter Alibaba Cloud OSS - - - - com.alibaba.cloud - spring-cloud-alicloud-context - - - - com.aliyun.oss - aliyun-sdk-oss - - - - org.springframework.boot - spring-boot-actuator - true - - - - org.springframework.boot - spring-boot-actuator-autoconfigure - true - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.slf4j - slf4j-api - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.mockito - mockito-core - test - - - com.aliyun.oss - aliyun-sdk-oss - - - org.springframework.boot - spring-boot-starter - - - - diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java deleted file mode 100644 index 030464d1..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssApplicationListener.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss; - -import java.util.Map; - -import com.aliyun.oss.OSS; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextClosedEvent; - -/** - * Shutdown All OSS Clients when {@code ApplicationContext} gets closed - * {@link ApplicationListener}. - * - * @author Jim - */ -public class OssApplicationListener implements ApplicationListener { - - private static final Logger log = LoggerFactory - .getLogger(OssApplicationListener.class); - - @Override - public void onApplicationEvent(ContextClosedEvent event) { - Map ossClientMap = event.getApplicationContext() - .getBeansOfType(OSS.class); - log.info("{} OSSClients will be shutdown soon", ossClientMap.size()); - ossClientMap.keySet().forEach(beanName -> { - log.info("shutdown ossClient: {}", beanName); - ossClientMap.get(beanName).shutdown(); - }); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java deleted file mode 100644 index 5c6b168c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssAutoConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import com.alibaba.alicloud.oss.resource.OssStorageProtocolResolver; -import com.aliyun.oss.OSS; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME; - -/** - * OSS Auto {@link Configuration}. - * - * @author Jim - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(OSS.class) -@ConditionalOnProperty(name = OssConstants.ENABLED, havingValue = "true", - matchIfMissing = true) -public class OssAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public OssStorageProtocolResolver ossStorageProtocolResolver() { - return new OssStorageProtocolResolver(); - } - - @Bean(name = OSS_TASK_EXECUTOR_BEAN_NAME) - @ConditionalOnMissingBean - public ExecutorService ossTaskExecutor() { - int coreSize = Runtime.getRuntime().availableProcessors(); - return new ThreadPoolExecutor(coreSize, 128, 60, TimeUnit.SECONDS, - new SynchronousQueue<>()); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java deleted file mode 100644 index 6552959a..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/OssConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss; - -/** - * OSS constants. - * - * @author Jim - */ -public final class OssConstants { - - /** - * Prefix of OSSConfigurationProperties. - */ - public static final String PREFIX = "spring.cloud.alibaba.oss"; - - /** - * Enable OSS. - */ - public static final String ENABLED = PREFIX + ".enabled"; - - /** - * OSS ThreadPool bean name. - */ - public static final String OSS_TASK_EXECUTOR_BEAN_NAME = "ossTaskExecutor"; - - private OssConstants() { - throw new AssertionError("Must not instantiate constant utility class"); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java deleted file mode 100644 index 96d14a82..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpoint.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss.endpoint; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.aliyun.oss.OSSClient; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; -import org.springframework.context.ApplicationContext; - -/** - * Actuator {@link Endpoint} to expose OSS Meta Data. - * - * @author Jim - */ -@Endpoint(id = "oss") -public class OssEndpoint { - - @Autowired - private ApplicationContext applicationContext; - - @ReadOperation - public Map invoke() { - Map result = new HashMap<>(); - - Map ossClientMap = applicationContext - .getBeansOfType(OSSClient.class); - - int size = ossClientMap.size(); - - List ossClientList = new ArrayList<>(); - - ossClientMap.keySet().forEach(beanName -> { - Map ossProperties = new HashMap<>(); - OSSClient client = ossClientMap.get(beanName); - ossProperties.put("beanName", beanName); - ossProperties.put("endpoint", client.getEndpoint().toString()); - ossProperties.put("clientConfiguration", client.getClientConfiguration()); - ossProperties.put("credentials", - client.getCredentialsProvider().getCredentials()); - ossProperties.put("bucketList", client.listBuckets().stream() - .map(bucket -> bucket.getName()).toArray()); - ossClientList.add(ossProperties); - }); - - result.put("size", size); - result.put("info", ossClientList); - - return result; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java deleted file mode 100644 index 8ac753c7..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/endpoint/OssEndpointAutoConfiguration.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss.endpoint; - -import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * OSS {@link Endpoint} Auto-{@link Configuration}. - * - * @author Jim - */ -@ConditionalOnClass(Endpoint.class) -public class OssEndpointAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint - public OssEndpoint ossEndpoint() { - return new OssEndpoint(); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java deleted file mode 100644 index 7273f900..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageProtocolResolver.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss.resource; - -import com.aliyun.oss.OSS; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.ResourceLoaderAware; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.ProtocolResolver; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; - -/** - * A {@link ProtocolResolver} implementation for the {@code oss://} protocol. - * - * @author Jim - */ -public class OssStorageProtocolResolver - implements ProtocolResolver, BeanFactoryPostProcessor, ResourceLoaderAware { - - /** - * protocol of oss resource. - */ - public static final String PROTOCOL = "oss://"; - - private static final Logger log = LoggerFactory - .getLogger(OssStorageProtocolResolver.class); - - private ConfigurableListableBeanFactory beanFactory; - - private OSS oss; - - private OSS getOSS() { - if (this.oss == null) { - if (this.beanFactory.getBeansOfType(OSS.class).size() > 1) { - log.warn( - "There are multiple OSS instances, consider marking one of them as @Primary to resolve oss " - + "protocol."); - } - this.oss = this.beanFactory.getBean(OSS.class); - } - return this.oss; - } - - @Override - public Resource resolve(String location, ResourceLoader resourceLoader) { - if (!location.startsWith(PROTOCOL)) { - return null; - } - return new OssStorageResource(getOSS(), location, beanFactory); - } - - @Override - public void setResourceLoader(ResourceLoader resourceLoader) { - if (DefaultResourceLoader.class.isAssignableFrom(resourceLoader.getClass())) { - ((DefaultResourceLoader) resourceLoader).addProtocolResolver(this); - } - else { - log.warn("The provided delegate resource loader is not an implementation " - + "of DefaultResourceLoader. Custom Protocol using oss:// prefix will not be enabled."); - } - } - - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) - throws BeansException { - this.beanFactory = beanFactory; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java deleted file mode 100644 index 3995518e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/java/com/alibaba/alicloud/oss/resource/OssStorageResource.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss.resource; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.concurrent.ExecutorService; - -import com.aliyun.oss.ClientException; -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSException; -import com.aliyun.oss.model.Bucket; -import com.aliyun.oss.model.OSSObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.core.io.Resource; -import org.springframework.core.io.WritableResource; -import org.springframework.util.Assert; - -import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME; - -/** - * Implements {@link Resource} for reading and writing objects in Aliyun Object Storage - * Service (OSS). An instance of this class represents a handle to a bucket or an - * OSSObject. - * - * @author Jim - * @see OSS - * @see Bucket - * @see OSSObject - */ -public class OssStorageResource implements WritableResource { - - private static final Logger logger = LoggerFactory - .getLogger(OssStorageResource.class); - - private static final String MESSAGE_KEY_NOT_EXIST = "The specified key does not exist."; - - private final OSS oss; - - private final String bucketName; - - private final String objectKey; - - private final URI location; - - private final boolean autoCreateFiles; - - private final ExecutorService ossTaskExecutor; - - private final ConfigurableListableBeanFactory beanFactory; - - public OssStorageResource(OSS oss, String location, - ConfigurableListableBeanFactory beanFactory) { - this(oss, location, beanFactory, false); - } - - public OssStorageResource(OSS oss, String location, - ConfigurableListableBeanFactory beanFactory, boolean autoCreateFiles) { - Assert.notNull(oss, "Object Storage Service can not be null"); - Assert.isTrue(location.startsWith(OssStorageProtocolResolver.PROTOCOL), - "Location must start with " + OssStorageProtocolResolver.PROTOCOL); - this.oss = oss; - this.autoCreateFiles = autoCreateFiles; - this.beanFactory = beanFactory; - try { - URI locationUri = new URI(location); - this.bucketName = locationUri.getAuthority(); - - if (locationUri.getPath() != null && locationUri.getPath().length() > 1) { - this.objectKey = locationUri.getPath().substring(1); - } - else { - this.objectKey = null; - } - this.location = locationUri; - } - catch (URISyntaxException e) { - throw new IllegalArgumentException("Invalid location: " + location, e); - } - - this.ossTaskExecutor = this.beanFactory.getBean(OSS_TASK_EXECUTOR_BEAN_NAME, - ExecutorService.class); - } - - public boolean isAutoCreateFiles() { - return this.autoCreateFiles; - } - - @Override - public boolean exists() { - try { - return isBucket() ? getBucket() != null : getOSSObject() != null; - } - catch (Exception e) { - return false; - } - } - - /** - * Since the oss: protocol will normally not have a URL stream handler registered, - * this method will always throw a {@link java.net.MalformedURLException}. - * @return The URL for the OSS resource, if a URL stream handler is registered for the - * oss protocol. - */ - @Override - public URL getURL() throws IOException { - return this.location.toURL(); - } - - @Override - public URI getURI() throws IOException { - return this.location; - } - - @Override - public File getFile() throws IOException { - throw new UnsupportedOperationException( - getDescription() + " cannot be resolved to absolute file path"); - } - - @Override - public long contentLength() throws IOException { - assertExisted(); - if (isBucket()) { - throw new FileNotFoundException("OSSObject not existed."); - } - return getOSSObject().getObjectMetadata().getContentLength(); - } - - @Override - public long lastModified() throws IOException { - assertExisted(); - if (isBucket()) { - throw new FileNotFoundException("OSSObject not existed."); - } - return getOSSObject().getObjectMetadata().getLastModified().getTime(); - } - - @Override - public Resource createRelative(String relativePath) throws IOException { - return new OssStorageResource(this.oss, - this.location.resolve(relativePath).toString(), this.beanFactory); - } - - @Override - public String getFilename() { - return isBucket() ? this.bucketName : this.objectKey; - } - - @Override - public String getDescription() { - return this.location.toString(); - } - - @Override - public InputStream getInputStream() throws IOException { - assertExisted(); - if (isBucket()) { - throw new IllegalStateException( - "Cannot open an input stream to a bucket: '" + this.location + "'"); - } - else { - return getOSSObject().getObjectContent(); - } - } - - /** - * Returns the {@link Bucket} associated with the resource. - * @return the bucket if it exists, or null otherwise - */ - public Bucket getBucket() { - return this.oss.listBuckets().stream() - .filter(bucket -> bucket.getName().equals(this.bucketName)).findFirst() - .orElse(null); - } - - /** - * Checks for the existence of the {@link Bucket} associated with the resource. - * @return true if the bucket exists - */ - public boolean bucketExists() { - return getBucket() != null; - } - - /** - * Gets the underlying resource object in Aliyun Object Storage Service. - * @return The resource object, will be null if it does not exist in Aliyun Object - * Storage Service. - * @throws OSSException it is thrown upon error when accessing OSS - * @throws ClientException it is the one thrown by the client side when accessing OSS - */ - public OSSObject getOSSObject() { - return this.oss.getObject(this.bucketName, this.objectKey); - } - - /** - * Check if this resource references a bucket and not a blob. - * @return if the resource is bucket - */ - public boolean isBucket() { - return this.objectKey == null; - } - - private void assertExisted() throws FileNotFoundException { - if (!exists()) { - throw new FileNotFoundException("Bucket or OSSObject not existed."); - } - } - - /** - * create a bucket. - * @return OSS Bucket - */ - public Bucket createBucket() { - return this.oss.createBucket(this.bucketName); - } - - @Override - public boolean isWritable() { - return !isBucket() && (this.autoCreateFiles || exists()); - } - - /** - * acquire an OutputStream for write. Note: please close the stream after writing is - * done - * @return OutputStream of OSS resource - * @throws IOException throw by oss operation - */ - @Override - public OutputStream getOutputStream() throws IOException { - if (isBucket()) { - throw new IllegalStateException( - "Cannot open an output stream to a bucket: '" + getURI() + "'"); - } - else { - OSSObject ossObject; - - try { - ossObject = this.getOSSObject(); - } - catch (OSSException ex) { - if (ex.getMessage() != null - && ex.getMessage().startsWith(MESSAGE_KEY_NOT_EXIST)) { - ossObject = null; - } - else { - throw ex; - } - } - - if (ossObject == null) { - if (!this.autoCreateFiles) { - throw new FileNotFoundException( - "The object was not found: " + getURI()); - } - - } - - PipedInputStream in = new PipedInputStream(); - final PipedOutputStream out = new PipedOutputStream(in); - - ossTaskExecutor.submit(() -> { - try { - OssStorageResource.this.oss.putObject(bucketName, objectKey, in); - } - catch (Exception ex) { - logger.error("Failed to put object", ex); - } - }); - - return out; - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 23156e69..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,5 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.alibaba.alicloud.oss.OssAutoConfiguration,\ -com.alibaba.alicloud.oss.endpoint.OssEndpointAutoConfiguration -org.springframework.context.ApplicationListener=\ -com.alibaba.alicloud.oss.OssApplicationListener \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java deleted file mode 100644 index 66eeb079..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/DummyOssClient.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss.resource; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import com.aliyun.oss.model.Bucket; -import com.aliyun.oss.model.OSSObject; -import com.aliyun.oss.model.ObjectMetadata; -import com.aliyun.oss.model.PutObjectResult; - -import org.springframework.util.StreamUtils; - -/** - * @author lich - */ -public class DummyOssClient { - - private Map storeMap = new ConcurrentHashMap<>(); - - private Map bucketSet = new HashMap<>(); - - public String getStoreKey(String bucketName, String objectKey) { - return String.join(".", bucketName, objectKey); - } - - public PutObjectResult putObject(String bucketName, String objectKey, - InputStream inputStream) { - - try { - byte[] result = StreamUtils.copyToByteArray(inputStream); - storeMap.put(getStoreKey(bucketName, objectKey), result); - } - catch (IOException ex) { - throw new RuntimeException(ex); - } - finally { - try { - inputStream.close(); - } - catch (IOException ex) { - throw new RuntimeException(ex); - } - } - - return new PutObjectResult(); - } - - public OSSObject getOSSObject(String bucketName, String objectKey) { - byte[] value = storeMap.get(this.getStoreKey(bucketName, objectKey)); - if (value == null) { - return null; - } - OSSObject ossObject = new OSSObject(); - ossObject.setBucketName(bucketName); - ossObject.setKey(objectKey); - InputStream inputStream = new ByteArrayInputStream(value); - ossObject.setObjectContent(inputStream); - - ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentLength(value.length); - ossObject.setObjectMetadata(objectMetadata); - - return ossObject; - } - - public Bucket createBucket(String bucketName) { - if (bucketSet.containsKey(bucketName)) { - return bucketSet.get(bucketName); - } - Bucket bucket = new Bucket(); - bucket.setCreationDate(new Date()); - bucket.setName(bucketName); - bucketSet.put(bucketName, bucket); - return bucket; - } - - public List bucketList() { - return new ArrayList<>(bucketSet.values()); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java deleted file mode 100644 index 7894a8b7..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-oss/src/test/java/com/alibaba/alicloud/oss/resource/OssStorageResourceTest.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.oss.resource; - -import java.io.ByteArrayInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Random; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import com.aliyun.oss.OSS; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mockito; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.core.io.Resource; -import org.springframework.core.io.WritableResource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.StreamUtils; - -import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; - -/** - * @author lich - */ -@SpringBootTest -@RunWith(SpringRunner.class) -public class OssStorageResourceTest { - - /** - * Used to test exception messages and types. - */ - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @Autowired - private ConfigurableListableBeanFactory beanFactory; - - @Autowired - private OSS oss; - - @Value("oss://aliyun-test-bucket/") - private Resource bucketResource; - - @Value("oss://aliyun-test-bucket/myfilekey") - private Resource remoteResource; - - public static byte[] generateRandomBytes(int blen) { - byte[] array = new byte[blen]; - new Random().nextBytes(array); - return array; - } - - @Test - public void testResourceType() { - assertThat(remoteResource.getClass()).isEqualTo(OssStorageResource.class); - OssStorageResource ossStorageResource = (OssStorageResource) remoteResource; - assertThat(ossStorageResource.getFilename()).isEqualTo("myfilekey"); - assertThat(ossStorageResource.isBucket()).isEqualTo(false); - } - - @Test - public void testValidObject() throws Exception { - assertThat(remoteResource.exists()).isEqualTo(true); - OssStorageResource ossStorageResource = (OssStorageResource) remoteResource; - assertThat(ossStorageResource.bucketExists()).isEqualTo(true); - assertThat(remoteResource.contentLength()).isEqualTo(4096L); - assertThat(remoteResource.getURI().toString()) - .isEqualTo("oss://aliyun-test-bucket/myfilekey"); - assertThat(remoteResource.getFilename()).isEqualTo("myfilekey"); - } - - @Test - public void testBucketResource() throws Exception { - assertThat(bucketResource.exists()).isEqualTo(true); - assertThat(((OssStorageResource) this.bucketResource).isBucket()).isEqualTo(true); - assertThat(((OssStorageResource) this.bucketResource).bucketExists()) - .isEqualTo(true); - assertThat(bucketResource.getURI().toString()) - .isEqualTo("oss://aliyun-test-bucket/"); - assertThat(this.bucketResource.getFilename()).isEqualTo("aliyun-test-bucket"); - } - - @Test - public void testBucketNotEndingInSlash() { - assertThat( - new OssStorageResource(this.oss, "oss://aliyun-test-bucket", beanFactory) - .isBucket()).isEqualTo(true); - } - - @Test - public void testSpecifyPathCorrect() { - OssStorageResource ossStorageResource = new OssStorageResource(this.oss, - "oss://aliyun-test-bucket/myfilekey", beanFactory, false); - assertThat(ossStorageResource.exists()).isEqualTo(true); - } - - @Test - public void testSpecifyBucketCorrect() { - OssStorageResource ossStorageResource = new OssStorageResource(this.oss, - "oss://aliyun-test-bucket", beanFactory, false); - - assertThat(ossStorageResource.isBucket()).isEqualTo(true); - assertThat(ossStorageResource.getBucket().getName()) - .isEqualTo("aliyun-test-bucket"); - assertThat(ossStorageResource.exists()).isEqualTo(true); - } - - @Test - public void testBucketOutputStream() throws IOException { - this.expectedEx.expect(IllegalStateException.class); - this.expectedEx.expectMessage( - "Cannot open an output stream to a bucket: 'oss://aliyun-test-bucket/'"); - ((WritableResource) this.bucketResource).getOutputStream(); - } - - @Test - public void testBucketInputStream() throws IOException { - this.expectedEx.expect(IllegalStateException.class); - this.expectedEx.expectMessage( - "Cannot open an input stream to a bucket: 'oss://aliyun-test-bucket/'"); - this.bucketResource.getInputStream(); - } - - @Test - public void testBucketContentLength() throws IOException { - this.expectedEx.expect(FileNotFoundException.class); - this.expectedEx.expectMessage("OSSObject not existed."); - this.bucketResource.contentLength(); - } - - @Test - public void testBucketFile() throws IOException { - this.expectedEx.expect(UnsupportedOperationException.class); - this.expectedEx.expectMessage( - "oss://aliyun-test-bucket/ cannot be resolved to absolute file path"); - this.bucketResource.getFile(); - } - - @Test - public void testBucketLastModified() throws IOException { - this.expectedEx.expect(FileNotFoundException.class); - this.expectedEx.expectMessage("OSSObject not existed."); - this.bucketResource.lastModified(); - } - - @Test - public void testBucketResourceStatuses() { - assertThat(this.bucketResource.isOpen()).isEqualTo(false); - assertThat(((WritableResource) this.bucketResource).isWritable()) - .isEqualTo(false); - assertThat(this.bucketResource.exists()).isEqualTo(true); - } - - @Test - public void testWritable() throws Exception { - assertThat(this.remoteResource instanceof WritableResource).isEqualTo(true); - WritableResource writableResource = (WritableResource) this.remoteResource; - assertThat(writableResource.isWritable()).isEqualTo(true); - writableResource.getOutputStream(); - } - - @Test - public void testWritableOutputStream() throws Exception { - String location = "oss://aliyun-test-bucket/test"; - OssStorageResource resource = new OssStorageResource(this.oss, location, - beanFactory, true); - OutputStream os = resource.getOutputStream(); - assertThat(os).isNotNull(); - - byte[] randomBytes = generateRandomBytes(1203); - String expectedString = new String(randomBytes); - - os.write(randomBytes); - os.close(); - - InputStream in = resource.getInputStream(); - - byte[] result = StreamUtils.copyToByteArray(in); - String actualString = new String(result); - - assertThat(actualString).isEqualTo(expectedString); - } - - @Test - public void testCreateBucket() { - String location = "oss://my-new-test-bucket/"; - OssStorageResource resource = new OssStorageResource(this.oss, location, - beanFactory, true); - - resource.createBucket(); - - assertThat(resource.bucketExists()).isEqualTo(true); - } - - /** - * Configuration for the tests. - */ - @Configuration - @Import(OssStorageProtocolResolver.class) - static class TestConfiguration { - - @Bean(name = OSS_TASK_EXECUTOR_BEAN_NAME) - @ConditionalOnMissingBean - public ExecutorService ossTaskExecutor() { - return new ThreadPoolExecutor(8, 128, 60, TimeUnit.SECONDS, - new SynchronousQueue<>()); - } - - @Bean - public static OSS mockOSS() { - DummyOssClient dummyOssStub = new DummyOssClient(); - OSS oss = mock(OSS.class); - - doAnswer(invocation -> dummyOssStub.putObject(invocation.getArgument(0), - invocation.getArgument(1), invocation.getArgument(2))).when(oss) - .putObject(Mockito.anyString(), Mockito.anyString(), - Mockito.any(InputStream.class)); - - doAnswer(invocation -> dummyOssStub.getOSSObject(invocation.getArgument(0), - invocation.getArgument(1))).when(oss).getObject(Mockito.anyString(), - Mockito.anyString()); - - doAnswer(invocation -> dummyOssStub.bucketList()).when(oss).listBuckets(); - - doAnswer(invocation -> dummyOssStub.createBucket(invocation.getArgument(0))) - .when(oss).createBucket(Mockito.anyString()); - - // prepare object - dummyOssStub.createBucket("aliyun-test-bucket"); - - byte[] content = generateRandomBytes(4096); - ByteArrayInputStream inputStream = new ByteArrayInputStream(content); - dummyOssStub.putObject("aliyun-test-bucket", "myfilekey", inputStream); - - return oss; - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/pom.xml b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/pom.xml deleted file mode 100644 index 6076036f..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - 4.0.0 - - - com.alibaba.cloud - spring-cloud-starter-alicloud - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - spring-cloud-starter-alicloud-schedulerx - Spring Cloud Starter Alibaba Cloud SchedulerX - - - - org.springframework.boot - spring-boot-starter - - - - com.alibaba.cloud - spring-cloud-alicloud-context - - - - org.slf4j - slf4j-api - - - - com.alibaba.edas - schedulerX-client - - - - com.aliyun - aliyun-java-sdk-core - - - - com.aliyun - aliyun-java-sdk-edas - - - - org.springframework.boot - spring-boot-autoconfigure - true - - - - org.springframework.boot - spring-boot-actuator-autoconfigure - true - - - - org.springframework.boot - spring-boot-actuator - true - - - - diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java deleted file mode 100644 index 3ee04004..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/ScxAutoConfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.scx; - -import org.springframework.context.annotation.Configuration; - -/** - * placeholder configuration. - * - * @author xiaolongzuo - */ -@Configuration(proxyBeanMethods = false) -public class ScxAutoConfiguration { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java deleted file mode 100644 index 64801f94..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpoint.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.scx.endpoint; - -import java.util.HashMap; -import java.util.Map; - -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.alicloud.context.scx.ScxProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - -/** - * @author xiaolongzuo - */ -@Endpoint(id = "scx") -public class ScxEndpoint { - - private static final Logger LOGGER = LoggerFactory.getLogger(ScxEndpoint.class); - - private ScxProperties scxProperties; - - private EdasProperties edasProperties; - - public ScxEndpoint(EdasProperties edasProperties, ScxProperties scxProperties) { - this.edasProperties = edasProperties; - this.scxProperties = scxProperties; - } - - /** - * @return scx endpoint - */ - @ReadOperation - public Map invoke() { - Map scxEndpoint = new HashMap<>(); - LOGGER.info("SCX endpoint invoke, scxProperties is {}", scxProperties); - scxEndpoint.put("namespace", - edasProperties == null ? "" : edasProperties.getNamespace()); - scxEndpoint.put("scxProperties", scxProperties); - return scxEndpoint; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java deleted file mode 100644 index 366cc540..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/java/com/alibaba/alicloud/scx/endpoint/ScxEndpointAutoConfiguration.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.scx.endpoint; - -import com.alibaba.alicloud.context.edas.EdasProperties; -import com.alibaba.alicloud.context.scx.ScxProperties; - -import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; - -/** - * @author xiaolongzuo - */ -@ConditionalOnWebApplication -@ConditionalOnClass(Endpoint.class) -public class ScxEndpointAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint - public ScxEndpoint scxEndpoint(EdasProperties edasProperties, - ScxProperties scxProperties) { - return new ScxEndpoint(edasProperties, scxProperties); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 3032200c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-schedulerx/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.alibaba.alicloud.scx.endpoint.ScxEndpointAutoConfiguration,\ - com.alibaba.alicloud.scx.ScxAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/pom.xml b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/pom.xml deleted file mode 100644 index b535a7cb..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - 4.0.0 - - - com.alibaba.cloud - spring-cloud-starter-alicloud - 2.2.1.BUILD-SNAPSHOT - ../pom.xml - - - spring-cloud-starter-alicloud-sms - Spring Cloud Starter Alibaba Cloud SMS - - - - - org.springframework.boot - spring-boot-starter - true - - - - org.springframework.boot - spring-boot-actuator-autoconfigure - true - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-actuator - true - - - - org.slf4j - slf4j-api - true - - - - com.alibaba.cloud - spring-cloud-alicloud-context - - - com.aliyun - aliyun-java-sdk-core - - - - - - - com.aliyun - aliyun-java-sdk-core - - - - com.aliyun - aliyun-java-sdk-dysmsapi - - - - com.aliyun.mns - aliyun-sdk-mns - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java deleted file mode 100644 index 4101ae9c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/AbstractSmsService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -import java.util.concurrent.ConcurrentHashMap; - -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.profile.DefaultProfile; - -/** - * @author pbting - */ -public abstract class AbstractSmsService implements ISmsService { - - private ConcurrentHashMap acsClientConcurrentHashMap = new ConcurrentHashMap<>(); - - @Override - public IAcsClient getHangZhouRegionClientProfile(String accessKeyId, - String accessKeySecret) { - - return acsClientConcurrentHashMap.computeIfAbsent( - getKey("cn-hangzhou", accessKeyId, accessKeySecret), - (iacsClient) -> new DefaultAcsClient(DefaultProfile - .getProfile("cn-hangzhou", accessKeyId, accessKeySecret))); - } - - private String getKey(String regionId, String accessKeyId, String accessKeySecret) { - - return regionId + ":" + accessKeyId + ":" + accessKeySecret; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java deleted file mode 100644 index 882009db..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/ISmsService.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -import com.aliyuncs.IAcsClient; -import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse; -import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsResponse; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; - -/** - * @author pbting - */ -public interface ISmsService { - - IAcsClient getHangZhouRegionClientProfile(String accessKeyId, String secret); - - SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest) - throws ServerException, ClientException; - - SendBatchSmsResponse sendSmsBatchRequest(SendBatchSmsRequest sendBatchSmsRequest) - throws ServerException, ClientException; - - SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest, String accessKeyId, - String accessKeySecret) throws ServerException, ClientException; - - SendBatchSmsResponse sendSmsBatchRequest(SendBatchSmsRequest sendSmsRequest, - String accessKeyId, String accessKeySecret) - throws ServerException, ClientException; - - boolean startSmsReportMessageListener( - SmsReportMessageListener smsReportMessageListener); - - boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener); - - QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request, - String accessKeyId, String accessKeySecret) throws ClientException; - - QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request) - throws ClientException; - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java deleted file mode 100644 index a356b0b5..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsInitializerEventListener.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -import java.util.Collection; -import java.util.concurrent.atomic.AtomicBoolean; - -import com.alibaba.alicloud.context.sms.SmsProperties; -import com.alibaba.alicloud.sms.base.MessageListener; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.profile.DefaultProfile; - -import org.springframework.boot.context.event.ApplicationStartedEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Component; - -/** - * @author pbting - */ -@Component -public class SmsInitializerEventListener - implements ApplicationListener { - - private final AtomicBoolean isCalled = new AtomicBoolean(false); - - private SmsProperties msConfigProperties; - - private ISmsService smsService; - - public SmsInitializerEventListener(SmsProperties msConfigProperties, - ISmsService smsService) { - this.msConfigProperties = msConfigProperties; - this.smsService = smsService; - } - - @Override - public void onApplicationEvent(ApplicationStartedEvent event) { - if (!isCalled.compareAndSet(false, true)) { - return; - } - - // 整个application context refreshed then do - // 可自助调整超时时间 - System.setProperty("sun.net.client.defaultConnectTimeout", - msConfigProperties.getConnectTimeout()); - System.setProperty("sun.net.client.defaultReadTimeout", - msConfigProperties.getReadTimeout()); - // 初始化acsClient,暂不支持region化 - try { - DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", - SmsProperties.SMS_PRODUCT, SmsProperties.SMS_DOMAIN); - Collection messageListeners = event.getApplicationContext() - .getBeansOfType(MessageListener.class).values(); - if (messageListeners.isEmpty()) { - return; - } - - for (MessageListener messageListener : messageListeners) { - if (SmsReportMessageListener.class.isInstance(messageListener)) { - if (msConfigProperties.getReportQueueName() != null - && msConfigProperties.getReportQueueName().trim() - .length() > 0) { - smsService.startSmsReportMessageListener( - (SmsReportMessageListener) messageListener); - continue; - } - - throw new IllegalArgumentException("the SmsReport queue name for " - + messageListener.getClass().getCanonicalName() - + " must be set."); - } - - if (SmsUpMessageListener.class.isInstance(messageListener)) { - - if (msConfigProperties.getUpQueueName() != null - && msConfigProperties.getUpQueueName().trim().length() > 0) { - smsService.startSmsUpMessageListener( - (SmsUpMessageListener) messageListener); - continue; - } - - throw new IllegalArgumentException("the SmsUp queue name for " - + messageListener.getClass().getCanonicalName() - + " must be set."); - } - } - } - catch (ClientException e) { - throw new RuntimeException( - "initialize sms profile end point cause an exception"); - } - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java deleted file mode 100644 index 3df32e94..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsMessageListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -import com.alibaba.alicloud.sms.base.MessageListener; - -/** - * @author pbting - */ -public interface SmsMessageListener extends MessageListener { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java deleted file mode 100644 index 7194a3a1..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsReportMessageListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -/** - * @author pbting - */ -public interface SmsReportMessageListener extends SmsMessageListener { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java deleted file mode 100644 index f5c49576..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsServiceImpl.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -import java.text.ParseException; - -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.sms.SmsProperties; -import com.alibaba.alicloud.sms.base.DefaultAlicomMessagePuller; -import com.alibaba.alicloud.sms.endpoint.EndpointManager; -import com.alibaba.alicloud.sms.endpoint.ReceiveMessageEntity; -import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse; -import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsResponse; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author pbting - */ -public final class SmsServiceImpl extends AbstractSmsService { - - private static final Logger log = LoggerFactory.getLogger(SmsServiceImpl.class); - - /** - * will expose user to call this method send sms message. - */ - private SmsProperties smsProperties; - - private AliCloudProperties aliCloudProperties; - - public SmsServiceImpl(AliCloudProperties aliCloudProperties, - SmsProperties smsProperties) { - this.aliCloudProperties = aliCloudProperties; - this.smsProperties = smsProperties; - } - - @Override - public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest) - throws ClientException { - - return sendSmsRequest(sendSmsRequest, aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); - } - - @Override - public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest, - String accessKeyId, String accessKeySecret) - throws ServerException, ClientException { - EndpointManager.addSendSmsRequest(sendSmsRequest); - // hint 此处可能会抛出异常,注意catch - return getHangZhouRegionClientProfile(accessKeyId, accessKeySecret) - .getAcsResponse(sendSmsRequest); - } - - @Override - public boolean startSmsReportMessageListener( - SmsReportMessageListener smsReportMessageListener) { - // 短信回执:SmsReport,短信上行:SmsUp - String messageType = "SmsReport"; - String queueName = smsProperties.getReportQueueName(); - return startReceiveMsg(messageType, queueName, smsReportMessageListener); - } - - @Override - public boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener) { - // 短信回执:SmsReport,短信上行:SmsUp - String messageType = "SmsUp"; - String queueName = smsProperties.getUpQueueName(); - return startReceiveMsg(messageType, queueName, smsUpMessageListener); - } - - private boolean startReceiveMsg(String messageType, String queueName, - SmsMessageListener messageListener) { - String accessKeyId = aliCloudProperties.getAccessKey(); - String accessKeySecret = aliCloudProperties.getSecretKey(); - boolean result = true; - try { - new DefaultAlicomMessagePuller().startReceiveMsg(accessKeyId, accessKeySecret, - messageType, queueName, messageListener); - EndpointManager.addReceiveMessageEntity( - new ReceiveMessageEntity(messageType, queueName, messageListener)); - } - catch (ClientException e) { - log.error("start sms report message listener cause an exception", e); - result = false; - } - catch (ParseException e) { - log.error("start sms report message listener cause an exception", e); - result = false; - } - return result; - } - - @Override - public SendBatchSmsResponse sendSmsBatchRequest( - SendBatchSmsRequest sendBatchSmsRequest) - throws ServerException, ClientException { - - return sendSmsBatchRequest(sendBatchSmsRequest, aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); - } - - @Override - public SendBatchSmsResponse sendSmsBatchRequest( - SendBatchSmsRequest sendBatchSmsRequest, String accessKeyId, - String accessKeySecret) throws ClientException { - EndpointManager.addSendBatchSmsRequest(sendBatchSmsRequest); - return getHangZhouRegionClientProfile(accessKeyId, accessKeySecret) - .getAcsResponse(sendBatchSmsRequest); - } - - @Override - public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request, - String accessKeyId, String accessKeySecret) throws ClientException { - return getHangZhouRegionClientProfile(accessKeyId, accessKeySecret) - .getAcsResponse(request); - } - - @Override - public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request) - throws ClientException { - return querySendDetails(request, aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java deleted file mode 100644 index b6c5242a..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/SmsUpMessageListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms; - -/** - * @author pbting - */ -public interface SmsUpMessageListener extends SmsMessageListener { - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java deleted file mode 100755 index c823ac4f..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/DefaultAlicomMessagePuller.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; - -import com.aliyun.mns.client.CloudQueue; -import com.aliyun.mns.common.ClientException; -import com.aliyun.mns.common.ServiceException; -import com.aliyun.mns.model.Message; -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 阿里通信官方消息默认拉取工具类. - */ -public class DefaultAlicomMessagePuller { - - private static final Logger log = LoggerFactory - .getLogger(DefaultAlicomMessagePuller.class); - - private String mnsAccountEndpoint = "https://1943695596114318.mns.cn-hangzhou.aliyuncs.com/"; // 阿里通信消息的endpoint,固定。 - - private String endpointNameForPop = "cn-hangzhou"; - - private String regionIdForPop = "cn-hangzhou"; - - private String domainForPop = "dybaseapi.aliyuncs.com"; - - private TokenGetterForAlicom tokenGetter; - - private MessageListener messageListener; - - private boolean isRunning = false; - - private Integer pullMsgThreadSize = 1; - - private boolean debugLogOpen = false; - - private Integer sleepSecondWhenNoData = 30; - - public void openDebugLog(boolean debugLogOpen) { - this.debugLogOpen = debugLogOpen; - } - - public Integer getSleepSecondWhenNoData() { - return sleepSecondWhenNoData; - } - - public void setSleepSecondWhenNoData(Integer sleepSecondWhenNoData) { - this.sleepSecondWhenNoData = sleepSecondWhenNoData; - } - - public Integer getPullMsgThreadSize() { - return pullMsgThreadSize; - } - - public void setPullMsgThreadSize(Integer pullMsgThreadSize) { - if (pullMsgThreadSize != null && pullMsgThreadSize > 1) { - this.pullMsgThreadSize = pullMsgThreadSize; - } - } - - private ExecutorService executorService; - - public ExecutorService getExecutorService() { - return executorService; - } - - public void setExecutorService(ExecutorService executorService) { - this.executorService = executorService; - } - - protected static final Map S_LOCK_OBJ_MAP = new HashMap<>(); - - protected static Map sPollingMap = new ConcurrentHashMap<>(); - - protected Object lockObj; - - public boolean setPolling(String queueName) { - synchronized (lockObj) { - Boolean ret = sPollingMap.get(queueName); - if (ret == null || !ret) { - sPollingMap.put(queueName, true); - return true; - } - return false; - } - } - - public void clearPolling(String queueName) { - synchronized (lockObj) { - sPollingMap.put(queueName, false); - lockObj.notifyAll(); - if (debugLogOpen) { - log.info("PullMessageTask_WakeUp:Everyone WakeUp and Work!"); - } - } - } - - public boolean isRunning() { - return isRunning; - } - - public void setRunning(boolean running) { - isRunning = running; - } - - /** - * @param accessKeyId accessKeyId - * @param accessKeySecret accessKeySecret - * @param messageType 消息类型 - * @param queueName 队列名称 - * @param messageListener 回调的listener,用户自己实现 - * @throws com.aliyuncs.exceptions.ClientException throw by sdk - * @throws ParseException throw parse exception - */ - public void startReceiveMsg(String accessKeyId, String accessKeySecret, - String messageType, String queueName, MessageListener messageListener) - throws com.aliyuncs.exceptions.ClientException, ParseException { - - tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, - endpointNameForPop, regionIdForPop, domainForPop, null); - - this.messageListener = messageListener; - isRunning = true; - PullMessageTask task = new PullMessageTask(); - task.messageType = messageType; - task.queueName = queueName; - - synchronized (S_LOCK_OBJ_MAP) { - lockObj = S_LOCK_OBJ_MAP.get(queueName); - if (lockObj == null) { - lockObj = new Object(); - S_LOCK_OBJ_MAP.put(queueName, lockObj); - } - } - - if (executorService == null) { - ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( - pullMsgThreadSize, - new BasicThreadFactory.Builder() - .namingPattern( - "PullMessageTask-" + messageType + "-thread-pool-%d") - .daemon(true).build()); - executorService = scheduledExecutorService; - } - for (int i = 0; i < pullMsgThreadSize; i++) { - executorService.execute(task); - } - } - - /** - * @param accessKeyId accessKeyId - * @param accessKeySecret accessKeySecret - * @param messageType 消息类型 - * @param queueName 队列名称 - * @param regionIdForPop region - * @param endpointNameForPop endpoint name - * @param domainForPop domain - * @param mnsAccountEndpoint mns account endpoint - * @param messageListener 回调的listener,用户自己实现 - * @throws com.aliyuncs.exceptions.ClientException throw by sdk - * @throws ParseException throw parse exception - */ - public void startReceiveMsgForVPC(String accessKeyId, String accessKeySecret, - String messageType, String queueName, String regionIdForPop, - String endpointNameForPop, String domainForPop, String mnsAccountEndpoint, - MessageListener messageListener) - throws com.aliyuncs.exceptions.ClientException, ParseException { - this.mnsAccountEndpoint = mnsAccountEndpoint; - tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, - endpointNameForPop, regionIdForPop, domainForPop, null); - - this.messageListener = messageListener; - isRunning = true; - PullMessageTask task = new PullMessageTask(); - task.messageType = messageType; - task.queueName = queueName; - - synchronized (S_LOCK_OBJ_MAP) { - lockObj = S_LOCK_OBJ_MAP.get(queueName); - if (lockObj == null) { - lockObj = new Object(); - S_LOCK_OBJ_MAP.put(queueName, lockObj); - } - } - - if (executorService == null) { - ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( - pullMsgThreadSize, - new BasicThreadFactory.Builder() - .namingPattern( - "PullMessageTask-" + messageType + "-thread-pool-%d") - .daemon(true).build()); - executorService = scheduledExecutorService; - } - for (int i = 0; i < pullMsgThreadSize; i++) { - executorService.execute(task); - } - } - - /** - * 虚商用户定制接收消息方法. - * @param accessKeyId accessKeyId - * @param accessKeySecret accessKeySecret - * @param ownerId 实际的ownerId - * @param messageType 消息类型 - * @param queueName 队列名称 - * @param messageListener 回调listener - * @throws com.aliyuncs.exceptions.ClientException throw by sdk - * @throws ParseException throw parse exception - */ - public void startReceiveMsgForPartnerUser(String accessKeyId, String accessKeySecret, - Long ownerId, String messageType, String queueName, - MessageListener messageListener) - throws com.aliyuncs.exceptions.ClientException, ParseException { - - tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret, - endpointNameForPop, regionIdForPop, domainForPop, ownerId); - - this.messageListener = messageListener; - isRunning = true; - PullMessageTask task = new PullMessageTask(); - task.messageType = messageType; - task.queueName = queueName; - - synchronized (S_LOCK_OBJ_MAP) { - lockObj = S_LOCK_OBJ_MAP.get(queueName); - if (lockObj == null) { - lockObj = new Object(); - S_LOCK_OBJ_MAP.put(queueName, lockObj); - } - } - - if (executorService == null) { - ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor( - pullMsgThreadSize, - new BasicThreadFactory.Builder() - .namingPattern( - "PullMessageTask-" + messageType + "-thread-pool-%d") - .daemon(true).build()); - executorService = scheduledExecutorService; - } - for (int i = 0; i < pullMsgThreadSize; i++) { - executorService.execute(task); - } - } - - public void stop() { - isRunning = false; - } - - private class PullMessageTask implements Runnable { - - private String messageType; - - private String queueName; - - @Override - public void run() { - - boolean polling = false; - while (isRunning) { - try { - synchronized (lockObj) { - Boolean p = sPollingMap.get(queueName); - if (p != null && p) { - try { - if (debugLogOpen) { - log.info("PullMessageTask_sleep:" - + Thread.currentThread().getName() - + " Have a nice sleep!"); - } - polling = false; - lockObj.wait(); - } - catch (InterruptedException e) { - if (debugLogOpen) { - log.info("PullMessageTask_Interrupted!" - + Thread.currentThread().getName() - + " QueueName is " + queueName); - } - continue; - } - } - } - - TokenForAlicom tokenObject = tokenGetter.getTokenByMessageType( - messageType, queueName, mnsAccountEndpoint); - CloudQueue queue = tokenObject.getQueue(); - Message popMsg = null; - if (!polling) { - popMsg = queue.popMessage(); - if (debugLogOpen) { - SimpleDateFormat format = new SimpleDateFormat( - "yyyy-MM-dd HH:mm:ss"); - log.info("PullMessageTask_popMessage:" - + Thread.currentThread().getName() + "-popDone at " - + "," + format.format(new Date()) + " msgSize=" - + (popMsg == null ? 0 : popMsg.getMessageId())); - } - if (popMsg == null) { - polling = true; - continue; - } - } - else { - if (setPolling(queueName)) { - if (debugLogOpen) { - log.info("PullMessageTask_setPolling:" - + Thread.currentThread().getName() + " Polling!"); - } - } - else { - continue; - } - do { - if (debugLogOpen) { - log.info("PullMessageTask_Keep_Polling" - + Thread.currentThread().getName() - + "KEEP Polling!"); - } - try { - popMsg = queue.popMessage(sleepSecondWhenNoData); - } - catch (ClientException e) { - if (debugLogOpen) { - log.info( - "PullMessageTask_Pop_Message:ClientException Refresh accessKey" - + e); - } - tokenObject = tokenGetter.getTokenByMessageType( - messageType, queueName, mnsAccountEndpoint); - queue = tokenObject.getQueue(); - - } - catch (ServiceException e) { - if (debugLogOpen) { - log.info( - "PullMessageTask_Pop_Message:ServiceException Refresh accessKey" - + e); - } - tokenObject = tokenGetter.getTokenByMessageType( - messageType, queueName, mnsAccountEndpoint); - queue = tokenObject.getQueue(); - - } - catch (Exception e) { - if (debugLogOpen) { - log.info( - "PullMessageTask_Pop_Message:Exception Happened when polling popMessage: " - + e); - } - } - } - while (popMsg == null && isRunning); - clearPolling(queueName); - } - boolean dealResult = messageListener.dealMessage(popMsg); - if (dealResult) { - // remember to delete message when consume message successfully. - if (debugLogOpen) { - log.info("PullMessageTask_Deal_Message:" - + Thread.currentThread().getName() + "deleteMessage " - + popMsg.getMessageId()); - } - queue.deleteMessage(popMsg.getReceiptHandle()); - } - } - catch (ClientException e) { - log.error("PullMessageTask_execute_error,messageType:" + messageType - + ",queueName:" + queueName, e); - break; - - } - catch (ServiceException e) { - if (e.getErrorCode().equals("AccessDenied")) { - log.error("PullMessageTask_execute_error,messageType:" - + messageType + ",queueName:" + queueName - + ",please check messageType and queueName", e); - } - else { - log.error("PullMessageTask_execute_error,messageType:" - + messageType + ",queueName:" + queueName, e); - } - break; - - } - catch (com.aliyuncs.exceptions.ClientException e) { - if (e.getErrCode().equals("InvalidAccessKeyId.NotFound")) { - log.error("PullMessageTask_execute_error,messageType:" - + messageType + ",queueName:" + queueName - + ",please check AccessKeyId", e); - } - if (e.getErrCode().equals("SignatureDoesNotMatch")) { - log.error("PullMessageTask_execute_error,messageType:" - + messageType + ",queueName:" + queueName - + ",please check AccessKeySecret", e); - } - else { - log.error("PullMessageTask_execute_error,messageType:" - + messageType + ",queueName:" + queueName, e); - } - break; - - } - catch (Exception e) { - log.error("PullMessageTask_execute_error,messageType:" + messageType - + ",queueName:" + queueName, e); - try { - Thread.sleep(sleepSecondWhenNoData); - } - catch (InterruptedException e1) { - log.error("PullMessageTask_execute_error,messageType:" - + messageType + ",queueName:" + queueName, e); - } - } - } - - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java deleted file mode 100755 index 9717f050..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/MessageListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import com.aliyun.mns.model.Message; - -public interface MessageListener { - - boolean dealMessage(Message message); - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java deleted file mode 100644 index 8a8889cd..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueRequest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import com.aliyuncs.RpcAcsRequest; - -public class QueryTokenForMnsQueueRequest - extends RpcAcsRequest { - - private String resourceOwnerAccount; - - private String messageType; - - private Long resourceOwnerId; - - private Long ownerId; - - public QueryTokenForMnsQueueRequest() { - super("Dybaseapi", "2017-05-25", "QueryTokenForMnsQueue"); - } - - public String getResourceOwnerAccount() { - return this.resourceOwnerAccount; - } - - public void setResourceOwnerAccount(String resourceOwnerAccount) { - this.resourceOwnerAccount = resourceOwnerAccount; - if (resourceOwnerAccount != null) { - this.putQueryParameter("ResourceOwnerAccount", resourceOwnerAccount); - } - - } - - public String getMessageType() { - return this.messageType; - } - - public void setMessageType(String messageType) { - this.messageType = messageType; - if (messageType != null) { - this.putQueryParameter("MessageType", messageType); - } - - } - - public Long getResourceOwnerId() { - return this.resourceOwnerId; - } - - public void setResourceOwnerId(Long resourceOwnerId) { - this.resourceOwnerId = resourceOwnerId; - if (resourceOwnerId != null) { - this.putQueryParameter("ResourceOwnerId", resourceOwnerId.toString()); - } - - } - - public Long getOwnerId() { - return this.ownerId; - } - - public void setOwnerId(Long ownerId) { - this.ownerId = ownerId; - if (ownerId != null) { - this.putQueryParameter("OwnerId", ownerId.toString()); - } - - } - - @Override - public Class getResponseClass() { - return QueryTokenForMnsQueueResponse.class; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java deleted file mode 100644 index 3b1a2b3e..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponse.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import com.aliyuncs.AcsResponse; -import com.aliyuncs.transform.UnmarshallerContext; - -public class QueryTokenForMnsQueueResponse extends AcsResponse { - - private String requestId; - - private String code; - - private String message; - - private QueryTokenForMnsQueueResponse.MessageTokenDTO messageTokenDTO; - - public QueryTokenForMnsQueueResponse() { - } - - public String getRequestId() { - return this.requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getCode() { - return this.code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getMessage() { - return this.message; - } - - public void setMessage(String message) { - this.message = message; - } - - public QueryTokenForMnsQueueResponse.MessageTokenDTO getMessageTokenDTO() { - return this.messageTokenDTO; - } - - public void setMessageTokenDTO( - QueryTokenForMnsQueueResponse.MessageTokenDTO messageTokenDTO) { - this.messageTokenDTO = messageTokenDTO; - } - - @Override - public QueryTokenForMnsQueueResponse getInstance(UnmarshallerContext context) { - return QueryTokenForMnsQueueResponseUnmarshaller.unmarshall(this, context); - } - - public static class MessageTokenDTO { - - private String accessKeyId; - - private String accessKeySecret; - - private String securityToken; - - private String createTime; - - private String expireTime; - - public MessageTokenDTO() { - } - - public String getAccessKeyId() { - return this.accessKeyId; - } - - public void setAccessKeyId(String accessKeyId) { - this.accessKeyId = accessKeyId; - } - - public String getAccessKeySecret() { - return this.accessKeySecret; - } - - public void setAccessKeySecret(String accessKeySecret) { - this.accessKeySecret = accessKeySecret; - } - - public String getSecurityToken() { - return this.securityToken; - } - - public void setSecurityToken(String securityToken) { - this.securityToken = securityToken; - } - - public String getCreateTime() { - return this.createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public String getExpireTime() { - return this.expireTime; - } - - public void setExpireTime(String expireTime) { - this.expireTime = expireTime; - } - - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java deleted file mode 100644 index 36ca1f69..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/QueryTokenForMnsQueueResponseUnmarshaller.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import com.aliyuncs.transform.UnmarshallerContext; - -public final class QueryTokenForMnsQueueResponseUnmarshaller { - - private QueryTokenForMnsQueueResponseUnmarshaller() { - } - - public static QueryTokenForMnsQueueResponse unmarshall( - QueryTokenForMnsQueueResponse queryTokenForMnsQueueResponse, - UnmarshallerContext context) { - queryTokenForMnsQueueResponse.setRequestId( - context.stringValue("QueryTokenForMnsQueueResponse.RequestId")); - queryTokenForMnsQueueResponse - .setCode(context.stringValue("QueryTokenForMnsQueueResponse.Code")); - queryTokenForMnsQueueResponse - .setMessage(context.stringValue("QueryTokenForMnsQueueResponse.Message")); - QueryTokenForMnsQueueResponse.MessageTokenDTO messageTokenDTO = new QueryTokenForMnsQueueResponse.MessageTokenDTO(); - messageTokenDTO.setAccessKeyId(context.stringValue( - "QueryTokenForMnsQueueResponse.MessageTokenDTO.AccessKeyId")); - messageTokenDTO.setAccessKeySecret(context.stringValue( - "QueryTokenForMnsQueueResponse.MessageTokenDTO.AccessKeySecret")); - messageTokenDTO.setSecurityToken(context.stringValue( - "QueryTokenForMnsQueueResponse.MessageTokenDTO.SecurityToken")); - messageTokenDTO.setCreateTime(context - .stringValue("QueryTokenForMnsQueueResponse.MessageTokenDTO.CreateTime")); - messageTokenDTO.setExpireTime(context - .stringValue("QueryTokenForMnsQueueResponse.MessageTokenDTO.ExpireTime")); - queryTokenForMnsQueueResponse.setMessageTokenDTO(messageTokenDTO); - return queryTokenForMnsQueueResponse; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java deleted file mode 100755 index 97b67072..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenForAlicom.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import com.aliyun.mns.client.CloudQueue; -import com.aliyun.mns.client.MNSClient; - -/** - * 用于接收云通信消息的临时token. - * - */ -public class TokenForAlicom { - - private String messageType; - - private String token; - - private Long expireTime; - - private String tempAccessKeyId; - - private String tempAccessKeySecret; - - private MNSClient client; - - private CloudQueue queue; - - public String getMessageType() { - return messageType; - } - - public void setMessageType(String messageType) { - this.messageType = messageType; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public Long getExpireTime() { - return expireTime; - } - - public void setExpireTime(Long expireTime) { - this.expireTime = expireTime; - } - - public String getTempAccessKeyId() { - return tempAccessKeyId; - } - - public void setTempAccessKeyId(String tempAccessKeyId) { - this.tempAccessKeyId = tempAccessKeyId; - } - - public String getTempAccessKeySecret() { - return tempAccessKeySecret; - } - - public void setTempAccessKeySecret(String tempAccessKeySecret) { - this.tempAccessKeySecret = tempAccessKeySecret; - } - - public MNSClient getClient() { - return client; - } - - public void setClient(MNSClient client) { - this.client = client; - } - - public CloudQueue getQueue() { - return queue; - } - - public void setQueue(CloudQueue queue) { - this.queue = queue; - } - - public void closeClient() { - if (client != null) { - this.client.close(); - } - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java deleted file mode 100755 index 54e15df6..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/base/TokenGetterForAlicom.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.base; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.TimeZone; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.aliyun.mns.client.CloudAccount; -import com.aliyun.mns.client.CloudQueue; -import com.aliyun.mns.client.MNSClient; -import com.aliyuncs.DefaultAcsClient; -import com.aliyuncs.IAcsClient; -import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; -import com.aliyuncs.http.FormatType; -import com.aliyuncs.http.MethodType; -import com.aliyuncs.http.ProtocolType; -import com.aliyuncs.profile.DefaultProfile; -import com.aliyuncs.profile.IClientProfile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * 获取接收云通信消息的临时token. - */ -public class TokenGetterForAlicom { - - private static final Logger log = LoggerFactory.getLogger(TokenGetterForAlicom.class); - - private String accessKeyId; - - private String accessKeySecret; - - private String endpointNameForPop; - - private String regionIdForPop; - - private String domainForPop; - - private IAcsClient iAcsClient; - - private Long ownerId; - - private final static String PRODUCT_NAME = "Dybaseapi"; - - private long bufferTime = 1000 * 60 * 2; // 过期时间小于2分钟则重新获取,防止服务器时间误差 - - private final Object lock = new Object(); - - private ConcurrentMap tokenMap = new ConcurrentHashMap(); - - public TokenGetterForAlicom(String accessKeyId, String accessKeySecret, - String endpointNameForPop, String regionIdForPop, String domainForPop, - Long ownerId) throws ClientException { - this.accessKeyId = accessKeyId; - this.accessKeySecret = accessKeySecret; - this.endpointNameForPop = endpointNameForPop; - this.regionIdForPop = regionIdForPop; - this.domainForPop = domainForPop; - this.ownerId = ownerId; - init(); - } - - private void init() throws ClientException { - DefaultProfile.addEndpoint(endpointNameForPop, regionIdForPop, PRODUCT_NAME, - domainForPop); - IClientProfile profile = DefaultProfile.getProfile(regionIdForPop, accessKeyId, - accessKeySecret); - profile.getHttpClientConfig().setCompatibleMode(true); - iAcsClient = new DefaultAcsClient(profile); - } - - private TokenForAlicom getTokenFromRemote(String messageType) - throws ServerException, ClientException, ParseException { - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - df.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); - QueryTokenForMnsQueueRequest request = new QueryTokenForMnsQueueRequest(); - request.setAcceptFormat(FormatType.JSON); - request.setMessageType(messageType); - request.setOwnerId(ownerId); - request.setProtocol(ProtocolType.HTTPS); - request.setMethod(MethodType.POST); - QueryTokenForMnsQueueResponse response = iAcsClient.getAcsResponse(request); - String resultCode = response.getCode(); - if (resultCode != null && "OK".equals(resultCode)) { - QueryTokenForMnsQueueResponse.MessageTokenDTO dto = response - .getMessageTokenDTO(); - TokenForAlicom token = new TokenForAlicom(); - String timeStr = dto.getExpireTime(); - token.setMessageType(messageType); - token.setExpireTime(df.parse(timeStr).getTime()); - token.setToken(dto.getSecurityToken()); - token.setTempAccessKeyId(dto.getAccessKeyId()); - token.setTempAccessKeySecret(dto.getAccessKeySecret()); - return token; - } - else { - log.error("getTokenFromRemote_error,messageType:" + messageType + ",code:" - + response.getCode() + ",message:" + response.getMessage()); - throw new ServerException(response.getCode(), response.getMessage()); - } - } - - public TokenForAlicom getTokenByMessageType(String messageType, String queueName, - String mnsAccountEndpoint) - throws ServerException, ClientException, ParseException { - TokenForAlicom token = tokenMap.get(messageType); - Long now = System.currentTimeMillis(); - if (token == null || (token.getExpireTime() - now) < bufferTime) { // 过期时间小于2分钟则重新获取,防止服务器时间误差 - synchronized (lock) { - token = tokenMap.get(messageType); - if (token == null || (token.getExpireTime() - now) < bufferTime) { - TokenForAlicom oldToken = null; - if (token != null) { - oldToken = token; - } - token = getTokenFromRemote(messageType); - // 因为换token时需要重建client和关闭老的client,所以创建client的代码和创建token放在一起 - CloudAccount account = new CloudAccount(token.getTempAccessKeyId(), - token.getTempAccessKeySecret(), mnsAccountEndpoint, - token.getToken()); - MNSClient client = account.getMNSClient(); - CloudQueue queue = client.getQueueRef(queueName); - token.setClient(client); - token.setQueue(queue); - tokenMap.put(messageType, token); - if (oldToken != null) { - oldToken.closeClient(); - } - } - } - } - return token; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java deleted file mode 100644 index 62c2a2a9..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/config/SmsAutoConfiguration.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.config; - -import com.alibaba.alicloud.context.AliCloudProperties; -import com.alibaba.alicloud.context.sms.SmsProperties; -import com.alibaba.alicloud.sms.ISmsService; -import com.alibaba.alicloud.sms.SmsInitializerEventListener; -import com.alibaba.alicloud.sms.SmsServiceImpl; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; - -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.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author pbting - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnClass(SendSmsRequest.class) -@ConditionalOnProperty(value = "spring.cloud.alicloud.sms.enable", matchIfMissing = true) -public class SmsAutoConfiguration { - - @Bean - public SmsServiceImpl smsService(AliCloudProperties aliCloudProperties, - SmsProperties smsProperties) { - return new SmsServiceImpl(aliCloudProperties, smsProperties); - } - - @Bean - public SmsInitializerEventListener smsInitializePostListener( - SmsProperties smsProperties, ISmsService smsService) { - return new SmsInitializerEventListener(smsProperties, smsService); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java deleted file mode 100644 index 963a2651..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/EndpointManager.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.endpoint; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.locks.ReentrantLock; - -import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest; -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; - -/** - * - */ -public final class EndpointManager { - - private EndpointManager() { - - } - - private final static int BACKLOG_SIZE = 20; - - private final static ReentrantLock SEND_REENTRANT_LOCK = new ReentrantLock(true); - - private final static ReentrantLock SEND_BATCH_REENTRANT_LOCK = new ReentrantLock( - true); - - private final static LinkedBlockingQueue SEND_SMS_REQUESTS = new LinkedBlockingQueue( - BACKLOG_SIZE); - - private final static LinkedBlockingQueue SEND_BATCH_SMS_REQUESTS = new LinkedBlockingQueue( - BACKLOG_SIZE); - - private final static LinkedBlockingQueue RECEIVE_MESSAGE_ENTITIES = new LinkedBlockingQueue( - BACKLOG_SIZE); - - public static void addSendSmsRequest(SendSmsRequest sendSmsRequest) { - if (SEND_SMS_REQUESTS.offer(sendSmsRequest)) { - return; - } - try { - SEND_REENTRANT_LOCK.lock(); - SEND_SMS_REQUESTS.poll(); - SEND_SMS_REQUESTS.offer(sendSmsRequest); - } - finally { - SEND_REENTRANT_LOCK.unlock(); - } - } - - public static void addSendBatchSmsRequest(SendBatchSmsRequest sendBatchSmsRequest) { - if (SEND_BATCH_SMS_REQUESTS.offer(sendBatchSmsRequest)) { - return; - } - try { - SEND_BATCH_REENTRANT_LOCK.lock(); - SEND_BATCH_SMS_REQUESTS.poll(); - SEND_BATCH_SMS_REQUESTS.offer(sendBatchSmsRequest); - } - finally { - SEND_BATCH_REENTRANT_LOCK.unlock(); - } - } - - public static void addReceiveMessageEntity( - ReceiveMessageEntity receiveMessageEntity) { - if (RECEIVE_MESSAGE_ENTITIES.offer(receiveMessageEntity)) { - return; - } - RECEIVE_MESSAGE_ENTITIES.poll(); - RECEIVE_MESSAGE_ENTITIES.offer(receiveMessageEntity); - } - - public static Map getSmsEndpointMessage() { - List sendSmsRequests = new LinkedList<>(); - List sendBatchSmsRequests = new LinkedList<>(); - List receiveMessageEntities = new LinkedList<>(); - try { - SEND_REENTRANT_LOCK.lock(); - SEND_BATCH_REENTRANT_LOCK.lock(); - sendSmsRequests.addAll(SEND_SMS_REQUESTS); - sendBatchSmsRequests.addAll(SEND_BATCH_SMS_REQUESTS); - } - finally { - SEND_REENTRANT_LOCK.unlock(); - SEND_BATCH_REENTRANT_LOCK.unlock(); - } - receiveMessageEntities.addAll(RECEIVE_MESSAGE_ENTITIES); - - Map endpointMessages = new HashMap<>(); - endpointMessages.put("send-sms-request", sendSmsRequests); - endpointMessages.put("send-batch-sms-request", sendBatchSmsRequests); - endpointMessages.put("message-listener", receiveMessageEntities); - - return endpointMessages; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java deleted file mode 100644 index df3ea7c7..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/ReceiveMessageEntity.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.endpoint; - -import java.io.Serializable; - -import com.alibaba.alicloud.sms.base.MessageListener; - -/** - * @author pbting - */ -public class ReceiveMessageEntity implements Serializable { - - private String messageType; - - private String queueName; - - private MessageListener messageListener; - - public ReceiveMessageEntity(String messageType, String queueName, - MessageListener messageListener) { - this.messageType = messageType; - this.queueName = queueName; - this.messageListener = messageListener; - } - - public String getMessageType() { - return messageType; - } - - public void setMessageType(String messageType) { - this.messageType = messageType; - } - - public String getQueueName() { - return queueName; - } - - public void setQueueName(String queueName) { - this.queueName = queueName; - } - - public MessageListener getMessageListener() { - return messageListener; - } - - public void setMessageListener(MessageListener messageListener) { - this.messageListener = messageListener; - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java deleted file mode 100644 index 7f87d67c..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.endpoint; - -import java.util.Map; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - -@Endpoint(id = "sms") -public class SmsEndpoint { - - @ReadOperation - public Map invoke() { - - return EndpointManager.getSmsEndpointMessage(); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java deleted file mode 100644 index f788aae0..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/java/com/alibaba/alicloud/sms/endpoint/SmsEndpointAutoConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2013-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 com.alibaba.alicloud.sms.endpoint; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; - -@ConditionalOnWebApplication -@ConditionalOnClass(Endpoint.class) -public class SmsEndpointAutoConfiguration { - - @Bean - public SmsEndpoint smsEndpoint() { - return new SmsEndpoint(); - } - -} diff --git a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/resources/META-INF/spring.factories b/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/resources/META-INF/spring.factories deleted file mode 100644 index a6c328d2..00000000 --- a/spring-cloud-starter-alicloud/spring-cloud-starter-alicloud-sms/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - com.alibaba.alicloud.sms.config.SmsAutoConfiguration,\ - com.alibaba.alicloud.sms.endpoint.SmsEndpointAutoConfiguration \ No newline at end of file