-
Notifications
You must be signed in to change notification settings - Fork 136
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
Swappable HTTP Client #273
Conversation
This allows us to separate the entity from the client
Goal is to create a simpler contract for alternative clients to implement.
Explicitly setting this to null for clarity. This also reduces the parameters needed to construct a client.
StashNotifier gets a HttpNotifier that encapsulates all of the client-specific code. Old methods are left intact, but deprecated, in case other consumers are referencing these methods.
The default implementation is the same as today - always returning the DefaultApacheHttpNotifier.
Users can specify a system property to have a custom HttpNotifierSelector injected instead of the default.
This is resolved at runtime and does not need to be serialized. Use setter injection and inject HttpNotifierSelector when used to prevent runtime NPE.
Simplifies HttpNotifierSelector implementations by allowing authors to easily inject the plugin's default to fall back to.
Thanks @sghill. I'll take a deep look on this, but I can't promise this will be fast |
Sounds good @scaytrase. Let me know if I can help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM. Is it supposed to be drop-in replacement?
@scaytrase yes, it should function the same. Users like me who want something else need to:
|
I have no way to test this, since I've no own installation of Jenkins today, so I have to trust my eyes here. This looks reasonable and good for me. I'll merge this and try to release this as fast as I can, maybe in a few days, maybe tomorrow, cant be sure |
Thanks @sghill |
Hi @scaytrase, thanks for the review and the merge. Do you think this week is looking likely for a release? |
I've encountered some problems releasing this. Trying to sort thing out, I've lost my local release setup from last release. Sounds like some unreleased changes break release flow |
Looks like I've messed up JDK installations. Can you check that new version is available? |
I don't think 1.21 made it unfortunately. The last version I see in Jenkins Artifactory is 1.20. |
That's bad. Will try again in the evening |
1.22 appeared on your link. can you check it? |
Confirmed 1.22 is released and working. I ran a test build with the default notifier and it posted to Bitbucket successfully. Thanks! |
Thank you too for your contribution |
This is a possible implementation of #272.
Here's a quick drawing of how this changes the plugin. I think it's 100% backwards-compatible, but allows for other plugins to change how notifications are sent without job configuration changing.
HttpNotifier
The first change is to separate the Apache HTTP Client implementation from what the plugin is doing. I left all the old methods intact so there could be one release with a deprecation, but I'm happy to remove them if you'd prefer. I called this interface
HttpNotifier
. The implementation included in the plugin (DefaultApacheHttpNotifier
) is virtually unchanged, differing only to support the more generic method signatures.HttpNotifierSelector
The second change introduces a
HttpNotifierSelector
. This is a layer that allows for doing live migrations to a running system. I have an implementation in another plugin that checks a list for jobs that are "enrolled" in the migration I'm doing. If a job is in the list, it gets myCustomHttpNotifier
with different settings. If the job is not enrolled, it gets the default implementation. If there is some problem, I'm able to unenroll it without disrupting anyone and investigate what else needs to happen first while the build continues on the default notifier.The implementation included in the plugin always returns
DefaultApacheHttpNotifier
for backwards compatibility.Implementing A Custom
HttpNotifierSelector
Here's how I have implemented a custom selector:
To use a custom
HttpNotifierSelector
, Jenkins has to know about it. This means it can either be in a Guice module tagged with thehudson.Extension
annotation, or the class can be tagged directly withhudson.Extension
. I think Guice makes testing much more friendly, so that's the approach I'm using:Note it's easy to inject the default
HttpNotifierSelector
for fallback scenarios.Choosing A Custom
HttpNotifierSelector
ImplementationTo choose an alternate implementation, the system property
org.jenkinsci.plugins.stashNotifier.HttpNotifierSelector.className
must be set to the fully qualified class name of the custom class. Jenkins will log which implementation its using when the first build using stashNotifier runs. Here's an example from my system:If a user happens to define a class name that cannot be found, it will log a warning and fall back to the default implementation:
I chose the system property approach because this is what Jenkins does for custom
PluginManager
implementations.