Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
7.9 KiB

3 years ago
# managing the components
# -----------------------------------------------------------------------------
"""
component has to be created in relation of the application (basis.yml).
Each componente could be created mostly once, but not everytime:
* the same instance of a component is used in different contexts
* there could be exist more instances
* there could be alternatives of an instance
Each kind of instance has its component-class and for each use should be an object be created.
Each crated component-onject are documented in the parameter-file.
"""
import utils.config_tool
import utils.conn_tool
3 years ago
import basic.program
import basic.message
3 years ago
import components.component
import importlib
import copy
3 years ago
comps = {}
PARAM_NOSUBNODE = ["artifact", "components", "instance"]
def getComponents(mainfct):
3 years ago
job = basic.program.Job.getInstance()
3 years ago
verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + mainfct)
out = []
for c in comps:
job.debug(verify, "getComponents " + c + ": " + str(comps[c].conf))
print("getComponents " + c + ": " + str(comps[c].conf))
if mainfct in comps[c].conf["function"]:
out.append(c)
return out
3 years ago
class ComponentManager:
__instance = None
"""
initializes the Manager with all necessary components
"""
3 years ago
3 years ago
def __init__(self):
3 years ago
job = basic.program.Job.getInstance()
3 years ago
job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
3 years ago
self.components = {}
3 years ago
print ("init ComponentHandling "+str(self))
3 years ago
def initComponents(self):
# sets components the first time
# afterwards set components from parameter-file
3 years ago
job = basic.program.Job.getInstance()
3 years ago
anw = job.par.application
3 years ago
job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
3 years ago
if not job.conf.confs["applicationen"].get(anw):
job.m.setFatal("application " + job.par.application + " is not configured")
return
for k in job.conf.confs["applicationen"].get(anw):
3 years ago
job.m.logDebug("applicationscomponente -- " + k + ":")
3 years ago
self.createComponents(k, 0, "")
def setComponents(self):
# set components from parameter-file
3 years ago
job = basic.program.Job.getInstance()
3 years ago
job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
3 years ago
def getComponent(self, compobjname):
3 years ago
job = basic.program.Job.getInstance()
3 years ago
verify = -2 + job.getDebugLevel("job_tool")
3 years ago
job.debug(verify, "getComponents " + compobjname)
3 years ago
return comps[compobjname]
3 years ago
3 years ago
def getComponents(mainfct):
job = basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + mainfct)
out = []
for c in comps:
job.debug(verify, "getComponents " + c + ": " + str(comps[c].conf))
print("getComponents " + c + ": " + str(comps[c].conf))
if mainfct in comps[c].conf["function"]:
out.append(c)
return out
3 years ago
@staticmethod
def getInstance():
if (ComponentManager.__instance is not None):
return ComponentManager.__instance
else:
raise Exception("Klasse noch nicht initialisiert")
def createComponents(self, componentName, nr, suffix):
"""
in order to create a component it must be loaded
* knogwedge of the application - which components should be created
* technical-knowledge of the instanciated component, especially the connection, user, password
* business-knowledge of the component, especially of their interfaces resp. artifacts
:param componentName: Name of the component
:param nr:
3 years ago
:param suffix:
3 years ago
:return:
"""
3 years ago
job = basic.program.Job.getInstance()
3 years ago
verify = job.getDebugLevel("job_tool")
3 years ago
componentName = componentName.lower()
print("createComponent " + componentName)
confs = utils.config_tool.getConfig("comp", componentName)
conns = utils.conn_tool.getConnections(componentName)
print("createComponent -91- " + componentName + " : " + str(confs))
if nr > 0 and int(confs["conf"]["instance"]["count"]) > 1:
job.m.setError("for multiple callers are multiple calls not implemented ")
if nr > 0 and len(conns) == 0:
job.m.setError("for multiple calls has only one call configured")
print(confs)
print("createComponent 1 " + componentName)
print(getComponentPath(componentName))
print("createComponent 2 " + componentName)
cmodul = importlib.import_module(getComponentPath(componentName))
class_ = getattr(cmodul, getComponentClass(componentName))
readedPar = job.loadParameter()
if len(conns) == 1:
print("createComponent 3 a " + componentName)
if nr > 0 and confs["conf"]["instance"]["single"] == "n":
name = componentName + "_0" + str(nr)
else:
name = componentName
c = class_()
c.name = name
c.conf = confs["conf"]
c.conf["conn"] = conns[0]
3 years ago
c.m = basic.message.Message(basic.message.LIMIT_DEBUG, "logTime", name)
3 years ago
c.init()
print("createComponent 4 a " + componentName)
print(vars(c))
print(vars(c.m))
if readedPar is not None:
3 years ago
print("createComponent 5 a " + name + " : " + str(readedPar))
3 years ago
for k in readedPar["components"][name].keys():
c.conf[k] = readedPar["components"][name][k]
3 years ago
comps[name] = c
3 years ago
self.createComponent(c, nr, suffix)
else:
i = 1
print("createComponent 3 b " + componentName)
for cn in conns:
3 years ago
name = componentName + "_0" + str(i)
3 years ago
c = class_()
c.name = name
c.conf = confs["conf"]
c.conf["conn"] = conns[0]
3 years ago
c.m = basic.message.Message(basic.message.LIMIT_DEBUG, "logTime", name)
3 years ago
c.init()
print("createComponent 4 b " + componentName)
print(vars(c))
if readedPar is not None:
for k in readedPar["components"][name].keys():
c.conf[k] = readedPar["components"][name][k]
3 years ago
comps[name] = c
3 years ago
self.createComponent(c, i, suffix)
i = i + 1
print("createComponent 9 " + componentName)
3 years ago
print(comps)
3 years ago
def createComponent(self, comp, nr, suffix):
3 years ago
job = basic.program.Job.getInstance()
3 years ago
verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + str(comp.conf["components"]))
for c in comp.conf["components"].keys():
if c == "none":
continue
self.createComponents(c, nr, suffix)
3 years ago
3 years ago
def getComponentFolder(comp):
return comp.lower()
3 years ago
3 years ago
def getComponentModul(comp):
return comp[0:1].upper() + comp[1:].lower()
3 years ago
3 years ago
def getComponentClass(comp):
return comp[0:1].upper() + comp[1:].lower()
3 years ago
3 years ago
def getComponentPath(comp):
return "components." + getComponentFolder(comp) + "." + getComponentModul(comp)
3 years ago
3 years ago
def getComponentDict():
3 years ago
job = basic.program.Job.getInstance()
3 years ago
verify = -2 + job.getDebugLevel("job_tool")
3 years ago
job.debug(verify, "getComponents ")
out = {}
3 years ago
for c in comps:
out[comps[c].name] = {}
print("getCompDict " + comps[c].name)
for k in comps[c].confs.keys():
3 years ago
print("getCompDict " + k)
3 years ago
if isParameterSubnode(k): # "artifact" in k or "components" in k or "instance" in k:
3 years ago
print("getCompDict -b- " + k)
3 years ago
out[comps[c].name][k] = copy.deepcopy(comps[c].confs[k])
3 years ago
return out
3 years ago
3 years ago
def isParameterSubnode(key):
for k in PARAM_NOSUBNODE:
if key in k:
return False
3 years ago
return True