Class GerritServer
java.lang.Object
com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer
- All Implemented Interfaces:
Action,Describable<GerritServer>,ModelObject
@ExportedBean(defaultVisibility=2)
@StaplerAccessibleType
public class GerritServer
extends Object
implements Describable<GerritServer>, Action
Every instance of this class represents a Gerrit server having its own unique name,
connection, project list updater, configuration, and lists of listeners.
All interactions with a Gerrit server should go through this class.
The list of GerritServer is kept in @PluginImpl.
- Author:
- Robert Sandell <robert.sandell@sonyericsson.com>, Mathieu Wang <mathieu.wang@ericsson.com>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescriptor is only used for UI form bindings. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey that is used to select to trigger a build on events from any server. -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor.GerritServer(String name) Constructor.GerritServer(String name, boolean noConnectionOnStartup) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(com.sonymobile.tools.gerrit.gerritevents.ConnectionListener listener) Adds a Connection Listener to the manager.voidaddListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener listener) Adds a listener to the EventManager.voiddoConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Saves the form to the configuration and disk.Checks that the provided parameter is an integer, not negative, that is larger than the minimum value.doIntegerCheck(String value) Checks that the provided parameter is an integer.doNameFreeCheck(String value) Checks whether server name already exists.doPositiveIntegerCheck(String value) Checks that the provided parameter is an integer and not negative.voiddoRemoveConfirm(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Saves the form to the configuration and disk.net.sf.json.JSONObjectdoSleep()Server to sleep.doUrlCheck(String value) Checks if the value is a valid URL.doValidKeyFileCheck(String value) Checks to see if the provided value is a file path to a valid private key file.doValidTimeCheck(String from, String to) Checks to see if the provided value represents a time on the hh:mm format.net.sf.json.JSONObjectdoWakeup()Wakeup server.Generates a list of helper objects for the jelly view.Gets the global config of this server.Convenience method for remove.jelly.Get the response after a start/stop/restartConnection; Used by jelly.Returns the list of disabled features.Get frontend url of the server.Get the GerritConnectionListener for GerritAdministrativeMonitor.Returns a list of Gerrit projects.Returns the current Gerrit version.Get hostname of the server.Get HTTP username of the server.Returns the Missed Events playback manager.getName()Get the name of the server.Convenience method for jelly to get url of the server list's page relative to root.Returns the GerritProjectListUpdater of this server so that it can be configured.com.sonymobile.tools.gerrit.gerritevents.GerritQueryHandlerGets the global query handler of this server.final PermissionJenkins.ADMINISTERpermission for viewing and changing the configuration.intGet ssh port of the server.getUrl()Convenience method for jelly to get url of this server's config page relative to root.Get the url encoded name of the server.Get username of the server.booleanIf server with features disabled due to old Gerrit version.booleanThis server has errors or not.booleanThis server has warnings or not.static booleanisAnyServer(String serverName) If the parameter representsANY_SERVER.booleanA quick check if a connection to Gerrit is open.booleanIf connection could not be established.booleanIf Gerrit Missed Events Playback is supported.booleanIf Gerrit is a snapshot version.booleanCheck whether this server is the last one.booleanIf no connection on startup or not.booleanChecks whether the current server support project-created events or not.booleanDeprecated.booleanReturn if the current server support replication events.booleanGets wakeup is failed by timeout or not.Returns localized texts for each known notification value.voidremoveListener(com.sonymobile.tools.gerrit.gerritevents.ConnectionListener listener) Removes a connection listener from the manager.voidremoveListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener listener) Removes a listener from the manager.voidRestarts the connection to Gerrit stream of events.voidsetConfig(IGerritHudsonTriggerConfig config) Sets the global config of this server.voidSet the server name.voidsetNoConnectionOnStartup(boolean noConnectionOnStartup) Sets connect on startup.voidsetPseudoMode(boolean pseudoMode) Deprecated.voidstart()Starts the server's project list updater, send command queue and event manager.voidStarts the connection to Gerrit stream of events.voidstop()Stops the server's project list updater, send command queue and event manager.voidStops the connection to Gerrit stream of events.voidtriggerEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent event) Adds the given event to the stream of events.
-
Field Details
-
ANY_SERVER
Key that is used to select to trigger a build on events from any server.- See Also:
-
-
Constructor Details
-
GerritServer
@DataBoundConstructor public GerritServer()Empty constructor. -
GerritServer
Constructor.- Parameters:
name- the name of the server.
-
GerritServer
Constructor.- Parameters:
name- the name of the server.noConnectionOnStartup- if noConnectionOnStartup or not.
-
-
Method Details
-
getDescriptor
- Specified by:
getDescriptorin interfaceDescribable<GerritServer>
-
getMissedEventsPlaybackManager
Returns the Missed Events playback manager.- Returns:
- GerritMissedEventsPlaybackManager
-
getParentUrl
Convenience method for jelly to get url of the server list's page relative to root.- Returns:
- the relative url
- See Also:
-
getUrl
Convenience method for jelly to get url of this server's config page relative to root.- Returns:
- the relative url
- See Also:
-
isAnyServer
If the parameter representsANY_SERVER. I.e. if serverName is null or empty or equal toANY_SERVER.- Parameters:
serverName- the String to test- Returns:
- true if so.
- See Also:
-
GerritTrigger.isAnyServer()
-
getConfig
Gets the global config of this server.- Returns:
- the config.
-
setConfig
Sets the global config of this server.- Parameters:
config- the config.
-
getQueryHandler
public com.sonymobile.tools.gerrit.gerritevents.GerritQueryHandler getQueryHandler()Gets the global query handler of this server.- Returns:
- the query handler.
-
getName
Get the name of the server.- Returns:
- name the name of the server.
-
setName
Set the server name.- Parameters:
name- New name
-
getHostName
Get hostname of the server.- Returns:
- the hostname of the server.
-
getSshPort
@Exported public int getSshPort()Get ssh port of the server.- Returns:
- the ssh port of the server.
-
getUserName
Get username of the server.- Returns:
- the username of the server.
-
getHttpUserName
Get HTTP username of the server.- Returns:
- HTTP username of the server.
-
getFrontEndUrl
Get frontend url of the server.- Returns:
- the frontend url of the server.
-
isPseudoMode
Deprecated.If pseudo mode or not.- Returns:
- true if so.
-
setPseudoMode
Deprecated.Sets pseudo mode.- Parameters:
pseudoMode- true if pseudoMode connection.
-
isNoConnectionOnStartup
@Exported public boolean isNoConnectionOnStartup()If no connection on startup or not.- Returns:
- true if so.
-
setNoConnectionOnStartup
public void setNoConnectionOnStartup(boolean noConnectionOnStartup) Sets connect on startup.- Parameters:
noConnectionOnStartup- true if connect on startup.
-
isTimeoutWakeup
@Exported public boolean isTimeoutWakeup()Gets wakeup is failed by timeout or not.- Returns:
- true if wakeup is failed by timeout.
-
getIconFileName
- Specified by:
getIconFileNamein interfaceAction
-
getDisplayName
- Specified by:
getDisplayNamein interfaceAction- Specified by:
getDisplayNamein interfaceModelObject
-
getUrlName
- Specified by:
getUrlNamein interfaceAction
-
getUrlEncodedName
Get the url encoded name of the server.- Returns:
- the url encoded name.
-
isLastServer
public boolean isLastServer()Check whether this server is the last one. Used by jelly to stop removal if true.- Returns:
- whether it is the last one;
-
getRequiredPermission
Jenkins.ADMINISTERpermission for viewing and changing the configuration. Also used by Jelly- Returns:
- the permission
-
start
public void start()Starts the server's project list updater, send command queue and event manager. -
stop
public void stop()Stops the server's project list updater, send command queue and event manager. -
addListener
public void addListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener listener) Adds a listener to the EventManager. The listener will receive all events from Gerrit.- Parameters:
listener- the listener to add.- See Also:
-
GerritHandler.addListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener)
-
removeListener
public void removeListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener listener) Removes a listener from the manager.- Parameters:
listener- the listener to remove.- See Also:
-
GerritHandler.removeListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener)
-
removeListener
public void removeListener(com.sonymobile.tools.gerrit.gerritevents.ConnectionListener listener) Removes a connection listener from the manager.- Parameters:
listener- the listener to remove.
-
getGerritConnectionListener
Get the GerritConnectionListener for GerritAdministrativeMonitor.- Returns:
- the GerritConnectionListener, or null if it has not yet been initialized.
-
startConnection
public void startConnection()Starts the connection to Gerrit stream of events. During startup it is called byGerritItemListener. -
stopConnection
public void stopConnection()Stops the connection to Gerrit stream of events. -
isConnected
@Exported public boolean isConnected()A quick check if a connection to Gerrit is open.- Returns:
- true if so.
-
restartConnection
public void restartConnection()Restarts the connection to Gerrit stream of events. -
addListener
public void addListener(com.sonymobile.tools.gerrit.gerritevents.ConnectionListener listener) Adds a Connection Listener to the manager. Return the current connection status so that listeners that are added later than a connectionestablished/ connectiondown will get the current connection status.- Parameters:
listener- the listener to be added.
-
getGerritProjects
Returns a list of Gerrit projects.- Returns:
- list of gerrit projects
-
triggerEvent
public void triggerEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent event) Adds the given event to the stream of events. It gets added to the same event queue as any event coming from the stream-events command in Gerrit. Throws IllegalStateException if the event manager is null- Parameters:
event- the event.- See Also:
-
GerritHandler.triggerEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent)
-
getProjectListUpdater
Returns the GerritProjectListUpdater of this server so that it can be configured.- Returns:
- the GerritProjectListUpdater used in this server
-
getGerritVersion
Returns the current Gerrit version.- Returns:
- the current Gerrit version as a String if connected, or null otherwise.
-
isReplicationEventsSupported
public boolean isReplicationEventsSupported()Return if the current server support replication events.- Returns:
- true if replication events are supported, otherwise false
-
isProjectCreatedEventsSupported
public boolean isProjectCreatedEventsSupported()Checks whether the current server support project-created events or not. Note: We need to exclude snapshot versions from this check. Otherwise, snapshot versions that are < Gerrit 2.12 will default to waiting for Project Created events which are only supported in Gerrit >= 2.12.- Returns:
- true if project-created events are supported, otherwise false
-
notificationLevelTextsById
public static Map<com.sonymobile.tools.gerrit.gerritevents.dto.rest.Notify,String> notificationLevelTextsById()Returns localized texts for each known notification value.- Returns:
- a map with level id to level text.
-
doConfigSubmit
public void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws javax.servlet.ServletException, IOException, InterruptedException Saves the form to the configuration and disk.- Parameters:
req- StaplerRequestrsp- StaplerResponse- Throws:
javax.servlet.ServletException- if something unfortunate happens.IOException- if something unfortunate happens.InterruptedException- if something unfortunate happens.
-
getConfiguredJobs
Convenience method for remove.jelly.- Returns:
- the list of jobs configured with this server.
-
doWakeup
public net.sf.json.JSONObject doWakeup()Wakeup server. This method returns after actual connection status is changed or timeout. Used by jelly.- Returns:
- connection status.
-
doSleep
public net.sf.json.JSONObject doSleep()Server to sleep. This method returns actual connection status is changed or timeout. Used by jelly.- Returns:
- connection status.
-
hasErrors
public boolean hasErrors()This server has errors or not.- Returns:
- true if this server has errors.
-
hasWarnings
public boolean hasWarnings()This server has warnings or not.- Returns:
- true if this server has warnings.
-
isConnectionError
@JavaScriptMethod public boolean isConnectionError()If connection could not be established.- Returns:
- true if so. false otherwise.
-
isGerritSnapshotVersion
@JavaScriptMethod public boolean isGerritSnapshotVersion()If Gerrit is a snapshot version.- Returns:
- true if so, false otherwise.
-
isGerritMissedEventsSupported
@JavaScriptMethod public boolean isGerritMissedEventsSupported()If Gerrit Missed Events Playback is supported.- Returns:
- true if so, false otherwise.
-
hasDisabledFeatures
@JavaScriptMethod public boolean hasDisabledFeatures()If server with features disabled due to old Gerrit version.- Returns:
- true if so, false otherwise.
-
getDisabledFeatures
Returns the list of disabled features.- Returns:
- the list of disabled features or empty list if listener not found
-
getConnectionResponse
Get the response after a start/stop/restartConnection; Used by jelly.- Returns:
- the connection response
-
doRemoveConfirm
public void doRemoveConfirm(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws javax.servlet.ServletException, IOException, InterruptedException Saves the form to the configuration and disk.- Parameters:
req- StaplerRequestrsp- StaplerResponse- Throws:
javax.servlet.ServletException- if something unfortunate happens.IOException- if something unfortunate happens.InterruptedException- if something unfortunate happens.
-
doPositiveIntegerCheck
Checks that the provided parameter is an integer and not negative.- Parameters:
value- the value.- Returns:
FormValidation.validatePositiveInteger(String)
-
doDynamicConfigRefreshCheck
Checks that the provided parameter is an integer, not negative, that is larger than the minimum value.- Parameters:
value- the value.- Returns:
FormValidation.validatePositiveInteger(String)
-
doIntegerCheck
Checks that the provided parameter is an integer.- Parameters:
value- the value.- Returns:
FormValidation.validatePositiveInteger(String)
-
doUrlCheck
Checks if the value is a valid URL. It does not check if the URL is reachable.- Parameters:
value- the value- Returns:
FormValidation.ok()if it is so.
-
doValidKeyFileCheck
Checks to see if the provided value is a file path to a valid private key file.- Parameters:
value- the value.- Returns:
FormValidation.ok()if it is so.
-
doValidTimeCheck
Checks to see if the provided value represents a time on the hh:mm format. Also checks that from is before to.- Parameters:
from- the from value.to- the to value.- Returns:
FormValidation.ok()if it is so.
-
doNameFreeCheck
Checks whether server name already exists.- Parameters:
value- the value of the name field.- Returns:
- ok or error.
-
generateHelper
Generates a list of helper objects for the jelly view.- Returns:
- a list of helper objects.
-