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

[JENKINS-25106] Support minimumNoInstances #401

Merged
merged 11 commits into from
Sep 25, 2019

Conversation

erikhakansson
Copy link
Contributor

I'm attempting to open an entirely new PR instead of #343 to see if my weird issues goes away.

@@ -126,6 +128,8 @@

public int instanceCap;

public int minimumNumberOfInstances;
Copy link
Member

Choose a reason for hiding this comment

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

No need to add more public fields here. That's not a great practice in Java.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I probably just followed the existing pattern there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commited a fix


import java.util.List;

public abstract class EC2SlaveConfig {
Copy link
Member

Choose a reason for hiding this comment

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

I'm just think out loud here, but this config with builder class pattern being developed here seems like a nice candidate for improving Jenkins' databinding feature to natively support this type of pattern.

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'm generally of fan of builder patterns as it shows the user of the class a very verbose representation of what's used in constructing the class. withSomeProperty() is a lot more easier to understand at a quick glance than Constructor parameter #5 :)

That being said, I don't have that much experience with Jenkins' databinding, or Jenkins at all (other than using it) so I don't feel qualified to judge if this pattern works everywhere else :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't, either, though I do have extensive experience in the equivalent functionality in Log4j2, so it's an active interest of mine in general. :)

The gist of my idea at least would be using @DataBoundSetter on the with or set methods and a build() method (or a new annotation), though I'm not sure how that would fit in with Stapler and Jenkins APIs. Hopefully I'll remember to revisit this after figuring that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yeah there's always the issue of remembering stuff.

@jvz
Copy link
Member

jvz commented Sep 20, 2019

Do you think the new slave-related classes can use the updated term "agent"? We could refactor the old slave classes to use agent in a separate PR, but it'd be easier if we didn't introduce new code with the old name since it's a pain to change when people are already depending on the API.

erikhakansson and others added 3 commits September 20, 2019 20:23
Co-Authored-By: Matt Sicker <boards@gmail.com>
Co-Authored-By: Matt Sicker <boards@gmail.com>
@erikhakansson
Copy link
Contributor Author

Do you think the new slave-related classes can use the updated term "agent"? We could refactor the old slave classes to use agent in a separate PR, but it'd be easier if we didn't introduce new code with the old name since it's a pain to change when people are already depending on the API.

Sure! Just Slave to Agent like that? Is that a Jenkins thing, that it's been changed to Agent?

@jvz
Copy link
Member

jvz commented Sep 20, 2019

At some point, Jenkins changed the name from "slave" to "agent" officially, though fully migrating everything to the new name would break various existing APIs, so it's mostly been done through the UI and documentation. New code has been encouraged to use the new name.

Someone went through the trouble of renaming Hudson to Jenkins in a backwards compatible way, so I'm not sure why the main Slave classes haven't also been similarly renamed yet. The jar file is agent.jar nowadays, though Remoting supports a few filename variants.

return instance;
}

EC2OndemandSlave createOnDemandSlave(EC2AgentConfig.OnDemand config) throws Descriptor.FormException, IOException;
Copy link
Member

Choose a reason for hiding this comment

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

You can also rename the newly added methods.

} else {
mock = Mockito.mock(AmazonEC2.class);
mock = Mockito.mock(AmazonEC2Client.class);
Copy link
Member

@jvz jvz Sep 20, 2019

Choose a reason for hiding this comment

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

Nit: You can use static imports for Mockito methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added static import now, but I actually prefer not to have them. With Mockito.mock it makes it obvious that it's Mockito and not e.g. PowerMock.

Similarly to assertEquals; are we talking AssertJ, Junit, something else? I just prefer the explicitness :)

Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the great work!

@erikhakansson
Copy link
Contributor Author

LGTM! Thanks for the great work!

Thank you! :)

Copy link
Contributor

@res0nance res0nance left a comment

Choose a reason for hiding this comment

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

This is some great work

@res0nance res0nance added the enhancement Feature additions or enhancements label Sep 23, 2019
@erikhakansson
Copy link
Contributor Author

Thanks :) Let's see if CI ever lets it through though :)

Copy link
Contributor

@fcojfernandez fcojfernandez left a comment

Choose a reason for hiding this comment

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

Really LGTM!

@res0nance res0nance merged commit 31ec8d6 into jenkinsci:master Sep 25, 2019
@erikhakansson erikhakansson deleted the minimumNoInstances branch September 27, 2019 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature additions or enhancements
Projects
None yet
4 participants