-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[Feature-16300][registry] Added Consul-based Register implementation #16301
Closed
qianweisheng88892
wants to merge
4
commits into
apache:dev
from
qianweisheng88892:feat-registry-consul
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
07bc682
[Feature][Registry] Support using Consul to implement the Registry
qianweisheng88892 6322cec
[Feature][Registry] Support using Consul to implement the Registry
qianweisheng88892 472e8de
[Feature][Registry] Support using Consul to implement the Registry
qianweisheng88892 e812e99
Merge branch 'apache:dev' into feat-registry-consul
qianweisheng88892 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-consul/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Introduction | ||
|
||
This module is the consul registry plugin module, this plugin will use consul as the registry center. | ||
|
||
# How to use | ||
|
||
If you want to set the registry center as consul,you need to set the registry properties in master/worker/api's application.yml | ||
|
||
```yaml | ||
registry: | ||
type: consul | ||
url: http://localhost:8500 | ||
namespace: dolphinscheduler | ||
session-timeout: 30s | ||
session-refresh-time: 3s | ||
user-name: | ||
password: | ||
acl-token: | ||
``` | ||
|
||
After do this config, you can start your DolphinScheduler cluster, your cluster will use consul as registry center to | ||
store server metadata. |
53 changes: 53 additions & 0 deletions
53
...duler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-consul/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-registry-plugins</artifactId> | ||
<version>dev-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dolphinscheduler-registry-consul</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-registry-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-common</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-registry-it</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.orbitz.consul</groupId> | ||
<artifactId>consul-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
112 changes: 112 additions & 0 deletions
112
...ava/org/apache/dolphinscheduler/plugin/registry/consul/ConsulConnectionStateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.dolphinscheduler.plugin.registry.consul; | ||
|
||
import org.apache.dolphinscheduler.registry.api.ConnectionListener; | ||
import org.apache.dolphinscheduler.registry.api.ConnectionState; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import com.orbitz.consul.Consul; | ||
|
||
public class ConsulConnectionStateListener implements AutoCloseable { | ||
|
||
private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>()); | ||
// A thread pool that periodically obtains connection status | ||
private final ScheduledExecutorService scheduledExecutorService; | ||
// monitored client | ||
private final Consul consulClient; | ||
// The state of the last monitor | ||
private volatile ConnectionState connectionState; | ||
|
||
public ConsulConnectionStateListener(Consul consulClient) { | ||
this.consulClient = consulClient; | ||
this.scheduledExecutorService = Executors.newScheduledThreadPool( | ||
1, | ||
new ThreadFactoryBuilder().setNameFormat("ConsulConnectionStateListenerThread") | ||
.setDaemon(true).build()); | ||
} | ||
|
||
public void addConnectionListener(ConnectionListener connectionListener) { | ||
connectionListeners.add(connectionListener); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
connectionListeners.clear(); | ||
scheduledExecutorService.shutdownNow(); | ||
} | ||
|
||
/** | ||
* Apply for a lease through the client, if there is no exception, the connection is normal | ||
* @return the current connection state | ||
* @throws if there is an exception, return is DISCONNECTED | ||
*/ | ||
private ConnectionState currentConnectivityState() { | ||
try { | ||
consulClient.agentClient().ping(); | ||
return ConnectionState.CONNECTED; | ||
} catch (Exception e) { | ||
return ConnectionState.DISCONNECTED; | ||
} | ||
} | ||
|
||
/** | ||
* Periodically execute thread to get connection status | ||
*/ | ||
public void start() { | ||
long initialDelay = 500L; | ||
long delay = 500L; | ||
this.scheduledExecutorService.scheduleWithFixedDelay(() -> { | ||
ConnectionState currentConnectionState = currentConnectivityState(); | ||
if (currentConnectionState == connectionState) { | ||
return; | ||
} | ||
if (connectionState == ConnectionState.CONNECTED) { | ||
if (currentConnectionState == ConnectionState.DISCONNECTED) { | ||
connectionState = ConnectionState.DISCONNECTED; | ||
triggerListener(ConnectionState.DISCONNECTED); | ||
} | ||
} else if (connectionState == ConnectionState.DISCONNECTED) { | ||
if (currentConnectionState == ConnectionState.CONNECTED) { | ||
connectionState = ConnectionState.CONNECTED; | ||
triggerListener(ConnectionState.RECONNECTED); | ||
} | ||
} else if (connectionState == null) { | ||
connectionState = currentConnectionState; | ||
triggerListener(connectionState); | ||
} | ||
}, | ||
initialDelay, | ||
delay, | ||
TimeUnit.MILLISECONDS); | ||
} | ||
|
||
// notify all listeners | ||
private void triggerListener(ConnectionState connectionState) { | ||
for (ConnectionListener connectionListener : connectionListeners) { | ||
connectionListener.onUpdate(connectionState); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 to this.
Since we already have multiple registry plugins, add a new one registry plugin is not a urgent need.
And this repo has been archived. https://github.com/rickfast/consul-client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1