Scott Baker | 162516a | 2018-05-14 15:56:15 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 17 | import json |
Scott Baker | c6ed1c4 | 2019-01-29 16:57:10 -0800 | [diff] [blame] | 18 | from xossynchronizer.event_steps.eventstep import EventStep |
Scott Baker | 162516a | 2018-05-14 15:56:15 -0700 | [diff] [blame] | 19 | from xosconfig import Config |
| 20 | from multistructlog import create_logger |
| 21 | |
| 22 | log = create_logger(Config().get('logging')) |
| 23 | |
Scott Baker | 31c3c0a | 2019-04-02 11:22:41 -0700 | [diff] [blame] | 24 | |
Scott Baker | 162516a | 2018-05-14 15:56:15 -0700 | [diff] [blame] | 25 | class 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 Baker | c6ed1c4 | 2019-01-29 16:57:10 -0800 | [diff] [blame] | 37 | objs = self.model_accessor.SimpleExampleServiceInstance.objects.filter(name=service_instance_name) |
Scott Baker | 162516a | 2018-05-14 15:56:15 -0700 | [diff] [blame] | 38 | 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 Baker | 31c3c0a | 2019-04-02 11:22:41 -0700 | [diff] [blame] | 43 | obj.save(always_update_timestamp=True) |