com.sonyericsson.hudson.plugins.multislaveconfigplugin
Class NodeList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<hudson.model.Node>
              extended by com.sonyericsson.hudson.plugins.multislaveconfigplugin.NodeList
All Implemented Interfaces:
Serializable, Cloneable, Iterable<hudson.model.Node>, Collection<hudson.model.Node>, List<hudson.model.Node>, RandomAccess

public class NodeList
extends ArrayList<hudson.model.Node>

Manages a list of nodes.

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

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
NodeList()
          Redirecting to the super class constructor.
NodeList(List<hudson.model.Node> list)
          Constructor to help adding existing nodes to a new list.
 
Method Summary
protected  String addLabels(String labelsToAdd, String oldLabels)
          Adds one or more labels to an existing String.
protected  NodeList changeSettings(Map settings)
          Changes the settings for all nodes in the list.
protected  String getCommon(Setting type)
          Gets the common setting of given type for all slaves in this list.
 String getCommon(String type)
          Method for getting common settings of slaves by using a String as type.
protected  List<hudson.model.Node> getComplementaryNodes()
          Returns the Jenkins registered nodes that are not in the given list.
protected  hudson.slaves.DumbSlave getFirstSlave()
          Gets the first Slave in this list.
 hudson.slaves.ComputerLauncher getLauncher()
          Gets the common ComputerLauncher for all slaves in this list.
 String getLauncherDescription()
          Returns a description to be used by the jelly scripts if the launcher settings differs.
 hudson.model.Node.Mode getMode()
          Gets the common mode setting for all slaves in this list.
 List<hudson.slaves.NodeProperty> getNodeProperties()
          Gets a list of NodePropertys that are common for all slaves in this list.
 String getRetentionDescription()
          Returns a description to be used by the jelly scripts if the retention strategy settings differs.
 hudson.slaves.RetentionStrategy getRetentionStrategy()
          Gets the common RetentionStrategy for all nodes in this list.
protected  boolean hasLabels(String labels)
          Checks all the labels in the parameter to make sure each of them exist on at least one slave in this list.
protected static HashMap interpretJSON(net.sf.json.JSONObject json)
          Converts submitted form (JSON) to a HashMap containing only the settings to change.
 boolean isEmpty()
          Checks if there are any DumbSlaves in the list instead of any Node.
protected  String removeLabels(String labelsToRemove, String oldLabels)
          Removes one or more labels from an existing String.
protected  boolean slavesStillExist()
          Checks if the slaves in this list still exist in the master nodelist.
 NodeList sortByName()
          Sorts this list by name.
 net.sf.json.JSONArray toJSONArray()
          Represents this list as a JSONArray.
 String toString()
          Represents this list as a String using the node names separated with space.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

NodeList

public NodeList(List<hudson.model.Node> list)
Constructor to help adding existing nodes to a new list.

Parameters:
list - the nodes to be added

NodeList

public NodeList()
Redirecting to the super class constructor.

Method Detail

isEmpty

public boolean isEmpty()
Checks if there are any DumbSlaves in the list instead of any Node.

Specified by:
isEmpty in interface Collection<hudson.model.Node>
Specified by:
isEmpty in interface List<hudson.model.Node>
Overrides:
isEmpty in class ArrayList<hudson.model.Node>
Returns:
if are any slaves in the list

sortByName

public NodeList sortByName()
Sorts this list by name.

Returns:
sorted list.

toString

public String toString()
Represents this list as a String using the node names separated with space.

Overrides:
toString in class AbstractCollection<hudson.model.Node>
Returns:
list as String

toJSONArray

public net.sf.json.JSONArray toJSONArray()
Represents this list as a JSONArray.

Returns:
JSONArray with matching slave-representations from this NodeList.

getFirstSlave

protected hudson.slaves.DumbSlave getFirstSlave()
Gets the first Slave in this list.

Returns:
the first Slave in the list if there is any

slavesStillExist

protected boolean slavesStillExist()
Checks if the slaves in this list still exist in the master nodelist.

Returns:
if all the slaves still exist or not

changeSettings

protected NodeList changeSettings(Map settings)
Changes the settings for all nodes in the list.

Parameters:
settings - the settings to make as a hashmap
Returns:
The changed list

addLabels

protected String addLabels(String labelsToAdd,
                           String oldLabels)
Adds one or more labels to an existing String. Makes sure each label appears only once.

Parameters:
labelsToAdd - the labels to be added
oldLabels - the already existing label string
Returns:
the new label string

removeLabels

protected String removeLabels(String labelsToRemove,
                              String oldLabels)
Removes one or more labels from an existing String.

Parameters:
labelsToRemove - the labels to be removed
oldLabels - the already existing label string
Returns:
the new label string

getComplementaryNodes

protected List<hudson.model.Node> getComplementaryNodes()
Returns the Jenkins registered nodes that are not in the given list.

Returns:
the complementary list

hasLabels

protected boolean hasLabels(String labels)
Checks all the labels in the parameter to make sure each of them exist on at least one slave in this list.

Parameters:
labels - the labels to check.
Returns:
true/false if they existed.

interpretJSON

protected static HashMap interpretJSON(net.sf.json.JSONObject json)
Converts submitted form (JSON) to a HashMap containing only the settings to change. Using Strings and not enum Setting as keys since the jelly scripts don't seem to get enum keys correctly.

Parameters:
json - to interpret
Returns:
the hash map

getCommon

public String getCommon(String type)
Method for getting common settings of slaves by using a String as type. Needed since jelly doesn't seem to work with enum.

Parameters:
type - the setting type as a String
Returns:
the common setting string if there was one

getCommon

protected String getCommon(Setting type)
Gets the common setting of given type for all slaves in this list. Returns null if no common setting is available.

Parameters:
type - the setting type to get
Returns:
the common setting string if there was any

getMode

public hudson.model.Node.Mode getMode()
Gets the common mode setting for all slaves in this list. Returns null if no common mode setting is available.

Returns:
the common mode if there is any

getLauncher

public hudson.slaves.ComputerLauncher getLauncher()
Gets the common ComputerLauncher for all slaves in this list. Returns null if no common launcher is available. If the launcher types are the same, it will also compare the specific settings, for example the launch command if all were CommandLaunchers. If all were CommandLaunchers with different launch commands, the returned launcher will have an empty launch command. However, if they had the same launch command, it will return a launcher with that common command.

Returns:
the common ComputerLauncher

getRetentionStrategy

public hudson.slaves.RetentionStrategy getRetentionStrategy()
Gets the common RetentionStrategy for all nodes in this list. Returns null if no common strategy is available. If the strategy types are the same, it will also compare the specific settings, for example the startup schedule if all were SimpleScheduledRetentionStrategies. If all were SimpleScheduledRetentionStrategies with different startup schedule settings, the returned RetentionStrategy will have an empty startup schedule. However, if they had the same startup schedule, it will return a launcher with that startup schedule.

Returns:
the common RetentionStrategy

getLauncherDescription

public String getLauncherDescription()
Returns a description to be used by the jelly scripts if the launcher settings differs.

Returns:
generated description

getRetentionDescription

public String getRetentionDescription()
Returns a description to be used by the jelly scripts if the retention strategy settings differs.

Returns:
the description

getNodeProperties

public List<hudson.slaves.NodeProperty> getNodeProperties()
Gets a list of NodePropertys that are common for all slaves in this list. NodeProperties that are not equal are left out.

Returns:
list of NodePropertys


Copyright © 2004-2014. All Rights Reserved.