summaryrefslogtreecommitdiffstats
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
parent0a5e370b59373d8147e2a8e682bc3296eec0d639 (diff)
parent8b0c481d2ced3d01a2259a38265b7e43d84ae622 (diff)
Merge pull request #6489 from vespa-engine/freva/fix-services-xml
Create StoredInteger
-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
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java25
4 files changed, 76 insertions, 11 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");
}
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java
index d29d8741438..7f37336db70 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java
@@ -9,6 +9,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -16,6 +17,7 @@ import static org.mockito.Mockito.mock;
public class YumTest {
private final TaskContext taskContext = mock(TaskContext.class);
private final TestTerminal terminal = new TestTerminal();
+ private final Yum yum = new Yum(terminal);
@Before
public void tearDown() {
@@ -29,7 +31,6 @@ public class YumTest {
0,
"foobar\nNothing to do\n");
- Yum yum = new Yum(terminal);
assertFalse(yum
.install("package-1", "package-2")
.enableRepo("repo-name")
@@ -43,7 +44,7 @@ public class YumTest {
0,
"foobar\nNo packages marked for update\n");
- assertFalse(new Yum(terminal)
+ assertFalse(yum
.upgrade("package-1", "package-2")
.converge(taskContext));
}
@@ -55,7 +56,7 @@ public class YumTest {
0,
"foobar\nNo Packages marked for removal\n");
- assertFalse(new Yum(terminal)
+ assertFalse(yum
.remove("package-1", "package-2")
.converge(taskContext));
}
@@ -67,7 +68,6 @@ public class YumTest {
0,
"installing, installing");
- Yum yum = new Yum(terminal);
assertTrue(yum
.install("package-1", "package-2")
.converge(taskContext));
@@ -80,7 +80,6 @@ public class YumTest {
0,
"installing, installing");
- Yum yum = new Yum(terminal);
assertTrue(yum
.install("package-1", "package-2")
.enableRepo("repo-name")
@@ -94,7 +93,6 @@ public class YumTest {
1,
"error");
- Yum yum = new Yum(terminal);
yum.install("package-1", "package-2")
.enableRepo("repo-name")
.converge(taskContext);
@@ -112,15 +110,26 @@ public class YumTest {
"No package package-2 available.\n" +
"Nothing to do\n");
- Yum yum = new Yum(terminal);
Yum.GenericYumCommand install = yum.install("package-1", "package-2", "package-3");
try {
install.converge(taskContext);
fail();
} catch (Exception e) {
- assertTrue(e.getCause() != null);
+ assertNotNull(e.getCause());
assertEquals("Unknown package: package-1", e.getCause().getMessage());
}
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void throwIfNoPackagesSpecified() {
+ yum.install();
+ }
+
+ @Test
+ public void allowToCallUpgradeWithNoPackages() {
+ terminal.expectCommand("yum upgrade --assumeyes 2>&1", 0, "OK");
+
+ yum.upgrade().converge(taskContext);
+ }
} \ No newline at end of file