Allow LogServlet to query based upon Filename 34/78034/5
authorEmmettCox <emmett.cox@est.tech>
Mon, 18 Feb 2019 12:24:01 +0000 (12:24 +0000)
committerEmmettCox <emmett.cox@est.tech>
Mon, 18 Feb 2019 12:24:01 +0000 (12:24 +0000)
Documentation updates for filename Query on LogServlet

Change-Id: I22036c42e202831766a7968bd434340cfcb6c2f5
Issue-ID: DMAAP-1022
Issue-ID: DMAAP-1029
Signed-off-by: EmmettCox <emmett.cox@est.tech>
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java
datarouter-prov/src/test/resources/create.sql
docs/data-router/data-router.rst

index eceab57..8a1a4ba 100644 (file)
@@ -69,7 +69,7 @@ public class LogServlet extends BaseServlet {
     private static final String FMT_1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
     private static final String FMT_2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
 \r
-    private static  boolean isfeedlog;\r
+    private boolean isfeedlog;\r
 \r
     public abstract class RowHandler {\r
         private final ServletOutputStream out;\r
@@ -281,12 +281,14 @@ public class LogServlet extends BaseServlet {
                 map.put("err", "bad type");\r
                 return map;\r
             }\r
-        } else\r
+        } else {\r
             map.put("type", "all");\r
+        }\r
         map.put("publishSQL", "");\r
         map.put("statusSQL", "");\r
         map.put("resultSQL", "");\r
         map.put("reasonSQL", "");\r
+        map.put("filenameSQL", "");\r
 \r
         s = req.getParameter("publishId");\r
         if (s != null) {\r
@@ -297,6 +299,11 @@ public class LogServlet extends BaseServlet {
             map.put("publishSQL", " AND PUBLISH_ID = '"+s+"'");\r
         }\r
 \r
+        s = req.getParameter("filename");\r
+        if (s != null) {\r
+            map.put("filenameSQL", " AND FILENAME = '"+s+"'");\r
+        }\r
+\r
         s = req.getParameter("statusCode");\r
         if (s != null) {\r
             String sql = null;\r
@@ -388,7 +395,7 @@ public class LogServlet extends BaseServlet {
         if (type.equals("all") || type.equals("pub")) {\r
             String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
                 + " AND TYPE = 'pub'"\r
-                + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL");\r
+                + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL") + map.get("filenameSQL");\r
             getRecordsForSQL(sql, rh);\r
         }\r
     }\r
index 2cde397..5e16bac 100644 (file)
@@ -68,7 +68,7 @@ public class PublishRecord extends BaseLogRecord {
         this.remoteAddr = rs.getString("REMOTE_ADDR");\r
         this.user = rs.getString("USER");\r
         this.status = rs.getInt("STATUS");\r
-        this.fileName = StringUtils.substringAfterLast(this.getRequestUri(), "/");\r
+        this.fileName = rs.getString("FILENAME");\r
     }\r
 \r
     public String getFeedFileid() {\r
index 03e3d4f..c2bccb7 100755 (executable)
@@ -43,8 +43,7 @@ import javax.persistence.Persistence;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
 import static org.powermock.api.mockito.PowerMockito.when;
 
 
@@ -60,6 +59,9 @@ public class LogServletTest extends DrServletTestBase {
     @Mock
     private HttpServletResponse response;
 
+    @Mock
+    private ServletOutputStream s;
+
     ListAppender<ILoggingEvent> listAppender;
 
     @BeforeClass
@@ -183,6 +185,38 @@ public class LogServletTest extends DrServletTestBase {
         verify(response).setStatus(eq(HttpServletResponse.SC_OK));
     }
 
+    @Test
+    public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_With_Filename_That_exists_A_STATUS_OK_Response_Is_Generated_And_Correct_Value_Returned()
+            throws Exception {
+        when(request.getParameter("type")).thenReturn("pub");
+        when(request.getPathInfo()).thenReturn("/1");
+        when(request.getParameter("publishId")).thenReturn("ID");
+        when(request.getParameter("expiryReason")).thenReturn(null);
+        when(request.getParameter("statusCode")).thenReturn("204");
+        when(request.getParameter("filename")).thenReturn("file123");
+        logServlet.doGet(request, response);
+        verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+        verify(s, times(1)).print("[");
+        verify(s, times(1)).print(matches("\n\\{\"statusCode\":204,\"publishId\":\"ID\",\"requestURI\":\"URL/file123\",\"sourceIP\":\"172.0.0.8\",\"method\":\"PUT\",\"contentType\":\"application/vnd.dmaap-dr.log-list; version=1.0\",\"endpointId\":\"user\",\"type\":\"pub\",\"date\":\"2050-05-14T1[6-7]:46:04.422Z\",\"contentLength\":100,\"fileName\":\"file123\"}"));
+        verify(s, times(1)).print("[");
+    }
+
+    @Test
+    public void Given_Request_Is_GetPublishRecordsForFeed_And_Type_Is_Publish_With_Filename_That_Doesnt_exist_A_STATUS_OK_Response_Is_Generated_And_Empty_Array_Returned()
+            throws Exception {
+        when(request.getParameter("type")).thenReturn("pub");
+        when(request.getPathInfo()).thenReturn("/1");
+        when(request.getParameter("publishId")).thenReturn("ID");
+        when(request.getParameter("expiryReason")).thenReturn(null);
+        when(request.getParameter("statusCode")).thenReturn("204");
+        when(request.getParameter("filename")).thenReturn("file456");
+        logServlet.doGet(request, response);
+        verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+        verify(s, times(1)).print("[");
+        verify(s, times(0)).print(matches("\n\\{\"statusCode\":204,\"publishId\":\"ID\",\"requestURI\":\"URL/file123\",\"sourceIP\":\"172.0.0.8\",\"method\":\"PUT\",\"contentType\":\"application/vnd.dmaap-dr.log-list; version=1.0\",\"endpointId\":\"user\",\"type\":\"pub\",\"date\":\"2050-05-14T1[6-7]:46:04.422Z\",\"contentLength\":100,\"fileName\":\"file123\"}"));
+        verify(s, times(1)).print("[");
+    }
+
     @Test
     public void Given_Request_Is_getDeliveryRecordsForFeed_And_Type_Is_Delivery_A_STATUS_OK_Response_Is_Generated()
             throws Exception {
@@ -232,9 +266,9 @@ public class LogServletTest extends DrServletTestBase {
         when(request.getParameter("publishId")).thenReturn("bad_PublishID");
         when(request.getParameter("statusCode")).thenReturn("-1");
         when(request.getParameter("expiryReason")).thenReturn("other");
-        when(request.getParameter("start")).thenReturn(null);
-        when(request.getParameter("end")).thenReturn(null);
-        ServletOutputStream s = mock(ServletOutputStream.class);
+        when(request.getParameter("start")).thenReturn("2536159564422");
+        when(request.getParameter("end")).thenReturn("2536159564422");
+        s = mock(ServletOutputStream.class);
         when(response.getOutputStream()).thenReturn(s);
     }
 }
\ No newline at end of file
index fa7402a..d29e589 100755 (executable)
@@ -169,8 +169,8 @@ VALUES (2,1,'user',null,2);
 insert into NODESETS(SETID, NODEID)
 VALUES (2,2);
 
-insert into LOG_RECORDS(RECORD_ID,TYPE,EVENT_TIME,PUBLISH_ID,FEEDID,REQURI,METHOD,CONTENT_TYPE,CONTENT_LENGTH,FEED_FILEID,REMOTE_ADDR,USER,STATUS,DELIVERY_SUBID,DELIVERY_FILEID,RESULT,ATTEMPTS,REASON)
-VALUES(1,'pub',2536159564422,'ID',1,'URL','GET','application/vnd.dmaap-dr.log-list; version=1.0',100,1,'172.0.0.8','user',204,1,1,204,0,'other');
+insert into LOG_RECORDS(RECORD_ID,TYPE,EVENT_TIME,PUBLISH_ID,FEEDID,REQURI,METHOD,CONTENT_TYPE,CONTENT_LENGTH,FEED_FILEID,REMOTE_ADDR,USER,STATUS,DELIVERY_SUBID,DELIVERY_FILEID,RESULT,ATTEMPTS,REASON,FILENAME)
+VALUES(1,'pub',2536159564422,'ID',1,'URL/file123','PUT','application/vnd.dmaap-dr.log-list; version=1.0',100,1,'172.0.0.8','user',204,1,1,204,0,'other','file123');
 
 CREATE ALIAS IF NOT EXISTS `SUBSTRING_INDEX` AS $$
     String Function(String one, String two, String three){
index 2c3e1a6..14b5181 100755 (executable)
@@ -886,7 +886,7 @@ Request parameters
 +------------------------+---------------------------------+------------------+------------+--------------+-------------+--------------------------------------+\r
 | Name                   | Description                     |  Param Type      |  Data Type |   MaxLen     |  Required   |  Valid/Example Values                |\r
 +========================+=================================+==================+============+==============+=============+======================================+\r
-| feedId                 | Id of the feed you want         |     Path         |   String   |              |     N       | 1                                    |\r
+| feedId                 | Id of the feed you want         |     Path         |   String   |              |     Y       | 1                                    |\r
 |                        | logs for                        |                  |            |              |             |                                      |\r
 +------------------------+---------------------------------+------------------+------------+--------------+-------------+--------------------------------------+\r
 | type                   | Select records of the           |     Path         |   String   |              |     N       | * pub: Publish attempt               |\r
@@ -914,6 +914,9 @@ Request parameters
 | expiryReason           | Select records with the         |     Path         |   String   |              |     N       |                                      |\r
 |                        | specified expiry reason         |                  |            |              |             |                                      |\r
 +------------------------+---------------------------------+------------------+------------+--------------+-------------+--------------------------------------+\r
+| filename               | Select published records with   |     Path         |   String   |              |     N       |                                      |\r
+|                        | the specified filename          |                  |            |              |             |                                      |\r
++------------------------+---------------------------------+------------------+------------+--------------+-------------+--------------------------------------+\r
 \r
 Response Parameters\r
 ===================\r
@@ -975,6 +978,8 @@ Response Parameters
 | attempts               | Total number of attempts made before         |\r
 |                        | delivery attempts were discontinued          |\r
 +------------------------+----------------------------------------------+\r
+| filename               | File name associated with a publish record   |\r
++------------------------+----------------------------------------------+\r
 \r
 Response/Error Codes\r
 ====================\r