blob: 07374b9d0349257be74167c449d081fdbd61c344 [file] [log] [blame]
Scott Baker162516a2018-05-14 15:56:15 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17import json
18import os
19import sys
Scott Bakerc6ed1c42019-01-29 16:57:10 -080020from xossynchronizer.event_steps.eventstep import EventStep
Scott Baker162516a2018-05-14 15:56:15 -070021from xosconfig import Config
22from multistructlog import create_logger
23
24log = create_logger(Config().get('logging'))
25
26class SimpleExampleEventStep(EventStep):
27 topics = ["SimpleExampleEvent"]
28 technology = "kafka"
29
30 def __init__(self, *args, **kwargs):
31 super(SimpleExampleEventStep, self).__init__(*args, **kwargs)
32
33 def process_event(self, event):
34 value = json.loads(event.value)
35 service_instance_name = value["service_instance"]
36 tenant_message = value["tenant_message"]
37
Scott Bakerc6ed1c42019-01-29 16:57:10 -080038 objs = self.model_accessor.SimpleExampleServiceInstance.objects.filter(name=service_instance_name)
Scott Baker162516a2018-05-14 15:56:15 -070039 if not objs:
40 raise Exception("failed to find %s" % service_instance_name)
41
42 for obj in objs:
43 obj.tenant_message = tenant_message
44 obj.save(always_update_timestamp = True)