Repository: lens Updated Branches: refs/heads/master 70855ea8c -> 54961853f
LENS-1325 : Add tests and document passing encoded urls for query http notifications Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/54961853 Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/54961853 Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/54961853 Branch: refs/heads/master Commit: 54961853fb6762431f5e20d0af95be3bb00d2afa Parents: 70855ea Author: Puneet Gupta <puneetgu...@apache.org> Authored: Thu Oct 20 09:53:24 2016 +0530 Committer: Amareshwari Sriramadasu <amareshw...@apache.org> Committed: Thu Oct 20 09:53:24 2016 +0530 ---------------------------------------------------------------------- .../server/query/QueryEventHttpNotifier.java | 6 ++--- .../src/main/resources/lenssession-default.xml | 3 ++- .../query/TestQueryNotifictaionResource.java | 23 ++++++++++++++++++-- .../lens/server/query/TestQueryService.java | 15 ++++++++++--- src/site/apt/admin/session-config.apt | 2 +- 5 files changed, 39 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/54961853/lens-server/src/main/java/org/apache/lens/server/query/QueryEventHttpNotifier.java ---------------------------------------------------------------------- diff --git a/lens-server/src/main/java/org/apache/lens/server/query/QueryEventHttpNotifier.java b/lens-server/src/main/java/org/apache/lens/server/query/QueryEventHttpNotifier.java index 1760bec..6e7bd3b 100644 --- a/lens-server/src/main/java/org/apache/lens/server/query/QueryEventHttpNotifier.java +++ b/lens-server/src/main/java/org/apache/lens/server/query/QueryEventHttpNotifier.java @@ -146,7 +146,7 @@ public abstract class QueryEventHttpNotifier<T extends QueryEvent> extends Async queryContext.getQueryHandleString(), httpEndPoint, responseCode); } catch (LensException e) { log.error("Error while sending {} HTTP Notification for Query {} to {}", getNotificationType(), - queryContext.getQueryHandleString(), httpEndPoint, e); + queryContext.getQueryHandleString(), httpEndPoint, e); // continue to try other httpEndPoints.. } } } @@ -187,7 +187,6 @@ public abstract class QueryEventHttpNotifier<T extends QueryEvent> extends Async */ private int notifyEvent(String httpEndPoint, Map<String, Object> eventDetails, MediaType mediaType) throws LensException { - final WebTarget target = buildClient().target(httpEndPoint); FormDataMultiPart mp = new FormDataMultiPart(); for (Map.Entry<String, Object> eventDetail : eventDetails.entrySet()) { @@ -203,8 +202,9 @@ public abstract class QueryEventHttpNotifier<T extends QueryEvent> extends Async } catch (Exception e) { throw new LensException("Error while publishing Http notification", e); } + //2XX = SUCCESS - if (!(response.getStatus() >= 200 && response.getStatus() < 300)) { + if (!response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) { throw new LensException("Error while publishing Http notification. Response code " + response.getStatus()); } return response.getStatus(); http://git-wip-us.apache.org/repos/asf/lens/blob/54961853/lens-server/src/main/resources/lenssession-default.xml ---------------------------------------------------------------------- diff --git a/lens-server/src/main/resources/lenssession-default.xml b/lens-server/src/main/resources/lenssession-default.xml index b6bfa2e..9a8f9da 100644 --- a/lens-server/src/main/resources/lenssession-default.xml +++ b/lens-server/src/main/resources/lenssession-default.xml @@ -263,7 +263,8 @@ <name>lens.query.http.notification.urls</name> <value></value> <description>These are the http end points for Query http notifications. Users can specify more than one comma - separated end points for a query. If this property is not set, no http notification will be sent out by lens + separated end points for a query. Url parameter values that include special characters should be + encoded. Please note that if this property is not set, no http notification will be sent out by lens server for the query.</description> </property> http://git-wip-us.apache.org/repos/asf/lens/blob/54961853/lens-server/src/test/java/org/apache/lens/server/query/TestQueryNotifictaionResource.java ---------------------------------------------------------------------- diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryNotifictaionResource.java b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryNotifictaionResource.java index 6a57b20..da1a1c6 100644 --- a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryNotifictaionResource.java +++ b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryNotifictaionResource.java @@ -45,6 +45,10 @@ public class TestQueryNotifictaionResource { private static int failedCount = 0; @Getter private static int cancelledCount = 0; + @Getter + private static int accessTokenCount = 0; + @Getter + private static int dataCount = 0; @POST @Path("finished") @@ -53,15 +57,28 @@ public class TestQueryNotifictaionResource { public void prepareQuery( @FormDataParam("eventtype") String eventtype, @FormDataParam("eventtime") String eventtime, - @FormDataParam("query") LensQuery query) throws LensException { + @FormDataParam("query") LensQuery query, + @QueryParam("access_token") String accessToken, + @QueryParam("data") String data) throws LensException { System.out.println("@@@@ Received Finished Event for queryid: " + query.getQueryHandleString() + " queryname:" + query.getQueryName() + " user:" + query.getSubmittedUser() - + " status:" + query.getStatus() + " eventtype:" + eventtype); + + " status:" + query.getStatus() + " eventtype:" + eventtype + " access_token:" + accessToken + + " data:" + data); finishedCount++; + + if (accessToken != null && accessToken.equals("ABC123")) { + accessTokenCount++; + } + + if (data != null && data.equals("x<>yz,\"abc")) { + dataCount++; + } + Assert.assertTrue(query.getQueryName().toUpperCase().contains(query.getStatus().getStatus().name()), "query " + query.getQueryName() + " " + query.getStatus()); + if (query.getStatus().successful()) { successfulCount++; } else if (query.getStatus().failed()) { @@ -76,6 +93,8 @@ public class TestQueryNotifictaionResource { successfulCount = 0; cancelledCount = 0; failedCount = 0; + accessTokenCount = 0; + dataCount = 0; } http://git-wip-us.apache.org/repos/asf/lens/blob/54961853/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java ---------------------------------------------------------------------- diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java index 415f56f..ecbd689 100644 --- a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java +++ b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java @@ -30,6 +30,7 @@ import static org.apache.lens.server.common.RestAPITestUtil.*; import static org.testng.Assert.*; import java.io.*; +import java.net.URLEncoder; import java.sql.*; import java.util.*; @@ -1919,14 +1920,20 @@ public class TestQueryService extends LensJerseyTest { @Test(dataProvider = "mediaTypeData") - public void testFinishedNotification(MediaType mt) throws LensException, InterruptedException { + public void testFinishedNotification(MediaType mt) throws Exception { try { String query = "select ID, IDSTR, count(*) from " + TEST_TABLE + " group by ID, IDSTR"; String endpoint = getBaseUri() + "/queryapi/notifictaion/finished"; + String encodedHttpEndPoint1 = endpoint + "?access_token=" + URLEncoder.encode("ABC123", "UTF-8"); + System.out.println("encodedHttpEndPoint1 :" + encodedHttpEndPoint1); + String encodedHttpEndPoint2 = endpoint + "?access_token=" + URLEncoder.encode("ABC123", "UTF-8") + "&data=" + + URLEncoder.encode("x<>yz,\"abc", "UTF-8"); + System.out.println("encodedHttpEndPoint2 :" + encodedHttpEndPoint2); LensConf conf = new LensConf(); conf.addProperty(LensConfConstants.QUERY_HTTP_NOTIFICATION_TYPE_FINISHED, "true"); conf.addProperty(LensConfConstants.QUERY_HTTP_NOTIFICATION_MEDIATYPE, mt); - conf.addProperty(LensConfConstants.QUERY_HTTP_NOTIFICATION_URLS, endpoint + " , " + endpoint); + conf.addProperty(LensConfConstants.QUERY_HTTP_NOTIFICATION_URLS, encodedHttpEndPoint1 + " , " + + encodedHttpEndPoint2); //Test for SUCCESSFUL FINISH notification QueryHandle handle1 = queryService.executeAsync(lensSessionId, query, conf, @@ -1946,7 +1953,7 @@ public class TestQueryService extends LensJerseyTest { for (QueryHandle handle : new QueryHandle[]{handle1, handle2, handle3}) { LensQuery lensQuery = queryService.getQuery(lensSessionId, handle); while (!lensQuery.getStatus().finished()) { - Thread.sleep(1000); + Thread.sleep(100); lensQuery = queryService.getQuery(lensSessionId, handle); } assertTrue(lensQuery.getQueryName().toUpperCase().contains(lensQuery.getStatus().getStatus().name()), @@ -1959,6 +1966,8 @@ public class TestQueryService extends LensJerseyTest { assertEquals(TestQueryNotifictaionResource.getSuccessfulCount(), 2); assertEquals(TestQueryNotifictaionResource.getCancelledCount(), 2); assertEquals(TestQueryNotifictaionResource.getFailedCount(), 2); + assertEquals(TestQueryNotifictaionResource.getAccessTokenCount(), 6); + assertEquals(TestQueryNotifictaionResource.getDataCount(), 3); } finally { TestQueryNotifictaionResource.clearState(); } http://git-wip-us.apache.org/repos/asf/lens/blob/54961853/src/site/apt/admin/session-config.apt ---------------------------------------------------------------------- diff --git a/src/site/apt/admin/session-config.apt b/src/site/apt/admin/session-config.apt index c4b3c04..d480f88 100644 --- a/src/site/apt/admin/session-config.apt +++ b/src/site/apt/admin/session-config.apt @@ -64,7 +64,7 @@ Lens session configuration *--+--+---+--+ |20|lens.query.http.notification.type.FINISHED|false|Setting this property to true will enable query FINISHED notifications which includes SUCCESSFUL, FAILED and CANCELLED queries. The notification will have eventtype = "FINISHED", eventtime = long event time and query = org.apache.lens.api.query.LensQuery instance. The mediatype for eventtype and eventtime will be TEXT/PLAIN and the mediatype for query will be based on property lens.query.http.notification.mediatype. Default value of this property is false.| *--+--+---+--+ -|21|lens.query.http.notification.urls| |These are the http end points for Query http notifications. Users can specify more than one comma separated end points for a query. If this property is not set, no http notification will be sent out by lens server for the query.| +|21|lens.query.http.notification.urls| |These are the http end points for Query http notifications. Users can specify more than one comma separated end points for a query. Url parameter values that include special characters should be encoded. Please note that if this property is not set, no http notification will be sent out by lens server for the query.| *--+--+---+--+ |22|lens.query.output.charset.encoding|UTF-8|The charset encoding for formatting query result. It supports all the encodings supported by java.io.OutputStreamWriter.| *--+--+---+--+