You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@predictionio.apache.org by do...@apache.org on 2016/08/09 21:43:36 UTC

[28/52] [abbrv] incubator-predictionio git commit: Seperate util methods for import/send events batch

Seperate util methods for import/send events batch

send_events_batch makes POST request to /batch/events.json
import_events_batch imports events from file


Project: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/commit/c1ecef56
Tree: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/tree/c1ecef56
Diff: http://git-wip-us.apache.org/repos/asf/incubator-predictionio/diff/c1ecef56

Branch: refs/heads/develop
Commit: c1ecef569ebd166a1dc19696afcfc08be7880458
Parents: 92634f0
Author: Chan Lee <ch...@gmail.com>
Authored: Mon Aug 1 11:48:00 2016 -0700
Committer: Marcin Ziemi\u0144ski <zi...@gmail.com>
Committed: Wed Aug 3 14:41:19 2016 -0700

----------------------------------------------------------------------
 utils.py | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/c1ecef56/utils.py
----------------------------------------------------------------------
diff --git a/utils.py b/utils.py
index 53d4935..b93582d 100644
--- a/utils.py
+++ b/utils.py
@@ -84,14 +84,31 @@ def send_event(event, test_context, access_key):
         access_key: applications access key 
     Returns: `requests.Response`
     """
+    # TODO: Add channel param
     url = get_app_eventserver_url_json(test_context)
     return requests.post(
             url,
             params={'accessKey': access_key},
             json=event)
 
-def send_events_batch(events, test_context, appid, channel=None):
-    """ Imports events in batch with pio import
+def send_events_batch(events, test_context, access_key):
+    """ Send events in batch to the eventserver
+    Args:
+        events: a list of json-like dictionaries for events
+        test_context (obj: `TestContext`):
+        access_key: applications access key
+    Returns: `requests.Response`
+    """
+    url = 'http://{}:{}/batch/events.json'.format(
+        test_context.es_ip, test_context.es_port)
+    return requests.post(
+            url,
+            params={'accessKey': access_key},
+            json=events)
+
+
+def import_events_batch(events, test_context, appid, channel=None):
+    """ Imports events from file in batch with `pio import`
     Args:
         events: a list of json-like dictionaries for events
         test_context (obj: `TestContext`)
@@ -259,7 +276,10 @@ class AppEngine:
         return send_event(event, self.test_context, self.access_key)
 
     def send_events_batch(self, events):
-        return send_events_batch(events, self.test_context, self.id)
+        return send_events_batch(events, self.test_context, self.access_key)
+
+    def import_events_batch(self, events):
+        return import_events_batch(events, self.test_context, self.id)
 
     def get_events(self, params={}):
         return get_events(self.test_context, self.access_key, params)