From 115b9e1575c666354276bf9bbc6d06fbea54ea2a Mon Sep 17 00:00:00 2001 From: Valerij Fredriksen Date: Mon, 26 Apr 2021 13:17:17 +0200 Subject: Expose notification level in API --- .../hosted/controller/notification/Notification.java | 17 +++++++++++++++-- .../restapi/application/ApplicationApiHandler.java | 11 ++++++++++- .../responses/notifications-tenant1-app2.json | 3 ++- .../application/responses/notifications-tenant1.json | 4 +++- 4 files changed, 30 insertions(+), 5 deletions(-) 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 7a4052367c6..299ef3ef50d 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 @@ -50,12 +50,25 @@ public class Notification { '}'; } + public enum Level { + warning, error; + } + public enum Type { /** Warnings about usage of deprecated features in application package */ - APPLICATION_PACKAGE_WARNING, + APPLICATION_PACKAGE_WARNING(Level.warning), /** Failure to deploy application package */ - DEPLOYMENT_FAILURE + DEPLOYMENT_FAILURE(Level.error); + + private final Level level; + Type(Level level) { + this.level = level; + } + + public Level level() { + return level; + } } } 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 e5ec3f324ad..9a358f63293 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 @@ -496,6 +496,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { private static void toSlime(Cursor cursor, Notification notification) { cursor.setLong("at", notification.at().toEpochMilli()); + cursor.setString("level", notificatioLevelAsString(notification.type().level())); cursor.setString("type", notificationTypeAsString(notification.type())); Cursor messagesArray = cursor.setArray("messages"); notification.messages().forEach(messagesArray::addString); @@ -507,7 +508,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { cursor.setString("region", zoneId.region().value()); }); notification.source().clusterId().ifPresent(clusterId -> cursor.setString("clusterId", clusterId.value())); - notification.source().jobType().ifPresent(jobType -> cursor.setString("jobType", jobType.jobName())); + notification.source().jobType().ifPresent(jobType -> cursor.setString("jobName", jobType.jobName())); notification.source().runNumber().ifPresent(runNumber -> cursor.setLong("runNumber", runNumber)); } @@ -519,6 +520,14 @@ public class ApplicationApiHandler extends LoggingRequestHandler { } } + private static String notificatioLevelAsString(Notification.Level level) { + switch (level) { + case warning: return "warning"; + case error: return "error"; + default: throw new IllegalArgumentException("No serialization defined for notification level " + level); + } + } + private HttpResponse applications(String tenantName, Optional applicationName, HttpRequest request) { TenantName tenant = TenantName.from(tenantName); if (controller.tenants().get(tenantName).isEmpty()) diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1-app2.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1-app2.json index 7f583a7d803..ab8262e26bd 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1-app2.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1-app2.json @@ -2,13 +2,14 @@ "notifications": [ { "at": "(ignore)", + "level": "error", "type": "DEPLOYMENT_FAILURE", "messages": [ "Failed to deploy: Out of capacity" ], "application": "app2", "instance": "instance1", - "jobType": "system-test", + "jobName": "system-test", "runNumber": 12 } ] diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1.json index 0ed8e9201a0..2b2c03bb75a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/notifications-tenant1.json @@ -2,6 +2,7 @@ "notifications": [ { "at": "(ignore)", + "level": "warning", "type": "APPLICATION_PACKAGE_WARNING", "messages": [ "Something something deprecated..." @@ -10,13 +11,14 @@ }, { "at": "(ignore)", + "level": "error", "type": "DEPLOYMENT_FAILURE", "messages": [ "Failed to deploy: Out of capacity" ], "application": "app2", "instance": "instance1", - "jobType": "system-test", + "jobName": "system-test", "runNumber": 12 } ] -- cgit v1.2.3