From ef16253bb7bbd398ff2198b7310a4e9b19790f28 Mon Sep 17 00:00:00 2001 From: Pil0tXia Date: Tue, 7 Jan 2025 10:10:45 +0800 Subject: [PATCH] [ISSUE #4825] Deprecate Webhook function of EventMesh Runtime(v1) (#5153) --- build.gradle | 5 +- .../common/config/CommonConfiguration.java | 4 - .../config/CommonConfigurationTest.java | 2 - .../eventmesh-protocol-webhook/build.gradle | 22 -- .../gradle.properties | 18 -- .../webhook/WebHookProtocolAdaptor.java | 90 -------- ...che.eventmesh.protocol.api.ProtocolAdaptor | 16 -- eventmesh-runtime/build.gradle | 5 - eventmesh-runtime/conf/eventmesh.properties | 15 +- .../admin/handler/AdminHandlerManager.java | 19 -- .../handler/v1/ConfigurationHandlerV1.java | 1 - .../v1/DeleteWebHookConfigHandler.java | 82 ------- .../v1/InsertWebHookConfigHandler.java | 89 -------- .../v1/QueryWebHookConfigByIdHandler.java | 94 -------- ...eryWebHookConfigByManufacturerHandler.java | 92 -------- .../v1/UpdateWebHookConfigHandler.java | 86 ------- .../response/v1/GetConfigurationResponse.java | 3 - .../runtime/boot/EventMeshHTTPServer.java | 16 +- .../runtime/boot/EventMeshTCPServer.java | 14 -- .../runtime/boot/HTTPThreadPoolGroup.java | 7 - .../EventMeshHTTPConfiguration.java | 3 - .../LocalSubscribeEventProcessor.java | 10 - .../RemoteSubscribeEventProcessor.java | 28 --- .../http/processor/SubscribeProcessor.java | 12 - .../http/processor/WebHookProcessor.java | 61 ----- .../http/push/AsyncHTTPPushRequest.java | 8 - .../eventmesh/runtime/util/WebhookUtil.java | 123 ---------- .../runtime/boot/EventMeshServerTest.java | 2 - .../EventMeshGrpcConfigurationTest.java | 2 - .../EventMeshHTTPConfigurationTest.java | 2 - .../EventMeshTCPConfigurationTest.java | 2 - .../processor/WebHookProcessorTest.java | 114 ---------- .../runtime/util/WebhookUtilTest.java | 92 -------- eventmesh-webhook/build.gradle | 38 ---- .../eventmesh-webhook-admin/bin/.gitignore | 1 - .../eventmesh-webhook-admin/build.gradle | 38 ---- .../eventmesh-webhook-admin/gradle.properties | 16 -- .../AdminWebHookConfigOperationManager.java | 83 ------- .../admin/FileWebHookConfigOperation.java | 190 ---------------- .../admin/NacosWebHookConfigOperation.java | 209 ----------------- .../webhook/config/AdminConfiguration.java | 48 ---- ...dminWebHookConfigOperationManagerTest.java | 38 ---- .../admin/FileWebHookConfigOperationTest.java | 74 ------ .../config/AdminConfigurationTest.java | 48 ---- .../src/test/resources/eventmesh.properties | 28 --- .../eventmesh-webhook-api/bin/.gitignore | 1 - .../eventmesh-webhook-api/build.gradle | 26 --- .../eventmesh-webhook-api/gradle.properties | 16 -- .../eventmesh/webhook/api/Manufacturer.java | 59 ----- .../eventmesh/webhook/api/WebHookConfig.java | 94 -------- .../webhook/api/WebHookConfigOperation.java | 46 ---- .../webhook/api/WebHookOperationConstant.java | 55 ----- .../webhook/api/common/SharedLatchHolder.java | 25 --- .../webhook/api/utils/ClassUtils.java | 25 --- .../eventmesh-webhook-receive/bin/.gitignore | 1 - .../eventmesh-webhook-receive/build.gradle | 39 ---- .../gradle.properties | 16 -- .../webhook/receive/ManufacturerProtocol.java | 40 ---- .../webhook/receive/WebHookController.java | 137 ------------ .../webhook/receive/WebHookMQProducer.java | 64 ------ .../webhook/receive/WebHookRequest.java | 44 ---- .../receive/config/ReceiveConfiguration.java | 51 ----- .../receive/protocol/GithubProtocol.java | 116 ---------- .../receive/protocol/ProtocolManager.java | 46 ---- .../AbstractWebHookConfigOperation.java | 22 -- .../storage/HookConfigOperationManager.java | 178 --------------- .../receive/storage/WebhookFileListener.java | 211 ------------------ .../config/ReceiveConfigurationTest.java | 51 ----- .../src/test/resources/eventmesh.properties | 30 --- eventmesh-webhook/gradle.properties | 16 -- eventmesh-webhook/webhook.jmx | 122 ---------- settings.gradle | 9 +- 72 files changed, 4 insertions(+), 3486 deletions(-) delete mode 100644 eventmesh-protocol-plugin/eventmesh-protocol-webhook/build.gradle delete mode 100644 eventmesh-protocol-plugin/eventmesh-protocol-webhook/gradle.properties delete mode 100644 eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java delete mode 100644 eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.protocol.api.ProtocolAdaptor delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/WebHookProcessor.java delete mode 100644 eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/WebhookUtil.java delete mode 100644 eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/protocol/processor/WebHookProcessorTest.java delete mode 100644 eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/WebhookUtilTest.java delete mode 100644 eventmesh-webhook/build.gradle delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/bin/.gitignore delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/build.gradle delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/gradle.properties delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManager.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManagerTest.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperationTest.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/config/AdminConfigurationTest.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-admin/src/test/resources/eventmesh.properties delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/bin/.gitignore delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/build.gradle delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/gradle.properties delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/Manufacturer.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfig.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfigOperation.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookOperationConstant.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/common/SharedLatchHolder.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/utils/ClassUtils.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/bin/.gitignore delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/build.gradle delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/gradle.properties delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/ManufacturerProtocol.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookController.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookMQProducer.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookRequest.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/GithubProtocol.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/ProtocolManager.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/AbstractWebHookConfigOperation.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/HookConfigOperationManager.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/test/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfigurationTest.java delete mode 100644 eventmesh-webhook/eventmesh-webhook-receive/src/test/resources/eventmesh.properties delete mode 100644 eventmesh-webhook/gradle.properties delete mode 100644 eventmesh-webhook/webhook.jmx diff --git a/build.gradle b/build.gradle index 2e50eb3891..ca9804cec0 100644 --- a/build.gradle +++ b/build.gradle @@ -174,10 +174,7 @@ tasks.register('dist') { "eventmesh-spi", "eventmesh-starter", "eventmesh-storage-plugin:eventmesh-storage-api", - "eventmesh-trace-plugin:eventmesh-trace-api", - "eventmesh-webhook:eventmesh-webhook-api", - "eventmesh-webhook:eventmesh-webhook-admin", - "eventmesh-webhook:eventmesh-webhook-receive"] + "eventmesh-trace-plugin:eventmesh-trace-api"] doLast { includedProjects.each { def subProject = findProject(it) diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java index 04c4ae60ed..b2f0ebbb0c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java @@ -97,9 +97,6 @@ public class CommonConfiguration { @ConfigField(field = "server.provide.protocols", reload = true) private List eventMeshProvideServerProtocols; - @ConfigField(reload = true) - private String eventMeshWebhookOrigin; - @ConfigField(reload = true) private String meshGroup; @@ -122,7 +119,6 @@ public class CommonConfiguration { private boolean eventMeshRegistryPluginEnabled = false; public void reload() { - this.eventMeshWebhookOrigin = "eventmesh." + eventMeshIDC; if (Strings.isNullOrEmpty(this.eventMeshServerIp)) { this.eventMeshServerIp = IPUtils.getLocalAddress(); diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java index fb1ebc1635..ce173d3ffe 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java @@ -69,7 +69,5 @@ public void testGetCommonConfiguration() { Assertions.assertTrue(config.isEventMeshServerSecurityEnable()); Assertions.assertTrue(config.isEventMeshServerMetaStorageEnable()); Assertions.assertTrue(config.isEventMeshServerTraceEnable()); - - Assertions.assertEquals("eventmesh.idc-succeed!!!", config.getEventMeshWebhookOrigin()); } } diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/build.gradle b/eventmesh-protocol-plugin/eventmesh-protocol-webhook/build.gradle deleted file mode 100644 index a34c34646a..0000000000 --- a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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. - */ - -dependencies { - implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-api") - implementation "io.cloudevents:cloudevents-core" - implementation "io.cloudevents:cloudevents-json-jackson" -} diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/gradle.properties b/eventmesh-protocol-plugin/eventmesh-protocol-webhook/gradle.properties deleted file mode 100644 index 79ead4554f..0000000000 --- a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/gradle.properties +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -# - -pluginType=protocol -pluginName=webhook \ No newline at end of file diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java deleted file mode 100644 index 58f8e2aedf..0000000000 --- a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/java/org/apache/eventmesh/protocol/webhook/WebHookProtocolAdaptor.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.protocol.webhook; - -import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.ProtocolTransportObject; -import org.apache.eventmesh.common.protocol.http.HttpEventWrapper; -import org.apache.eventmesh.common.protocol.http.WebhookProtocolTransportObject; -import org.apache.eventmesh.common.utils.RandomStringUtils; -import org.apache.eventmesh.protocol.api.ProtocolAdaptor; -import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; - -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; - -public class WebHookProtocolAdaptor implements ProtocolAdaptor { - - @Override - public CloudEvent toCloudEvent(WebhookProtocolTransportObject protocol) throws ProtocolHandleException { - return CloudEventBuilder.v1() - .withId(protocol.getCloudEventId()) - .withSubject(protocol.getCloudEventName()) - .withSource(URI.create(protocol.getCloudEventSource())) - .withDataContentType(protocol.getDataContentType()) - .withType(protocol.getEventType()) - .withData(protocol.getBody()) - .withExtension(Constants.PROTOCOL_TYPE, "webhook") - .withExtension("bizseqno", RandomStringUtils.generateNum(30)) - .withExtension("uniqueid", RandomStringUtils.generateNum(30)) - .build(); - } - - @Override - public List toBatchCloudEvent(WebhookProtocolTransportObject protocol) { - return new ArrayList<>(); - } - - @Override - public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) { - final HttpEventWrapper httpEventWrapper = new HttpEventWrapper(); - Map sysHeaderMap = new HashMap<>(); - // ce attributes - Set attributeNames = cloudEvent.getAttributeNames(); - // ce extensions - Set extensionNames = cloudEvent.getExtensionNames(); - for (String attributeName : attributeNames) { - sysHeaderMap.put(attributeName, cloudEvent.getAttribute(attributeName)); - } - for (String extensionName : extensionNames) { - sysHeaderMap.put(extensionName, cloudEvent.getExtension(extensionName)); - } - sysHeaderMap.put("cloudEventId", cloudEvent.getId()); - sysHeaderMap.put("cloudEventName", cloudEvent.getSubject()); - sysHeaderMap.put("cloudEventSource", cloudEvent.getSource().toString()); - sysHeaderMap.put("type", cloudEvent.getType()); - httpEventWrapper.setSysHeaderMap(sysHeaderMap); - if (cloudEvent.getData() != null) { - httpEventWrapper.setBody(cloudEvent.getData().toBytes()); - } - return httpEventWrapper; - } - - @Override - public String getProtocolType() { - return "webhookProtocolAdaptor"; - } - -} diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.protocol.api.ProtocolAdaptor b/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.protocol.api.ProtocolAdaptor deleted file mode 100644 index 1d1804fec0..0000000000 --- a/eventmesh-protocol-plugin/eventmesh-protocol-webhook/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.protocol.api.ProtocolAdaptor +++ /dev/null @@ -1,16 +0,0 @@ -# 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. - -webhook=org.apache.eventmesh.protocol.webhook.WebHookProtocolAdaptor \ No newline at end of file diff --git a/eventmesh-runtime/build.gradle b/eventmesh-runtime/build.gradle index b016e18bfe..d66baad447 100644 --- a/eventmesh-runtime/build.gradle +++ b/eventmesh-runtime/build.gradle @@ -65,7 +65,6 @@ dependencies { implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-meshmessage") implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-openmessage") implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-http") - implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-webhook") implementation project(":eventmesh-metrics-plugin:eventmesh-metrics-api") implementation project(":eventmesh-metrics-plugin:eventmesh-metrics-prometheus") @@ -73,10 +72,6 @@ dependencies { implementation project(":eventmesh-trace-plugin:eventmesh-trace-api") implementation project(":eventmesh-trace-plugin:eventmesh-trace-zipkin") - implementation project(":eventmesh-webhook:eventmesh-webhook-admin") - implementation project(":eventmesh-webhook:eventmesh-webhook-api") - implementation project(":eventmesh-webhook:eventmesh-webhook-receive") - implementation project(":eventmesh-retry:eventmesh-retry-api") testImplementation "org.mockito:mockito-inline" diff --git a/eventmesh-runtime/conf/eventmesh.properties b/eventmesh-runtime/conf/eventmesh.properties index 9c2e5ee0d4..87a24a1369 100644 --- a/eventmesh-runtime/conf/eventmesh.properties +++ b/eventmesh-runtime/conf/eventmesh.properties @@ -156,17 +156,4 @@ eventMesh.metrics.plugin=prometheus # trace plugin eventMesh.server.trace.enabled=false -eventMesh.trace.plugin=zipkin - -# webhook -# Start webhook admin service -eventMesh.webHook.admin.start=true -# Webhook event configuration storage mode. Currently, only file and nacos are supported -eventMesh.webHook.operationMode=file -# The file storage path of the file storage mode. If #{eventMeshHome} is written, it is in the EventMesh root directory -eventMesh.webHook.fileMode.filePath= #{eventMeshHome}/webhook -# Nacos storage mode, and the configuration naming rule is EventMesh webHook. nacosMode. {nacos native configuration key} please see the specific configuration [nacos github api](https://github.com/alibaba/nacos/blob/develop/api/src/main/java/com/alibaba/nacos/api/SystemPropertyKeyConst.java) -## Address of Nacos -eventMesh.webHook.nacosMode.serverAddr=127.0.0.1:8848 -# Webhook CloudEvent sending mode. This property is the same as the eventMesh.storage.plugin.type configuration. -eventMesh.webHook.producer.storage=standalone +eventMesh.trace.plugin=zipkin \ No newline at end of file diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java index 35d01a5e3a..672479f1dc 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java @@ -18,15 +18,11 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.runtime.admin.handler.v1.ConfigurationHandlerV1; -import org.apache.eventmesh.runtime.admin.handler.v1.DeleteWebHookConfigHandler; import org.apache.eventmesh.runtime.admin.handler.v1.EventHandler; import org.apache.eventmesh.runtime.admin.handler.v1.GrpcClientHandler; import org.apache.eventmesh.runtime.admin.handler.v1.HTTPClientHandler; -import org.apache.eventmesh.runtime.admin.handler.v1.InsertWebHookConfigHandler; import org.apache.eventmesh.runtime.admin.handler.v1.MetaHandler; import org.apache.eventmesh.runtime.admin.handler.v1.QueryRecommendEventMeshHandler; -import org.apache.eventmesh.runtime.admin.handler.v1.QueryWebHookConfigByIdHandler; -import org.apache.eventmesh.runtime.admin.handler.v1.QueryWebHookConfigByManufacturerHandler; import org.apache.eventmesh.runtime.admin.handler.v1.RedirectClientByIpPortHandler; import org.apache.eventmesh.runtime.admin.handler.v1.RedirectClientByPathHandler; import org.apache.eventmesh.runtime.admin.handler.v1.RedirectClientBySubSystemHandler; @@ -38,7 +34,6 @@ import org.apache.eventmesh.runtime.admin.handler.v1.ShowListenClientByTopicHandler; import org.apache.eventmesh.runtime.admin.handler.v1.TCPClientHandler; import org.apache.eventmesh.runtime.admin.handler.v1.TopicHandler; -import org.apache.eventmesh.runtime.admin.handler.v1.UpdateWebHookConfigHandler; import org.apache.eventmesh.runtime.admin.handler.v2.ConfigurationHandler; import org.apache.eventmesh.runtime.boot.EventMeshGrpcServer; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; @@ -46,11 +41,8 @@ import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.meta.MetaStorage; -import org.apache.eventmesh.webhook.admin.AdminWebHookConfigOperationManager; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -67,8 +59,6 @@ public class AdminHandlerManager { private MetaStorage eventMeshMetaStorage; - private AdminWebHookConfigOperationManager adminWebHookConfigOperationManage; - private final Map httpHandlerMap = new ConcurrentHashMap<>(); public AdminHandlerManager(EventMeshServer eventMeshServer) { @@ -77,7 +67,6 @@ public AdminHandlerManager(EventMeshServer eventMeshServer) { this.eventMeshGrpcServer = eventMeshServer.getEventMeshGrpcServer(); this.eventMeshHTTPServer = eventMeshServer.getEventMeshHTTPServer(); this.eventMeshMetaStorage = eventMeshServer.getMetaStorage(); - this.adminWebHookConfigOperationManage = eventMeshTCPServer.getAdminWebHookConfigOperationManage(); } public void registerHttpHandler() { @@ -102,14 +91,6 @@ public void registerHttpHandler() { initHandler(new TopicHandler(eventMeshTCPServer.getEventMeshTCPConfiguration().getEventMeshStoragePluginType())); initHandler(new EventHandler(eventMeshTCPServer.getEventMeshTCPConfiguration().getEventMeshStoragePluginType())); initHandler(new MetaHandler(eventMeshMetaStorage)); - if (Objects.nonNull(adminWebHookConfigOperationManage.getWebHookConfigOperation())) { - WebHookConfigOperation webHookConfigOperation = adminWebHookConfigOperationManage.getWebHookConfigOperation(); - initHandler(new InsertWebHookConfigHandler(webHookConfigOperation)); - initHandler(new UpdateWebHookConfigHandler(webHookConfigOperation)); - initHandler(new DeleteWebHookConfigHandler(webHookConfigOperation)); - initHandler(new QueryWebHookConfigByIdHandler(webHookConfigOperation)); - initHandler(new QueryWebHookConfigByManufacturerHandler(webHookConfigOperation)); - } // v2 endpoints initHandler(new ConfigurationHandler( diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java index d9c5c6bb8e..5c2670f306 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java @@ -76,7 +76,6 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex eventMeshTCPConfiguration.getEventMeshCluster(), eventMeshTCPConfiguration.getEventMeshServerIp(), eventMeshTCPConfiguration.getEventMeshName(), - eventMeshTCPConfiguration.getEventMeshWebhookOrigin(), eventMeshTCPConfiguration.isEventMeshServerSecurityEnable(), eventMeshTCPConfiguration.isEventMeshServerMetaStorageEnable(), // TCP Configuration diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java deleted file mode 100644 index 390ed38bc4..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.runtime.admin.handler.v1; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; -import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; -import org.apache.eventmesh.runtime.util.HttpRequestUtil; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; - -import java.util.Map; -import java.util.Objects; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.HttpRequest; - -import lombok.extern.slf4j.Slf4j; - -/** - * This class handles the HTTP requests of {@code /webhook/deleteWebHookConfig} endpoint and deletes an existing WebHook configuration according to - * the given {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}. - *

- * The implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation#deleteWebHookConfig WebHookConfigOperation} interface - * depends on the {@code eventMesh.webHook.operationMode} configuration in {@code eventmesh.properties}. - *

- * For example, when {@code eventMesh.webHook.operationMode=file}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation - * #deleteWebHookConfig FileWebHookConfigOperation} method as implementation to delete the WebHook configuration file; - *

- * When {@code eventMesh.webHook.operationMode=nacos}, It calls the {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation - * #deleteWebHookConfig NacosWebHookConfigOperation} method as implementation to delete the WebHook configuration from Nacos. - *

- * The {@linkplain org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#deleteWebHookConfig HookConfigOperationManager} , another - * implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation WebHookConfigOperation} interface, is not used for this - * endpoint. - * - * @see AbstractHttpHandler - */ - -@SuppressWarnings("restriction") -@Slf4j -@EventMeshHttpHandler(path = "/webhook/deleteWebHookConfig") -public class DeleteWebHookConfigHandler extends AbstractHttpHandler { - - private final WebHookConfigOperation operation; - - /** - * @param operation the WebHookConfigOperation implementation used to delete the WebHook config - */ - public DeleteWebHookConfigHandler(WebHookConfigOperation operation) { - super(); - this.operation = operation; - } - - @Override - public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); - Objects.requireNonNull(body, "body can not be null"); - // Resolve to WebHookConfig - WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); - // Delete the existing WebHookConfig - Integer code = operation.deleteWebHookConfig(webHookConfig); // operating result - String result = 1 == code ? "deleteWebHookConfig Succeed!" : "deleteWebHookConfig Failed!"; - writeText(ctx, result); - } -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java deleted file mode 100644 index 140decba92..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.runtime.admin.handler.v1; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; -import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; -import org.apache.eventmesh.runtime.util.HttpRequestUtil; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; - -import java.util.Map; -import java.util.Objects; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.HttpRequest; - -import lombok.extern.slf4j.Slf4j; - -/** - * This class handles the HTTP requests of {@code /webhook/insertWebHookConfig} endpoint and adds a new WebHook configuration according to the given - * {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}, if there isn't an existing duplicate configuration already. - *

- * The implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation#insertWebHookConfig WebHookConfigOperation} interface - * depends on the {@code eventMesh.webHook.operationMode} configuration in {@code eventmesh.properties}. - *

- * For example, when {@code eventMesh.webHook.operationMode=file}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation#insertWebHookConfig - * FileWebHookConfigOperation} method as implementation to save the WebHook configuration as a file; - *

- * When {@code eventMesh.webHook.operationMode=nacos}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation#insertWebHookConfig - * NacosWebHookConfigOperation} method as implementation to save the WebHook configuration into Nacos. - *

- * The {@linkplain org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#insertWebHookConfig HookConfigOperationManager} , another - * implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation WebHookConfigOperation} interface, is not used for this - * endpoint. - * - * @see AbstractHttpHandler - */ - -@SuppressWarnings("restriction") -@Slf4j -@EventMeshHttpHandler(path = "/webhook/insertWebHookConfig") -public class InsertWebHookConfigHandler extends AbstractHttpHandler { - - private final WebHookConfigOperation operation; - - /** - * Constructs a new instance with the specified WebHook config operation. - * - * @param operation the WebHookConfigOperation implementation used to insert the WebHook config - */ - public InsertWebHookConfigHandler(WebHookConfigOperation operation) { - super(); - this.operation = operation; - } - - /** - * Handles requests by adding a WebHook configuration. - * - * @throws Exception if an I/O error occurs while handling the request - */ - @Override - public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); - Objects.requireNonNull(body, "body can not be null"); - WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); - // Add the WebHookConfig if no existing duplicate configuration is found - Integer code = operation.insertWebHookConfig(webHookConfig); // operating result - String result = 1 == code ? "insertWebHookConfig Succeed!" : "insertWebHookConfig Failed!"; - writeText(ctx, result); - } -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java deleted file mode 100644 index 97e2c29e2a..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.runtime.admin.handler.v1; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; -import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; -import org.apache.eventmesh.runtime.util.HttpRequestUtil; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; - -import java.util.Map; -import java.util.Objects; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.HttpRequest; - -import lombok.extern.slf4j.Slf4j; - -/** - * This class handles the HTTP requests of {@code /webhook/queryWebHookConfigById} endpoint and returns the corresponding WebHook configuration - * information based on the WebHook callback path specified in {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}. - *

- * Parameters: - *

    - *
  • WebHook callback path: {@code callbackPath} | Example: {@code /webhook/github/eventmesh/all}
  • - *
  • WebHook manufacturer name: {@code manufacturerName} | Example: {@code github}
  • - *
- * The implementation of - * {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation#queryWebHookConfigById WebHookConfigOperation} - * interface depends on the {@code eventMesh.webHook.operationMode} configuration in {@code eventmesh.properties}. - *

- * For example, when {@code eventMesh.webHook.operationMode=file}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation#queryWebHookConfigById FileWebHookConfigOperation} - * method as implementation to retrieve the WebHook configuration from a file; - *

- * When {@code eventMesh.webHook.operationMode=nacos}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation#queryWebHookConfigById NacosWebHookConfigOperation} - * method as implementation to retrieve the WebHook configuration from Nacos. - *

- * After this, the {@linkplain org.apache.eventmesh.webhook.receive.WebHookController#execute WebHookController} - * will use - * {@linkplain org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#queryWebHookConfigById HookConfigOperationManager} - * to retrieve existing WebHook configuration by callback path when processing received WebHook data from manufacturers. - * - * @see AbstractHttpHandler - */ - -@SuppressWarnings("restriction") -@Slf4j -@EventMeshHttpHandler(path = "/webhook/queryWebHookConfigById") -public class QueryWebHookConfigByIdHandler extends AbstractHttpHandler { - - private final WebHookConfigOperation operation; - - /** - * Constructs a new instance with the specified WebHook config operation. - * - * @param operation the WebHookConfigOperation implementation used to query the WebHook config - */ - public QueryWebHookConfigByIdHandler(WebHookConfigOperation operation) { - super(); - this.operation = operation; - } - - @Override - public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - // Resolve to WebHookConfig - Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); - if (!Objects.isNull(body)) { - WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); - // Retrieve the WebHookConfig by callback path - WebHookConfig result = operation.queryWebHookConfigById(webHookConfig); // operating result - String json = JsonUtils.toJSONString(result); - writeJson(ctx, json); - } - throw new Exception(); - } -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java deleted file mode 100644 index 063cd6fd05..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.runtime.admin.handler.v1; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; -import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; -import org.apache.eventmesh.runtime.util.HttpRequestUtil; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; - -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.HttpRequest; - -import lombok.extern.slf4j.Slf4j; - -/** - * This class handles the HTTP requests of {@code /webhook/queryWebHookConfigByManufacturer} endpoint and returns a list of WebHook configurations - * based on the WebHook manufacturer name (such as github) specified in {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}. - *

- * The implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation#queryWebHookConfigByManufacturer WebHookConfigOperation} - * interface depends on the {@code eventMesh.webHook.operationMode} configuration in {@code eventmesh.properties}. - *

- * For example, when {@code eventMesh.webHook.operationMode=file} It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation - * #queryWebHookConfigByManufacturer - * FileWebHookConfigOperation} method as implementation to retrieve the WebHook configuration from a file; - *

- * When {@code eventMesh.webHook.operationMode=nacos} It calls the {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation - * #queryWebHookConfigByManufacturer - * NacosWebHookConfigOperation} method as implementation to retrieve the WebHook configuration from Nacos. - *

- * The {@linkplain org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#queryWebHookConfigByManufacturer - * HookConfigOperationManager} , another implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation WebHookConfigOperation} - * interface, is not used for this endpoint. - * - * @see AbstractHttpHandler - */ - -@SuppressWarnings("restriction") -@Slf4j -@EventMeshHttpHandler(path = "/webhook/queryWebHookConfigByManufacturer") -public class QueryWebHookConfigByManufacturerHandler extends AbstractHttpHandler { - - private final transient WebHookConfigOperation operation; - - /** - * Constructs a new instance with the specified WebHook config operation. - * - * @param operation the WebHookConfigOperation implementation used to query the WebHook config - */ - public QueryWebHookConfigByManufacturerHandler(WebHookConfigOperation operation) { - super(); - this.operation = operation; - Objects.requireNonNull(operation, "WebHookConfigOperation can not be null"); - - } - - @Override - public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - // Resolve to WebHookConfig - Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); - Objects.requireNonNull(body, "body can not be null"); - WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); - Integer pageNum = Integer.valueOf(body.get("pageNum").toString()); - Integer pageSize = Integer.valueOf(body.get("pageSize").toString()); - - // Retrieve the WebHookConfig list by manufacturer name - List listWebHookConfig = operation.queryWebHookConfigByManufacturer(webHookConfig, pageNum, pageSize); // operating result - String result = JsonUtils.toJSONString(listWebHookConfig); - writeJson(ctx, result); - } -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java deleted file mode 100644 index ab0c1192d1..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.runtime.admin.handler.v1; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; -import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; -import org.apache.eventmesh.runtime.util.HttpRequestUtil; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; - -import java.util.Map; -import java.util.Objects; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.HttpRequest; - -import lombok.extern.slf4j.Slf4j; - -/** - * This class handles the HTTP requests of {@code /webhook/updateWebHookConfig} endpoint and updates an existing WebHook configuration according to - * the given {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}. - *

- * The implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation#updateWebHookConfig WebHookConfigOperation} interface - * depends on the {@code eventMesh.webHook.operationMode} configuration in {@code eventmesh.properties}. - *

- * For example, when {@code eventMesh.webHook.operationMode=file}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation - * #updateWebHookConfig - * FileWebHookConfigOperation} method as implementation to update the WebHook configuration in a file; - *

- * When {@code eventMesh.webHook.operationMode=nacos}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation#updateWebHookConfig - * NacosWebHookConfigOperation} method as implementation to update the WebHook configuration in Nacos. - *

- * The {@linkplain org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#updateWebHookConfig HookConfigOperationManager} , another - * implementation of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfigOperation WebHookConfigOperation} interface, is not used for this - * endpoint. - * - * @see AbstractHttpHandler - */ - -@SuppressWarnings("restriction") -@Slf4j -@EventMeshHttpHandler(path = "/webhook/updateWebHookConfig") -public class UpdateWebHookConfigHandler extends AbstractHttpHandler { - - private final WebHookConfigOperation operation; - - /** - * Constructs a new instance with the specified WebHook config operation. - * - * @param operation the WebHookConfigOperation implementation used to update the WebHook config - */ - public UpdateWebHookConfigHandler(WebHookConfigOperation operation) { - super(); - this.operation = operation; - } - - @Override - public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); - Objects.requireNonNull(body, "body can not be null"); - // Resolve to WebHookConfig - WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); - // Update the existing WebHookConfig - Integer code = operation.updateWebHookConfig(webHookConfig); // operating result - String result = 1 == code ? "updateWebHookConfig Succeed!" : "updateWebHookConfig Failed!"; - writeText(ctx, result); - } -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java index 47cceabcac..bdcbb5da67 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java @@ -33,7 +33,6 @@ public class GetConfigurationResponse { private boolean eventMeshServerRegistryEnable; private String eventMeshName; private String sysID; - private String eventMeshWebhookOrigin; private String namesrvAddr; private int eventMeshTcpServerPort; @@ -54,7 +53,6 @@ public GetConfigurationResponse( @JsonProperty("eventMeshCluster") String eventMeshCluster, @JsonProperty("eventMeshServerIp") String eventMeshServerIp, @JsonProperty("eventMeshName") String eventMeshName, - @JsonProperty("eventMeshWebhookOrigin") String eventMeshWebhookOrigin, @JsonProperty("eventMeshServerSecurityEnable") boolean eventMeshServerSecurityEnable, @JsonProperty("eventMeshServerRegistryEnable") boolean eventMeshServerRegistryEnable, @@ -77,7 +75,6 @@ public GetConfigurationResponse( this.eventMeshCluster = eventMeshCluster; this.eventMeshServerIp = eventMeshServerIp; this.eventMeshName = eventMeshName; - this.eventMeshWebhookOrigin = eventMeshWebhookOrigin; this.eventMeshServerSecurityEnable = eventMeshServerSecurityEnable; this.eventMeshServerRegistryEnable = eventMeshServerRegistryEnable; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java index 1089a1cafb..1528e71f28 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java @@ -49,13 +49,11 @@ import org.apache.eventmesh.runtime.core.protocol.http.processor.SendSyncMessageProcessor; import org.apache.eventmesh.runtime.core.protocol.http.processor.SubscribeProcessor; import org.apache.eventmesh.runtime.core.protocol.http.processor.UnSubscribeProcessor; -import org.apache.eventmesh.runtime.core.protocol.http.processor.WebHookProcessor; import org.apache.eventmesh.runtime.core.protocol.http.push.HTTPClientPool; import org.apache.eventmesh.runtime.core.protocol.http.retry.HttpRetryer; import org.apache.eventmesh.runtime.core.protocol.producer.ProducerManager; import org.apache.eventmesh.runtime.meta.MetaStorage; import org.apache.eventmesh.runtime.metrics.http.EventMeshHttpMetricsManager; -import org.apache.eventmesh.webhook.receive.WebHookController; import org.apache.commons.lang3.StringUtils; @@ -282,17 +280,5 @@ private void registerHTTPRequestProcessor() throws Exception { final QuerySubscriptionProcessor querySubscriptionProcessor = new QuerySubscriptionProcessor(this); this.getHandlerService().register(querySubscriptionProcessor); - - registerWebhook(); - } - - private void registerWebhook() throws Exception { - final WebHookProcessor webHookProcessor = new WebHookProcessor(); - final WebHookController webHookController = new WebHookController(); - - webHookController.init(); - webHookProcessor.setWebHookController(webHookController); - - this.getHandlerService().register(webHookProcessor, super.getHttpThreadPoolGroup().getWebhookExecutor()); } -} +} \ No newline at end of file diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java index 1c75e583f4..3bede2a442 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java @@ -45,7 +45,6 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.retry.TcpRetryer; import org.apache.eventmesh.runtime.meta.MetaStorage; import org.apache.eventmesh.runtime.metrics.tcp.EventMeshTcpMetricsManager; -import org.apache.eventmesh.webhook.admin.AdminWebHookConfigOperationManager; import java.util.List; import java.util.Optional; @@ -74,8 +73,6 @@ public class EventMeshTCPServer extends AbstractTCPServer { private TcpRetryer tcpRetryer; - private AdminWebHookConfigOperationManager adminWebHookConfigOperationManage; - private RateLimiter rateLimiter; private EventMeshRebalanceService eventMeshRebalanceService; @@ -112,9 +109,6 @@ public void init() throws Exception { eventMeshRebalanceService.init(); } - adminWebHookConfigOperationManage = new AdminWebHookConfigOperationManager(); - adminWebHookConfigOperationManage.init(); - registerTCPRequestProcessor(); log.info("--------------------------EventMeshTCPServer Inited"); @@ -253,14 +247,6 @@ public EventMeshRebalanceService getEventMeshRebalanceService() { return eventMeshRebalanceService; } - public AdminWebHookConfigOperationManager getAdminWebHookConfigOperationManage() { - return adminWebHookConfigOperationManage; - } - - public void setAdminWebHookConfigOperationManage(AdminWebHookConfigOperationManager adminWebHookConfigOperationManage) { - this.adminWebHookConfigOperationManage = adminWebHookConfigOperationManage; - } - public Acl getAcl() { return acl; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java index aa11788501..4eb1e2d749 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java @@ -41,8 +41,6 @@ public class HTTPThreadPoolGroup implements ThreadPoolGroup { private ThreadPoolExecutor pushMsgExecutor; @Getter private ThreadPoolExecutor clientManageExecutor; - @Getter - private ThreadPoolExecutor webhookExecutor; public HTTPThreadPoolGroup(EventMeshHTTPConfiguration eventMeshHttpConfiguration) { this.eventMeshHttpConfiguration = eventMeshHttpConfiguration; @@ -85,11 +83,6 @@ public void initThreadPool() { eventMeshHttpConfiguration.getEventMeshServerReplyMsgThreadNum(), eventMeshHttpConfiguration.getEventMeshServerReplyMsgThreadNum(), new LinkedBlockingQueue<>(100), "eventMesh-replyMsg", true); - - webhookExecutor = ThreadPoolFactory.createThreadPoolExecutor( - eventMeshHttpConfiguration.getEventMeshServerWebhookThreadNum(), - eventMeshHttpConfiguration.getEventMeshServerWebhookThreadNum(), - new LinkedBlockingQueue<>(100), "eventMesh-webhook", true); } @Override diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java index 287c222245..389a677052 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java @@ -66,9 +66,6 @@ public class EventMeshHTTPConfiguration extends CommonConfiguration { @ConfigField(field = "retry.threads.num") private int eventMeshServerRetryThreadNum = 2; - @ConfigField(field = "") - private int eventMeshServerWebhookThreadNum = 4; - @ConfigField(field = "pull.metaStorage.interval") private int eventMeshServerPullMetaStorageInterval = 30000; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java index 860e77335f..3a74c72c2c 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/LocalSubscribeEventProcessor.java @@ -33,7 +33,6 @@ import org.apache.eventmesh.runtime.core.consumer.SubscriptionManager; import org.apache.eventmesh.runtime.core.protocol.http.processor.inf.AbstractEventProcessor; import org.apache.eventmesh.runtime.util.RemotingHelper; -import org.apache.eventmesh.runtime.util.WebhookUtil; import java.util.Collections; import java.util.HashMap; @@ -146,15 +145,6 @@ public void handler(final HandlerService.HandlerSpecific handlerSpecific, final return; } - // obtain webhook delivery agreement for Abuse Protection - if (!WebhookUtil.obtainDeliveryAgreement(eventMeshHTTPServer.getHttpClientPool().getClient(), - url, eventMeshHTTPServer.getEventMeshHttpConfiguration().getEventMeshWebhookOrigin())) { - log.error("subscriber url {} is not allowed by the target system", url); - handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap, - responseBodyMap, null); - return; - } - synchronized (eventMeshHTTPServer.getSubscriptionManager().getLocalClientInfoMapping()) { ClientInfo clientInfo = getClientInfo(requestWrapper); SubscriptionManager subscriptionManager = eventMeshHTTPServer.getSubscriptionManager(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteSubscribeEventProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteSubscribeEventProcessor.java index 84a5812afc..821b5d3001 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteSubscribeEventProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteSubscribeEventProcessor.java @@ -141,34 +141,6 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest } } - // validate URL - // try { - // if (!IPUtils.isValidDomainOrIp(url, eventMeshHttpConfiguration.getEventMeshIpv4BlackList(), - // eventMeshHttpConfiguration.getEventMeshIpv6BlackList())) { - // httpLogger.error("subscriber url {} is not valid", url); - // handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap, - // responseBodyMap, null); - // return; - // } - // } catch (Exception e) { - // httpLogger.error("subscriber url {} is not valid, error {}", url, e.getMessage()); - // handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap, - // responseBodyMap, null); - // return; - // } - // - // CloseableHttpClient closeableHttpClient = eventMeshHTTPServer.getHttpClientPool().getClient(); - // // obtain webhook delivery agreement for Abuse Protection - // boolean isWebhookAllowed = WebhookUtil.obtainDeliveryAgreement(closeableHttpClient, - // url, eventMeshHttpConfiguration.getEventMeshWebhookOrigin()); - // - // if (!isWebhookAllowed) { - // httpLogger.error("subscriber url {} is not allowed by the target system", url); - // handlerSpecific.sendErrorResponse(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR, responseHeaderMap, - // responseBodyMap, null); - // return; - // } - long startTime = System.currentTimeMillis(); try { // local subscription url diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java index 74a7a7b7fb..272feb7db4 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java @@ -37,7 +37,6 @@ import org.apache.eventmesh.runtime.core.protocol.http.async.CompleteHandler; import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.RemotingHelper; -import org.apache.eventmesh.runtime.util.WebhookUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -142,17 +141,6 @@ public void processRequest(final ChannelHandlerContext ctx, final AsyncContext header = new HashMap<>(); - for (Map.Entry entry : httpRequest.headers().entries()) { - header.put(entry.getKey().toLowerCase(), entry.getValue()); - } - ByteBuf buf = ((FullHttpRequest) httpRequest).content(); - webHookController.execute(httpRequest.uri(), header, ByteBufUtil.getBytes(buf)); - return HttpResponseUtils.createSuccess(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java index 69506ede8a..ad136fad73 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java @@ -37,7 +37,6 @@ import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.http.consumer.HandleMsgContext; import org.apache.eventmesh.runtime.util.EventMeshUtil; -import org.apache.eventmesh.runtime.util.WebhookUtil; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -211,13 +210,6 @@ public void tryHTTPRequest() { builder.setEntity(httpEntity); - // for CloudEvents Webhook spec - String urlAuthType = handleMsgContext.getConsumerGroupConfig().getConsumerGroupTopicConf() - .get(handleMsgContext.getTopic()).getHttpAuthTypeMap().get(currPushUrl); - - WebhookUtil.setWebhookHeaders(builder, httpEntity.getContentType().getValue(), - eventMeshHttpConfiguration.getEventMeshWebhookOrigin(), urlAuthType); - eventMeshHTTPServer.getEventMeshHttpMetricsManager().getHttpMetrics().recordPushMsg(); this.lastPushTime = System.currentTimeMillis(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/WebhookUtil.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/WebhookUtil.java deleted file mode 100644 index 9c916bd2ae..0000000000 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/WebhookUtil.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.runtime.util; - -import org.apache.eventmesh.api.auth.AuthService; -import org.apache.eventmesh.spi.EventMeshExtensionFactory; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.validator.routines.UrlValidator; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpOptions; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.message.BasicHeader; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - -import lombok.extern.slf4j.Slf4j; - -/** - * Utility class for implementing CloudEvents Http Webhook spec - * - * @see CloudEvents Http Webhook - */ -@Slf4j -public class WebhookUtil { - - private static final String CONTENT_TYPE_HEADER = "Content-Type"; - private static final String REQUEST_ORIGIN_HEADER = "WebHook-Request-Origin"; - private static final String ALLOWED_ORIGIN_HEADER = "WebHook-Allowed-Origin"; - - private static final Map AUTH_SERVICES_MAP = new ConcurrentHashMap<>(); - - private static final String[] ALLOWED_SCHEMES = new String[]{"http", "https"}; - - private static final UrlValidator URL_VALIDATOR = new UrlValidator(ALLOWED_SCHEMES); - - public static boolean obtainDeliveryAgreement(final CloseableHttpClient httpClient, - final String targetUrl, - final String requestOrigin) { - - log.info("obtain webhook delivery agreement for url: {}", targetUrl); - - if (isInvalidUrl(targetUrl)) { - log.error("Target url is invalid url: {}", targetUrl); - return false; - } - - final HttpOptions builder = new HttpOptions(targetUrl); - builder.addHeader(REQUEST_ORIGIN_HEADER, requestOrigin); - - try (CloseableHttpResponse response = httpClient.execute(builder)) { - String allowedOrigin = null; - - if (response.getLastHeader(ALLOWED_ORIGIN_HEADER) != null) { - allowedOrigin = response.getLastHeader(ALLOWED_ORIGIN_HEADER).getValue(); - } - return StringUtils.isEmpty(allowedOrigin) - || "*".equals(allowedOrigin) || allowedOrigin.equalsIgnoreCase(requestOrigin); - } catch (Exception e) { - log.error("HTTP Options Method is not supported at the Delivery Target: {}, " - + "unable to obtain the webhook delivery agreement.", targetUrl); - } - return true; - } - - private static boolean isInvalidUrl(String targetUrl) { - return !URL_VALIDATOR.isValid(targetUrl); - } - - public static void setWebhookHeaders(final HttpPost builder, - final String contentType, - final String requestOrigin, - final String urlAuthType) { - builder.setHeader(CONTENT_TYPE_HEADER, contentType); - builder.setHeader(REQUEST_ORIGIN_HEADER, requestOrigin); - - final Map authParam = getHttpAuthParam(urlAuthType); - if (authParam != null) { - authParam.forEach((k, v) -> builder.addHeader(new BasicHeader(k, v))); - } - } - - @SuppressWarnings("unchecked") - private static Map getHttpAuthParam(final String authType) { - if (StringUtils.isEmpty(authType)) { - return new HashMap(); - } - - final AuthService authService = getHttpAuthPlugin(authType); - return authService != null ? authService.getAuthParams() : null; - } - - private static AuthService getHttpAuthPlugin(final String pluginType) { - if (AUTH_SERVICES_MAP.containsKey(pluginType)) { - return AUTH_SERVICES_MAP.get(pluginType); - } - - final AuthService authService = EventMeshExtensionFactory.getExtension(AuthService.class, pluginType); - Objects.requireNonNull(authService, "authService can not be null"); - authService.init(); - AUTH_SERVICES_MAP.put(pluginType, authService); - return authService; - } -} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java index 83baf20fb9..cf63ce974c 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java @@ -107,7 +107,5 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertTrue(config.isEventMeshServerSecurityEnable()); Assertions.assertTrue(config.isEventMeshServerMetaStorageEnable()); Assertions.assertTrue(config.isEventMeshServerTraceEnable()); - - Assertions.assertEquals("eventmesh.idc-succeed!!!", config.getEventMeshWebhookOrigin()); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java index 4dc59a2000..799c0a37cd 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java @@ -86,7 +86,5 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertTrue(config.isEventMeshServerSecurityEnable()); Assertions.assertTrue(config.isEventMeshServerMetaStorageEnable()); Assertions.assertTrue(config.isEventMeshServerTraceEnable()); - - Assertions.assertEquals("eventmesh.idc-succeed!!!", config.getEventMeshWebhookOrigin()); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java index 9e99bc511d..4c167a82c1 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java @@ -101,7 +101,5 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertTrue(config.isEventMeshServerSecurityEnable()); Assertions.assertTrue(config.isEventMeshServerMetaStorageEnable()); Assertions.assertTrue(config.isEventMeshServerTraceEnable()); - - Assertions.assertEquals("eventmesh.idc-succeed!!!", config.getEventMeshWebhookOrigin()); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java index 2aee84ef72..9669adf0d7 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java @@ -88,7 +88,5 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertTrue(config.isEventMeshServerSecurityEnable()); Assertions.assertTrue(config.isEventMeshServerMetaStorageEnable()); Assertions.assertTrue(config.isEventMeshServerTraceEnable()); - - Assertions.assertEquals("eventmesh.idc-succeed!!!", config.getEventMeshWebhookOrigin()); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/protocol/processor/WebHookProcessorTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/protocol/processor/WebHookProcessorTest.java deleted file mode 100644 index a6f49c3886..0000000000 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/protocol/processor/WebHookProcessorTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.runtime.protocol.processor; - -import static org.mockito.ArgumentMatchers.any; - -import org.apache.eventmesh.common.protocol.ProtocolTransportObject; -import org.apache.eventmesh.protocol.api.ProtocolAdaptor; -import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; -import org.apache.eventmesh.runtime.core.protocol.http.processor.WebHookProcessor; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.receive.WebHookController; -import org.apache.eventmesh.webhook.receive.WebHookMQProducer; -import org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager; - -import org.apache.commons.lang3.StringUtils; - -import java.nio.charset.StandardCharsets; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.Spy; -import org.mockito.junit.jupiter.MockitoExtension; - -import io.cloudevents.CloudEvent; -import io.cloudevents.core.data.BytesCloudEventData; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.handler.codec.http.DefaultFullHttpRequest; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpVersion; - -@ExtendWith(MockitoExtension.class) -public class WebHookProcessorTest { - - @Mock - private transient HookConfigOperationManager hookConfigOperationManager; - @Mock - private transient WebHookMQProducer webHookMQProducer; - @Spy - private transient ProtocolAdaptor protocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor("webhook"); - - private transient ArgumentCaptor captor = ArgumentCaptor.forClass(CloudEvent.class); - - @InjectMocks - private transient WebHookController controller = new WebHookController(); - - @BeforeEach - public void init() throws Exception { - Mockito.when(hookConfigOperationManager.queryWebHookConfigById(any())).thenReturn(buildMockWebhookConfig()); - Mockito.doNothing().when(webHookMQProducer).send(captor.capture(), any()); - } - - @Test - public void testHandler() { - WebHookProcessor processor = new WebHookProcessor(); - processor.setWebHookController(controller); - processor.handler(buildMockWebhookRequest()); - - CloudEvent msgSendToMq = captor.getValue(); - Assertions.assertNotNull(msgSendToMq); - Assertions.assertTrue(StringUtils.isNoneBlank(msgSendToMq.getId())); - Assertions.assertEquals("www.github.com", msgSendToMq.getSource().getPath()); - Assertions.assertEquals("github.ForkEvent", msgSendToMq.getType()); - Assertions.assertEquals(BytesCloudEventData.wrap("\"mock_data\":0".getBytes(StandardCharsets.UTF_8)), msgSendToMq.getData()); - } - - private HttpRequest buildMockWebhookRequest() { - ByteBuf buffer = Unpooled.buffer(); - buffer.writeBytes("\"mock_data\":0".getBytes(StandardCharsets.UTF_8)); - - FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/webhook/github/eventmesh/all", buffer); - request.headers().set("content-type", "application/json"); - // encrypt method see: GithubProtocol - request.headers().set("x-hub-signature-256", "sha256=ddb62e1182e2e6d364c0b5d03f2413fd5d1f68d99d1a4b3873e0d6850650d4b3"); - return request; - } - - private WebHookConfig buildMockWebhookConfig() { - WebHookConfig config = new WebHookConfig(); - config.setCallbackPath("/webhook/github/eventmesh/all"); - config.setManufacturerName("github"); - config.setManufacturerDomain("www.github.com"); - config.setManufacturerEventName("ForkEvent"); - config.setContentType("application/json"); - config.setSecret("secret"); - config.setCloudEventName("github-eventmesh"); - config.setCloudEventIdGenerateMode("uuid"); - return config; - } -} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/WebhookUtilTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/WebhookUtilTest.java deleted file mode 100644 index 777467e9a9..0000000000 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/WebhookUtilTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.runtime.util; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; - -import org.apache.eventmesh.api.auth.AuthService; -import org.apache.eventmesh.spi.EventMeshExtensionFactory; - -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.message.BasicHeader; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -public class WebhookUtilTest { - - @Test - public void testObtainDeliveryAgreement() throws Exception { - // normal case - try (CloseableHttpClient httpClient = mock(CloseableHttpClient.class); - CloseableHttpResponse response = mock(CloseableHttpResponse.class); - CloseableHttpClient httpClient2 = mock(CloseableHttpClient.class)) { - - Mockito.when(response.getLastHeader("WebHook-Allowed-Origin")) - .thenReturn(new BasicHeader("WebHook-Allowed-Origin", "*")); - Mockito.when(httpClient.execute(any())).thenReturn(response); - Assertions.assertTrue(WebhookUtil.obtainDeliveryAgreement(httpClient, "https://eventmesh.apache.org", "*"), - "match logic must return true"); - - // abnormal case - Mockito.when(httpClient2.execute(any())).thenThrow(new RuntimeException()); - Assertions.assertTrue(WebhookUtil.obtainDeliveryAgreement(httpClient2, "https://eventmesh.apache.org", "*"), - "when throw exception ,default return true"); - } - } - - @Test - public void testObtainDeliveryAgreementWithInvalidTargetUrl() throws Exception { - try (CloseableHttpClient httpClient = mock(CloseableHttpClient.class); - CloseableHttpResponse response = mock(CloseableHttpResponse.class)) { - Mockito.when(response.getLastHeader("WebHook-Allowed-Origin")) - .thenReturn(new BasicHeader("WebHook-Allowed-Origin", "*")); - Mockito.when(httpClient.execute(any())).thenReturn(response); - Assertions.assertFalse(WebhookUtil.obtainDeliveryAgreement(httpClient, "ftp://eventmesh.apache.org", "*"), - "when target url is invalid, return false"); - } - } - - @Test - public void testSetWebhookHeaders() { - final String authType = "auth-http-basic"; - final AuthService authService = mock(AuthService.class); - doNothing().when(authService).init(); - final Map authParams = new HashMap<>(); - final String key = "Authorization"; - final String value = "Basic ****"; - authParams.put(key, value); - Mockito.when(authService.getAuthParams()).thenReturn(authParams); - - try (MockedStatic dummyStatic = Mockito.mockStatic(EventMeshExtensionFactory.class)) { - dummyStatic.when(() -> EventMeshExtensionFactory.getExtension(AuthService.class, authType)).thenReturn(authService); - final HttpPost post = new HttpPost(); - WebhookUtil.setWebhookHeaders(post, "application/json", "eventmesh.FT", authType); - Assertions.assertEquals(post.getLastHeader(key).getValue(), value, "match expect value"); - } - } -} diff --git a/eventmesh-webhook/build.gradle b/eventmesh-webhook/build.gradle deleted file mode 100644 index b461b7c920..0000000000 --- a/eventmesh-webhook/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ - -task copyEventMeshAdmin(dependsOn: ['jar']) { - doFirst { - new File(projectDir, '../eventmesh-webhook/dist/apps').mkdir() - new File(projectDir, '../dist/webhook/').mkdirs() - } - doLast { - copy { - into('../eventmesh-webhook/dist/apps/') - from project.jar.getArchivePath() - exclude { - "eventmesh-webhook-${version}.jar" - } - } - copy { - into '../dist/webhook' - from "../eventmesh-webhook/dist/apps/eventmesh-webhook-api.jar" - from "../eventmesh-webhook/dist/apps/eventmesh-webhook-admin.jar" - from "../eventmesh-webhook/dist/apps/eventmesh-webhook-receive.jar" - } - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/bin/.gitignore b/eventmesh-webhook/eventmesh-webhook-admin/bin/.gitignore deleted file mode 100644 index ddf9c65631..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/main/ diff --git a/eventmesh-webhook/eventmesh-webhook-admin/build.gradle b/eventmesh-webhook/eventmesh-webhook-admin/build.gradle deleted file mode 100644 index ac0c54162e..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ - /* - * 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. - */ - -dependencies { - - implementation project(":eventmesh-common") - implementation project(":eventmesh-webhook:eventmesh-webhook-api") - - implementation 'org.slf4j:slf4j-api' - implementation "com.alibaba.nacos:nacos-client" - implementation "com.fasterxml.jackson.core:jackson-databind" - implementation "com.fasterxml.jackson.core:jackson-core" - implementation "com.fasterxml.jackson.core:jackson-annotations" - - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - - testCompileOnly 'org.projectlombok:lombok' - testAnnotationProcessor 'org.projectlombok:lombok' - - testImplementation project(":eventmesh-webhook:eventmesh-webhook-api") - - -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/gradle.properties b/eventmesh-webhook/eventmesh-webhook-admin/gradle.properties deleted file mode 100644 index a9fd83fea0..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/gradle.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# 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. -# \ No newline at end of file diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManager.java b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManager.java deleted file mode 100644 index df06ce9875..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManager.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.webhook.admin; - -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.OPERATION_MODE_FILE; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.OPERATION_MODE_NACOS; - -import org.apache.eventmesh.common.config.ConfigService; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; -import org.apache.eventmesh.webhook.config.AdminConfiguration; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class AdminWebHookConfigOperationManager { - - private static final Map> WEBHOOK_CONFIG_OPERATION_MAP = new HashMap<>(); - - static { - WEBHOOK_CONFIG_OPERATION_MAP.put(OPERATION_MODE_FILE, FileWebHookConfigOperation.class); - WEBHOOK_CONFIG_OPERATION_MAP.put(OPERATION_MODE_NACOS, NacosWebHookConfigOperation.class); - } - - private transient AdminConfiguration adminConfiguration; - - private transient WebHookConfigOperation webHookConfigOperation; - - public WebHookConfigOperation getWebHookConfigOperation() { - return webHookConfigOperation; - } - - public void init() throws InvocationTargetException, InstantiationException, IllegalAccessException, - NoSuchMethodException { - - adminConfiguration = ConfigService.getInstance().buildConfigInstance(AdminConfiguration.class); - if (!adminConfiguration.isAdminStart()) { - return; - } - - final String operationMode = adminConfiguration.getOperationMode(); - if (!WEBHOOK_CONFIG_OPERATION_MAP.containsKey(operationMode)) { - throw new IllegalStateException("operationMode is not supported."); - } - - // Affects which implementation of the WebHookConfigOperation interface is used. - final Constructor constructor = - WEBHOOK_CONFIG_OPERATION_MAP.get(operationMode).getDeclaredConstructor(Properties.class); - // Save the original accessibility of constructor - final boolean oldAccessible = constructor.isAccessible(); - try { - constructor.setAccessible(true); - final Properties operationProperties = adminConfiguration.getOperationProperties(); - - log.info("operationMode is {} properties is {} ", operationMode, operationProperties); - this.webHookConfigOperation = constructor.newInstance(operationProperties); - } finally { - // Restore the original accessibility of constructor - constructor.setAccessible(oldAccessible); - } - - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java deleted file mode 100644 index 1d1ce1309f..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperation.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * 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.webhook.admin; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; -import org.apache.eventmesh.webhook.api.WebHookOperationConstant; -import org.apache.eventmesh.webhook.api.common.SharedLatchHolder; -import org.apache.eventmesh.webhook.api.utils.ClassUtils; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Properties; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class FileWebHookConfigOperation implements WebHookConfigOperation { - - private final transient String webHookFilePath; - - public FileWebHookConfigOperation(final Properties properties) throws FileNotFoundException { - final String webHookFilePath = WebHookOperationConstant.getFilePath(properties.getProperty("filePath")); - - final File webHookFileDir = new File(webHookFilePath); - if (!webHookFileDir.exists()) { - webHookFileDir.mkdirs(); - } - if (!webHookFileDir.isDirectory()) { - throw new FileNotFoundException("File path " + webHookFilePath + " is not directory"); - } - this.webHookFilePath = webHookFilePath; - } - - @Override - public Integer insertWebHookConfig(final WebHookConfig webHookConfig) { - if (!webHookConfig.getCallbackPath().startsWith(WebHookOperationConstant.CALLBACK_PATH_PREFIX)) { - log.error("webhookConfig callback path must start with {}", WebHookOperationConstant.CALLBACK_PATH_PREFIX); - return 0; - } - - final File manuDir = new File(getWebhookConfigManuDir(webHookConfig)); - if (!manuDir.exists()) { - manuDir.mkdir(); - } - - final File webhookConfigFile = getWebhookConfigFile(webHookConfig); - if (webhookConfigFile.exists()) { - log.error("webhookConfig {} exists", webHookConfig.getCallbackPath()); - return 0; - } - return writeToFile(webhookConfigFile, webHookConfig) ? 1 : 0; - } - - @Override - public Integer updateWebHookConfig(final WebHookConfig webHookConfig) { - final File webhookConfigFile = getWebhookConfigFile(webHookConfig); - if (!webhookConfigFile.exists()) { - log.error("webhookConfig {} does not exist", webHookConfig.getCallbackPath()); - return 0; - } - return writeToFile(webhookConfigFile, webHookConfig) ? 1 : 0; - } - - @Override - public Integer deleteWebHookConfig(final WebHookConfig webHookConfig) { - synchronized (SharedLatchHolder.lock) { - final File webhookConfigFile = getWebhookConfigFile(webHookConfig); - if (!webhookConfigFile.exists()) { - log.error("webhookConfig {} does not exist", webHookConfig.getCallbackPath()); - return 0; - } - return webhookConfigFile.delete() ? 1 : 0; - } - } - - /** - * Query WebHook configuration information based on the WebHook callback path specified in {@link WebHookConfig}. - */ - @Override - public WebHookConfig queryWebHookConfigById(final WebHookConfig webHookConfig) { - final File webhookConfigFile = getWebhookConfigFile(webHookConfig); - if (!webhookConfigFile.exists()) { - log.error("webhookConfig {} does not exist", webHookConfig.getCallbackPath()); - return null; - } - - return getWebHookConfigFromFile(webhookConfigFile); - } - - @Override - public List queryWebHookConfigByManufacturer(final WebHookConfig webHookConfig, - final Integer pageNum, - final Integer pageSize) { - final String manuDirPath = getWebhookConfigManuDir(webHookConfig); - final File manuDir = new File(manuDirPath); - if (!manuDir.exists()) { - log.warn("webhookConfig dir {} does not exist", manuDirPath); - return new ArrayList<>(); - } - - final List webHookConfigs = new ArrayList<>(); - - final File[] webhookFiles = manuDir.listFiles(); - if (webhookFiles == null || webhookFiles.length == 0) { - return webHookConfigs; - } - - final int startIndex = (pageNum - 1) * pageSize; - final int endIndex = pageNum * pageSize - 1; - if (webhookFiles.length > startIndex) { - for (int i = startIndex; i <= endIndex && i < webhookFiles.length; i++) { - webHookConfigs.add(getWebHookConfigFromFile(webhookFiles[i])); - } - } - return webHookConfigs; - } - - private WebHookConfig getWebHookConfigFromFile(final File webhookConfigFile) { - final StringBuilder fileContent = new StringBuilder(); - - try (BufferedReader br = Files.newBufferedReader(Paths.get(webhookConfigFile.getAbsolutePath()), - StandardCharsets.UTF_8)) { - String line; - while ((line = br.readLine()) != null) { - fileContent.append(line); - } - } catch (IOException e) { - log.error("get webHookConfig from file {} error", webhookConfigFile.getPath(), e); - return null; - } - - return JsonUtils.parseObject(fileContent.toString(), WebHookConfig.class); - } - - public static boolean writeToFile(final File webhookConfigFile, final WebHookConfig webHookConfig) { - // Wait for the previous cacheInit to complete in case of concurrency - synchronized (SharedLatchHolder.lock) { - try (FileOutputStream fos = new FileOutputStream(webhookConfigFile); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, StandardCharsets.UTF_8))) { - // Lock this file to prevent concurrent modification and it will be automatically unlocked when fos closes - fos.getChannel().lock(); - bw.write(Objects.requireNonNull(JsonUtils.toJSONString(webHookConfig))); - } catch (IOException e) { - log.error("write webhookConfig {} to file error", webHookConfig.getCallbackPath()); - return false; - } - return true; - } - } - - private String getWebhookConfigManuDir(final WebHookConfig webHookConfig) { - return webHookFilePath + WebHookOperationConstant.FILE_SEPARATOR + webHookConfig.getManufacturerName(); - } - - private File getWebhookConfigFile(final WebHookConfig webHookConfig) { - final String webhookConfigFilePath = this.getWebhookConfigManuDir(webHookConfig) - + WebHookOperationConstant.FILE_SEPARATOR - + ClassUtils.convertResourcePathToClassName(webHookConfig.getCallbackPath()); - - return new File(webhookConfigFilePath); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java deleted file mode 100644 index f6c9667dd9..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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.webhook.admin; - -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.DATA_ID_EXTENSION; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.GROUP_PREFIX; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.MANUFACTURERS_DATA_ID; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.TIMEOUT_MS; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.webhook.api.Manufacturer; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; -import org.apache.eventmesh.webhook.api.WebHookOperationConstant; - -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import com.alibaba.nacos.api.config.ConfigFactory; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.ConfigType; -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class NacosWebHookConfigOperation implements WebHookConfigOperation { - - private static final String CONSTANTS_WEBHOOK = "webhook"; - - private final ConfigService configService; - - public NacosWebHookConfigOperation(final Properties properties) throws NacosException { - configService = ConfigFactory.createConfigService(properties); - - final String manufacturers = configService.getConfig(MANUFACTURERS_DATA_ID, CONSTANTS_WEBHOOK, TIMEOUT_MS); - if (manufacturers == null) { - configService.publishConfig(MANUFACTURERS_DATA_ID, CONSTANTS_WEBHOOK, - JsonUtils.toJSONString(new Manufacturer()), ConfigType.JSON.getType()); - } - - } - - @Override - public Integer insertWebHookConfig(final WebHookConfig webHookConfig) { - if (!webHookConfig.getCallbackPath().startsWith(WebHookOperationConstant.CALLBACK_PATH_PREFIX)) { - log.error("webhookConfig callback path must start with {}", WebHookOperationConstant.CALLBACK_PATH_PREFIX); - return 0; - } - - Boolean result; - final String manufacturerName = webHookConfig.getManufacturerName(); - try { - if (configService.getConfig(getWebHookConfigDataId(webHookConfig), - getManuGroupId(webHookConfig), TIMEOUT_MS) != null) { - log.error("insertWebHookConfig failed, config has existed"); - return 0; - } - result = configService.publishConfig(getWebHookConfigDataId(webHookConfig), getManuGroupId(webHookConfig), - JsonUtils.toJSONString(webHookConfig), ConfigType.JSON.getType()); - } catch (NacosException e) { - log.error("insertWebHookConfig failed", e); - return 0; - } - - if (result) { - // update manufacturer config - try { - final Manufacturer manufacturer = getManufacturersInfo(); - manufacturer.addManufacturer(manufacturerName); - manufacturer.getManufacturerEvents(manufacturerName).add(getWebHookConfigDataId(webHookConfig)); - configService.publishConfig(MANUFACTURERS_DATA_ID, CONSTANTS_WEBHOOK, - JsonUtils.toJSONString(manufacturer), ConfigType.JSON.getType()); - } catch (NacosException e) { - log.error("update manufacturersInfo error", e); - // rollback insert - try { - configService.removeConfig(getWebHookConfigDataId(webHookConfig), getManuGroupId(webHookConfig)); - } catch (NacosException ex) { - log.error("rollback insertWebHookConfig failed", e); - } - } - } - return result ? 1 : 0; - } - - @Override - public Integer updateWebHookConfig(final WebHookConfig webHookConfig) { - boolean result = false; - try { - if (configService.getConfig(getWebHookConfigDataId(webHookConfig), getManuGroupId(webHookConfig), - TIMEOUT_MS) == null) { - log.error("updateWebHookConfig failed, config is not existed"); - return 0; - } - result = configService.publishConfig(getWebHookConfigDataId(webHookConfig), - getManuGroupId(webHookConfig), JsonUtils.toJSONString(webHookConfig), ConfigType.JSON.getType()); - } catch (NacosException e) { - log.error("updateWebHookConfig failed", e); - } - return result ? 1 : 0; - } - - @Override - public Integer deleteWebHookConfig(final WebHookConfig webHookConfig) { - boolean result = false; - final String manufacturerName = webHookConfig.getManufacturerName(); - - try { - result = configService.removeConfig(getWebHookConfigDataId(webHookConfig), getManuGroupId(webHookConfig)); - } catch (NacosException e) { - log.error("deleteWebHookConfig failed", e); - } - if (result) { - try { - final Manufacturer manufacturer = getManufacturersInfo(); - manufacturer.getManufacturerEvents(manufacturerName).remove(getWebHookConfigDataId(webHookConfig)); - configService.publishConfig(MANUFACTURERS_DATA_ID, CONSTANTS_WEBHOOK, - JsonUtils.toJSONString(manufacturer), ConfigType.JSON.getType()); - } catch (NacosException e) { - log.error("update manufacturersInfo error", e); - } - } - return result ? 1 : 0; - } - - /** - * Query WebHook configuration information based on the WebHook callback path specified in {@link WebHookConfig}. - */ - @Override - public WebHookConfig queryWebHookConfigById(final WebHookConfig webHookConfig) { - try { - final String content = configService.getConfig(getWebHookConfigDataId(webHookConfig), - getManuGroupId(webHookConfig), TIMEOUT_MS); - return JsonUtils.parseObject(content, WebHookConfig.class); - } catch (NacosException e) { - log.error("queryWebHookConfigById failed", e); - } - return null; - } - - @Override - public List queryWebHookConfigByManufacturer(final WebHookConfig webHookConfig, - final Integer pageNum, - final Integer pageSize) { - final List webHookConfigs = new ArrayList<>(); - final String manufacturerName = webHookConfig.getManufacturerName(); - - // get manufacturer event list - try { - final List manufacturerEvents = getManufacturersInfo().getManufacturerEvents(manufacturerName); - final int startIndex = (pageNum - 1) * pageSize; - final int endIndex = pageNum * pageSize - 1; - if (manufacturerEvents.size() > startIndex) { - // nacos API is not able to get all config, so use foreach - for (int i = startIndex; i < endIndex && i < manufacturerEvents.size(); i++) { - final String content = configService.getConfig(manufacturerEvents.get(i) + DATA_ID_EXTENSION, - getManuGroupId(webHookConfig), TIMEOUT_MS); - webHookConfigs.add(JsonUtils.parseObject(content, WebHookConfig.class)); - } - } - } catch (NacosException e) { - log.error("queryWebHookConfigByManufacturer failed", e); - } - return webHookConfigs; - } - - /** - * Escape callback path to a valid dataId. - */ - private String getWebHookConfigDataId(final WebHookConfig webHookConfig) { - String dataId = webHookConfig.getCallbackPath(); - if (dataId.startsWith("/")) { - // remove the first slash - dataId = dataId.substring(1); - } - // then replace the subsequent invalid chars with dots - return dataId.replaceAll("[@#$%^&*,/\\\\]", ".") + DATA_ID_EXTENSION; - } - - private String getManuGroupId(final WebHookConfig webHookConfig) { - return GROUP_PREFIX + webHookConfig.getManufacturerName(); - } - - private Manufacturer getManufacturersInfo() throws NacosException { - final String manufacturersContent = configService.getConfig(MANUFACTURERS_DATA_ID, CONSTANTS_WEBHOOK, TIMEOUT_MS); - return StringUtil.isNullOrEmpty(manufacturersContent) - ? new Manufacturer() - : JsonUtils.parseObject(manufacturersContent, Manufacturer.class); - } - -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java deleted file mode 100644 index 1bbba42fe8..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.webhook.config; - -import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigField; - -import java.util.Properties; - -import lombok.Data; - -@Data -@Config(prefix = "eventMesh.webHook") -public class AdminConfiguration { - - @ConfigField(field = "admin.start") - private boolean adminStart = false; - - @ConfigField(field = "operationMode") - private String operationMode; - - @ConfigField(field = "", reload = true) - private Properties operationProperties; - - public void reload() { - processOperationProperties(); - } - - public void processOperationProperties() { - String prefix = operationMode + "Mode"; - this.operationProperties = (Properties) operationProperties.get(prefix); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManagerTest.java b/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManagerTest.java deleted file mode 100644 index 6eabd2f313..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/AdminWebHookConfigOperationManagerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.webhook.admin; - -import org.apache.eventmesh.common.config.ConfigService; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class AdminWebHookConfigOperationManagerTest { - - @Test - public void init() throws Exception { - ConfigService configService = ConfigService.getInstance(); - configService.setRootConfig("classPath://eventmesh.properties"); - - AdminWebHookConfigOperationManager adminWebHookConfigOperationManage = new AdminWebHookConfigOperationManager(); - adminWebHookConfigOperationManage.init(); - - Assertions.assertTrue( - adminWebHookConfigOperationManage.getWebHookConfigOperation() instanceof FileWebHookConfigOperation); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperationTest.java b/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperationTest.java deleted file mode 100644 index 2179341557..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/admin/FileWebHookConfigOperationTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.webhook.admin; - -import org.apache.eventmesh.webhook.api.WebHookConfig; - -import java.io.File; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.Properties; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class FileWebHookConfigOperationTest { - - @Test - public void testInsertWebHookConfig() throws Exception { - Properties properties = new Properties(); - properties.setProperty("filePath", "test_dir"); - - WebHookConfig config = new WebHookConfig(); - config.setCallbackPath("/webhook/github/eventmesh/all"); - config.setManufacturerName("github"); - config.setManufacturerDomain("www.github.com"); - config.setManufacturerEventName("all"); - config.setSecret("eventmesh"); - config.setCloudEventName("github-eventmesh"); - - try { - FileWebHookConfigOperation fileWebHookConfigOperation = new FileWebHookConfigOperation(properties); - Integer result = fileWebHookConfigOperation.insertWebHookConfig(config); - Assertions.assertTrue(Objects.nonNull(result) && result == 1); - - WebHookConfig queryConfig = new WebHookConfig(); - queryConfig.setManufacturerName("github"); - List queryResult = fileWebHookConfigOperation.queryWebHookConfigByManufacturer(queryConfig, 1, 1); - Assertions.assertTrue(Objects.nonNull(queryResult) && queryResult.size() == 1); - Assertions.assertEquals(queryResult.get(0).getCallbackPath(), config.getCallbackPath()); - } finally { - deleteDir("test_dir"); - } - } - - private boolean deleteDir(String path) { - try { - Files.walk(FileSystems.getDefault().getPath(path)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile).forEach(File::delete); - return true; - } catch (Exception e) { - return false; - } - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/config/AdminConfigurationTest.java b/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/config/AdminConfigurationTest.java deleted file mode 100644 index 54a2e98ac1..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/test/java/org/apache/eventmesh/webhook/config/AdminConfigurationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.webhook.config; - -import org.apache.eventmesh.common.config.ConfigService; - -import java.util.Properties; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class AdminConfigurationTest { - - @Test - public void testGetAdminConfiguration() throws Exception { - - ConfigService configService = ConfigService.getInstance(); - configService.setRootConfig("classPath://eventmesh.properties"); - - AdminConfiguration config = configService.buildConfigInstance(AdminConfiguration.class); - - assertAdminConfiguration(config); - } - - private void assertAdminConfiguration(AdminConfiguration config) { - Assertions.assertTrue(config.isAdminStart()); - Assertions.assertEquals("file", config.getOperationMode()); - - Properties properties = new Properties(); - properties.put("filePath", "."); - Assertions.assertEquals(properties, config.getOperationProperties()); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/test/resources/eventmesh.properties b/eventmesh-webhook/eventmesh-webhook-admin/src/test/resources/eventmesh.properties deleted file mode 100644 index b808436f97..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/test/resources/eventmesh.properties +++ /dev/null @@ -1,28 +0,0 @@ -# -# 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. -# -# webhook -# Start webhook admin service -eventMesh.webHook.admin.start=true -# Webhook event configuration storage mode. Currently, only file and Nacos are supported -eventMesh.webHook.operationMode=file -# The file storage path of the file storage mode. If #{eventmeshhome} is written, it is in the eventmesh root directory -eventMesh.webHook.fileMode.filePath=. -# Nacos storage mode, and the configuration naming rule is eventmesh webHook. nacosMode. {nacos native configuration key} please see the specific configuration [nacos github api](https://github.com/alibaba/nacos/blob/develop/api/src/main/java/com/alibaba/nacos/api/SystemPropertyKeyConst.java) -## Address of Nacos -eventMesh.webHook.nacosMode.serverAddr=127.0.0.1:8848 -# Webhook CloudEvent sending mode. This property is the same as the eventMesh.storage.plugin.type configuration. -eventMesh.webHook.producer.storage=standalone diff --git a/eventmesh-webhook/eventmesh-webhook-api/bin/.gitignore b/eventmesh-webhook/eventmesh-webhook-api/bin/.gitignore deleted file mode 100644 index ddf9c65631..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/main/ diff --git a/eventmesh-webhook/eventmesh-webhook-api/build.gradle b/eventmesh-webhook/eventmesh-webhook-api/build.gradle deleted file mode 100644 index b005d67307..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -dependencies { - implementation project(":eventmesh-common") - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - - testCompileOnly 'org.projectlombok:lombok' - testAnnotationProcessor 'org.projectlombok:lombok' - -} diff --git a/eventmesh-webhook/eventmesh-webhook-api/gradle.properties b/eventmesh-webhook/eventmesh-webhook-api/gradle.properties deleted file mode 100644 index a9fd83fea0..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/gradle.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# 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. -# \ No newline at end of file diff --git a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/Manufacturer.java b/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/Manufacturer.java deleted file mode 100644 index 6573c8e258..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/Manufacturer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.webhook.api; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -public class Manufacturer { - - private Set manufacturerSet = new HashSet<>(); - - private Map> manufacturerEventMap = new ConcurrentHashMap<>(); - - public Set getManufacturerSet() { - return manufacturerSet; - } - - public Set addManufacturer(String manufacturer) { - manufacturerSet.add(manufacturer); - return manufacturerSet; - } - - public Set removeManufacturer(String manufacturer) { - manufacturerSet.remove(manufacturer); - return manufacturerSet; - } - - public Map> getManufacturerEventMap() { - return manufacturerEventMap; - } - - public void setManufacturerEventMap(Map> manufacturerEventMap) { - this.manufacturerEventMap = manufacturerEventMap; - } - - public List getManufacturerEvents(String manufacturerName) { - manufacturerEventMap.putIfAbsent(manufacturerName, new ArrayList()); - return manufacturerEventMap.get(manufacturerName); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfig.java b/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfig.java deleted file mode 100644 index 3f1d26c876..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfig.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.webhook.api; - -import lombok.Data; - -@Data -public class WebHookConfig { - - /** - * manufacturer callback path - */ - private String callbackPath; - - /** - * manufacturer name, like github - */ - private String manufacturerName; - - /** - * manufacturer domain name, like www.github.com - */ - private String manufacturerDomain; - - /** - * webhook event name, like rep-push - */ - private String manufacturerEventName; - - /** - * http header content type - */ - private String contentType = "application/json"; - - /** - * description of this WebHookConfig - */ - private String description; - - /** - * secret key, for authentication - */ - private String secret; - - /** - * userName, for HTTP authentication - */ - private String userName; - - /** - * password, for HTTP authentication - */ - private String password; - - /** - * roll out protocol, like HTTP/Kafka - */ - private String cloudEventProtocol; - - /** - * roll out addr - */ - private String cloudEventServiceAddress; - - /** - * roll out event name, like topic to MQ - */ - private String cloudEventName; - - /** - * roll out data format -> CloudEvent serialization mode If HTTP protocol is used, the request header contentType needs to be marked - */ - private String dataContentType = "application/json"; - - /** - * id of cloudEvent, like uuid/manufacturerEventId - */ - private String cloudEventIdGenerateMode = "manufacturerEventId"; -} diff --git a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfigOperation.java b/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfigOperation.java deleted file mode 100644 index e7f3fbc20d..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookConfigOperation.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.webhook.api; - -import java.util.List; - -/** - * This interface has three implementation classes, among which - * {@code FileWebHookConfigOperation} and {@code NacosWebHookConfigOperation} - * serve the {@code /webhook/deleteWebHookConfig} endpoint. - *

- * They correspond to the persistent configuration of {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig} - * for {@code file} and {@code Nacos}, respectively. - *

- * However, the {@code HookConfigOperationManager}, which is located in the {@code org.apache.eventmesh.webhook.receive.storage} - * package, differs from the other two implementations which are located in the {@code org.apache.eventmesh.webhook.admin} - * package. Refer to {@code QueryWebHookConfigByIdHandler} for the reasons and details. - */ -public interface WebHookConfigOperation { - - Integer insertWebHookConfig(WebHookConfig webHookConfig); - - Integer updateWebHookConfig(WebHookConfig webHookConfig); - - Integer deleteWebHookConfig(WebHookConfig webHookConfig); - - WebHookConfig queryWebHookConfigById(WebHookConfig webHookConfig); - - List queryWebHookConfigByManufacturer(WebHookConfig webHookConfig, Integer pageNum, - Integer pageSize); -} diff --git a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookOperationConstant.java b/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookOperationConstant.java deleted file mode 100644 index d4386ded28..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/WebHookOperationConstant.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.webhook.api; - -import org.apache.eventmesh.common.Constants; - -import java.io.File; - -public class WebHookOperationConstant { - - public static final String FILE_SEPARATOR = File.separator; - - public static final String FILE_EXTENSION = ".json"; - - public static final String GROUP_PREFIX = "webhook_"; - - public static final String CALLBACK_PATH_PREFIX = "/webhook"; - - public static final String DATA_ID_EXTENSION = ".json"; - - public static final String MANUFACTURERS_DATA_ID = "manufacturers" + DATA_ID_EXTENSION; - - public static final long TIMEOUT_MS = 3 * 1000L; - - public static final String OPERATION_MODE_FILE = "file"; - - public static final String OPERATION_MODE_NACOS = "nacos"; - - public static final String EVENTMESH_HOME = "#{eventMeshHome}"; - - public static String getFilePath(String filePath) { - if (filePath.startsWith(EVENTMESH_HOME)) { - String configPath = Constants.EVENTMESH_CONF_HOME; - - filePath = filePath.replace(EVENTMESH_HOME, configPath.substring(0, configPath.lastIndexOf(FILE_SEPARATOR))); - } - return filePath; - } - -} diff --git a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/common/SharedLatchHolder.java b/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/common/SharedLatchHolder.java deleted file mode 100644 index c59ff54b31..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/common/SharedLatchHolder.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.webhook.api.common; - -public class SharedLatchHolder { - - // secure the execution sequence of writeToFile and cacheInit - public static final Object lock = new Object(); - -} diff --git a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/utils/ClassUtils.java b/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/utils/ClassUtils.java deleted file mode 100644 index 4d19dd4845..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-api/src/main/java/org/apache/eventmesh/webhook/api/utils/ClassUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.webhook.api.utils; - -public class ClassUtils { - - public static String convertResourcePathToClassName(String path) { - return path.substring(1).replace('/', '.'); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/bin/.gitignore b/eventmesh-webhook/eventmesh-webhook-receive/bin/.gitignore deleted file mode 100644 index ddf9c65631..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/main/ diff --git a/eventmesh-webhook/eventmesh-webhook-receive/build.gradle b/eventmesh-webhook/eventmesh-webhook-receive/build.gradle deleted file mode 100644 index 061ec37a6a..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ - -dependencies { - - compileOnly project(":eventmesh-common") - implementation project(":eventmesh-protocol-plugin:eventmesh-protocol-api") - implementation project(":eventmesh-webhook:eventmesh-webhook-api") - implementation project(":eventmesh-storage-plugin:eventmesh-storage-api") - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - - implementation "io.openmessaging:openmessaging-api" - - implementation "io.cloudevents:cloudevents-core" - implementation "io.cloudevents:cloudevents-json-jackson" - implementation "com.alibaba.nacos:nacos-client" - implementation "com.fasterxml.jackson.core:jackson-databind" - implementation "com.fasterxml.jackson.core:jackson-core" - implementation "com.fasterxml.jackson.core:jackson-annotations" - - testImplementation project(":eventmesh-webhook:eventmesh-webhook-api") - - -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/gradle.properties b/eventmesh-webhook/eventmesh-webhook-receive/gradle.properties deleted file mode 100644 index a9fd83fea0..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/gradle.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# 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. -# \ No newline at end of file diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/ManufacturerProtocol.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/ManufacturerProtocol.java deleted file mode 100644 index 5f67307d7a..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/ManufacturerProtocol.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.webhook.receive; - -import org.apache.eventmesh.webhook.api.WebHookConfig; - -import java.util.Map; - -/** - * Information and protocol resolution methods for different manufacturers - */ -public interface ManufacturerProtocol { - - String getManufacturerName(); - - /** - * - 1.authentication - 2.parse webhook content to WebHookRequest - * - * @param webHookRequest formatted data - * @param webHookConfig webhook config - * @param header webhook content header - * @throws Exception authenticate failed ,or content parse failed - */ - void execute(WebHookRequest webHookRequest, WebHookConfig webHookConfig, Map header) throws Exception; -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookController.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookController.java deleted file mode 100644 index 217a3720b3..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookController.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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.webhook.receive; - -import org.apache.eventmesh.api.SendCallback; -import org.apache.eventmesh.api.SendResult; -import org.apache.eventmesh.api.exception.OnExceptionContext; -import org.apache.eventmesh.common.config.ConfigService; -import org.apache.eventmesh.common.protocol.ProtocolTransportObject; -import org.apache.eventmesh.common.protocol.http.WebhookProtocolTransportObject; -import org.apache.eventmesh.common.utils.LogUtil; -import org.apache.eventmesh.protocol.api.ProtocolAdaptor; -import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.receive.config.ReceiveConfiguration; -import org.apache.eventmesh.webhook.receive.protocol.ProtocolManager; -import org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager; - -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.UUID; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class WebHookController { - - private static final String PROTOCOL_ADAPTOR = "webhook"; - - private static final String CONTENT_TYPE = "content-type"; - - private static final String UUID_GENERATE_MODE = "uuid"; - - private static final String DOT = "."; - - /** - * protocol pool - */ - private final transient ProtocolManager protocolManager = new ProtocolManager(); - - /** - * config pool - */ - private transient HookConfigOperationManager hookConfigOperationManager; - - private transient WebHookMQProducer webHookMQProducer; - - private transient ProtocolAdaptor protocolAdaptor; - - private transient ReceiveConfiguration receiveConfiguration; - - public void init() throws Exception { - receiveConfiguration = ConfigService.getInstance().buildConfigInstance(ReceiveConfiguration.class); - Properties rootConfig = ConfigService.getInstance().getRootConfig(); - - this.webHookMQProducer = new WebHookMQProducer(rootConfig, receiveConfiguration.getStoragePluginType()); - this.hookConfigOperationManager = new HookConfigOperationManager(receiveConfiguration); - this.protocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(PROTOCOL_ADAPTOR); - } - - /** - * 1. get webhookConfig from path 2. get ManufacturerProtocol and execute 3. convert to cloudEvent obj 4. send cloudEvent - * - * @param path CallbackPath - * @param header map of webhook request header - * @param body data - * @throws Exception if any uncaught exception occurs during execution - */ - public void execute(String path, Map header, byte[] body) throws Exception { - - // 1. get webhookConfig from path - WebHookConfig webHookConfig = new WebHookConfig(); - webHookConfig.setCallbackPath(path); - webHookConfig = hookConfigOperationManager.queryWebHookConfigById(webHookConfig); - if (webHookConfig == null) { - throw new Exception("No matching webhookConfig."); - } - - if (!Objects.equals(webHookConfig.getContentType(), header.get(CONTENT_TYPE))) { - throw new Exception( - "http request header content-type value is mismatch. current value " + header.get(CONTENT_TYPE)); - } - - // 2. get ManufacturerProtocol and execute - String manufacturerName = webHookConfig.getManufacturerName(); - ManufacturerProtocol protocol = protocolManager.getManufacturerProtocol(manufacturerName); - WebHookRequest webHookRequest = new WebHookRequest(); - webHookRequest.setData(body); - try { - protocol.execute(webHookRequest, webHookConfig, header); - } catch (Exception e) { - throw new Exception("Webhook Message Parse Failed. " + e.getMessage(), e); - } - - // 3. convert to cloudEvent obj - String cloudEventId = UUID_GENERATE_MODE.equals(webHookConfig.getCloudEventIdGenerateMode()) ? UUID.randomUUID().toString() - : webHookRequest.getManufacturerEventId(); - String eventType = manufacturerName + DOT + webHookConfig.getManufacturerEventName(); - - WebhookProtocolTransportObject webhookProtocolTransportObject = WebhookProtocolTransportObject.builder() - .cloudEventId(cloudEventId).eventType(eventType).cloudEventName(webHookConfig.getCloudEventName()) - .cloudEventSource(webHookConfig.getManufacturerDomain()) - .dataContentType(webHookConfig.getDataContentType()).body(body).build(); - - // 4. send cloudEvent - webHookMQProducer.send(this.protocolAdaptor.toCloudEvent(webhookProtocolTransportObject), new SendCallback() { - - @Override - public void onSuccess(SendResult sendResult) { - LogUtil.debug(log, "{}", sendResult::toString); - } - - @Override - public void onException(OnExceptionContext context) { - log.warn("", context.getException()); - } - - }); - } - -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookMQProducer.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookMQProducer.java deleted file mode 100644 index 9cda2154ff..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookMQProducer.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.webhook.receive; - -import org.apache.eventmesh.api.RequestReplyCallback; -import org.apache.eventmesh.api.SendCallback; -import org.apache.eventmesh.api.factory.StoragePluginFactory; -import org.apache.eventmesh.api.producer.Producer; - -import java.util.Objects; -import java.util.Properties; - -import io.cloudevents.CloudEvent; - -public class WebHookMQProducer { - - private transient Producer hookMQProducer; - - public WebHookMQProducer(final Properties properties, String storagePluginType) throws Exception { - this.hookMQProducer = StoragePluginFactory.getMeshMQProducer(storagePluginType); - Objects.requireNonNull(hookMQProducer, "doesn't load the hookMQProducer plugin, please check."); - - this.hookMQProducer.init(properties); - } - - public void send(final CloudEvent cloudEvent, final SendCallback sendCallback) throws Exception { - Objects.requireNonNull(cloudEvent, "cloudEvent can not be null"); - - hookMQProducer.publish(cloudEvent, sendCallback); - } - - public void request(final CloudEvent cloudEvent, final RequestReplyCallback rrCallback, final long timeout) - throws Exception { - Objects.requireNonNull(cloudEvent, "cloudEvent can not be null"); - - hookMQProducer.request(cloudEvent, rrCallback, timeout); - } - - public boolean reply(final CloudEvent cloudEvent, final SendCallback sendCallback) throws Exception { - Objects.requireNonNull(cloudEvent, "cloudEvent can not be null"); - - return hookMQProducer.reply(cloudEvent, sendCallback); - } - - public Producer getHookMQProducer() { - return hookMQProducer; - } - -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookRequest.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookRequest.java deleted file mode 100644 index 7fdc78bd86..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/WebHookRequest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.webhook.receive; - -import lombok.Data; - -@Data -public class WebHookRequest { - - /** - * manufacturer event id - */ - private String manufacturerEventId; - - /** - * manufacturer event name - */ - private String manufacturerEventName; - - /** - * manufacturer name - */ - private String manufacturerSource; - - /** - * webhook request body - */ - private byte[] data; -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java deleted file mode 100644 index fef6cee41b..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.webhook.receive.config; - -import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigField; - -import java.util.Properties; - -import lombok.Data; - -@Data -@Config(prefix = "eventMesh.webHook") -public class ReceiveConfiguration { - - @ConfigField(field = "producer.storage") - private String storagePluginType; - - @ConfigField(field = "operationMode") - private String operationMode; - - @ConfigField(field = "fileMode.filePath") - private String filePath; - - @ConfigField(field = "", reload = true) - private Properties operationProperties; - - public void reload() { - processOperationProperties(); - } - - public void processOperationProperties() { - final String prefix = operationMode + "Mode"; - this.operationProperties = (Properties) operationProperties.get(prefix); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/GithubProtocol.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/GithubProtocol.java deleted file mode 100644 index ce6fa22fe5..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/GithubProtocol.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.webhook.receive.protocol; - -import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.receive.ManufacturerProtocol; -import org.apache.eventmesh.webhook.receive.WebHookRequest; - -import java.util.Map; -import java.util.stream.IntStream; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class GithubProtocol implements ManufacturerProtocol { - - private static final String MANU_FACTURER_NAME = "github"; - - private static final String FROM_SIGNATURE = "x-hub-signature-256"; - - private static final String MANU_FACTURER_EVENT_ID = "x-github-delivery"; - - private static final String HASH = "sha256="; - - private static final String H_MAC_SHA = "HmacSHA256"; - - private static final char ZERO_CHAR = '0'; - - @Override - public String getManufacturerName() { - return MANU_FACTURER_NAME; - } - - @Override - public void execute(final WebHookRequest webHookRequest, final WebHookConfig webHookConfig, - final Map header) throws Exception { - - final String fromSignature = header.get(FROM_SIGNATURE); - if (Boolean.FALSE.equals(isValid(fromSignature, webHookRequest.getData(), webHookConfig.getSecret()))) { - throw new Exception("webhook-GithubProtocol authenticate failed"); - } - - try { - webHookRequest.setManufacturerEventId(header.get(MANU_FACTURER_EVENT_ID)); - webHookRequest.setManufacturerEventName(webHookConfig.getManufacturerEventName()); - webHookRequest.setManufacturerSource(getManufacturerName()); - } catch (Exception e) { - throw new Exception("webhook-GithubProtocol parse failed", e); - } - } - - /** - * Authentication - * - * @param fromSignature Signature received - * @param data data - * @param secret secret key - * @return Authentication result - */ - private Boolean isValid(String fromSignature, byte[] data, String secret) { - String hash = HASH; - try { - Mac sha = Mac.getInstance(H_MAC_SHA); - SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(Constants.DEFAULT_CHARSET), H_MAC_SHA); - sha.init(secretKey); - byte[] bytes = sha.doFinal(data); - hash += byteArrayToHexString(bytes); - } catch (Exception e) { - log.error("Error HmacSHA256", e); - } - return hash.equals(fromSignature); - } - - /** - * byte array -> hexadecimal character string - * - * @param b byte array - * @return hexadecimal character string - */ - private String byteArrayToHexString(byte[] b) { - if (b == null) { - return ""; - } - - final StringBuilder hs = new StringBuilder(); - - IntStream.range(0, b.length).forEach(i -> { - String stmp = Integer.toHexString(b[i] & 0XFF); - if (stmp.length() == 1) { - hs.append(ZERO_CHAR); - } - hs.append(stmp); - }); - - return hs.toString().toLowerCase(); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/ProtocolManager.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/ProtocolManager.java deleted file mode 100644 index ee31d78d3c..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/protocol/ProtocolManager.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.webhook.receive.protocol; - -import org.apache.eventmesh.webhook.receive.ManufacturerProtocol; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -public class ProtocolManager { - - /** - * ManufacturerProtocol pool - */ - private final transient Map protocolMap = new HashMap<>(); - - { - this.register(new GithubProtocol()); - } - - void register(final ManufacturerProtocol manufacturerProtocol) { - Objects.requireNonNull(manufacturerProtocol, "manufacturerProtocol can not be null"); - - protocolMap.put(manufacturerProtocol.getManufacturerName(), manufacturerProtocol); - } - - public ManufacturerProtocol getManufacturerProtocol(final String manufacturerName) { - return protocolMap.get(manufacturerName); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/AbstractWebHookConfigOperation.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/AbstractWebHookConfigOperation.java deleted file mode 100644 index bdb1e4c1cf..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/AbstractWebHookConfigOperation.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.webhook.receive.storage; - -public abstract class AbstractWebHookConfigOperation { - -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/HookConfigOperationManager.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/HookConfigOperationManager.java deleted file mode 100644 index d700715d9d..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/HookConfigOperationManager.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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.webhook.receive.storage; - -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.DATA_ID_EXTENSION; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.GROUP_PREFIX; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.OPERATION_MODE_FILE; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.OPERATION_MODE_NACOS; -import static org.apache.eventmesh.webhook.api.WebHookOperationConstant.TIMEOUT_MS; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookConfigOperation; -import org.apache.eventmesh.webhook.api.utils.ClassUtils; -import org.apache.eventmesh.webhook.receive.config.ReceiveConfiguration; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; - -import com.alibaba.nacos.api.config.ConfigFactory; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.exception.NacosException; - -import lombok.extern.slf4j.Slf4j; - -/** - * This class manages the operations related to WebHook configurations. Mainly used by - * {@linkplain org.apache.eventmesh.webhook.receive.WebHookController#execute WebHookController} - * to retrieve existing WebHook configuration by callback path when processing received WebHook data from manufacturers. - *

- * This class is initialized together with the {@linkplain org.apache.eventmesh.webhook.receive.WebHookController WebHookController} - * during the initialization phase of the {@code EventMeshHTTPServer}. - * - * @see WebHookConfigOperation - */ - -@Slf4j -public class HookConfigOperationManager implements WebHookConfigOperation { - - /** - * webhook config pool -> key is CallbackPath - */ - private final transient Map cacheWebHookConfig = new ConcurrentHashMap<>(); - private transient String operationMode; - private transient ConfigService nacosConfigService; - - public HookConfigOperationManager() { - } - - /** - * Initialize according to operation mode. - *

- * OPERATION_MODE_FILE: The WebHook configurations are read from a file specified by the filePath. - * OPERATION_MODE_NACOS: The WebHook configurations are fetched from a Nacos configuration service - * using the properties specified in operationProperties. - * - * @param receiveConfiguration The ReceiveConfiguration object containing the operation mode and related properties. - * @throws NacosException If there is an error with the Nacos configuration service. - */ - public HookConfigOperationManager(final ReceiveConfiguration receiveConfiguration) throws NacosException { - - this.operationMode = receiveConfiguration.getOperationMode(); - - switch (operationMode) { - case OPERATION_MODE_FILE: - new WebhookFileListener(receiveConfiguration.getFilePath(), cacheWebHookConfig); - break; - case OPERATION_MODE_NACOS: - nacosModeInit(receiveConfiguration.getOperationProperties()); - break; - default: - break; - } - } - - private void nacosModeInit(final Properties config) throws NacosException { - nacosConfigService = ConfigFactory.createConfigService(config); - } - - /** - * Retrieves a WebHook configuration according to its WebHook callback path in - * {@linkplain org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}. - * - * @param webHookConfig The WebHookConfig object containing the callback path. - * @return The retrieved WebHookConfig object which contains full configuration. - */ - @Override - public WebHookConfig queryWebHookConfigById(final WebHookConfig webHookConfig) { - switch (operationMode) { - case OPERATION_MODE_FILE: - return cacheWebHookConfig.get(ClassUtils.convertResourcePathToClassName(webHookConfig.getCallbackPath())); - case OPERATION_MODE_NACOS: - try { - final String content = nacosConfigService.getConfig( - webHookConfig.getManufacturerEventName() + DATA_ID_EXTENSION, - GROUP_PREFIX + webHookConfig.getManufacturerName(), - TIMEOUT_MS); - return JsonUtils.parseObject(content, WebHookConfig.class); - } catch (NacosException e) { - log.error("queryWebHookConfigById failed", e); - } - break; - default: - break; - } - return null; - } - - /** - * Retrieves a list of WebHook configurations for a specific manufacturer. - * - * @param webHookConfig The WebHookConfig object containing the manufacturer name. - * @param pageNum The page number for pagination. - * @param pageSize The page size for pagination. - * @return The list of WebHookConfig objects which each contains full configuration. - */ - @Override - public List queryWebHookConfigByManufacturer(final WebHookConfig webHookConfig, - final Integer pageNum, - final Integer pageSize) { - return new ArrayList(); - } - - /** - * Inserts a new WebHook configuration into the cache. - * - * @param webHookConfig The WebHookConfig object to insert. - * @return The result code indicating the success of the operation. - */ - @Override - public Integer insertWebHookConfig(final WebHookConfig webHookConfig) { - cacheWebHookConfig.put(webHookConfig.getCallbackPath(), webHookConfig); - return 1; - } - - /** - * Updates an existing WebHook configuration in the cache. - * - * @param webHookConfig The WebHookConfig object to update. - * @return The result code indicating the success of the operation. - */ - @Override - public Integer updateWebHookConfig(final WebHookConfig webHookConfig) { - cacheWebHookConfig.put(webHookConfig.getCallbackPath(), webHookConfig); - return 1; - } - - /** - * Deletes a WebHook configuration from the cache. - * - * @param webHookConfig The WebHookConfig object to delete. - * @return The result code indicating the success of the operation. - */ - @Override - public Integer deleteWebHookConfig(final WebHookConfig webHookConfig) { - cacheWebHookConfig.remove(webHookConfig.getCallbackPath()); - return 1; - } - -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java deleted file mode 100644 index e5af8501b5..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/storage/WebhookFileListener.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * 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.webhook.receive.storage; - -import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; -import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; -import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; - -import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.webhook.api.WebHookConfig; -import org.apache.eventmesh.webhook.api.WebHookOperationConstant; -import org.apache.eventmesh.webhook.api.common.SharedLatchHolder; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.WatchEvent; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class WebhookFileListener { - - private final transient Set pathSet = new LinkedHashSet<>(); // monitored subdirectory - private final transient Map watchKeyPathMap = new ConcurrentHashMap<>(); // WatchKey's path - private transient String filePath; - private final transient Map cacheWebHookConfig; - - public WebhookFileListener(final String filePath, final Map cacheWebHookConfig) { - this.filePath = WebHookOperationConstant.getFilePath(filePath); - this.cacheWebHookConfig = cacheWebHookConfig; - filePatternInit(); - } - - /** - * Read the directory and register the listener - */ - private void filePatternInit() { - final File webHookFileDir = new File(filePath); - if (!webHookFileDir.exists()) { - webHookFileDir.mkdirs(); - } else { - readFiles(webHookFileDir); - } - - fileWatchRegister(); - } - - /** - * Recursively traverse the folder - * - * @param file file - */ - private void readFiles(final File file) { - final File[] fs = file.listFiles(); - for (final File f : Objects.requireNonNull(fs)) { - if (f.isDirectory()) { - readFiles(f); - } else if (f.isFile()) { - cacheInit(f); - } - } - } - - /** - * Read the file and cache it in local map for manufacturers webhook payload delivery - *

- * A shared lock is used to ensure that this method should be invoked after the {@code webhookConfigFile} is written completely - * by {@code org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation#writeToFile} when multiple modify events are triggered. - * - * @param webhookConfigFile webhookConfigFile - */ - private void cacheInit(final File webhookConfigFile) { - final StringBuilder fileContent = new StringBuilder(); - try (BufferedReader br = Files.newBufferedReader(Paths.get(webhookConfigFile.getAbsolutePath()), StandardCharsets.UTF_8)) { - while (br.ready()) { - fileContent.append(br.readLine()); - } - } catch (IOException e) { - log.error("cacheInit buffer read failed", e); - } - final WebHookConfig webHookConfig = JsonUtils.parseObject(fileContent.toString(), WebHookConfig.class); - cacheWebHookConfig.put(webhookConfigFile.getName(), webHookConfig); - } - - public void deleteConfig(final File webhookConfigFile) { - cacheWebHookConfig.remove(webhookConfigFile.getName()); - } - - /** - * Register listeners with folders - */ - private void fileWatchRegister() { - final ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1); - cachedThreadPool.execute(() -> { - final File root = new File(filePath); - loopDirInsertToSet(root, pathSet); - - WatchService service = null; - try { - service = FileSystems.getDefault().newWatchService(); - } catch (Exception e) { - log.error("getWatchService failed.", e); - } - - for (final String path : pathSet) { - WatchKey key = null; - try { - key = Paths.get(path).register(service, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); - } catch (IOException e) { - log.error("registerWatchKey failed", e); - } - watchKeyPathMap.put(key, path); - } - - while (true) { - WatchKey key = null; - try { - assert service != null; - // The code will block here until a file system event occurs - key = service.take(); - } catch (InterruptedException e) { - log.error("Interrupted", e); - Thread.currentThread().interrupt(); - } - - assert key != null; - // A newly created config file will be captured for two events, ENTRY_CREATE and ENTRY_MODIFY - for (final WatchEvent event : key.pollEvents()) { - final String flashPath = watchKeyPathMap.get(key); - // manufacturer change - final String path = flashPath.concat(WebHookOperationConstant.FILE_SEPARATOR).concat(event.context().toString()); - final File file = new File(path); - // Wait for file write/delete completion before initializing the cache - synchronized (SharedLatchHolder.lock) { - if (file.isDirectory() && (ENTRY_CREATE == event.kind() || ENTRY_MODIFY == event.kind())) { - // If it is a folder, re-register the listener - try { - key = Paths.get(path).register(service, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); - watchKeyPathMap.put(key, path); - } catch (IOException e) { - log.error("registerWatchKey failed", e); - } - } else if (file.isFile() && ENTRY_MODIFY == event.kind()) { - // If it is a file, cache it only when it is modified to wait for complete file writes - try { - cacheInit(file); - } catch (Exception e) { - log.error("cacheInit failed", e); - } - } else if (ENTRY_DELETE == event.kind()) { - if (file.isDirectory()) { - watchKeyPathMap.remove(key); - } else { - deleteConfig(file); - } - } - } - } - // Reset the WatchKey to receive subsequent file system events - if (!key.reset()) { - break; - } - } - }); - } - - /** - * Recursive folder, adding folder's path to set - * - * @param parent parent folder - * @param pathSet folder's path set - */ - private void loopDirInsertToSet(final File parent, final Set pathSet) { - if (!parent.isDirectory()) { - return; - } - pathSet.add(parent.getPath()); - for (final File child : Objects.requireNonNull(parent.listFiles())) { - loopDirInsertToSet(child, pathSet); - } - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/test/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfigurationTest.java b/eventmesh-webhook/eventmesh-webhook-receive/src/test/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfigurationTest.java deleted file mode 100644 index 1b1390dfb9..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/test/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfigurationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.webhook.receive.config; - -import org.apache.eventmesh.common.config.ConfigService; - -import java.util.Properties; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class ReceiveConfigurationTest { - - @Test - public void testGetReceiveConfiguration() throws Exception { - - ConfigService configService = ConfigService.getInstance(); - configService.setRootConfig("classPath://eventmesh.properties"); - - Properties rootConfig = ConfigService.getInstance().getRootConfig(); - Assertions.assertEquals("DEFAULT", rootConfig.get("eventMesh.server.idc")); - - ReceiveConfiguration config = configService.buildConfigInstance(ReceiveConfiguration.class); - assertReceiveConfiguration(config); - } - - private void assertReceiveConfiguration(ReceiveConfiguration config) { - Assertions.assertEquals("nacos", config.getOperationMode()); - - Properties properties = new Properties(); - properties.put("serverAddr", "127.0.0.1:8848"); - Assertions.assertEquals(properties, config.getOperationProperties()); - Assertions.assertEquals("standalone", config.getStoragePluginType()); - Assertions.assertEquals(".", config.getFilePath()); - } -} diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/test/resources/eventmesh.properties b/eventmesh-webhook/eventmesh-webhook-receive/src/test/resources/eventmesh.properties deleted file mode 100644 index bd700c26c9..0000000000 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/test/resources/eventmesh.properties +++ /dev/null @@ -1,30 +0,0 @@ -# -# 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. -# -eventMesh.server.idc=DEFAULT - -# webhook -# Start webhook admin service -eventMesh.webHook.admin.start=true -# Webhook event configuration storage mode. Currently, only file and Nacos are supported -eventMesh.webHook.operationMode=nacos -# The file storage path of the file storage mode. If #{eventmeshhome} is written, it is in the eventmesh root directory -eventMesh.webHook.fileMode.filePath=. -# Nacos storage mode, and the configuration naming rule is eventmesh webHook. nacosMode. {nacos native configuration key} please see the specific configuration [nacos github api](https://github.com/alibaba/nacos/blob/develop/api/src/main/java/com/alibaba/nacos/api/SystemPropertyKeyConst.java) -## Address of Nacos -eventMesh.webHook.nacosMode.serverAddr=127.0.0.1:8848 -# Webhook CloudEvent sending mode. This property is the same as the eventMesh.storage.plugin.type configuration. -eventMesh.webHook.producer.storage=standalone diff --git a/eventmesh-webhook/gradle.properties b/eventmesh-webhook/gradle.properties deleted file mode 100644 index a9fd83fea0..0000000000 --- a/eventmesh-webhook/gradle.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# 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. -# \ No newline at end of file diff --git a/eventmesh-webhook/webhook.jmx b/eventmesh-webhook/webhook.jmx deleted file mode 100644 index 9bc56e8073..0000000000 --- a/eventmesh-webhook/webhook.jmx +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - false - true - false - - - - - - - - continue - - false - 1 - - 1 - 1 - false - - - - - - - - content-type - application/json - - - - - - true - - - - false - { -"callbackPath":"/webhook/test", -"manufacturerName":"1111" -} - = - - - - 127.0.0.1 - 10106 - - - /webhook/insertWebHookConfig - POST - true - false - true - false - - - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - false - true - false - false - false - true - 0 - true - true - true - true - true - true - - - - - - - - - diff --git a/settings.gradle b/settings.gradle index c49a5c4242..070d4f02dc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -103,7 +103,6 @@ include 'eventmesh-protocol-plugin:eventmesh-protocol-openmessage' include 'eventmesh-protocol-plugin:eventmesh-protocol-cloudevents' include 'eventmesh-protocol-plugin:eventmesh-protocol-meshmessage' include 'eventmesh-protocol-plugin:eventmesh-protocol-http' -include 'eventmesh-protocol-plugin:eventmesh-protocol-webhook' include 'eventmesh-protocol-plugin:eventmesh-protocol-grpc' include 'eventmesh-protocol-plugin:eventmesh-protocol-grpcmessage' @@ -117,11 +116,6 @@ include 'eventmesh-trace-plugin:eventmesh-trace-zipkin' include 'eventmesh-trace-plugin:eventmesh-trace-pinpoint' include 'eventmesh-trace-plugin:eventmesh-trace-jaeger' -include 'eventmesh-webhook' -include 'eventmesh-webhook:eventmesh-webhook-api' -include 'eventmesh-webhook:eventmesh-webhook-admin' -include 'eventmesh-webhook:eventmesh-webhook-receive' - include 'eventmesh-retry' include 'eventmesh-retry:eventmesh-retry-api' include 'eventmesh-retry:eventmesh-retry-rocketmq' @@ -134,5 +128,4 @@ include 'eventmesh-registry:eventmesh-registry-nacos' include 'eventmesh-function' include 'eventmesh-function:eventmesh-function-api' include 'eventmesh-function:eventmesh-function-filter' -include 'eventmesh-function:eventmesh-function-transformer' - +include 'eventmesh-function:eventmesh-function-transformer' \ No newline at end of file