summaryrefslogtreecommitdiffstats
path: root/node-admin/src/main
diff options
context:
space:
mode:
authorHÃ¥kon Hallingstad <hakon@oath.com>2018-07-31 10:01:38 +0200
committerGitHub <noreply@github.com>2018-07-31 10:01:38 +0200
commit05f3204947b8abbc478a3c79fe08eb2ee9e3e619 (patch)
treece69a4617d7246b61dc272c142b383371f14663a /node-admin/src/main
parent0a5e370b59373d8147e2a8e682bc3296eec0d639 (diff)
parent8b0c481d2ced3d01a2259a38265b7e43d84ae622 (diff)
Merge pull request #6489 from vespa-engine/freva/fix-services-xml
Create StoredInteger
Diffstat (limited to 'node-admin/src/main')
-rw-r--r--node-admin/src/main/application/services.xml4
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredInteger.java52
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/Yum.java6
3 files changed, 59 insertions, 3 deletions
diff --git a/node-admin/src/main/application/services.xml b/node-admin/src/main/application/services.xml
index 96fe82a5b94..284b356d2ca 100644
--- a/node-admin/src/main/application/services.xml
+++ b/node-admin/src/main/application/services.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
<services version="1.0" xmlns:preprocess="properties">
- <jdisc id="node-admin" jetty="true" version="1.0">
+ <container id="node-admin" version="1.0">
<!-- Please update container test when changing this file -->
<accesslog type="vespa" fileNamePattern="logs/vespa/node-admin/access.log.%Y%m%d%H%M%S" rotationScheme="date" symlinkName="access.log" />
<component id="docker-api" class="com.yahoo.vespa.hosted.dockerapi.DockerImpl" bundle="docker-api"/>
@@ -13,5 +13,5 @@
</config>
<preprocess:include file="variant.xml" required="false"/>
- </jdisc>
+ </container>
</services>
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredInteger.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredInteger.java
new file mode 100644
index 00000000000..61c0624e6a9
--- /dev/null
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/StoredInteger.java
@@ -0,0 +1,52 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.node.admin.task.util.file;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.util.OptionalInt;
+import java.util.function.Supplier;
+
+/**
+ * Class wrapping an integer stored on disk
+ *
+ * @author freva
+ */
+public class StoredInteger implements Supplier<OptionalInt> {
+
+ private final Path path;
+ private OptionalInt value;
+ private boolean hasBeenRead = false;
+
+ public StoredInteger(Path path) {
+ this.path = path;
+ }
+
+ @Override
+ public OptionalInt get() {
+ if (!hasBeenRead) {
+ try {
+ String value = new String(Files.readAllBytes(path));
+ this.value = OptionalInt.of(Integer.valueOf(value));
+ } catch (NoSuchFileException e) {
+ this.value = OptionalInt.empty();
+ } catch (IOException e) {
+ throw new UncheckedIOException("Failed to read integer in " + path, e);
+ }
+ hasBeenRead = true;
+ }
+ return value;
+ }
+
+ public void write(int value) {
+ try {
+ Files.write(path, Integer.toString(value).getBytes());
+ this.value = OptionalInt.of(value);
+ this.hasBeenRead = true;
+ } catch (IOException e) {
+ throw new UncheckedIOException("Failed to store integer in " + path, e);
+ }
+ }
+}
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 d88c6f4ab33..5d60823d1c5 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
@@ -36,6 +36,10 @@ public class Yum {
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) {
return newYumCommand("upgrade", packages, UPGRADE_NOOP_PATTERN);
}
@@ -70,7 +74,7 @@ public class Yum {
this.packages = packages;
this.commandOutputNoopPattern = commandOutputNoopPattern;
- if (packages.isEmpty()) {
+ if (packages.isEmpty() && ! "upgrade".equals(yumCommand)) {
throw new IllegalArgumentException("No packages specified");
}
}