Skip to content

Conversation

@karsonto
Copy link
Member

@karsonto karsonto commented Jan 11, 2024

Fixes #4750 Replace sun.net.httpserver.HttpServer to use netty server

Motivation

Explain the content here.
Explain why you want to make the changes and what problem you're trying to solve.

Modifications

Describe the modifications you've done.

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

Copy link
Member

@Pil0tXia Pil0tXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a AdminProcessor in EventMeshHTTPServer like AdminMetricsProcessor, is enough, admin is not a protocol.

@Pil0tXia
Copy link
Member

Pil0tXia commented Jan 14, 2024

I didn't see changes under org.apache.eventmesh.runtime.admin.handler packages. They are using com.sun.net.httpserver.HttpExchange and can be replaced with netty usages.

Furthermore, com.sun.net.httpserver.HttpExchange also introduced complexity in logging exceptions. There is no need to print stacktrace twice and they can be replaced with a more concise usage like log.error("Runtime Admin endpoint failed to create topic: {}", e.getMessage());.

httpExchange.sendResponseHeaders(200, 0);
} catch (Exception e) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
e.printStackTrace(printWriter);
printWriter.flush();
String stackTrace = writer.toString();
Error error = new Error(e.toString(), stackTrace);
String result = JsonUtils.toJSONString(error);
httpExchange.sendResponseHeaders(500, Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length);
log.error(result, e);
}

@karsonto
Copy link
Member Author

@Pil0tXia I think this issue should be handled in two PRs. 1. Convert the existing HTTP server to Netty server, and maintain the compatibility of the original Handler. 2. Change the HTTP handler to the Netty HttpRequestProcessor used in the project.

@Pil0tXia
Copy link
Member

You may merge lastest master branch to fix CI errors.

@Pil0tXia
Copy link
Member

I think this issue should be handled in two PRs. 1. Convert the existing HTTP server to Netty server, and maintain the compatibility of the original Handler. 2. Change the HTTP handler to the Netty HttpRequestProcessor used in the project.

@karsonto Please create two subtask issues of #4738 and link this PR to one of them.

Comment on lines +85 to +87
thread.start();
started.compareAndSet(false, true);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L86, better not to edit the startup status boolean of an abstract class (AbstractHTTPServer).

Comment on lines 483 to 485
@Sharable
private class HttpConnectionHandler extends ChannelDuplexHandler {
protected class HttpConnectionHandler extends ChannelDuplexHandler {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to keep it private here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EventMeshAdminServer can not use If this HttpConnectionHandler keep private .

@karsonto karsonto changed the title [ISSUE #4738] Integrate Runtime admin endpoints with Netty server [ISSUE #4750] Integrate Runtime admin endpoints with Netty server Jan 18, 2024
@karsonto karsonto changed the title [ISSUE #4750] Integrate Runtime admin endpoints with Netty server [ISSUE #4750] Replace sun.net.httpserver.HttpServer to use netty server Jan 18, 2024
Comment on lines 87 to 103
public void exec(ChannelHandlerContext ctx, HttpRequest httpRequest) {
String uriStr = httpRequest.uri();
URI uri = URI.create(uriStr);
HttpHandler httpHandler = httpHandlerMap.get(uri.getPath());
if (httpHandler != null) {
try {
HttpHandlerManager.AdminHttpExchange adminHttpExchange = new HttpHandlerManager.AdminHttpExchange(ctx, httpRequest);
httpHandler.handle(adminHttpExchange);
adminHttpExchange.writeAndFlash();
return;
} catch (Exception e) {
log.error(e.getMessage(), e);
ctx.writeAndFlush(HttpResponseUtils.createInternalServerError()).addListener(ChannelFutureListener.CLOSE);
}
} else {
ctx.writeAndFlush(HttpResponseUtils.createNotFound()).addListener(ChannelFutureListener.CLOSE);
}
Copy link
Member

@Pil0tXia Pil0tXia Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about integrating EventMeshAdminServer with HandlerService instead of implementing a group of http processing logic seperately for admin?

Copy link
Member

@Pil0tXia Pil0tXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you haven't implement EventMeshAdminBootstrap.

@karsonto
Copy link
Member Author

It seems that you haven't implement EventMeshAdminBootstrap.

Your means add AdminBootstrap startup list in EventMeshServer?

Comment on lines 42 to 44
import org.apache.eventmesh.runtime.admin.handler.UpdateWebHookConfigHandler;
import org.apache.eventmesh.runtime.boot.EventMeshAdminServer;
import org.apache.eventmesh.runtime.boot.EventMeshAdminBootstrap;
import org.apache.eventmesh.runtime.boot.EventMeshGrpcServer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EventMeshAdminBootstrap should be referenced by EventMeshServer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it,please review again

Comment on lines 59 to 61

private transient ClientManageController clientManageController;
// private transient ClientManageController clientManageController;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why commented here?

Comment on lines 19 to 21

import org.apache.eventmesh.runtime.admin.controller.HttpHandlerManager;
import org.apache.eventmesh.runtime.admin.controller.ClientManageController;
import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that referencing ClientManageController in EventMeshAdminBootstrap is not a good practice. I think the design of ClientManageController and HttpHandlerManager has been outdated and it will be great if you may redesign them to fit EventMesh style of Netty HTTP Server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right,please review it.

Comment on lines 129 to 159
private void registerHttpHandler() {
initHandler(new ShowClientHandler(eventMeshTCPServer));
initHandler(new ShowClientBySystemHandler(eventMeshTCPServer));
initHandler(new RejectAllClientHandler(eventMeshTCPServer));
initHandler(new RejectClientByIpPortHandler(eventMeshTCPServer));
initHandler(new RejectClientBySubSystemHandler(eventMeshTCPServer));
initHandler(new RedirectClientBySubSystemHandler(eventMeshTCPServer));
initHandler(new RedirectClientByPathHandler(eventMeshTCPServer));
initHandler(new RedirectClientByIpPortHandler(eventMeshTCPServer));
initHandler(new ShowListenClientByTopicHandler(eventMeshTCPServer));
initHandler(new QueryRecommendEventMeshHandler(eventMeshTCPServer));
initHandler(new TCPClientHandler(eventMeshTCPServer));
initHandler(new HTTPClientHandler(eventMeshHTTPServer));
initHandler(new GrpcClientHandler(eventMeshGrpcServer));
initHandler(new ConfigurationHandler(
eventMeshTCPServer.getEventMeshTCPConfiguration(),
eventMeshHTTPServer.getEventMeshHttpConfiguration(),
eventMeshGrpcServer.getEventMeshGrpcConfiguration()));
initHandler(new MetricsHandler(eventMeshHTTPServer, eventMeshTCPServer));
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));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about putting this method (registering endpoints) in a Manager class just like the ConsumerManager does in EventMeshHTTPServer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure,please review.

Copy link
Member

@Pil0tXia Pil0tXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please have a throughout test on endpoint handlers.

Need more reviewers to check whether this PR's AdminServer implementation fit the EventMesh style.

String connectorPluginType,
HttpHandlerManager httpHandlerManager) {
super(httpHandlerManager);
String connectorPluginType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this param seems like storagePluginType, as well as the comment on this Class, not the connector plugin type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be optimized in the future.Thank you.

@xwm1992 xwm1992 merged commit 648f3e9 into apache:master Feb 4, 2024
} catch (Exception ex) {
log.error("AdminHttpServer shutdown error!", ex);
}
System.exit(-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it appropriate for the admin server to exit when it starts a failed process? Older versions of admin server didn't have such strong constraints. Please keep an eye on the community, I'm not sure if it's appropriate or not.

admin server启动失败进程就退出是否合适?旧版的admin server没有这么强的约束。请社区留意,我不知道合适与否。

@xwm1992 xwm1992 added this to the 1.11.0 milestone Dec 18, 2024
xuhongjia pushed a commit to Deckers-Ohana/eventmesh that referenced this pull request Mar 13, 2025
…y server (apache#4739)

* fix 4738

* fix some bug

* fix bug

* remove initProducerManager from AbstractRemotingServer init

* bug fix

* bug fix

* some enhance

* some enhance

* add admin bootstrap

* some enhance

* remove HttpHandlerManager and ClientManageController.

* modify some unit test

* add admin http handlermanager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Integrate Runtime admin endpoints with Netty server phase 1

4 participants