Class UpdateCenter
- All Implemented Interfaces:
ModelObject
,Saveable
,SearchableModelObject
,SearchItem
,Loadable
,OnMaster
,org.kohsuke.stapler.StaplerProxy
The main job of this class is to keep track of the latest update center metadata file, and perform installations.
Much of the UI about choosing plugins to install is done in PluginManager
.
The update center can be configured to contact alternate servers for updates
and plugins, and to use alternate strategies for downloading, installing
and updating components. See the Javadocs for UpdateCenter.UpdateCenterConfiguration
for more information.
Extending Update Centers. The update center in Jenkins
can be replaced by defining a
System Property (hudson.model.UpdateCenter.className
). See createUpdateCenter(hudson.model.UpdateCenter.UpdateCenterConfiguration)
.
This className should be available on early startup, so it cannot come only from a library
(e.g. Jenkins module or Extra library dependency in the WAR file project).
Plugins cannot be used for such purpose.
In order to be correctly instantiated, the class definition must have two constructors:
UpdateCenter()
and UpdateCenter(hudson.model.UpdateCenter.UpdateCenterConfiguration)
.
If the class does not comply with the requirements, a fallback to the default UpdateCenter will be performed.
- Since:
- 1.220
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Modifier and TypeClassDescriptionfinal class
final class
Tests the internet connectivity.static final class
AdministrativeMonitor
that checks if there's Jenkins update.class
Base class for a job that downloads a file from the Jenkins project.class
Enables a required plugin, provides feedback in the update centerfinal class
final class
Represents the state of the upgrade activity of Jenkins core.class
Represents the state of the installation activity of one plugin.class
A no-op, e.g.final class
Represents the state of the downgrading activity of plugin.static final class
Deprecated.class
Restarts jenkins.static class
Strategy object for controlling the update center's behaviors.class
Things thatinstallerService
executes. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
ID of the default update site.static final String
static boolean
Deprecated.static final String
static boolean
Escape hatch for StaplerProxy-based access controlprotected final ExecutorService
AnExecutorService
for updating UpdateSites.static final XStream2
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Configures update center to get plugins/updates from alternate servers, and optionally using alternate strategies for downloading, installing and upgrading.protected UpdateSite
static UpdateCenter
Creates an update center.void
doCancelRestart
(org.kohsuke.stapler.StaplerResponse2 response) Cancel all scheduled jenkins restartsorg.kohsuke.stapler.HttpResponse
doConnectionStatus
(org.kohsuke.stapler.StaplerRequest request) Deprecated.org.kohsuke.stapler.HttpResponse
doConnectionStatus
(org.kohsuke.stapler.StaplerRequest2 request) Get the current connection status.void
doDowngrade
(org.kohsuke.stapler.StaplerResponse2 rsp) Performs hudson downgrade.org.kohsuke.stapler.HttpResponse
Called to determine if there was an incomplete installation, what the statuses of the plugins areorg.kohsuke.stapler.HttpResponse
doInstallStatus
(org.kohsuke.stapler.StaplerRequest2 request) Get the current installation status of a plugin set.org.kohsuke.stapler.HttpResponse
Invalidates the update center JSON data for all the sites and force re-retrieval.void
doRestart
(org.kohsuke.stapler.StaplerResponse2 rsp) Performs hudson downgrade.void
doSafeRestart
(org.kohsuke.stapler.StaplerRequest2 request, org.kohsuke.stapler.StaplerResponse2 response) Schedules a Jenkins restart.void
doUpgrade
(org.kohsuke.stapler.StaplerResponse2 rsp) Schedules a Jenkins upgrade.getApi()
Returns String with version of backup .war file, if the file does not exists returns nullgetBadge()
GetsUpdateSite
by its ID.Deprecated.usegetAvailables()
static String
getCategoryDisplayName
(String category) Gets theUpdateSite
from which we receive updates forjenkins.war
.Deprecated.TODO: revisit tool update mechanism, as that should be de-centralized, too.Returns latest Jenkins upgrade job.getJob
(int id) Gets a job by its ID.getJob
(UpdateSite.Plugin plugin) Returns latest install/upgrade job for the given plugin.getJobs()
Returns the list ofUpdateCenter.UpdateCenterJob
representing scheduled installation attempts.Gets the string representing how long ago the data was obtained.Gets the plugin with the given name from the firstUpdateSite
to contain it.getPlugin
(String artifactId, VersionNumber minVersion) Gets the plugin with the given name from the firstUpdateSite
to contain it.getPluginFromAllSites
(String artifactId, VersionNumber minVersion) Gets plugin info from all available sitesReturns the URL of this item relative to the parentSearchItem
.Alias forgetById(java.lang.String)
.The same asgetSites()
but for REST API.getSites()
Returns the list ofUpdateSite
s to be used.boolean
static void
Initializes the update center.boolean
Returns true if backup of jenkins.war exists on the hard driveboolean
If any of the executedUpdateCenter.UpdateCenterJob
s requires a restart to take effect, this method returns true.boolean
Checks if the restart operation is scheduled (which means in near future Jenkins will restart by itself)boolean
Whether it is probably safe to call allUpdateSite.getData()
without blocking.void
load()
Loads the data from the disk into this object.void
Called to persist the currently installing plugin states.void
save()
Saves the configuration info to the disk.Ensure that all UpdateSites are up to date, without requiring a user to browse to the instance.static void
static void
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError, sendError, sendError, sendError
-
Field Details
-
PREDEFINED_UPDATE_SITE_ID
- See Also:
-
ID_DEFAULT
ID of the default update site.- Since:
- 1.483; configurable via system property since 2.4
-
ID_UPLOAD
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final String ID_UPLOAD- See Also:
-
updateService
AnExecutorService
for updating UpdateSites. -
SKIP_PERMISSION_CHECK
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_PERMISSION_CHECKEscape hatch for StaplerProxy-based access control -
neverUpdate
Deprecated.as of 1.333 UseUpdateSite.neverUpdate
-
XSTREAM
-
-
Constructor Details
-
UpdateCenter
public UpdateCenter()
-
-
Method Details
-
createUpdateCenter
@NonNull public static UpdateCenter createUpdateCenter(@CheckForNull UpdateCenter.UpdateCenterConfiguration config) Creates an update center.- Parameters:
config
- Requested configuration. May benull
if defaults should be used- Returns:
- Created Update center.
UpdateCenter
by default, but may be overridden - Since:
- 2.4
-
getApi
-
configure
Configures update center to get plugins/updates from alternate servers, and optionally using alternate strategies for downloading, installing and upgrading.- Parameters:
config
- Configuration data- See Also:
-
getJobs
Returns the list ofUpdateCenter.UpdateCenterJob
representing scheduled installation attempts.- Returns:
- can be empty but never null. Oldest entries first.
-
getJob
Gets a job by its ID. Primarily to makeUpdateCenter.UpdateCenterJob
bound to URL. -
getJob
Returns latest install/upgrade job for the given plugin.- Returns:
- InstallationJob or null if not found
-
getBadge
-
doConnectionStatus
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doConnectionStatus(org.kohsuke.stapler.StaplerRequest2 request) Get the current connection status.Supports a "siteId" request parameter, defaulting to
ID_DEFAULT
for the default update site.- Returns:
- The current connection status.
-
doConnectionStatus
@Deprecated @StaplerNotDispatchable @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doConnectionStatus(org.kohsuke.stapler.StaplerRequest request) Deprecated. -
doIncompleteInstallStatus
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doIncompleteInstallStatus()Called to determine if there was an incomplete installation, what the statuses of the plugins are -
persistInstallStatus
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void persistInstallStatus()Called to persist the currently installing plugin states. This allows us to support install resume if Jenkins is restarted while plugins are being installed. -
doInstallStatus
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doInstallStatus(org.kohsuke.stapler.StaplerRequest2 request) Get the current installation status of a plugin set.Supports a "correlationId" request parameter if you only want to get the install status of a set of plugins requested for install through
PluginManager.doInstallPlugins(org.kohsuke.stapler.StaplerRequest2)
.- Returns:
- The current installation status of a plugin set.
-
getHudsonJob
Returns latest Jenkins upgrade job.- Returns:
- HudsonUpgradeJob or null if not found
-
getSites
Returns the list ofUpdateSite
s to be used. This is a live list, whose change will be persisted automatically.- Returns:
- can be empty but never null.
-
isSiteDataReady
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean isSiteDataReady()Whether it is probably safe to call allUpdateSite.getData()
without blocking.- Returns:
- true if all data is currently ready (or absent); false if some is not ready now (but it will be loaded in the background)
-
getSiteList
The same asgetSites()
but for REST API. -
getSite
Alias forgetById(java.lang.String)
.- Parameters:
id
- ID of the update site to be retrieved- Returns:
- Discovered
UpdateSite
.null
if it cannot be found
-
getLastUpdatedString
Gets the string representing how long ago the data was obtained. Will be the newest of allUpdateSite
s. -
getById
GetsUpdateSite
by its ID. Used to bind them to URL.- Parameters:
id
- ID of the update site to be retrieved- Returns:
- Discovered
UpdateSite
.null
if it cannot be found
-
getCoreSource
Gets theUpdateSite
from which we receive updates forjenkins.war
.- Returns:
null
if no such update center is provided.
-
getDefaultBaseUrl
Deprecated.TODO: revisit tool update mechanism, as that should be de-centralized, too. In the mean time, please try not to use this method, and instead ping us to get this part completed.Gets the default base URL. -
getPlugin
Gets the plugin with the given name from the firstUpdateSite
to contain it.- Returns:
- Discovered
UpdateSite.Plugin
.null
if it cannot be found
-
getPlugin
@CheckForNull public UpdateSite.Plugin getPlugin(String artifactId, @CheckForNull VersionNumber minVersion) Gets the plugin with the given name from the firstUpdateSite
to contain it.- Returns:
- Discovered
UpdateSite.Plugin
.null
if it cannot be found
-
getPluginFromAllSites
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public List<UpdateSite.Plugin> getPluginFromAllSites(String artifactId, @CheckForNull VersionNumber minVersion) Gets plugin info from all available sites- Returns:
- list of plugins
-
doUpgrade
public void doUpgrade(org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Schedules a Jenkins upgrade.- Throws:
IOException
jakarta.servlet.ServletException
-
doInvalidateData
public org.kohsuke.stapler.HttpResponse doInvalidateData()Invalidates the update center JSON data for all the sites and force re-retrieval.- Since:
- 1.432
-
doSafeRestart
public void doSafeRestart(org.kohsuke.stapler.StaplerRequest2 request, org.kohsuke.stapler.StaplerResponse2 response) throws IOException, jakarta.servlet.ServletException Schedules a Jenkins restart.- Throws:
IOException
jakarta.servlet.ServletException
-
doCancelRestart
public void doCancelRestart(org.kohsuke.stapler.StaplerResponse2 response) throws IOException, jakarta.servlet.ServletException Cancel all scheduled jenkins restarts- Throws:
IOException
jakarta.servlet.ServletException
-
isRestartRequiredForCompletion
@Exported public boolean isRestartRequiredForCompletion()If any of the executedUpdateCenter.UpdateCenterJob
s requires a restart to take effect, this method returns true.This doesn't necessarily mean the user has scheduled or initiated the restart operation.
- See Also:
-
isRestartScheduled
public boolean isRestartScheduled()Checks if the restart operation is scheduled (which means in near future Jenkins will restart by itself)- See Also:
-
isDowngradable
public boolean isDowngradable()Returns true if backup of jenkins.war exists on the hard drive -
doDowngrade
public void doDowngrade(org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Performs hudson downgrade.- Throws:
IOException
jakarta.servlet.ServletException
-
doRestart
public void doRestart(org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Performs hudson downgrade.- Throws:
IOException
jakarta.servlet.ServletException
-
getBackupVersion
Returns String with version of backup .war file, if the file does not exists returns null -
addJob
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public Future<UpdateCenter.UpdateCenterJob> addJob(UpdateCenter.UpdateCenterJob job) -
getDisplayName
- Specified by:
getDisplayName
in interfaceModelObject
-
getSearchUrl
Description copied from interface:SearchItem
Returns the URL of this item relative to the parentSearchItem
.- Specified by:
getSearchUrl
in interfaceSearchItem
- Returns:
- URL like "foo" or "foo/bar". The path can end with '/'. The path that starts with '/' will be interpreted as the absolute path (within the context path of Jenkins.)
-
save
public void save()Saves the configuration info to the disk. -
load
Loads the data from the disk into this object.- Specified by:
load
in interfaceLoadable
- Throws:
IOException
- The state could not be loaded.
-
createDefaultUpdateSite
-
getAvailables
-
getCategorizedAvailables
Deprecated.usegetAvailables()
Returns a list of plugins that should be shown in the "available" tab, grouped by category. A plugin with multiple categories will appear multiple times in the list. -
getCategoryDisplayName
-
getUpdates
-
hasIncompatibleUpdates
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean hasIncompatibleUpdates(PluginManager.MetadataCache cache) -
updateAllSites
Ensure that all UpdateSites are up to date, without requiring a user to browse to the instance.- Returns:
- a list of
FormValidation
for each updated Update Site - Throws:
InterruptedException
ExecutionException
- Since:
- 1.501
-
init
@Initializer(after=PLUGINS_STARTED, fatal=false) public static void init(Jenkins h) throws IOException Initializes the update center. This has to wait until after all plugins load, to let custom UpdateCenterConfiguration take effect first.- Throws:
IOException
-
updateAllSitesNow
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void updateAllSitesNow() -
updateDefaultSite
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void updateDefaultSite() -
getTarget
- Specified by:
getTarget
in interfaceorg.kohsuke.stapler.StaplerProxy
-
UpdateSite.neverUpdate