Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add (set|get)Mode and enhance label functionality #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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