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 Classes Modifier and Type Class Description static class
GerritServer.DescriptorImpl
Descriptor is only used for UI form bindings.
-
Field Summary
Fields Modifier and Type Field Description static String
ANY_SERVER
Key that is used to select to trigger a build on events from any server.
-
Constructor Summary
Constructors Constructor Description GerritServer()
Empty constructor.GerritServer(String name)
Constructor.GerritServer(String name, boolean noConnectionOnStartup)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addListener(com.sonymobile.tools.gerrit.gerritevents.ConnectionListener listener)
Adds a Connection Listener to the manager.void
addListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener listener)
Adds a listener to the EventManager.void
doConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Saves the form to the configuration and disk.FormValidation
doDynamicConfigRefreshCheck(String value)
Checks that the provided parameter is an integer, not negative, that is larger than the minimum value.FormValidation
doIntegerCheck(String value)
Checks that the provided parameter is an integer.FormValidation
doNameFreeCheck(String value)
Checks whether server name already exists.FormValidation
doPositiveIntegerCheck(String value)
Checks that the provided parameter is an integer and not negative.void
doRemoveConfirm(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Saves the form to the configuration and disk.net.sf.json.JSONObject
doSleep()
Server to sleep.FormValidation
doUrlCheck(String value)
Checks if the value is a valid URL.FormValidation
doValidKeyFileCheck(String value)
Checks to see if the provided value is a file path to a valid private key file.FormValidation
doValidTimeCheck(String from, String to)
Checks to see if the provided value represents a time on the hh:mm format.net.sf.json.JSONObject
doWakeup()
Wakeup server.List<ExceptionDataHelper>
generateHelper()
Generates a list of helper objects for the jelly view.IGerritHudsonTriggerConfig
getConfig()
Gets the global config of this server.List<Job>
getConfiguredJobs()
Convenience method for remove.jelly.String
getConnectionResponse()
Get the response after a start/stop/restartConnection; Used by jelly.GerritServer.DescriptorImpl
getDescriptor()
List<GerritVersionChecker.Feature>
getDisabledFeatures()
Returns the list of disabled features.String
getDisplayName()
String
getFrontEndUrl()
Get frontend url of the server.GerritConnectionListener
getGerritConnectionListener()
Get the GerritConnectionListener for GerritAdministrativeMonitor.List<String>
getGerritProjects()
Returns a list of Gerrit projects.String
getGerritVersion()
Returns the current Gerrit version.String
getHostName()
Get hostname of the server.String
getHttpUserName()
Get HTTP username of the server.String
getIconFileName()
GerritMissedEventsPlaybackManager
getMissedEventsPlaybackManager()
Returns the Missed Events playback manager.String
getName()
Get the name of the server.String
getParentUrl()
Convenience method for jelly to get url of the server list's page relative to root.GerritProjectListUpdater
getProjectListUpdater()
Returns the GerritProjectListUpdater of this server so that it can be configured.com.sonymobile.tools.gerrit.gerritevents.GerritQueryHandler
getQueryHandler()
Gets the global query handler of this server.Permission
getRequiredPermission()
Jenkins.ADMINISTER
permission for viewing and changing the configuration.int
getSshPort()
Get ssh port of the server.String
getUrl()
Convenience method for jelly to get url of this server's config page relative to root.String
getUrlEncodedName()
Get the url encoded name of the server.String
getUrlName()
String
getUserName()
Get username of the server.boolean
hasDisabledFeatures()
If server with features disabled due to old Gerrit version.boolean
hasErrors()
This server has errors or not.boolean
hasWarnings()
This server has warnings or not.static boolean
isAnyServer(String serverName)
If the parameter representsANY_SERVER
.boolean
isConnected()
A quick check if a connection to Gerrit is open.boolean
isConnectionError()
If connection could not be established.boolean
isGerritMissedEventsSupported()
If Gerrit Missed Events Playback is supported.boolean
isGerritSnapshotVersion()
If Gerrit is a snapshot version.boolean
isLastServer()
Check whether this server is the last one.boolean
isNoConnectionOnStartup()
If no connection on startup or not.boolean
isProjectCreatedEventsSupported()
Checks whether the current server support project-created events or not.boolean
isPseudoMode()
Deprecated.boolean
isReplicationEventsSupported()
Return if the current server support replication events.boolean
isTimeoutWakeup()
Gets wakeup is failed by timeout or not.static Map<com.sonymobile.tools.gerrit.gerritevents.dto.rest.Notify,String>
notificationLevelTextsById()
Returns localized texts for each known notification value.void
removeListener(com.sonymobile.tools.gerrit.gerritevents.ConnectionListener listener)
Removes a connection listener from the manager.void
removeListener(com.sonymobile.tools.gerrit.gerritevents.GerritEventListener listener)
Removes a listener from the manager.void
restartConnection()
Restarts the connection to Gerrit stream of events.void
setConfig(IGerritHudsonTriggerConfig config)
Sets the global config of this server.void
setName(String name)
Set the server name.void
setNoConnectionOnStartup(boolean noConnectionOnStartup)
Sets connect on startup.void
setPseudoMode(boolean pseudoMode)
Deprecated.void
start()
Starts the server's project list updater, send command queue and event manager.void
startConnection()
Starts the connection to Gerrit stream of events.void
stop()
Stops the server's project list updater, send command queue and event manager.void
stopConnection()
Stops the connection to Gerrit stream of events.void
triggerEvent(com.sonymobile.tools.gerrit.gerritevents.dto.GerritEvent event)
Adds the given event to the stream of events.
-
-
-
Field Detail
-
ANY_SERVER
public static final String ANY_SERVER
Key that is used to select to trigger a build on events from any server.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GerritServer
@DataBoundConstructor public GerritServer()
Empty constructor.
-
GerritServer
public GerritServer(String name)
Constructor.- Parameters:
name
- the name of the server.
-
GerritServer
public GerritServer(String name, boolean noConnectionOnStartup)
Constructor.- Parameters:
name
- the name of the server.noConnectionOnStartup
- if noConnectionOnStartup or not.
-
-
Method Detail
-
getDescriptor
public GerritServer.DescriptorImpl getDescriptor()
- Specified by:
getDescriptor
in interfaceDescribable<GerritServer>
-
getMissedEventsPlaybackManager
public GerritMissedEventsPlaybackManager getMissedEventsPlaybackManager()
Returns the Missed Events playback manager.- Returns:
- GerritMissedEventsPlaybackManager
-
getParentUrl
public String getParentUrl()
Convenience method for jelly to get url of the server list's page relative to root.- Returns:
- the relative url
- See Also:
GerritManagement.getUrlName()
-
getUrl
public String getUrl()
Convenience method for jelly to get url of this server's config page relative to root.- Returns:
- the relative url
- See Also:
GerritManagement.getUrlName()
-
isAnyServer
public static boolean isAnyServer(String serverName)
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
public IGerritHudsonTriggerConfig getConfig()
Gets the global config of this server.- Returns:
- the config.
-
setConfig
@DataBoundSetter public void setConfig(IGerritHudsonTriggerConfig config)
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
@Exported public String getName()
Get the name of the server.- Returns:
- name the name of the server.
-
setName
public void setName(String name)
Set the server name.- Parameters:
name
- New name
-
getHostName
@Exported public String 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
@Exported public String getUserName()
Get username of the server.- Returns:
- the username of the server.
-
getHttpUserName
@Exported public String getHttpUserName()
Get HTTP username of the server.- Returns:
- HTTP username of the server.
-
getFrontEndUrl
@Exported public String getFrontEndUrl()
Get frontend url of the server.- Returns:
- the frontend url of the server.
-
isPseudoMode
@Deprecated public boolean isPseudoMode()
Deprecated.If pseudo mode or not.- Returns:
- true if so.
-
setPseudoMode
@Deprecated public void setPseudoMode(boolean pseudoMode)
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
public String getIconFileName()
- Specified by:
getIconFileName
in interfaceAction
-
getDisplayName
public String getDisplayName()
- Specified by:
getDisplayName
in interfaceAction
- Specified by:
getDisplayName
in interfaceModelObject
-
getUrlName
public String getUrlName()
- Specified by:
getUrlName
in interfaceAction
-
getUrlEncodedName
public String 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
public final Permission getRequiredPermission()
Jenkins.ADMINISTER
permission 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
public GerritConnectionListener 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
public List<String> 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
public GerritProjectListUpdater getProjectListUpdater()
Returns the GerritProjectListUpdater of this server so that it can be configured.- Returns:
- the GerritProjectListUpdater used in this server
-
getGerritVersion
public String 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
public List<Job> 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
public List<GerritVersionChecker.Feature> getDisabledFeatures()
Returns the list of disabled features.- Returns:
- the list of disabled features or empty list if listener not found
-
getConnectionResponse
public String 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
public FormValidation doPositiveIntegerCheck(@QueryParameter("value") String value)
Checks that the provided parameter is an integer and not negative.- Parameters:
value
- the value.- Returns:
FormValidation.validatePositiveInteger(String)
-
doDynamicConfigRefreshCheck
public FormValidation doDynamicConfigRefreshCheck(@QueryParameter("value") String value)
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
public FormValidation doIntegerCheck(@QueryParameter("value") String value)
Checks that the provided parameter is an integer.- Parameters:
value
- the value.- Returns:
FormValidation.validatePositiveInteger(String)
-
doUrlCheck
public FormValidation doUrlCheck(@QueryParameter("value") String value)
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
public FormValidation doValidKeyFileCheck(@QueryParameter("value") String value)
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
public FormValidation doValidTimeCheck(@QueryParameter String from, @QueryParameter String to)
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
public FormValidation doNameFreeCheck(@QueryParameter("value") String value)
Checks whether server name already exists.- Parameters:
value
- the value of the name field.- Returns:
- ok or error.
-
generateHelper
public List<ExceptionDataHelper> generateHelper()
Generates a list of helper objects for the jelly view.- Returns:
- a list of helper objects.
-
-