aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-08-18 09:11:41 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-08-18 09:11:41 +0200
commita771eb02b360b0ea4189023a1ead1bd6f257d63b (patch)
tree8ada2abef6986d02d480e725256c98ce23af3a4a
parent8faedcf0a8393e3ccfa3f289916bf271c17302e8 (diff)
Use the new enhanced switch after Intellij advise.
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java1
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/Notification.java2
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java204
3 files changed, 96 insertions, 111 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java
index f2fbff84907..fc33830e707 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java
@@ -39,7 +39,6 @@ import com.yahoo.vespa.config.server.http.v2.response.ReindexingResponse;
import com.yahoo.vespa.config.server.tenant.Tenant;
import java.io.IOException;
-import java.io.OutputStream;
import java.net.URI;
import java.time.Duration;
import java.time.Instant;
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/Notification.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/Notification.java
index 8a363405c41..b6e18881dab 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/Notification.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/notification/Notification.java
@@ -82,7 +82,7 @@ public class Notification {
feedBlock,
/** Application cluster is reindexing document(s) */
- reindex;
+ reindex
}
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
index a4bb9034a85..ce537822f02 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
@@ -59,7 +59,6 @@ import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbi
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.api.identifiers.TenantId;
import com.yahoo.vespa.hosted.controller.api.integration.aws.TenantRoles;
-import com.yahoo.vespa.hosted.controller.api.integration.billing.Quota;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ApplicationReindexing;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Cluster;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException;
@@ -165,7 +164,6 @@ import static java.util.Map.Entry.comparingByKey;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toUnmodifiableList;
/**
* This implements the application/v4 API which is used to deploy and manage applications
@@ -202,15 +200,15 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
public HttpResponse auditAndHandle(HttpRequest request) {
try {
Path path = new Path(request.getUri());
- switch (request.getMethod()) {
- case GET: return handleGET(path, request);
- case PUT: return handlePUT(path, request);
- case POST: return handlePOST(path, request);
- case PATCH: return handlePATCH(path, request);
- case DELETE: return handleDELETE(path, request);
- case OPTIONS: return handleOPTIONS();
- default: return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported");
- }
+ return switch (request.getMethod()) {
+ case GET: yield handleGET(path, request);
+ case PUT: yield handlePUT(path, request);
+ case POST: yield handlePOST(path, request);
+ case PATCH: yield handlePATCH(path, request);
+ case DELETE: yield handleDELETE(path, request);
+ case OPTIONS: yield handleOPTIONS();
+ default: yield ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported");
+ };
}
catch (RestApiException.Forbidden e) {
return ErrorResponse.forbidden(Exceptions.toMessageString(e));
@@ -225,16 +223,12 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
return ErrorResponse.badRequest(Exceptions.toMessageString(e));
}
catch (ConfigServerException e) {
- switch (e.code()) {
- case NOT_FOUND:
- return ErrorResponse.notFoundError(Exceptions.toMessageString(e));
- case ACTIVATION_CONFLICT:
- return new ErrorResponse(CONFLICT, e.code().name(), Exceptions.toMessageString(e));
- case INTERNAL_SERVER_ERROR:
- return ErrorResponse.internalServerError(Exceptions.toMessageString(e));
- default:
- return new ErrorResponse(BAD_REQUEST, e.code().name(), Exceptions.toMessageString(e));
- }
+ return switch (e.code()) {
+ case NOT_FOUND: yield ErrorResponse.notFoundError(Exceptions.toMessageString(e));
+ case ACTIVATION_CONFLICT: yield new ErrorResponse(CONFLICT, e.code().name(), Exceptions.toMessageString(e));
+ case INTERNAL_SERVER_ERROR: yield ErrorResponse.internalServerError(Exceptions.toMessageString(e));
+ default: yield new ErrorResponse(BAD_REQUEST, e.code().name(), Exceptions.toMessageString(e));
+ };
}
catch (RuntimeException e) {
log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e);
@@ -714,19 +708,18 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static TenantContacts.Audience fromAudience(String value) {
- switch (value) {
- case "tenant": return TenantContacts.Audience.TENANT;
- case "notifications": return TenantContacts.Audience.NOTIFICATIONS;
+ return switch (value) {
+ case "tenant": yield TenantContacts.Audience.TENANT;
+ case "notifications": yield TenantContacts.Audience.NOTIFICATIONS;
default: throw new IllegalArgumentException("Unknown contact audience '" + value + "'.");
- }
+ };
}
private static String toAudience(TenantContacts.Audience audience) {
- switch (audience) {
- case TENANT: return "tenant";
- case NOTIFICATIONS: return "notifications";
- default: throw new IllegalArgumentException("Unexpected contact audience '" + audience + "'.");
- }
+ return switch (audience) {
+ case TENANT: yield "tenant";
+ case NOTIFICATIONS: yield "notifications";
+ };
}
@@ -820,18 +813,18 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
private TenantContacts updateTenantInfoContacts(Inspector insp, TenantContacts oldContacts) {
if (!insp.valid()) return oldContacts;
- List<TenantContacts.Contact> contacts = SlimeUtils.entriesStream(insp).map(inspector -> {
+ List<TenantContacts.EmailContact> contacts = SlimeUtils.entriesStream(insp).map(inspector -> {
String email = inspector.field("email").asString().trim();
List<TenantContacts.Audience> audiences = SlimeUtils.entriesStream(inspector.field("audiences"))
.map(audience -> fromAudience(audience.asString()))
- .collect(Collectors.toUnmodifiableList());
+ .toList();
if (!email.contains("@")) {
throw new IllegalArgumentException("'email' needs to be an email address");
}
return new TenantContacts.EmailContact(audiences, email);
- }).collect(toUnmodifiableList());
+ }).toList();
return new TenantContacts(contacts);
}
@@ -884,24 +877,21 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static String notificationTypeAsString(Notification.Type type) {
- switch (type) {
- case submission:
- case applicationPackage: return "applicationPackage";
- case testPackage: return "testPackage";
- case deployment: return "deployment";
- case feedBlock: return "feedBlock";
- case reindex: return "reindex";
- default: throw new IllegalArgumentException("No serialization defined for notification type " + type);
- }
+ return switch (type) {
+ case submission, applicationPackage: yield "applicationPackage";
+ case testPackage: yield "testPackage";
+ case deployment: yield "deployment";
+ case feedBlock: yield "feedBlock";
+ case reindex: yield "reindex";
+ };
}
private static String notificationLevelAsString(Notification.Level level) {
- switch (level) {
- case info: return "info";
- case warning: return "warning";
- case error: return "error";
- default: throw new IllegalArgumentException("No serialization defined for notification level " + level);
- }
+ return switch (level) {
+ case info: yield "info";
+ case warning: yield "warning";
+ case error: yield "error";
+ };
}
private HttpResponse applications(String tenantName, Optional<String> applicationName, HttpRequest request) {
@@ -1334,17 +1324,19 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static String valueOf(Node.State state) {
- switch (state) {
- case failed: return "failed";
- case parked: return "parked";
- case dirty: return "dirty";
- case ready: return "ready";
- case active: return "active";
- case inactive: return "inactive";
- case reserved: return "reserved";
- case provisioned: return "provisioned";
+ return switch (state) {
+ case failed: yield "failed";
+ case parked: yield "parked";
+ case dirty: yield "dirty";
+ case ready: yield "ready";
+ case active: yield "active";
+ case inactive: yield "inactive";
+ case reserved: yield "reserved";
+ case provisioned: yield "provisioned";
+ case breakfixed: yield "breakfixed";
+ case deprovisioned: yield "deprovisioned";
default: throw new IllegalArgumentException("Unexpected node state '" + state + "'.");
- }
+ };
}
static String valueOf(Node.ServiceState state) {
@@ -1360,31 +1352,29 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static String valueOf(Node.ClusterType type) {
- switch (type) {
- case admin: return "admin";
- case content: return "content";
- case container: return "container";
- case combined: return "combined";
- default: throw new IllegalArgumentException("Unexpected node cluster type '" + type + "'.");
- }
+ return switch (type) {
+ case admin: yield "admin";
+ case content: yield "content";
+ case container: yield "container";
+ case combined: yield "combined";
+ case unknown: throw new IllegalArgumentException("Unexpected node cluster type '" + type + "'.");
+ };
}
private static String valueOf(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 : yield "fast";
+ case slow : yield "slow";
+ case any : yield "any";
+ };
}
private static String valueOf(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 : yield "remote";
+ case local : yield "local";
+ case any : yield "any";
+ };
}
private HttpResponse logs(String tenantName, String applicationName, String instanceName, String environment, String region, Map<String, String> queryParameters) {
@@ -2146,11 +2136,11 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
List<String> clusterNames = Optional.ofNullable(request.getProperty("clusterId")).stream()
.flatMap(clusters -> Stream.of(clusters.split(",")))
.filter(cluster -> ! cluster.isBlank())
- .collect(toUnmodifiableList());
+ .toList();
List<String> documentTypes = Optional.ofNullable(request.getProperty("documentType")).stream()
.flatMap(types -> Stream.of(types.split(",")))
.filter(type -> ! type.isBlank())
- .collect(toUnmodifiableList());
+ .toList();
Double speed = request.hasProperty("speed") ? Double.parseDouble(request.getProperty("speed")) : null;
boolean indexedOnly = request.getBooleanProperty("indexedOnly");
@@ -2209,13 +2199,12 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static String toString(ApplicationReindexing.State state) {
- switch (state) {
- case PENDING: return "pending";
- case RUNNING: return "running";
- case FAILED: return "failed";
- case SUCCESSFUL: return "successful";
- default: return null;
- }
+ return switch (state) {
+ case PENDING: yield "pending";
+ case RUNNING: yield "running";
+ case FAILED: yield "failed";
+ case SUCCESSFUL: yield "successful";
+ };
}
/** Enables reindexing of an application in a zone. */
@@ -2893,12 +2882,11 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static String tenantType(Tenant tenant) {
- switch (tenant.type()) {
- case athenz: return "ATHENS";
- case cloud: return "CLOUD";
- case deleted: return "DELETED";
- default: throw new IllegalArgumentException("Unknown tenant type: " + tenant.getClass().getSimpleName());
- }
+ return switch (tenant.type()) {
+ case athenz: yield "ATHENS";
+ case cloud: yield "CLOUD";
+ case deleted: yield "DELETED";
+ };
}
private static ApplicationId appIdFromPath(Path path) {
@@ -3003,29 +2991,27 @@ public class ApplicationApiHandler extends AuditLoggingRequestHandler {
}
private static String rotationStateString(RotationState state) {
- switch (state) {
- case in: return "IN";
- case out: return "OUT";
- }
- return "UNKNOWN";
+ return switch (state) {
+ case in: yield "IN";
+ case out: yield "OUT";
+ case unknown: yield "UNKNOWN";
+ };
}
private static String endpointScopeString(Endpoint.Scope scope) {
- switch (scope) {
- case weighted: return "weighted";
- case application: return "application";
- case global: return "global";
- case zone: return "zone";
- }
- throw new IllegalArgumentException("Unknown endpoint scope " + scope);
+ return switch (scope) {
+ case weighted: yield "weighted";
+ case application: yield "application";
+ case global: yield "global";
+ case zone: yield "zone";
+ };
}
private static String routingMethodString(RoutingMethod method) {
- switch (method) {
- case exclusive: return "exclusive";
- case sharedLayer4: return "sharedLayer4";
- }
- throw new IllegalArgumentException("Unknown routing method " + method);
+ return switch (method) {
+ case exclusive: yield "exclusive";
+ case sharedLayer4: yield "sharedLayer4";
+ };
}
private static <T> T getAttribute(HttpRequest request, String attributeName, Class<T> cls) {