com.sonyericsson.hudson.plugins.multislaveconfigplugin
Class NodeManageLink

java.lang.Object
  extended by hudson.model.ManagementLink
      extended by com.sonyericsson.hudson.plugins.multislaveconfigplugin.NodeManageLink
All Implemented Interfaces:
hudson.ExtensionPoint, hudson.model.Action, hudson.model.Describable<NodeManageLink>, hudson.model.ModelObject

@Extension
public class NodeManageLink
extends hudson.model.ManagementLink
implements hudson.model.Describable<NodeManageLink>

Registers the plugin to be recognized by Jenkins as a management link and controls the main attributes of the plugin.

Author:
Nicklas Nilsson <nicklas3.nilsson@sonyericsson.com>, Fredrik Persson <fredrik4.persson@sonyericsson.com>

Nested Class Summary
static class NodeManageLink.DescriptorImpl
          Descriptor is only used for auto completion.
static class NodeManageLink.RemovePropertyDescriptor
          Descriptor to show in the removal list for node properties.
static class NodeManageLink.UserMode
          Different user modes, depending on which wizard the user is running.
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
protected static String ICON
          Icon used by this plugin.
protected static String URL
          URL to the plugin.
protected  HashMap<String,NodeManageLink.UserMode> userMode
          Hashmap with user and what userMode that currently is active.
 
Fields inherited from class hudson.model.ManagementLink
LIST
 
Constructor Summary
NodeManageLink()
           
 
Method Summary
 boolean connectSlaves(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Connects (not forced) to selected slaves.
 boolean disconnectSlaves(String reason, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Disconnects from selected slaves.
 void doAddRedirect(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Redirects to the add slaves-wizard, also setting usermode to add.
 void doApply(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Applies the settings on the current slaves.
 void doConfigureRedirect(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Redirects to the configure-wizard, also setting usermode to configure.
 void doCreateSlaves(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String slaveNames, String slaveName, String mode, String first, String last, String copyFrom, boolean extendedEnvInterpretation)
          Adds the slaves to create to the current NodeList.
 void doDeleteRedirect(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Redirects to the delete-wizard, also setting usermode to delete.
 void doDeleteSlaves(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Deletes the slaves in this list.
 void doHomeRedirect(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Redirects to home.
 void doManageRedirect(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Redirects to Slaves management, also setting usermode to MANAGE.
 net.sf.json.JSONArray doSearch(String sessionId, net.sf.json.JSONObject searchParameters)
          Searches for slaves.
 void doSelectSlaves(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Adds all slaves that are checked on the slavefilter page to a NodeList.
 String generateStars(int length)
          Generates a string of given length filled with stars characters.
 List<hudson.model.Node> getAllNodes()
          Gets all Jenkins registered nodes.
 String getDescription()
          Gets the description of this plugin.
 hudson.model.Descriptor<NodeManageLink> getDescriptor()
          Gets the descriptor.
 String getDisplayName()
          Gets the name of this plugin.
 String getIconFileName()
          Gets the icon for this plugin.
static NodeManageLink getInstance()
          Returns the instance of NodeManageLink.
 HashMap getLastChangedSettings(String sessionId)
          Used for letting the jelly scripts find out what changes have been applied.
 NodeList getNodeList(String sessionId)
          Gets the active nodelist of a specific sessionid.
 List<hudson.slaves.NodePropertyDescriptor> getNodePropertyDescriptors()
          This is needed by settingsselector.jelly to list the Node properties the user can add or change.
 List<NodeManageLink.RemovePropertyDescriptor> getRemovePropertyDescriptor()
          This is needed by settingsselector.jelly to list the Node properties the user can remove.
 hudson.security.Permission getRequiredPermission()
          Returns required permission to use this plugin.
static HashSet<String> getSlaveNames(String slaveNames, String nodeName, String first, String last)
          Calculates all new node names and returns them as a set.
 String getUrlName()
          The URL of this plugin.
 boolean hadLabels(String sessionId)
          Checks if the used nodelist (by searching for session id) contained the labels to remove before removing them.
 boolean isAddMode()
          Checks if current used mode was UserMode Add.
 boolean isCommandLauncher(hudson.slaves.ComputerLauncher candidate)
          Checks if argument is instance of CommandLauncher.
 boolean isConfigureMode()
          Checks if current used mode was UserMode Configure.
 boolean isDeleteMode()
          Checks if current used mode was UserMode Delete.
 boolean isJNLPLauncher(hudson.slaves.ComputerLauncher candidate)
          Checks if argument is instance of JNLPLauncher.
static boolean isLenientShutdownPluginInstalled()
          Checks if Lenient Shutdown Plugin is installed.
 boolean isManagedWindowsServiceLauncher(hudson.slaves.ComputerLauncher candidate)
          Checks if argument is instance of ManagedWindowsServiceLauncher.
 boolean isManageMode()
          Checks if current used mode was UserMode Manage.
 boolean isRetentionStrategyAlways(hudson.slaves.RetentionStrategy candidate)
          Checks if argument is instance of RetentionStrategy.Always.
 boolean isRetentionStrategyDemand(hudson.slaves.RetentionStrategy candidate)
          Checks if argument is instance of RetentionStrategy.Demand.
 boolean isSimpleScheduledRetentionStrategy(hudson.slaves.RetentionStrategy candidate)
          Checks if argument is instance of SimpleScheduledRetentionStrategy.
 String mapClassToDescriptorName(String className)
          Maps a class name to a real descriptor name.
 boolean takeOffline(String reason, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Requests the selected slaves to go offline.
 boolean takeOfflineLeniently(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Requests the selected slaves to go offline leniently.
 boolean takeOnline(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Requests the selected slaves to go online.
 
Methods inherited from class hudson.model.ManagementLink
all, getRequiresConfirmation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL

protected static final String URL
URL to the plugin.

See Also:
Constant Field Values

ICON

protected static final String ICON
Icon used by this plugin.

See Also:
Constant Field Values

userMode

protected HashMap<String,NodeManageLink.UserMode> userMode
Hashmap with user and what userMode that currently is active.

Constructor Detail

NodeManageLink

public NodeManageLink()
Method Detail

getDescriptor

public hudson.model.Descriptor<NodeManageLink> getDescriptor()
Gets the descriptor.

Specified by:
getDescriptor in interface hudson.model.Describable<NodeManageLink>
Returns:
descriptor.

getIconFileName

public String getIconFileName()
Gets the icon for this plugin.

Specified by:
getIconFileName in interface hudson.model.Action
Specified by:
getIconFileName in class hudson.model.ManagementLink
Returns:
icon url

getUrlName

public String getUrlName()
The URL of this plugin.

Specified by:
getUrlName in interface hudson.model.Action
Specified by:
getUrlName in class hudson.model.ManagementLink
Returns:
url

getDisplayName

public String getDisplayName()
Gets the name of this plugin.

Specified by:
getDisplayName in interface hudson.model.Action
Specified by:
getDisplayName in interface hudson.model.ModelObject
Returns:
plugin name

getDescription

public String getDescription()
Gets the description of this plugin.

Overrides:
getDescription in class hudson.model.ManagementLink
Returns:
description

getRequiredPermission

public hudson.security.Permission getRequiredPermission()
Returns required permission to use this plugin.

Overrides:
getRequiredPermission in class hudson.model.ManagementLink
Returns:
Hudson administer permission.

getInstance

public static NodeManageLink getInstance()
Returns the instance of NodeManageLink.

Returns:
instance the NodeManageLink.

getNodeList

public NodeList getNodeList(String sessionId)
Gets the active nodelist of a specific sessionid. Mostly used within the jelly pages.

Parameters:
sessionId - the session id to get the list from
Returns:
the active nodelist

getLastChangedSettings

public HashMap getLastChangedSettings(String sessionId)
Used for letting the jelly scripts find out what changes have been applied.

Parameters:
sessionId - which session id to get the settings from
Returns:
the last changed settings

isManagedWindowsServiceLauncher

public boolean isManagedWindowsServiceLauncher(hudson.slaves.ComputerLauncher candidate)
Checks if argument is instance of ManagedWindowsServiceLauncher.

Parameters:
candidate - RetentionStrategy to check
Returns:
if it was an instance of ManagedWindowsServiceLauncher

isCommandLauncher

public boolean isCommandLauncher(hudson.slaves.ComputerLauncher candidate)
Checks if argument is instance of CommandLauncher.

Parameters:
candidate - RetentionStrategy to check
Returns:
if it was an instance of CommandLauncher

isJNLPLauncher

public boolean isJNLPLauncher(hudson.slaves.ComputerLauncher candidate)
Checks if argument is instance of JNLPLauncher.

Parameters:
candidate - RetentionStrategy to check
Returns:
if it was an instance of JNLPLauncher

isRetentionStrategyAlways

public boolean isRetentionStrategyAlways(hudson.slaves.RetentionStrategy candidate)
Checks if argument is instance of RetentionStrategy.Always.

Parameters:
candidate - RetentionStrategy to check
Returns:
if it was an instance of RetentionStrategy.Always

isRetentionStrategyDemand

public boolean isRetentionStrategyDemand(hudson.slaves.RetentionStrategy candidate)
Checks if argument is instance of RetentionStrategy.Demand.

Parameters:
candidate - RetentionStrategy to check
Returns:
if it was an instance of RetentionStrategy.Demand

isSimpleScheduledRetentionStrategy

public boolean isSimpleScheduledRetentionStrategy(hudson.slaves.RetentionStrategy candidate)
Checks if argument is instance of SimpleScheduledRetentionStrategy.

Parameters:
candidate - RetentionStrategy to check
Returns:
if it was an instance of SimpleScheduledRetentionStrategy

isConfigureMode

public boolean isConfigureMode()
Checks if current used mode was UserMode Configure.

Returns:
true/false if last used mode was UserMode Configure

isDeleteMode

public boolean isDeleteMode()
Checks if current used mode was UserMode Delete.

Returns:
true/false if last used mode was UserMode Delete

isAddMode

public boolean isAddMode()
Checks if current used mode was UserMode Add.

Returns:
true/false if last used mode was UserMode Add.

isManageMode

public boolean isManageMode()
Checks if current used mode was UserMode Manage.

Returns:
true/false if last used mode was UserMode Manage.

getAllNodes

public List<hudson.model.Node> getAllNodes()
Gets all Jenkins registered nodes. Used for the jelly scripts

Returns:
a list with all nodes

generateStars

public String generateStars(int length)
Generates a string of given length filled with stars characters.

Parameters:
length - how many stars it should contain
Returns:
the generated string

doConfigureRedirect

public void doConfigureRedirect(org.kohsuke.stapler.StaplerRequest req,
                                org.kohsuke.stapler.StaplerResponse rsp)
                         throws IOException
Redirects to the configure-wizard, also setting usermode to configure.

Parameters:
req - StaplerRequest
rsp - StaplerResponse to redirect with
Throws:
IOException - if redirection goes wrong

doAddRedirect

public void doAddRedirect(org.kohsuke.stapler.StaplerRequest req,
                          org.kohsuke.stapler.StaplerResponse rsp)
                   throws IOException
Redirects to the add slaves-wizard, also setting usermode to add.

Parameters:
req - StaplerRequest
rsp - StaplerResponse to redirect with
Throws:
IOException - if redirection goes wrong

doManageRedirect

public void doManageRedirect(org.kohsuke.stapler.StaplerRequest req,
                             org.kohsuke.stapler.StaplerResponse rsp)
                      throws IOException
Redirects to Slaves management, also setting usermode to MANAGE.

Parameters:
req - StaplerRequest
rsp - StaplerResponse to redirect with
Throws:
IOException - if redirection goes wrong

doDeleteRedirect

public void doDeleteRedirect(org.kohsuke.stapler.StaplerRequest req,
                             org.kohsuke.stapler.StaplerResponse rsp)
                      throws IOException
Redirects to the delete-wizard, also setting usermode to delete.

Parameters:
req - StaplerRequest
rsp - StaplerResponse to redirect with
Throws:
IOException - if redirection goes wrong

doHomeRedirect

public void doHomeRedirect(org.kohsuke.stapler.StaplerRequest req,
                           org.kohsuke.stapler.StaplerResponse rsp)
                    throws IOException
Redirects to home.

Parameters:
req - StaplerRequest
rsp - StaplerResponse to redirect with
Throws:
IOException - if redirection goes wrong

doSearch

@JavaScriptMethod
public net.sf.json.JSONArray doSearch(String sessionId,
                                                       net.sf.json.JSONObject searchParameters)
Searches for slaves. Also saves the results as a nodelist bound to the sessionid.

Parameters:
sessionId - the current session ID to to place the nodeList with.
searchParameters - JSONObject with information on what to search for.
Returns:
JSONArray with matching slave-representations from the search.

doSelectSlaves

public void doSelectSlaves(org.kohsuke.stapler.StaplerRequest req,
                           org.kohsuke.stapler.StaplerResponse rsp)
                    throws IOException
Adds all slaves that are checked on the slavefilter page to a NodeList.

Parameters:
rsp - StaplerRequest
req - StaplerRequest
Throws:
IOException - if redirection goes wrong
hudson.model.Failure

doApply

public void doApply(org.kohsuke.stapler.StaplerRequest req,
                    org.kohsuke.stapler.StaplerResponse rsp)
             throws IOException,
                    javax.servlet.ServletException
Applies the settings on the current slaves.

Parameters:
rsp - StaplerRequest.
req - StaplerRequest.
Throws:
IOException - if redirection goes wrong.
javax.servlet.ServletException - if something is wrong with the submitted form.

hadLabels

public boolean hadLabels(String sessionId)
Checks if the used nodelist (by searching for session id) contained the labels to remove before removing them. Used for the confirmation page

Parameters:
sessionId - the session id to get the state from
Returns:
true/false

doDeleteSlaves

public void doDeleteSlaves(org.kohsuke.stapler.StaplerRequest req,
                           org.kohsuke.stapler.StaplerResponse rsp)
                    throws IOException
Deletes the slaves in this list.

Parameters:
req - StaplerRequest
rsp - StaplerResponse
Throws:
IOException - if redirection goes wrong

doCreateSlaves

public void doCreateSlaves(org.kohsuke.stapler.StaplerRequest req,
                           org.kohsuke.stapler.StaplerResponse rsp,
                           @QueryParameter
                           String slaveNames,
                           @QueryParameter
                           String slaveName,
                           @QueryParameter
                           String mode,
                           @QueryParameter
                           String first,
                           @QueryParameter
                           String last,
                           @QueryParameter
                           String copyFrom,
                           @QueryParameter
                           boolean extendedEnvInterpretation)
                    throws IOException,
                           hudson.model.Descriptor.FormException
Adds the slaves to create to the current NodeList.

Parameters:
rsp - StaplerResponse.
req - StaplerRequest.
slaveNames - string with several names separated by space.
slaveName - string with a single name, used when automatically creating a span of slaves.
mode - different kinds of create nodes.
first - the first number of the span.
last - the last number of the span.
copyFrom - a string containing the name of the node to copy.
extendedEnvInterpretation - if extended environment variable interpretation should be used.
Throws:
IOException - if slave creation goes wrong.
Descriptor.FormException - if slave creation goes wrong.
hudson.model.Failure

getSlaveNames

public static HashSet<String> getSlaveNames(String slaveNames,
                                            String nodeName,
                                            String first,
                                            String last)
Calculates all new node names and returns them as a set.

Parameters:
slaveNames - specific node names that is separated with space.
nodeName - contains a node name in a specific interval.
first - the first node in a interval
last - the last node in a interval
Returns:
the names separated in an array
Throws:
hudson.model.Failure

takeOnline

@JavaScriptMethod
public boolean takeOnline(org.kohsuke.stapler.StaplerRequest req,
                                           org.kohsuke.stapler.StaplerResponse rsp)
Requests the selected slaves to go online.

Parameters:
rsp - StaplerResponse.
req - StaplerRequest.
Returns:
false if no nodes were selected, otherwise true

takeOffline

@JavaScriptMethod
public boolean takeOffline(String reason,
                                            org.kohsuke.stapler.StaplerRequest req,
                                            org.kohsuke.stapler.StaplerResponse rsp)
Requests the selected slaves to go offline.

Parameters:
reason - String.
rsp - StaplerResponse.
req - StaplerRequest.
Returns:
false if no nodes were selected, otherwise true

takeOfflineLeniently

@JavaScriptMethod
public boolean takeOfflineLeniently(org.kohsuke.stapler.StaplerRequest req,
                                                     org.kohsuke.stapler.StaplerResponse rsp)
Requests the selected slaves to go offline leniently. Only possible if Lenient Shutdown Plugin is installed.

Parameters:
rsp - StaplerResponse.
req - StaplerRequest.
Returns:
false if no nodes were selected or something else goes wrong, otherwise true

connectSlaves

@JavaScriptMethod
public boolean connectSlaves(org.kohsuke.stapler.StaplerRequest req,
                                              org.kohsuke.stapler.StaplerResponse rsp)
Connects (not forced) to selected slaves.

Parameters:
rsp - StaplerResponse.
req - StaplerRequest.
Returns:
false if no nodes were selected, otherwise true

isLenientShutdownPluginInstalled

public static boolean isLenientShutdownPluginInstalled()
Checks if Lenient Shutdown Plugin is installed.

Returns:
true if the plugin is installed, otherwise false

disconnectSlaves

@JavaScriptMethod
public boolean disconnectSlaves(String reason,
                                                 org.kohsuke.stapler.StaplerRequest req,
                                                 org.kohsuke.stapler.StaplerResponse rsp)
Disconnects from selected slaves.

Parameters:
reason - the reason for disconnecting
rsp - StaplerResponse.
req - StaplerRequest.
Returns:
false if no nodes were selected, otherwise true

getNodePropertyDescriptors

public List<hudson.slaves.NodePropertyDescriptor> getNodePropertyDescriptors()
This is needed by settingsselector.jelly to list the Node properties the user can add or change.

Returns:
the NodePropertyDescriptor for DumbSlave

getRemovePropertyDescriptor

public List<NodeManageLink.RemovePropertyDescriptor> getRemovePropertyDescriptor()
This is needed by settingsselector.jelly to list the Node properties the user can remove.

Returns:
the NodePropertyDescriptor for DumbSlave

mapClassToDescriptorName

public String mapClassToDescriptorName(String className)
Maps a class name to a real descriptor name. This is to have something readable to show the user when properties are removed.

Parameters:
className - the class name to match with a descriptor name.
Returns:
the readable name match


Copyright © 2004-2014. All Rights Reserved.