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

Etcd register center #1161

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions soul-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-register-server-etcd</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,4 @@ public class AuthApplyDTO implements Serializable {
private String extInfo;

private List<String> pathList;



}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static SelectorData transFrom(final SelectorDO selectorDO, final String p
.type(selectorDO.getType())
.sort(selectorDO.getSort())
.enabled(selectorDO.getEnabled())
.loged(selectorDO.getLoged())
.logged(selectorDO.getLoged())
.continued(selectorDO.getContinued())
.handle(selectorDO.getHandle())
.conditionList(conditionDataList)
Expand Down
4 changes: 2 additions & 2 deletions soul-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ mybatis:

soul:
register:
registerType: http #zookeeper
serverLists : localhost:2181
registerType: http #http #zookeeper #etcd
serverLists : #localhost:2181 #http://localhost:2379
props:
sessionTimeout: 5000
connectionTimeout: 2000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void testOnPluginChanged() {
public void testOnSelectorChanged() {
String message = "{\"groupType\":\"SELECTOR\",\"eventType\":\"UPDATE\",\"data\":"
+ "[{\"id\":\"1336329408516136960\",\"pluginId\":\"5\",\"pluginName\":\"divide\",\"name\":"
+ "\"/http\",\"matchMode\":0,\"type\":1,\"sort\":1,\"enabled\":true,\"loged\":true,"
+ "\"/http\",\"matchMode\":0,\"type\":1,\"sort\":1,\"enabled\":true,\"logged\":true,"
+ "\"continued\":true,\"handle\":\"[{\\\\\\\"upstreamHost\\\\\\\":\\\\\\\"localhost\\\\\\\","
+ "\\\\\\\"protocol\\\\\\\":\\\\\\\"http://\\\\\\\",\\\\\\\"upstreamUrl\\\\\\\":"
+ "\\\\\\\"127.0.0.1:8187\\\\\\\",\\\\\\\"weight\\\\\\\":\\\\\\\"51\\\\\\\"},"
Expand Down Expand Up @@ -213,7 +213,7 @@ private void initSelectorDataList() {
selectorData.setHandle("[{\\\"upstreamHost\\\":\\\"localhost\\\",\\\"protocol\\\":\\\"http://\\\",\\\"upstreamUrl\\\":\\\"127.0.0.1:8187\\\","
+ "\\\"weight\\\":\\\"51\\\"},{\\\"upstreamHost\\\":\\\"localhost\\\",\\\"protocol\\\":\\\"http://\\\",\\\"upstreamUrl\\\":\\\"127.0.0.1:8188\\\",\\\"weight\\\":\\\"49\\\"}]");
selectorData.setId("1336329408516136960");
selectorData.setLoged(true);
selectorData.setLogged(true);
selectorData.setMatchMode(0);
selectorData.setName("/http");
selectorData.setPluginId("5");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private SelectorData buildSelectorData() {
.type(1)
.sort(1)
.enabled(true)
.loged(true)
.logged(true)
.continued(false)
.handle("handle")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private SelectorData buildSelectorData() {
selectorData.setContinued(true);
selectorData.setEnabled(true);
selectorData.setHandle("divide");
selectorData.setLoged(true);
selectorData.setLogged(true);
selectorData.setMatchMode(1);
selectorData.setPluginId("5");
selectorData.setName("divide");
Expand Down
5 changes: 5 additions & 0 deletions soul-client/soul-client-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@
<artifactId>soul-register-client-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-register-client-etcd</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
# limitations under the License.

http=org.dromara.soul.register.client.http.HttpClientRegisterRepository
zookeeper=org.dromara.soul.register.client.zookeeper.ZookeeperClientRegisterRepository
zookeeper=org.dromara.soul.register.client.zookeeper.ZookeeperClientRegisterRepository
etcd=org.dromara.soul.register.client.etcd.EtcdClientRegisterRepository
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dromara.soul.client.grpc.common.annotation.SoulGrpcClient;
import org.dromara.soul.client.grpc.common.dto.GrpcExt;
import org.dromara.soul.common.utils.GsonUtils;
import org.dromara.soul.common.utils.IpUtils;
import org.dromara.soul.register.client.api.SoulClientRegisterRepository;
import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
import org.dromara.soul.register.common.dto.MetaDataRegisterDTO;
Expand Down Expand Up @@ -59,6 +60,10 @@ public class GrpcClientBeanPostProcessor implements BeanPostProcessor {
private final String contextPath;

private final String ipAndPort;

private final String host;

private final int port;

/**
* Instantiates a new Soul client bean post processor.
Expand All @@ -69,11 +74,14 @@ public GrpcClientBeanPostProcessor(final SoulRegisterCenterConfig config) {
Properties props = config.getProps();
String contextPath = props.getProperty("contextPath");
String ipAndPort = props.getProperty("ipAndPort");
if (StringUtils.isEmpty(contextPath) || StringUtils.isEmpty(ipAndPort)) {
String port = props.getProperty("port");
if (StringUtils.isEmpty(contextPath) || StringUtils.isEmpty(ipAndPort) || StringUtils.isEmpty(port)) {
throw new RuntimeException("tars client must config the contextPath, ipAndPort");
}
this.ipAndPort = ipAndPort;
this.contextPath = contextPath;
this.host = props.getProperty("host");
this.port = Integer.parseInt(port);
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
Expand Down Expand Up @@ -123,6 +131,8 @@ private void handler(final Object serviceBean) {
private MetaDataRegisterDTO buildMetaDataDTO(final String packageName, final SoulGrpcClient soulGrpcClient, final Method method) {
String path = this.contextPath + soulGrpcClient.path();
String desc = soulGrpcClient.desc();
String configHost = this.host;
String host = org.apache.commons.lang3.StringUtils.isBlank(configHost) ? IpUtils.getHost() : configHost;
String configRuleName = soulGrpcClient.ruleName();
String ruleName = ("".equals(configRuleName)) ? path : configRuleName;
String methodName = method.getName();
Expand All @@ -134,6 +144,8 @@ private MetaDataRegisterDTO buildMetaDataDTO(final String packageName, final Sou
.serviceName(packageName)
.methodName(methodName)
.contextPath(contextPath)
.host(host)
.port(port)
.path(path)
.ruleName(ruleName)
.pathDesc(desc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dromara.soul.client.tars.common.annotation.SoulTarsService;
import org.dromara.soul.client.tars.common.dto.TarsRpcExt;
import org.dromara.soul.common.utils.GsonUtils;
import org.dromara.soul.common.utils.IpUtils;
import org.dromara.soul.register.client.api.SoulClientRegisterRepository;
import org.dromara.soul.register.common.config.SoulRegisterCenterConfig;
import org.dromara.soul.register.common.dto.MetaDataRegisterDTO;
Expand Down Expand Up @@ -65,16 +66,23 @@ public class TarsServiceBeanPostProcessor implements BeanPostProcessor {
private final String contextPath;

private final String ipAndPort;


private final String host;

private final int port;

public TarsServiceBeanPostProcessor(final SoulRegisterCenterConfig config) {
Properties props = config.getProps();
String contextPath = props.getProperty("contextPath");
String ipAndPort = props.getProperty("ipAndPort");
if (StringUtils.isEmpty(contextPath) || StringUtils.isEmpty(ipAndPort)) {
String port = props.getProperty("port");
if (StringUtils.isEmpty(contextPath) || StringUtils.isEmpty(ipAndPort) || StringUtils.isEmpty(port)) {
throw new RuntimeException("tars client must config the contextPath, ipAndPort");
}
this.contextPath = contextPath;
this.ipAndPort = ipAndPort;
this.host = props.getProperty("host");
this.port = Integer.parseInt(port);
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
SoulClientRegisterRepository soulClientRegisterRepository = SoulClientRegisterRepositoryFactory.newInstance(config);
publisher.start(soulClientRegisterRepository);
Expand Down Expand Up @@ -113,6 +121,8 @@ private MetaDataRegisterDTO buildMetaDataDTO(final String serviceName, final Sou
String ipAndPort = this.ipAndPort;
String path = this.contextPath + soulTarsClient.path();
String desc = soulTarsClient.desc();
String configHost = this.host;
String host = StringUtils.isBlank(configHost) ? IpUtils.getHost() : configHost;
String configRuleName = soulTarsClient.ruleName();
String ruleName = ("".equals(configRuleName)) ? path : configRuleName;
String methodName = method.getName();
Expand All @@ -125,6 +135,8 @@ private MetaDataRegisterDTO buildMetaDataDTO(final String serviceName, final Sou
.methodName(methodName)
.contextPath(this.contextPath)
.path(path)
.host(host)
.port(port)
.ruleName(ruleName)
.pathDesc(desc)
.parameterTypes(parameterTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void init() {
Properties properties = new Properties();
properties.setProperty("contextPath", "/tars");
properties.setProperty("ipAndPort", "localhost:8080");
properties.setProperty("port", "21715");

SoulRegisterCenterConfig mockRegisterCenter = new SoulRegisterCenterConfig();
mockRegisterCenter.setServerLists("http://localhost:58080");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class SelectorData implements Serializable {

private Boolean enabled;

private Boolean loged;
private Boolean logged;

private Boolean continued;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DubboTest findByIdsAndName(List<Integer> ids, String name) {
}

@Override
@SoulDubboClient(path = "/findByArrayIdsAndName")
@SoulDubboClient(path = "/findByArrayIdsAndName", desc = "findByArrayIdsAndName")
public DubboTest findByArrayIdsAndName(Integer[] ids, String name) {
DubboTest test = new DubboTest();
test.setId(Arrays.toString(ids));
Expand All @@ -50,7 +50,7 @@ public DubboTest findByArrayIdsAndName(Integer[] ids, String name) {
}

@Override
@SoulDubboClient(path = "/findByStringArray")
@SoulDubboClient(path = "/findByStringArray", desc = "findByStringArray")
public DubboTest findByStringArray(String[] ids) {
DubboTest test = new DubboTest();
test.setId(Arrays.toString(ids));
Expand All @@ -59,7 +59,7 @@ public DubboTest findByStringArray(String[] ids) {
}

@Override
@SoulDubboClient(path = "/findByListId")
@SoulDubboClient(path = "/findByListId", desc = "findByListId")
public DubboTest findByListId(List<String> ids) {
DubboTest test = new DubboTest();
test.setId(ids.toString());
Expand All @@ -68,7 +68,7 @@ public DubboTest findByListId(List<String> ids) {
}

@Override
@SoulDubboClient(path = "/batchSave")
@SoulDubboClient(path = "/batchSave", desc = "batchSave")
public DubboTest batchSave(List<DubboTest> dubboTestList) {
DubboTest test = new DubboTest();
test.setId(dubboTestList.stream().map(DubboTest::getId).collect(Collectors.joining("-")));
Expand All @@ -77,7 +77,7 @@ public DubboTest batchSave(List<DubboTest> dubboTestList) {
}

@Override
@SoulDubboClient(path = "/batchSaveAndNameAndId")
@SoulDubboClient(path = "/batchSaveAndNameAndId", desc = "batchSaveAndNameAndId")
public DubboTest batchSaveAndNameAndId(List<DubboTest> dubboTestList, String id, String name) {
DubboTest test = new DubboTest();
test.setId(id);
Expand All @@ -86,7 +86,7 @@ public DubboTest batchSaveAndNameAndId(List<DubboTest> dubboTestList, String id,
}

@Override
@SoulDubboClient(path = "/saveComplexBeanTest")
@SoulDubboClient(path = "/saveComplexBeanTest", desc = "saveComplexBeanTest")
public DubboTest saveComplexBeanTest(ComplexBeanTest complexBeanTest) {
DubboTest test = new DubboTest();
test.setId(complexBeanTest.getIdLists().toString());
Expand All @@ -95,7 +95,7 @@ public DubboTest saveComplexBeanTest(ComplexBeanTest complexBeanTest) {
}

@Override
@SoulDubboClient(path = "/saveComplexBeanTestAndName")
@SoulDubboClient(path = "/saveComplexBeanTestAndName", desc = "saveComplexBeanTestAndName")
public DubboTest saveComplexBeanTestAndName(ComplexBeanTest complexBeanTest, String name) {
DubboTest test = new DubboTest();
test.setId(complexBeanTest.getIdLists().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ spring:
allow-bean-definition-overriding: true
soul:
client:
registerType: http
serverLists: http://localhost:9095
# registerType: zookeeper
# serverLists: localhost:2181
registerType: http #http #zookeeper #etcd
serverLists: http://localhost:9095 #http:localhost:9095 #localhost:2181 #http://localhost:2379
props:
contextPath: /dubbo
appName: dubbo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class DubboMultiParamServiceImpl implements DubboMultiParamService {

@Override
@SoulDubboClient(path = "/findByIdsAndName")
@SoulDubboClient(path = "/findByIdsAndName", desc = "findByIdsAndName")
public DubboTest findByIdsAndName(List<Integer> ids, String name) {
DubboTest test = new DubboTest();
test.setId(ids.toString());
Expand All @@ -42,7 +42,7 @@ public DubboTest findByIdsAndName(List<Integer> ids, String name) {
}

@Override
@SoulDubboClient(path = "/findByArrayIdsAndName")
@SoulDubboClient(path = "/findByArrayIdsAndName", desc = "findByArrayIdsAndName")
public DubboTest findByArrayIdsAndName(Integer[] ids, String name) {
DubboTest test = new DubboTest();
test.setId(Arrays.toString(ids));
Expand All @@ -51,7 +51,7 @@ public DubboTest findByArrayIdsAndName(Integer[] ids, String name) {
}

@Override
@SoulDubboClient(path = "/findByStringArray")
@SoulDubboClient(path = "/findByStringArray", desc = "findByStringArray")
public DubboTest findByStringArray(String[] ids) {
DubboTest test = new DubboTest();
test.setId(Arrays.toString(ids));
Expand All @@ -60,7 +60,7 @@ public DubboTest findByStringArray(String[] ids) {
}

@Override
@SoulDubboClient(path = "/findByListId")
@SoulDubboClient(path = "/findByListId", desc = "findByListId")
public DubboTest findByListId(List<String> ids) {
DubboTest test = new DubboTest();
test.setId(ids.toString());
Expand All @@ -69,7 +69,7 @@ public DubboTest findByListId(List<String> ids) {
}

@Override
@SoulDubboClient(path = "/batchSave")
@SoulDubboClient(path = "/batchSave", desc = "batchSave")
public DubboTest batchSave(List<DubboTest> dubboTestList) {
DubboTest test = new DubboTest();
test.setId(dubboTestList.stream().map(DubboTest::getId).collect(Collectors.joining("-")));
Expand All @@ -78,7 +78,7 @@ public DubboTest batchSave(List<DubboTest> dubboTestList) {
}

@Override
@SoulDubboClient(path = "/batchSaveAndNameAndId")
@SoulDubboClient(path = "/batchSaveAndNameAndId", desc = "batchSaveAndNameAndId")
public DubboTest batchSaveAndNameAndId(List<DubboTest> dubboTestList, String id, String name) {
DubboTest test = new DubboTest();
test.setId(id);
Expand All @@ -87,7 +87,7 @@ public DubboTest batchSaveAndNameAndId(List<DubboTest> dubboTestList, String id,
}

@Override
@SoulDubboClient(path = "/saveComplexBeanTest")
@SoulDubboClient(path = "/saveComplexBeanTest", desc = "saveComplexBeanTest")
public DubboTest saveComplexBeanTest(ComplexBeanTest complexBeanTest) {
DubboTest test = new DubboTest();
test.setId(complexBeanTest.getIdLists().toString());
Expand All @@ -96,7 +96,7 @@ public DubboTest saveComplexBeanTest(ComplexBeanTest complexBeanTest) {
}

@Override
@SoulDubboClient(path = "/saveComplexBeanTestAndName")
@SoulDubboClient(path = "/saveComplexBeanTestAndName", desc = "saveComplexBeanTestAndName")
public DubboTest saveComplexBeanTestAndName(ComplexBeanTest complexBeanTest, String name) {
DubboTest test = new DubboTest();
test.setId(complexBeanTest.getIdLists().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ spring:

soul:
client:
registerType: http
serverLists: http://localhost:9095
# registerType: zookeeper
# serverLists: localhost:2181
registerType: http #http #zookeeper #etcd
serverLists: http://localhost:9095 #http:localhost:9095 #localhost:2181 #http://localhost:2379
props:
contextPath: /dubbo
appName: dubbo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class EchoServiceImpl extends EchoServiceGrpc.EchoServiceImplBase {

@Override
@SoulGrpcClient(path = "/echo")
@SoulGrpcClient(path = "/echo", desc = "echo")
public void echo(EchoRequest request, StreamObserver<EchoResponse> responseObserver) {
System.out.println("Received: " + request.getMessage());
EchoResponse.Builder response = EchoResponse.newBuilder()
Expand Down