Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #453] OpenSchema integration with EventMesh #434

Closed
wants to merge 16 commits into from

Conversation

yzhao244
Copy link
Contributor

@yzhao244 yzhao244 commented Jul 13, 2021

Fixes to child ISSUE#453 of its parent ISSUE#339.

Motivation

  • Support Schema Registry feature in EventMesh by integrating with OpenSchema Specifications

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

  • The purpose of this pull request is for introducing Schema Registry as part of the EventMesh.
    The Schema Registry is a central repository with RESTful interfaces for developers to define and register standard schemas. Addresses the problem of inconsistent or incompatible data(event) format between event producer and event consumer.

Modifications

  • Added eventmesh-store-api module which is an abstract layer abstracts the CRUD capability of the schema registry into this module.
  • Added eventmesh-store-h2 module which contains the actual implementation
  • Modified eventmesh-runtime which exposes three new subject APIs (schemaregistry/createSubject, /schemaregistry/readSubjectByName and /schemaregistry/showAllSubjectNames) via ClientManageController.

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? Another follow up issue or PR will be created for adding the documentation
  • 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
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to the Apache EventMesh (incubating) community!!
This is your first PR in our project. We're very excited to have you onboard contributing. Your contributions are greatly appreciated!

Please make sure that the changes are covered by tests.
We will be here shortly.
Let us know if you need any help!

Want to get closer to the community?

WeChat Group:
wechat_qr

Mailing Lists:

Name Description Subscribe Unsubscribe Archive
Users User support and questions mailing list Subscribe Unsubscribe Mail Archives
Development Development related discussions Subscribe Unsubscribe Mail Archives
Commits All commits to repositories Subscribe Unsubscribe Mail Archives

@yzhao244
Copy link
Contributor Author

yzhao244 commented Jul 13, 2021

{
	"subject": "test-topic",
	"namespace": "org.apache.rocketmq",
	"tenant": "messaging/rocketmq",
	"app": "rocketmq",
	"description": "rocketmq user information",
	"compatibility": "NONE",
	"status": "deprecated"
}

As shown above, the above APIs are not very closely following best practice of REST APIs. Therefore, I have proposed in the issue #339 to restify the EventMesh Schema Registry APIs by adding a new module.

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2021

Codecov Report

Merging #434 (d490f04) into develop (d8ac875) will decrease coverage by 0.11%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             develop    #434      +/-   ##
============================================
- Coverage       8.49%   8.38%   -0.12%     
  Complexity       256     256              
============================================
  Files            228     231       +3     
  Lines          10783   10930     +147     
  Branches         918     932      +14     
============================================
  Hits             916     916              
- Misses          9793    9940     +147     
  Partials          74      74              
Impacted Files Coverage Δ
...ntime/admin/controller/ClientManageController.java 0.00% <0.00%> (ø)
...sh/runtime/admin/handler/CreateSubjectHandler.java 0.00% <0.00%> (ø)
...untime/admin/handler/ReadSubjectByNameHandler.java 0.00% <0.00%> (ø)
...time/admin/handler/ShowAllSubjectNamesHandler.java 0.00% <0.00%> (ø)
...apache/eventmesh/runtime/boot/EventMeshServer.java 0.00% <0.00%> (ø)
...ventmesh/runtime/constants/EventMeshConstants.java 0.00% <ø> (ø)
...va/org/apache/eventmesh/runtime/util/NetUtils.java 9.67% <0.00%> (-2.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8ac875...d490f04. Read the comment docs.

@qqeasonchen qqeasonchen changed the title OpenSchema integration with EventMesh [ISSUE #339] OpenSchema integration with EventMesh Jul 14, 2021
@qqeasonchen
Copy link
Contributor

@yzhao244 License check seems failed.

@ruanwenjun
Copy link
Member

@yzhao244 It might be better to add a new module such like eventmesh-store-plugin, and make the eventmesh-store-h2 as a submodule of eventmesh-store-plugin, this makes it easier to manage plugins.

And we have recently enhanced the SPI module #419, you can use EventMeshExtensionFactory.getExtension(Class<T> extensionType, String extensionName) to get plugin instance rather than using ServiceLoader. You can find some detail of SPI in eventmesh-connector-rocketmq module.

@qqeasonchen
Copy link
Contributor

@yzhao244 It might be better to add a new module such like eventmesh-store-plugin, and make the eventmesh-store-h2 as a submodule of eventmesh-store-plugin, this makes it easier to manage plugins.

And we have recently enhanced the SPI module #419, you can use EventMeshExtensionFactory.getExtension(Class<T> extensionType, String extensionName) to get plugin instance rather than using ServiceLoader. You can find some detail of SPI in eventmesh-connector-rocketmq module.

yes, @ruanwenjun It seems also needs a eventmesh-connector-plugin moudle.

@@ -29,8 +29,12 @@ List open_message = [
"io.openmessaging:openmessaging-api:2.2.1-pubsub"
]

List h2_database = [
Copy link
Member

Choose a reason for hiding this comment

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

This dependency should move to eventmesh-store-h2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -57,6 +60,10 @@ public void start() throws IOException {
server.createContext("/clientManage/redirectClientByPath", new RedirectClientByPathHandler(eventMeshTCPServer));
server.createContext("/clientManage/redirectClientByIpPort", new RedirectClientByIpPortHandler(eventMeshTCPServer));
server.createContext("/clientManage/showListenClientByTopic", new ShowListenClientByTopicHandler(eventMeshTCPServer));

server.createContext("/schemaregistry/createSubject", new CreateSubjectHandler());
Copy link
Member

Choose a reason for hiding this comment

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

schemaregistry should rename to schemaRegistry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -0,0 +1,94 @@
package org.apache.eventmesh.runtime.admin.handler;
Copy link
Member

Choose a reason for hiding this comment

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

Add license header here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed license header


private Logger logger = LoggerFactory.getLogger(CreateSubjectHandler.class);

private static ObjectMapper jsonMapper;
Copy link
Member

Choose a reason for hiding this comment

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

It might be better use JsonUtils to serialize or deserialize JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ruanwenjun just to confirm :) .. do you mean by creating a new utility class called "JsonUtils" under path (org.apache.eventmesh.runtime.util) which leverages ObjectMapper for JSON serialization or deserialization?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it can be placed at common module

logger.error(result);
out.write(result.getBytes());
return;
} finally {
Copy link
Member

Choose a reason for hiding this comment

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

Use try with resource instead of try finally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In catch block, out.write(result.getBytes()); is used to return error response.. Therefore, out.write(result.getBytes()) becomes undefined if defining "OutputStream out" using Try with resource


private String compatibilityLevel;

/* @ApiModelProperty(value = "Compatability Level",
Copy link
Member

Choose a reason for hiding this comment

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

Remove unused code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

/* @ApiModelProperty(value = "Compatability Level",
allowableValues = "BACKWARD, BACKWARD_TRANSITIVE, FORWARD, FORWARD_TRANSITIVE, FULL, "
+ "FULL_TRANSITIVE, NONE")*/
@JsonProperty("compatibility")
Copy link
Member

Choose a reason for hiding this comment

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

It might make confusion why the returned attribute don't match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

private String version;

@JsonCreator
public SchemaCreateRequest(@JsonProperty("name") String name,
Copy link
Member

Choose a reason for hiding this comment

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

Remove @JsonCreator and @JsonProperty


import com.fasterxml.jackson.annotation.JsonProperty;

public class BaseRequest {
Copy link
Member

Choose a reason for hiding this comment

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

The request might implement Serializable


}

public static synchronized DBDataSource createDataSource(DBConfiguration dbConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

The DBDataSource is singleton?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, DBDataSource is singleton. Basically, it performs init, start and shutdown as part of EventMeshServer init, start and shutdown process.

Copy link
Member

Choose a reason for hiding this comment

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

But when we execute createDataSource method twice, we will get two DBDataSource instances, this is confusion, I think you would better make this class to be a real singleton.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I pushed fixes to DBDataSource class. thx

@ruanwenjun
Copy link
Member

@qqeasonchen You are right, the eventmesh-connector-plugin is at this pr #433

@yzhao244
Copy link
Contributor Author

@qqeasonchen @ruanwenjun Thanks a lot for the review comments. I will start to address them :)

@Jackzeng1224
Copy link

Hello, @yzhao244 ! I looked interface at the development, it seems that some interfaces are missing. I refer to https://github.com/openmessaging/openschema/blob/master/spec.md
for instance:
7.1.2
7.2.4
7.2.6
7.2.7

@yzhao244
Copy link
Contributor Author

Hello, @yzhao244 ! I looked interface at the development, it seems that some interfaces are missing. I refer to https://github.com/openmessaging/openschema/blob/master/spec.md
for instance:
7.1.2
7.2.4
7.2.6
7.2.7

@Jackzeng1224 Thanks for the question. Yes, you are right. The current commit so far only contains three Subject related APIs such as create subject, readySubjectbyname and showAllSubjects which have been mentioned in my first comment of this PR. :) . However, I am going to implement the rest of missing interfaces as soon as we are okay with the new modules(eventmesh-store-api and eventmesh-store-plugin), because I can follow new modules standards to code/implement the rest of interfaces. lol

@yzhao244
Copy link
Contributor Author

@yzhao244 It might be better to add a new module such like eventmesh-store-plugin, and make the eventmesh-store-h2 as a submodule of eventmesh-store-plugin, this makes it easier to manage plugins.

And we have recently enhanced the SPI module #419, you can use EventMeshExtensionFactory.getExtension(Class<T> extensionType, String extensionName) to get plugin instance rather than using ServiceLoader. You can find some detail of SPI in eventmesh-connector-rocketmq module.

@ruanwenjun Thanks for the suggestion. I have made eventmesh-store-h2 as a submodule of eventmesh-store-plugin module and enhanced my implementation by using EventMeshExtensionFactory.getExtension instead of ServiceLoader. :)

@Jackzeng1224
Copy link

Hello, @yzhao244 ! I looked interface at the development, it seems that some interfaces are missing. I refer to https://github.com/openmessaging/openschema/blob/master/spec.md
for instance:
7.1.2
7.2.4
7.2.6
7.2.7

@Jackzeng1224 Thanks for the question. Yes, you are right. The current commit so far only contains three Subject related APIs such as create subject, readySubjectbyname and showAllSubjects which have been mentioned in my first comment of this PR. :) . However, I am going to implement the rest of missing interfaces as soon as we are okay with the new modules(eventmesh-store-api and eventmesh-store-plugin), because I can follow new modules standards to code/implement the rest of interfaces. lol

Thanks for answering questions! Looking forward to eventmesh-store-plugin module

@Jackzeng1224
Copy link

Jackzeng1224 commented Jul 16, 2021

@yzhao244 hello,I found a problem with createDataSource. First, the new H2SchemaAdapter is initialized.
image
DBDataSource.createDataSource(dbConfig) in the start() method.
There should be a problem with the createDataSource() method. For example: ds, new DBDataSource(). It is different from other methods of creating data sources.
image
image

@Jackzeng1224
Copy link

@yzhao244 hello,I looked at DBDataSource(), this "ds" does not belong to the object. Did you look right?
image

@yzhao244
Copy link
Contributor Author

@yzhao244 hello,I looked at DBDataSource(), this "ds" does not belong to the object. Did you look right?
image

You are right, I removed "static" when defining BasicDataSource ds.

@Jackzeng1224
Copy link

Jackzeng1224 commented Jul 20, 2021

@yzhao244 hello,I looked at DBDataSource(), this "ds" does not belong to the object. Did you look right?
图像

You are right, I removed "static" when defining BasicDataSource ds.
Thanks! I will try again

@yzhao244
Copy link
Contributor Author

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@ruanwenjun
Copy link
Member

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@yzhao244 Hi, I have a question, the h2 is a memory database, it seems doesn't support distributed, how can the different eventmesh-runtime sync the schema change?

@qqeasonchen
Copy link
Contributor

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@yzhao244 Hi, I have a question, the h2 is a memory database, it seems doesn't support distributed, how can the different eventmesh-runtime sync the schema change?

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

  1. Eventmesh-store-api can be moved into eventmesh-store-plugin, just like connector.
  2. Did all the apis in the openSchema implement now?
  3. Did the management apis implement now?
  4. Did the sdk implement now?

@Jackzeng1224
Copy link

@yzhao244 hello,this problem occurs with the new receiving code. "configurationWraper" or "configurationWrapper"?
image

@yzhao244
Copy link
Contributor Author

yzhao244 commented Jul 21, 2021

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@yzhao244 Hi, I have a question, the h2 is a memory database, it seems doesn't support distributed, how can the different eventmesh-runtime sync the schema change?

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@qqeasonchen I answered your questions below. :)

  1. Eventmesh-store-api can be moved into eventmesh-store-plugin, just like connector.
    Yes, I have pushed my latest changes which moved Eventmesh-store-api to be under eventmesh-store-plugin.
  2. Did all the apis in the openSchema implement now?
    Not yet, I am thinking it is better delivering OpenSchema Integration in an incremental delivery fashion. :) .. In total, OpenSchema APIs can be seen as three groups.. /subject/ related APIs, /schema/ related APIs, /config/compatibility related APIs which I would suggest to deliver each group by individually separated PRs. The PR 434 currently delivers /subject/ related APIs.
    Three child issues are Implement OpenSchema Subject APIs #453
    , Implement OpenSchema Schema APIs #454, Implement OpenSchema Compatibility APIs #455
  3. Did the management apis implement now?
    Three new subject APIs (schemaregistry/createSubject, /schemaregistry/readSubjectByName and /schemaregistry/showAllSubjectNames) via ClientManageController. The rest of the OpenSchema APIs will be tracked/implemented by individually separated issues and PRs
  4. Did the sdk implement now?
    Sorry, do you mean by eventmesh-sdk-java? All OpenSchema APIs are exposed as a RESTful API via webhook in ClientManageController.

@yzhao244
Copy link
Contributor Author

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@yzhao244 Hi, I have a question, the h2 is a memory database, it seems doesn't support distributed, how can the different eventmesh-runtime sync the schema change?

very good question.. Actually, h2 can be turned into a persistent database by using the following example configuration (datasource.url=jdbc:h2:file:~/subdirectory/demodb) which persists data in file system.
Additionally, database configuration/url can be easily changed to point to any MySQL database service as an example based on end-user's choice for different eventmesh-runtime instances to sync the schema change. I am thinking to create separate issue for tracking documentation works for OpenSchema Integration and h2 plugin module.
image

@yzhao244 yzhao244 changed the title [ISSUE #339] OpenSchema integration with EventMesh [ISSUE #453] OpenSchema integration with EventMesh Jul 21, 2021
@qqeasonchen
Copy link
Contributor

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@yzhao244 Hi, I have a question, the h2 is a memory database, it seems doesn't support distributed, how can the different eventmesh-runtime sync the schema change?

@qqeasonchen @ruanwenjun Hi guys, do you have any concerns before merging this PR? Please let me know if I missed anything here. :)

@qqeasonchen I answered your questions below. :)

  1. Eventmesh-store-api can be moved into eventmesh-store-plugin, just like connector.
    Yes, I have pushed my latest changes which moved Eventmesh-store-api to be under eventmesh-store-plugin.
  2. Did all the apis in the openSchema implement now?
    Not yet, I am thinking it is better delivering OpenSchema Integration in an incremental delivery fashion. :) .. In total, OpenSchema APIs can be seen as three groups.. /subject/ related APIs, /schema/ related APIs, /config/compatibility related APIs which I would suggest to deliver each group by individually separated PRs. The PR 434 currently delivers /subject/ related APIs.
    Three child issues are Implement OpenSchema Subject APIs #453
    , Implement OpenSchema Schema APIs #454, Implement OpenSchema Compatibility APIs #455
  3. Did the management apis implement now?
    Three new subject APIs (schemaregistry/createSubject, /schemaregistry/readSubjectByName and /schemaregistry/showAllSubjectNames) via ClientManageController. The rest of the OpenSchema APIs will be tracked/implemented by individually separated issues and PRs
  4. Did the sdk implement now?
    Sorry, do you mean by eventmesh-sdk-java? All OpenSchema APIs are exposed as a RESTful API via webhook in ClientManageController.

@yzhao244 Individually separated PRs is good for me. But it is not very clear about how to use schema when pub/sub events, it seems eventmesh provides a management service for schema only in the request implementations, am i right?

@ruanwenjun
Copy link
Member

@yzhao244 Great, you mean if we use Mysql then we don't need to consider Scheme synchronization, because all the runtimes connect to the same Mysql. And if we use a public file system(e.g. NFS) to store h2 persistent file, then we also needn't consider Scheme synchronization, because the h2 help us to the job, am I right?
By the way, I don't know much about this, but I think your plan is ok. I think you would better send a mail to the community, let more people know your plan, and Apache community believes that all important decision need to be made in mail list.

@Jackzeng1224
Copy link

@yzhao244 hello,Can the module be tested and used normally now? or still to be modified.

@qqeasonchen
Copy link
Contributor

@yzhao244 hi, I suggest split this pr into several small ones, so that it can easily be reviewed and merged, for example, eventmesh-rest、eventmesh-store-api、eventmesh-store-h2 ect.

@qqeasonchen
Copy link
Contributor

@yzhao244 Could you please submmit this feature to branch openschema? i think eventmesh-rest can be merged to develop first.

@yzhao244
Copy link
Contributor Author

@qqeasonchen @Jackzeng1224 @ruanwenjun Hi guys, I agree with @qqeasonchen that splitting this pr into smaller ones will be easier and safer for reviewing and merging each individual plugin/module. Therefore, I am thinking to close this PR and will submit separate PRs for each module after some modifications.

Additionally, @ruanwenjun brought a good point regarding decision-making of important design. Should I create a design doc and push it to https://github.com/apache/incubator-eventmesh/tree/develop/docs/en/features (similar as eventmesh-stream-design.md which explains design in details and gets the whole community's awareness instead of only explaining designs under an issue) :)

@qqeasonchen
Copy link
Contributor

@yzhao244 That would be good if the desing was clear.

@yzhao244 yzhao244 closed this Jul 30, 2021
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.

None yet

5 participants