From ac19260adba43f0ee3c04882c567d35f25d69cee Mon Sep 17 00:00:00 2001 From: Shubham Verma Date: Wed, 11 Apr 2018 11:07:10 -0400 Subject: [PATCH] Extracted label strings to Constants file - Modified the API to use label strings from Constants.groovy - Added setDescription function issue #2 Signed-off-by: Shubham Verma --- src/NodeHelper.groovy | 89 ++++++++++++++++++++++++++++++++++++++----- vars/Constants.groovy | 12 +++++- 2 files changed, 91 insertions(+), 10 deletions(-) diff --git a/src/NodeHelper.groovy b/src/NodeHelper.groovy index afa856c..bbf0b2c 100644 --- a/src/NodeHelper.groovy +++ b/src/NodeHelper.groovy @@ -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(); @@ -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(); @@ -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(); @@ -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); } @@ -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; @@ -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(); @@ -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); @@ -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"; @@ -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. @@ -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); } /** diff --git a/vars/Constants.groovy b/vars/Constants.groovy index f781839..c7f7c7b 100644 --- a/vars/Constants.groovy +++ b/vars/Constants.groovy @@ -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} @"; 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"; +}