aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@oath.com>2018-02-21 14:20:54 +0100
committerValerij Fredriksen <valerijf@oath.com>2018-02-21 14:20:54 +0100
commite9679bdbed60b0a03407cc7ce055c49af4a75a53 (patch)
treeb4bd2d1ef82c53d7c4fe1a8b6b8db863c58cffd5 /node-admin
parentfcfdd914e1e90906a8106f4f32480dbcc5e18ce3 (diff)
Add Vespa home in node resolver
Diffstat (limited to 'node-admin')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/Environment.java19
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/PathResolver.java11
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java118
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/logging/FilebeatConfigProvider.java9
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java42
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerFailTest.java4
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java5
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/MultiDockerTest.java8
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeStateTest.java6
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RebootTest.java2
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RestartTest.java2
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/EnvironmentTest.java11
12 files changed, 131 insertions, 106 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/Environment.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/Environment.java
index c093865fb88..0fe9cc97b0f 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/Environment.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/Environment.java
@@ -212,13 +212,12 @@ public class Environment {
/**
* Translates an absolute path in node agent container to an absolute path in node admin container.
* @param containerName name of the node agent container
- * @param absolutePathInNode absolute path in that container
+ * @param pathInNode absolute path in that container
* @return the absolute path in node admin container pointing at the same inode
*/
- public Path pathInNodeAdminFromPathInNode(ContainerName containerName, String absolutePathInNode) {
- Path pathInNode = Paths.get(absolutePathInNode);
+ public Path pathInNodeAdminFromPathInNode(ContainerName containerName, Path pathInNode) {
if (! pathInNode.isAbsolute()) {
- throw new IllegalArgumentException("The specified path in node was not absolute: " + absolutePathInNode);
+ throw new IllegalArgumentException("The specified path in node was not absolute: " + pathInNode);
}
return pathResolver.getApplicationStoragePathForNodeAdmin()
@@ -229,13 +228,12 @@ public class Environment {
/**
* Translates an absolute path in node agent container to an absolute path in host.
* @param containerName name of the node agent container
- * @param absolutePathInNode absolute path in that container
+ * @param pathInNode absolute path in that container
* @return the absolute path in host pointing at the same inode
*/
- public Path pathInHostFromPathInNode(ContainerName containerName, String absolutePathInNode) {
- Path pathInNode = Paths.get(absolutePathInNode);
+ public Path pathInHostFromPathInNode(ContainerName containerName, Path pathInNode) {
if (! pathInNode.isAbsolute()) {
- throw new IllegalArgumentException("The specified path in node was not absolute: " + absolutePathInNode);
+ throw new IllegalArgumentException("The specified path in node was not absolute: " + pathInNode);
}
return pathResolver.getApplicationStoragePathForHost()
@@ -243,6 +241,11 @@ public class Environment {
.resolve(PathResolver.ROOT.relativize(pathInNode));
}
+ public Path pathInNodeUnderVespaHome(String relativePath) {
+ return pathResolver.getVespaHomePathForContainer()
+ .resolve(relativePath);
+ }
+
public List<String> getLogstashNodes() {
return logstashNodes;
}
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/PathResolver.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/PathResolver.java
index f70f451d33d..76a62ef972c 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/PathResolver.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/PathResolver.java
@@ -1,6 +1,8 @@
// 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.component;
+import com.yahoo.vespa.defaults.Defaults;
+
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -11,20 +13,27 @@ public class PathResolver {
public static final Path ROOT = Paths.get("/");
public static final Path RELATIVE_APPLICATION_STORAGE_PATH = Paths.get("home/docker/container-storage");
+ private final Path vespaHomePathForContainer;
private final Path applicationStoragePathForNodeAdmin;
private final Path applicationStoragePathForHost;
public PathResolver() {
this(
+ Paths.get(Defaults.getDefaults().vespaHome()),
Paths.get("/host").resolve(RELATIVE_APPLICATION_STORAGE_PATH),
ROOT.resolve(RELATIVE_APPLICATION_STORAGE_PATH));
}
- public PathResolver(Path applicationStoragePathForNodeAdmin, Path applicationStoragePathForHost) {
+ public PathResolver(Path vespaHomePathForContainer, Path applicationStoragePathForNodeAdmin, Path applicationStoragePathForHost) {
+ this.vespaHomePathForContainer = vespaHomePathForContainer;
this.applicationStoragePathForNodeAdmin = applicationStoragePathForNodeAdmin;
this.applicationStoragePathForHost = applicationStoragePathForHost;
}
+ public Path getVespaHomePathForContainer() {
+ return vespaHomePathForContainer;
+ }
+
public Path getApplicationStoragePathForNodeAdmin() {
return applicationStoragePathForNodeAdmin;
}
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java
index c0d939b0d97..d79f3440399 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java
@@ -20,6 +20,8 @@ import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.URI;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -36,65 +38,25 @@ import static com.yahoo.vespa.defaults.Defaults.getDefaults;
* @author Haakon Dybdahl
*/
public class DockerOperationsImpl implements DockerOperations {
- public static final String NODE_PROGRAM = getDefaults().underVespaHome("bin/vespa-nodectl");
-
- private static final String[] RESUME_NODE_COMMAND = new String[]{NODE_PROGRAM, "resume"};
- private static final String[] SUSPEND_NODE_COMMAND = new String[]{NODE_PROGRAM, "suspend"};
- private static final String[] RESTART_VESPA_ON_NODE_COMMAND = new String[]{NODE_PROGRAM, "restart-vespa"};
- private static final String[] STOP_NODE_COMMAND = new String[]{NODE_PROGRAM, "stop"};
private static final String MANAGER_NAME = "node-admin";
private static final String LOCAL_IPV6_PREFIX = "fd00::";
private static final String DOCKER_CUSTOM_BRIDGE_NETWORK_NAME = "vespa-bridge";
-
- // Map of directories to mount and whether they should be writable by everyone
- private static final Map<String, Boolean> DIRECTORIES_TO_MOUNT = new HashMap<>();
-
- static {
- DIRECTORIES_TO_MOUNT.put("/etc/yamas-agent", true);
- DIRECTORIES_TO_MOUNT.put("/etc/filebeat", true);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/daemontools_y"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/jdisc_core"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/langdetect/"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/vespa"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/yca"), true);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/yck"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/yell"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/ykeykey"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/ykeykeyd"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/yms_agent"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/ysar"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/ystatus"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("logs/zpu"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/cache"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/crash"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/db/jdisc"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/db/vespa"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/jdisc_container"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/jdisc_core"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/maven"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/run"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/scoreboards"), true);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/service"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/share"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/spool"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/vespa"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/yca"), true);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/ycore++"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/zookeeper"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("var/zpe"), false);
- DIRECTORIES_TO_MOUNT.put(getDefaults().underVespaHome("tmp"), false);
- }
-
+
private final Docker docker;
private final Environment environment;
private final ProcessExecuter processExecuter;
+ private final String nodeProgram;
+ private Map<Path, Boolean> directoriesToMount;
public DockerOperationsImpl(Docker docker, Environment environment, ProcessExecuter processExecuter) {
this.docker = docker;
this.environment = environment;
this.processExecuter = processExecuter;
+
+ this.nodeProgram = environment.pathInNodeUnderVespaHome("bin/vespa-nodectl").toString();
+ this.directoriesToMount = getDirectoriesToMount(environment);
}
@Override
@@ -133,9 +95,9 @@ public class DockerOperationsImpl implements DockerOperations {
command.withNetworkMode(DOCKER_CUSTOM_BRIDGE_NETWORK_NAME);
}
- for (String pathInNode : DIRECTORIES_TO_MOUNT.keySet()) {
+ for (Path pathInNode : directoriesToMount.keySet()) {
String pathInHost = environment.pathInHostFromPathInNode(containerName, pathInNode).toString();
- command.withVolume(pathInHost, pathInNode);
+ command.withVolume(pathInHost, pathInNode.toString());
}
// TODO: Enforce disk constraints
@@ -174,8 +136,11 @@ public class DockerOperationsImpl implements DockerOperations {
docker.startContainer(containerName);
}
- DIRECTORIES_TO_MOUNT.entrySet().stream().filter(Map.Entry::getValue).forEach(entry ->
- docker.executeInContainerAsRoot(containerName, "chmod", "-R", "a+w", entry.getKey()));
+ directoriesToMount.entrySet().stream()
+ .filter(Map.Entry::getValue)
+ .map(Map.Entry::getKey)
+ .forEach(path ->
+ docker.executeInContainerAsRoot(containerName, "chmod", "-R", "a+w", path.toString()));
} catch (IOException e) {
throw new RuntimeException("Failed to start container " + containerName.asString(), e);
}
@@ -227,13 +192,12 @@ public class DockerOperationsImpl implements DockerOperations {
public void trySuspendNode(ContainerName containerName) {
try {
// TODO: Change to waiting w/o timeout (need separate thread that we can stop).
- executeCommandInContainer(containerName, SUSPEND_NODE_COMMAND);
+ executeCommandInContainer(containerName, nodeProgram, "suspend");
} catch (RuntimeException e) {
PrefixLogger logger = PrefixLogger.getNodeAgentLogger(DockerOperationsImpl.class, containerName);
// It's bad to continue as-if nothing happened, but on the other hand if we do not proceed to
// remove container, we will not be able to upgrade to fix any problems in the suspend logic!
- logger.warning("Failed trying to suspend container " + containerName.asString() + " with "
- + Arrays.toString(SUSPEND_NODE_COMMAND), e);
+ logger.warning("Failed trying to suspend container " + containerName.asString(), e);
}
}
@@ -308,17 +272,17 @@ public class DockerOperationsImpl implements DockerOperations {
@Override
public void resumeNode(ContainerName containerName) {
- executeCommandInContainer(containerName, RESUME_NODE_COMMAND);
+ executeCommandInContainer(containerName, nodeProgram, "resume");
}
@Override
public void restartVespaOnNode(ContainerName containerName) {
- executeCommandInContainer(containerName, RESTART_VESPA_ON_NODE_COMMAND);
+ executeCommandInContainer(containerName, nodeProgram, "restart-vespa");
}
@Override
public void stopServicesOnNode(ContainerName containerName) {
- executeCommandInContainer(containerName, STOP_NODE_COMMAND);
+ executeCommandInContainer(containerName, nodeProgram, "stop");
}
@Override
@@ -340,4 +304,46 @@ public class DockerOperationsImpl implements DockerOperations {
public void deleteUnusedDockerImages() {
docker.deleteUnusedDockerImages();
}
+
+ /**
+ * Returns map of directories to mount and whether they should be writable by everyone
+ */
+ private static Map<Path, Boolean> getDirectoriesToMount(Environment environment) {
+ final Map<Path, Boolean> directoriesToMount = new HashMap<>();
+ directoriesToMount.put(Paths.get("/etc/yamas-agent"), true);
+ directoriesToMount.put(Paths.get("/etc/filebeat"), true);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/daemontools_y"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/jdisc_core"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/langdetect/"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/vespa"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/yca"), true);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/yck"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/yell"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/ykeykey"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/ykeykeyd"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/yms_agent"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/ysar"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/ystatus"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("logs/zpu"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/cache"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/crash"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/db/jdisc"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/db/vespa"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/jdisc_container"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/jdisc_core"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/maven"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/run"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/scoreboards"), true);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/service"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/share"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/spool"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/vespa"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/yca"), true);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/ycore++"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/zookeeper"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("var/zpe"), false);
+ directoriesToMount.put(environment.pathInNodeUnderVespaHome("tmp"), false);
+
+ return directoriesToMount;
+ }
}
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/logging/FilebeatConfigProvider.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/logging/FilebeatConfigProvider.java
index 422e47fe83a..c83f7dd2e6b 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/logging/FilebeatConfigProvider.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/logging/FilebeatConfigProvider.java
@@ -1,7 +1,6 @@
// Copyright 2017 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.logging;
-import static com.yahoo.vespa.defaults.Defaults.getDefaults;
import com.yahoo.vespa.hosted.node.admin.ContainerNodeSpec;
import com.yahoo.vespa.hosted.node.admin.component.Environment;
@@ -61,7 +60,7 @@ public class FilebeatConfigProvider {
: String.format("\"%s\"", logstashNode);
}
- private static String getTemplate() {
+ private String getTemplate() {
return "################### Filebeat Configuration Example #########################\n" +
"\n" +
"############################# Filebeat ######################################\n" +
@@ -71,7 +70,7 @@ public class FilebeatConfigProvider {
"\n" +
" # vespa\n" +
" - paths:\n" +
- " - " + getDefaults().underVespaHome("logs/vespa/vespa.log") + "\n" +
+ " - " + environment.pathInNodeUnderVespaHome("logs/vespa/vespa.log") + "\n" +
" exclude_files: [\".gz$\"]\n" +
" document_type: vespa\n" +
" fields:\n" +
@@ -87,7 +86,7 @@ public class FilebeatConfigProvider {
"\n" +
" # vespa qrs\n" +
" - paths:\n" +
- " - " + getDefaults().underVespaHome("logs/vespa/qrs/QueryAccessLog.*.*") + "\n" +
+ " - " + environment.pathInNodeUnderVespaHome("logs/vespa/qrs/QueryAccessLog.*.*") + "\n" +
" exclude_files: [\".gz$\"]\n" +
" exclude_lines: [\"reserved-for-internal-use/feedapi\"]\n" +
" document_type: vespa-qrs\n" +
@@ -201,7 +200,7 @@ public class FilebeatConfigProvider {
" # To enable logging to files, to_files option has to be set to true\n" +
" files:\n" +
" # The directory where the log files will written to.\n" +
- " path: " + getDefaults().underVespaHome("logs/filebeat") + "\n" +
+ " path: " + environment.pathInNodeUnderVespaHome("logs/filebeat") + "\n" +
"\n" +
" # The name of the files where the logs are written to.\n" +
" name: filebeat\n" +
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java
index c12f1168240..a09dea69a1c 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainer.java
@@ -67,13 +67,14 @@ public class StorageMaintainer {
}
public void writeMetricsConfig(ContainerName containerName, ContainerNodeSpec nodeSpec) {
- final Path yamasAgentFolder = environment.pathInNodeAdminFromPathInNode(containerName, "/etc/yamas-agent/");
+ final Path yamasAgentFolder = environment.pathInNodeAdminFromPathInNode(
+ containerName, Paths.get("/etc/yamas-agent/"));
- Path vespaCheckPath = Paths.get(getDefaults().underVespaHome("libexec/yms/yms_check_vespa"));
+ Path vespaCheckPath = environment.pathInNodeUnderVespaHome("libexec/yms/yms_check_vespa");
SecretAgentScheduleMaker vespaSchedule = new SecretAgentScheduleMaker("vespa", 60, vespaCheckPath, "all")
.withTag("parentHostname", environment.getParentHostHostname());
- Path hostLifeCheckPath = Paths.get(getDefaults().underVespaHome("libexec/yms/yms_check_host_life"));
+ Path hostLifeCheckPath = environment.pathInNodeUnderVespaHome("libexec/yms/yms_check_host_life");
SecretAgentScheduleMaker hostLifeSchedule = new SecretAgentScheduleMaker("host-life", 60, hostLifeCheckPath)
.withTag("namespace", "Vespa")
.withTag("role", "tenants")
@@ -112,7 +113,8 @@ public class StorageMaintainer {
logger.error("Was not able to generate a config for filebeat, ignoring filebeat file creation." + nodeSpec.toString());
return;
}
- Path filebeatPath = environment.pathInNodeAdminFromPathInNode(containerName, "/etc/filebeat/filebeat.yml");
+ Path filebeatPath = environment.pathInNodeAdminFromPathInNode(
+ containerName, Paths.get("/etc/filebeat/filebeat.yml"));
Files.write(filebeatPath, config.get().getBytes());
logger.info("Wrote filebeat config.");
} catch (Throwable t) {
@@ -121,7 +123,7 @@ public class StorageMaintainer {
}
public Optional<Long> getDiskUsageFor(ContainerName containerName) {
- Path containerDir = environment.pathInNodeAdminFromPathInNode(containerName, "/home/");
+ Path containerDir = environment.pathInNodeAdminFromPathInNode(containerName, Paths.get("/home/"));
try {
return Optional.of(getDiskUsedInBytes(containerDir));
} catch (Throwable e) {
@@ -165,15 +167,15 @@ public class StorageMaintainer {
}
private void addRemoveOldFilesCommand(MaintainerExecutor maintainerExecutor, ContainerName containerName) {
- String[] pathsToClean = {
- getDefaults().underVespaHome("logs/elasticsearch2"),
- getDefaults().underVespaHome("logs/logstash2"),
- getDefaults().underVespaHome("logs/daemontools_y"),
- getDefaults().underVespaHome("logs/nginx"),
- getDefaults().underVespaHome("logs/vespa")
+ Path[] pathsToClean = {
+ environment.pathInNodeUnderVespaHome("logs/elasticsearch2"),
+ environment.pathInNodeUnderVespaHome("logs/logstash2"),
+ environment.pathInNodeUnderVespaHome("logs/daemontools_y"),
+ environment.pathInNodeUnderVespaHome("logs/nginx"),
+ environment.pathInNodeUnderVespaHome("logs/vespa")
};
- for (String pathToClean : pathsToClean) {
+ for (Path pathToClean : pathsToClean) {
Path path = environment.pathInNodeAdminFromPathInNode(containerName, pathToClean);
if (Files.exists(path)) {
maintainerExecutor.addJob("delete-files")
@@ -185,7 +187,7 @@ public class StorageMaintainer {
}
Path qrsDir = environment.pathInNodeAdminFromPathInNode(
- containerName, getDefaults().underVespaHome("logs/vespa/qrs"));
+ containerName, environment.pathInNodeUnderVespaHome("logs/vespa/qrs"));
maintainerExecutor.addJob("delete-files")
.withArgument("basePath", qrsDir)
.withArgument("maxAgeSeconds", Duration.ofDays(3).getSeconds())
@@ -193,14 +195,14 @@ public class StorageMaintainer {
.withArgument("recursive", false);
Path logArchiveDir = environment.pathInNodeAdminFromPathInNode(
- containerName, getDefaults().underVespaHome("logs/vespa/logarchive"));
+ containerName, environment.pathInNodeUnderVespaHome("logs/vespa/logarchive"));
maintainerExecutor.addJob("delete-files")
.withArgument("basePath", logArchiveDir)
.withArgument("maxAgeSeconds", Duration.ofDays(31).getSeconds())
.withArgument("recursive", false);
Path fileDistrDir = environment.pathInNodeAdminFromPathInNode(
- containerName, getDefaults().underVespaHome("var/db/vespa/filedistribution"));
+ containerName, environment.pathInNodeUnderVespaHome("var/db/vespa/filedistribution"));
maintainerExecutor.addJob("delete-files")
.withArgument("basePath", fileDistrDir)
.withArgument("maxAgeSeconds", Duration.ofDays(31).getSeconds())
@@ -247,7 +249,7 @@ public class StorageMaintainer {
maintainerExecutor.addJob("handle-core-dumps")
.withArgument("doneCoredumpsPath", environment.pathInNodeAdminToDoneCoredumps())
.withArgument("coredumpsPath", environment.pathInNodeAdminFromPathInNode(
- containerName, getDefaults().underVespaHome("var/crash")))
+ containerName, environment.pathInNodeUnderVespaHome("var/crash")))
.withArgument("feedEndpoint", environment.getCoredumpFeedEndpoint().get())
.withArgument("attributes", attributes);
}
@@ -268,14 +270,14 @@ public class StorageMaintainer {
.withArgument("dirNameRegex", "^" + Pattern.quote(Environment.APPLICATION_STORAGE_CLEANUP_PATH_PREFIX));
Path nodeAdminJDiskLogsPath = environment.pathInNodeAdminFromPathInNode(
- NODE_ADMIN, getDefaults().underVespaHome("logs/vespa/"));
+ NODE_ADMIN, environment.pathInNodeUnderVespaHome("logs/vespa/"));
maintainerExecutor.addJob("delete-files")
.withArgument("basePath", nodeAdminJDiskLogsPath)
.withArgument("maxAgeSeconds", Duration.ofDays(31).getSeconds())
.withArgument("recursive", false);
Path fileDistrDir = environment.pathInNodeAdminFromPathInNode(
- NODE_ADMIN, getDefaults().underVespaHome("var/db/vespa/filedistribution"));
+ NODE_ADMIN, environment.pathInNodeUnderVespaHome("var/db/vespa/filedistribution"));
maintainerExecutor.addJob("delete-files")
.withArgument("basePath", fileDistrDir)
.withArgument("maxAgeSeconds", Duration.ofDays(31).getSeconds())
@@ -302,10 +304,10 @@ public class StorageMaintainer {
private void addArchiveNodeData(MaintainerExecutor maintainerExecutor, ContainerName containerName) {
maintainerExecutor.addJob("recursive-delete")
.withArgument("path", environment.pathInNodeAdminFromPathInNode(
- containerName, getDefaults().underVespaHome("var")));
+ containerName, environment.pathInNodeUnderVespaHome("var")));
maintainerExecutor.addJob("move-files")
- .withArgument("from", environment.pathInNodeAdminFromPathInNode(containerName, "/"))
+ .withArgument("from", environment.pathInNodeAdminFromPathInNode(containerName, Paths.get("/")))
.withArgument("to", environment.pathInNodeAdminToNodeCleanup(containerName));
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerFailTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerFailTest.java
index 34506bb3143..2c8cea4c8de 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerFailTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerFailTest.java
@@ -37,14 +37,14 @@ public class DockerFailTest {
dockerTester.callOrderVerifier.assertInOrder(
"createContainerCommand with DockerImage { imageId=dockerImage }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }",
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
dockerTester.dockerMock.deleteContainer(new ContainerName("host1"));
dockerTester.callOrderVerifier.assertInOrder(
"deleteContainer with ContainerName { name=host1 }",
"createContainerCommand with DockerImage { imageId=dockerImage }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }",
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
}
}
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java
index d22cb968969..bacae51ab83 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerTester.java
@@ -20,6 +20,7 @@ import com.yahoo.vespa.hosted.node.admin.component.PathResolver;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Clock;
import java.time.Duration;
@@ -37,6 +38,8 @@ import static org.mockito.Mockito.when;
public class DockerTester implements AutoCloseable {
private static final Duration NODE_AGENT_SCAN_INTERVAL = Duration.ofMillis(100);
private static final Duration NODE_ADMIN_CONVERGE_STATE_INTERVAL = Duration.ofMillis(10);
+ private static final Path pathToVespaHome = Paths.get("/opt/vespa");
+ static final String NODE_PROGRAM = pathToVespaHome.resolve("bin/vespa-nodectl").toString();
final CallOrderVerifier callOrderVerifier = new CallOrderVerifier();
final Docker dockerMock = new DockerMock(callOrderVerifier);
@@ -56,7 +59,7 @@ public class DockerTester implements AutoCloseable {
Environment environment = new Environment.Builder()
.inetAddressResolver(inetAddressResolver)
- .pathResolver(new PathResolver(Paths.get("/tmp"), Paths.get("/tmp"))).build();
+ .pathResolver(new PathResolver(pathToVespaHome, Paths.get("/tmp"), Paths.get("/tmp"))).build();
Clock clock = Clock.systemUTC();
DockerOperations dockerOperations = new DockerOperationsImpl(dockerMock, environment, null);
StorageMaintainerMock storageMaintainer = new StorageMaintainerMock(dockerOperations, null, environment, callOrderVerifier, clock);
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/MultiDockerTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/MultiDockerTest.java
index 75a0727cb04..b987150ea57 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/MultiDockerTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/MultiDockerTest.java
@@ -40,16 +40,16 @@ public class MultiDockerTest {
dockerTester.callOrderVerifier.assertInOrder(
"createContainerCommand with DockerImage { imageId=image1 }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }",
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]",
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]",
"createContainerCommand with DockerImage { imageId=image2 }, HostName: host2.test.yahoo.com, ContainerName { name=host2 }",
- "executeInContainerAsRoot with ContainerName { name=host2 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]",
+ "executeInContainerAsRoot with ContainerName { name=host2 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]",
"stopContainer with ContainerName { name=host2 }",
"deleteContainer with ContainerName { name=host2 }",
"createContainerCommand with DockerImage { imageId=image1 }, HostName: host3.test.yahoo.com, ContainerName { name=host3 }",
- "executeInContainerAsRoot with ContainerName { name=host3 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
+ "executeInContainerAsRoot with ContainerName { name=host3 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
dockerTester.callOrderVerifier.assertInOrderWithAssertMessage(
"Maintainer did not receive call to delete application storage",
@@ -89,7 +89,7 @@ public class MultiDockerTest {
ContainerName containerName = ContainerName.fromHostname(hostName);
tester.callOrderVerifier.assertInOrder(
"createContainerCommand with " + dockerImage + ", HostName: " + hostName + ", " + containerName,
- "executeInContainerAsRoot with " + containerName + ", args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
+ "executeInContainerAsRoot with " + containerName + ", args: [" + DockerTester.NODE_PROGRAM + ", resume]");
return containerNodeSpec;
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeStateTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeStateTest.java
index 669556f07ba..94d598002cb 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeStateTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeStateTest.java
@@ -38,7 +38,7 @@ public class NodeStateTest {
tester.callOrderVerifier.assertInOrder(
"createContainerCommand with DockerImage { imageId=dockerImage }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }",
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
}
@@ -61,7 +61,7 @@ public class NodeStateTest {
}
dockerTester.callOrderVerifier.assertInOrder(
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", stop]",
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", stop]",
"stopContainer with ContainerName { name=host1 }",
"deleteContainer with ContainerName { name=host1 }");
}
@@ -104,7 +104,7 @@ public class NodeStateTest {
"Node not started again after being put to active state",
"deleteContainer with ContainerName { name=host1 }",
"createContainerCommand with DockerImage { imageId=newDockerImage }, HostName: host1.test.yahoo.com, ContainerName { name=host1 }",
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", resume]");
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", resume]");
}
}
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RebootTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RebootTest.java
index 2db93ba4203..f46b5cd2eca 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RebootTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RebootTest.java
@@ -58,7 +58,7 @@ public class RebootTest {
assertTrue(nodeAdmin.setFrozen(false));
dockerTester.callOrderVerifier.assertInOrder(
- "executeInContainer with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", stop]");
+ "executeInContainer with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", stop]");
}
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RestartTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RestartTest.java
index 24821e3b75d..23fc1d2af42 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RestartTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/RestartTest.java
@@ -40,7 +40,7 @@ public class RestartTest {
dockerTester.callOrderVerifier.assertInOrder(
"Suspend for host1.test.yahoo.com",
- "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerOperationsImpl.NODE_PROGRAM + ", restart-vespa]");
+ "executeInContainerAsRoot with ContainerName { name=host1 }, args: [" + DockerTester.NODE_PROGRAM + ", restart-vespa]");
}
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/EnvironmentTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/EnvironmentTest.java
index 49a10e34fa6..826fc192f6d 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/EnvironmentTest.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/EnvironmentTest.java
@@ -7,6 +7,9 @@ import com.yahoo.vespa.hosted.node.admin.component.Environment;
import com.yahoo.vespa.hosted.node.admin.component.PathResolver;
import org.junit.Test;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
import static org.junit.Assert.assertEquals;
/**
@@ -20,11 +23,11 @@ public class EnvironmentTest {
ContainerName containerName = new ContainerName("docker1-1");
assertEquals(
"/host/home/docker/container-storage/" + containerName.asString(),
- environment.pathInNodeAdminFromPathInNode(containerName, "/").toString());
+ environment.pathInNodeAdminFromPathInNode(containerName, Paths.get("/")).toString());
assertEquals(
"/home/docker/container-storage/" + containerName.asString(),
- environment.pathInHostFromPathInNode(containerName, "/").toString());
+ environment.pathInHostFromPathInNode(containerName, Paths.get("/")).toString());
}
@Test
@@ -35,13 +38,13 @@ public class EnvironmentTest {
String[] absolutePathsInContainer = {"/" + varPath, varPath, varPath + "/"};
for (String pathInContainer : absolutePathsInContainer) {
- assertEquals(expected, environment.pathInNodeAdminFromPathInNode(containerName, pathInContainer).toString());
+ assertEquals(expected, environment.pathInNodeAdminFromPathInNode(containerName, Paths.get(pathInContainer)).toString());
}
}
@Test(expected=IllegalArgumentException.class)
public void testNonAbsolutePathInNodeConversion() {
- String varPath = getDefaults().underVespaHome("var").substring(1);
+ Path varPath = Paths.get("some/relative/path");
environment.pathInNodeAdminFromPathInNode(new ContainerName("container-1"), varPath);
}
}