mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.sentinel;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.cloud.alicloud.context.Constants;
|
||||
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public class SentinelAliCloudListener
|
||||
extends AbstractOnceApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(SentinelAliCloudListener.class);
|
||||
|
||||
@Override
|
||||
protected void handleEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
|
||||
.getEdasChangeOrderConfiguration();
|
||||
logger.info("Sentinel Nacos datasource will"
|
||||
+ (edasChangeOrderConfiguration.isEdasManaged() ? " be " : " not be ")
|
||||
+ "changed by edas change order.");
|
||||
if (!edasChangeOrderConfiguration.isEdasManaged()) {
|
||||
return;
|
||||
}
|
||||
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_ENDPOINT,
|
||||
edasChangeOrderConfiguration.getAddressServerDomain());
|
||||
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_NAMESPACE,
|
||||
edasChangeOrderConfiguration.getTenantId());
|
||||
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_AK,
|
||||
edasChangeOrderConfiguration.getDauthAccessKey());
|
||||
System.getProperties().setProperty(Constants.Sentinel.NACOS_DATASOURCE_SK,
|
||||
edasChangeOrderConfiguration.getDauthSecretKey());
|
||||
System.getProperties().setProperty(Constants.Sentinel.PROJECT_NAME,
|
||||
edasChangeOrderConfiguration.getProjectName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String conditionalOnClass() {
|
||||
return "com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource";
|
||||
}
|
||||
|
||||
}
|
@@ -11,5 +11,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.context.ApplicationListener=\
|
||||
org.springframework.cloud.alicloud.context.ans.AnsContextApplicationListener,\
|
||||
org.springframework.cloud.alicloud.context.nacos.NacosConfigParameterInitListener,\
|
||||
org.springframework.cloud.alicloud.context.nacos.NacosDiscoveryParameterInitListener,\
|
||||
org.springframework.cloud.alicloud.context.sentinel.SentinelAliCloudListener
|
||||
org.springframework.cloud.alicloud.context.nacos.NacosDiscoveryParameterInitListener
|
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.sentinel;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
|
||||
import org.springframework.cloud.alicloud.context.Constants;
|
||||
import org.springframework.cloud.alicloud.utils.ChangeOrderUtils;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @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");
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user