Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

JCLOUDS-543: hack to not barf on old images that are no longer listed in the api #58

Closed
wants to merge 3 commits into from

Conversation

cobbzilla
Copy link

preface -- I'm sure there is probably a better way to do this and I'm open to suggestions on changes.

the problem: some of the droplets in my account are long-running, and have image_ids that are no longer returned from DO's /images api call. So, when I'm trying to create a new droplet, it fails here with a NPE while iterating over the existing droplets (trying to find ones that might match the group name).

@buildhive
Copy link

jclouds » jclouds-labs #982 SUCCESS
This pull request looks good
(what's this?)

@cloudbees-pull-request-builder

jclouds-labs-pull-requests #141 SUCCESS
This pull request looks good

@nacx
Copy link
Member

nacx commented Apr 19, 2014

Thanks for the contribution @cobbzilla!

Out of curiosity, what happens if you just leave the image (and all image derived fields) to null? If possible, I think it makes more sense to have a node without image, to express it does no longer exist, than having the wrong one set.

It's nice to have DO users and to see use cases like this! Your long-living droplets will help us umderstand some of their api internals :)

@demobox
Copy link
Member

demobox commented Apr 20, 2014

if you just leave the image (and all image derived fields) to null

Would an Optional perhaps make sense here, just as an alternative suggestion?

@nacx
Copy link
Member

nacx commented Apr 20, 2014

That would be cleaner but require to change the portable model (affecting all providers). For the moment I'd see what happens when leaving them null, and if we find this being a common/real use case in other providers (how often does this happen?) we can properly model it in the portable interface. WDYT @demobox?

@demobox
Copy link
Member

demobox commented Apr 20, 2014

WDYT @demobox?

Agreed...if this is a corner case, the minimal possible change sounds sensible (how about a "Null image object", then, i.e. something like Image.NULL, rather than null with the attendant NPE risks?

@nacx
Copy link
Member

nacx commented Apr 20, 2014

The point is that the model only exposes the imageId, which is a String, and the OperatingSystem, both already marked as @nullable in the NodeMetadata interface; the entire image object itself is not exposed

@demobox
Copy link
Member

demobox commented Apr 20, 2014

and the OperatingSystem, both already marked as @nullable in the NodeMetadata interface

Oops...lazy me ;-) In that case, null seems indeed like a good option.

@nacx
Copy link
Member

nacx commented Apr 20, 2014

And also lazy me! I didn't express it properly in my first comment :) It's always good to discuss these kind of details!

@cobbzilla
Copy link
Author

@nacx I'm not sure I understand your question -- if I let the "image" variable be null, the very next line (builder.imageId(image.getId());) causes a NPE.

@nacx
Copy link
Member

nacx commented Apr 22, 2014

I meant to not assign the imageId and operatingSystem if the image is null. Could you try that?

@cobbzilla
Copy link
Author

@nacx I see what you mean -- yes I can try that. I'll report back after I've given it a whirl.

@cobbzilla
Copy link
Author

yup, that change seems to have worked fine -- the integration test I have that uses this code still passes A-OK.

@cloudbees-pull-request-builder

jclouds-labs-pull-requests #142 SUCCESS
This pull request looks good

@buildhive
Copy link

jclouds » jclouds-labs #984 SUCCESS
This pull request looks good
(what's this?)

@@ -91,8 +91,10 @@ public boolean apply(Location location) {
}));

Image image = images.get().get(String.valueOf(input.getImageId()));
builder.imageId(image.getId());
builder.operatingSystem(image.getOperatingSystem());
if (image != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment describing under which circumstances this may occur?

@nacx: I guess we should also have a JIRA issue and a unit test for this?

@nacx
Copy link
Member

nacx commented Apr 23, 2014

I guess we should also have a JIRA issue and a unit test for this?

I've just opened JCLOUDS-543 to track this.

There is no unit test class for the DropletToNodeMetadata class. @cobbzilla, mind creating the DropletToNodeMetadataTest class and add a unit test that validates your change? We use EasyMock for this kind of unit tests. If you need some reference, you can take a look at how the EC2 or Abiquo tests work. There's no need to add a complete test for all cases in this PR, just add one to validate your changes. Thanks!

@demobox demobox changed the title hack to not barf on old images that are no longer listed in the api JCLOUDS-543: hack to not barf on old images that are no longer listed in the api Apr 23, 2014
@demobox
Copy link
Member

demobox commented Apr 23, 2014

I've just opened JCLOUDS-543 to track this.

Thanks, @nacx!

@cobbzilla
Copy link
Author

I added the comment. Re adding a test, I have to admit I'm pretty swamped and I may take a long while getting to it. Time permitting, I will try.

@cloudbees-pull-request-builder

jclouds-labs-pull-requests #143 SUCCESS
This pull request looks good

@buildhive
Copy link

jclouds » jclouds-labs #985 SUCCESS
This pull request looks good
(what's this?)

@nacx
Copy link
Member

nacx commented Apr 23, 2014

Thanks @cobbzilla. I'm working on a PR to add tests for the existing functionality in those transformation functions (let's fix our technical debt!) and hope to open it tomorrow. If it is ok to you, you can wait until then, and just add your test to the ones I'll create.
Anyway, feel free to create the tests on your own and update this PR! :)

@cobbzilla
Copy link
Author

thanks @nacx -- I would much prefer adding one test to an existing test suite that clearly illustrates the patterns/conventions you'd like to see followed, versus stumbling around in the dark :)

If you do end up creating some tests, could you post to this thread and point me to the appropriate place where you'd like me to add a test for this PR?

@demobox
Copy link
Member

demobox commented May 13, 2014

@nacx @cobbzilla Ping on this? Just wondering where we're currently at here..?

@nacx
Copy link
Member

nacx commented May 13, 2014

I plan to merge the checkstyle PR tomorrow and then open a new one adding the test classes. So in a day or two everything should be in place to make it trivial to add the missing tests!

@nacx
Copy link
Member

nacx commented May 13, 2014

Thanks for thw ping @demobox! I started this but completely forgot! :)

@cobbzilla
Copy link
Author

@demobox I will patiently wait for some kind of exemplary test framework that's easy to understand so I can quickly add a test to it.

It'd be nice to get this PR merged in, but I'm not in a huge rush.

@demobox
Copy link
Member

demobox commented May 14, 2014

I plan to merge the checkstyle PR tomorrow and then open a new one adding the test classes

Ah, great. Thanks, @nacx!

@nacx
Copy link
Member

nacx commented May 16, 2014

@demobox @cobbzilla I've just opened #62 adding the missing tests.

@demobox
Copy link
Member

demobox commented May 19, 2014

I've just opened #62 adding the missing tests.

Thanks, @nacx!

@nacx
Copy link
Member

nacx commented May 19, 2014

This is also affecting the Jenkins plugin:
https://issues.jenkins-ci.org/browse/JENKINS-22963

As commented in the issue there, now that thay've added support for slugs everywhere I think the right fix would be to use them everywhere instead of the ids. I'll try to have a PR for that soon if you don't beat me! :)

@demobox
Copy link
Member

demobox commented May 19, 2014

I'll try to have a PR for that soon if you don't beat me! :)

I'm not in the race, but perhaps @cobbzilla is ;-)

@nacx
Copy link
Member

nacx commented May 19, 2014

I've just opened #63 adding support for using the "slug" values as IDs to properly fix the entire thing, now that we know more a bit more about the DO api. It was not as straightforward as I had initially supposed (now methods have been added to the api), but I think it will make the provider easier to use.

If that PR buids without issues (I've executed the live tests locally and all pass), I think we'd better merge it and close this one. Are you ok with this @cobbzilla? Many thanks for the investigation and the pointers! That has definitely been the key point to these improvements and helped a lot identifying the Jenkins issue!

@cobbzilla
Copy link
Author

Sure -- I'm fine with merging it. The only potential problem would be if some code relied on the builder having a non-null imageId or operatingSystem, in which case we've just pushed the NPE to somewhere else. But the alternative is to bomb out on a lot of stuff that would otherwise work just fine with a null imageId/operatingSystem. ceteris paribus, I think this fix is the better way.

@nacx nacx closed this May 21, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants