Class UpdateCenter
- java.lang.Object
-
- hudson.model.AbstractModelObject
-
- hudson.model.UpdateCenter
-
- All Implemented Interfaces:
ModelObject,Saveable,SearchableModelObject,SearchItem,Loadable,OnMaster,org.kohsuke.stapler.StaplerProxy
@ExportedBean public class UpdateCenter extends AbstractModelObject implements Loadable, Saveable, OnMaster, org.kohsuke.stapler.StaplerProxy
Controls update center capability.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.UpdateCenterConfigurationfor more information.Extending Update Centers. The update center in
Jenkinscan be replaced by defining a System Property (hudson.model.UpdateCenter.className). SeecreateUpdateCenter(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()andUpdateCenter(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
Nested Classes Modifier and Type Class Description classUpdateCenter.CompleteBatchJobclassUpdateCenter.ConnectionCheckJobTests the internet connectivity.static classUpdateCenter.CoreUpdateMonitorAdministrativeMonitorthat checks if there's Jenkins update.classUpdateCenter.DownloadJobBase class for a job that downloads a file from the Jenkins project.classUpdateCenter.EnableJobEnables a required plugin, provides feedback in the update centerclassUpdateCenter.HudsonDowngradeJobclassUpdateCenter.HudsonUpgradeJobRepresents the state of the upgrade activity of Jenkins core.classUpdateCenter.InstallationJobRepresents the state of the installation activity of one plugin.classUpdateCenter.NoOpJobA no-op, e.g.classUpdateCenter.PluginDowngradeJobRepresents the state of the downgrading activity of plugin.static classUpdateCenter.PluginEntryDeprecated.classUpdateCenter.RestartJenkinsJobRestarts jenkins.static classUpdateCenter.UpdateCenterConfigurationStrategy object for controlling the update center's behaviors.classUpdateCenter.UpdateCenterJobThings thatinstallerServiceexecutes.
-
Field Summary
Fields Modifier and Type Field Description static StringID_DEFAULTID of the default update site.static StringID_UPLOADstatic booleanneverUpdateDeprecated.as of 1.333 UseUpdateSite.neverUpdatestatic StringPREDEFINED_UPDATE_SITE_IDstatic booleanSKIP_PERMISSION_CHECKEscape hatch for StaplerProxy-based access controlprotected ExecutorServiceupdateServiceAnExecutorServicefor updating UpdateSites.static XStream2XSTREAM
-
Constructor Summary
Constructors Constructor Description UpdateCenter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Future<UpdateCenter.UpdateCenterJob>addJob(UpdateCenter.UpdateCenterJob job)voidconfigure(UpdateCenter.UpdateCenterConfiguration config)Configures update center to get plugins/updates from alternate servers, and optionally using alternate strategies for downloading, installing and upgrading.protected UpdateSitecreateDefaultUpdateSite()static UpdateCentercreateUpdateCenter(UpdateCenter.UpdateCenterConfiguration config)Creates an update center.voiddoCancelRestart(org.kohsuke.stapler.StaplerResponse response)Cancel all scheduled jenkins restartsorg.kohsuke.stapler.HttpResponsedoConnectionStatus(org.kohsuke.stapler.StaplerRequest request)Get the current connection status.voiddoDowngrade(org.kohsuke.stapler.StaplerResponse rsp)Performs hudson downgrade.org.kohsuke.stapler.HttpResponsedoIncompleteInstallStatus()Called to determine if there was an incomplete installation, what the statuses of the plugins areorg.kohsuke.stapler.HttpResponsedoInstallStatus(org.kohsuke.stapler.StaplerRequest request)Get the current installation status of a plugin set.org.kohsuke.stapler.HttpResponsedoInvalidateData()Invalidates the update center JSON data for all the sites and force re-retrieval.voiddoRestart(org.kohsuke.stapler.StaplerResponse rsp)Performs hudson downgrade.voiddoSafeRestart(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response)Schedules a Jenkins restart.voiddoUpgrade(org.kohsuke.stapler.StaplerResponse rsp)Schedules a Jenkins upgrade.ApigetApi()List<UpdateSite.Plugin>getAvailables()StringgetBackupVersion()Returns String with version of backup .war file, if the file does not exists returns nullBadgegetBadge()UpdateSitegetById(String id)GetsUpdateSiteby its ID.UpdateCenter.PluginEntry[]getCategorizedAvailables()Deprecated.usegetAvailables()static StringgetCategoryDisplayName(String category)UpdateSitegetCoreSource()Gets theUpdateSitefrom which we receive updates forjenkins.war.StringgetDefaultBaseUrl()Deprecated.TODO: revisit tool update mechanism, as that should be de-centralized, too.StringgetDisplayName()UpdateCenter.HudsonUpgradeJobgetHudsonJob()Returns latest Jenkins upgrade job.UpdateCenter.UpdateCenterJobgetJob(int id)Gets a job by its ID.UpdateCenter.InstallationJobgetJob(UpdateSite.Plugin plugin)Returns latest install/upgrade job for the given plugin.List<UpdateCenter.UpdateCenterJob>getJobs()Returns the list ofUpdateCenter.UpdateCenterJobrepresenting scheduled installation attempts.StringgetLastUpdatedString()Gets the string representing how long ago the data was obtained.UpdateSite.PlugingetPlugin(String artifactId)Gets the plugin with the given name from the firstUpdateSiteto contain it.UpdateSite.PlugingetPlugin(String artifactId, VersionNumber minVersion)Gets the plugin with the given name from the firstUpdateSiteto contain it.List<UpdateSite.Plugin>getPluginFromAllSites(String artifactId, VersionNumber minVersion)Gets plugin info from all available sitesStringgetSearchUrl()Returns the URL of this item relative to the parentSearchItem.UpdateSitegetSite(String id)Alias forgetById(java.lang.String).List<UpdateSite>getSiteList()The same asgetSites()but for REST API.PersistedList<UpdateSite>getSites()Returns the list ofUpdateSites to be used.ObjectgetTarget()List<UpdateSite.Plugin>getUpdates()booleanhasIncompatibleUpdates(PluginManager.MetadataCache cache)static voidinit(Jenkins h)Initializes the update center.booleanisDowngradable()Returns true if backup of jenkins.war exists on the hard drivebooleanisRestartRequiredForCompletion()If any of the executedUpdateCenter.UpdateCenterJobs requires a restart to take effect, this method returns true.booleanisRestartScheduled()Checks if the restart operation is scheduled (which means in near future Jenkins will restart by itself)booleanisSiteDataReady()Whether it is probably safe to call allUpdateSite.getData()without blocking.voidload()Loads the data from the disk into this object.voidpersistInstallStatus()Called to persist the currently installing plugin states.voidsave()Saves the configuration info to the disk.List<FormValidation>updateAllSites()Ensure that all UpdateSites are up to date, without requiring a user to browse to the instance.static voidupdateAllSitesNow()static voidupdateDefaultSite()-
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
-
-
-
-
Field Detail
-
PREDEFINED_UPDATE_SITE_ID
public static final String PREDEFINED_UPDATE_SITE_ID
- See Also:
- Constant Field Values
-
ID_DEFAULT
public static final String 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:
- Constant Field Values
-
updateService
protected final ExecutorService updateService
AnExecutorServicefor updating UpdateSites.
-
SKIP_PERMISSION_CHECK
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_PERMISSION_CHECK
Escape hatch for StaplerProxy-based access control
-
neverUpdate
@Deprecated public static boolean neverUpdate
Deprecated.as of 1.333 UseUpdateSite.neverUpdate
-
XSTREAM
public static final XStream2 XSTREAM
-
-
Method Detail
-
createUpdateCenter
@NonNull public static UpdateCenter createUpdateCenter(@CheckForNull UpdateCenter.UpdateCenterConfiguration config)
Creates an update center.- Parameters:
config- Requested configuration. May benullif defaults should be used- Returns:
- Created Update center.
UpdateCenterby default, but may be overridden - Since:
- 2.4
-
getApi
public Api getApi()
-
configure
public void configure(UpdateCenter.UpdateCenterConfiguration config)
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:
UpdateCenter.UpdateCenterConfiguration
-
getJobs
@Exported @StaplerDispatchable public List<UpdateCenter.UpdateCenterJob> getJobs()
Returns the list ofUpdateCenter.UpdateCenterJobrepresenting scheduled installation attempts.- Returns:
- can be empty but never null. Oldest entries first.
-
getJob
public UpdateCenter.UpdateCenterJob getJob(int id)
Gets a job by its ID. Primarily to makeUpdateCenter.UpdateCenterJobbound to URL.
-
getJob
public UpdateCenter.InstallationJob getJob(UpdateSite.Plugin plugin)
Returns latest install/upgrade job for the given plugin.- Returns:
- InstallationJob or null if not found
-
getBadge
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public Badge getBadge()
-
doConnectionStatus
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public org.kohsuke.stapler.HttpResponse doConnectionStatus(org.kohsuke.stapler.StaplerRequest request)
Get the current connection status.Supports a "siteId" request parameter, defaulting to
ID_DEFAULTfor the default update site.- Returns:
- The current connection status.
-
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.StaplerRequest 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.StaplerRequest).- Returns:
- The current installation status of a plugin set.
-
getHudsonJob
public UpdateCenter.HudsonUpgradeJob getHudsonJob()
Returns latest Jenkins upgrade job.- Returns:
- HudsonUpgradeJob or null if not found
-
getSites
@StaplerDispatchable public PersistedList<UpdateSite> getSites()
Returns the list ofUpdateSites 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
@Exported(name="sites") public List<UpdateSite> getSiteList()
The same asgetSites()but for REST API.
-
getSite
@CheckForNull public UpdateSite getSite(String id)
Alias forgetById(java.lang.String).- Parameters:
id- ID of the update site to be retrieved- Returns:
- Discovered
UpdateSite.nullif it cannot be found
-
getLastUpdatedString
public String getLastUpdatedString()
Gets the string representing how long ago the data was obtained. Will be the newest of allUpdateSites.
-
getById
@CheckForNull public UpdateSite getById(String id)
GetsUpdateSiteby its ID. Used to bind them to URL.- Parameters:
id- ID of the update site to be retrieved- Returns:
- Discovered
UpdateSite.nullif it cannot be found
-
getCoreSource
@CheckForNull public UpdateSite getCoreSource()
Gets theUpdateSitefrom which we receive updates forjenkins.war.- Returns:
nullif no such update center is provided.
-
getDefaultBaseUrl
@Deprecated public String 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
@CheckForNull public UpdateSite.Plugin getPlugin(String artifactId)
Gets the plugin with the given name from the firstUpdateSiteto contain it.- Returns:
- Discovered
UpdateSite.Plugin.nullif it cannot be found
-
getPlugin
@CheckForNull public UpdateSite.Plugin getPlugin(String artifactId, @CheckForNull VersionNumber minVersion)
Gets the plugin with the given name from the firstUpdateSiteto contain it.- Returns:
- Discovered
UpdateSite.Plugin.nullif 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.StaplerResponse rsp) throws IOException, javax.servlet.ServletExceptionSchedules a Jenkins upgrade.- Throws:
IOExceptionjavax.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.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response) throws IOException, javax.servlet.ServletExceptionSchedules a Jenkins restart.- Throws:
IOExceptionjavax.servlet.ServletException
-
doCancelRestart
public void doCancelRestart(org.kohsuke.stapler.StaplerResponse response) throws IOException, javax.servlet.ServletExceptionCancel all scheduled jenkins restarts- Throws:
IOExceptionjavax.servlet.ServletException
-
isRestartRequiredForCompletion
@Exported public boolean isRestartRequiredForCompletion()
If any of the executedUpdateCenter.UpdateCenterJobs 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()
-
isRestartScheduled
public boolean isRestartScheduled()
Checks if the restart operation is scheduled (which means in near future Jenkins will restart by itself)- See Also:
isRestartRequiredForCompletion()
-
isDowngradable
public boolean isDowngradable()
Returns true if backup of jenkins.war exists on the hard drive
-
doDowngrade
public void doDowngrade(org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletExceptionPerforms hudson downgrade.- Throws:
IOExceptionjavax.servlet.ServletException
-
doRestart
public void doRestart(org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletExceptionPerforms hudson downgrade.- Throws:
IOExceptionjavax.servlet.ServletException
-
getBackupVersion
public String 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
public String getDisplayName()
- Specified by:
getDisplayNamein interfaceModelObject
-
getSearchUrl
public String getSearchUrl()
Description copied from interface:SearchItemReturns the URL of this item relative to the parentSearchItem.- Specified by:
getSearchUrlin 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
public void load() throws IOExceptionLoads the data from the disk into this object.- Specified by:
loadin interfaceLoadable- Throws:
IOException- The state could not be loaded.
-
createDefaultUpdateSite
protected UpdateSite createDefaultUpdateSite()
-
getAvailables
@Exported public List<UpdateSite.Plugin> getAvailables()
-
getCategorizedAvailables
@Deprecated public UpdateCenter.PluginEntry[] 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
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String getCategoryDisplayName(String category)
-
getUpdates
public List<UpdateSite.Plugin> getUpdates()
-
hasIncompatibleUpdates
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public boolean hasIncompatibleUpdates(PluginManager.MetadataCache cache)
-
updateAllSites
public List<FormValidation> updateAllSites() throws InterruptedException, ExecutionException
Ensure that all UpdateSites are up to date, without requiring a user to browse to the instance.- Returns:
- a list of
FormValidationfor each updated Update Site - Throws:
InterruptedExceptionExecutionException- 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
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public Object getTarget()
- Specified by:
getTargetin interfaceorg.kohsuke.stapler.StaplerProxy
-
-