From 17093b4dc68eea59835536926c2ad2d642d334ea Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 4 Feb 2019 13:27:42 +0100 Subject: [PATCH] availability checks now return non-2XX response code if unavailable; status script adjusted; the java/target/status script now uses the consolidated /sailingserver/api/v1/status end point and returns a 200 response if and only if the RacingEventService has loaded all races it needs to load and replication reports availability. In all other cases, non-2XX codes are reported, such as 503 (not available) or 404 (not found) Change-Id: I55ca3c98de993be0e6fff8e02837d17dd54431f6 --- .../server/gateway/jaxrs/api/StatusResource.java | 9 ++++++--- .../sse/replication/impl/ReplicationServlet.java | 5 +++++ java/target/status | 13 ++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/java/com.sap.sailing.server.gateway/src/com/sap/sailing/server/gateway/jaxrs/api/StatusResource.java b/java/com.sap.sailing.server.gateway/src/com/sap/sailing/server/gateway/jaxrs/api/StatusResource.java index b05d92f7e91..92445615582 100755 --- a/java/com.sap.sailing.server.gateway/src/com/sap/sailing/server/gateway/jaxrs/api/StatusResource.java +++ b/java/com.sap.sailing.server.gateway/src/com/sap/sailing/server/gateway/jaxrs/api/StatusResource.java @@ -1,5 +1,6 @@ package com.sap.sailing.server.gateway.jaxrs.api; +import javax.servlet.http.HttpServletResponse; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -27,8 +28,10 @@ public class StatusResource extends AbstractSailingServerResource { if (replicationStatus != null) { result.put("replication", replicationStatus.toJSONObject()); } - result.put("available", service.getNumberOfTrackedRacesRestored() >= service.getNumberOfTrackedRacesToRestore() && - (replicationStatus == null || replicationStatus.isAvailable())); - return Response.ok(result.toJSONString()).header("Content-Type", MediaType.APPLICATION_JSON + ";charset=UTF-8").build(); + final boolean available = service.getNumberOfTrackedRacesRestored() >= service.getNumberOfTrackedRacesToRestore() && + (replicationStatus == null || replicationStatus.isAvailable()); + result.put("available", available); + return Response.status(available ? HttpServletResponse.SC_OK : HttpServletResponse.SC_SERVICE_UNAVAILABLE). + entity(result.toJSONString()).header("Content-Type", MediaType.APPLICATION_JSON + ";charset=UTF-8").build(); } } \ No newline at end of file diff --git a/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationServlet.java b/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationServlet.java index e2bde087a97..00270101c06 100755 --- a/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationServlet.java +++ b/java/com.sap.sse.replication/src/com/sap/sse/replication/impl/ReplicationServlet.java @@ -212,6 +212,11 @@ public class ReplicationServlet extends AbstractHttpServlet { result.put("available", status.isAvailable()); resp.setContentType("application/json;charset=UTF-8"); resp.getWriter().print(result.toJSONString()); + if (status.isAvailable()) { + resp.setStatus(HttpServletResponse.SC_OK); + } else { + resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); + } } /** diff --git a/java/target/status b/java/target/status index bb2d572dee8..e3de7e89864 100755 --- a/java/target/status +++ b/java/target/status @@ -27,15 +27,14 @@ echo "JAVA_HOME: $JAVA_HOME" echo "INSTANCE_ID: $INSTANCE_ID" echo "" -RACING_EVENT_SERVICE_AVAILABLE=$(curl http://127.0.0.1:$SERVER_PORT/sailingserver/api/v1/status 2>/dev/null | jq .available) -REPLICATION_AVAILABLE=$(curl http://127.0.0.1:$SERVER_PORT/replication/replication?action=STATUS 2>/dev/null | jq .available) -INDEX_HTML_STATUS=$(curl -I http://127.0.0.1:8888/index.html 2>/dev/null | head -n 1 | cut -d ' ' -f 2) +STATUS=$(curl -i http://127.0.0.1:$SERVER_PORT/sailingserver/api/v1/status 2>/dev/null) +RESPONSE_STATUS_CODE=$(echo $STATUS | head -n 1 | cut -d ' ' -f 2) -echo "RACING_EVENT_SERVICE_AVAILABLE: $RACING_EVENT_SERVICE_AVAILABLE" -echo "REPLICATION_AVAILABLE: $REPLICATION_AVAILABLE" -echo "INDEX_HTML_STATUS: $INDEX_HTML_STATUS" +echo "AVAILABILITY_STATUS: $RESPONSE_STATUS_CODE" +echo "AVAILABILITY_DETAILS:" +echo "$STATUS" | grep "^\{" | jq . -if [[ $RACING_EVENT_SERVICE_AVAILABLE == "true" && $REPLICATION_AVAILABLE == "true" && $INDEX_HTML_STATUS =~ 2.. ]]; then +if [[ $RESPONSE_STATUS_CODE =~ 2.. ]]; then echo "Server $SERVER_NAME is available on $SERVER_PORT" exit 0 else