Skip to content

Commit

Permalink
add (set|get)Mode and enhance label functionality
Browse files Browse the repository at this point in the history
append label now stable and will not revert back and set|get_mode method were added to library

Signed-off-by: Mahdi Ardekanian <mahdi@ibm.com>
  • Loading branch information
mahdipub committed Oct 17, 2023
1 parent 3e12d3e commit 4ecad1d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/NodeHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,51 @@ class NodeHelper {
return ret;
}

/**
* Overwrites the existing mode with the one passed in.
* modes could be either normal or exclusive
*
* @param computerName the computer whose labels need to be updated
* @param mode the net mode for the computer
*
* @return Done if mode changed and setMode:SLAVE_NOT_FOUND if no node found
*/
public String setMode(String computerName, String mode) {
String ret = "setMode:SLAVE_NOT_FOUND";

def slave = Jenkins.getInstance().getSlave(computerName)
if (slave != null) {
if(mode == 'NORMAL'){
slave.setMode(hudson.model.Node.Mode.NORMAL);
}else{
slave.setMode(hudson.model.Node.Mode.EXCLUSIVE);
}
slave.save()
return 'Done'
}

return ret;
}


/**
* Returns mode of the node.
*
* @param computerName the computer whose labels need to be updated
*
* @return either NORMAL or EXCLUSIVE
*/
public String getMode(String computerName) {
String ret = "setMode:SLAVE_NOT_FOUND";

def slave = Jenkins.getInstance().getSlave(computerName)
if (slave != null) {
return slave.getMode() == hudson.model.Node.Mode.NORMAL ? "NORMAL" : "EXCLUSIVE"
}

return ret;
}

/**
* Overwrites the existing labels with the ones passed
* in. Labels should be seperated by spaces.
Expand All @@ -108,6 +153,7 @@ class NodeHelper {
Computer computer = getComputer(computerName);
if (computer != null) {
computer.getNode().setLabelString(label.toLowerCase());
computer.getNode().save()
ret = getLabels(computer.getName());
}

Expand Down

0 comments on commit 4ecad1d

Please sign in to comment.