This is an automated email from the ASF dual-hosted git repository.
mxsm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 81eacbd70 [ISSUE #4211] Add JavaDoc for eventmesh.runtime.admin APIs
(not in dashboard) (#4272)
81eacbd70 is described below
commit 81eacbd705668d994c869f7a18eae1dc4476ea68
Author: Pil0tXia <[email protected]>
AuthorDate: Thu Jul 27 09:20:13 2023 +0800
[ISSUE #4211] Add JavaDoc for eventmesh.runtime.admin APIs (not in
dashboard) (#4272)
* doc: Add JavaDoc for ClientManageController
* doc: Add JavaDoc for HttpHandlerManager
* doc: Add JavaDoc for AbstractHttpHandler
* doc: Add JavaDoc for ConfigurationHandler
* doc: Add JavaDoc for MetricsHandler
* doc: Add JavaDoc for RegistryHandler
* doc: Add JavaDoc for TopicHandler
* doc: Add JavaDoc for EventHandler
* doc: Add JavaDoc for TCPClientHandler
* doc: Add JavaDoc for HTTPClientHandler
* doc: Add JavaDoc for GrpcClientHandler
* doc: Add JavaDoc for HookConfigOperationManager (Outside)
* doc: Add JavaDoc for InsertWebHookConfigHandler
* doc: Add JavaDoc for UpdateWebHookConfigHandler
* doc: Add JavaDoc for DeleteWebHookConfigHandler
* doc: Update JavaDoc for QueryWebHookConfigByIdHandler (WIP)
* Breaking Change: Update JavaDoc for HookConfigOperationManager
* Breaking Change: Update JavaDoc for QueryWebHookConfigByIdHandler
* doc: Update JavaDoc for InsertWebHookConfigHandler
* doc: Update JavaDoc for UpdateWebHookConfigHandler
* doc: Update JavaDoc for DeleteWebHookConfigHandler
* doc: Add JavaDoc for QueryWebHookConfigByManufacturerHandler
* doc: Add JavaDoc for QueryRecommendEventMeshHandler
* doc: Add JavaDoc for RedirectClientByIpPortHandler
* doc: Add JavaDoc for RedirectClientByPathHandler and multiple minor
changes
* doc: Add JavaDoc for RedirectClientBySubSystemHandler
* doc: Add JavaDoc for RejectClientByIpPortHandler
* doc: Add JavaDoc for RejectClientBySubSystemHandler
* doc: Add JavaDoc for RejectAllClientHandler
* doc: Add JavaDoc for ShowClientBySystemHandler
* doc: Add JavaDoc for ShowListenClientByTopicHandler and multiple minor
changes
* doc: Add JavaDoc for ShowClientHandler and multiple minor changes
* fix: Remove redundant throw and its JavaDoc
* fix: redundant import and formatting
* feat: Streamline and Reduce existing single-line comments
* Optimize: Explain more clearly why HookConfigOperationManager is not used
in UpdateWebHookConfigHandler
* Optimze: Explain HookConfigOperationManager more clearly in
WebHookConfigOperation
* Optimize: Concise the implement of handle()
* Optimze: Remove some relatively simple comments
* Fix: CI report reference not found
---
.../admin/handler/DeleteWebHookConfigHandler.java | 44 ++++++++++++++++--
.../admin/handler/InsertWebHookConfigHandler.java | 41 ++++++++++++++++-
.../handler/QueryRecommendEventMeshHandler.java | 30 +++++++++++-
.../handler/QueryWebHookConfigByIdHandler.java | 47 ++++++++++++++++++-
.../QueryWebHookConfigByManufacturerHandler.java | 42 ++++++++++++++++-
.../handler/RedirectClientByIpPortHandler.java | 49 +++++++++++++++++---
.../admin/handler/RedirectClientByPathHandler.java | 39 ++++++++++++++--
.../handler/RedirectClientBySubSystemHandler.java | 36 ++++++++++++++-
.../admin/handler/RejectAllClientHandler.java | 27 +++++++++--
.../admin/handler/RejectClientByIpPortHandler.java | 39 +++++++++++++++-
.../handler/RejectClientBySubSystemHandler.java | 36 +++++++++++++--
.../admin/handler/ShowClientBySystemHandler.java | 30 ++++++++++--
.../runtime/admin/handler/ShowClientHandler.java | 24 +++++++++-
.../handler/ShowListenClientByTopicHandler.java | 29 +++++++++++-
.../admin/handler/UpdateWebHookConfigHandler.java | 42 ++++++++++++++++-
.../admin/AdminWebHookConfigOperationManager.java | 2 +-
.../webhook/admin/FileWebHookConfigOperation.java | 3 ++
.../webhook/admin/NacosWebHookConfigOperation.java | 3 ++
.../eventmesh/webhook/api/WebHookConfig.java | 16 +++----
.../webhook/api/WebHookConfigOperation.java | 11 ++++-
.../webhook/receive/WebHookController.java | 1 +
.../storage/HookConfigOperationManager.java | 53 +++++++++++++++++++++-
22 files changed, 599 insertions(+), 45 deletions(-)
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java
index b43df2fcf..592225ef9 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java
@@ -33,6 +33,30 @@ import com.sun.net.httpserver.HttpExchange;
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}.
+ * <p>
+ * 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}.
+ * <p>
+ * 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;
+ * <p>
+ * 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.
+ * <p>
+ * 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
@EventHttpHandler(path = "/webhook/deleteWebHookConfig")
@@ -40,22 +64,36 @@ public class DeleteWebHookConfigHandler extends
AbstractHttpHandler {
private final WebHookConfigOperation operation;
+ /**
+ * Constructs a new instance with the specified WebHook config operation
and HTTP handler manager.
+ *
+ * @param operation the WebHookConfigOperation implementation used to
delete the WebHook config
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public DeleteWebHookConfigHandler(WebHookConfigOperation operation,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.operation = operation;
}
-
+ /**
+ * Handles requests by deleting a WebHook configuration.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ *
+ * @see
org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#deleteWebHookConfig
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
NetUtils.sendSuccessResponseHeaders(httpExchange);
- // get requestBody and resolve to WebHookConfig
+ // Resolve to WebHookConfig
String requestBody = NetUtils.parsePostBody(httpExchange);
WebHookConfig webHookConfig = JsonUtils.parseObject(requestBody,
WebHookConfig.class);
try (OutputStream out = httpExchange.getResponseBody()) {
-
+ // Delete the existing WebHookConfig
Integer code = operation.deleteWebHookConfig(webHookConfig); //
operating result
String result = 1 == code ? "deleteWebHookConfig Succeed!" :
"deleteWebHookConfig Failed!";
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java
index dfbfd9f26..d361dd6df 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java
@@ -33,6 +33,31 @@ import com.sun.net.httpserver.HttpExchange;
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.
+ * <p>
+ * 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}.
+ * <p>
+ * 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;
+ * <p>
+ * 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.
+ * <p>
+ * 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
@EventHttpHandler(path = "/webhook/insertWebHookConfig")
@@ -40,20 +65,34 @@ public class InsertWebHookConfigHandler extends
AbstractHttpHandler {
private final WebHookConfigOperation operation;
+ /**
+ * Constructs a new instance with the specified WebHook config operation
and HTTP handler manager.
+ *
+ * @param operation the WebHookConfigOperation implementation used to
insert the WebHook config
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public InsertWebHookConfigHandler(WebHookConfigOperation operation,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.operation = operation;
}
+ /**
+ * Handles requests by adding a WebHook configuration.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
NetUtils.sendSuccessResponseHeaders(httpExchange);
- // get requestBody and resolve to WebHookConfig
+ // Resolve to WebHookConfig
String requestBody = NetUtils.parsePostBody(httpExchange);
WebHookConfig webHookConfig = JsonUtils.parseObject(requestBody,
WebHookConfig.class);
try (OutputStream out = httpExchange.getResponseBody()) {
+ // 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!";
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java
index 18741c7e5..5d35cc553 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java
@@ -38,7 +38,19 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
/**
- * query recommend eventmesh
+ * This class handles the HTTP requests of {@code /eventMesh/recommend}
endpoint,
+ * which is used to calculate and return the recommended EventMesh server node
to the client
+ * based on the provided {@code group} and {@code purpose} parameters.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client group: {@code group} | Example: {@code
EventmeshTestGroup}</li>
+ * <li>client purpose: {@code purpose} | Example: {@code sub}</li>
+ * </ul>
+ * It uses an {@link EventMeshRecommendStrategy} which is implemented by
{@link EventMeshRecommendImpl}
+ * to calculate the recommended EventMesh server node.
+ *
+ * @see AbstractHttpHandler
*/
@Slf4j
@EventHttpHandler(path = "/eventMesh/recommend")
@@ -46,11 +58,24 @@ public class QueryRecommendEventMeshHandler extends
AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public QueryRecommendEventMeshHandler(EventMeshTCPServer
eventMeshTCPServer, HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by calculating a recommended EventMesh server node.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String result = "";
@@ -60,8 +85,10 @@ public class QueryRecommendEventMeshHandler extends
AbstractHttpHandler {
}
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameters from the query string
String group =
queryStringInfo.get(EventMeshConstants.MANAGE_GROUP);
String purpose =
queryStringInfo.get(EventMeshConstants.MANAGE_PURPOSE);
+ // Check the validity of the parameters
if (StringUtils.isBlank(group) || StringUtils.isBlank(purpose)) {
NetUtils.sendSuccessResponseHeaders(httpExchange);
result = "params illegal!";
@@ -70,6 +97,7 @@ public class QueryRecommendEventMeshHandler extends
AbstractHttpHandler {
}
EventMeshRecommendStrategy eventMeshRecommendStrategy = new
EventMeshRecommendImpl(eventMeshTCPServer);
+ // Calculate the recommended EventMesh node according to the given
group and purpose
String recommendEventMeshResult =
eventMeshRecommendStrategy.calculateRecommendEventMesh(group, purpose);
result = (recommendEventMeshResult == null) ? "null" :
recommendEventMeshResult;
log.info("recommend eventmesh:{},group:{},purpose:{}", result,
group, purpose);
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java
index 35ea9a671..968d94677 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java
@@ -36,6 +36,36 @@ import com.sun.net.httpserver.HttpExchange;
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}.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>WebHook callback path: {@code callbackPath} | Example: {@code
/webhook/github/eventmesh/all}</li>
+ * <li>WebHook manufacturer name: {@code manufacturerName} | Example:
{@code github}</li>
+ * </ul>
+ * 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}.
+ * <p>
+ * 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;
+ * <p>
+ * 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.
+ * <p>
+ * 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
@EventHttpHandler(path = "/webhook/queryWebHookConfigById")
@@ -43,22 +73,35 @@ public class QueryWebHookConfigByIdHandler extends
AbstractHttpHandler {
private final WebHookConfigOperation operation;
+ /**
+ * Constructs a new instance with the specified WebHook config operation
and HTTP handler manager.
+ *
+ * @param operation the WebHookConfigOperation implementation used to
query the WebHook config
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public QueryWebHookConfigByIdHandler(WebHookConfigOperation operation,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.operation = operation;
}
-
+ /**
+ * Handles requests by retrieving a WebHook configuration.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
NetUtils.sendSuccessResponseHeaders(httpExchange);
httpExchange.getResponseHeaders().add(CONTENT_TYPE, APPLICATION_JSON);
- // get requestBody and resolve to WebHookConfig
+ // Resolve to WebHookConfig
String requestBody = NetUtils.parsePostBody(httpExchange);
WebHookConfig webHookConfig = JsonUtils.parseObject(requestBody,
WebHookConfig.class);
try (OutputStream out = httpExchange.getResponseBody()) {
+ // Retrieve the WebHookConfig by callback path
WebHookConfig result =
operation.queryWebHookConfigById(webHookConfig); // operating result
out.write(Objects.requireNonNull(JsonUtils.toJSONString(result)).getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java
index 3a16cce36..7301ecd7d 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java
@@ -39,6 +39,31 @@ import com.sun.net.httpserver.HttpExchange;
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}.
+ * <p>
+ * 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}.
+ * <p>
+ * 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;
+ * <p>
+ * 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.
+ * <p>
+ * 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
@EventHttpHandler(path = "/webhook/queryWebHookConfigByManufacturer")
@@ -46,6 +71,13 @@ public class QueryWebHookConfigByManufacturerHandler extends
AbstractHttpHandler
private final transient WebHookConfigOperation operation;
+ /**
+ * Constructs a new instance with the specified WebHook config operation
and HTTP handler manager.
+ *
+ * @param operation the WebHookConfigOperation implementation used to
query the WebHook config
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public QueryWebHookConfigByManufacturerHandler(WebHookConfigOperation
operation,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
@@ -55,7 +87,12 @@ public class QueryWebHookConfigByManufacturerHandler extends
AbstractHttpHandler
}
-
+ /**
+ * Handles requests by retrieving a list of WebHook configurations.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
Objects.requireNonNull(httpExchange, "httpExchange can not be null");
@@ -63,7 +100,7 @@ public class QueryWebHookConfigByManufacturerHandler extends
AbstractHttpHandler
NetUtils.sendSuccessResponseHeaders(httpExchange);
httpExchange.getResponseHeaders().add(CONTENT_TYPE, APPLICATION_JSON);
- // get requestBody and resolve to WebHookConfig
+ // Resolve to WebHookConfig
JsonNode node =
JsonUtils.getJsonNode(NetUtils.parsePostBody(httpExchange));
Objects.requireNonNull(node, "JsonNode can not be null");
@@ -72,6 +109,7 @@ public class QueryWebHookConfigByManufacturerHandler extends
AbstractHttpHandler
Integer pageSize = Integer.valueOf(node.get("pageSize").toString());
try (OutputStream out = httpExchange.getResponseBody()) {
+ // Retrieve the WebHookConfig list by manufacturer name
List<WebHookConfig> result =
operation.queryWebHookConfigByManufacturer(webHookConfig, pageNum, pageSize);
// operating result
out.write(Objects.requireNonNull(JsonUtils.toJSONString(result)).getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java
index b886e8b62..75be8fa07 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java
@@ -40,28 +40,62 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
+/**
+ * This class handles the HTTP requests of {@code
/clientManage/redirectClientByIpPort} endpoint,
+ * which is used to redirect matching clients to a target EventMesh server node
+ * based on the provided IP address and port.
+ * <p>
+ * The request must specify the client's and target EventMesh node's IP and
port.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client's IP: {@code ip}</li>
+ * <li>client's port: {@code port}</li>
+ * <li>target EventMesh node's IP: {@code desteventmeshIp}</li>
+ * <li>target EventMesh node's port: {@code desteventmeshport}</li>
+ * </ul>
+ * It uses the {@link EventMeshTcp2Client#redirectClient2NewEventMesh} method
to redirect the matching client.
+ *
+ * @see AbstractHttpHandler
+ */
+
@Slf4j
@EventHttpHandler(path = "/clientManage/redirectClientByIpPort")
public class RedirectClientByIpPortHandler extends AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public RedirectClientByIpPortHandler(EventMeshTCPServer
eventMeshTCPServer, HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by redirecting matching clients to a target EventMesh
server node.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String result = "";
try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameters from the query string
String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP);
String port = queryStringInfo.get(EventMeshConstants.MANAGE_PORT);
String destEventMeshIp =
queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP);
String destEventMeshPort =
queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT);
+ // Check the validity of the parameters
if (StringUtils.isBlank(ip) || !StringUtils.isNumeric(port)
|| StringUtils.isBlank(destEventMeshIp) ||
StringUtils.isBlank(destEventMeshPort)
|| !StringUtils.isNumeric(destEventMeshPort)) {
@@ -72,17 +106,20 @@ public class RedirectClientByIpPortHandler extends
AbstractHttpHandler {
}
log.info("redirectClientByIpPort in
admin,ip:{},port:{},destIp:{},destPort:{}====================", ip,
port, destEventMeshIp, destEventMeshPort);
+ // Retrieve the mapping between Sessions and their corresponding
client address
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
StringBuilder redirectResult = new StringBuilder();
try {
if (!sessionMap.isEmpty()) {
+ // Iterate through the sessionMap to find matching
sessions where the client's IP and port match the given ones
for (Session session : sessionMap.values()) {
+ // For each matching session found, redirect the client
+ // to the new EventMesh node specified by given
EventMesh IP and port.
if (session.getClient().getHost().equals(ip) &&
String.valueOf(
session.getClient().getPort()).equals(port)) {
redirectResult.append("|");
- redirectResult.append(
-
EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer,
+
redirectResult.append(EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer,
destEventMeshIp,
Integer.parseInt(destEventMeshPort),
session, clientSessionGroupMapping));
}
@@ -95,18 +132,16 @@ public class RedirectClientByIpPortHandler extends
AbstractHttpHandler {
result = String.format("redirectClientByIpPort fail!
sessionMap size {%d}, {clientIp=%s clientPort=%s "
+
"destEventMeshIp=%s destEventMeshPort=%s}, result
{%s}, errorMsg : %s",
- sessionMap.size(), ip, port, destEventMeshIp,
destEventMeshPort,
- redirectResult.toString(), e
- .getMessage());
+ sessionMap.size(), ip, port, destEventMeshIp,
destEventMeshPort, redirectResult, e.getMessage());
NetUtils.sendSuccessResponseHeaders(httpExchange);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
return;
}
+ // Serialize the result of redirection into output stream
result = String.format("redirectClientByIpPort success! sessionMap
size {%d}, {ip=%s port=%s "
+
"destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ",
- sessionMap.size(), ip, port, destEventMeshIp,
destEventMeshPort,
- redirectResult.toString());
+ sessionMap.size(), ip, port, destEventMeshIp,
destEventMeshPort, redirectResult);
NetUtils.sendSuccessResponseHeaders(httpExchange);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
} catch (Exception e) {
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java
index a4cbaf166..2d98980de 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java
@@ -41,29 +41,59 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
/**
- * redirect subsystem for path
+ * This class handles the HTTP requests of {@code
/clientManage/redirectClientByPath} endpoint,
+ * which is used to redirect matching clients to a target EventMesh server node
+ * based on the provided client UserAgent path.
+ * <p>
+ * The request must specify the client's path and target EventMesh node's IP
and port.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client's path: {@code path} | Example: {@code
/data/app/umg_proxy}</li>
+ * <li>target EventMesh node's IP: {@code desteventmeshIp}</li>
+ * <li>target EventMesh node's port: {@code desteventmeshport}</li>
+ * </ul>
+ * It uses the {@link EventMeshTcp2Client#redirectClient2NewEventMesh} method
to redirect the matching client.
+ *
+ * @see AbstractHttpHandler
*/
+
@Slf4j
@EventHttpHandler(path = "/clientManage/redirectClientByPath")
public class RedirectClientByPathHandler extends AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public RedirectClientByPathHandler(EventMeshTCPServer eventMeshTCPServer,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by redirecting matching clients to a target EventMesh
server node.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String result = "";
try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameters from the query string
String path = queryStringInfo.get(EventMeshConstants.MANAGE_PATH);
String destEventMeshIp =
queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP);
String destEventMeshPort =
queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT);
+ // Check the validity of the parameters
if (StringUtils.isBlank(path) ||
StringUtils.isBlank(destEventMeshIp)
|| StringUtils.isBlank(destEventMeshPort)
|| !StringUtils.isNumeric(destEventMeshPort)) {
@@ -74,12 +104,16 @@ public class RedirectClientByPathHandler extends
AbstractHttpHandler {
}
log.info("redirectClientByPath in
admin,path:{},destIp:{},destPort:{}====================", path,
destEventMeshIp, destEventMeshPort);
+ // Retrieve the mapping between Sessions and their corresponding
client address
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
StringBuilder redirectResult = new StringBuilder();
try {
if (!sessionMap.isEmpty()) {
+ // Iterate through the sessionMap to find matching
sessions where the client's path matches the given param
for (Session session : sessionMap.values()) {
+ // For each matching session found, redirect the client
+ // to the new EventMesh node specified by given
EventMesh IP and port.
if (session.getClient().getPath().contains(path)) {
redirectResult.append("|");
redirectResult.append(EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer,
@@ -95,8 +129,7 @@ public class RedirectClientByPathHandler extends
AbstractHttpHandler {
result = String.format("redirectClientByPath fail! sessionMap
size {%d}, {path=%s "
+
"destEventMeshIp=%s destEventMeshPort=%s}, result
{%s}, errorMsg : %s",
- sessionMap.size(), path, destEventMeshIp,
destEventMeshPort, redirectResult, e
- .getMessage());
+ sessionMap.size(), path, destEventMeshIp,
destEventMeshPort, redirectResult, e.getMessage());
NetUtils.sendSuccessResponseHeaders(httpExchange);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
return;
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java
index 42ecf69d6..7543a30b5 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java
@@ -42,30 +42,60 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
/**
- * redirect subsystem for subsys and dcn
+ * This class handles the HTTP requests of {@code
/clientManage/redirectClientBySubSystem} endpoint,
+ * which is used to redirect matching clients to a target EventMesh server node
+ * based on the provided client subsystem id in a Data Communication Network
(DCN).
+ * <p>
+ * The request must specify the client's subsystem id and target EventMesh
node's IP and port.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client's subsystem id: {@code subsystem} | Example: {@code
5023}</li>
+ * <li>target EventMesh node's IP: {@code desteventmeshIp}</li>
+ * <li>target EventMesh node's port: {@code desteventmeshport}</li>
+ * </ul>
+ * It uses the {@link EventMeshTcp2Client#redirectClient2NewEventMesh} method
to redirect the matching client.
+ *
+ * @see AbstractHttpHandler
*/
+
@Slf4j
@EventHttpHandler(path = "/clientManage/redirectClientBySubSystem")
public class RedirectClientBySubSystemHandler extends AbstractHttpHandler {
private final transient EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public RedirectClientBySubSystemHandler(final EventMeshTCPServer
eventMeshTCPServer,
final HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by redirecting matching clients to a target EventMesh
server node.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(final HttpExchange httpExchange) throws IOException {
Objects.requireNonNull(httpExchange, "httpExchange can not be null");
try (OutputStream out = httpExchange.getResponseBody()) {
final Map<String, String> queryStringInfo =
NetUtils.formData2Dic(httpExchange.getRequestURI().getQuery());
+ // Extract parameters from the query string
final String subSystem =
queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
final String destEventMeshIp =
queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP);
final String destEventMeshPort =
queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT);
+ // Check the validity of the parameters
if (!StringUtils.isNumeric(subSystem)
|| StringUtils.isBlank(destEventMeshIp) ||
StringUtils.isBlank(destEventMeshPort)
|| !StringUtils.isNumeric(destEventMeshPort)) {
@@ -78,12 +108,16 @@ public class RedirectClientBySubSystemHandler extends
AbstractHttpHandler {
subSystem, destEventMeshIp, destEventMeshPort);
}
+ // Retrieve the mapping between Sessions and their corresponding
client address
final ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
final ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
final StringBuilder redirectResult = new StringBuilder();
try {
if (!sessionMap.isEmpty()) {
+ // Iterate through the sessionMap to find matching
sessions where the client's subsystem id matches the given param
for (final Session session : sessionMap.values()) {
+ // For each matching session found, redirect the client
+ // to the new EventMesh node specified by given
EventMesh IP and port.
if
(session.getClient().getSubsystem().equals(subSystem)) {
redirectResult.append('|')
.append(EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer,
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java
index 449c1033a..adca074bf 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java
@@ -39,12 +39,30 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
+/**
+ * This class handles the HTTP requests of {@code
/clientManage/rejectAllClient} endpoint,
+ * which is used to reject ALL client connections belonging to the current
EventMesh server node.
+ * <p>
+ * CAUTION: USE WITH CARE
+ * <p>
+ * It uses the {@link EventMeshTcp2Client#serverGoodby2Client} method to close
the matching client connection.
+ *
+ * @see AbstractHttpHandler
+ */
+
@Slf4j
@EventHttpHandler(path = "/clientManage/rejectAllClient")
public class RejectAllClientHandler extends AbstractHttpHandler {
private final transient EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public RejectAllClientHandler(final EventMeshTCPServer eventMeshTCPServer,
final HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
@@ -52,14 +70,15 @@ public class RejectAllClientHandler extends
AbstractHttpHandler {
}
/**
- * remove all clients accessed by eventMesh
+ * Handles requests by rejecting all clients.
*
- * @param httpExchange
- * @throws IOException
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
*/
@Override
public void handle(final HttpExchange httpExchange) throws IOException {
try (OutputStream out = httpExchange.getResponseBody()) {
+ // Retrieve the mapping between Sessions and their corresponding
client address
final ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
final ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
final List<InetSocketAddress> successRemoteAddrs = new
ArrayList<>();
@@ -68,9 +87,11 @@ public class RejectAllClientHandler extends
AbstractHttpHandler {
log.info("rejectAllClient in admin====================");
}
if (!sessionMap.isEmpty()) {
+ // Iterate through the sessionMap and close each client
connection
for (final Map.Entry<InetSocketAddress, Session> entry :
sessionMap.entrySet()) {
final InetSocketAddress addr =
EventMeshTcp2Client.serverGoodby2Client(
eventMeshTCPServer, entry.getValue(),
clientSessionGroupMapping);
+ // Add the remote client address to a list of
successfully rejected addresses
if (addr != null) {
successRemoteAddrs.add(addr);
}
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java
index 77722daa8..b627f8d48 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java
@@ -42,26 +42,60 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
+/**
+ * This class handles the HTTP requests of {@code
/clientManage/rejectClientByIpPort} endpoint,
+ * which is used to reject a client connection
+ * that matches the provided IP address and port.
+ * <p>
+ * The request must specify the client's and target EventMesh node's IP and
port.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client's IP: {@code ip}</li>
+ * <li>client's port: {@code port}</li>
+ * <li>target EventMesh node's IP: {@code desteventmeshIp}</li>
+ * <li>target EventMesh node's port: {@code desteventmeshport}</li>
+ * </ul>
+ * It uses the {@link EventMeshTcp2Client#serverGoodby2Client} method to close
the matching client connection.
+ *
+ * @see AbstractHttpHandler
+ */
+
@Slf4j
@EventHttpHandler(path = "/clientManage/rejectClientByIpPort")
public class RejectClientByIpPortHandler extends AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public RejectClientByIpPortHandler(EventMeshTCPServer eventMeshTCPServer,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by rejecting matching clients.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String result = "";
try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameters from the query string
String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP);
String port = queryStringInfo.get(EventMeshConstants.MANAGE_PORT);
+ // Check the validity of the parameters
if (StringUtils.isBlank(ip) || StringUtils.isBlank(port)) {
NetUtils.sendSuccessResponseHeaders(httpExchange);
result = "params illegal!";
@@ -69,15 +103,19 @@ public class RejectClientByIpPortHandler extends
AbstractHttpHandler {
return;
}
log.info("rejectClientByIpPort in
admin,ip:{},port:{}====================", ip, port);
+ // Retrieve the mapping between Sessions and their corresponding
client address
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
final List<InetSocketAddress> successRemoteAddrs = new
ArrayList<InetSocketAddress>();
try {
if (!sessionMap.isEmpty()) {
+ // Iterate through the sessionMap to find matching
sessions where the remote client address matches the given IP and port
for (Map.Entry<InetSocketAddress, Session> entry :
sessionMap.entrySet()) {
+ // Reject client connection for each matching session
found
if (entry.getKey().getHostString().equals(ip) &&
String.valueOf(entry.getKey().getPort()).equals(port)) {
InetSocketAddress addr =
EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer,
entry.getValue(), clientSessionGroupMapping);
+ // Add the remote client address to a list of
successfully rejected addresses
if (addr != null) {
successRemoteAddrs.add(addr);
}
@@ -92,7 +130,6 @@ public class RejectClientByIpPortHandler extends
AbstractHttpHandler {
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
return;
}
-
result = String.format("rejectClientByIpPort success! {ip=%s
port=%s}, had reject {%s}", ip, port,
NetUtils.addressToString(successRemoteAddrs));
NetUtils.sendSuccessResponseHeaders(httpExchange);
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java
index 16e155c47..5dfcc8059 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java
@@ -42,12 +42,35 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
+/**
+ * This class handles the HTTP requests of {@code
/clientManage/rejectClientBySubSystem} endpoint,
+ * which is used to reject a client connection
+ * that matches the provided client subsystem id in a Data Communication
Network (DCN).
+ * <p>
+ * The request must specify the client's subsystem id.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client's subsystem id: {@code subsystem} | Example: {@code
5023}</li>
+ * </ul>
+ * It uses the {@link EventMeshTcp2Client#serverGoodby2Client} method to close
the matching client connection.
+ *
+ * @see AbstractHttpHandler
+ */
+
@EventHttpHandler(path = "/clientManage/rejectClientBySubSystem")
@Slf4j
public class RejectClientBySubSystemHandler extends AbstractHttpHandler {
private final transient EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public RejectClientBySubSystemHandler(EventMeshTCPServer
eventMeshTCPServer, HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
@@ -65,10 +88,10 @@ public class RejectClientBySubSystemHandler extends
AbstractHttpHandler {
}
/**
- * remove c client by dcn and susysId
+ * Handles requests by rejecting matching clients.
*
- * @param httpExchange
- * @throws IOException
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
*/
@Override
public void handle(HttpExchange httpExchange) throws IOException {
@@ -76,8 +99,10 @@ public class RejectClientBySubSystemHandler extends
AbstractHttpHandler {
try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameter from the query string
String subSystem =
queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
+ // Check the validity of the parameters
if (StringUtils.isBlank(subSystem)) {
NetUtils.sendSuccessResponseHeaders(httpExchange);
result = "params illegal!";
@@ -86,15 +111,19 @@ public class RejectClientBySubSystemHandler extends
AbstractHttpHandler {
}
log.info("rejectClientBySubSystem in
admin,subsys:{}====================", subSystem);
+ // Retrieve the mapping between Sessions and their corresponding
client address
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
final List<InetSocketAddress> successRemoteAddrs = new
ArrayList<>();
try {
if (!sessionMap.isEmpty()) {
+ // Iterate through the sessionMap to find matching
sessions where the client's subsystem id matches the given param
for (Session session : sessionMap.values()) {
+ // Reject client connection for each matching session
found
if
(session.getClient().getSubsystem().equals(subSystem)) {
InetSocketAddress addr =
EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, session,
clientSessionGroupMapping);
+ // Add the remote client address to a list of
successfully rejected addresses
if (addr != null) {
successRemoteAddrs.add(addr);
}
@@ -111,6 +140,7 @@ public class RejectClientBySubSystemHandler extends
AbstractHttpHandler {
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
return;
}
+ // Serialize the successfully rejected client addresses into
output stream
result = String.format("rejectClientBySubSystem success!
sessionMap size {%d}, had reject {%s} , {"
+
"subSystemId=%s}", sessionMap.size(),
printClients(successRemoteAddrs), subSystem);
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
index 58168a0d4..262274033 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java
@@ -38,22 +38,42 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
+/**
+ * This class handles the HTTP requests of {@code
/clientManage/showClientBySystem} endpoint,
+ * which is used to display connected clients information
+ * under a specific subsystem by subsystem id.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>client's subsystem id: {@code subsystem} | Example: {@code
5023}</li>
+ * </ul>
+ *
+ * @see AbstractHttpHandler
+ */
+
@Slf4j
@EventHttpHandler(path = "/clientManage/showClientBySystem")
public class ShowClientBySystemHandler extends AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
/**
- * print clientInfo by subsys
+ * Handles requests by displaying clients information.
*
- * @param httpExchange
- * @throws IOException
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
*/
@Override
public void handle(HttpExchange httpExchange) throws IOException {
@@ -61,16 +81,20 @@ public class ShowClientBySystemHandler extends
AbstractHttpHandler {
try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameter from the query string
String subSystem =
queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM);
String newLine = System.getProperty("line.separator");
if (log.isInfoEnabled()) {
log.info("showClientBySubsys,subsys:{}", subSystem);
}
+ // Retrieve the mapping between Sessions and their corresponding
client address
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
if (sessionMap != null && !sessionMap.isEmpty()) {
+ // Iterate through the sessionMap to find matching sessions
where the client's subsystem id matches the given param
for (Session session : sessionMap.values()) {
+ // For each matching session found, append the client's
information to the result
if (session.getClient().getSubsystem().equals(subSystem)) {
UserAgent userAgent = session.getClient();
result.append(String.format("pid=%s | ip=%s | port=%s
| path=%s | purpose=%s",
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java
index cbfa2a2bf..9e28d4641 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java
@@ -38,19 +38,38 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
/**
- * This handler used to print the total client info
+ * This class handles the HTTP requests of {@code /clientManage/showClient}
endpoint.
+ * <p>
+ * It is used to query information about all clients connected to the current
EventMesh server node
+ * and to provide statistics on the number of clients in each subsystem.
+ *
+ * @see AbstractHttpHandler
*/
+
@Slf4j
@EventHttpHandler(path = "/clientManage/showClient")
public class ShowClientHandler extends AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public ShowClientHandler(EventMeshTCPServer eventMeshTCPServer,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by displaying clients information.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
StringBuilder result = new StringBuilder();
@@ -59,10 +78,12 @@ public class ShowClientHandler extends AbstractHttpHandler {
log.info("showAllClient=================");
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
+ // Store the subsystem and the corresponding client count.
HashMap<String, AtomicInteger> statMap = new HashMap<String,
AtomicInteger>();
Map<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
if (!sessionMap.isEmpty()) {
+ // Iterate through each Session to count the clients in each
subsystem.
for (Session session : sessionMap.values()) {
String key = session.getClient().getSubsystem();
if (!statMap.containsKey(key)) {
@@ -72,6 +93,7 @@ public class ShowClientHandler extends AbstractHttpHandler {
}
}
+ // Generate the result with the number of clients for each
subsystem.
for (Map.Entry<String, AtomicInteger> entry :
statMap.entrySet()) {
result.append(String.format("System=%s | ClientNum=%d",
entry.getKey(), entry.getValue().intValue())).append(newLine);
}
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java
index 8d9376f46..57b8a8ba9 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java
@@ -39,36 +39,63 @@ import com.sun.net.httpserver.HttpExchange;
import lombok.extern.slf4j.Slf4j;
/**
- * query client subscription by topic
+ * This class handles the HTTP requests of {@code
/clientManage/showListenClientByTopic} endpoint,
+ * which is used to display clients information
+ * subscribed to a specific topic.
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>Message Topic: {@code topic}</li>
+ * </ul>
+ *
+ * @see AbstractHttpHandler
*/
+
@Slf4j
@EventHttpHandler(path = "/clientManage/showListenClientByTopic")
public class ShowListenClientByTopicHandler extends AbstractHttpHandler {
private final EventMeshTCPServer eventMeshTCPServer;
+ /**
+ * Constructs a new instance with the provided server instance and HTTP
handler manager.
+ *
+ * @param eventMeshTCPServer the TCP server instance of EventMesh
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public ShowListenClientByTopicHandler(EventMeshTCPServer
eventMeshTCPServer, HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.eventMeshTCPServer = eventMeshTCPServer;
}
+ /**
+ * Handles requests by displaying clients information.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
StringBuilder result = new StringBuilder();
try (OutputStream out = httpExchange.getResponseBody()) {
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo =
NetUtils.formData2Dic(queryString);
+ // Extract parameter from the query string
String topic =
queryStringInfo.get(EventMeshConstants.MANAGE_TOPIC);
String newLine = System.getProperty("line.separator");
log.info("showListeningClientByTopic,topic:{}=================",
topic);
+ // Retrieve the mappings of client subsystem to client group
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
ConcurrentHashMap<String, ClientGroupWrapper> clientGroupMap =
clientSessionGroupMapping.getClientGroupMap();
if (!clientGroupMap.isEmpty()) {
+ // Iterate through the client group to get matching sessions
in the group by given topic
for (ClientGroupWrapper cgw : clientGroupMap.values()) {
Map<String, Session> listenSessions =
cgw.getTopic2sessionInGroupMapping().get(topic);
if (listenSessions != null && !listenSessions.isEmpty()) {
result.append(String.format("group:%s",
cgw.getGroup())).append(newLine);
+ // Iterate through the sessions to get each client
information
for (Session session : listenSessions.values()) {
UserAgent userAgent = session.getClient();
result.append(String.format("pid=%s | ip=%s |
port=%s | path=%s | version=%s", userAgent.getPid(), userAgent
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java
index 2990cd9ba..6ff342936 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java
@@ -33,6 +33,30 @@ import com.sun.net.httpserver.HttpExchange;
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}.
+ * <p>
+ * 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}.
+ * <p>
+ * 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;
+ * <p>
+ * 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.
+ * <p>
+ * 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
@EventHttpHandler(path = "/webhook/updateWebHookConfig")
@@ -40,20 +64,36 @@ public class UpdateWebHookConfigHandler extends
AbstractHttpHandler {
private final WebHookConfigOperation operation;
+ /**
+ * Constructs a new instance with the specified WebHook config operation
and HTTP handler manager.
+ *
+ * @param operation the WebHookConfigOperation implementation used to
update the WebHook config
+ * @param httpHandlerManager Manages the registration of {@linkplain
com.sun.net.httpserver.HttpHandler HttpHandler}
+ * for an {@link
com.sun.net.httpserver.HttpServer HttpServer}.
+ */
public UpdateWebHookConfigHandler(WebHookConfigOperation operation,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
this.operation = operation;
}
+ /**
+ * Handles requests by updating a WebHook configuration.
+ *
+ * @param httpExchange the exchange containing the request from the client
and used to send the response
+ * @throws IOException if an I/O error occurs while handling the request
+ *
+ * @see
org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#updateWebHookConfig(WebHookConfig)
+ */
@Override
public void handle(HttpExchange httpExchange) throws IOException {
NetUtils.sendSuccessResponseHeaders(httpExchange);
- // get requestBody and resolve to WebHookConfig
+ // Resolve to WebHookConfig
String requestBody = NetUtils.parsePostBody(httpExchange);
WebHookConfig webHookConfig = JsonUtils.parseObject(requestBody,
WebHookConfig.class);
try (OutputStream out = httpExchange.getResponseBody()) {
+ // Update the existing WebHookConfig
Integer code = operation.updateWebHookConfig(webHookConfig); //
operating result
String result = 1 == code ? "updateWebHookConfig Succeed!" :
"updateWebHookConfig Failed!";
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
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
index 5c2899947..d29142de0 100644
---
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
@@ -65,6 +65,7 @@ public class AdminWebHookConfigOperationManager {
throw new IllegalStateException("operationMode is not supported.");
}
+ // Affects which implementation of the WebHookConfigOperation
interface is used.
final Constructor<? extends WebHookConfigOperation> constructor =
WEBHOOK_CONFIG_OPERATION_MAP.get(operationMode).getDeclaredConstructor(Properties.class);
// Save the original accessibility of constructor
@@ -75,7 +76,6 @@ public class AdminWebHookConfigOperationManager {
if (log.isInfoEnabled()) {
log.info("operationMode is {} properties is {} ",
operationMode, operationProperties);
}
- // Affects which implementation of the WebHookConfigOperation
interface is used.
this.webHookConfigOperation =
constructor.newInstance(operationProperties);
} finally {
// Restore the original accessibility of constructor
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
index b9a8d6d96..7fe69a21c 100644
---
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
@@ -107,6 +107,9 @@ public class FileWebHookConfigOperation implements
WebHookConfigOperation {
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);
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
index 4af4500d7..0d5f5e8a9 100644
---
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
@@ -153,6 +153,9 @@ public class NacosWebHookConfigOperation implements
WebHookConfigOperation {
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 {
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
index 9989a4862..840724d67 100644
---
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
@@ -28,12 +28,12 @@ public class WebHookConfig {
private String callbackPath;
/**
- * manufacturer name ,like github
+ * manufacturer name, like github
*/
private String manufacturerName;
/**
- * webhook event name ,like rep-push
+ * webhook event name, like rep-push
*/
private String manufacturerEventName;
@@ -48,22 +48,22 @@ public class WebHookConfig {
private String description;
/**
- * secret key ,for authentication
+ * secret key, for authentication
*/
private String secret;
/**
- * userName ,for HTTP authentication
+ * userName, for HTTP authentication
*/
private String userName;
/**
- * password ,for HTTP authentication
+ * password, for HTTP authentication
*/
private String password;
/**
- * roll out protocol ,like http/kafka
+ * roll out protocol, like HTTP/Kafka
*/
private String cloudEventProtocol;
@@ -73,7 +73,7 @@ public class WebHookConfig {
private String cloudEventServiceAddress;
/**
- * roll out event name ,like topic to mq
+ * roll out event name, like topic to MQ
*/
private String cloudEventName;
@@ -88,7 +88,7 @@ public class WebHookConfig {
private String cloudEventSource;
/**
- * id of cloudEvent ,like uuid/manufacturerEventId
+ * 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
index fbe270088..e7f3fbc20 100644
---
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
@@ -20,7 +20,16 @@ package org.apache.eventmesh.webhook.api;
import java.util.List;
/**
- * WebHookConfigOperation
+ * This interface has three implementation classes, among which
+ * {@code FileWebHookConfigOperation} and {@code NacosWebHookConfigOperation}
+ * serve the {@code /webhook/deleteWebHookConfig} endpoint.
+ * <p>
+ * They correspond to the persistent configuration of {@linkplain
org.apache.eventmesh.webhook.api.WebHookConfig WebHookConfig}
+ * for {@code file} and {@code Nacos}, respectively.
+ * <p>
+ * 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 {
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
index 6e672a3db..d7c2474c4 100644
---
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
@@ -79,6 +79,7 @@ public class WebHookController {
* @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<String, String> header, byte[] body)
throws Exception {
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
index 2190f3174..d700715d9 100644
---
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
@@ -41,6 +41,17 @@ 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.
+ * <p>
+ * 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 {
@@ -55,9 +66,14 @@ public class HookConfigOperationManager implements
WebHookConfigOperation {
}
/**
- * Initialize according to operationMode
+ * Initialize according to operation mode.
+ * <p>
+ * 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 receiveConfiguration
+ * @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 {
@@ -79,6 +95,13 @@ public class HookConfigOperationManager implements
WebHookConfigOperation {
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) {
@@ -101,6 +124,14 @@ public class HookConfigOperationManager implements
WebHookConfigOperation {
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<WebHookConfig> queryWebHookConfigByManufacturer(final
WebHookConfig webHookConfig,
final Integer pageNum,
@@ -108,18 +139,36 @@ public class HookConfigOperationManager implements
WebHookConfigOperation {
return new ArrayList<WebHookConfig>();
}
+ /**
+ * 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());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]