summaryrefslogtreecommitdiffstats
path: root/node-admin
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@yahooinc.com>2022-09-01 20:24:59 +0200
committerValerij Fredriksen <valerijf@yahooinc.com>2022-09-01 20:39:25 +0200
commit60967a9460da95dacefc21f700c649b1c200c63b (patch)
tree17834d23de2466c849f01f61fd2a40fef113bced /node-admin
parentecc69cf2cdf7166de11d068beeb38dd5415d71c9 (diff)
Non-functional changes: Use new switch style
Diffstat (limited to 'node-admin')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/noderepository/RealNodeRepository.java72
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/container/CGroup.java14
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Editor.java11
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/CommandLine.java8
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateParser.java17
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTester.java14
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApiImplTest.java4
7 files changed, 62 insertions, 78 deletions
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/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/task/util/file/Editor.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/Editor.java
index 8fbb2d4e8e9..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()) {
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);