mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
refactor sentinel datasource and support commercialized
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public interface Constants {
|
||||
|
||||
interface Sentinel {
|
||||
String PROPERTY_PREFIX = "spring.cloud.sentinel";
|
||||
String NACOS_DATASOURCE_AK = PROPERTY_PREFIX + ".nacos.config.access-key";
|
||||
String NACOS_DATASOURCE_SK = PROPERTY_PREFIX + ".nacos.config.secret-key";
|
||||
String NACOS_DATASOURCE_NAMESPACE = PROPERTY_PREFIX + ".nacos.config.namespace";
|
||||
String NACOS_DATASOURCE_ENDPOINT = PROPERTY_PREFIX + ".nacos.config.endpoint";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String conditionalOnClass() {
|
||||
return "com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource";
|
||||
}
|
||||
|
||||
}
|
@@ -9,4 +9,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.alicloud.context.statistics.StatisticsTaskStarter
|
||||
org.springframework.context.ApplicationListener=\
|
||||
org.springframework.cloud.alicloud.context.ans.AnsContextApplicationListener,\
|
||||
org.springframework.cloud.alicloud.context.nacos.NacosParameterInitListener
|
||||
org.springframework.cloud.alicloud.context.nacos.NacosParameterInitListener,\
|
||||
org.springframework.cloud.alicloud.context.sentinel.SentinelAliCloudListener
|
Reference in New Issue
Block a user