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 |
| 18 | import os |
| 19 | import sys |
| 20 | from synchronizers.new_base.eventstep import EventStep |
| 21 | from synchronizers.new_base.modelaccessor import * |
| 22 | from xosconfig import Config |
| 23 | from multistructlog import create_logger |
| 24 | |
| 25 | log = create_logger(Config().get('logging')) |
| 26 | |
| 27 | class SimpleExampleEventStep(EventStep): |
| 28 | topics = ["SimpleExampleEvent"] |
| 29 | technology = "kafka" |
| 30 | |
| 31 | def __init__(self, *args, **kwargs): |
| 32 | super(SimpleExampleEventStep, self).__init__(*args, **kwargs) |
| 33 | |
| 34 | def process_event(self, event): |
| 35 | value = json.loads(event.value) |
| 36 | service_instance_name = value["service_instance"] |
| 37 | tenant_message = value["tenant_message"] |
| 38 | |
| 39 | objs = SimpleExampleServiceInstance.objects.filter(name=service_instance_name) |
| 40 | if not objs: |
| 41 | raise Exception("failed to find %s" % service_instance_name) |
| 42 | |
| 43 | for obj in objs: |
| 44 | obj.tenant_message = tenant_message |
| 45 | obj.save(always_update_timestamp = True) |