added simplified pattern
parent
031fc0aa26
commit
403d1e2471
|
|
@ -17,7 +17,7 @@ class KROption(Flag):
|
||||||
RESOLVESERVICES = auto()
|
RESOLVESERVICES = auto()
|
||||||
|
|
||||||
class KRParser:
|
class KRParser:
|
||||||
patterns=[patterns.Pattern1(), patterns.Pattern2(), patterns.Pattern3(), patterns.Pattern5(), patterns.Pattern4() ]
|
patterns=[patterns.Pattern1(), patterns.Pattern2(), patterns.Pattern3(), patterns.Pattern5(), patterns.Pattern4(), patterns.Pattern5()]
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
def normalize(self,x):
|
def normalize(self,x):
|
||||||
|
|
@ -191,7 +191,7 @@ class KRParser:
|
||||||
tmp_methods=self.getKeyRequestsByServices(group["services"])
|
tmp_methods=self.getKeyRequestsByServices(group["services"])
|
||||||
|
|
||||||
for m in tmp_methods:
|
for m in tmp_methods:
|
||||||
tmp=merge({"displayName": None,"comparer": "entityId", "entityId":m["entityId"], "groupId":gid, "hasData":{}, "services":[], "found":False, "foundCount":0, "exception":""},self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
tmp=merge({"displayName": None,"comparer": "entityId", "entityId":m["entityId"], "groupId":gid, "hasData":{}, "count":{},"services":[], "found":False, "foundCount":0, "exception":""},self.config["extendResultObjects"]) #"exists":None, 'hasData_1W':None,
|
||||||
kr.keyRequests.append(tmp)
|
kr.keyRequests.append(tmp)
|
||||||
|
|
||||||
for method in group["methods"]:
|
for method in group["methods"]:
|
||||||
|
|
@ -258,8 +258,9 @@ class KRParser:
|
||||||
executor.submit(self.parseBySLO, slo)
|
executor.submit(self.parseBySLO, slo)
|
||||||
|
|
||||||
elif type(input) == dict:
|
elif type(input) == dict:
|
||||||
self.pbar = tqdm(total=1, desc=self.name)
|
#self.pbar = tqdm(total=1, desc=self.name)
|
||||||
executor.submit(self.parseBySLO, row)
|
#executor.submit(self.parseBySLO, slo)
|
||||||
|
self.parseBySLO(input)
|
||||||
|
|
||||||
|
|
||||||
return self.krs
|
return self.krs
|
||||||
|
|
|
||||||
|
|
@ -81,16 +81,16 @@ class Pattern5:
|
||||||
|
|
||||||
#Endoce
|
#Endoce
|
||||||
metricExpression=re.sub(r'~([A-Z0-9\:\<\>\_\$\.\s\-\,\(\),\[\]\\\\/*]*)~', lambda m: str(urllib.parse.quote_plus(m.group(1))), metricExpression, flags=re.IGNORECASE|re.X|re.MULTILINE)
|
metricExpression=re.sub(r'~([A-Z0-9\:\<\>\_\$\.\s\-\,\(\),\[\]\\\\/*]*)~', lambda m: str(urllib.parse.quote_plus(m.group(1))), metricExpression, flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||||
result = re.findall(r"type\(\"?service_method\"?\),fromRelationship\.isServiceMethodOfService\(type\(\"?service\"?\),entityName[\.]*[in]*\(([^\)]*)\)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
result = re.findall(r"type\(\"?service_method\"?\),fromRelationship\.isServiceMethodOfService\(type\(\"?service\"?\),entityName[\.]*[in]*\(([^\)]*)\)\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||||
|
#type\(\"?service_method\"?\),fromRelationship\.isServiceMethodOfService\(type\(\"?service\"?\),entityName[\.]*[in]*\(([^\)]*)\)
|
||||||
#result = re.findall(r"type\(\"?service_method\"?\)[\s\n\r]*,[\s\n\r]*fromRelationship[\s\n\r]*\.[\s\n\r]*isServiceMethodOfService[\s\n\r]*\([\s\n\r]*type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*entityName[\s\n\r]*[\.]*[\s\n\r]*[in]*[\s\n\r]*\([\s\n\r]*([^\)]*)\)[\s\n\r]*\)[\s\n\r]*\,[\s\n\r]*entityName[\s\n\r]*[\.]*[\s\n\r]*[in]*\([\s\n\r]*([^\)]*)[\s\n\r]*\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
#result = re.findall(r"type\(\"?service_method\"?\)[\s\n\r]*,[\s\n\r]*fromRelationship[\s\n\r]*\.[\s\n\r]*isServiceMethodOfService[\s\n\r]*\([\s\n\r]*type\(\"?service\"?\)[\s\n\r]*,[\s\n\r]*entityName[\s\n\r]*[\.]*[\s\n\r]*[in]*[\s\n\r]*\([\s\n\r]*([^\)]*)\)[\s\n\r]*\)[\s\n\r]*\,[\s\n\r]*entityName[\s\n\r]*[\.]*[\s\n\r]*[in]*\([\s\n\r]*([^\)]*)[\s\n\r]*\)", metricExpression,flags=re.IGNORECASE|re.X|re.MULTILINE)
|
||||||
#services=[]
|
#services=[]
|
||||||
#methods=[]
|
#methods=[]
|
||||||
groups=[]
|
groups=[]
|
||||||
if result:
|
if result:
|
||||||
for r in result:
|
for r in result:
|
||||||
if not r:
|
services=[s.strip() for s in urllib.parse.unquote_plus(r).split(",")]
|
||||||
services=[s.strip() for s in urllib.parse.unquote_plus(r).split(",")]
|
|
||||||
#methods=[s.strip() for s in urllib.parse.unquote_plus(r[1]).split(",")]
|
#methods=[s.strip() for s in urllib.parse.unquote_plus(r[1]).split(",")]
|
||||||
groups.append({"services":services, "methods":[]})
|
groups.append({"services":services, "methods":[]})
|
||||||
#return services, methods
|
#return services, methods
|
||||||
return groups
|
return groups
|
||||||
|
|
@ -25,18 +25,11 @@ class TestStringMethods(unittest.TestCase):
|
||||||
self.env_doc = yaml.safe_load(file)
|
self.env_doc = yaml.safe_load(file)
|
||||||
|
|
||||||
|
|
||||||
def test_upper(self):
|
|
||||||
self.assertEqual('foo'.upper(), 'FOO')
|
|
||||||
|
|
||||||
def test_isupper(self):
|
|
||||||
self.assertTrue('FOO'.isupper())
|
|
||||||
self.assertFalse('Foo'.isupper())
|
|
||||||
|
|
||||||
def test_simplifySLOs(self):
|
def test_simplifySLOs(self):
|
||||||
DTURL=self.env_doc['euprod'][1]["env-url"]
|
DTURL=self.env_doc['euprod'][1]["env-url"]
|
||||||
DTTOKEN = config(self.env_doc['euprod'][2].get('env-token-name'))
|
DTTOKEN = config(self.env_doc['euprod'][2].get('env-token-name'))
|
||||||
|
|
||||||
api_url = DTURL+"/api/v2/slo/15c29ec3-71a7-3298-9e99-aad2e5bf347c"
|
api_url = DTURL+"/api/v2/slo/b2a300b5-5b1c-3ff8-8ee6-84e0ba071a90"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|
@ -45,22 +38,11 @@ class TestStringMethods(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
result=get_request(api_url, headers, {})
|
result=get_request(api_url, headers, {})
|
||||||
|
slo=result.json()
|
||||||
|
|
||||||
krp = KRParser(options=KROption.RESOLVEKEYREQUETS | KROption.VALIDATE_HASDATA | KROption.RESOLVESERVICES, config={"threads":10,"serviceLookupParams":{"fields":"tags"},"extendResultObjects":{"env":"emea"}}, DTAPIURL=DTURL, DTAPIToken=DTTOKEN)
|
krp = KRParser(options=KROption.RESOLVEKEYREQUETS | KROption.VALIDATE_HASDATA | KROption.RESOLVESERVICES, config={"threads":10,"serviceLookupParams":{"fields":"tags"},"extendResultObjects":{"env":"emea"}}, DTAPIURL=DTURL, DTAPIToken=DTTOKEN)
|
||||||
|
|
||||||
#df = pd.DataFrame.from_dict(result.json().items())
|
krp.parse(slo)
|
||||||
#for index, row in pd.DataFrame(result.json().items()).iterrows():
|
|
||||||
slo=result.json()
|
|
||||||
slo["env"]="emea"
|
|
||||||
|
|
||||||
listSlo=[slo, slo]
|
|
||||||
krp.parse(listSlo)
|
|
||||||
|
|
||||||
#krp.parseBySLO(0,slo)
|
|
||||||
#krp.parseBySLO_Threaded(0, )
|
|
||||||
|
|
||||||
#self.assertEqual(s.split(), ['hello', 'world'])
|
|
||||||
# check that s.split fails when the separator is not a strin
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Loading…
Reference in New Issue