asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Blow (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Output From ShutdownAPIServlet; status 405 on GET
Date Thu, 01 Sep 2016 15:49:18 GMT
Michael Blow has submitted this change and it was merged.

Change subject: Output From ShutdownAPIServlet; status 405 on GET
......................................................................


Output From ShutdownAPIServlet; status 405 on GET

Change-Id: I3f1a7d707ebdcb2a6502bc06d35d7ed38121e472
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1136
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
---
M asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
1 file changed, 22 insertions(+), 10 deletions(-)

Approvals:
  Till Westmann: Looks good to me, approved
  Jenkins: Verified; No violations found; Verified



diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
index 6d8c444..dd2f799 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ShutdownAPIServlet.java
@@ -19,6 +19,8 @@
 package org.apache.asterix.api.http.servlet;
 
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Date;
 import java.util.logging.Level;
 
 import javax.servlet.ServletContext;
@@ -28,7 +30,9 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.asterix.common.config.GlobalConfig;
+import org.apache.asterix.om.util.AsterixClusterProperties;
 import org.apache.hyracks.api.client.IHyracksClientConnection;
+import org.json.JSONObject;
 
 import static org.apache.asterix.api.http.servlet.ServletConstants.HYRACKS_CONNECTION_ATTR;
 
@@ -39,23 +43,31 @@
     protected void doPost(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
 
-        response.setContentType("application/json");
-        response.setCharacterEncoding("utf-8");
-
         ServletContext context = getServletContext();
         IHyracksClientConnection hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
         Thread t = new Thread(() -> {
             try {
                 hcc.stopCluster();
             } catch (Exception e) {
-                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
+                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, "Exception stopping cluster",
e);
             }
-        });
-        t.start();
-        response.setStatus(HttpServletResponse.SC_ACCEPTED);
-    }
+        }, "Shutdown Servlet Worker");
 
-    @Override
-    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
+        response.setContentType("application/json");
+        response.setCharacterEncoding("utf-8");
+        response.setStatus(HttpServletResponse.SC_ACCEPTED);
+        JSONObject jsonObject = new JSONObject();
+        try {
+            jsonObject.put("status", "SHUTTING_DOWN");
+            jsonObject.put("date", new Date());
+            jsonObject.put("cluster" , AsterixClusterProperties.INSTANCE.getClusterStateDescription());
+
+            final PrintWriter writer = response.getWriter();
+            writer.print(jsonObject.toString(4));
+            writer.close();
+        } catch (Exception e) {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, "Exception writing response", e);
+        }
+        t.start();
     }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1136
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3f1a7d707ebdcb2a6502bc06d35d7ed38121e472
Gerrit-PatchSet: 2
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mblow@apache.org>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mblow@apache.org>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>

Mime
View raw message