From bd1690b3b625c0923b9a400df0ad4d477c299955 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Tue, 9 Apr 2024 20:26:02 +0800 Subject: [PATCH 01/22] runtime tcp http grpc client impl --- eventmesh-dashboard-core/pom.xml | 18 +++ .../core/function/SDK/SDKManager.java | 5 + .../SDK/config/CreateRuntimeConfig.java | 74 ++++++++++++ .../SDK/operation/NacosSDKOperation.java | 5 +- .../RuntimeGrpcConsumerSDKOperation.java | 54 +++++++++ .../RuntimeGrpcProducerSDKOperation.java | 53 +++++++++ .../RuntimeHttpConsumerSDKOperation.java | 53 +++++++++ .../RuntimeHttpProducerSDKOperation.java | 53 +++++++++ .../SDK/operation/RuntimeSDKOperation.java | 100 +++++++++++++++- .../RuntimeTcpCloudEventSDKOperation.java | 62 ++++++++++ .../RuntimeTcpEventMeshSDKOperation.java | 62 ++++++++++ .../RuntimeTcpOpenMessageSDKOperation.java | 57 ++++++++++ .../SDK/util/RuntimeSDKOperationUtils.java | 107 ++++++++++++++++++ .../function/SDK/wrapper/NacosSDKWrapper.java | 2 + .../SDK/wrapper/RuntimeSDKWrapper.java | 52 +++++++++ .../RuntimeGrpcConsumerSDKOperationTest.java | 28 +++++ .../RuntimeGrpcProducerSDKOperationTest.java | 28 +++++ .../RuntimeHttpConsumerSDKOperationTest.java | 34 ++++++ .../RuntimeHttpProducerSDKOperationTest.java | 34 ++++++ .../operation/RuntimeSDKOperationTest.java | 45 ++++++++ .../RuntimeTcpCloudEventSDKOperationTest.java | 47 ++++++++ .../RuntimeTcpEventMeshSDKOperationTest.java | 46 ++++++++ ...RuntimeTcpOpenMessageSDKOperationTest.java | 15 +++ 23 files changed, 1028 insertions(+), 6 deletions(-) create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperation.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/util/RuntimeSDKOperationUtils.java create mode 100644 eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java create mode 100644 eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index 64d6dff9..c80b6f33 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -52,6 +52,18 @@ 0.0.1-SNAPSHOT + + + org.apache.eventmesh + eventmesh-sdk-java + 1.10.0-release + + + org.apache.eventmesh + eventmesh-common + 1.10.0-release + + com.alibaba.nacos @@ -62,6 +74,12 @@ io.etcd jetcd-core 0.3.0 + + + io.grpc + grpc-core + + diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java index a203ff30..74ddd475 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java @@ -114,4 +114,9 @@ public void deleteClient(SDKTypeEnum clientTypeEnum, String uniqueKey) { public Object getClient(SDKTypeEnum clientTypeEnum, String uniqueKey) { return this.clientMap.get(clientTypeEnum).get(uniqueKey); } + + // get all client + public Map getClients(SDKTypeEnum clientTypeEnum) { + return this.clientMap.get(clientTypeEnum); + } } diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java new file mode 100644 index 00000000..cf4b6a21 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java @@ -0,0 +1,74 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.config; + +import org.apache.eventmesh.common.protocol.tcp.UserAgent; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CreateRuntimeConfig implements CreateSDKConfig { + + // 127.0.0.1:10105;127.0.0.2:10105 + private String runtimeServerAddress; + + // protocol example:HTTP,TCP,GRPC + private String protocol; + // for tcp:cloudevents,eventmeshmessage,openmessage + private String protocolName; + + // producer or consumer + private String clientType; + + // topic + private String topic; + + // grpc subscriptionItem + // private SubscriptionMode mode; + // private SubscriptionType type; + + // config + private String env; + private String idc; + private String ip; + private String sys; + private String pid; + private String username; + private String password; + + // producer + private String producerGroup; + + // consumer + private String consumerGroup; + private String subUrl; + + // Agent + private UserAgent userAgent; + + @Override + public String getUniqueKey() { + return runtimeServerAddress; + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosSDKOperation.java index c3651f6c..ba78cbb3 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosSDKOperation.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/NacosSDKOperation.java @@ -22,6 +22,7 @@ import org.apache.eventmesh.dashboard.core.function.SDK.wrapper.NacosSDKWrapper; import java.util.AbstractMap.SimpleEntry; +import java.util.Objects; import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.naming.NamingService; @@ -34,8 +35,8 @@ public class NacosSDKOperation extends AbstractSDKOperation { @Override public SimpleEntry createClient(CreateSDKConfig createClientConfig) { SimpleEntry configSimpleEntry = nacosConfigClientCreateOperation.createClient(createClientConfig); - SimpleEntry namingSimpleEntry = nacosNamingClientCreateOperation.createClient(createClientConfig); - if (configSimpleEntry.getKey() != namingSimpleEntry.getKey()) { + SimpleEntry namingSimpleEntry = nacosNamingClientCreateOperation.createClient(createClientConfig); + if (!Objects.equals(configSimpleEntry.getKey(), namingSimpleEntry.getKey())) { throw new RuntimeException("Nacos config and naming server address not match"); } NacosSDKWrapper nacosClient = new NacosSDKWrapper( diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperation.java new file mode 100644 index 00000000..63e26a3b --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperation.java @@ -0,0 +1,54 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshGrpcConsumerConfig; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.consumer.EventMeshGrpcConsumer; +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeGrpcConsumerSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + final EventMeshGrpcClientConfig grpcClientConfig = buildEventMeshGrpcConsumerConfig(runtimeConfig); + EventMeshGrpcConsumer grpcConsumer = null; + try { + grpcConsumer = new EventMeshGrpcConsumer(grpcClientConfig); + grpcConsumer.init(); + } catch (EventMeshException e) { + log.error("create runtime grpc Consumer client failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), grpcConsumer); + } + + @Override + public void close(Object client) { + castClient(client).close(); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperation.java new file mode 100644 index 00000000..2c46a6b8 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperation.java @@ -0,0 +1,53 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshGrpcProducerConfig; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeGrpcProducerSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + final EventMeshGrpcClientConfig grpcClientConfig = buildEventMeshGrpcProducerConfig(runtimeConfig); + EventMeshGrpcProducer grpcProducer = null; + try { + grpcProducer = new EventMeshGrpcProducer(grpcClientConfig); + } catch (EventMeshException e) { + log.error("create runtime grpc Producer client failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), grpcProducer); + } + + @Override + public void close(Object client) { + castClient(client).close(); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperation.java new file mode 100644 index 00000000..e6c026af --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperation.java @@ -0,0 +1,53 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshHttpConsumerConfig; + +import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; +import org.apache.eventmesh.client.http.consumer.EventMeshHttpConsumer; +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeHttpConsumerSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + final EventMeshHttpClientConfig httpClientConfig = buildEventMeshHttpConsumerConfig(runtimeConfig); + EventMeshHttpConsumer httpConsumer = null; + try { + httpConsumer = new EventMeshHttpConsumer(httpClientConfig); + } catch (EventMeshException e) { + log.error("create runtime http Consumer client failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), httpConsumer); + } + + @Override + public void close(Object client) { + castClient(client).close(); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperation.java new file mode 100644 index 00000000..79071c7d --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperation.java @@ -0,0 +1,53 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshHttpProducerConfig; + +import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; +import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeHttpProducerSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + final EventMeshHttpClientConfig httpClientConfig = buildEventMeshHttpProducerConfig(runtimeConfig); + EventMeshHttpProducer httpProducer = null; + try { + httpProducer = new EventMeshHttpProducer(httpClientConfig); + } catch (EventMeshException e) { + log.error("create runtime http Producer client failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), httpProducer); + } + + @Override + public void close(Object client) { + castClient(client).close(); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperation.java index d630bc09..8ef5b81f 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperation.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperation.java @@ -17,19 +17,111 @@ package org.apache.eventmesh.dashboard.core.function.SDK.operation; +import org.apache.eventmesh.client.grpc.consumer.EventMeshGrpcConsumer; +import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; +import org.apache.eventmesh.client.http.consumer.EventMeshHttpConsumer; +import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; +import org.apache.eventmesh.client.tcp.impl.cloudevent.CloudEventTCPClient; +import org.apache.eventmesh.client.tcp.impl.eventmeshmessage.EventMeshMessageTCPClient; +import org.apache.eventmesh.client.tcp.impl.openmessage.OpenMessageTCPClient; +import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.wrapper.RuntimeSDKWrapper; import java.util.AbstractMap.SimpleEntry; -public class RuntimeSDKOperation extends AbstractSDKOperation { +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeSDKOperation extends AbstractSDKOperation { + + private final RuntimeTcpCloudEventSDKOperation tcpCloudEventSDKOperation = new RuntimeTcpCloudEventSDKOperation(); + private final RuntimeTcpEventMeshSDKOperation tcpEventMeshSDKOperation = new RuntimeTcpEventMeshSDKOperation(); + private final RuntimeTcpOpenMessageSDKOperation tcpOpenMessageSDKOperation = new RuntimeTcpOpenMessageSDKOperation(); + + private final RuntimeHttpProducerSDKOperation httpProducerSDKOperation = new RuntimeHttpProducerSDKOperation(); + private final RuntimeHttpConsumerSDKOperation httpConsumerSDKOperation = new RuntimeHttpConsumerSDKOperation(); + + private final RuntimeGrpcProducerSDKOperation grpcProducerSDKOperation = new RuntimeGrpcProducerSDKOperation(); + private final RuntimeGrpcConsumerSDKOperation grpcConsumerSDKOperation = new RuntimeGrpcConsumerSDKOperation(); + @Override - public SimpleEntry createClient(CreateSDKConfig clientConfig) { - return null; + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + final String protocol = ((CreateRuntimeConfig) clientConfig).getProtocol(); + final String protocolName = ((CreateRuntimeConfig) clientConfig).getProtocolName(); + final String clientType = ((CreateRuntimeConfig) clientConfig).getClientType(); + + SimpleEntry cloudSimpleEntry = null; + SimpleEntry eventMeshMessageSimpleEntry = null; + SimpleEntry openMessageSimpleEntry = null; + + SimpleEntry httpProducerSimpleEntry = null; + SimpleEntry httpConsumerSimpleEntry = null; + + SimpleEntry grpcProducerSimpleEntry = null; + SimpleEntry grpcConsumerSimpleEntry = null; + + switch (protocol) { + case Constants.TCP: + switch (protocolName) { + case Constants.CLOUD_EVENTS_PROTOCOL_NAME: + cloudSimpleEntry = tcpCloudEventSDKOperation.createClient(runtimeConfig); + break; + case Constants.EM_MESSAGE_PROTOCOL_NAME: + eventMeshMessageSimpleEntry = tcpEventMeshSDKOperation.createClient(runtimeConfig); + break; + case Constants.OPEN_MESSAGE_PROTOCOL_NAME: + openMessageSimpleEntry = tcpOpenMessageSDKOperation.createClient(runtimeConfig); + break; + default: + break; + } + break; + case Constants.HTTP: + switch (clientType) { + case "producer": + httpProducerSimpleEntry = httpProducerSDKOperation.createClient(runtimeConfig); + break; + case "consumer": + httpConsumerSimpleEntry = httpConsumerSDKOperation.createClient(runtimeConfig); + break; + default: + break; + } + break; + case Constants.GRPC: + switch (clientType) { + case "producer": + grpcProducerSimpleEntry = grpcProducerSDKOperation.createClient(runtimeConfig); + break; + case "consumer": + grpcConsumerSimpleEntry = grpcConsumerSDKOperation.createClient(runtimeConfig); + break; + default: + break; + } + break; + default: + log.warn("clients that do not support the current protocol"); + break; + } + RuntimeSDKWrapper runtimeClient = new RuntimeSDKWrapper( + cloudSimpleEntry != null ? cloudSimpleEntry.getValue() : null, + eventMeshMessageSimpleEntry != null ? eventMeshMessageSimpleEntry.getValue() : null, + openMessageSimpleEntry != null ? openMessageSimpleEntry.getValue() : null, + httpProducerSimpleEntry != null ? httpProducerSimpleEntry.getValue() : null, + httpConsumerSimpleEntry != null ? httpConsumerSimpleEntry.getValue() : null, + grpcProducerSimpleEntry != null ? grpcProducerSimpleEntry.getValue() : null, + grpcConsumerSimpleEntry != null ? grpcConsumerSimpleEntry.getValue() : null + ); + return new SimpleEntry<>(clientConfig.getUniqueKey(), runtimeClient); } @Override public void close(Object client) { - + castClient(client).close(); } } diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperation.java new file mode 100644 index 00000000..e097e2c9 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperation.java @@ -0,0 +1,62 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshTCPClientConfig; +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildUserAgent; + +import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.client.tcp.impl.cloudevent.CloudEventTCPClient; +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeTcpCloudEventSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + CloudEventTCPClient cloudEventTCPClient = null; + try { + final UserAgent userAgent = buildUserAgent(runtimeConfig.getUserAgent()); + final EventMeshTCPClientConfig eventMeshTCPClientConfig = buildEventMeshTCPClientConfig( + runtimeConfig.getRuntimeServerAddress(), userAgent); + cloudEventTCPClient = new CloudEventTCPClient(eventMeshTCPClientConfig); + cloudEventTCPClient.init(); + } catch (EventMeshException e) { + log.error("create runtime CloudEvent tcp client failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), cloudEventTCPClient); + } + + @Override + public void close(Object client) { + try { + castClient(client).close(); + } catch (Exception e) { + log.error("close eventmesh runtime tcp client failed"); + } + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperation.java new file mode 100644 index 00000000..45f71526 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperation.java @@ -0,0 +1,62 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshTCPClientConfig; +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildUserAgent; + +import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.client.tcp.impl.eventmeshmessage.EventMeshMessageTCPClient; +import org.apache.eventmesh.common.exception.EventMeshException; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap.SimpleEntry; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeTcpEventMeshSDKOperation extends AbstractSDKOperation { + + @Override + public SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + EventMeshMessageTCPClient eventMeshTCPClient = null; + try { + UserAgent userAgent = buildUserAgent(runtimeConfig.getUserAgent()); + final EventMeshTCPClientConfig eventMeshTCPClientConfig = buildEventMeshTCPClientConfig( + runtimeConfig.getRuntimeServerAddress(), userAgent); + eventMeshTCPClient = new EventMeshMessageTCPClient(eventMeshTCPClientConfig); + eventMeshTCPClient.init(); + } catch (EventMeshException e) { + log.error("create runtime EventMeshMessage tcp client failed", e); + } + return new SimpleEntry<>(clientConfig.getUniqueKey(), eventMeshTCPClient); + } + + @Override + public void close(Object client) { + try { + castClient(client).close(); + } catch (Exception e) { + log.error("EventMeshMessage client close failed", e); + } + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperation.java new file mode 100644 index 00000000..0a281068 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperation.java @@ -0,0 +1,57 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; + +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildEventMeshTCPClientConfig; +import static org.apache.eventmesh.dashboard.core.function.SDK.util.RuntimeSDKOperationUtils.buildUserAgent; + +import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.client.tcp.impl.openmessage.OpenMessageTCPClient; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.AbstractSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; + +import java.util.AbstractMap; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeTcpOpenMessageSDKOperation extends AbstractSDKOperation { + + @Override + public AbstractMap.SimpleEntry createClient(CreateSDKConfig clientConfig) { + final CreateRuntimeConfig runtimeConfig = (CreateRuntimeConfig) clientConfig; + OpenMessageTCPClient openMessageTCPClient = null; + try { + UserAgent userAgent = buildUserAgent(runtimeConfig.getUserAgent()); + final EventMeshTCPClientConfig eventMeshTCPClientConfig = buildEventMeshTCPClientConfig( + runtimeConfig.getRuntimeServerAddress(), userAgent); + openMessageTCPClient = new OpenMessageTCPClient(eventMeshTCPClientConfig); + openMessageTCPClient.init(); + } catch (Exception e) { + log.error("create runtime eventmesh OpenMessage client failed", e); + } + return new AbstractMap.SimpleEntry<>(clientConfig.getUniqueKey(), openMessageTCPClient); + } + + @Override + public void close(Object client) { + castClient(client).close(); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/util/RuntimeSDKOperationUtils.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/util/RuntimeSDKOperationUtils.java new file mode 100644 index 00000000..435949cd --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/util/RuntimeSDKOperationUtils.java @@ -0,0 +1,107 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.util; + +import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig; +import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; +import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +public class RuntimeSDKOperationUtils { + + public static EventMeshTCPClientConfig buildEventMeshTCPClientConfig(String serverAddress, UserAgent userAgent) { + String clientHost = serverAddress.split(":")[0]; + int clientPort = Integer.parseInt(serverAddress.split(":")[1]); + return EventMeshTCPClientConfig.builder() + .host(clientHost) + .port(clientPort) + .userAgent(userAgent) + .build(); + } + + public static UserAgent buildUserAgent(UserAgent userAgent) { + return UserAgent.builder() + .host(userAgent.getHost()) + .subsystem(userAgent.getSubsystem()) + .port(userAgent.getPort()) + .group(userAgent.getGroup()) + .idc(userAgent.getIdc()) + .env(userAgent.getPassword()) + .pid(userAgent.getPid()) + .path(userAgent.getPath()) + .username(userAgent.getUsername()) + .password(userAgent.getPassword()) + .version(userAgent.getVersion()) + .purpose(userAgent.getPurpose()) + .build(); + } + + public static EventMeshHttpClientConfig buildEventMeshHttpConsumerConfig(CreateRuntimeConfig runtimeConfig) { + return EventMeshHttpClientConfig.builder() + .liteEventMeshAddr(runtimeConfig.getRuntimeServerAddress()) + .consumerGroup(runtimeConfig.getConsumerGroup()) + .sys(runtimeConfig.getSys()) + .env(runtimeConfig.getEnv()) + .idc(runtimeConfig.getIdc()) + .ip(runtimeConfig.getIp()) + .pid(runtimeConfig.getPid()) + .build(); + } + + public static EventMeshHttpClientConfig buildEventMeshHttpProducerConfig(CreateRuntimeConfig runtimeConfig) { + return EventMeshHttpClientConfig.builder() + .liteEventMeshAddr(runtimeConfig.getRuntimeServerAddress()) + .producerGroup(runtimeConfig.getProducerGroup()) + .env(runtimeConfig.getEnv()) + .idc(runtimeConfig.getIdc()) + .sys(runtimeConfig.getSys()) + .pid(runtimeConfig.getPid()) + .userName(runtimeConfig.getUsername()) + .password(runtimeConfig.getPassword()) + .build(); + } + + public static EventMeshGrpcClientConfig buildEventMeshGrpcConsumerConfig(CreateRuntimeConfig runtimeConfig) { + final String grpcServerAddress = runtimeConfig.getRuntimeServerAddress(); + String clientHost = grpcServerAddress.split(":")[0]; + int clientPort = Integer.parseInt(grpcServerAddress.split(":")[1]); + return EventMeshGrpcClientConfig.builder() + .serverAddr(clientHost) + .serverPort(clientPort) + .consumerGroup(runtimeConfig.getConsumerGroup()) + .env(runtimeConfig.getEnv()) + .idc(runtimeConfig.getIdc()) + .sys(runtimeConfig.getSys()) + .build(); + } + + public static EventMeshGrpcClientConfig buildEventMeshGrpcProducerConfig(CreateRuntimeConfig runtimeConfig) { + final String grpcServerAddress = runtimeConfig.getRuntimeServerAddress(); + String clientHost = grpcServerAddress.split(":")[0]; + int clientPort = Integer.parseInt(grpcServerAddress.split(":")[1]); + return EventMeshGrpcClientConfig.builder() + .serverAddr(clientHost) + .serverPort(clientPort) + .producerGroup(runtimeConfig.getProducerGroup()) + .env(runtimeConfig.getEnv()) + .idc(runtimeConfig.getIdc()) + .sys(runtimeConfig.getSys()) + .build(); + } +} diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/NacosSDKWrapper.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/NacosSDKWrapper.java index a0c0858a..60f9022d 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/NacosSDKWrapper.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/NacosSDKWrapper.java @@ -22,7 +22,9 @@ import com.alibaba.nacos.api.naming.NamingService; import lombok.AllArgsConstructor; +import lombok.Data; +@Data @AllArgsConstructor public class NacosSDKWrapper { diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java new file mode 100644 index 00000000..45bfb0e8 --- /dev/null +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java @@ -0,0 +1,52 @@ + +package org.apache.eventmesh.dashboard.core.function.SDK.wrapper; + +import org.apache.eventmesh.client.grpc.consumer.EventMeshGrpcConsumer; +import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; +import org.apache.eventmesh.client.http.consumer.EventMeshHttpConsumer; +import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; +import org.apache.eventmesh.client.tcp.impl.cloudevent.CloudEventTCPClient; +import org.apache.eventmesh.client.tcp.impl.eventmeshmessage.EventMeshMessageTCPClient; +import org.apache.eventmesh.client.tcp.impl.openmessage.OpenMessageTCPClient; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class RuntimeSDKWrapper { + + private CloudEventTCPClient tcpCloudEventClient; + private EventMeshMessageTCPClient tcpEventMeshClient; + private OpenMessageTCPClient openMessageTCPClient; + + private EventMeshHttpProducer httpProducerClient; + private EventMeshHttpConsumer httpConsumerClient; + + private EventMeshGrpcProducer grpcProducerClient; + private EventMeshGrpcConsumer grpcConsumerClient; + + public void close() { + try { + if (tcpCloudEventClient != null) { + tcpCloudEventClient.close(); + } else if (tcpEventMeshClient != null) { + tcpEventMeshClient.close(); + } else if (openMessageTCPClient != null) { + openMessageTCPClient.close(); + } else if (httpProducerClient != null) { + httpProducerClient.close(); + } else if (httpConsumerClient != null) { + httpConsumerClient.close(); + } else if (grpcProducerClient != null) { + grpcProducerClient.close(); + } else if (grpcConsumerClient != null) { + grpcConsumerClient.close(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java new file mode 100644 index 00000000..0c7141ac --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java @@ -0,0 +1,28 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.grpc.consumer.EventMeshGrpcConsumer; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +import java.util.AbstractMap; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class RuntimeGrpcConsumerSDKOperationTest { + + private final RuntimeGrpcConsumerSDKOperation grpcConsumerSDKOperation = new RuntimeGrpcConsumerSDKOperation(); + + @Test + void testCreateClient() { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10205") + .consumerGroup("EventMeshTest-consumerGroup") + .env("test") + .idc("idc") + .sys("1234") + .build(); + final AbstractMap.SimpleEntry grpcConsumerSimpleEntry = + grpcConsumerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10205", grpcConsumerSimpleEntry.getKey()); + } +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java new file mode 100644 index 00000000..6f655db1 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java @@ -0,0 +1,28 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +import java.util.AbstractMap; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class RuntimeGrpcProducerSDKOperationTest { + + private final RuntimeGrpcProducerSDKOperation grpcProducerSDKOperation = new RuntimeGrpcProducerSDKOperation(); + + @Test + void testCreateClient() { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10205") + .producerGroup("EventMeshTest-producerGroup") + .env("test") + .idc("idc") + .sys("1234") + .build(); + final AbstractMap.SimpleEntry grpcProducerSimpleEntry = + grpcProducerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10205", grpcProducerSimpleEntry.getKey()); + } +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java new file mode 100644 index 00000000..4c3eb530 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java @@ -0,0 +1,34 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.http.consumer.EventMeshHttpConsumer; +import org.apache.eventmesh.common.utils.IPUtils; +import org.apache.eventmesh.common.utils.ThreadUtils; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +import java.util.AbstractMap; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class RuntimeHttpConsumerSDKOperationTest { + + private final RuntimeHttpConsumerSDKOperation httpConsumerSDKOperation = new RuntimeHttpConsumerSDKOperation(); + + @Test + void testCreateClient() { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10105") + .consumerGroup("EventMeshTest-consumerGroup") + .env("test") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())) + .username("eventmesh") + .password("123456") + .build(); + final AbstractMap.SimpleEntry httpConsumerSimpleEntry = + httpConsumerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10105", httpConsumerSimpleEntry.getKey()); + } +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java new file mode 100644 index 00000000..08ad3f67 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java @@ -0,0 +1,34 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; +import org.apache.eventmesh.common.utils.IPUtils; +import org.apache.eventmesh.common.utils.ThreadUtils; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +import java.util.AbstractMap; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class RuntimeHttpProducerSDKOperationTest { + + private final RuntimeHttpProducerSDKOperation httpProducerSDKOperation = new RuntimeHttpProducerSDKOperation(); + + @Test + void testCreateClient() { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10105") + .producerGroup("EventMeshTest-producerGroup") + .env("test") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())) + .username("eventmesh") + .password("123456") + .build(); + final AbstractMap.SimpleEntry httpProducerSimpleEntry = + httpProducerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10105", httpProducerSimpleEntry.getKey()); + } +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java new file mode 100644 index 00000000..04b0b8e8 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java @@ -0,0 +1,45 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; +import org.apache.eventmesh.dashboard.core.function.SDK.wrapper.RuntimeSDKWrapper; + +import java.util.AbstractMap; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class RuntimeSDKOperationTest { + + private final RuntimeSDKOperation runtimeSDKOperation = new RuntimeSDKOperation(); + + @Test + void testCreateClient() { + final UserAgent userAgent = UserAgent.builder() + .env("test") + .host("localhost") + .password("123456") + .username("eventmesh") + .group("EventmeshTestGroup") + .path("/") + .port(8366) + .subsystem("502") + .pid(32894) + .version("2.1") + .idc("A") + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10000") + .protocol("TCP") + .protocolName(Constants.EM_MESSAGE_PROTOCOL_NAME) + .userAgent(userAgent) + .build(); + final AbstractMap.SimpleEntry sdkWrapperSimpleEntry = + runtimeSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10000", sdkWrapperSimpleEntry.getKey()); + Assertions.assertNotNull(sdkWrapperSimpleEntry.getValue().getTcpEventMeshClient()); + } +} \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java new file mode 100644 index 00000000..68963f7f --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java @@ -0,0 +1,47 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.client.tcp.impl.cloudevent.CloudEventTCPClient; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +import java.util.AbstractMap.SimpleEntry; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeTcpCloudEventSDKOperationTest { + + private final RuntimeTcpCloudEventSDKOperation runtimeTCPPushSDKOperation = new RuntimeTcpCloudEventSDKOperation(); + + @Test + void testCreateClient() { + final UserAgent userAgent = UserAgent.builder() + .env("test") + .host("localhost") + .password("123456") + .username("eventmesh") + .group("EventmeshTestGroup") + .path("/") + .port(8366) + .subsystem("502") + .pid(32894) + .version("2.1") + .idc("A") + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); + log.info("{}", userAgent); + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10000") + .userAgent(userAgent) + .build(); + log.info("{}", runtimeConfig); + final SimpleEntry simpleEntry = + runtimeTCPPushSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + } + +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java new file mode 100644 index 00000000..f9e972a0 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java @@ -0,0 +1,46 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + +import org.apache.eventmesh.client.tcp.common.EventMeshCommon; +import org.apache.eventmesh.client.tcp.impl.eventmeshmessage.EventMeshMessageTCPClient; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; + +import java.util.AbstractMap.SimpleEntry; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeTcpEventMeshSDKOperationTest { + + private final RuntimeTcpEventMeshSDKOperation eventMeshSDKOperation = new RuntimeTcpEventMeshSDKOperation(); + + @Test + void testCreateClient() { + final UserAgent userAgent = UserAgent.builder() + .env("test") + .host("localhost") + .password("123456") + .username("eventmesh") + .group("EventmeshTestGroup") + .path("/") + .port(8365) + .subsystem("501") + .pid(32893) + .version("2.1") + .idc("A") + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); + log.info("userAgent {}", userAgent); + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10000") + .userAgent(userAgent) + .build(); + log.info("{}", runtimeConfig); + final SimpleEntry simpleEntry = + eventMeshSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + } +} diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java new file mode 100644 index 00000000..6762c521 --- /dev/null +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java @@ -0,0 +1,15 @@ +package org.apache.eventmesh.dashboard.core.function.SDK.operation; + + +import org.junit.jupiter.api.Test; + +public class RuntimeTcpOpenMessageSDKOperationTest { + + private final RuntimeTcpOpenMessageSDKOperation tcpOpenMessageSDKOperation = new RuntimeTcpOpenMessageSDKOperation(); + + @Test + void testCreateClient() { + // todo no impl + } + +} From f5b5816a78bed236f1aafec954b5bc865a6826c0 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Tue, 9 Apr 2024 20:48:17 +0800 Subject: [PATCH 02/22] check --- .../core/function/SDK/SDKManager.java | 19 +++++++++++++++++ .../core/function/SDK/SDKTypeEnum.java | 12 +++++++++++ .../RuntimeGrpcConsumerSDKOperationTest.java | 21 +++++++++++++++++-- .../RuntimeGrpcProducerSDKOperationTest.java | 21 +++++++++++++++++-- .../RuntimeHttpConsumerSDKOperationTest.java | 21 +++++++++++++++++-- .../RuntimeHttpProducerSDKOperationTest.java | 21 +++++++++++++++++-- .../operation/RuntimeSDKOperationTest.java | 21 +++++++++++++++++-- .../RuntimeTcpCloudEventSDKOperationTest.java | 17 +++++++++++++++ .../RuntimeTcpEventMeshSDKOperationTest.java | 17 +++++++++++++++ ...RuntimeTcpOpenMessageSDKOperationTest.java | 17 +++++++++++++++ 10 files changed, 177 insertions(+), 10 deletions(-) diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java index 74ddd475..a84274b4 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java @@ -26,6 +26,14 @@ import org.apache.eventmesh.dashboard.core.function.SDK.operation.RocketMQProduceSDKOperation; import org.apache.eventmesh.dashboard.core.function.SDK.operation.RocketMQPushConsumerSDKOperation; import org.apache.eventmesh.dashboard.core.function.SDK.operation.RocketMQRemotingSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeGrpcConsumerSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeGrpcProducerSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeHttpConsumerSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeHttpProducerSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeTcpCloudEventSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeTcpEventMeshSDKOperation; +import org.apache.eventmesh.dashboard.core.function.SDK.operation.RuntimeTcpOpenMessageSDKOperation; import java.util.AbstractMap.SimpleEntry; import java.util.Map; @@ -73,6 +81,17 @@ public static SDKManager getInstance() { clientCreateOperationMap.put(SDKTypeEnum.META_ETCD, new EtcdSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_EVENTMESH_CLIENT, new RuntimeSDKOperation()); + + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_TCP_CLOUDEVENT_CLIENT, new RuntimeTcpCloudEventSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_TCP_EVENTMESH_CLIENT, new RuntimeTcpEventMeshSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_TCP_OPENMESSAGE_CLIENT, new RuntimeTcpOpenMessageSDKOperation()); + + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_HTTP_PRODUCER, new RuntimeHttpProducerSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_HTTP_CONSUMER, new RuntimeHttpConsumerSDKOperation()); + + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_GRPC_PRODUCER, new RuntimeGrpcProducerSDKOperation()); + clientCreateOperationMap.put(SDKTypeEnum.RUNTIME_GRPC_CONSUMER, new RuntimeGrpcConsumerSDKOperation()); } private SDKManager() { diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKTypeEnum.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKTypeEnum.java index c6524c8e..b10cde9f 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKTypeEnum.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKTypeEnum.java @@ -35,4 +35,16 @@ public enum SDKTypeEnum { META_NACOS_NAMING, META_ETCD, + + RUNTIME_EVENTMESH_CLIENT, + + RUNTIME_TCP_CLOUDEVENT_CLIENT, + RUNTIME_TCP_EVENTMESH_CLIENT, + RUNTIME_TCP_OPENMESSAGE_CLIENT, + + RUNTIME_HTTP_PRODUCER, + RUNTIME_HTTP_CONSUMER, + + RUNTIME_GRPC_PRODUCER, + RUNTIME_GRPC_CONSUMER, } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java index 0c7141ac..ff58b0a5 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java @@ -1,9 +1,26 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.grpc.consumer.EventMeshGrpcConsumer; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; -import java.util.AbstractMap; +import java.util.AbstractMap.SimpleEntry; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -21,7 +38,7 @@ void testCreateClient() { .idc("idc") .sys("1234") .build(); - final AbstractMap.SimpleEntry grpcConsumerSimpleEntry = + final SimpleEntry grpcConsumerSimpleEntry = grpcConsumerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10205", grpcConsumerSimpleEntry.getKey()); } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java index 6f655db1..0d3db925 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java @@ -1,9 +1,26 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.grpc.producer.EventMeshGrpcProducer; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; -import java.util.AbstractMap; +import java.util.AbstractMap.SimpleEntry; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -21,7 +38,7 @@ void testCreateClient() { .idc("idc") .sys("1234") .build(); - final AbstractMap.SimpleEntry grpcProducerSimpleEntry = + final SimpleEntry grpcProducerSimpleEntry = grpcProducerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10205", grpcProducerSimpleEntry.getKey()); } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java index 4c3eb530..17f2ddde 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java @@ -1,3 +1,20 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.http.consumer.EventMeshHttpConsumer; @@ -5,7 +22,7 @@ import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; -import java.util.AbstractMap; +import java.util.AbstractMap.SimpleEntry; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -27,7 +44,7 @@ void testCreateClient() { .username("eventmesh") .password("123456") .build(); - final AbstractMap.SimpleEntry httpConsumerSimpleEntry = + final SimpleEntry httpConsumerSimpleEntry = httpConsumerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10105", httpConsumerSimpleEntry.getKey()); } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java index 08ad3f67..07d16408 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java @@ -1,3 +1,20 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; @@ -5,7 +22,7 @@ import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; -import java.util.AbstractMap; +import java.util.AbstractMap.SimpleEntry; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -27,7 +44,7 @@ void testCreateClient() { .username("eventmesh") .password("123456") .build(); - final AbstractMap.SimpleEntry httpProducerSimpleEntry = + final SimpleEntry httpProducerSimpleEntry = httpProducerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10105", httpProducerSimpleEntry.getKey()); } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java index 04b0b8e8..f496382b 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java @@ -1,3 +1,20 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; @@ -6,7 +23,7 @@ import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRuntimeConfig; import org.apache.eventmesh.dashboard.core.function.SDK.wrapper.RuntimeSDKWrapper; -import java.util.AbstractMap; +import java.util.AbstractMap.SimpleEntry; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -37,7 +54,7 @@ void testCreateClient() { .protocolName(Constants.EM_MESSAGE_PROTOCOL_NAME) .userAgent(userAgent) .build(); - final AbstractMap.SimpleEntry sdkWrapperSimpleEntry = + final SimpleEntry sdkWrapperSimpleEntry = runtimeSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10000", sdkWrapperSimpleEntry.getKey()); Assertions.assertNotNull(sdkWrapperSimpleEntry.getValue().getTcpEventMeshClient()); diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java index 68963f7f..26ed222e 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java @@ -1,3 +1,20 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java index f9e972a0..ba6c3ea9 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java @@ -1,3 +1,20 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java index 6762c521..64300e04 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpOpenMessageSDKOperationTest.java @@ -1,3 +1,20 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.operation; From e34aa8c5e3c5e3cacf23d1e0f7b4d34e816e0dc1 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Tue, 9 Apr 2024 20:49:30 +0800 Subject: [PATCH 03/22] check --- .../core/function/SDK/config/CreateRuntimeConfig.java | 4 ---- .../core/function/SDK/operation/EtcdSDKOperation.java | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java index cf4b6a21..7ddfc805 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRuntimeConfig.java @@ -44,10 +44,6 @@ public class CreateRuntimeConfig implements CreateSDKConfig { // topic private String topic; - // grpc subscriptionItem - // private SubscriptionMode mode; - // private SubscriptionType type; - // config private String env; private String idc; diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java index b630a38b..7206dad0 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java @@ -48,7 +48,7 @@ public SimpleEntry createClient(CreateSDKConfig clientConfig) { } private static String[] getSplitEndpoints(CreateEtcdConfig etcdConfig) { - return etcdConfig.getEtcdServerAddress().split(","); + return etcdConfig.getEtcdServerAddress().split(";"); } @Override From 76bc678e31f9942f125f7f8afd6d34484ab707db Mon Sep 17 00:00:00 2001 From: Alonexc <91315508+Alonexc@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:00:21 +0800 Subject: [PATCH 04/22] check --- eventmesh-dashboard-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index c31bdab4..597327c0 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -62,7 +62,7 @@ org.apache.eventmesh eventmesh-common 1.10.0-release - @@ -139,4 +139,4 @@ test - \ No newline at end of file + From e80b40231e23a51355403c1fb9568b28e4a7cfa2 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Tue, 9 Apr 2024 21:04:24 +0800 Subject: [PATCH 05/22] check --- .../function/SDK/wrapper/RuntimeSDKWrapper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java index 45bfb0e8..6ac403b9 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java @@ -1,3 +1,19 @@ +/* + * 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.eventmesh.dashboard.core.function.SDK.wrapper; From 9c8da49854667a6a08e1cc91cfafc7b6aed857bf Mon Sep 17 00:00:00 2001 From: Alonexc Date: Tue, 9 Apr 2024 21:21:39 +0800 Subject: [PATCH 06/22] check --- eventmesh-dashboard-core/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index 597327c0..d783a4f5 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -62,6 +62,12 @@ org.apache.eventmesh eventmesh-common 1.10.0-release + + + org.apache.logging.log4j + log4j-slf4j-impl + + From d0043b5eba7f52a75ddd1eeb3fa0f9fe8878ba09 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Tue, 9 Apr 2024 21:28:37 +0800 Subject: [PATCH 07/22] check --- .../core/function/SDK/operation/EtcdSDKCreateOperationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java index a4d8f4be..5315a1ef 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java @@ -42,7 +42,7 @@ public class EtcdSDKCreateOperationTest { private static final String value = "test"; - private static final String url = "http://127.0.0.1:2379"; + private static final String url = "http://locaholst:2379"; @Test void testCreateClient() { From baa202d94015085ecdda63bfb06257da364d42cc Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 09:01:50 +0800 Subject: [PATCH 08/22] check --- eventmesh-dashboard-core/pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index d783a4f5..68c168d0 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -58,17 +58,6 @@ eventmesh-sdk-java 1.10.0-release - - org.apache.eventmesh - eventmesh-common - 1.10.0-release - - - org.apache.logging.log4j - log4j-slf4j-impl - - - From 46c796fbf27953d802cc55c71d33e9a3d3451ab9 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 09:07:36 +0800 Subject: [PATCH 09/22] check --- eventmesh-dashboard-core/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index 68c168d0..5bcb9cdc 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -57,6 +57,12 @@ org.apache.eventmesh eventmesh-sdk-java 1.10.0-release + + + org.apache.logging.log4j + log4j-slf4j-impl + + From bf33cad569190a11f0c4657073cc48b70c873078 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 10:52:05 +0800 Subject: [PATCH 10/22] Upgrade the grpc version. --- eventmesh-dashboard-core/pom.xml | 34 ++++++++++++++----- .../operation/EtcdSDKCreateOperationTest.java | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index 5bcb9cdc..28a36098 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -40,6 +40,18 @@ + + + io.grpc + grpc-all + 1.51.0 + + + com.google.guava + guava + 32.1.3-jre + + org.apache.eventmesh.dashboard.common @@ -52,6 +64,12 @@ 0.0.1-SNAPSHOT + + + + + + org.apache.eventmesh @@ -64,7 +82,13 @@ - + + + + + + + com.alibaba.nacos @@ -74,13 +98,7 @@ io.etcd jetcd-core - 0.3.0 - - - io.grpc - grpc-core - - + 0.7.5 diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java index 5315a1ef..8baf5f74 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java @@ -42,7 +42,7 @@ public class EtcdSDKCreateOperationTest { private static final String value = "test"; - private static final String url = "http://locaholst:2379"; + private static final String url = "http://localhost:2379"; @Test void testCreateClient() { From 7b1d72efdfdf38e410b67dddc6f57f310435af2a Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 10:57:11 +0800 Subject: [PATCH 11/22] check --- eventmesh-dashboard-core/pom.xml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/eventmesh-dashboard-core/pom.xml b/eventmesh-dashboard-core/pom.xml index 28a36098..9f3a19ca 100644 --- a/eventmesh-dashboard-core/pom.xml +++ b/eventmesh-dashboard-core/pom.xml @@ -46,6 +46,7 @@ grpc-all 1.51.0 + com.google.guava guava @@ -64,12 +65,6 @@ 0.0.1-SNAPSHOT - - - - - - org.apache.eventmesh @@ -83,12 +78,6 @@ - - - - - - com.alibaba.nacos From 51dc35967d8a1772aabd9bd71e7b54316157f774 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 15:46:46 +0800 Subject: [PATCH 12/22] check --- .../RuntimeGrpcConsumerSDKOperationTest.java | 30 ++++++---- .../RuntimeGrpcProducerSDKOperationTest.java | 30 ++++++---- .../RuntimeHttpConsumerSDKOperationTest.java | 38 +++++++----- .../RuntimeHttpProducerSDKOperationTest.java | 38 +++++++----- .../operation/RuntimeSDKOperationTest.java | 58 +++++++++++-------- .../RuntimeTcpCloudEventSDKOperationTest.java | 54 +++++++++-------- .../RuntimeTcpEventMeshSDKOperationTest.java | 53 +++++++++-------- 7 files changed, 182 insertions(+), 119 deletions(-) diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java index ff58b0a5..198fe023 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java @@ -25,21 +25,31 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class RuntimeGrpcConsumerSDKOperationTest { private final RuntimeGrpcConsumerSDKOperation grpcConsumerSDKOperation = new RuntimeGrpcConsumerSDKOperation(); @Test void testCreateClient() { - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10205") - .consumerGroup("EventMeshTest-consumerGroup") - .env("test") - .idc("idc") - .sys("1234") - .build(); - final SimpleEntry grpcConsumerSimpleEntry = - grpcConsumerSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10205", grpcConsumerSimpleEntry.getKey()); + SimpleEntry grpcConsumerSimpleEntry = null; + try { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10205") + .consumerGroup("EventMeshTest-consumerGroup") + .env("test") + .idc("idc") + .sys("1234") + .build(); + grpcConsumerSimpleEntry = grpcConsumerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10205", grpcConsumerSimpleEntry.getKey()); + } catch (Exception e) { + log.error("create runtime GRPC consumer client failed", e); + if (grpcConsumerSimpleEntry != null) { + grpcConsumerSimpleEntry.getValue().close(); + } + } } } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java index 0d3db925..33ba467a 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java @@ -25,21 +25,31 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class RuntimeGrpcProducerSDKOperationTest { private final RuntimeGrpcProducerSDKOperation grpcProducerSDKOperation = new RuntimeGrpcProducerSDKOperation(); @Test void testCreateClient() { - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10205") - .producerGroup("EventMeshTest-producerGroup") - .env("test") - .idc("idc") - .sys("1234") - .build(); - final SimpleEntry grpcProducerSimpleEntry = - grpcProducerSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10205", grpcProducerSimpleEntry.getKey()); + SimpleEntry grpcProducerSimpleEntry = null; + try { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10205") + .producerGroup("EventMeshTest-producerGroup") + .env("test") + .idc("idc") + .sys("1234") + .build(); + grpcProducerSimpleEntry = grpcProducerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10205", grpcProducerSimpleEntry.getKey()); + } catch (Exception e) { + log.error("create runtime GRPC producer client failed", e); + if (grpcProducerSimpleEntry != null) { + grpcProducerSimpleEntry.getValue().close(); + } + } } } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java index 17f2ddde..a721deb0 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java @@ -27,25 +27,35 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class RuntimeHttpConsumerSDKOperationTest { private final RuntimeHttpConsumerSDKOperation httpConsumerSDKOperation = new RuntimeHttpConsumerSDKOperation(); @Test void testCreateClient() { - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10105") - .consumerGroup("EventMeshTest-consumerGroup") - .env("test") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())) - .username("eventmesh") - .password("123456") - .build(); - final SimpleEntry httpConsumerSimpleEntry = - httpConsumerSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10105", httpConsumerSimpleEntry.getKey()); + SimpleEntry httpConsumerSimpleEntry = null; + try { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10105") + .consumerGroup("EventMeshTest-consumerGroup") + .env("test") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())) + .username("eventmesh") + .password("123456") + .build(); + httpConsumerSimpleEntry = httpConsumerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10105", httpConsumerSimpleEntry.getKey()); + } catch (Exception e) { + log.error("create runtime GRPC consumer client failed", e); + if (httpConsumerSimpleEntry != null) { + httpConsumerSimpleEntry.getValue().close(); + } + } } } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java index 07d16408..217f1f28 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java @@ -27,25 +27,35 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class RuntimeHttpProducerSDKOperationTest { private final RuntimeHttpProducerSDKOperation httpProducerSDKOperation = new RuntimeHttpProducerSDKOperation(); @Test void testCreateClient() { - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10105") - .producerGroup("EventMeshTest-producerGroup") - .env("test") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())) - .username("eventmesh") - .password("123456") - .build(); - final SimpleEntry httpProducerSimpleEntry = - httpProducerSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10105", httpProducerSimpleEntry.getKey()); + SimpleEntry httpProducerSimpleEntry = null; + try { + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10105") + .producerGroup("EventMeshTest-producerGroup") + .env("test") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())) + .username("eventmesh") + .password("123456") + .build(); + httpProducerSimpleEntry = httpProducerSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10105", httpProducerSimpleEntry.getKey()); + } catch (Exception e) { + log.error("create runtime EventMesh HTTP producer client failed", e); + if (httpProducerSimpleEntry != null) { + httpProducerSimpleEntry.getValue().close(); + } + } } } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java index f496382b..b24fd054 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java @@ -28,35 +28,45 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import lombok.extern.slf4j.Slf4j; + +@Slf4j class RuntimeSDKOperationTest { private final RuntimeSDKOperation runtimeSDKOperation = new RuntimeSDKOperation(); @Test void testCreateClient() { - final UserAgent userAgent = UserAgent.builder() - .env("test") - .host("localhost") - .password("123456") - .username("eventmesh") - .group("EventmeshTestGroup") - .path("/") - .port(8366) - .subsystem("502") - .pid(32894) - .version("2.1") - .idc("A") - .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) - .build(); - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10000") - .protocol("TCP") - .protocolName(Constants.EM_MESSAGE_PROTOCOL_NAME) - .userAgent(userAgent) - .build(); - final SimpleEntry sdkWrapperSimpleEntry = - runtimeSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10000", sdkWrapperSimpleEntry.getKey()); - Assertions.assertNotNull(sdkWrapperSimpleEntry.getValue().getTcpEventMeshClient()); + SimpleEntry sdkWrapperSimpleEntry = null; + try { + final UserAgent userAgent = UserAgent.builder() + .env("test") + .host("localhost") + .password("123456") + .username("eventmesh") + .group("EventmeshTestGroup") + .path("/") + .port(8366) + .subsystem("502") + .pid(32894) + .version("2.1") + .idc("A") + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10000") + .protocol("TCP") + .protocolName(Constants.EM_MESSAGE_PROTOCOL_NAME) + .userAgent(userAgent) + .build(); + sdkWrapperSimpleEntry = runtimeSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10000", sdkWrapperSimpleEntry.getKey()); + Assertions.assertNotNull(sdkWrapperSimpleEntry.getValue().getTcpEventMeshClient()); + } catch (Exception e) { + log.error("create runtime client failed", e); + if (sdkWrapperSimpleEntry != null) { + sdkWrapperSimpleEntry.getValue().close(); + } + } } } \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java index 26ed222e..534e2ce7 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java @@ -36,29 +36,35 @@ public class RuntimeTcpCloudEventSDKOperationTest { @Test void testCreateClient() { - final UserAgent userAgent = UserAgent.builder() - .env("test") - .host("localhost") - .password("123456") - .username("eventmesh") - .group("EventmeshTestGroup") - .path("/") - .port(8366) - .subsystem("502") - .pid(32894) - .version("2.1") - .idc("A") - .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) - .build(); - log.info("{}", userAgent); - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10000") - .userAgent(userAgent) - .build(); - log.info("{}", runtimeConfig); - final SimpleEntry simpleEntry = - runtimeTCPPushSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + SimpleEntry simpleEntry = null; + try { + final UserAgent userAgent = UserAgent.builder() + .env("test") + .host("localhost") + .password("123456") + .username("eventmesh") + .group("EventmeshTestGroup") + .path("/") + .port(8366) + .subsystem("502") + .pid(32894) + .version("2.1") + .idc("A") + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); + log.info("{}", userAgent); + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10000") + .userAgent(userAgent) + .build(); + log.info("{}", runtimeConfig); + simpleEntry = runtimeTCPPushSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + } catch (Exception e) { + log.error("create runtime tcp CloudEvent client failed", e); + if (simpleEntry != null) { + simpleEntry.getValue().close(); + } + } } - } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java index ba6c3ea9..1e977928 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java @@ -36,28 +36,35 @@ public class RuntimeTcpEventMeshSDKOperationTest { @Test void testCreateClient() { - final UserAgent userAgent = UserAgent.builder() - .env("test") - .host("localhost") - .password("123456") - .username("eventmesh") - .group("EventmeshTestGroup") - .path("/") - .port(8365) - .subsystem("501") - .pid(32893) - .version("2.1") - .idc("A") - .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) - .build(); - log.info("userAgent {}", userAgent); - final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() - .runtimeServerAddress("127.0.0.1:10000") - .userAgent(userAgent) - .build(); - log.info("{}", runtimeConfig); - final SimpleEntry simpleEntry = - eventMeshSDKOperation.createClient(runtimeConfig); - Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + SimpleEntry simpleEntry = null; + try { + final UserAgent userAgent = UserAgent.builder() + .env("test") + .host("localhost") + .password("123456") + .username("eventmesh") + .group("EventmeshTestGroup") + .path("/") + .port(8365) + .subsystem("501") + .pid(32893) + .version("2.1") + .idc("A") + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); + log.info("userAgent {}", userAgent); + final CreateRuntimeConfig runtimeConfig = CreateRuntimeConfig.builder() + .runtimeServerAddress("127.0.0.1:10000") + .userAgent(userAgent) + .build(); + log.info("{}", runtimeConfig); + simpleEntry = eventMeshSDKOperation.createClient(runtimeConfig); + Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + } catch (Exception e) { + log.error("create runtime tcp EventMeshMessage client failed", e); + if (simpleEntry != null) { + simpleEntry.getValue().close(); + } + } } } From 202fede8dceb8f16ea4370034ace271ed180d390 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 17:04:19 +0800 Subject: [PATCH 13/22] ci try-catch --- .github/workflows/ci.yml | 2 ++ .../core/function/SDK/wrapper/RuntimeSDKWrapper.java | 7 +++++-- .../SDK/operation/RedisSDKCreateOperationTest.java | 8 ++++++-- .../operation/RuntimeGrpcConsumerSDKOperationTest.java | 1 + .../operation/RuntimeGrpcProducerSDKOperationTest.java | 1 + .../operation/RuntimeHttpConsumerSDKOperationTest.java | 1 + .../operation/RuntimeHttpProducerSDKOperationTest.java | 1 + .../function/SDK/operation/RuntimeSDKOperationTest.java | 1 + .../operation/RuntimeTcpCloudEventSDKOperationTest.java | 1 + .../operation/RuntimeTcpEventMeshSDKOperationTest.java | 1 + 10 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aac6fa1f..5b5f712d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,8 @@ name: "Continuous Integration" on: push: branches: [ '**' ] + paths-ignore: + - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' pull_request: branches: [ '**' ] diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java index 6ac403b9..9e6370b3 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/wrapper/RuntimeSDKWrapper.java @@ -24,14 +24,17 @@ import org.apache.eventmesh.client.tcp.impl.cloudevent.CloudEventTCPClient; import org.apache.eventmesh.client.tcp.impl.eventmeshmessage.EventMeshMessageTCPClient; import org.apache.eventmesh.client.tcp.impl.openmessage.OpenMessageTCPClient; +import org.apache.eventmesh.common.exception.EventMeshException; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; @Data @AllArgsConstructor @NoArgsConstructor +@Slf4j public class RuntimeSDKWrapper { private CloudEventTCPClient tcpCloudEventClient; @@ -61,8 +64,8 @@ public void close() { } else if (grpcConsumerClient != null) { grpcConsumerClient.close(); } - } catch (Exception e) { - throw new RuntimeException(e); + } catch (EventMeshException e) { + log.error("runtime client close failed", e); } } } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java index ec90f29c..7ccb2efc 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java @@ -38,14 +38,18 @@ class RedisSDKCreateOperationTest { void testCreateClient() { CreateRedisConfig createClientConfig = new CreateRedisConfig(); createClientConfig.setRedisUrl("redis://localhost:6379"); + SimpleEntry> simpleEntry = null; try { - SimpleEntry> simpleEntry = redisClientCreateOperation.createClient(createClientConfig); + simpleEntry = redisClientCreateOperation.createClient(createClientConfig); assertEquals("redis://localhost:6379", simpleEntry.getKey()); String response = simpleEntry.getValue().sync().ping(); log.info("response:{}", response); + simpleEntry.getValue().close(); } catch (Exception e) { log.error("create redis client failed", e); + if (simpleEntry != null) { + simpleEntry.getValue().close(); + } } - } } \ No newline at end of file diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java index 198fe023..a3869a67 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcConsumerSDKOperationTest.java @@ -45,6 +45,7 @@ void testCreateClient() { .build(); grpcConsumerSimpleEntry = grpcConsumerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10205", grpcConsumerSimpleEntry.getKey()); + grpcConsumerSimpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime GRPC consumer client failed", e); if (grpcConsumerSimpleEntry != null) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java index 33ba467a..f593f2f4 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeGrpcProducerSDKOperationTest.java @@ -45,6 +45,7 @@ void testCreateClient() { .build(); grpcProducerSimpleEntry = grpcProducerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10205", grpcProducerSimpleEntry.getKey()); + grpcProducerSimpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime GRPC producer client failed", e); if (grpcProducerSimpleEntry != null) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java index a721deb0..0d129697 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpConsumerSDKOperationTest.java @@ -51,6 +51,7 @@ void testCreateClient() { .build(); httpConsumerSimpleEntry = httpConsumerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10105", httpConsumerSimpleEntry.getKey()); + httpConsumerSimpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime GRPC consumer client failed", e); if (httpConsumerSimpleEntry != null) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java index 217f1f28..1407214b 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeHttpProducerSDKOperationTest.java @@ -51,6 +51,7 @@ void testCreateClient() { .build(); httpProducerSimpleEntry = httpProducerSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10105", httpProducerSimpleEntry.getKey()); + httpProducerSimpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime EventMesh HTTP producer client failed", e); if (httpProducerSimpleEntry != null) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java index b24fd054..8f8d2099 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeSDKOperationTest.java @@ -62,6 +62,7 @@ void testCreateClient() { sdkWrapperSimpleEntry = runtimeSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10000", sdkWrapperSimpleEntry.getKey()); Assertions.assertNotNull(sdkWrapperSimpleEntry.getValue().getTcpEventMeshClient()); + sdkWrapperSimpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime client failed", e); if (sdkWrapperSimpleEntry != null) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java index 534e2ce7..ca43b48a 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpCloudEventSDKOperationTest.java @@ -60,6 +60,7 @@ void testCreateClient() { log.info("{}", runtimeConfig); simpleEntry = runtimeTCPPushSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + simpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime tcp CloudEvent client failed", e); if (simpleEntry != null) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java index 1e977928..733d39ed 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RuntimeTcpEventMeshSDKOperationTest.java @@ -60,6 +60,7 @@ void testCreateClient() { log.info("{}", runtimeConfig); simpleEntry = eventMeshSDKOperation.createClient(runtimeConfig); Assertions.assertEquals("127.0.0.1:10000", simpleEntry.getKey()); + simpleEntry.getValue().close(); } catch (Exception e) { log.error("create runtime tcp EventMeshMessage client failed", e); if (simpleEntry != null) { From e12f946e1efdab566243e64247eda597c2203d72 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 17:07:27 +0800 Subject: [PATCH 14/22] ci try-catch --- .../function/SDK/operation/EtcdSDKCreateOperationTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java index 8baf5f74..a71718e3 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java @@ -48,8 +48,9 @@ public class EtcdSDKCreateOperationTest { void testCreateClient() { final CreateEtcdConfig etcdConfig = new CreateEtcdConfig(); etcdConfig.setEtcdServerAddress(url); + SimpleEntry simpleEntry = null; try { - final SimpleEntry simpleEntry = etcdSDKOperation.createClient(etcdConfig); + simpleEntry = etcdSDKOperation.createClient(etcdConfig); Assertions.assertEquals(url, simpleEntry.getKey()); simpleEntry.getValue().put(bytesOf(key), bytesOf(value)); final GetResponse response = simpleEntry.getValue().get(bytesOf(key)).get(); @@ -57,8 +58,12 @@ void testCreateClient() { log.info("get key = {} , value = {} from etcd success", keyValues.get(0).getKey().toString(StandardCharsets.UTF_8), keyValues.get(0).getValue().toString(StandardCharsets.UTF_8)); + simpleEntry.getValue().close(); } catch (Exception e) { log.error("create etcd client failed", e); + if (simpleEntry != null) { + simpleEntry.getValue().close(); + } } } From 28b43acc4cf8c7a7066aaaa89be27c4912534e55 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 19:49:14 +0800 Subject: [PATCH 15/22] redis client update --- .../function/SDK/config/CreateRedisConfig.java | 10 ++++++++++ .../function/SDK/operation/RedisSDKOperation.java | 15 +++++++++++++-- .../operation/RedisSDKCreateOperationTest.java | 10 +++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java index a4577491..ec23c483 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java @@ -17,13 +17,23 @@ package org.apache.eventmesh.dashboard.core.function.SDK.config; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor public class CreateRedisConfig implements CreateSDKConfig { private String redisUrl; + private String password; + + private Integer timeOut; + @Override public String getUniqueKey() { return redisUrl; diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java index 5fd3d4f1..1717f54d 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java @@ -21,17 +21,28 @@ import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateRedisConfig; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; +import java.time.Duration; import java.util.AbstractMap.SimpleEntry; import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisURI; import io.lettuce.core.api.StatefulRedisConnection; public class RedisSDKOperation extends AbstractSDKOperation> { @Override public SimpleEntry> createClient(CreateSDKConfig clientConfig) { - String redisUrl = ((CreateRedisConfig) clientConfig).getRedisUrl(); - RedisClient redisClient = RedisClient.create(redisUrl); + CreateRedisConfig redisConfig = (CreateRedisConfig) clientConfig; + String redisUrl = redisConfig.getRedisUrl(); + String clientHost = redisUrl.split(":")[0]; + int clientPort = Integer.parseInt(redisUrl.split(":")[1]); + RedisURI redisURI = RedisURI.builder() + .withHost(clientHost) + .withPort(clientPort) + .withPassword(redisConfig.getPassword()) + .withTimeout(Duration.ofSeconds(redisConfig.getTimeOut())) + .build(); + RedisClient redisClient = RedisClient.create(redisURI); return new SimpleEntry<>(clientConfig.getUniqueKey(), redisClient.connect()); } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java index 7ccb2efc..050c6b07 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java @@ -36,12 +36,16 @@ class RedisSDKCreateOperationTest { @Test void testCreateClient() { - CreateRedisConfig createClientConfig = new CreateRedisConfig(); - createClientConfig.setRedisUrl("redis://localhost:6379"); + CreateRedisConfig createClientConfig = CreateRedisConfig.builder() + .redisUrl("localhost:6379") + .password("") + .timeOut(5) + .build(); + // createClientConfig.setRedisUrl("redis://localhost:6379"); SimpleEntry> simpleEntry = null; try { simpleEntry = redisClientCreateOperation.createClient(createClientConfig); - assertEquals("redis://localhost:6379", simpleEntry.getKey()); + assertEquals("localhost:6379", simpleEntry.getKey()); String response = simpleEntry.getValue().sync().ping(); log.info("response:{}", response); simpleEntry.getValue().close(); From 0cee8a427a243a738f2b9bfdb4237dc6eeff517c Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 19:53:07 +0800 Subject: [PATCH 16/22] redis client update --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b5f712d..aac6fa1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,6 @@ name: "Continuous Integration" on: push: branches: [ '**' ] - paths-ignore: - - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' pull_request: branches: [ '**' ] From 64b8d9fa9280e0d008589c225e6dedee051c78ee Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 20:06:12 +0800 Subject: [PATCH 17/22] redis client test --- .../dashboard/core/function/SDK/SDKManagerTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java index 7d9008f8..e936696b 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManagerTest.java @@ -30,13 +30,17 @@ @Slf4j class SDKManagerTest { - private final CreateRedisConfig createRedisConfig = new CreateRedisConfig(); private String redisKey; @BeforeEach void setUp() { try { - createRedisConfig.setRedisUrl("redis://localhost:6379"); + CreateRedisConfig createRedisConfig = CreateRedisConfig.builder() + .redisUrl("localhost:6379") + .password("") + .timeOut(30) + .build(); + // createRedisConfig.setRedisUrl("redis://localhost:6379"); redisKey = SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, createRedisConfig).getKey(); } catch (Exception e) { log.warn("SDK manager test init failed, possible reason: redis-server is offline. {}", this.getClass().getSimpleName(), e); From 6bed1aefa43e5c93ca2ff95fca9b83529ca404d2 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 20:10:04 +0800 Subject: [PATCH 18/22] ci --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aac6fa1f..96651db1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,8 @@ name: "Continuous Integration" on: push: + paths-ignore: + - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' branches: [ '**' ] pull_request: branches: [ '**' ] From 466ada3db0ff985955d0d8dc49352135614d68bf Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 20:29:20 +0800 Subject: [PATCH 19/22] ci --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96651db1..c08ecd7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,11 +21,13 @@ name: "Continuous Integration" on: push: + branches: [ '**' ] paths-ignore: - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' - branches: [ '**' ] pull_request: branches: [ '**' ] + paths-ignore: + - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' jobs: build: From 60209c4ad148fbe28986585708eb3ddeb11308d9 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 20:39:52 +0800 Subject: [PATCH 20/22] etcd add connect time --- .../core/function/SDK/config/CreateEtcdConfig.java | 8 ++++++++ .../core/function/SDK/operation/EtcdSDKOperation.java | 2 ++ .../SDK/operation/EtcdSDKCreateOperationTest.java | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java index 1168a65b..9a3e1d64 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java @@ -17,13 +17,21 @@ package org.apache.eventmesh.dashboard.core.function.SDK.config; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor public class CreateEtcdConfig implements CreateSDKConfig { private String etcdServerAddress; + private Long connectTime; + @Override public String getUniqueKey() { return etcdServerAddress; diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java index 7206dad0..98f88bdd 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKOperation.java @@ -21,6 +21,7 @@ import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateEtcdConfig; import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateSDKConfig; +import java.time.Duration; import java.util.AbstractMap.SimpleEntry; import io.etcd.jetcd.Client; @@ -39,6 +40,7 @@ public SimpleEntry createClient(CreateSDKConfig clientConfig) { try { final Client client = Client.builder() .endpoints(getSplitEndpoints(etcdConfig)) + .connectTimeout(Duration.ofSeconds(etcdConfig.getConnectTime())) .build(); kvClient = client.getKVClient(); } catch (EtcdException e) { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java index a71718e3..503faea5 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java @@ -46,8 +46,11 @@ public class EtcdSDKCreateOperationTest { @Test void testCreateClient() { - final CreateEtcdConfig etcdConfig = new CreateEtcdConfig(); - etcdConfig.setEtcdServerAddress(url); + final CreateEtcdConfig etcdConfig = CreateEtcdConfig.builder() + .etcdServerAddress(url) + .connectTime(10L) + .build(); + // etcdConfig.setEtcdServerAddress(url); SimpleEntry simpleEntry = null; try { simpleEntry = etcdSDKOperation.createClient(etcdConfig); From ad5a26be8fa5611b996c26cc2006e49c049e4723 Mon Sep 17 00:00:00 2001 From: Alonexc Date: Wed, 10 Apr 2024 21:29:19 +0800 Subject: [PATCH 21/22] update --- .github/workflows/ci.yml | 4 -- .../operation/EtcdSDKCreateOperationTest.java | 44 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c08ecd7f..aac6fa1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,12 +22,8 @@ name: "Continuous Integration" on: push: branches: [ '**' ] - paths-ignore: - - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' pull_request: branches: [ '**' ] - paths-ignore: - - 'eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/**' jobs: build: diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java index 503faea5..04c2c189 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java @@ -46,28 +46,28 @@ public class EtcdSDKCreateOperationTest { @Test void testCreateClient() { - final CreateEtcdConfig etcdConfig = CreateEtcdConfig.builder() - .etcdServerAddress(url) - .connectTime(10L) - .build(); - // etcdConfig.setEtcdServerAddress(url); - SimpleEntry simpleEntry = null; - try { - simpleEntry = etcdSDKOperation.createClient(etcdConfig); - Assertions.assertEquals(url, simpleEntry.getKey()); - simpleEntry.getValue().put(bytesOf(key), bytesOf(value)); - final GetResponse response = simpleEntry.getValue().get(bytesOf(key)).get(); - final List keyValues = response.getKvs(); - log.info("get key = {} , value = {} from etcd success", - keyValues.get(0).getKey().toString(StandardCharsets.UTF_8), - keyValues.get(0).getValue().toString(StandardCharsets.UTF_8)); - simpleEntry.getValue().close(); - } catch (Exception e) { - log.error("create etcd client failed", e); - if (simpleEntry != null) { - simpleEntry.getValue().close(); - } - } + // final CreateEtcdConfig etcdConfig = CreateEtcdConfig.builder() + // .etcdServerAddress(url) + // .connectTime(10L) + // .build(); + // // etcdConfig.setEtcdServerAddress(url); + // SimpleEntry simpleEntry = null; + // try { + // simpleEntry = etcdSDKOperation.createClient(etcdConfig); + // Assertions.assertEquals(url, simpleEntry.getKey()); + // simpleEntry.getValue().put(bytesOf(key), bytesOf(value)); + // final GetResponse response = simpleEntry.getValue().get(bytesOf(key)).get(); + // final List keyValues = response.getKvs(); + // log.info("get key = {} , value = {} from etcd success", + // keyValues.get(0).getKey().toString(StandardCharsets.UTF_8), + // keyValues.get(0).getValue().toString(StandardCharsets.UTF_8)); + // simpleEntry.getValue().close(); + // } catch (Exception e) { + // log.error("create etcd client failed", e); + // if (simpleEntry != null) { + // simpleEntry.getValue().close(); + // } + // } } private static ByteSequence bytesOf(String val) { From 59f9fc0151ded391cd76697eb37bb9721d46d0dc Mon Sep 17 00:00:00 2001 From: Alonexc Date: Mon, 15 Apr 2024 11:19:24 +0800 Subject: [PATCH 22/22] optimisation --- .../core/function/SDK/SDKManager.java | 11 +++- .../function/SDK/config/CreateEtcdConfig.java | 3 +- .../SDK/config/CreateRedisConfig.java | 3 +- .../operation/EtcdSDKCreateOperationTest.java | 50 ++++++------------- .../RedisSDKCreateOperationTest.java | 3 +- 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java index a84274b4..e8e722ea 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/SDKManager.java @@ -46,10 +46,17 @@ */ public class SDKManager { - private static final SDKManager INSTANCE = new SDKManager(); + private static volatile SDKManager INSTANCE = null; - public static SDKManager getInstance() { + public static synchronized SDKManager getInstance() { + if (INSTANCE == null) { + synchronized (SDKManager.class) { + if (INSTANCE == null) { + INSTANCE = new SDKManager(); + } + } + } return INSTANCE; } diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java index 9a3e1d64..2f116e06 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateEtcdConfig.java @@ -30,7 +30,8 @@ public class CreateEtcdConfig implements CreateSDKConfig { private String etcdServerAddress; - private Long connectTime; + @Builder.Default() + private int connectTime = 10; @Override public String getUniqueKey() { diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java index ec23c483..fb42f880 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/config/CreateRedisConfig.java @@ -32,7 +32,8 @@ public class CreateRedisConfig implements CreateSDKConfig { private String password; - private Integer timeOut; + @Builder.Default + private int timeOut = 10; @Override public String getUniqueKey() { diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java index 04c2c189..13afca1b 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/EtcdSDKCreateOperationTest.java @@ -19,17 +19,12 @@ import org.apache.eventmesh.dashboard.core.function.SDK.config.CreateEtcdConfig; -import java.nio.charset.StandardCharsets; import java.util.AbstractMap.SimpleEntry; -import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.KV; -import io.etcd.jetcd.KeyValue; -import io.etcd.jetcd.kv.GetResponse; import lombok.extern.slf4j.Slf4j; @@ -38,39 +33,24 @@ public class EtcdSDKCreateOperationTest { private final EtcdSDKOperation etcdSDKOperation = new EtcdSDKOperation(); - private static final String key = "/test/foo"; - - private static final String value = "test"; - private static final String url = "http://localhost:2379"; @Test void testCreateClient() { - // final CreateEtcdConfig etcdConfig = CreateEtcdConfig.builder() - // .etcdServerAddress(url) - // .connectTime(10L) - // .build(); - // // etcdConfig.setEtcdServerAddress(url); - // SimpleEntry simpleEntry = null; - // try { - // simpleEntry = etcdSDKOperation.createClient(etcdConfig); - // Assertions.assertEquals(url, simpleEntry.getKey()); - // simpleEntry.getValue().put(bytesOf(key), bytesOf(value)); - // final GetResponse response = simpleEntry.getValue().get(bytesOf(key)).get(); - // final List keyValues = response.getKvs(); - // log.info("get key = {} , value = {} from etcd success", - // keyValues.get(0).getKey().toString(StandardCharsets.UTF_8), - // keyValues.get(0).getValue().toString(StandardCharsets.UTF_8)); - // simpleEntry.getValue().close(); - // } catch (Exception e) { - // log.error("create etcd client failed", e); - // if (simpleEntry != null) { - // simpleEntry.getValue().close(); - // } - // } - } - - private static ByteSequence bytesOf(String val) { - return ByteSequence.from(val, StandardCharsets.UTF_8); + final CreateEtcdConfig etcdConfig = CreateEtcdConfig.builder() + .etcdServerAddress(url) + .connectTime(5) + .build(); + SimpleEntry simpleEntry = null; + try { + simpleEntry = etcdSDKOperation.createClient(etcdConfig); + Assertions.assertEquals(url, simpleEntry.getKey()); + simpleEntry.getValue().close(); + } catch (Exception e) { + log.error("create etcd client failed", e); + if (simpleEntry != null) { + simpleEntry.getValue().close(); + } + } } } diff --git a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java index 050c6b07..2129d74f 100644 --- a/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java +++ b/eventmesh-dashboard-core/src/test/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKCreateOperationTest.java @@ -32,7 +32,7 @@ @Slf4j class RedisSDKCreateOperationTest { - private RedisSDKOperation redisClientCreateOperation = new RedisSDKOperation(); + private final RedisSDKOperation redisClientCreateOperation = new RedisSDKOperation(); @Test void testCreateClient() { @@ -41,7 +41,6 @@ void testCreateClient() { .password("") .timeOut(5) .build(); - // createClientConfig.setRedisUrl("redis://localhost:6379"); SimpleEntry> simpleEntry = null; try { simpleEntry = redisClientCreateOperation.createClient(createClientConfig);