aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@oath.com>2018-08-29 14:33:08 +0200
committerHåkon Hallingstad <hakon@oath.com>2018-08-29 14:33:08 +0200
commit2af3765db588666fa909f244c3e13c8dae6eb81a (patch)
treec1720e8a944c21d0536cd7f61f3068f5841812e0 /node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java
parent6591a9f52683829f296c9b0eb2610b9278b5f5ba (diff)
Use YumPackageName internally
- Make install, remove, etc also work with YumPackageName. - adds hashCode and equals
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java56
1 files changed, 35 insertions, 21 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java
index 226135a1617..cb23f053086 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java
@@ -12,6 +12,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
/**
* @author hakonhall
@@ -31,27 +32,41 @@ public class Yum {
this.terminal = terminal;
}
- /**
- * @param packages A list of packages, each package being of the form name-1.2.3-1.el7.noarch
- */
- public GenericYumCommand install(String... packages) {
+ public GenericYumCommand install(YumPackageName... packages) {
return newYumCommand("install", packages, INSTALL_NOOP_PATTERN);
}
- /**
- * @param packages A list of packages, each package being of the form name-1.2.3-1.el7.noarch,
- * if no packages are given, will upgrade all installed packages
- */
- public GenericYumCommand upgrade(String... packages) {
+ public GenericYumCommand install(String package1, String... packages) {
+ return install(toYumPackageNameArray(package1, packages));
+ }
+
+ public GenericYumCommand upgrade(YumPackageName... packages) {
return newYumCommand("upgrade", packages, UPGRADE_NOOP_PATTERN);
}
- public GenericYumCommand remove(String... packages) {
+ public GenericYumCommand upgrade(String package1, String... packages) {
+ return upgrade(toYumPackageNameArray(package1, packages));
+ }
+
+ public GenericYumCommand remove(YumPackageName... packages) {
return newYumCommand("remove", packages, REMOVE_NOOP_PATTERN);
}
+ public GenericYumCommand remove(String package1, String... packages) {
+ return remove(toYumPackageNameArray(package1, packages));
+ }
+
+ static YumPackageName[] toYumPackageNameArray(String package1, String... packages) {
+ YumPackageName[] array = new YumPackageName[1 + packages.length];
+ array[0] = YumPackageName.fromString(package1);
+ for (int i = 0; i < packages.length; ++i) {
+ array[1 + i] = YumPackageName.fromString(packages[i]);
+ }
+ return array;
+ }
+
private GenericYumCommand newYumCommand(String yumCommand,
- String[] packages,
+ YumPackageName[] packages,
Pattern noopPattern) {
return new GenericYumCommand(
terminal,
@@ -63,7 +78,7 @@ public class Yum {
public static class GenericYumCommand {
private final Terminal terminal;
private final String yumCommand;
- private final List<String> packages;
+ private final List<YumPackageName> packages;
private final Pattern commandOutputNoopPattern;
private Optional<String> enabledRepo = Optional.empty();
@@ -71,7 +86,7 @@ public class Yum {
private GenericYumCommand(Terminal terminal,
String yumCommand,
- List<String> packages,
+ List<YumPackageName> packages,
Pattern commandOutputNoopPattern) {
this.terminal = terminal;
this.yumCommand = yumCommand;
@@ -93,11 +108,12 @@ public class Yum {
* Ensure the version of the installs are locked.
*
* <p>WARNING: In order to simplify the user interface of {@link #lockVersion()},
- * the package name specified in the command, e.g. {@link #install(String...)}, MUST be of
+ * the package name specified in the command, e.g. {@link #install(String, String...)}, MUST be of
* a simple format, see {@link YumPackageName#fromString(String)}.
*/
public GenericYumCommand lockVersion() {
- packages.forEach(YumPackageName::fromString); // to throw any parse error here instead of later
+ // Verify each package has sufficient info to form a proper version lock name.
+ packages.forEach(YumPackageName::toVersionLockName);
lockVersion = true;
return this;
}
@@ -109,11 +125,9 @@ public class Yum {
if (lockVersion) {
// Remove all locks for other version
- packages.stream()
- .map(YumPackageName::fromString)
- .forEach(packageName -> {
+ packages.forEach(packageName -> {
packageNamesToLock.add(packageName.getName());
- fullPackageNamesToLock.add(packageName.toVersionLock());
+ fullPackageNamesToLock.add(packageName.toVersionLockName());
});
terminal.newCommandLine(context)
@@ -128,7 +142,7 @@ public class Yum {
if (packageNamesToLock.contains(packageName.getName())) {
// If existing lock doesn't exactly match the full package name,
// it means it's locked to another version and we must remove that lock.
- String versionLockName = packageName.toVersionLock();
+ String versionLockName = packageName.toVersionLockName();
if (!fullPackageNamesToLock.remove(versionLockName)) {
terminal.newCommandLine(context)
.add("yum", "versionlock", "delete", versionLockName)
@@ -141,7 +155,7 @@ public class Yum {
CommandLine commandLine = terminal.newCommandLine(context);
commandLine.add("yum", yumCommand, "--assumeyes");
enabledRepo.ifPresent(repo -> commandLine.add("--enablerepo=" + repo));
- commandLine.add(packages);
+ commandLine.add(packages.stream().map(YumPackageName::toName).collect(Collectors.toList()));
// There's no way to figure out whether a yum command would have been a no-op.
// Therefore, run the command and parse the output to decide.