Skip to content

Commit

Permalink
Merge "Removed support for href linking - when aggregation is done in…
Browse files Browse the repository at this point in the history
… alarmgen, href linking will never work"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Apr 6, 2016
2 parents 11f2b47 + d56b559 commit 081bc46
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 72 deletions.
81 changes: 43 additions & 38 deletions src/opserver/test/test_uveserver.py
Expand Up @@ -101,23 +101,23 @@ def MakeStringList(strings):
result = AppendList(result, "element", elems)
return result

def MakeHrefList(strings):
if isinstance(strings[0],basestring):
# This is an input to the aggregation
result = MakeStringList(strings)
result['@ulink'] = "ObjectIf:mystruct"
else:
# This is a test output of the aggregation
result = {}
for elems in strings:
item = {}
item['name'] = MakeBasic("string", elems['name'])
item['href'] = MakeBasic("string", elems['href'])
if not result:
result = MakeList("struct", "LinkObj", item)
else:
result = AppendList(result, "LinkObj", item)
def MakeStringMap(inmap):
result = {}
result['@type'] = "map"
result['@aggtype'] = "union"
result['map'] = {}
result['map']['@value'] = "string"
result['map']['@size'] = str(len(inmap))
result['map']['element'] = []
keytype = None
for elem in inmap.keys():
result['map']['element'].append(elem)
result['map']['element'].append(inmap[elem])
if isinstance(elem,basestring):
keytype = 'string'
else:
keytype = 'i32'
result['map']['@key'] = keytype
return result

'''
Expand All @@ -131,7 +131,7 @@ def MakeHrefList(strings):
5: optional i32 total_acl_rules
6: optional i64 in_tpkts (aggtype="counter")
7: optional list<VnStats> in_stats (aggtype="append")
8: optional list<string> ifs (aggtype="union",ulink="ObjectIf:mystruct")
8: optional map<i32,string> mstr (aggtype="union")
'''


Expand All @@ -145,7 +145,7 @@ def MakeUVEVirtualNetwork(
total_acl_rules=None,
in_tpkts=None,
in_stats=None,
ifs=None):
mstr=None):
rsult = copy.deepcopy(istate)
if rsult is None:
rsult = {}
Expand All @@ -163,11 +163,11 @@ def MakeUVEVirtualNetwork(
result['UVEVirtualNetwork']['connected_networks'] = {}
result['UVEVirtualNetwork']['connected_networks'][source] = \
MakeStringList(connected_networks)
if ifs is not None:
if ('ifs' not in result['UVEVirtualNetwork']):
result['UVEVirtualNetwork']['ifs'] = {}
result['UVEVirtualNetwork']['ifs'][source] = \
MakeHrefList(ifs)
if mstr is not None:
if ('mstr' not in result['UVEVirtualNetwork']):
result['UVEVirtualNetwork']['mstr'] = {}
result['UVEVirtualNetwork']['mstr'][source] = \
MakeStringMap(mstr)
if total_virtual_machines is not None:
if ('total_virtual_machines' not in result['UVEVirtualNetwork']):
result['UVEVirtualNetwork']['total_virtual_machines'] = {}
Expand Down Expand Up @@ -256,8 +256,8 @@ def test_default_agg(self):
res['UVEVirtualNetwork']['total_acl_rules'][1][1]]))
logging.info(json.dumps(res, indent=4, sort_keys=True))

def test_union_agg(self):
logging.info("*** Running test_union_agg ***")
def test_list_union_agg(self):
logging.info("*** Running test_list_union_agg ***")

uvevn = MakeUVEVirtualNetwork(
None, "abc-corp:vn-00", "10.10.10.10",
Expand Down Expand Up @@ -290,29 +290,34 @@ def test_union_agg(self):
'connected_networks']["10.10.10.11"]
self.assertEqual(cn, res['UVEVirtualNetwork']['connected_networks'])

def test_href_agg(self):
logging.info("*** Running test_href_agg ***")
def test_map_union_agg(self):
logging.info("*** Running test_map_union_agg ***")

uvevn = MakeUVEVirtualNetwork(
None, "abc-corp:vn-00", "10.10.10.10",
ifs=["host1:eth0"],
mstr={2:"xxx", 3:"yyy"},
)

uvevn2 = MakeUVEVirtualNetwork(
uvevn, "abc-corp:vn-00", "10.10.10.11",
mstr={3:"xxx", 4:"yyy"},
)

pa = ParallelAggregator(uvevn, {"ObjectIf":"if"})
res = pa.aggregate("abc-corp:vn-00", True, "127.0.0.1:8081")
pa = ParallelAggregator(uvevn2)
res = pa.aggregate("abc-corp:vn-00", False)

logging.info(json.dumps(res, indent=4, sort_keys=True))

uvetest = MakeUVEVirtualNetwork(
None, "abc-corp:vn-00", "10.10.10.10",
ifs=[{"name":"host1:eth0",
"href":"127.0.0.1:8081/analytics/uves/if/host1:eth0?cfilt=mystruct"}],
None, "abc-corp:vn-00", "10.10.10.11",
mstr={"10.10.10.10:2":"xxx", "10.10.10.10:3":"yyy",\
"10.10.10.11:3":"xxx", "10.10.10.11:4":"yyy"}
)

cn = OpServerUtils.uve_attr_flatten(
uvetest["abc-corp:vn-00"]['UVEVirtualNetwork'][
"ifs"]["10.10.10.10"])
self.assertEqual(cn, res['UVEVirtualNetwork']['ifs'])
cn = uvetest["abc-corp:vn-00"]['UVEVirtualNetwork'][
'mstr']["10.10.10.11"]
self.assertEqual(sorted(cn['map']['element']),
sorted(res['UVEVirtualNetwork']['mstr']['map']['element']))

def test_sum_agg(self):
logging.info("*** Running test_sum_agg ***")
Expand Down
90 changes: 56 additions & 34 deletions src/opserver/uveserver.py
Expand Up @@ -556,7 +556,7 @@ def _is_sum(self, oattr):
return True
return False

def _is_union(self, oattr):
def _is_list_union(self, oattr):
akey = oattr.keys()[0]
if not oattr[akey]['@type'] in ["list"]:
return False
Expand All @@ -567,6 +567,17 @@ def _is_union(self, oattr):
else:
return False

def _is_map_union(self, oattr):
akey = oattr.keys()[0]
if not oattr[akey]['@type'] in ["map"]:
return False
if '@aggtype' not in oattr[akey]:
return False
if oattr[akey]['@aggtype'] in ["union"]:
return True
else:
return False

def _is_append(self, oattr):
akey = oattr.keys()[0]
if not oattr[akey]['@type'] in ["list"]:
Expand Down Expand Up @@ -604,13 +615,17 @@ def _sum_agg(self, oattr):
result['#text'] = str(count)
return result

def _union_agg(self, oattr):
def _list_union_agg(self, oattr):
akey = oattr.keys()[0]
result = copy.deepcopy(oattr[akey])
result = {}
for anno in oattr[akey].keys():
if anno[0] == "@":
result[anno] = oattr[akey][anno]
itemset = set()
sname = ParallelAggregator.get_list_name(oattr[akey])
result['list'] = {}
result['list'][sname] = []

result['list']['@type'] = oattr[akey]['list']['@type']
siz = 0
for source in oattr.keys():
if isinstance(oattr[source]['list'][sname], basestring):
Expand All @@ -625,6 +640,30 @@ def _union_agg(self, oattr):

return result

def _map_union_agg(self, oattr):
akey = oattr.keys()[0]
result = {}
for anno in oattr[akey].keys():
if anno[0] == "@":
result[anno] = oattr[akey][anno]
result['map'] = {}
result['map']['@key'] = 'string'
result['map']['@value'] = oattr[akey]['map']['@value']
result['map']['element'] = []

siz = 0
for source in oattr.keys():
for subidx in range(0,int(oattr[source]['map']['@size'])):
result['map']['element'].append(source + ":" + \
json.dumps(oattr[source]['map']['element'][subidx*2]))
result['map']['element'].append(\
oattr[source]['map']['element'][(subidx*2) + 1])
siz += 1

result['map']['@size'] = str(siz)

return result

def _append_agg(self, oattr):
akey = oattr.keys()[0]
result = copy.deepcopy(oattr[akey])
Expand Down Expand Up @@ -708,39 +747,22 @@ def aggregate(self, key, flat, base_url = None):
OpServerUtils.uve_attr_flatten(sum_res)
else:
result[typ][objattr] = sum_res
elif self._is_union(self._state[key][typ][objattr]):
union_res = self._union_agg(
elif self._is_list_union(self._state[key][typ][objattr]):
unionl_res = self._list_union_agg(
self._state[key][typ][objattr])
conv_res = None
if union_res.has_key('@ulink') and base_url and \
union_res['list']['@type'] == 'string':
uterms = union_res['@ulink'].split(":",1)

# This is the linked UVE's table name
m_table = uterms[0]

if self._rev_map.has_key(m_table):
h_table = self._rev_map[m_table]
conv_res = []
sname = ParallelAggregator.get_list_name(union_res)
for el in union_res['list'][sname]:
lobj = {}
lobj['name'] = el
lobj['href'] = base_url + '/analytics/uves/' + \
h_table + '/' + el
if len(uterms) == 2:
lobj['href'] = lobj['href'] + '?cfilt=' + uterms[1]
else:
lobj['href'] = lobj['href'] + '?flat'
conv_res.append(lobj)
if flat:
if not conv_res:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(union_res)
else:
result[typ][objattr] = conv_res
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(unionl_res)
else:
result[typ][objattr] = unionl_res
elif self._is_map_union(self._state[key][typ][objattr]):
unionm_res = self._map_union_agg(
self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(unionm_res)
else:
result[typ][objattr] = union_res
result[typ][objattr] = unionm_res
elif self._is_append(self._state[key][typ][objattr]):
result[typ][objattr] = self._append_agg(
self._state[key][typ][objattr])
Expand Down

0 comments on commit 081bc46

Please sign in to comment.