Skip to content

Conversation

@minglumlu
Copy link
Member

This is to merge Go SDK feature (including backwards compatibility support) into master branch.
Basically, the changes in feature include:

  1. auto-gen Go SDK through mustache templates;
  2. unit tests against auto-gen OCaml code;
  3. component tests against Go clients using generated Go SDK;
  4. functional tests in github.com/xenserver/xenserver-samples/go.

Most of the changes are under "ocaml/sdk-gen/". One exception is 612b73b, in which the Api.errors (strings) have to be collected in the way.

duobei and others added 30 commits April 15, 2024 13:40
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
CP-47350: Add mustache template for Record/Ref/Class Types
CP-47365: Add mustache template for API messages/errors
CP-47363: Add mustache template for file header

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
…ed JSON is wanted

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
…mmonFunctions`

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
…files

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Before we got the enums alongside objs,  the readability of code is so poor. We separate to get them now.

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Just check the fields only we need instead of generalized recursive functions

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
…unctions

Signed-off-by: xueqingz <xueqing.zhang@citrix.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: xueqingz <xueqing.zhang@citrix.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
changed templates: APIVersions.mustache,APIErrors.mustache, Record.mustache

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: xueqingz <xueqing.zhang@citrix.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
…lass messages

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
…h_enums`

Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
CP-48855: fix go lint var-name warnings
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
Signed-off-by: Luca Zhang <feiya.zhang@cloud.com>
minglumlu and others added 7 commits May 31, 2024 10:25
…_feature

Merge master to Go SDK feature branch
* CP-49707: Go SDK: Add JSON tag for structs

This aims to allow a Go SDK client to unmarshal JSON to Go structs with
the function in Go json pacakge instead of using Go SDK.

The unmarshalling in Go SDK contains two steps: JSON -> map -> struct.
This is because some special cases need to be handled explicitly.
But for sake of safety, this unmarshalling is not exposed to clients.

Signed-off-by: Ming Lu <ming.lu@cloud.com>

* CP-49349: Go SDK: Append UTC timezone to unix timestamp

The date time in Go requires a date time with timezone info. But XAPI
may return a UNIX timestamp to clients.

This commit blindly adds a UTC timezone for UNIX timestamps returned
from XAPI server.

Signed-off-by: Ming Lu <ming.lu@cloud.com>

* CP-49349: Go SDK: Allow spaces in special value of float type

Some special values of float standing in JSON are handled specifically.
This commit allows the special values contain spaces.

Signed-off-by: Ming Lu <ming.lu@cloud.com>

* Go SDK: Disable golangci tagliatelle

This check complains the struct json tag naming style. It expects the
Caml style, but Go SDK has to use Snake.

Signed-off-by: Ming Lu <ming.lu@cloud.com>

---------

Signed-off-by: Ming Lu <ming.lu@cloud.com>
Signed-off-by: Xihuan Yang <xihuan.yang@cloud.com>
…_test

CP-47928: Add component test for Go SDK
Signed-off-by: xueqingz <xueqing.zhang@citrix.com>
…_feature

Merge master branch to go_sdk feature branch
@xueqingz xueqingz requested review from gangj and xueqingz June 11, 2024 03:23
Copy link
Contributor

@xueqingz xueqingz left a comment

Choose a reason for hiding this comment

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


A. Navigate to the extracted `XenServer-SDK\XenServerGo\src` directory and copy the whole folder `src` into your Go project directory.

B. To use XenServer Go SDK as a local Go module, update one line into the `go.mod` file under your Go project:
Copy link

Choose a reason for hiding this comment

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

"update one line into" => Shouldn't this be "include the following line into"?

Copy link

Choose a reason for hiding this comment

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

"To use XenServer Go SDK as a local Go module" => "To use the XenServer SDK for Go as a local Go module"

```
replace xenapi => ./src
```
You can then import this XenServer SDK Go module with the following command:
Copy link

@kc284 kc284 Jun 11, 2024

Choose a reason for hiding this comment

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

"this XenServer SDK Go module" => "the XenServer SDK for Go" or "the XenServer module for Go"

@kc284
Copy link

kc284 commented Jun 11, 2024

I've just noticed that the mustache templates do not have the BSD 2-clause licence disclaimer at the top. All the autogenerated source files for all the SDK languages should include this. Is it added somehow by the generation code? If not, the simplest is to just hardcode it at the top of the mustache file (see other mustache files for the other langauges).

@minglumlu
Copy link
Member Author

I've just noticed that the mustache templates do not have the BSD 2-clause licence disclaimer at the top. All the autogenerated source files for all the SDK languages should include this. Is it added somehow by the generation code? If not, the simplest is to just hardcode it at the top of the mustache file (see other mustache files for the other langauges).

I think this should be included in the FQP and test report.

@minglumlu
Copy link
Member Author

All fixes are in #5687
This PR can be continued when the fixup PR merged.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
Signed-off-by: Ming Lu <ming.lu@cloud.com>
Signed-off-by: Ming Lu <ming.lu@cloud.com>
Prior to this change, the function parameter list is generated by
Mustache template. As a result, a template boolean variable 'first' has
to be used to determine if a leading comma is presented or not. E.g.
when the 'first' is true, a parameter would be rendered as "a string',
and then the next parameter with the 'first' being false would be
rendered as ", b string". Putting them together would result in
"a string, b string".

This could work but is difficult to be understood.

In this commit, it is changed to construct the whole function parameter
list as a string in OCaml code and bind it to the template variable
'func_params'.

Similar changes apply to the template variable 'is_session_id'. It is
removed in this commit and the expected values are generated by OCaml
code.

Signed-off-by: Ming Lu <ming.lu@cloud.com>
Signed-off-by: Ming Lu <ming.lu@cloud.com>
@psafont
Copy link
Member

psafont commented Jun 14, 2024

Looks fine to me, waiting on tina to review this. This is because she didn't approve the fixup PR

@xueqingz
Copy link
Contributor

Koji build base on branch feature/go_sdk latest commit "cca5a6e250b56a98294987a95b7ee53870188c41" https://koji.eng.citrite.net/koji/buildinfo?buildID=20734.
Build new SDK and re-run FQP. Quality status report updated: https://info.citrite.net/display/xenserver/Quality+Status+Report+for+XenServer+Go+SDK

@xueqingz xueqingz requested a review from kc284 June 14, 2024 09:14
@psafont psafont merged commit 94b24f5 into master Jun 14, 2024
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.

8 participants