Skip to content

Commit

Permalink
Extracted label strings to Constants file
Browse files Browse the repository at this point in the history
- Modified the API to use label strings from Constants.groovy
- Added setDescription function

issue #2

Signed-off-by: Shubham Verma <shubhamv.sv@gmail.com>
  • Loading branch information
VermaSh committed Apr 11, 2018
1 parent 9ac4cf3 commit ac19260
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 10 deletions.
89 changes: 80 additions & 9 deletions src/NodeHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,16 @@ class NodeHelper {
def osInfo = getOsInfo(computer.getName());
String osVersion = osInfo.get(1);

ret = "sw.os." + osInfo.get(0) + osVersion;
ret += " sw.os." + osInfo.get(0);
ret = String.format(
Constants.OS_LABEL_FORMAT,
Constants.OS_LABEL_PREFIX,
osInfo.get(0),osVersion);
ret += ' ';
ret += String.format(
Constants.GENERIC_LABEL_FORMAT,
Constants.OS_LABEL_PREFIX,
osInfo.get(0));

}

return ret.toLowerCase();
Expand All @@ -246,7 +254,10 @@ class NodeHelper {

Computer computer = getComputer(computerName);
if (computer != null) {
ret = "hw.endian." + getEndian(computer.getName());
ret = String.format(
Constants.GENERIC_LABEL_FORMAT,
Constants.ENDIAN_LABEL_PREFIX,
getEndian(computer.getName()));
}

return ret.toLowerCase();
Expand All @@ -273,7 +284,10 @@ class NodeHelper {
break;
}

ret = "hw.platform." + ret;
ret = String.format(
Constants.GENERIC_LABEL_FORMAT,
Constants.PLATFORM_LABEL_PREFIX,
ret);
}

return ret.toLowerCase();
Expand Down Expand Up @@ -328,7 +342,10 @@ class NodeHelper {
ret = "INVALID_ARCH";
break;
}
ret = "hw.arch." + ret;
ret = String.format(
Constants.GENERIC_LABEL_FORMAT,
Constants.ARCH_LABEL_PREFIX,
ret);
}


Expand All @@ -341,7 +358,10 @@ class NodeHelper {
Computer computer = getComputer(computerName);
if (computer != null) {
def kernelInfo = getOsKernelInfo(computer.getName());
ret = "sw.os." + kernelInfo.get(0);
ret = String.format(
Constants.GENERIC_LABEL_FORMAT,
Constants.OS_LABEL_PREFIX,
kernelInfo.get(0));
}

return ret;
Expand All @@ -352,7 +372,11 @@ class NodeHelper {

Computer computer = getComputer(computerName);
if (computer != null) {
ret = "hw.hypervisor.";// TODO: finish implementation, get something
// TODO: finish implementation, get something
// ret = String.format(
// Constants.GENERIC_LABEL_FORMAT,
// Constants.HYPERVISOR_LABEL_PREFIX,
// kernelInfo.get(0));
}

return ret.toLowerCase();
Expand Down Expand Up @@ -523,7 +547,11 @@ class NodeHelper {
/* As of now, cases 1-3 should work with
* parseRedHatOsInfoString
*/
osInfo = parseRedHatOsInfoString(cmdResult);
if (cmdResult.contains("Fedora")) {
osInfo = parseFedoraOsInfoString(cmdResult);
} else {
osInfo = parseRedHatOsInfoString(cmdResult);
}
break;
case 4:
osInfo = parseSuseOsInfoString(cmdResult);
Expand Down Expand Up @@ -631,6 +659,29 @@ class NodeHelper {
return new Tuple(retOsName,retOsVersion);
}

private Tuple parseFedoraOsInfoString(String rawValue) {
String retOsName = "parseFedoraOsInfoString:INVALID_INPUT";
String retOsVersion = "parseFedoraOsInfoString:INVALID_INPUT";

/* Sample raw values
* Fedora release 24 (twenty-four)
*/

if (rawValue.length() > 0) {
rawValue = rawValue.trim();

String[] rawValueSplit = rawValue.split(" ");

retOsName = rawValueSplit[0];
if (rawValueSplit[1].equals("release")) {
retOsVersion = rawValueSplit[2];
}

}

return new Tuple(retOsName,retOsVersion);
}

private Tuple parseOsInfoString(String rawValue) {
String retOsName = "parseOsInfoString:INVALID_INPUT";
String retOsVersion = "parseOsInfoString:INVALID_INPUT";
Expand Down Expand Up @@ -805,6 +856,26 @@ class NodeHelper {
return ret;
}

/**
* Sets the machine description from jenkins
*
* @param compterName computer whose location is needed
* @param description the new updated description
*
* @return machine description as string
*/
public String setDescription(String computerName, String description) {
String ret = "setDescription:COMPUTER_NOT_FOUND";

Computer computer = getComputer(computerName);
if (computer != null) {
computer.getNode().setNodeDescription(description);
ret = getDescription(computerName);
}

return ret;
}

/**
* Gets cpu count via exec on the computer passed
* in.
Expand Down Expand Up @@ -1093,7 +1164,7 @@ class NodeHelper {
*/
humanReadable = humanReadable/1000;

return String.format("%d%sB", (Math.rint(humanReadable)).intValue(), pre);
return String.format("%d %sB", (Math.rint(humanReadable)).intValue(), pre);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion vars/Constants.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ class Constants {
static final String WGET_SLAVE_JAR = "\"wget -q --no-check-certificate -O slave.jar ${SLAVE_JAR_LOCATION} ; java -jar slave.jar\"";
static final String SSH_COMMAND = "ssh -C -i ${SSH_KEY_LOCATION} <userName/>@";
static final String SSH_KEY_LOCATION = "";
}

static final String JENKINS_URL = "https://ci.adoptopenjdk.net/";

static final String OS_LABEL_FORMAT = "%s.%s.%s";
static final String GENERIC_LABEL_FORMAT = "%s.%s";
static final String OS_LABEL_PREFIX = "sw.os";
static final String ENDIAN_LABEL_PREFIX = "hw.endian";
static final String PLATFORM_LABEL_PREFIX = "hw.platform";
static final String ARCH_LABEL_PREFIX = "hw.arch";
static final String KERNEL_LABEL_PREFIX = "hw.kernel";
static final String HYPERVISOR_LABEL_PREFIX = "hw.hypervisor";
}

0 comments on commit ac19260

Please sign in to comment.