1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from logging import log
19 from o2app import bootstrap
20 from o2common.config import config
21 # from o2common.domain import commands
22 from o2dms.domain import commands
23 from o2dms.domain import events
25 from o2common.helper import o2logging
26 logger = o2logging.get_logger(__name__)
28 r = redis.Redis(**config.get_redis_host_and_port())
32 logger.info("Redis pubsub starting")
33 bus = bootstrap.bootstrap()
34 pubsub = r.pubsub(ignore_subscribe_messages=True)
35 pubsub.subscribe("NfDeploymentStateChanged")
37 for m in pubsub.listen():
39 handle_dms_changed(m, bus)
40 except Exception as ex:
41 logger.warning("{}".format(str(ex)))
45 def handle_dms_changed(m, bus):
46 logger.info("handling %s", m)
47 channel = m['channel'].decode("UTF-8")
48 if channel == "NfDeploymentStateChanged":
50 data = json.loads(datastr)
51 logger.info('HandleNfDeploymentStateChanged with cmd:{}'.format(data))
52 cmd = commands.HandleNfDeploymentStateChanged(
53 NfDeploymentId = data['NfDeploymentId'],
54 FromState = data['FromState'],
55 ToState = data['ToState']
59 logger.info("unhandled:{}".format(channel))
62 if __name__ == "__main__":