Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dubbo cloud native #4850

Merged
merged 65 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
f51b394
Polish apache/dubbo#4542 : [Enhancement] Adapt the Java standard Even…
mercyblitz Jul 11, 2019
9e58caa
Polish apache/dubbo#4541 : [Feature] Add local File System DynamicCon…
mercyblitz Jul 15, 2019
9252be1
Polish apache#4541 : Bugfix
mercyblitz Jul 15, 2019
08089b6
Polish apache/dubbo#4541 : Optimization
mercyblitz Jul 15, 2019
cdd9338
Polish apache/dubbo#4541 : Add the compatibility for PollingWatchServ…
mercyblitz Jul 16, 2019
f0408f7
Polish apache/dubbo#4541 : Add delay publish without ThreadPoolExecutor
mercyblitz Jul 16, 2019
5f354a0
Polish apache/dubbo#4541 : Refactor the extension name
mercyblitz Jul 17, 2019
8152a75
Polish apache/dubbo#4541 : Add remove ops
mercyblitz Jul 17, 2019
df1a258
Polish apache/dubbo#4541 : Add testable constructor
mercyblitz Jul 17, 2019
52c0205
Polish apache/dubbo#4541 : Add getConfigGroups method
mercyblitz Jul 17, 2019
293a70d
Polish apache/dubbo#4610 : [Refactor] Refactor the bootstrap module
mercyblitz Jul 20, 2019
3218a1f
Polish apache/dubbo#4541 : Fix the nulling URL issue
mercyblitz Jul 20, 2019
d5c78ac
Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager
mercyblitz Jul 25, 2019
1d54a1d
Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager
mercyblitz Jul 25, 2019
5071a04
Polish apache/dubbo#4622 : Support multiple configcenters
mercyblitz Jul 26, 2019
ccf614c
Polish apache/dubbo#4671 : ServiceNameMapping will not map the group,…
mercyblitz Jul 26, 2019
87e88e2
update referenceCount log (#4683)
haiyang1985 Jul 29, 2019
5d299af
Polish /apache/dubbo#4687 : Remove the duplicated test code in dubbo-…
mercyblitz Jul 29, 2019
25ec31e
#4685 修改代码if判断false问题 if (hasException == false)修改成if (!hasException…
smipo Jul 30, 2019
c3132b8
Fixed Service annotation method parameters are not in effect (#4598)
Leishunyu Jul 31, 2019
f490df8
keep demo simple, and switch to use zookeeper as registry center (#4705)
beiwei30 Jul 31, 2019
c8dbd7d
@Reference auto-wires the instance of generic interface #4594 (#4677)
CodingSinger Jul 31, 2019
65a0140
try to shorten maven output to make travis build pass (#4710)
beiwei30 Aug 1, 2019
5b38331
use CountDownLatch to check zk registry if establish connection (#4589)
tswstarplanet Aug 1, 2019
a646874
Minor change
mercyblitz Aug 1, 2019
b8e601a
Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native
mercyblitz Aug 2, 2019
0644fe1
Rename the extension name of WritableMetadataService
mercyblitz Aug 5, 2019
9f405d7
Polish apache/dubbo#4759 : [Refactor] Change the signature of methods…
mercyblitz Aug 7, 2019
a344121
Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native
mercyblitz Aug 7, 2019
8c7f37a
Polish apache/dubbo#3984 : Add the implementation of Page<ServiceInst…
mercyblitz Aug 7, 2019
2a88323
Code merge
mercyblitz Aug 7, 2019
240c456
Code merge
mercyblitz Aug 8, 2019
391d053
Fix the cases
mercyblitz Aug 8, 2019
3e57a0a
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 8, 2019
83fc425
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 8, 2019
a147829
Refactor ConfigManager
mercyblitz Aug 12, 2019
eea35ce
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 12, 2019
e307e98
Refactor ConfigManager
mercyblitz Aug 12, 2019
f84a33d
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 12, 2019
ad3e638
Resolve the issues on ConfigManager
mercyblitz Aug 12, 2019
19f1474
Resolve conflict
mercyblitz Aug 12, 2019
07cf7b1
Refactor and add test-cases for ConfigManager
mercyblitz Aug 13, 2019
b4bf6ba
Merge branch 'cloud-native' into dubbo-cloud-native
mercyblitz Aug 13, 2019
a7088ef
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 13, 2019
df9ff69
Merge remote-tracking branch 'origin/dubbo-cloud-native' into dubbo-c…
mercyblitz Aug 13, 2019
51d2be4
Polish apache/dubbo#4774 : [Feature] Dubbo Cloud Native - To Support …
mercyblitz Aug 13, 2019
c284dad
Polish apache/dubbo#4808 : [Feature] Add the registered/unregistered …
mercyblitz Aug 13, 2019
3d84c35
Polish apache/dubbo#4807 : [Feature] Add the callback mechanism Shutd…
mercyblitz Aug 13, 2019
21bcfaa
Polish apache/dubbo#4813 : [Feature] add Prioritized implementation f…
mercyblitz Aug 13, 2019
63a315c
Polish apache/dubbo#4815 : [Feature] Add the ServiceLoader for Dubbo'…
mercyblitz Aug 14, 2019
741321c
Polish apache/dubbo#4815 : [Feature] Add the ServiceLoader for Dubbo'…
mercyblitz Aug 14, 2019
70f9de2
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 14, 2019
16c77fc
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 14, 2019
d448ab6
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 14, 2019
1ac1ad7
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 15, 2019
f67d769
Polish apache/dubbo#4813 : [Feature] add Prioritized implementation f…
mercyblitz Aug 15, 2019
b286e1d
Polish apache/dubbo#4807 : Add sort implementation
mercyblitz Aug 15, 2019
9f6e79e
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 15, 2019
0bfda83
Refactor
mercyblitz Aug 15, 2019
b5da5da
Refactor
mercyblitz Aug 16, 2019
8a7f52b
Polish apache/dubbo#4845 : [Feature] Enhance the Event-Publishing fea…
mercyblitz Aug 16, 2019
4a43d0c
Merge branch 'cloud-native' into dubbo-cloud-native
mercyblitz Aug 16, 2019
f50eed8
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 16, 2019
c70f55b
Merge remote-tracking branch 'origin/dubbo-cloud-native' into dubbo-c…
mercyblitz Aug 16, 2019
176d56b
Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud…
mercyblitz Aug 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@
import org.apache.dubbo.config.utils.ReferenceConfigCache;
import org.apache.dubbo.event.EventDispatcher;
import org.apache.dubbo.event.EventListener;
import org.apache.dubbo.event.GenericEventListener;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.MetadataServiceExporter;
import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.metadata.report.MetadataReportInstance;
import org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory;
import org.apache.dubbo.registry.client.DefaultServiceInstance;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.event.ServiceDiscoveryInitializingEvent;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -65,6 +66,7 @@
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Condition;
Expand All @@ -77,6 +79,7 @@
import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties;
import static org.apache.dubbo.common.config.configcenter.DynamicConfiguration.getDynamicConfiguration;
import static org.apache.dubbo.common.constants.CommonConstants.METADATA_REMOTE;
import static org.apache.dubbo.common.function.ThrowableAction.execute;
import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty;
import static org.apache.dubbo.config.context.ConfigManager.getInstance;
import static org.apache.dubbo.metadata.WritableMetadataService.getExtension;
Expand All @@ -88,7 +91,7 @@
*
* @since 2.7.4
*/
public class DubboBootstrap implements Lifecycle {
public class DubboBootstrap extends GenericEventListener implements Lifecycle {

public static final String DEFAULT_REGISTRY_ID = "REGISTRY#DEFAULT";

Expand Down Expand Up @@ -137,10 +140,22 @@ public class DubboBootstrap implements Lifecycle {

private volatile MetadataServiceExporter metadataServiceExporter;

private SortedSet<ServiceDiscovery> serviceDiscoveries = new ConcurrentSkipListSet<>();

public DubboBootstrap() {
DubboShutdownHook.getDubboShutdownHook().register();
}

/**
* Store the {@link ServiceDiscovery} instances into {@link ServiceDiscoveryInitializingEvent}
*
* @param event {@link ServiceDiscoveryInitializingEvent}
* @see {@linkplan org.apache.dubbo.registry.client.EventPublishingServiceDiscovery}
*/
public void onServiceDiscoveryInitializing(ServiceDiscoveryInitializingEvent event) {
serviceDiscoveries.add(event.getSource());
}

/**
* Set only register provider or not
*
Expand Down Expand Up @@ -440,6 +455,8 @@ public DubboBootstrap initialize() {

initMetadataServiceExporter();

initEventListener();

initialized = true;

if (logger.isInfoEnabled()) {
Expand All @@ -451,22 +468,74 @@ public DubboBootstrap initialize() {
return this;
}

/**
* Initialize {@link MetadataService} from {@link WritableMetadataService}'s extension
*/
private void initMetadataService() {
this.metadataService = getExtension(isDefaultMetadataStorageType());
private void startConfigCenter() {
Collection<ConfigCenterConfig> configCenters = configManager.getConfigCenters();

if (CollectionUtils.isNotEmpty(configCenters)) {
CompositeDynamicConfiguration compositeDynamicConfiguration = new CompositeDynamicConfiguration();
for (ConfigCenterConfig configCenter : configCenters) {
configCenter.refresh();
compositeDynamicConfiguration.addConfiguration(prepareEnvironment(configCenter));
}
Environment.getInstance().setDynamicConfiguration(compositeDynamicConfiguration);
}
configManager.refreshAll();
}

private void startMetadataReport() {
ApplicationConfig applicationConfig = configManager.getApplication().orElseThrow(
() -> new IllegalStateException("There's no ApplicationConfig specified.")
);

String metadataType = applicationConfig.getMetadata();
// FIXME, multiple metadata config support.
Collection<MetadataReportConfig> metadataReportConfigs = configManager.getMetadataConfigs();
if (CollectionUtils.isEmpty(metadataReportConfigs)) {
if (METADATA_REMOTE.equals(metadataType)) {
throw new IllegalStateException("No MetadataConfig found, you must specify the remote Metadata Center address when set 'metadata=remote'.");
}
return;
}
MetadataReportConfig metadataReportConfig = metadataReportConfigs.iterator().next();
if (!metadataReportConfig.isValid()) {
return;
}

MetadataReportInstance.init(metadataReportConfig.toUrl());
}

/**
* Initialize {@link MetadataServiceExporter}
* For compatibility purpose, use registry as the default config center when the registry protocol is zookeeper and
* there's no config center specified explicitly.
*/
private void initMetadataServiceExporter() {
this.metadataServiceExporter = new ConfigurableMetadataServiceExporter()
.setApplicationConfig(getApplication())
.setRegistries(configManager.getRegistries())
.setProtocols(configManager.getProtocols())
.metadataService(metadataService);
private void useRegistryAsConfigCenterIfNecessary() {
// we use the loading status of DynamicConfiguration to decide whether ConfigCenter has been initiated.
if (Environment.getInstance().getDynamicConfiguration().isPresent()) {
return;
}

if (CollectionUtils.isNotEmpty(configManager.getConfigCenters())) {
return;
}

configManager.getDefaultRegistries().stream()
.filter(registryConfig -> registryConfig.getUseAsConfigCenter() == null || registryConfig.getUseAsConfigCenter())
.forEach(registryConfig -> {
String protocol = registryConfig.getProtocol();
String id = "config-center-" + protocol + "-" + registryConfig.getPort();
ConfigCenterConfig cc = new ConfigCenterConfig();
cc.setId(id);
cc.setParameters(registryConfig.getParameters() == null ?
new HashMap<>() :
new HashMap<>(registryConfig.getParameters()));
cc.getParameters().put(CLIENT_KEY, registryConfig.getClient());
cc.setProtocol(registryConfig.getProtocol());
cc.setAddress(registryConfig.getAddress());
cc.setNamespace(registryConfig.getGroup());
cc.setHighestPriority(false);
configManager.addConfigCenter(cc);
});
startConfigCenter();
}

private void loadRemoteConfigs() {
Expand Down Expand Up @@ -503,42 +572,35 @@ private void loadRemoteConfigs() {
configManager.addProtocols(tmpProtocols);
}


/**
* For compatibility purpose, use registry as the default config center when the registry protocol is zookeeper and
* there's no config center specified explicitly.
* Initialize {@link MetadataService} from {@link WritableMetadataService}'s extension
*/
private void useRegistryAsConfigCenterIfNecessary() {
// we use the loading status of DynamicConfiguration to decide whether ConfigCenter has been initiated.
if (Environment.getInstance().getDynamicConfiguration().isPresent()) {
return;
}
private void initMetadataService() {
this.metadataService = getExtension(isDefaultMetadataStorageType());
}

if (CollectionUtils.isNotEmpty(configManager.getConfigCenters())) {
return;
}
/**
* Initialize {@link MetadataServiceExporter}
*/
private void initMetadataServiceExporter() {
this.metadataServiceExporter = new ConfigurableMetadataServiceExporter()
.setApplicationConfig(getApplication())
.setRegistries(configManager.getRegistries())
.setProtocols(configManager.getProtocols())
.metadataService(metadataService);
}

configManager.getDefaultRegistries().stream()
.filter(registryConfig -> registryConfig.getUseAsConfigCenter() == null || registryConfig.getUseAsConfigCenter())
.forEach(registryConfig -> {
String protocol = registryConfig.getProtocol();
String id = "config-center-" + protocol + "-" + registryConfig.getPort();
ConfigCenterConfig cc = new ConfigCenterConfig();
cc.setId(id);
cc.setParameters(registryConfig.getParameters() == null ?
new HashMap<>() :
new HashMap<>(registryConfig.getParameters()));
cc.getParameters().put(CLIENT_KEY, registryConfig.getClient());
cc.setProtocol(registryConfig.getProtocol());
cc.setAddress(registryConfig.getAddress());
cc.setNamespace(registryConfig.getGroup());
cc.setHighestPriority(false);
configManager.addConfigCenter(cc);
});
startConfigCenter();
/**
* Initialize {@link EventListener}
*/
private void initEventListener() {
// Add current instance into listeners
addEventListener(this);
}

private Collection<ServiceDiscovery> getServiceDiscoveries() {
return AbstractServiceDiscoveryFactory.getDiscoveries();
return serviceDiscoveries;
}

/**
Expand Down Expand Up @@ -631,8 +693,8 @@ public boolean isInitialized() {
public boolean isStarted() {
return started;
}

/* serve for builder apis, begin */

private ApplicationBuilder createApplicationBuilder(String name) {
return new ApplicationBuilder().name(name);
}
Expand Down Expand Up @@ -660,43 +722,7 @@ private ProviderBuilder createProviderBuilder(String id) {
private ConsumerBuilder createConsumerBuilder(String id) {
return new ConsumerBuilder().id(id);
}

/* serve for builder apis, end */
private void startMetadataReport() {
ApplicationConfig applicationConfig = configManager.getApplication().orElseThrow(
() -> new IllegalStateException("There's no ApplicationConfig specified.")
);

String metadataType = applicationConfig.getMetadata();
// FIXME, multiple metadata config support.
Collection<MetadataReportConfig> metadataReportConfigs = configManager.getMetadataConfigs();
if (CollectionUtils.isEmpty(metadataReportConfigs)) {
if (METADATA_REMOTE.equals(metadataType)) {
throw new IllegalStateException("No MetadataConfig found, you must specify the remote Metadata Center address when set 'metadata=remote'.");
}
return;
}
MetadataReportConfig metadataReportConfig = metadataReportConfigs.iterator().next();
if (!metadataReportConfig.isValid()) {
return;
}

MetadataReportInstance.init(metadataReportConfig.toUrl());
}

private void startConfigCenter() {
Collection<ConfigCenterConfig> configCenters = configManager.getConfigCenters();

if (CollectionUtils.isNotEmpty(configCenters)) {
CompositeDynamicConfiguration compositeDynamicConfiguration = new CompositeDynamicConfiguration();
for (ConfigCenterConfig configCenter : configCenters) {
configCenter.refresh();
compositeDynamicConfiguration.addConfiguration(prepareEnvironment(configCenter));
}
Environment.getInstance().setDynamicConfiguration(compositeDynamicConfiguration);
}
configManager.refreshAll();
}

private DynamicConfiguration prepareEnvironment(ConfigCenterConfig configCenter) {
if (configCenter.isValid()) {
Expand Down Expand Up @@ -777,7 +803,7 @@ private void registerServiceInstance() {

int port = exportedURL.getPort();

ServiceInstance serviceInstance = initServiceInstance(serviceName, host, port);
ServiceInstance serviceInstance = createServiceInstance(serviceName, host, port);

getServiceDiscoveries().forEach(serviceDiscovery -> serviceDiscovery.register(serviceInstance));
}
Expand All @@ -801,42 +827,15 @@ private URL selectMetadataServiceExportedURL() {
return selectedURL;
}

/**
* Use rest protocol if there's one, otherwise, choose the first one available.
*
* @return
*/
private String findOneProtocolForServiceInstance(Set<String> protocols) {
String result = null;
for (String protocol : protocols) {
if ("rest".equalsIgnoreCase(protocol)) {
result = protocol;
break;
}
}

if (result == null) {
for (String protocol : protocols) {
if (!"injvm".equalsIgnoreCase(protocol) && "registry".equalsIgnoreCase(protocol)) {
result = protocol;
break;
}
}
}
return result;
}

private void unregisterServiceInstance() {

if (serviceInstance != null) {
getServiceDiscoveries().forEach(serviceDiscovery -> {
serviceDiscovery.unregister(serviceInstance);
});
}

}

private ServiceInstance initServiceInstance(String serviceName, String host, int port) {
private ServiceInstance createServiceInstance(String serviceName, String host, int port) {
this.serviceInstance = new DefaultServiceInstance(serviceName, host, port);
setMetadataStorageType(serviceInstance, isDefaultMetadataStorageType());
return this.serviceInstance;
Expand All @@ -850,6 +849,8 @@ public void destroy() {

destroyReferences();

destroyServiceDiscoveries();

clear();

release();
Expand All @@ -871,8 +872,20 @@ private void destroyReferences() {
}
}

private void destroyServiceDiscoveries() {
getServiceDiscoveries().forEach(serviceDiscovery -> {
execute(() -> {
serviceDiscovery.destroy();
});
});
if (logger.isDebugEnabled()) {
logger.debug(NAME + "'s all ServiceDiscoveries have been destroyed.");
}
}

private void clear() {
clearConfigs();
clearServiceDiscoveries();
}

private void clearConfigs() {
Expand All @@ -882,6 +895,13 @@ private void clearConfigs() {
}
}

private void clearServiceDiscoveries() {
serviceDiscoveries.clear();
if (logger.isDebugEnabled()) {
logger.debug(NAME + "'s serviceDiscoveries have been clear.");
}
}

private void release() {
executeMutually(() -> {
while (awaited.compareAndSet(false, true)) {
Expand Down
Loading