hudson.model
Class UpdateCenter

java.lang.Object
  extended by hudson.model.AbstractModelObject
      extended by hudson.model.UpdateCenter
All Implemented Interfaces:
ModelObject, Saveable, SearchableModelObject, SearchItem, OnMaster

@ExportedBean
public class UpdateCenter
extends AbstractModelObject
implements Saveable, OnMaster

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.UpdateCenterConfiguration for more information.

Since:
1.220
Author:
Kohsuke Kawaguchi

Nested Class Summary
 class UpdateCenter.ConnectionCheckJob
          Tests the internet connectivity.
static class UpdateCenter.CoreUpdateMonitor
          AdministrativeMonitor that checks if there's Jenkins update.
 class UpdateCenter.DownloadJob
          Base class for a job that downloads a file from the Jenkins project.
 class UpdateCenter.HudsonDowngradeJob
           
 class UpdateCenter.HudsonUpgradeJob
          Represents the state of the upgrade activity of Jenkins core.
 class UpdateCenter.InstallationJob
          Represents the state of the installation activity of one plugin.
static class UpdateCenter.PageDecoratorImpl
          Adds the update center data retriever to HTML.
 class UpdateCenter.PluginDowngradeJob
          Represents the state of the downgrading activity of plugin.
static class UpdateCenter.PluginEntry
           
 class UpdateCenter.RestartJenkinsJob
          Restarts jenkins.
static class UpdateCenter.UpdateCenterConfiguration
          Strategy object for controlling the update center's behaviors.
 class UpdateCenter.UpdateCenterJob
          Things that installerService executes.
 
Field Summary
static String ID_DEFAULT
          ID of the default update site.
static boolean neverUpdate
          Deprecated. as of 1.333 Use UpdateSite.neverUpdate
protected  ExecutorService updateService
          An ExecutorService for updating UpdateSites.
static XStream2 XSTREAM
           
 
Fields inherited from interface hudson.model.Saveable
NOOP
 
Constructor Summary
UpdateCenter()
           
 
Method Summary
 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.
 void doCancelRestart(org.kohsuke.stapler.StaplerResponse response)
          Cancel all scheduled jenkins restarts
 void doDowngrade(org.kohsuke.stapler.StaplerResponse rsp)
          Performs hudson downgrade.
 org.kohsuke.stapler.HttpResponse doInvalidateData()
          Invalidates the update center JSON data for all the sites and force re-retrieval.
 void doRestart(org.kohsuke.stapler.StaplerResponse rsp)
          Performs hudson downgrade.
 void doSafeRestart(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response)
          Schedules a Jenkins restart.
 void doUpgrade(org.kohsuke.stapler.StaplerResponse rsp)
          Schedules a Jenkins upgrade.
 Api getApi()
           
 List<UpdateSite.Plugin> getAvailables()
           
 String getBackupVersion()
          Returns String with version of backup .war file, if the file does not exists returns null
 UpdateSite getById(String id)
          Gets UpdateSite by its ID.
 UpdateCenter.PluginEntry[] getCategorizedAvailables()
          Returns a list of plugins that should be shown in the "available" tab, grouped by category.
 UpdateSite getCoreSource()
          Gets the UpdateSite from which we receive updates for jenkins.war.
 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.
 String getDisplayName()
           
 UpdateCenter.HudsonUpgradeJob getHudsonJob()
          Returns latest Jenkins upgrade job.
 UpdateCenter.UpdateCenterJob getJob(int id)
          Gets a job by its ID.
 UpdateCenter.InstallationJob getJob(UpdateSite.Plugin plugin)
          Returns latest install/upgrade job for the given plugin.
 List<UpdateCenter.UpdateCenterJob> getJobs()
          Returns the list of UpdateCenter.UpdateCenterJob representing scheduled installation attempts.
 String getLastUpdatedString()
          Gets the string representing how long ago the data was obtained.
 UpdateSite.Plugin getPlugin(String artifactId)
          Gets the plugin with the given name from the first UpdateSite to contain it.
 String getSearchUrl()
          Returns the URL of this item relative to the parent SearchItem.
 UpdateSite getSite(String id)
          Alias for getById(java.lang.String).
 List<UpdateSite> getSiteList()
          The same as getSites() but for REST API.
 PersistedList<UpdateSite> getSites()
          Returns the list of UpdateSites to be used.
 List<UpdateSite.Plugin> getUpdates()
           
static void init(Jenkins h)
          Initializes the update center.
 boolean isDowngradable()
          Returns true if backup of jenkins.war exists on the hard drive
 boolean isRestartRequiredForCompletion()
          If any of the executed UpdateCenter.UpdateCenterJobs requires a restart to take effect, this method returns true.
 boolean isRestartScheduled()
          Checks if the restart operation is scheduled (which means in near future Jenkins will restart by itself)
 void load()
          Loads the data from the disk into this object.
 void save()
          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.
 
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_DEFAULT

public static final String ID_DEFAULT
ID of the default update site.

Since:
1.483
See Also:
Constant Field Values

updateService

protected final ExecutorService updateService
An ExecutorService for updating UpdateSites.


neverUpdate

public static boolean neverUpdate
Deprecated. as of 1.333 Use UpdateSite.neverUpdate

XSTREAM

public static final XStream2 XSTREAM
Constructor Detail

UpdateCenter

public UpdateCenter()
Method Detail

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
public List<UpdateCenter.UpdateCenterJob> getJobs()
Returns the list of UpdateCenter.UpdateCenterJob representing 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 make UpdateCenter.UpdateCenterJob bound 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

getHudsonJob

public UpdateCenter.HudsonUpgradeJob getHudsonJob()
Returns latest Jenkins upgrade job.

Returns:
HudsonUpgradeJob or null if not found

getSites

public PersistedList<UpdateSite> getSites()
Returns the list of UpdateSites to be used. This is a live list, whose change will be persisted automatically.

Returns:
can be empty but never null.

getSiteList

@Exported(name="sites")
public List<UpdateSite> getSiteList()
The same as getSites() but for REST API.


getSite

public UpdateSite getSite(String id)
Alias for getById(java.lang.String).


getLastUpdatedString

public String getLastUpdatedString()
Gets the string representing how long ago the data was obtained. Will be the newest of all UpdateSites.


getById

public UpdateSite getById(String id)
Gets UpdateSite by its ID. Used to bind them to URL.


getCoreSource

public UpdateSite getCoreSource()
Gets the UpdateSite from which we receive updates for jenkins.war.

Returns:
null if no such update center is provided.

getDefaultBaseUrl

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 first UpdateSite to contain it.


doUpgrade

public void doUpgrade(org.kohsuke.stapler.StaplerResponse rsp)
               throws IOException,
                      javax.servlet.ServletException
Schedules a Jenkins upgrade.

Throws:
IOException
javax.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.ServletException
Schedules a Jenkins restart.

Throws:
IOException
javax.servlet.ServletException

doCancelRestart

public void doCancelRestart(org.kohsuke.stapler.StaplerResponse response)
                     throws IOException,
                            javax.servlet.ServletException
Cancel all scheduled jenkins restarts

Throws:
IOException
javax.servlet.ServletException

isRestartRequiredForCompletion

@Exported
public boolean isRestartRequiredForCompletion()
If any of the executed UpdateCenter.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.ServletException
Performs hudson downgrade.

Throws:
IOException
javax.servlet.ServletException

doRestart

public void doRestart(org.kohsuke.stapler.StaplerResponse rsp)
               throws IOException,
                      javax.servlet.ServletException
Performs hudson downgrade.

Throws:
IOException
javax.servlet.ServletException

getBackupVersion

public String getBackupVersion()
Returns String with version of backup .war file, if the file does not exists returns null


getDisplayName

public String getDisplayName()
Specified by:
getDisplayName in interface ModelObject

getSearchUrl

public String getSearchUrl()
Description copied from interface: SearchItem
Returns the URL of this item relative to the parent SearchItem.

Specified by:
getSearchUrl in interface SearchItem
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 Hudson.)

save

public void save()
Saves the configuration info to the disk.

Specified by:
save in interface Saveable

load

public void load()
          throws IOException
Loads the data from the disk into this object.

Throws:
IOException

getAvailables

public List<UpdateSite.Plugin> getAvailables()

getCategorizedAvailables

public UpdateCenter.PluginEntry[] getCategorizedAvailables()
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.


getUpdates

public List<UpdateSite.Plugin> getUpdates()

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 FormValidation for each updated Update Site
Throws:
ExecutionException
InterruptedException
Since:
1.501

init

@Initializer(after=PLUGINS_STARTED)
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


Copyright © 2004-2013. All Rights Reserved.