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

A huge migration to a newer swagger. #3481

Merged
merged 12 commits into from
Dec 13, 2016
Merged

A huge migration to a newer swagger. #3481

merged 12 commits into from
Dec 13, 2016

Conversation

vburenin
Copy link
Contributor

@vburenin vburenin commented Dec 9, 2016

What can I say? It is a HUGE change. Full CI passed, which is exciting and scary at the same time. Not sure there is a good way to review it all carefully, pick a part you are familiar with and see what happens.

Fixes: #929

@vburenin vburenin changed the title [full ci] Huge migration to a newer swagger. DO NOT REVIEW YET. [full ci] Huge migration to a newer swagger. Dec 10, 2016
@mdubya66
Copy link
Contributor

mdubya66 commented Dec 11, 2016

fixes #929 ?

@vburenin vburenin changed the title [full ci] Huge migration to a newer swagger. [full ci] A huge migration to a newer swagger. Dec 12, 2016
@@ -615,7 +616,7 @@ func TestPortInformation(t *testing.T) {
mockContainerInfo := &plmodels.ContainerInfo{}
mockContainerConfig := &plmodels.ContainerConfig{}
containerID := "foo"
mockContainerConfig.ContainerID = &containerID
mockContainerConfig.ContainerID = containerID
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a lot of these changes where we are taking away the pointer. Can we not do these in a separate PR; preferably in an iterative manner? These kinds of changes always have the danger of introducing subtle bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the least problematic change you can think of - at least for these values I was able to check the code surrounding it. The most scariest part is when I set "x-nullable":false - this is where zero values are no longer accepted. I tried to be careful with them, but things that are changed are not as scary as those that are unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, yes, this one in particular is not problematic. But that doesn't mean the multitude of others is not; its just not easy to go through everyone and understand the ramifications of a particular change. Is the "x-nullable" really necessary right now?

Copy link
Contributor Author

@vburenin vburenin Dec 12, 2016

Choose a reason for hiding this comment

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

@hmahmood without it the change would be an order of a magnitude larger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hmahmood the good part of this change is that it will expose problematic parts of our API and data checks earlier. What really worries me is that we do not really care about data validation relaying purely on a sane usage. At the moment it is fine, but AFAIK PortLayer API will be exposed in the future, so absence of data validation will bite us.

@mdubya66
Copy link
Contributor

My take on this is let's get it tested as much as possible. Run against the CI, the Nightlies, Stress and Longevity. We should aim to get it in sooner so that we can continue to iterate on it.

if container == nil {
log.Errorf("Could not find container with ID %s", *t.ContainerConfig.ContainerID)
cid := t.ContainerConfig.ContainerID
c := cache.ContainerCache().GetContainer(cid)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1. I really hate go programmer's habit of overloading one line with a bazillion operations. They need to remember the compiler doesn't care, and readability is more important.


"github.com/vmware/vic/lib/apiservers/engine/backends/cache"
"github.com/vmware/vic/lib/apiservers/engine/backends/container"
"github.com/vmware/vic/lib/apiservers/portlayer/client"
apiclient "github.com/vmware/vic/lib/apiservers/portlayer/client"
Copy link
Contributor

Choose a reason for hiding this comment

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

apiclient isn't really necessary to migrate from 1 swagger version to another. We can debate the naming of this later. Lets keep this change restricted only only the required changes to include the new swagger version. The unnecessary churn makes reviewing harder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used tools to deal with imports, all automatic changes are not easy to manage manually.

@@ -123,52 +124,52 @@ func hydrateCaches() error {

wg := sync.WaitGroup{}
wg.Add(waiters)
errors := make(chan error, waiters)
errChan := make(chan error, waiters)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above. This isn't strictly necessary to migrate to the new swagger version. Please remove it from your change and we can review these cosmetic changes in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the cosmetic change and the only one that you can say "big".

@@ -985,22 +984,25 @@ func (c *Container) ContainerInspect(name string, size bool, version version.Ver
}
var started time.Time
var stopped time.Time
if results.Payload.ProcessConfig.StartTime != nil && *results.Payload.ProcessConfig.StartTime > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this purely formatting? Unnecessary churn to migrate to the new swagger. Encapsulate these cosmetic changes in their own PR and we can review them later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a cosmetic change. it a result of a variable becoming a value not a pointer during migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fdawg4l There are a few cosmetic changes, but I would gloss over them and focus on the pointer issue. Vast majority of the changes I've seen so far are due to Swagger and not cosmetic.

if vchInfo.Memory != nil {
info.MemTotal = *vchInfo.Memory << 20 //Multiply by 1024*1024 to get Mebibytes
if vchInfo.Memory > 0 {
info.MemTotal = vchInfo.Memory * 1024 * 1024 // Get Mebibytes
Copy link
Contributor

Choose a reason for hiding this comment

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

come one - 2^20 FTW :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to keep it as is also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

come one - compiler will do the same thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, if go compiler is smart to do this. Still hurts the eyes of former C/C++ programmers. :)

@@ -1,225 +0,0 @@
package {{ .APIPackage }}
Copy link
Contributor

Choose a reason for hiding this comment

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

we needed this for 030764a . How do we handle it with new swagger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to verify it is still the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

#1244 is the original issue for your reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@caglar10ur Thanks for a good catch. I am going to backport this change directly into swagger, since it is actually makes sense. I was about to implement same thing on my previous projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@caglar10ur I integrated needed changes into swagger as well as updated portlayer accordingly.
go-swagger/go-swagger#784

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

}

// Ping sends an OK response to let the client know the server is up
func (handler *MiscHandlersImpl) Ping() middleware.Responder {
func (h *MiscHandlersImpl) Ping(param misc.PingParams) middleware.Responder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Parameter-less operations in the swagger spec now causes parameters to be generated?

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, they contain some useful objects like context, request, etc.

sc := &models.ScopeConfig{
ID: &id,
ID: scope.ID().String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a little inconsistent. Some places, you're introducing new vars for readability, but then you remove them in other places.

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 this case it makes sense, since it is a short string, I can see all at once.

"type": "integer",
"format": "int64"
"x-nullable": false,
"type": "integer"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a type integer instead of int64 now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

format != type.

Copy link
Contributor

Choose a reason for hiding this comment

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

The version of Swagger we used caused an int64 to get generated if we tag the parameter with format. Latest version of Swagger no longer does this?

"type": "string"
},
"createTime": {
"type": "integer",
"format": "int64"
"type": "integer"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Swagger defaulting to in64 now? I believe unix time is int64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it always was :-|

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if it wasn't it would not compile.

@@ -2721,8 +2763,7 @@
"$ref": "#/definitions/ReservationConfig"
},
"storageSize": {
"type": "integer",
"format": "int64"
"type": "integer"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Why integer instead of int64?

Copy link
Contributor

Choose a reason for hiding this comment

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

After our slack conversation, I see that integer now defaults to int64 in the latest Swagger generator.

@sflxn
Copy link
Contributor

sflxn commented Dec 12, 2016

Nothing seemed out of the ordinary. We'll just have to be aware of x-nullable and integer generation changes. Is this the extent of all the changes necessary?

lgtm

@caglar10ur
Copy link
Contributor

LGTM

@vburenin vburenin changed the title [full ci] A huge migration to a newer swagger. A huge migration to a newer swagger. Dec 13, 2016
@mdubya66
Copy link
Contributor

LGTM

@vburenin vburenin merged commit f57cd75 into vmware:master Dec 13, 2016
@vburenin vburenin deleted the swagger-update branch December 14, 2016 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants