com.sonyericsson.hudson.plugins.gerrit.trigger
Class GerritServer

java.lang.Object
  extended by com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer
All Implemented Interfaces:
hudson.model.Action, hudson.model.Describable<GerritServer>, hudson.model.ModelObject

public class GerritServer
extends Object
implements hudson.model.Describable<GerritServer>, hudson.model.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
static class GerritServer.DescriptorImpl
          Descriptor is only used for UI form bindings.
 
Field Summary
static String ANY_SERVER
          Key that is used to select to trigger a build on events from any server.
 
Constructor Summary
GerritServer(String name)
          Constructor.
 
Method Summary
 void addListener(ConnectionListener listener)
          Adds a Connection Listener to the manager.
 void addListener(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.
 void doConnectionSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
           
 hudson.util.FormValidation doDynamicConfigRefreshCheck(String value)
          Checks that the provided parameter is an integer, not negative, that is larger than the minimum value.
 hudson.util.FormValidation doEmptyOrIntegerCheck(String value)
          Checks that the provided parameter is an empty string or an integer.
 hudson.util.FormValidation doIntegerCheck(String value)
          Checks that the provided parameter is an integer.
 hudson.util.FormValidation doNameFreeCheck(String value)
          Checks whether server name already exists.
 hudson.util.FormValidation doNonNegativeIntegerCheck(String value)
          Checks that the provided parameter is an integer and not negative, zero is accepted.
 hudson.util.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.
 hudson.util.FormValidation doUrlCheck(String value)
          Checks if the value is a valid URL.
 hudson.util.FormValidation doValidKeyFileCheck(String value)
          Checks to see if the provided value is a file path to a valid private key file.
 hudson.util.FormValidation doValidTimeCheck(String fromValue, String toValue)
          Checks to see if the provided value represents a time on the hh:mm format.
 List<ExceptionDataHelper> generateHelper()
          Generates a list of helper objects for the jelly view.
 IGerritHudsonTriggerConfig getConfig()
          Gets the global config of this server.
 List<hudson.model.AbstractProject> getConfiguredJobs()
          Convenience method for remove.jelly.
 String getConnectionResponse()
          Get the response after a start/stop/restartConnection; Used by jelly.
 GerritServer.DescriptorImpl getDescriptor()
           
 String getDisplayName()
           
 GerritConnectionListener getGerritConnectionListener()
          Get the GerritConnectionListener for GerritAdministrativeMonitor.
 List<String> getGerritProjects()
          Returns a list of Gerrit projects.
 String getGerritVersion()
          Returns the current Gerrit version.
 String getIconFileName()
           
 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.
 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()
           
 boolean isConnected()
          A quick check if a connection to Gerrit is open.
 boolean isLastServer()
          Check whether this server is the last one.
 void removeListener(ConnectionListener listener)
          Removes a connection listener from the manager.
 void removeListener(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 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(GerritEvent event)
          Adds the given event to the stream of events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

public GerritServer(String name)
Constructor.

Parameters:
name - the name of the server.
Method Detail

getDescriptor

public GerritServer.DescriptorImpl getDescriptor()
Specified by:
getDescriptor in interface hudson.model.Describable<GerritServer>

getParentUrl

public String getParentUrl()
Convenience method for jelly to get url of the server list's page relative to root.

Returns:
the relative url

getUrl

public String getUrl()
Convenience method for jelly to get url of this server's config page relative to root.

Returns:
the relative url

getConfig

public IGerritHudsonTriggerConfig getConfig()
Gets the global config of this server.

Returns:
the config.

setConfig

public void setConfig(IGerritHudsonTriggerConfig config)
Sets the global config of this server.

Parameters:
config - the config.

getName

public String getName()
Get the name of the server.

Returns:
name the name of the server.

getIconFileName

public String getIconFileName()
Specified by:
getIconFileName in interface hudson.model.Action

getDisplayName

public String getDisplayName()
Specified by:
getDisplayName in interface hudson.model.Action
Specified by:
getDisplayName in interface hudson.model.ModelObject

getUrlName

public String getUrlName()
Specified by:
getUrlName in interface hudson.model.Action

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;

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(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.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritEventListener)

removeListener

public void removeListener(GerritEventListener listener)
Removes a listener from the manager.

Parameters:
listener - the listener to remove.
See Also:
GerritHandler.removeListener(com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritEventListener)

removeListener

public void removeListener(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 by GerritItemListener.

See Also:
doConnectionSubmit(StaplerRequest, StaplerResponse)

stopConnection

public void stopConnection()
Stops the connection to Gerrit stream of events.

See Also:
doConnectionSubmit(StaplerRequest, StaplerResponse)

isConnected

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.

See Also:
doConnectionSubmit(StaplerRequest, StaplerResponse)

addListener

public void addListener(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(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.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.GerritEvent)

getGerritVersion

public String getGerritVersion()
Returns the current Gerrit version.

Returns:
the current Gerrit version as a String if connected, or null otherwise.

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 - StaplerRequest
rsp - StaplerResponse
Throws:
javax.servlet.ServletException - if something unfortunate happens.
IOException - if something unfortunate happens.
InterruptedException - if something unfortunate happens.

getConfiguredJobs

public List<hudson.model.AbstractProject> getConfiguredJobs()
Convenience method for remove.jelly.

Returns:
the list of jobs configured with this server.

doConnectionSubmit

public void doConnectionSubmit(org.kohsuke.stapler.StaplerRequest req,
                               org.kohsuke.stapler.StaplerResponse rsp)
                        throws IOException
Parameters:
req - the StaplerRequest
rsp - the StaplerResponse
Throws:
IOException - if unable to send redirect.

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 - StaplerRequest
rsp - StaplerResponse
Throws:
javax.servlet.ServletException - if something unfortunate happens.
IOException - if something unfortunate happens.
InterruptedException - if something unfortunate happens.

doPositiveIntegerCheck

public hudson.util.FormValidation doPositiveIntegerCheck(@QueryParameter(value="value")
                                                         String value)
Checks that the provided parameter is an integer and not negative.

Parameters:
value - the value.
Returns:
FormValidation.validatePositiveInteger(String)

doNonNegativeIntegerCheck

public hudson.util.FormValidation doNonNegativeIntegerCheck(@QueryParameter(value="value")
                                                            String value)
Checks that the provided parameter is an integer and not negative, zero is accepted.

Parameters:
value - the value.
Returns:
FormValidation.validateNonNegativeInteger(String)

doDynamicConfigRefreshCheck

public hudson.util.FormValidation doDynamicConfigRefreshCheck(@QueryParameter(value="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 hudson.util.FormValidation doIntegerCheck(@QueryParameter(value="value")
                                                 String value)
Checks that the provided parameter is an integer.

Parameters:
value - the value.
Returns:
FormValidation.validatePositiveInteger(String)

doEmptyOrIntegerCheck

public hudson.util.FormValidation doEmptyOrIntegerCheck(@QueryParameter(value="value")
                                                        String value)
Checks that the provided parameter is an empty string or an integer.

Parameters:
value - the value.
Returns:
FormValidation.validatePositiveInteger(String)

doUrlCheck

public hudson.util.FormValidation doUrlCheck(@QueryParameter(value="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 hudson.util.FormValidation doValidKeyFileCheck(@QueryParameter(value="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 hudson.util.FormValidation doValidTimeCheck(@QueryParameter
                                                   String fromValue,
                                                   @QueryParameter
                                                   String toValue)
Checks to see if the provided value represents a time on the hh:mm format. Also checks that from is before to.

Parameters:
fromValue - the from value.
toValue - the to value.
Returns:
FormValidation.ok() if it is so.

doNameFreeCheck

public hudson.util.FormValidation doNameFreeCheck(@QueryParameter(value="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.


Copyright © 2004-2013. All Rights Reserved.