com.datalex.jenkins.plugins.nodestalker.wrapper
Class MyNodeAssignmentAction

java.lang.Object
  extended by com.datalex.jenkins.plugins.nodestalker.wrapper.MyNodeAssignmentAction
All Implemented Interfaces:
hudson.model.Action, hudson.model.labels.LabelAssignmentAction, hudson.model.ModelObject

public class MyNodeAssignmentAction
extends Object
implements hudson.model.labels.LabelAssignmentAction

This is the main class of the plugin. This class checks whether the plugin is enabled, then takes in the node and workspace locations of the last build of the parent job (the job specified by the user). It then restricts the current job to run on that node and (if Share Workspace is enabled) workspace.

Version:
1.0
Author:
Fabio Neves , Baris Batiege

Field Summary
static String DISPLAY_NAME
           
protected static Logger logger
           
 
Constructor Summary
MyNodeAssignmentAction()
           
 
Method Summary
 hudson.model.Label getAssignedLabel(hudson.model.queue.SubTask task)
          This method checks if the plugin is enabled then finds the node of the parent job.
 String getDisplayName()
           
 String getIconFileName()
           
protected  String getNodeJobLastRan(hudson.model.AbstractProject project, hudson.model.Label defaultLabel)
          This method sets node if it is an empty string, if node is currently null, it sets node to master.
protected  NodeStalkerBuildWrapper getNodeStalkerBuildWrapper(hudson.model.BuildableItemWithBuildWrappers project)
          This method checks current jobs configuration to see if NodeStalkerPlugin is enabled.
 String getUrlName()
           
protected  void updateWorkspace(hudson.model.AbstractProject followedProject, hudson.model.AbstractProject project)
          Overriding the Custom Workspace field of our job to follow the workspace of the parent job
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Logger logger

DISPLAY_NAME

public static final String DISPLAY_NAME
See Also:
Constant Field Values
Constructor Detail

MyNodeAssignmentAction

public MyNodeAssignmentAction()
Method Detail

getAssignedLabel

public hudson.model.Label getAssignedLabel(hudson.model.queue.SubTask task)
This method checks if the plugin is enabled then finds the node of the parent job. If the plugin is not enabled, the default label set by Jenkins is used. The method also checks whether Share Workspace option of the plugin is enabled.

Specified by:
getAssignedLabel in interface hudson.model.labels.LabelAssignmentAction
Parameters:
task - The current build of our job
Returns:
The node that the last build of the parent job was built on.

updateWorkspace

protected void updateWorkspace(hudson.model.AbstractProject followedProject,
                               hudson.model.AbstractProject project)
Overriding the Custom Workspace field of our job to follow the workspace of the parent job

Parameters:
followedProject - the project specified in the UI
project - The project that is currently building

getNodeStalkerBuildWrapper

protected NodeStalkerBuildWrapper getNodeStalkerBuildWrapper(hudson.model.BuildableItemWithBuildWrappers project)
This method checks current jobs configuration to see if NodeStalkerPlugin is enabled. It does this by checking if NodeStalkerPlugin exists in the jobs buildWrappersList, as NodeStalkerPlugin is a plugin of the buildWrappers category.

Parameters:
project - the job that is currently running
Returns:
  • Returns null if the projects BuildWrapperList does not exist
  • Returns NodeStalkerBuildWrapper if the projects BuildWrapperList is found and contains NodeStalkerPlugin

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

getNodeJobLastRan

protected String getNodeJobLastRan(hudson.model.AbstractProject project,
                                   hudson.model.Label defaultLabel)
This method sets node if it is an empty string, if node is currently null, it sets node to master.

Parameters:
project - job that we want to follow
defaultLabel - label that Jenkins would assign without Node Stalker plugin
Returns:
  • Normally returns the node that the followed job most recently ran on
  • returns DisplayName of defaultLabel if job can't be found, but defaultLabel exists
  • returns 'master' if job can't be found and defaultLabel is null
  • If 'node' is empty, returns master
  • If 'node' is null, returns null


Copyright © 2004-2014. All Rights Reserved.