blob: bc0fcd1d03d499dff636094daecad892e93aa7a6 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -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
rdudyalab086cf32016-08-11 00:07:45 -040017#!/usr/bin/python
18import socket
19from oslo_utils import units
20from oslo_utils import netutils
21import kafka
22import kafka_broker
23import fnmatch
24import logging
25import copy
26
27sub_info=[]
28class subinfo:
29 def __init__(self,scheme,app_id,app_ip,app_port,subscription_info,sub_info_filter,target):
30 logging.debug("* Updating subscription_info ")
31 self.scheme = scheme
32 self.app_id = app_id
33 self.ipaddress = app_ip
34 self.portno = app_port
35 self.subscription_info = subscription_info
36 self.sub_info_filter = sub_info_filter
37 self.target = target
38
39 if scheme == "kafka":
40 ''' Creating kafka publisher to send message over kafka '''
41 parse_target = netutils.urlsplit(target)
42 self.kafka_publisher = kafka_broker.KafkaBrokerPublisher(parse_target)
43 elif scheme == "udp":
44 ''' Creating UDP socket to send message over UDP '''
45 self.udp = socket.socket(socket.AF_INET, # Internet
46 socket.SOCK_DGRAM) # UDP
47 self.udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
48
49 def update_subinfo(self):
50 logging.info("* inside %s",self.update_subinfo.__name__)
51 if not sub_info:
52 logging.debug("* -----------List is EMpty -------------")
53 sub_info.append(self)
54 logging.debug("* Subscription is sucessful")
55 return "Subscription is sucessful \n"
56 for obj in sub_info:
57 if obj.app_id == self.app_id :
58 # obj.subscription_info=self.subscription_info
59 sub_info.remove(obj)
60 sub_info.append(self)
61 logging.warning("* entry already exists so overwriting this subscription \n")
62 return "entry already exists so overwriting this subscription \n"
63 sub_info.append(self)
64 return "Subscription is sucessful \n"
65
66 @staticmethod
67 def delete_subinfo(app_id):
68 logging.info("* inside %s",subinfo.delete_subinfo.__name__)
69 Flag = False
70 for obj in sub_info:
71 if obj.app_id == app_id :
72 sub_info.remove(obj)
73 Flag = True
74 logging.debug("* Un-Subscription is sucessful")
75 return "Un-Subscription is sucessful \n"
76 if not Flag :
77 err_str = "No subscription exists with app id: " + app_id + "\n"
78 logging.error("* No subscription exists with app id:%s ",app_id)
79 raise Exception (err_str)
80
81 @staticmethod
82 def print_subinfo():
83 logging.info("* inside %s",subinfo.print_subinfo.__name__)
84 for obj in sub_info:
85 logging.debug("* ------------------------------------------------")
86 logging.debug("* scheme:%s",obj.scheme)
87 logging.debug("* app_id:%s",obj.app_id)
88 logging.debug("* portno:%s",obj.portno )
89 logging.debug("* ipaddress:%s",obj.ipaddress)
90 logging.debug("* subscription_info:%s",obj.subscription_info)
91 logging.debug("* sub_info_filter:%s",obj.sub_info_filter)
92 logging.debug("* target:%s",obj.target)
93 logging.debug("* ------------------------------------------------")
94 @staticmethod
95 def get_subinfo(app_id):
96 logging.info("* inside %s",subinfo.get_subinfo.__name__)
97 Flag = False
98 for obj in sub_info:
99 if obj.app_id == app_id :
100 return obj.subscription_info,obj.target
101 return (None,None)
102
103
104 @staticmethod
105 def get_sub_list(notif_subscription_info):
106 logging.info("* inside %s",subinfo.get_sublist.__name__)
107 sub_list=[]
108 for obj in sub_info:
109 if obj.subscription_info == notif_subscription_info:
110 sub_list.append(obj)
111 return sub_list