Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/cloud-native' into cloud-native
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Sep 6, 2019
2 parents 50f8a51 + 262bc7c commit 0dad829
Show file tree
Hide file tree
Showing 62 changed files with 2,232 additions and 174 deletions.
76 changes: 60 additions & 16 deletions dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down Expand Up @@ -449,6 +459,16 @@
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down Expand Up @@ -498,6 +518,16 @@
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down Expand Up @@ -652,8 +682,15 @@
</includes>
</artifactSet>
<transformers>
<!-- dubbo-common beginning -->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.compiler.Compiler
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.compiler.Compiler
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
Expand All @@ -662,15 +699,34 @@
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.infra.InfraAdapter
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.status.StatusChecker
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.status.StatusChecker
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.threadpool.ThreadPool
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.store.DataStore
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/dubbo/internal/org.apache.dubbo.common.threadpool.ThreadPool
</resource>
</transformer>
<!-- dubbo-common end -->

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
Expand Down Expand Up @@ -754,22 +810,10 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.cache.CacheFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.store.DataStore
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.qos.command.BaseCommand
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory
</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory
</resource>
Expand Down
7 changes: 7 additions & 0 deletions dubbo-bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-redis</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-zookeeper</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.ConsumerConfig;
Expand Down Expand Up @@ -602,6 +603,11 @@ private Collection<ServiceDiscovery> getServiceDiscoveries() {
*/
@Override
public DubboBootstrap start() {

if (!shouldStart()) {
return this;
}

if (!isInitialized()) {
initialize();
}
Expand Down Expand Up @@ -632,6 +638,22 @@ public DubboBootstrap start() {
return this;
}

/**
* Should Start current bootstrap
*
* @return If there is not any service discovery registry in the {@link ConfigManager#getRegistries()}, it will not
* start current bootstrap
*/
private boolean shouldStart() {
return configManager.getRegistries()
.stream()
.map(RegistryConfig::getAddress)
.map(URL::valueOf)
.filter(UrlUtils::isServiceDiscoveryRegistryType)
.count() > 0;
}


private boolean hasExportedServices() {
return !metadataService.getExportedURLs().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void main(String[] args) throws Exception {
.application("dubbo-consumer-demo")
// Zookeeper
.protocol(builder -> builder.port(20887).name("dubbo"))
.registry("etcd3", builder -> builder.address("etcd3://127.0.0.1:2379?registry.type=service&subscribed.services=dubbo-provider-demo"))
.registry("etcd3", builder -> builder.address("etcd3://127.0.0.1:2379?registry-type=service&subscribed-services=dubbo-provider-demo"))
.metadataReport(new MetadataReportConfig("etcd://127.0.0.1:2379"))
// Nacos
// .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo").group("namespace1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void multipleRegistries() {

RegistryConfig serviceRegistry = new RegistryConfig();
serviceRegistry.setId("serviceRegistry");
serviceRegistry.setAddress("etcd3://127.0.0.1:2379?registry.type=service");
serviceRegistry.setAddress("etcd3://127.0.0.1:2379?registry-type=service");

ServiceConfig<EchoService> echoService = new ServiceConfig<>();
echoService.setInterface(EchoService.class.getName());
Expand All @@ -63,7 +63,7 @@ private static void multipleRegistries() {
// userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));

ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-provider-demo");
applicationConfig.setMetadataType("remote");
// applicationConfig.setMetadataType("remote");
new DubboBootstrap()
.application(applicationConfig)
// Zookeeper in service registry type
Expand All @@ -73,7 +73,7 @@ private static void multipleRegistries() {
.registries(Arrays.asList(interfaceRegistry, serviceRegistry))
// .registry(RegistryBuilder.newBuilder().address("consul://127.0.0.1:8500?registry.type=service").build())
.protocol(builder -> builder.port(-1).name("dubbo"))
.metadataReport(new MetadataReportConfig("etcd://127.0.0.1:2379"))
// .metadataReport(new MetadataReportConfig("etcd://127.0.0.1:2379"))
.service(echoService)
.service(userService)
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static void main(String[] args) throws Exception {
// applicationConfig.setMetadataType("remote");
new DubboBootstrap()
.application(applicationConfig)
// Zookeeper
// .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service&subscribed.services=dubbo-nacos-provider-demo"))
// .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=dubbo-nacos-provider-demo"))
.registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=service-provider"))
.metadataReport(new MetadataReportConfig("nacos://127.0.0.1:8848"))
.reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) {
.application("zookeeper-dubbo-provider")
.registry(builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service"))
.protocol("dubbo", builder -> builder.port(-1).name("dubbo"))
.protocol("rest", builder -> builder.port(8082).name("rest"))
.protocol("rest", builder -> builder.port(8081).name("rest"))
.service("echo", builder -> builder.interfaceClass(EchoService.class).ref(new EchoServiceImpl()).protocolIds("dubbo"))
.service("user", builder -> builder.interfaceClass(UserService.class).ref(new UserServiceImpl()).protocolIds("rest"))
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ protected static String getThreadPoolPrefixName(URL url) {
}

protected static int getThreadPoolSize(URL url) {
return url.getParameter(THREAD_POOL_SIZE_PARAM_NAME, DEFAULT_THREAD_POOL_SIZE);
return getParameter(url, THREAD_POOL_SIZE_PARAM_NAME, DEFAULT_THREAD_POOL_SIZE);
}

protected static long getThreadPoolKeepAliveTime(URL url) {
return url.getParameter(THREAD_POOL_KEEP_ALIVE_TIME_PARAM_NAME, DEFAULT_THREAD_POOL_KEEP_ALIVE_TIME);
return getParameter(url, THREAD_POOL_KEEP_ALIVE_TIME_PARAM_NAME, DEFAULT_THREAD_POOL_KEEP_ALIVE_TIME);
}

protected static String getParameter(URL url, String name, String defaultValue) {
Expand All @@ -202,4 +202,18 @@ protected static String getParameter(URL url, String name, String defaultValue)
}
return defaultValue;
}

protected static int getParameter(URL url, String name, int defaultValue) {
if (url != null) {
return url.getParameter(name, defaultValue);
}
return defaultValue;
}

protected static long getParameter(URL url, String name, long defaultValue) {
if (url != null) {
return url.getParameter(name, defaultValue);
}
return defaultValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;

/**
* Abstract {@link DynamicConfigurationFactory} implementation with cache ability
*
* @see DynamicConfigurationFactory
* @since 2.7.4
*/
public abstract class AbstractDynamicConfigurationFactory implements DynamicConfigurationFactory {

private volatile Map<String, DynamicConfiguration> dynamicConfigurations = new ConcurrentHashMap<>();

@Override
public DynamicConfiguration getDynamicConfiguration(URL url) {
public final DynamicConfiguration getDynamicConfiguration(URL url) {
String key = url == null ? DEFAULT_KEY : url.getAddress();
return dynamicConfigurations.computeIfAbsent(key, k -> createDynamicConfiguration(url));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ConfigChangedEvent(String key, String group, String content) {
}

public ConfigChangedEvent(String key, String group, String content, ConfigChangeType changeType) {
super(key + "=" + content);
super(key + "," + group);
this.key = key;
this.group = group;
this.content = content;
Expand All @@ -62,29 +62,29 @@ public ConfigChangeType getChangeType() {
return changeType;
}

@Override
public String toString() {
return "ConfigChangedEvent{" +
"key='" + key + '\'' +
", group='" + group + '\'' +
", content='" + content + '\'' +
", changeType=" + changeType +
"} " + super.toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ConfigChangedEvent)) return false;
ConfigChangedEvent that = (ConfigChangedEvent) o;
return Objects.equals(getKey(), that.getKey()) &&
Objects.equals(group, that.group) &&
Objects.equals(getGroup(), that.getGroup()) &&
Objects.equals(getContent(), that.getContent()) &&
getChangeType() == that.getChangeType();
}

@Override
public int hashCode() {
return Objects.hash(getKey(), group, getContent(), getChangeType());
}

@Override
public String toString() {
return "ConfigChangedEvent{" +
"key='" + key + '\'' +
", group='" + group + '\'' +
", content='" + content + '\'' +
", changeType=" + changeType +
"} " + super.toString();
return Objects.hash(getKey(), getGroup(), getContent(), getChangeType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,13 @@ private static Optional<WatchService> newWatchService() {
}

protected static File initDirectory(URL url) {
String directoryPath = url.getParameter(CONFIG_CENTER_DIR_PARAM_NAME, url.getPath());
String directoryPath = getParameter(url, CONFIG_CENTER_DIR_PARAM_NAME, url == null ? null : url.getPath());
File rootDirectory = null;
if (!StringUtils.isBlank(directoryPath)) {
rootDirectory = new File("/" + directoryPath);
}

if (!rootDirectory.exists()) { // If the directory does not exist
if (directoryPath == null || !rootDirectory.exists()) { // If the directory does not exist
rootDirectory = new File(DEFAULT_CONFIG_CENTER_DIR_PATH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ShutdownHookCallbacks {

private final List<ShutdownHookCallback> callbacks = new LinkedList<>();

public ShutdownHookCallbacks() {
ShutdownHookCallbacks() {
loadCallbacks();
}

Expand Down
Loading

0 comments on commit 0dad829

Please sign in to comment.