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:42 UTC

[34/52] [abbrv] incubator-predictionio git commit: Add channel param for sending events in utils.py

Add channel param for sending events in utils.py


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

Branch: refs/heads/develop
Commit: f449bdd4e551bc00e7324f13f672ce3d64c6f03a
Parents: 352eb5e
Author: Chan Lee <ch...@gmail.com>
Authored: Tue Aug 2 10:08:15 2016 -0700
Committer: Marcin Ziemi\u0144ski <zi...@gmail.com>
Committed: Wed Aug 3 14:42:06 2016 -0700

----------------------------------------------------------------------
 utils.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-predictionio/blob/f449bdd4/utils.py
----------------------------------------------------------------------
diff --git a/utils.py b/utils.py
index 8066c4b..629729e 100644
--- a/utils.py
+++ b/utils.py
@@ -76,36 +76,41 @@ def get_engine_url_json(engine_ip, engine_port):
   return 'http://{}:{}/queries.json'.format(
       engine_ip, engine_port)
 
-def send_event(event, test_context, access_key):
+def send_event(event, test_context, access_key, channel=None):
   """ Sends an event to the eventserver
   Args:
     event: json-like dictionary describing an event
     test_context (obj: `TestContext`):
     access_key: application's access key
+    channel (str): custom channel for storing event
   Returns: `requests.Response`
   """
-  # TODO: Add channel param
   url = get_app_eventserver_url_json(test_context)
+  params = { 'accessKey': access_key }
+  if channel: params['channel'] = channel
   return requests.post(
       url,
-      params={'accessKey': access_key},
+      params=params,
       json=event)
 
-def send_events_batch(events, test_context, access_key):
+def send_events_batch(events, test_context, access_key, channel=None):
   """ Send events in batch via REST to the eventserver
   Args:
     events: a list of json-like dictionaries for events
     test_context (obj: `TestContext`):
     access_key: application's access key
+    channel (str): custom channel for storing event
   Returns: `requests.Response`
   Requires: Events length must not exceed length of 50
     http://docs.prediction.io/datacollection/eventmodel/#3.-batch-events-to-the-eventserver
   """
   url = 'http://{}:{}/batch/events.json'.format(
       test_context.es_ip, test_context.es_port)
+  params = { 'accessKey': access_key }
+  if channel: params['channel'] = channel
   return requests.post(
       url,
-      params={'accessKey': access_key},
+      params=params,
       json=events)
 
 
@@ -115,7 +120,7 @@ def import_events_batch(events, test_context, appid, channel=None):
     events: a list of json-like dictionaries for events
     test_context (obj: `TestContext`)
     appid (int): application's id
-    channel (str):
+    channel (str): custom channel for storing event
   """
   # Writing events list to temporary file.
   # `pio import` requires each line of input file to be a JSON string
@@ -224,7 +229,7 @@ class AppEngine:
 
   # deletes this app from pio
   def delete(self):
-      srun('pio app delete {0} --force'.format(self.app_context.name))
+    srun('pio app delete {0} --force'.format(self.app_context.name))
 
   def build(self, sbt_extra=None, clean=False, no_asm=True):
     srun('cd {0}; pio build {1} {2} {3}'.format(