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

Node helper api #17

Merged
merged 2 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
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
69 changes: 60 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 @@ -1093,7 +1144,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";
}