-
Notifications
You must be signed in to change notification settings - Fork 59
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
Proposed api interface changes #29
Comments
This comment has been minimized.
This comment has been minimized.
@hzhou8 @softwarejl i need you approve and suggestions. This is not small task, but it don't need too much time to provide WIP for this. |
@vtolstov I support this idea! @softwarejl and I had discussed about having more generic API interface many times, just didn't get bandwidth to work on it. Maybe you could have a POC first. @softwarejl what do you think? |
Yes, we need to improve on that part, beside the interface, we need a way to define the data structure which aligns with ovn table structure. we need a poc firstly. |
first change in this series #42 |
@hzhou8 this is first part of storing in cache needed struct https://github.com/eBay/go-ovn/pull/44/files#diff-48d527baa1a7dc53e558c5548785cf1bR277 |
i think that if we store needed type inside cache all thing can be very simple. |
if somebody want helps me , i'l be happy =) |
@vtolstov Thanks for the effort. Could you complete the POC with just one end-to-end example, e.g. LogicalSwitchPort create/read/update/delete with the new approach? That would be very helpful for me to understand, since I am not sure yet if I understand what the helper function means exactly. |
@hzhou8 check ovnnbimp.go and acl.go |
@hzhou8 what can you say? |
@vtolstov this looks awesome! It simplifies a lot for the conversions. I think most of the code is generic for ovsdb, so it can actually be in libovsdb. For OVN part, it would be even better if we can generate the data types from schema, instead of manually write it (but it is totally ok now as the first step). |
I think we should have two sets of "get" methods. One is get by uuid, another is "find" by any combination of column values. |
Ok, so for now may be i can complete rewrite via ovn repo? And after that when all works fine we can move needed parts of code to libovsdb and change some parts of go-ovn? |
last question, does we need to support nested values in ExternalIDs? |
Do you have an example? I think we should support whatever column types can appear in OVSDB schema. (Of course it doesn't have to be complete in the first version) |
I can't find example now, but as i see in libovsdb map represented as map[string]interface{} , but ovn-nb says:
so may be recursion is not needed |
Yes, the schema defines as: The "value" has to be base-type, i.e. string, integer, etc. |
i don't have time to finish it. may be the best - generate needed struct from schema and replace own handmade stuff |
I have coded a small PoC based on @vtolstov's and some old code I had. The result is here: Since there is no proposal for an API (let's discuss this!), I've implemented an API that resembles a ORM: Taking @vtolstov's idea, the encoding/decoding is done based on struct tags: It's still very early, but it could serve as a discussion trigger. @hzhou8 WDYT? Some issues that I would like feedback on:
|
sorry i need more time to dig.
usually List, returns slice and err like datas, err := ovndbapi.List() Same thing for Get... |
I took inspiration from a well-known, widely-used Golang ORM
If @hzhou8 WDYT? |
i'm prefer this style:
so list of switches looks like
|
@amorenoz Sorry for the slow response. The POC looks promising. I need more time to study the Golang ORM example. Feel free to send a PR to the repo. (In fact I think ebay/libovsdb is where the major part of change should go) My answers to some of your questions:
I think it is important to return a command, so that it can be combined and executed together with other commands as a single transaction.
Yes we should auto-generate. I don't think we need to maitain the compatibility in the Go library. It is OVN's responsibility to keep the DB schema compatibility. We can follow the approach of the C IDL. |
Thanks @hzhou8, once there is consensus on the high level API, I'll send a PR.
Should "reading" functions (such as List(), Get()) be the same?
Right, but the IDL generation is at compile time, right? |
"reading" functions should directly return the results. In addition, for efficiency, we should provide an interface to iterate the local cache instead of duplicate the whole result list by a List() function.
Yes.
Yes. Do you think this is reasonable?
I didn't thought about this. Too generic API may be harder to use, but I didn't think deeply on this option. |
Good idea!
It might be complicated. Layered projects might want to stick with an old version of go-ovn feature-wise while supporting newer ovn schemas. That would put some pressure into go-ovn for being very conservative in the changes it introduces. The alternative would be to clone the entire repository per supported ovn version. Plus, you have the problem of guaranteeing what version of ovn you work with. Projects that work with a pre-defined version of go-ovn (such as ovn-kubernetes) might be able to cope with it, but others like skydive might not have it that easy.
The API in my last PoC is generic. The columns to read are determined by the tags of object the client passes to the function, e.g:
This would allow for us to provide a set of pre-defined structures per ovn version, place them in different directories and allow users to use the same version of go-ovn with multiple versions of ovn. Even more, it would allow developers to define their own structs (e.g: only partial readings, or out-of-tree / unmerged ovn schemas). |
we can generate structs for all needed ovn versions in different dirs. libovsdb may check ovn version on connect and return needed structs to go-ovn. and go-ovn may return needed data depending on ovn version i think |
OK, sounds good. How about the following for the API:
How does that look to you?
|
More questions:
|
I have updated my PoC to expose the API @vtolstov suggests: We would need to create a tool that generates the types and API structs per Table in the schema and combine them all into a DatabaseAPI object |
client using the api looks good to me. |
@vtolstov @hzhou8 Any updates? I'm waiting for some feedback from you to proceed. |
I want to propose interface changes, Firstly to follow go interface naming, api creates Client interface.
All methods have args with native types, so for adding port to logical switch we can provide
*LogicalSwitch struct to function, that have needed name. Also in this struct we can pass ExternalIDs, so LSPAdd can find needed ls by name, uuid, or external_ids. This is already handled with getRowUUIDs.
as in example of LSPAdd second arg is *LogicalSwitchPort with filled needed data. So function can receive only 2 args. We can easy handle optional params and default values.
Inside function we can use https://godoc.org/github.com/mitchellh/mapstructure to convert from struct to map[string]interface{}.
I think that this is more universal that current approach, and easy deduplicate many identical pieces of our code.
The text was updated successfully, but these errors were encountered: