diff options
author | Valerij Fredriksen <freva@users.noreply.github.com> | 2020-01-20 10:57:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-20 10:57:59 +0100 |
commit | 0c6b28ef310bb5714b8c2ba10651ae87068e9b59 (patch) | |
tree | d2c4aab1b43ccc71a4716c4c041e20c8d479249a | |
parent | a2050c8f5562f24fdf567b8edd7f6517d9945908 (diff) | |
parent | 70bdd96074323056411df99c2d54c8560bab2f08 (diff) |
Merge pull request #11847 from vespa-engine/freva/filter-table-diff
Optimize filter table diff
39 files changed, 139 insertions, 119 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ConfigServerInfo.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ConfigServerInfo.java index d515f0d0353..9da480e55c7 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ConfigServerInfo.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/component/ConfigServerInfo.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.hosted.node.admin.component; import com.yahoo.vespa.athenz.api.AthenzIdentity; import java.net.URI; -import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -27,7 +26,7 @@ public class ConfigServerInfo { this.configServerHostnameToUriMapper = hostname -> URI.create(scheme + "://" + hostname + ":" + port); this.configServerURIs = configServerHostNames.stream() .map(configServerHostnameToUriMapper) - .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); + .collect(Collectors.toUnmodifiableList()); } private static URI createLoadBalancerEndpoint(String loadBalancerHost, String scheme, int port) { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java index a533556bde8..67dcb6744ce 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImpl.java @@ -77,7 +77,7 @@ public class ConfigServerApiImpl implements ConfigServerApi { HostnameVerifier hostnameVerifier, HostName configServerHostname) { return new ConfigServerApiImpl( - Collections.singleton(info.getConfigServerUri(configServerHostname.value())), + List.of(info.getConfigServerUri(configServerHostname.value())), hostnameVerifier, provider); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/Acl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/Acl.java index 8f39fddfa1f..58c9c197d65 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/Acl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/Acl.java @@ -61,9 +61,9 @@ public class Acl { rules.add("-A INPUT -p " + ipVersion.icmpProtocol() + " -j ACCEPT"); // Allow trusted ports if any - String commaSeparatedPorts = trustedPorts.stream().map(i -> Integer.toString(i)).sorted().collect(Collectors.joining(",")); - if (!commaSeparatedPorts.isEmpty()) { - rules.add("-A INPUT -p tcp -m multiport --dports " + commaSeparatedPorts + " -j ACCEPT"); + if (!trustedPorts.isEmpty()) { + String ports = trustedPorts.stream().map(i -> Integer.toString(i)).sorted().collect(Collectors.joining(",")); + rules.add("-A INPUT -p tcp -m multiport --dports " + ports + " -j ACCEPT"); } // Allow traffic from trusted nodes diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/bindings/GetAclResponse.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/bindings/GetAclResponse.java index ea2f313f03a..2d59898dc52 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/bindings/GetAclResponse.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/bindings/GetAclResponse.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collections; import java.util.List; /** @@ -29,9 +28,9 @@ public class GetAclResponse { public GetAclResponse(@JsonProperty("trustedNodes") List<Node> trustedNodes, @JsonProperty("trustedNetworks") List<Network> trustedNetworks, @JsonProperty("trustedPorts") List<Port> trustedPorts) { - this.trustedNodes = trustedNodes == null ? Collections.emptyList() : trustedNodes; - this.trustedNetworks = trustedNetworks == null ? Collections.emptyList() : trustedNetworks; - this.trustedPorts = trustedPorts == null ? Collections.emptyList() : trustedPorts; + this.trustedNodes = trustedNodes == null ? List.of() : trustedNodes; + this.trustedNetworks = trustedNetworks == null ? List.of() : trustedNetworks; + this.trustedPorts = trustedPorts == null ? List.of() : trustedPorts; } @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditor.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditor.java index a9954200f8a..65941ed533a 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditor.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditor.java @@ -6,7 +6,6 @@ import com.yahoo.vespa.hosted.node.admin.task.util.file.LineEdit; import com.yahoo.vespa.hosted.node.admin.task.util.file.LineEditor; import com.yahoo.vespa.hosted.node.admin.task.util.network.IPVersion; -import java.util.LinkedList; import java.util.List; /** @@ -16,10 +15,11 @@ import java.util.List; */ class FilterTableLineEditor implements LineEditor { - private final LinkedList<String> wantedRules; + private final List<String> wantedRules; + private int position = 0; private FilterTableLineEditor(List<String> wantedRules) { - this.wantedRules = new LinkedList<>(wantedRules); + this.wantedRules = List.copyOf(wantedRules); } static FilterTableLineEditor from(Acl acl, IPVersion ipVersion) { @@ -29,15 +29,33 @@ class FilterTableLineEditor implements LineEditor { @Override public LineEdit edit(String line) { - // We have already added all the lines we wanted, remove the remainer - if (wantedRules.isEmpty()) return LineEdit.remove(); - - String wantedRule = wantedRules.pop(); - return wantedRule.equals(line) ? LineEdit.none() : LineEdit.replaceWith(wantedRule); + int index = indexOf(wantedRules, line, position); + // Unwanted rule, remove + if (index < 0) return LineEdit.remove(); + + // Wanted rule at the expected position, no diff + if (index == position) { + position++; + return LineEdit.none(); + } + + // Insert the rules between position and index before index + List<String> toInsert = wantedRules.subList(position, index); + position = ++index; + return LineEdit.insertBefore(toInsert); } @Override public List<String> onComplete() { - return this.wantedRules; + return wantedRules.subList(position, wantedRules.size()); + } + + private static <T> int indexOf(List<T> list, T value, int startPos) { + for (int i = startPos; i < list.size(); i++) { + if (value.equals(list.get(i))) + return i; + } + + return -1; } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditor.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditor.java index e1dc4a661ff..be08e1b2aec 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditor.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditor.java @@ -4,8 +4,6 @@ package com.yahoo.vespa.hosted.node.admin.maintenance.acl; import com.yahoo.vespa.hosted.node.admin.task.util.file.LineEdit; import com.yahoo.vespa.hosted.node.admin.task.util.file.LineEditor; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -45,7 +43,7 @@ class NatTableLineEditor implements LineEditor { @Override public List<String> onComplete() { - if (redirectExists) return new ArrayList<>(); - return Collections.singletonList(redirectRule); + if (redirectExists) return List.of(); + return List.of(redirectRule); } } 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 c063059e8a9..cdf5687d61a 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 @@ -82,7 +82,7 @@ public class CoreCollector { if (result.getExitStatus() != 0) throw new RuntimeException("Failed to read backtrace " + result + ", Command: " + Arrays.toString(command)); - return Arrays.asList(result.getOutput().split("\n")); + return List.of(result.getOutput().split("\n")); } List<String> readJstack(NodeAgentContext context, Path coredumpPath, Path binPath) { @@ -92,7 +92,7 @@ public class CoreCollector { if (result.getExitStatus() != 0) throw new RuntimeException("Failed to read jstack " + result + ", Command: " + Arrays.toString(command)); - return Arrays.asList(result.getOutput().split("\n")); + return List.of(result.getOutput().split("\n")); } /** diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java index 2874546da52..9b0a35d4b96 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/coredump/CoredumpHandler.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.hosted.node.admin.maintenance.coredump; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableMap; import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext; import com.yahoo.vespa.hosted.node.admin.task.util.file.FileFinder; import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixPath; @@ -159,7 +158,7 @@ public class CoredumpHandler { Map<String, Object> metadata = coreCollector.collect(context, coredumpFilePathInContainer); metadata.putAll(nodeAttributesSupplier.get()); - String metadataFields = objectMapper.writeValueAsString(ImmutableMap.of("fields", metadata)); + String metadataFields = objectMapper.writeValueAsString(Map.of("fields", metadata)); metadataPath.writeUtf8File(metadataFields); return metadataFields; } else { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java index 17dc61978cf..4c5ad7c5c3a 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/identity/AthenzCredentialsMaintainer.java @@ -44,11 +44,10 @@ import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; -import static java.util.Collections.singleton; - /** * A maintainer that is responsible for providing and refreshing Athenz credentials for a container. * @@ -103,7 +102,7 @@ public class AthenzCredentialsMaintainer implements CredentialsMaintainer { this.identityDocumentClient = new DefaultIdentityDocumentClient( configServerInfo.getLoadBalancerEndpoint(), hostIdentityProvider, - new AthenzIdentityVerifier(singleton(configserverIdentity))); + new AthenzIdentityVerifier(Set.of(configserverIdentity))); this.clock = clock; this.useInternalZts = useInternalZts; } @@ -194,7 +193,7 @@ public class AthenzCredentialsMaintainer implements CredentialsMaintainer { // Set up a hostname verified for zts if this is configured to use the config server (internal zts) apis HostnameVerifier ztsHostNameVerifier = useInternalZts - ? new AthenzIdentityVerifier(singleton(configserverIdentity)) + ? new AthenzIdentityVerifier(Set.of(configserverIdentity)) : null; try (ZtsClient ztsClient = new DefaultZtsClient(ztsEndpoint, hostIdentityProvider, ztsHostNameVerifier)) { InstanceIdentity instanceIdentity = @@ -223,7 +222,7 @@ public class AthenzCredentialsMaintainer implements CredentialsMaintainer { try { // Set up a hostname verified for zts if this is configured to use the config server (internal zts) apis HostnameVerifier ztsHostNameVerifier = useInternalZts - ? new AthenzIdentityVerifier(singleton(configserverIdentity)) + ? new AthenzIdentityVerifier(Set.of(configserverIdentity)) : null; try (ZtsClient ztsClient = new DefaultZtsClient(ztsEndpoint, containerIdentitySslContext, ztsHostNameVerifier)) { InstanceIdentity instanceIdentity = diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java index ca6a56413c3..caffe5ef2f1 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java @@ -47,20 +47,19 @@ public class NodeAdminImpl implements NodeAdmin { private final Counter numberOfUnhandledExceptions; public NodeAdminImpl(NodeAgentFactory nodeAgentFactory, Metrics metrics, Clock clock) { - this((NodeAgentWithSchedulerFactory) nodeAgentContext -> create(clock, nodeAgentFactory, nodeAgentContext), + this(nodeAgentContext -> create(clock, nodeAgentFactory, nodeAgentContext), metrics, clock, NODE_AGENT_FREEZE_TIMEOUT, NODE_AGENT_SPREAD); } public NodeAdminImpl(NodeAgentFactory nodeAgentFactory, Metrics metrics, Clock clock, Duration freezeTimeout, Duration spread) { - this((NodeAgentWithSchedulerFactory) nodeAgentContext -> create(clock, nodeAgentFactory, nodeAgentContext), + this(nodeAgentContext -> create(clock, nodeAgentFactory, nodeAgentContext), metrics, clock, freezeTimeout, spread); } NodeAdminImpl(NodeAgentWithSchedulerFactory nodeAgentWithSchedulerFactory, Metrics metrics, Clock clock, Duration freezeTimeout, Duration spread) { this.nodeAgentWithSchedulerFactory = nodeAgentWithSchedulerFactory; - this.clock = clock; this.freezeTimeout = freezeTimeout; this.spread = spread; 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 fdb9428dc3f..68178418e62 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 @@ -428,7 +428,7 @@ public class NodeAgentImpl implements NodeAgent { } container = removeContainerIfNeededUpdateContainerState(context, container); credentialsMaintainer.ifPresent(maintainer -> maintainer.converge(context)); - if (! container.isPresent()) { + if (container.isEmpty()) { containerState = STARTING; startContainer(context); containerState = UNKNOWN; @@ -497,7 +497,7 @@ public class NodeAgentImpl implements NodeAgent { private Optional<Container> getContainer(NodeAgentContext context) { if (containerState == ABSENT) return Optional.empty(); Optional<Container> container = dockerOperations.getContainer(context); - if (! container.isPresent()) containerState = ABSENT; + if (container.isEmpty()) containerState = ABSENT; return container; } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/editor/CursorImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/editor/CursorImpl.java index 47c710395f5..f5b5c8ae31e 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/editor/CursorImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/editor/CursorImpl.java @@ -1,8 +1,7 @@ // 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.editor; -import java.util.Arrays; +import java.util.List; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -223,7 +222,7 @@ public class CursorImpl implements Cursor { @Override public Cursor writeLines(String... lines) { - return writeLines(Arrays.asList(lines)); + return writeLines(List.of(lines)); } @Override @@ -307,7 +306,7 @@ public class CursorImpl implements Cursor { @Override public boolean replaceMatch(Pattern pattern, Function<Match, String> replacer) { Optional<Match> match = moveForwardToStartOfMatch(pattern); - if (!match.isPresent()) { + if (match.isEmpty()) { return false; } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/AttributeSync.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/AttributeSync.java index 16eb1a9b509..a781615e44d 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/AttributeSync.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/AttributeSync.java @@ -101,7 +101,7 @@ public class AttributeSync { Optional<String> wantedValue, Supplier<String> currentValueSupplier, Consumer<String> valueSetter) { - if (!wantedValue.isPresent()) { + if (wantedValue.isEmpty()) { return false; } 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 112197101b4..2b66c5fad2e 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 @@ -3,7 +3,6 @@ package com.yahoo.vespa.hosted.node.admin.task.util.file; import com.yahoo.vespa.hosted.node.admin.component.TaskContext; -import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java index b78d155bdbf..f10ebd5e315 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java @@ -14,9 +14,9 @@ import java.nio.file.attribute.BasicFileAttributes; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.Stack; import java.util.function.Consumer; import java.util.function.Predicate; @@ -139,7 +139,7 @@ public class FileFinder { try { // Only need to traverse as deep as we want to match, unless we want to match everything in directories // already matched - Files.walkFileTree(basePath, Collections.emptySet(), maxDepth, new SimpleFileVisitor<>() { + Files.walkFileTree(basePath, Set.of(), maxDepth, new SimpleFileVisitor<>() { private final Stack<FileAttributes> matchingDirectoryStack = new Stack<>(); private int currentLevel = -1; diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/LineEdit.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/LineEdit.java index 78e7a3e71b6..88bf25c65a9 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/LineEdit.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/LineEdit.java @@ -1,11 +1,7 @@ // 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 com.google.common.collect.ImmutableList; - import javax.annotation.concurrent.Immutable; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import static com.yahoo.vespa.hosted.node.admin.task.util.file.LineEdit.Type.REPLACE; @@ -18,17 +14,17 @@ import static com.yahoo.vespa.hosted.node.admin.task.util.file.LineEdit.Type.NON public class LineEdit { enum Type { NONE, REPLACE } - public static LineEdit none() { return insert(Collections.emptyList(), Collections.emptyList()); } - public static LineEdit remove() { return replaceWith(Collections.emptyList()); } + public static LineEdit none() { return insert(List.of(), List.of()); } + public static LineEdit remove() { return replaceWith(List.of()); } - public static LineEdit insertBefore(String... prepend) { return insertBefore(Arrays.asList(prepend)); } - public static LineEdit insertBefore(List<String> prepend) { return insert(prepend, Collections.emptyList()); } - public static LineEdit insertAfter(String... append) { return insertAfter(Arrays.asList(append)); } - public static LineEdit insertAfter(List<String> append) { return insert(Collections.emptyList(), append); } + public static LineEdit insertBefore(String... prepend) { return insertBefore(List.of(prepend)); } + public static LineEdit insertBefore(List<String> prepend) { return insert(prepend, List.of()); } + public static LineEdit insertAfter(String... append) { return insertAfter(List.of(append)); } + public static LineEdit insertAfter(List<String> append) { return insert(List.of(), append); } public static LineEdit insert(List<String> prepend, List<String> append) { return new LineEdit(NONE, prepend, append); } - public static LineEdit replaceWith(String... lines) { return replaceWith(Arrays.asList(lines)); } - public static LineEdit replaceWith(List<String> insertLines) { return new LineEdit(REPLACE, Collections.emptyList(), insertLines); } + public static LineEdit replaceWith(String... lines) { return replaceWith(List.of(lines)); } + public static LineEdit replaceWith(List<String> insertLines) { return new LineEdit(REPLACE, List.of(), insertLines); } private final Type type; private final List<String> prependLines; @@ -36,8 +32,8 @@ public class LineEdit { private LineEdit(Type type, List<String> prependLines, List<String> appendLines) { this.type = type; - this.prependLines = ImmutableList.copyOf(prependLines); - this.appendLines = ImmutableList.copyOf(appendLines); + this.prependLines = List.copyOf(prependLines); + this.appendLines = List.copyOf(appendLines); } public Type getType() { return type; } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java index 668c2787513..268e0a5ccfd 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java @@ -19,7 +19,6 @@ import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.UserPrincipal; import java.nio.file.attribute.UserPrincipalLookupService; import java.time.Instant; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; @@ -217,7 +216,7 @@ public class UnixPath { .map(UnixPath::new) .collect(Collectors.toList()); } catch (NoSuchFileException ignored) { - return Collections.emptyList(); + return List.of(); } catch (IOException e) { throw new RuntimeException("Failed to list contents of directory " + path.toAbsolutePath(), e); } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2Impl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2Impl.java index 2854dc55af8..0c03dc7f483 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2Impl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcess2Impl.java @@ -89,7 +89,7 @@ public class ChildProcess2Impl implements ChildProcess2 { @Override public void close() { try { - if ( ! commandLine.getOutputFile().isPresent()) + if (commandLine.getOutputFile().isEmpty()) Files.delete(outputPath); } catch (Throwable t) { logger.log(LogLevel.WARNING, "Failed to delete " + outputPath, t); 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 8f39c2d257b..d86c8745ceb 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 @@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -67,7 +66,7 @@ public class CommandLine { } /** Add arguments to the command. The first argument in the first call to add() is the program. */ - public CommandLine add(String... arguments) { return add(Arrays.asList(arguments)); } + public CommandLine add(String... arguments) { return add(List.of(arguments)); } /** Add arguments to the command. The first argument in the first call to add() is the program. */ public CommandLine add(Collection<String> arguments) { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ProcessFactoryImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ProcessFactoryImpl.java index a5f8e667ff2..dbe6b984211 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ProcessFactoryImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ProcessFactoryImpl.java @@ -85,7 +85,7 @@ public class ProcessFactoryImpl implements ProcessFactory { return new ChildProcess2Impl(commandLine, process, outputFile, timer); } catch (RuntimeException | Error throwable) { try { - if ( ! commandLine.getOutputFile().isPresent()) + if (commandLine.getOutputFile().isEmpty()) Files.delete(outputFile); } catch (IOException ioException) { logger.log(LogLevel.WARNING, "Failed to delete temporary file at " + diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTester.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTester.java index 56a2b2aeca2..c7264c2fe4d 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTester.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTester.java @@ -15,7 +15,7 @@ public class SystemCtlTester extends SystemCtl { private final Set<String> runningUnits = new HashSet<>(); - private TestTerminal terminal; + private final TestTerminal terminal; public SystemCtlTester(TestTerminal terminal) { super(terminal); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumPackageName.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumPackageName.java index fb85815c70f..54c8719bceb 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumPackageName.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumPackageName.java @@ -244,10 +244,10 @@ public class YumPackageName { public boolean isSubsetOf(YumPackageName other) { return Objects.equals(name, other.name) && - (!epoch.isPresent() || Objects.equals(epoch, other.epoch)) && - (!version.isPresent() || Objects.equals(version, other.version)) && - (!release.isPresent() || Objects.equals(release, other.release)) && - (!architecture.isPresent() || Objects.equals(architecture, other.architecture)); + (epoch.isEmpty() || Objects.equals(epoch, other.epoch)) && + (version.isEmpty() || Objects.equals(version, other.version)) && + (release.isEmpty() || Objects.equals(release, other.release)) && + (architecture.isEmpty() || Objects.equals(architecture, other.architecture)); } @Override 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 0909a03749e..a11fdc903e7 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 @@ -19,9 +19,7 @@ import java.net.SocketTimeoutException; import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.Arrays; import java.util.List; -import java.util.Optional; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.arrayContainingInAnyOrder; @@ -54,7 +52,7 @@ public class ConfigServerApiImplTest { private final String uri1 = "http://host1:666"; private final String uri2 = "http://host2:666"; - private final List<URI> configServers = Arrays.asList(URI.create(uri1), URI.create(uri2)); + private final List<URI> configServers = List.of(URI.create(uri1), URI.create(uri2)); private final StringBuilder mockLog = new StringBuilder(); private ConfigServerApiImpl configServerApi; @@ -122,7 +120,7 @@ public class ConfigServerApiImplTest { params.setConnectionTimeout(Duration.ofSeconds(3)); try { - TestPojo testPojo = configServerApi.get("/path", TestPojo.class, params); + configServerApi.get("/path", TestPojo.class, params); fail(); } catch (ConnectionException e) { assertNotNull(e.getCause()); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/AclTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/AclTest.java index 3010586e708..341f2b8ca02 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/AclTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/AclTest.java @@ -5,7 +5,6 @@ import com.yahoo.vespa.hosted.node.admin.task.util.network.IPVersion; import org.junit.Test; import java.util.Arrays; -import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; @@ -20,12 +19,12 @@ public class AclTest { private static final Acl aclCommon = new Acl( Set.of(1234, 453), testNodes("192.1.2.2", "fb00::1", "fe80::2", "fe80::3"), - Collections.emptySet()); + Set.of()); private static final Acl aclWithoutPorts = new Acl( - Collections.emptySet(), + Set.of(), testNodes("192.1.2.2", "fb00::1", "fe80::2"), - Collections.emptySet()); + Set.of()); @Test public void no_trusted_ports() { @@ -80,7 +79,7 @@ public class AclTest { Acl aclCommonDifferentOrder = new Acl( Set.of(453, 1234), testNodes("fe80::2", "192.1.2.2", "fb00::1", "fe80::3"), - Collections.emptySet()); + Set.of()); for (IPVersion ipVersion: IPVersion.values()) { assertEquals(aclCommon.toRules(ipVersion), aclCommonDifferentOrder.toRules(ipVersion)); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepositoryTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepositoryTest.java index 9b392395045..4e0fd95384c 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepositoryTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepositoryTest.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.URI; import java.time.Instant; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; @@ -67,7 +66,7 @@ public class RealNodeRepositoryTest { int port = findRandomOpenPort(); container = JDisc.fromServicesXml(ContainerConfig.servicesXmlV2(port), Networking.enable); ConfigServerApi configServerApi = ConfigServerApiImpl.createForTesting( - Collections.singletonList(URI.create("http://127.0.0.1:" + port))); + List.of(URI.create("http://127.0.0.1:" + port))); waitForJdiscContainerToServe(configServerApi); return; } catch (RuntimeException e) { diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java index 936a7bb224d..d118da07247 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java @@ -8,7 +8,6 @@ import com.yahoo.vespa.orchestrator.restapi.wire.HostStateChangeDenialReason; import com.yahoo.vespa.orchestrator.restapi.wire.UpdateHostResponse; import org.junit.Test; -import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -109,7 +108,7 @@ public class OrchestratorImplTest { @Test public void testBatchSuspendCall() { String parentHostName = "host1.test.yahoo.com"; - List<String> hostNames = Arrays.asList("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); + List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); when(configServerApi.put( eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"), @@ -124,7 +123,7 @@ public class OrchestratorImplTest { @Test(expected=OrchestratorException.class) public void testBatchSuspendCallWithFailureReason() { String parentHostName = "host1.test.yahoo.com"; - List<String> hostNames = Arrays.asList("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); + List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); String failureReason = "Failed to suspend"; when(configServerApi.put( @@ -140,7 +139,7 @@ public class OrchestratorImplTest { @Test(expected=RuntimeException.class) public void testBatchSuspendCallWithSomeException() { String parentHostName = "host1.test.yahoo.com"; - List<String> hostNames = Arrays.asList("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); + List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); String exceptionMessage = "Exception: Something crashed!"; when(configServerApi.put( diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeRepoMock.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeRepoMock.java index 625166a10d2..80069b38748 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeRepoMock.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/NodeRepoMock.java @@ -8,7 +8,6 @@ import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeReposit import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeSpec; import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeState; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -46,7 +45,7 @@ public class NodeRepoMock implements NodeRepository { @Override public Map<String, Acl> getAcls(String hostname) { - return Collections.emptyMap(); + return Map.of(); } @Override 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 4a232a5b2bd..d1778982043 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 @@ -10,7 +10,7 @@ import com.yahoo.vespa.hosted.node.admin.configserver.noderepository.NodeState; import com.yahoo.vespa.hosted.node.admin.nodeadmin.NodeAdminStateUpdater; import org.junit.Test; -import java.util.Arrays; +import java.util.List; import java.util.OptionalLong; import static com.yahoo.vespa.hosted.node.admin.integrationTests.DockerTester.HOST_HOSTNAME; @@ -40,7 +40,7 @@ public class RebootTest { } catch (RuntimeException ignored) { } tester.inOrder(tester.orchestrator).suspend( - eq(HOST_HOSTNAME.value()), eq(Arrays.asList(hostname, HOST_HOSTNAME.value()))); + eq(HOST_HOSTNAME.value()), eq(List.of(hostname, HOST_HOSTNAME.value()))); tester.inOrder(tester.docker).executeInContainerAsUser( eq(new ContainerName("host1")), eq("root"), eq(OptionalLong.empty()), eq(NODE_PROGRAM), eq("stop")); assertTrue(tester.nodeAdmin.setFrozen(true)); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainerTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainerTest.java index 90674f86907..adecc370b85 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainerTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainerTest.java @@ -15,8 +15,6 @@ import org.junit.Test; import java.nio.file.FileSystem; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.function.Function; @@ -70,7 +68,7 @@ public class AclMaintainerTest { verify(dockerOperations, times(2)).executeCommandInNetworkNamespace(eq(context), eq("ip6tables-restore"), any()); verifyNoMoreInteractions(dockerOperations); - List<String> expected = Arrays.asList( + List<String> expected = List.of( // IPv4 filter table restore "*filter\n" + "-P INPUT ACCEPT\n" + @@ -137,7 +135,7 @@ public class AclMaintainerTest { verify(dockerOperations, times(1)).executeCommandInNetworkNamespace(eq(context), eq("ip6tables-restore"), any()); verifyNoMoreInteractions(dockerOperations); - List<String> expected = Arrays.asList( + List<String> expected = List.of( // IPv4 filter table restore "*filter\n" + "-P INPUT ACCEPT\n" + @@ -194,7 +192,7 @@ public class AclMaintainerTest { verify(dockerOperations, never()).executeCommandInNetworkNamespace(eq(context), eq("ip6tables-restore"), any()); //we don't have a ip4 address for the container so no redirect verifyNoMoreInteractions(dockerOperations); - List<String> expected = Collections.singletonList( + List<String> expected = List.of( "*filter\n" + "-P INPUT ACCEPT\n" + "-P FORWARD ACCEPT\n" + diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java index f72cde92839..495c1318b71 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/FilterTableLineEditorTest.java @@ -6,7 +6,8 @@ import com.yahoo.vespa.hosted.node.admin.task.util.file.Editor; import com.yahoo.vespa.hosted.node.admin.task.util.network.IPVersion; import org.junit.Test; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; import static org.junit.Assert.assertEquals; @@ -37,14 +38,48 @@ public class FilterTableLineEditorTest { "-A INPUT -j REJECT --reject-with icmp6-port-unreachable"); } + @Test + public void produces_minimal_diff_simple() { + assertFilterTableDiff(List.of(2, 5, 3, 6, 1, 4), List.of(2, 5, 6, 1, 4), + "Patching file table:\n" + + "--A INPUT -s 2001::3/128 -j ACCEPT\n"); + } + + @Test + public void produces_minimal_diff_complex() { + assertFilterTableDiff(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), List.of(5, 11, 6, 3, 10, 4, 8, 12), + "Patching file table:\n" + + "--A INPUT -s 2001::1/128 -j ACCEPT\n" + + "--A INPUT -s 2001::2/128 -j ACCEPT\n" + + "+-A INPUT -s 2001::11/128 -j ACCEPT\n" + + "+-A INPUT -s 2001::12/128 -j ACCEPT\n" + + "--A INPUT -s 2001::7/128 -j ACCEPT\n" + + "--A INPUT -s 2001::9/128 -j ACCEPT\n"); + } + private static void assertFilterTableLineEditorResult( Acl acl, IPVersion ipVersion, String currentFilterTable, String expectedRestoreFileContent) { FilterTableLineEditor filterLineEditor = FilterTableLineEditor.from(acl, ipVersion); Editor editor = new Editor( "nat-table", - () -> Arrays.asList(currentFilterTable.split("\n")), + () -> List.of(currentFilterTable.split("\n")), result -> assertEquals(expectedRestoreFileContent, String.join("\n", result)), filterLineEditor); editor.edit(m -> {}); } + + private static void assertFilterTableDiff(List<Integer> currentIpSuffix, List<Integer> wantedIpSuffix, String diff) { + Acl.Builder currentAcl = new Acl.Builder(); + currentIpSuffix.forEach(i -> currentAcl.withTrustedNode("host" + i, "2001::" + i)); + List<String> currentTable = new ArrayList<>(); + + Acl.Builder wantedAcl = new Acl.Builder(); + wantedIpSuffix.forEach(i -> wantedAcl.withTrustedNode("host" + i, "2001::" + i)); + + new Editor("table", List::of, currentTable::addAll, FilterTableLineEditor.from(currentAcl.build(), IPVersion.IPv6)) + .edit(log -> {}); + + new Editor("table", () -> currentTable, result -> {}, FilterTableLineEditor.from(wantedAcl.build(), IPVersion.IPv6)) + .edit(log -> assertEquals(diff, log)); + } }
\ No newline at end of file diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditorTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditorTest.java index 63dc69a180c..1ea3658db76 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditorTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/NatTableLineEditorTest.java @@ -4,7 +4,7 @@ package com.yahoo.vespa.hosted.node.admin.maintenance.acl; import com.yahoo.vespa.hosted.node.admin.task.util.file.Editor; import org.junit.Test; -import java.util.Arrays; +import java.util.List; import static org.junit.Assert.assertEquals; @@ -88,7 +88,7 @@ public class NatTableLineEditorTest { NatTableLineEditor natLineEditor = NatTableLineEditor.from(redirectRule); Editor editor = new Editor( "nat-table", - () -> Arrays.asList(currentNatTable.split("\n")), + () -> List.of(currentNatTable.split("\n")), result -> assertEquals(expectedNatTable, String.join("\n", result)), natLineEditor); editor.edit(m -> {}); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java index 5aeccb4ab7d..3771774c9a5 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java @@ -117,7 +117,7 @@ public class NodeAgentContextManagerTest { return new NodeAgentContextImpl.Builder("container-123.domain.tld").build(); } - private class AsyncExecutor<T> { + private static class AsyncExecutor<T> { private final Object monitor = new Object(); private final Thread thread; private volatile Optional<T> response = Optional.empty(); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/provider/DebugHandlerHelperTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/provider/DebugHandlerHelperTest.java index a930e2babff..afb0c86ba2a 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/provider/DebugHandlerHelperTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/provider/DebugHandlerHelperTest.java @@ -1,10 +1,9 @@ // 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.provider; import org.junit.Test; -import java.util.Collections; +import java.util.Map; import static org.junit.Assert.assertEquals; @@ -14,7 +13,7 @@ public class DebugHandlerHelperTest { DebugHandlerHelper helper = new DebugHandlerHelper(); helper.addConstant("constant-key", "constant-value"); - NodeAdminDebugHandler handler = () -> Collections.singletonMap("handler-value-key", "handler-value-value"); + NodeAdminDebugHandler handler = () -> Map.of("handler-value-key", "handler-value-value"); helper.addHandler("handler-key", handler); helper.addThreadSafeSupplier("supplier-key", () -> "supplier-value"); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/EditorTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/EditorTest.java index 3d492c41d0f..06cb382a5c4 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/EditorTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/EditorTest.java @@ -1,5 +1,4 @@ // 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 com.yahoo.vespa.hosted.node.admin.component.TaskContext; @@ -8,7 +7,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import java.nio.file.FileSystem; -import java.util.Collections; import java.util.List; import static org.junit.Assert.assertEquals; @@ -16,7 +14,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockingDetails; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -62,8 +59,8 @@ public class EditorTest { LineEdit.insertBefore("first"), // insert first, and keep the second line LineEdit.replaceWith("third", "fourth"), // remove eight, and replace with third and fourth instead LineEdit.none(), // Keep fifth - LineEdit.insert(Collections.singletonList("sixth"), // insert sixth before seventh - Collections.singletonList("eight"))); // add eight after seventh + LineEdit.insert(List.of("sixth"), // insert sixth before seventh + List.of("eight"))); // add eight after seventh Editor editor = new Editor(path.toPath(), lineEditor); TaskContext context = mock(TaskContext.class); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinderTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinderTest.java index 1308e4ead8c..197077159d1 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinderTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinderTest.java @@ -19,7 +19,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; import java.time.Duration; import java.time.Instant; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -157,7 +156,7 @@ public class FileFinderTest { }); return paths; } catch (NoSuchFileException e) { - return Collections.emptyList(); + return List.of(); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSnapshotTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSnapshotTest.java index 8c73d522f1d..1439517bb53 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSnapshotTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSnapshotTest.java @@ -5,7 +5,6 @@ import com.yahoo.vespa.test.file.TestFileSystem; import org.junit.Test; import java.nio.file.FileSystem; -import java.nio.file.Path; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSyncTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSyncTest.java index a141faf290b..cbf471bd611 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSyncTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileSyncTest.java @@ -11,7 +11,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertArrayEquals; @@ -71,7 +70,7 @@ public class FileSyncTest { fileData.getPermissions().ifPresent(permissions -> assertEquals(permissions, unixPath.getPermissions())); List<String> actualMods = taskContext.getSystemModificationLog(); - List<String> expectedMods = Arrays.asList(systemModificationMessages); + List<String> expectedMods = List.of(systemModificationMessages); assertEquals(expectedMods, actualMods); UnixPath unixPath = new UnixPath(path); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/MakeDirectoryTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/MakeDirectoryTest.java index b714ab539f6..c28aa6faa30 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/MakeDirectoryTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/MakeDirectoryTest.java @@ -1,5 +1,4 @@ // 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 com.yahoo.vespa.hosted.node.admin.component.TestTaskContext; @@ -10,8 +9,7 @@ import java.io.UncheckedIOException; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.NoSuchFileException; -import java.util.Arrays; -import java.util.Collections; +import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -56,11 +54,11 @@ public class MakeDirectoryTest { .withGroup(group); assertTrue(makeDirectory.converge(context)); - assertEquals(Arrays.asList(modifications), context.getSystemModificationLog()); + assertEquals(List.of(modifications), context.getSystemModificationLog()); context.clearSystemModificationLog(); assertFalse(makeDirectory.converge(context)); - assertEquals(Collections.emptyList(), context.getSystemModificationLog()); + assertEquals(List.of(), context.getSystemModificationLog()); } @Test diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLineTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLineTest.java index 7bdf9a44ec7..6dd5087e8a0 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLineTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLineTest.java @@ -6,7 +6,6 @@ import org.junit.After; import org.junit.Test; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.function.Predicate; @@ -43,7 +42,7 @@ public class CommandLineTest { assertEquals(0, result.getExitCode()); assertEquals("line1\nline2", result.getOutput()); assertEquals("line1\nline2\n\n", result.getUntrimmedOutput()); - assertEquals(Arrays.asList("line1", "line2"), result.getOutputLines()); + assertEquals(List.of("line1", "line2"), result.getOutputLines()); assertEquals(1, context.getSystemModificationLog().size()); assertEquals("Executing command: foo bar 2>&1", context.getSystemModificationLog().get(0)); |