diff options
Diffstat (limited to 'node-admin')
27 files changed, 117 insertions, 206 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/TaskContext.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/TaskContext.java index 1a2f5799d94..2caf216c533 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/TaskContext.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/TaskContext.java @@ -2,8 +2,6 @@ package com.yahoo.vespa.hosted.node.admin.component; import java.util.logging.Level; - -import java.util.logging.Level; import java.util.logging.Logger; public interface TaskContext { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeAttributes.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeAttributes.java index 328b6b19a0b..8c58022b67f 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeAttributes.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeAttributes.java @@ -138,11 +138,10 @@ public class NodeAttributes { } @Override - public boolean equals(final Object o) { - if (!(o instanceof NodeAttributes)) { + public boolean equals(Object o) { + if (!(o instanceof NodeAttributes other)) { return false; } - final NodeAttributes other = (NodeAttributes) o; return Objects.equals(hostId, other.hostId) && Objects.equals(restartGeneration, other.restartGeneration) diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeSpec.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeSpec.java index 6e31e699e2c..3cca7deeeae 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeSpec.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/NodeSpec.java @@ -294,9 +294,7 @@ public class NodeSpec { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof NodeSpec)) return false; - - NodeSpec that = (NodeSpec) o; + if (!(o instanceof NodeSpec that)) return false; return Objects.equals(hostname, that.hostname) && Objects.equals(id, that.id) && diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepository.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepository.java index 34ff4feb548..e9359944d5d 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepository.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepository.java @@ -207,59 +207,59 @@ public class RealNodeRepository implements NodeRepository { private static NodeResources.DiskSpeed diskSpeedFromString(String diskSpeed) { if (diskSpeed == null) return NodeResources.DiskSpeed.getDefault(); - switch (diskSpeed) { - case "fast": return NodeResources.DiskSpeed.fast; - case "slow": return NodeResources.DiskSpeed.slow; - case "any": return NodeResources.DiskSpeed.any; - default: throw new IllegalArgumentException("Unknown disk speed '" + diskSpeed + "'"); - } + return switch (diskSpeed) { + case "fast" -> NodeResources.DiskSpeed.fast; + case "slow" -> NodeResources.DiskSpeed.slow; + case "any" -> NodeResources.DiskSpeed.any; + default -> throw new IllegalArgumentException("Unknown disk speed '" + diskSpeed + "'"); + }; } private static NodeResources.StorageType storageTypeFromString(String storageType) { if (storageType == null) return NodeResources.StorageType.getDefault(); - switch (storageType) { - case "remote": return NodeResources.StorageType.remote; - case "local": return NodeResources.StorageType.local; - case "any": return NodeResources.StorageType.any; - default: throw new IllegalArgumentException("Unknown storage type '" + storageType + "'"); - } + return switch (storageType) { + case "remote" -> NodeResources.StorageType.remote; + case "local" -> NodeResources.StorageType.local; + case "any" -> NodeResources.StorageType.any; + default -> throw new IllegalArgumentException("Unknown storage type '" + storageType + "'"); + }; } private static NodeResources.Architecture architectureFromString(String architecture) { if (architecture == null) return NodeResources.Architecture.getDefault(); - switch (architecture) { - case "arm64": return NodeResources.Architecture.arm64; - case "x86_64": return NodeResources.Architecture.x86_64; - case "any": return NodeResources.Architecture.any; - default: throw new IllegalArgumentException("Unknown architecture '" + architecture + "'"); - } + return switch (architecture) { + case "arm64" -> NodeResources.Architecture.arm64; + case "x86_64" -> NodeResources.Architecture.x86_64; + case "any" -> NodeResources.Architecture.any; + default -> throw new IllegalArgumentException("Unknown architecture '" + architecture + "'"); + }; } private static String toString(NodeResources.DiskSpeed diskSpeed) { - switch (diskSpeed) { - case fast : return "fast"; - case slow : return "slow"; - case any : return "any"; - default: throw new IllegalArgumentException("Unknown disk speed '" + diskSpeed.name() + "'"); - } + return switch (diskSpeed) { + case fast -> "fast"; + case slow -> "slow"; + case any -> "any"; + default -> throw new IllegalArgumentException("Unknown disk speed '" + diskSpeed.name() + "'"); + }; } private static String toString(NodeResources.StorageType storageType) { - switch (storageType) { - case remote : return "remote"; - case local : return "local"; - case any : return "any"; - default: throw new IllegalArgumentException("Unknown storage type '" + storageType.name() + "'"); - } + return switch (storageType) { + case remote -> "remote"; + case local -> "local"; + case any -> "any"; + default -> throw new IllegalArgumentException("Unknown storage type '" + storageType.name() + "'"); + }; } private static String toString(NodeResources.Architecture architecture) { - switch (architecture) { - case arm64 : return "arm64"; - case x86_64 : return "x86_64"; - case any : return "any"; - default: throw new IllegalArgumentException("Unknown architecture '" + architecture.name() + "'"); - } + return switch (architecture) { + case arm64 -> "arm64"; + case x86_64 -> "x86_64"; + case any -> "any"; + default -> throw new IllegalArgumentException("Unknown architecture '" + architecture.name() + "'"); + }; } private static NodeRepositoryNode nodeRepositoryNodeFromAddNode(AddNode addNode) { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java index 858bce27ed8..895515a2cff 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImpl.java @@ -57,7 +57,7 @@ public class OrchestratorImpl implements Orchestrator { } catch (HttpException.NotFoundException n) { throw new OrchestratorNotFoundException("Failed to suspend " + hostName + ", host not found"); } catch (HttpException e) { - throw new OrchestratorException("Failed to suspend " + hostName + ": " + e.toString()); + throw new OrchestratorException("Failed to suspend " + hostName + ": " + e); } catch (ConnectionException e) { throw ConvergenceException.ofTransient("Failed to suspend " + hostName + ": " + e.getMessage()); } catch (RuntimeException e) { @@ -70,7 +70,7 @@ public class OrchestratorImpl implements Orchestrator { } private static ConfigServerApi.RetryPolicy<UpdateHostResponse> createRetryPolicyForSuspend() { - return new ConfigServerApi.RetryPolicy<UpdateHostResponse>() { + return new ConfigServerApi.RetryPolicy<>() { @Override public boolean tryNextConfigServer(URI configServerEndpoint, UpdateHostResponse response) { HostStateChangeDenialReason reason = response.reason(); @@ -103,7 +103,7 @@ public class OrchestratorImpl implements Orchestrator { parentHostName, hostnames); batchOperationResult = configServerApi.put(url, Optional.empty(), BatchOperationResult.class, params); } catch (HttpException e) { - throw new OrchestratorException("Failed to batch suspend for " + parentHostName + ": " + e.toString()); + throw new OrchestratorException("Failed to batch suspend for " + parentHostName + ": " + e); } catch (ConnectionException e) { throw ConvergenceException.ofTransient("Failed to batch suspend for " + parentHostName + ": " + e.getMessage()); } catch (RuntimeException e) { @@ -124,7 +124,7 @@ public class OrchestratorImpl implements Orchestrator { } catch (HttpException.NotFoundException n) { throw new OrchestratorNotFoundException("Failed to resume " + hostName + ", host not found"); } catch (HttpException e) { - throw new OrchestratorException("Failed to resume " + hostName + ": " + e.toString()); + throw new OrchestratorException("Failed to resume " + hostName + ": " + e); } catch (ConnectionException e) { throw ConvergenceException.ofTransient("Failed to resume " + hostName + ": " + e.getMessage()); } catch (RuntimeException e) { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/CGroup.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/CGroup.java index df7043ceb78..b98ad7a11bc 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/CGroup.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/CGroup.java @@ -64,15 +64,11 @@ public interface CGroup { long parseValueV1(String value) { long longValue = Long.parseLong(value); - switch (this) { - case THROTTLED_TIME_USEC: - case TOTAL_USAGE_USEC: - return longValue / 1000; // Value in ns - case USER_USAGE_USEC: - case SYSTEM_USAGE_USEC: - return userHzToMicroSeconds(longValue); - default: return longValue; - } + return switch (this) { + case THROTTLED_TIME_USEC, TOTAL_USAGE_USEC -> longValue / 1000; // Value in ns + case USER_USAGE_USEC, SYSTEM_USAGE_USEC -> userHzToMicroSeconds(longValue); + default -> longValue; + }; } long parseValueV2(String value) { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Container.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Container.java index dd725a11364..fb789874acf 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Container.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/Container.java @@ -65,37 +65,11 @@ public class Container extends PartialContainer { } /** The network of a container */ - public static class Network { - - private final String name; - private final String ipv4Address; - - public Network(String name, String ipv4Address) { - this.name = Objects.requireNonNull(name); - this.ipv4Address = Objects.requireNonNull(ipv4Address); - } - - public String name() { - return name; - } - - public String ipv4Address() { - return ipv4Address; + public record Network(String name, String ipv4Address) { + public Network { + Objects.requireNonNull(name); + Objects.requireNonNull(ipv4Address); } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Network network = (Network) o; - return name.equals(network.name) && ipv4Address.equals(network.ipv4Address); - } - - @Override - public int hashCode() { - return Objects.hash(name, ipv4Address); - } - } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/ContainerName.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/ContainerName.java index 6e3b5b3f703..d059de18325 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/ContainerName.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/ContainerName.java @@ -36,13 +36,11 @@ public class ContainerName implements Comparable<ContainerName> { } @Override - public boolean equals(final Object o) { - if (!(o instanceof ContainerName)) { + public boolean equals(Object o) { + if (!(o instanceof ContainerName other)) { return false; } - final ContainerName other = (ContainerName) o; - return Objects.equals(name, other.name); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/RegistryCredentials.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/RegistryCredentials.java index 29934e3d1aa..86040c47efb 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/RegistryCredentials.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/RegistryCredentials.java @@ -8,38 +8,13 @@ import java.util.Objects; * * @author mpolden */ -public class RegistryCredentials { +public record RegistryCredentials(String username, String password) { public static final RegistryCredentials none = new RegistryCredentials("", ""); - private final String username; - private final String password; - - public RegistryCredentials(String username, String password) { - this.username = Objects.requireNonNull(username); - this.password = Objects.requireNonNull(password); - } - - public String username() { - return username; - } - - public String password() { - return password; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RegistryCredentials that = (RegistryCredentials) o; - return username.equals(that.username) && - password.equals(that.password); - } - - @Override - public int hashCode() { - return Objects.hash(username, password); + public RegistryCredentials { + Objects.requireNonNull(username); + Objects.requireNonNull(password); } @Override diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java index cb2134b36af..e8d10805a45 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java @@ -123,7 +123,7 @@ public class AclMaintainer { } private void writeUtf8Content(String content) throws IOException { - Files.write(path, content.getBytes(StandardCharsets.UTF_8)); + Files.writeString(path, content); } private String absolutePath() { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollector.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollector.java index 0933f22dee3..b5a47e0b3be 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollector.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollector.java @@ -26,7 +26,7 @@ public class CoreCollector { private static final Logger logger = Logger.getLogger(CoreCollector.class.getName()); private static final Pattern JAVA_HEAP_DUMP_PATTERN = Pattern.compile("java_pid.*\\.hprof$"); - private static final Pattern CORE_GENERATOR_PATH_PATTERN = Pattern.compile("^Core was generated by `(?<path>.*?)'.$"); + private static final Pattern CORE_GENERATOR_PATH_PATTERN = Pattern.compile("(?m)^Core was generated by `(?<path>.*?)'\\."); private static final Pattern EXECFN_PATH_PATTERN = Pattern.compile("^.* execfn: '(?<path>.*?)'"); private static final Pattern FROM_PATH_PATTERN = Pattern.compile("^.* from '(?<path>.*?)'"); static final String GDB_PATH_RHEL8 = "/opt/rh/gcc-toolset-11/root/bin/gdb"; @@ -40,19 +40,14 @@ public class CoreCollector { this.container = container; } - String getGdbPath(NodeAgentContext context) { - return GDB_PATH_RHEL8; - } - String readBinPathFallback(NodeAgentContext context, ContainerPath coredumpPath) { - String command = getGdbPath(context) + " -n -batch -core " + coredumpPath.pathInContainer() + " | grep \'^Core was generated by\'"; - String[] wrappedCommand = {"/bin/sh", "-c", command}; - CommandResult result = container.executeCommandInContainer(context, context.users().root(), wrappedCommand); + String[] command = {GDB_PATH_RHEL8, "-n", "-batch", "-core", coredumpPath.pathInContainer()}; + CommandResult result = container.executeCommandInContainer(context, context.users().root(), command); Matcher matcher = CORE_GENERATOR_PATH_PATTERN.matcher(result.getOutput()); if (! matcher.find()) { throw ConvergenceException.ofError(String.format("Failed to extract binary path from GDB, result: %s, command: %s", - asString(result), Arrays.toString(wrappedCommand))); + asString(result), Arrays.toString(command))); } return matcher.group("path").split(" ")[0]; } @@ -84,7 +79,7 @@ public class CoreCollector { List<String> readBacktrace(NodeAgentContext context, ContainerPath coredumpPath, String binPath, boolean allThreads) { String threads = allThreads ? "thread apply all bt" : "bt"; - String[] command = {getGdbPath(context), "-n", "-ex", "set print frame-arguments none", + String[] command = {GDB_PATH_RHEL8, "-n", "-ex", "set print frame-arguments none", "-ex", threads, "-batch", binPath, coredumpPath.pathInContainer()}; CommandResult result = container.executeCommandInContainer(context, context.users().root(), command); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/disk/DiskCleanupRule.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/disk/DiskCleanupRule.java index ebc47a0038b..3b11f68910c 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/disk/DiskCleanupRule.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/disk/DiskCleanupRule.java @@ -16,16 +16,5 @@ public interface DiskCleanupRule { LOWEST, LOW, MEDIUM, HIGH, HIGHEST } - class PrioritizedFileAttributes { - private final FileFinder.FileAttributes fileAttributes; - private final Priority priority; - - public PrioritizedFileAttributes(FileFinder.FileAttributes fileAttributes, Priority priority) { - this.fileAttributes = fileAttributes; - this.priority = priority; - } - - public Priority priority() { return priority; } - public FileFinder.FileAttributes fileAttributes() { return fileAttributes; } - } + record PrioritizedFileAttributes(FileFinder.FileAttributes fileAttributes, Priority priority) { } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 025723fe71c..ea352791b36 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -547,7 +547,7 @@ public class NodeAgentImpl implements NodeAgent { StringBuilder builder = new StringBuilder(); appendIfDifferent(builder, "state", lastNode, node, NodeSpec::state); if (builder.length() > 0) { - context.log(logger, Level.INFO, "Changes to node: " + builder.toString()); + context.log(logger, Level.INFO, "Changes to node: " + builder); } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/DefaultEnvWriter.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/DefaultEnvWriter.java index 7073142a8f9..c5a28c26786 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/DefaultEnvWriter.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/DefaultEnvWriter.java @@ -62,7 +62,7 @@ public class DefaultEnvWriter { return false; } else { context.log(logger, "Updating " + defaultEnvFile.toString()); - Path tempFile = Paths.get(defaultEnvFile.toString() + ".tmp"); + Path tempFile = Paths.get(defaultEnvFile + ".tmp"); uncheck(() -> Files.write(tempFile, newDefaultEnvLines)); uncheck(() -> Files.move(tempFile, defaultEnvFile, ATOMIC_MOVE)); return true; @@ -104,17 +104,7 @@ public class DefaultEnvWriter { return newDefaultEnvLines; } - private static class Operation { - final String action; - final String name; - final String value; - - Operation(String action, String name, String value) { - this.action = action; - this.name = name; - this.value = value; - } - + private record Operation(String action, String name, String value) { String toLine() { if (action.equals("unset")) { return "unset " + name; diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Editor.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Editor.java index 88bb1f49582..0a5a8eedef9 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Editor.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Editor.java @@ -75,15 +75,12 @@ public class Editor { } switch (edit.getType()) { - case REPLACE: + case REPLACE -> { modified = true; maybeRemove(diff, line); - break; - case NONE: - newLines.add(line); - break; - default: - throw new IllegalArgumentException("Unknown EditType " + edit.getType()); + } + case NONE -> newLines.add(line); + default -> throw new IllegalArgumentException("Unknown EditType " + edit.getType()); } if (!edit.appendLines().isEmpty()) { @@ -104,7 +101,7 @@ public class Editor { return false; } - String diffDescription = diffTooLarge() ? ": Diff too large (" + diffSize + ")" : ":\n" + diff.toString(); + String diffDescription = diffTooLarge() ? ": Diff too large (" + diffSize + ")" : ":\n" + diff; logConsumer.accept("Patching file " + name + diffDescription); consumer.accept(newLines); return true; diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystem.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystem.java index 4167ba2d76e..9be677fa6d6 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystem.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystem.java @@ -68,7 +68,7 @@ public class ContainerFileSystem extends FileSystem { } @Override - public void close() throws IOException { + public void close() { throw new UnsupportedOperationException(); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLine.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLine.java index be7ee1707ba..4dbf1f5f973 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLine.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLine.java @@ -335,12 +335,8 @@ public class CommandLine { for (int i = 0; i < argument.length(); ++i) { char c = argument.charAt(i); switch (c) { - case '"': - case '\\': - doubleQuoteEscaped.append("\\").append(c); - break; - default: - doubleQuoteEscaped.append(c); + case '"', '\\' -> doubleQuoteEscaped.append("\\").append(c); + default -> doubleQuoteEscaped.append(c); } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java index 41fd716a3e6..3586c649820 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java @@ -67,24 +67,21 @@ class TemplateParser { String type = skipId().orElseThrow(() -> new BadTemplateException(current, "Missing section name")); switch (type) { - case "else": + case "else" -> { if (!sentinels.contains(Sentinel.ELSE)) throw new BadTemplateException(startOfType, "Stray 'else'"); parseEndDirective(); return Optional.of(Sentinel.ELSE); - case "end": + } + case "end" -> { if (!sentinels.contains(Sentinel.END)) throw new BadTemplateException(startOfType, "Stray 'end'"); parseEndDirective(); return Optional.of(Sentinel.END); - case "if": - parseIfSection(sectionList); - break; - case "list": - parseListSection(sectionList); - break; - default: - throw new BadTemplateException(startOfType, "Unknown section '" + type + "'"); + } + case "if" -> parseIfSection(sectionList); + case "list" -> parseListSection(sectionList); + default -> throw new BadTemplateException(startOfType, "Unknown section '" + type + "'"); } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTester.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTester.java index 3052cd0d292..5d53f13420e 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTester.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTester.java @@ -65,14 +65,12 @@ public class YumTester extends Yum { /** Mock the return value of the converge(TaskContext) method for this operation (true iff system was modified) */ public YumTester andReturn(boolean value) { if (value) return execute("Success"); - switch (commandType) { - case deleteVersionLock: - case installFixed: - case install: return execute("Nothing to do"); - case upgrade: return execute("No packages marked for update"); - case remove: return execute("No Packages marked for removal"); - default: throw new IllegalArgumentException("Unknown command type: " + commandType); - } + return switch (commandType) { + case deleteVersionLock, installFixed, install -> execute("Nothing to do"); + case upgrade -> execute("No packages marked for update"); + case remove -> execute("No Packages marked for removal"); + default -> throw new IllegalArgumentException("Unknown command type: " + commandType); + }; } private YumTester execute(String output) { diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImplTest.java index 9014875d780..ff0456cf572 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImplTest.java @@ -60,8 +60,8 @@ public class ConfigServerApiImplTest { mockLog.append(get.getMethod()).append(" ").append(get.getURI()).append(" "); switch (mockReturnCode) { - case FAIL_RETURN_CODE: throw new RuntimeException("FAIL"); - case TIMEOUT_RETURN_CODE: throw new SocketTimeoutException("read timed out"); + case FAIL_RETURN_CODE -> throw new RuntimeException("FAIL"); + case TIMEOUT_RETURN_CODE -> throw new SocketTimeoutException("read timed out"); } BasicStatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, mockReturnCode, null); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainerTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainerTest.java index d98ca5d84f2..6db0bf0c730 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainerTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/StorageMaintainerTest.java @@ -141,7 +141,7 @@ public class StorageMaintainerTest { } @Test - void not_run_if_not_enough_used() throws IOException { + void not_run_if_not_enough_used() { NodeAgentContext context = NodeAgentContextImpl.builder( NodeSpec.Builder.testSpec("h123a.domain.tld").realResources(new NodeResources(1, 1, 1, 1)).build()) .fileSystem(fileSystem).build(); @@ -152,7 +152,7 @@ public class StorageMaintainerTest { } @Test - void deletes_correct_amount() throws IOException { + void deletes_correct_amount() { NodeAgentContext context = NodeAgentContextImpl.builder( NodeSpec.Builder.testSpec("h123a.domain.tld").realResources(new NodeResources(1, 1, 1, 1)).build()) .fileSystem(fileSystem).build(); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollectorTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollectorTest.java index c0bf6ebbeb3..ea73fd4af6f 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollectorTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoreCollectorTest.java @@ -62,8 +62,20 @@ public class CoreCollectorTest { assertEquals(TEST_BIN_PATH, coreCollector.readBinPath(context, TEST_CORE_PATH)); String fallbackResponse = "/response/from/fallback"; - mockExec(new String[]{"/bin/sh", "-c", GDB_PATH_RHEL8 + " -n -batch -core /tmp/core.1234 | grep '^Core was generated by'"}, - "Core was generated by `/response/from/fallback'."); + mockExec(new String[]{GDB_PATH_RHEL8, "-n", "-batch", "-core", "/tmp/core.1234"}, + """ + GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 + Type “apropos word” to search for commands related to “word”… + Reading symbols from abc…(no debugging symbols found)…done. + [New LWP 23678] + Core was generated by `/response/from/fallback'. \s + Program terminated with signal SIGSEGV, Segmentation fault. \s + #0 0x0000000000400541 in main () + #0 0x0000000000400541 in main () + (gdb) bt + #0 0x0000000000400541 in main () + (gdb) + """); mockExec(cmd, "/tmp/core.1234: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style"); assertEquals(fallbackResponse, coreCollector.readBinPath(context, TEST_CORE_PATH)); @@ -74,8 +86,7 @@ public class CoreCollectorTest { @Test void extractsBinaryPathUsingGdbTest() { - final String[] cmd = new String[]{"/bin/sh", "-c", - GDB_PATH_RHEL8 + " -n -batch -core /tmp/core.1234 | grep '^Core was generated by'"}; + String[] cmd = new String[]{GDB_PATH_RHEL8, "-n", "-batch", "-core", "/tmp/core.1234"}; mockExec(cmd, "Core was generated by `/usr/bin/program-from-gdb --identity foo/search/cluster.content_'."); assertEquals("/usr/bin/program-from-gdb", coreCollector.readBinPathFallback(context, TEST_CORE_PATH)); @@ -86,7 +97,7 @@ public class CoreCollectorTest { fail("Expected not to be able to get bin path"); } catch (RuntimeException e) { assertEquals("Failed to extract binary path from GDB, result: exit status 1, output 'Error 123', command: " + - "[/bin/sh, -c, /opt/rh/gcc-toolset-11/root/bin/gdb -n -batch -core /tmp/core.1234 | grep '^Core was generated by']", e.getMessage()); + "[/opt/rh/gcc-toolset-11/root/bin/gdb, -n, -batch, -core, /tmp/core.1234]", e.getMessage()); } } @@ -157,7 +168,7 @@ public class CoreCollectorTest { mockExec(new String[]{"file", TEST_CORE_PATH.pathInContainer()}, "dump.core.5954: ELF 64-bit LSB core file x86-64, version 1 (SYSV), too many program header sections (33172)"); - mockExec(new String[]{"/bin/sh", "-c", GDB_PATH_RHEL8 + " -n -batch -core /tmp/core.1234 | grep '^Core was generated by'"}, + mockExec(new String[]{GDB_PATH_RHEL8, "-n", "-batch", "-core", "/tmp/core.1234"}, "Core was generated by `" + JDK_PATH + " -Dconfig.id=default/container.11 -XX:+Pre'."); String jstack = "jstack11"; diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandlerTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandlerTest.java index 31579fb7c9b..082a1f3de58 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandlerTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandlerTest.java @@ -174,14 +174,14 @@ public class CoredumpHandlerTest { } @Test - void cant_get_metadata_if_no_core_file() throws IOException { + void cant_get_metadata_if_no_core_file() { assertThrows(IllegalStateException.class, () -> { coredumpHandler.getMetadata(context, context.paths().of("/fake/path"), Map::of); }); } @Test - void fails_to_get_core_file_if_only_compressed() throws IOException { + void fails_to_get_core_file_if_only_compressed() { assertThrows(IllegalStateException.class, () -> { ContainerPath coredumpDirectory = context.paths().of("/path/to/coredump/proccessing/id-123"); Files.createDirectories(coredumpDirectory); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/sync/ZstdCompressingInputStreamTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/sync/ZstdCompressingInputStreamTest.java index e6963175977..4eb5ca8a1cd 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/sync/ZstdCompressingInputStreamTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/sync/ZstdCompressingInputStreamTest.java @@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class ZstdCompressingInputStreamTest { @Test - void compression_test() throws Exception { + void compression_test() { Random rnd = new Random(); byte[] data = new byte[(int) (100_000 * (10 + rnd.nextDouble()))]; rnd.nextBytes(data); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdaterTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdaterTest.java index 1197fd1469b..75dc4fffff8 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdaterTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdaterTest.java @@ -58,7 +58,7 @@ public class NodeAdminStateUpdaterTest { mockNodeRepo(NodeState.active, 4); List<String> activeHostnames = nodeRepository.getNodes(hostHostname.value()).stream() .map(NodeSpec::hostname) - .collect(Collectors.toList()); + .toList(); List<String> suspendHostnames = new ArrayList<>(activeHostnames); suspendHostnames.add(hostHostname.value()); when(nodeAdmin.subsystemFreezeDuration()).thenReturn(Duration.ofSeconds(1)); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystemTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystemTest.java index b26f0fe5bf8..29a78519724 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystemTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/fs/ContainerFileSystemTest.java @@ -60,7 +60,7 @@ class ContainerFileSystemTest { unixPath.setOwnerId(500).setGroupId(200); assertOwnership(containerPath, 500, 200, 10500, 11200); - Files.write(containerPath, " world".getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); + Files.writeString(containerPath, " world", StandardOpenOption.APPEND); assertOwnership(containerPath, 500, 200, 10500, 11200); // Owner should not have been updated as the file already existed assertEquals("hello world", unixPath.readUtf8File()); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2ImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2ImplTest.java index f209290cb14..53fdb52102b 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2ImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2ImplTest.java @@ -100,7 +100,7 @@ public class ChildProcess2ImplTest { when(processApi.waitFor(anyLong(), any())).thenReturn(true); - Files.write(temporaryFile, "1234567890123".getBytes(StandardCharsets.UTF_8)); + Files.writeString(temporaryFile, "1234567890123"); try (ChildProcess2Impl child = new ChildProcess2Impl(commandLine, processApi, temporaryFile, timer)) { @@ -130,7 +130,7 @@ public class ChildProcess2ImplTest { when(processApi.waitFor(anyLong(), any())).thenReturn(false); - Files.write(temporaryFile, "1234567890123".getBytes(StandardCharsets.UTF_8)); + Files.writeString(temporaryFile, "1234567890123"); try (ChildProcess2Impl child = new ChildProcess2Impl(commandLine, processApi, temporaryFile, timer)) { |