CORD-1289 event step demo

Change-Id: If0730e95be34658a0c3e1618568c5d06165e15e1
diff --git a/xos/examples/README.md b/xos/examples/README.md
index 5e00ac6..5008de7 100644
--- a/xos/examples/README.md
+++ b/xos/examples/README.md
@@ -2,20 +2,44 @@
 
 1. Set your username and password
 
-    USERNAME=admin@opencord.org
-    PASSWORD=letmein
+```
+USERNAME=admin@opencord.org
+PASSWORD=letmein
+```
 
 2. Run the TOSCA recipe
 
-    TOSCA_URL=$(minikube service xos-tosca --url)
-    curl -H "xos-username: $USERNAME" -H "xos-password: $PASSWORD" -X POST --data-binary @SimpleExampleServiceInstance.yaml $TOSCA_URL/run
+```
+TOSCA_URL=$(minikube service xos-tosca --url)
+curl -H "xos-username: $USERNAME" -H "xos-password: $PASSWORD" -X POST --data-binary @SimpleExampleServiceInstance.yaml $TOSCA_URL/run
+```
 
 3. Wait a few seconds for the Kubernetes instances to be created.
 
 4. View the status
 
-    CHAMELEON_URL=$(minikube service xos-chameleon --url)
-    python ./show-instances.py $CHAMELEON_URL $USERNAME $PASSWORD
+```
+CHAMELEON_URL=$(minikube service xos-chameleon --url)
+python ./show-instances.py $CHAMELEON_URL $USERNAME $PASSWORD
+```
 
 5. View the web page
 Enter one of the other Kubernetes containers, any container such as one of the synchronizer containers will do, and perform a curl on the IP address obtained in step 4.
+
+6. Ensure Kafka is running
+
+```
+helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator
+helm install --name cord-kafka --set replicas=1 incubator/kafka
+```
+
+7. Send an Event to update a web page
+Enter one of the other Kubernetes containers, install the kafka library (`pip install kafka`) and execute the follow python:
+
+```
+import json
+from kafka import KafkaProducer
+producer = KafkaProducer(bootstrap_servers="cord-kafka-kafka")
+producer.send("SimpleExampleEvent", json.dumps({"service_instance": "My Simple Example Service Instance", "tenant_message": "Earth"}))
+producer.flush()
+```
diff --git a/xos/synchronizer/event_steps/simpleexampleevent.py b/xos/synchronizer/event_steps/simpleexampleevent.py
new file mode 100644
index 0000000..a0b1ec4
--- /dev/null
+++ b/xos/synchronizer/event_steps/simpleexampleevent.py
@@ -0,0 +1,45 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed 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.
+
+
+import json
+import os
+import sys
+from synchronizers.new_base.eventstep import EventStep
+from synchronizers.new_base.modelaccessor import *
+from xosconfig import Config
+from multistructlog import create_logger
+
+log = create_logger(Config().get('logging'))
+
+class SimpleExampleEventStep(EventStep):
+    topics = ["SimpleExampleEvent"]
+    technology = "kafka"
+
+    def __init__(self, *args, **kwargs):
+        super(SimpleExampleEventStep, self).__init__(*args, **kwargs)
+
+    def process_event(self, event):
+        value = json.loads(event.value)
+        service_instance_name = value["service_instance"]
+        tenant_message = value["tenant_message"]
+
+        objs = SimpleExampleServiceInstance.objects.filter(name=service_instance_name)
+        if not objs:
+            raise Exception("failed to find %s" % service_instance_name)
+
+        for obj in objs:
+            obj.tenant_message = tenant_message
+            obj.save(always_update_timestamp = True)
diff --git a/xos/synchronizer/simpleexampleservice_config.yaml b/xos/synchronizer/simpleexampleservice_config.yaml
index a43d5e4..9f80c69 100644
--- a/xos/synchronizer/simpleexampleservice_config.yaml
+++ b/xos/synchronizer/simpleexampleservice_config.yaml
@@ -30,6 +30,7 @@
   - KubernetesSecretVolumeMount
 dependency_graph: "/opt/xos/synchronizers/simpleexampleservice/model-deps"
 steps_dir: "/opt/xos/synchronizers/simpleexampleservice/steps"
+event_steps_dir: "/opt/xos/synchronizers/simpleexampleservice/event_steps"
 sys_dir: "/opt/xos/synchronizers/simpleexampleservice/sys"
 model_policies_dir: "/opt/xos/synchronizers/simpleexampleservice/model_policies"
 models_dir: "/opt/xos/synchronizers/simpleexampleservice/models"