blob: b544d1aaeb28e3a313f5f058a24b07037ab8d0be [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
Scott Bakerc6ed1c42019-01-29 16:57:10 -080018from xossynchronizer.event_steps.eventstep import EventStep
Scott Baker162516a2018-05-14 15:56:15 -070019from xosconfig import Config
20from multistructlog import create_logger
21
22log = create_logger(Config().get('logging'))
23
Scott Baker31c3c0a2019-04-02 11:22:41 -070024
Scott Baker162516a2018-05-14 15:56:15 -070025class SimpleExampleEventStep(EventStep):
26 topics = ["SimpleExampleEvent"]
27 technology = "kafka"
28
29 def __init__(self, *args, **kwargs):
30 super(SimpleExampleEventStep, self).__init__(*args, **kwargs)
31
32 def process_event(self, event):
33 value = json.loads(event.value)
34 service_instance_name = value["service_instance"]
35 tenant_message = value["tenant_message"]
36
Scott Bakerc6ed1c42019-01-29 16:57:10 -080037 objs = self.model_accessor.SimpleExampleServiceInstance.objects.filter(name=service_instance_name)
Scott Baker162516a2018-05-14 15:56:15 -070038 if not objs:
39 raise Exception("failed to find %s" % service_instance_name)
40
41 for obj in objs:
42 obj.tenant_message = tenant_message
Scott Baker31c3c0a2019-04-02 11:22:41 -070043 obj.save(always_update_timestamp=True)