rameeshm commented on code in PR #847:
URL: https://github.com/apache/ranger/pull/847#discussion_r2849244028


##########
ranger-audit-server/ranger-audit-server-service/src/main/java/org/apache/ranger/audit/rest/AuditREST.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.audit.rest;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.reflect.TypeToken;
+import org.apache.ranger.audit.model.AuthzAuditEvent;
+import org.apache.ranger.audit.producer.AuditDestinationMgr;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Path("/audit")
+@Component
+@Scope("request")
+public class AuditREST {
+    private static final Logger LOG  = 
LoggerFactory.getLogger(AuditREST.class);
+    private              Gson   gson = new 
GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create();
+    @Autowired
+    AuditDestinationMgr auditDestinationMgr;
+
+    /**
+     * Health check endpoint
+     */
+    @GET
+    @Path("/health")
+    @Produces("application/json")
+    public Response healthCheck() {
+        LOG.debug("==> AuditREST.healthCheck()");
+        Response ret;
+        String   jsonString;
+
+        try {
+            // Check if audit destination manager is available and healthy
+            if (auditDestinationMgr != null) {
+                Map<String, Object> resp = new HashMap<>();
+                resp.put("status", "UP");
+                resp.put("service", "ranger-audit-server");
+                jsonString = buildResponse(resp);
+                ret = Response.ok()
+                        .entity(jsonString)
+                        .build();
+            } else {
+                Map<String, Object> resp = new HashMap<>();
+                resp.put("status", "DOWN");
+                resp.put("service", "ranger-audit-server");
+                resp.put("reason", "AuditDestinationMgr not available");
+                jsonString = buildResponse(resp);
+                ret = Response.status(Response.Status.SERVICE_UNAVAILABLE)
+                        .entity(jsonString)
+                        .build();
+            }
+        } catch (Exception e) {
+            LOG.error("Health check failed", e);
+            Map<String, Object> resp = new HashMap<>();
+            resp.put("status", "DOWN");
+            resp.put("service", "ranger-audit-server");
+            resp.put("reason",  e.getMessage());
+            jsonString = buildResponse(resp);
+            ret = Response.status(Response.Status.SERVICE_UNAVAILABLE)
+                    .entity(jsonString)
+                    .build();
+        }
+
+        LOG.debug("<== AuditREST.healthCheck(): {}", ret);
+
+        return ret;
+    }
+
+    /**
+     * Status endpoint for monitoring
+     */
+    @GET
+    @Path("/status")
+    @Produces("application/json")
+    public Response getStatus() {
+        LOG.debug("==> AuditREST.getStatus()");
+
+        Response ret;
+        String   jsonString;
+
+        try {
+            String status = (auditDestinationMgr != null) ? "READY" : 
"NOT_READY";
+
+            Map<String, Object> resp = new HashMap<>();
+            resp.put("status", status);
+            resp.put("timestamp", System.currentTimeMillis());
+            resp.put("service", "ranger-audit-server");
+            jsonString = buildResponse(resp);
+            ret = Response.status(Response.Status.OK)
+                    .entity(jsonString)
+                    .build();
+        } catch (Exception e) {
+            LOG.error("Status check failed", e);
+            ret = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+                    .entity("{\"status\":\"ERROR\",\"error\":\"" + 
e.getMessage() + "\"}")
+                    .build();
+        }
+
+        LOG.debug("<== AuditREST.getStatus(): {}", ret);
+
+        return ret;
+    }
+
+    /**
+     *  Access Audits producer endpoint.
+     */
+    @POST
+    @Path("/post")
+    @Consumes("application/json")
+    @Produces("application/json")
+    public Response postAudit(String accessAudits) {

Review Comment:
   @mneethiraj  GdsREST uses POJOMappingFeature and XMLRootElement annotation 
for PoJo and it has a work around class NoContentException.java - The JAX-RS 
2.0 bridge class that allows Jackson 2.x providers to work with Jersey 1.x.  
This also add some dependency in the plugin side for the annotation that is 
used. I have made that change and verified looks fine. But need to  use Jersey 
2.x + jackson 2.x would at some point for better handling of this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to