Commit a6c2b748 authored by Frédéric Escudié's avatar Frédéric Escudié
Browse files

Read only once the makeflowlog for get_workflow_status().

parent 6eef1405
......@@ -185,8 +185,9 @@ class JFlowServer (object):
"components": []}
else:
components = []
components_status = workflow.get_components_status()
for i, component in enumerate(workflow.get_components_nameid()):
status_info = workflow.get_component_status(component)
status_info = components_status[component]
try: perc_waiting = (status_info["waiting"]*100.0)/status_info["tasks"]
except: perc_waiting = 0
try: perc_running = (status_info["running"]*100.0)/status_info["tasks"]
......
......@@ -73,6 +73,9 @@ class MINIWorkflow(object):
def get_components_nameid(self):
return self.component_nameids
def get_components_status(self):
return self.compts_status
def get_component_status(self, component_nameid):
return self.compts_status[component_nameid]
......@@ -468,8 +471,9 @@ class Workflow(threading.Thread):
# By components
components_errors = ""
status = "Components Status :\n"
components_status = workflow.get_components_status()
for i, component in enumerate(workflow.get_components_nameid()):
status_info = workflow.get_component_status(component)
status_info = components_status[component]
try: perc_waiting = (status_info["waiting"]*100.0)/status_info["tasks"]
except: perc_waiting = 0
try: perc_running = (status_info["running"]*100.0)/status_info["tasks"]
......@@ -902,8 +906,15 @@ class Workflow(threading.Thread):
def get_resource(self, resource):
return self.jflow_config_reader.get_resource(resource)
def get_component_status(self, component_nameid):
status = {"time": 0.0,
def get_components_status(self):
"""
@summary: Returns the components status for all components.
@return: [dict] The components status by component name id.
"""
status = dict()
makeflows_logs = list() # Workflows with dynamic component(s) have several makeflows_logs
for cmpt_nameid in self.get_components_nameid():
status[cmpt_nameid] = {"time": 0.0,
"tasks": 0,
"waiting": 0,
"running": 0,
......@@ -911,31 +922,38 @@ class Workflow(threading.Thread):
"aborted": 0,
"completed": 0,
"failed_commands": list() }
if component_nameid not in self.reseted_components:
if cmpt_nameid not in self.reseted_components:
if self.component_nameids[cmpt_nameid] not in makeflows_logs:
makeflows_logs.append(self.component_nameids[cmpt_nameid])
for current_makeflow_log in makeflows_logs:
try:
log = MakeflowLog(self.component_nameids[component_nameid])
log = MakeflowLog(current_makeflow_log)
log.parse()
symbols = set(n.symbol for n in log.nodes if n.symbol)
if not symbols: return None
for n in log.nodes:
if not n.symbol: continue
if n.symbol.replace('"', '') == component_nameid:
status["tasks"] += 1
status["time"] += n.elapsed_time
cmpt_nameid = n.symbol.replace('"', '')
if cmpt_nameid in self.component_nameids and cmpt_nameid not in self.reseted_components:
status[cmpt_nameid]["tasks"] += 1
status[cmpt_nameid]["time"] += n.elapsed_time
if n.state == Node.WAITING:
status["waiting"] += 1
status[cmpt_nameid]["waiting"] += 1
elif n.state == Node.RUNNING:
status["running"] += 1
status[cmpt_nameid]["running"] += 1
elif n.state == Node.FAILED:
status["failed"] += 1
status["failed_commands"].append( n.command )
status[cmpt_nameid]["failed"] += 1
status[cmpt_nameid]["failed_commands"].append( n.command )
elif n.state == Node.ABORTED:
status["aborted"] += 1
status[cmpt_nameid]["aborted"] += 1
elif n.state == Node.COMPLETED:
status["completed"] += 1
status[cmpt_nameid]["completed"] += 1
except: pass
return status
def get_component_status(self, component_nameid):
return self.get_components_status()[component_nameid]
def reset_component(self, component_name):
# first reinit the step to the execution step
self.__step = 1
......@@ -951,9 +969,7 @@ class Workflow(threading.Thread):
self._serialize()
def minimize(self):
compts_status = {}
for i, component in enumerate(self.get_components_nameid()):
compts_status[component] = self.get_component_status(component)
compts_status = self.get_components_status()
return MINIWorkflow(self.id, self.name, self.description, self.get_status(), self.start_time,
self.end_time, self.metadata, self.get_components_nameid(), compts_status,
self.get_errors())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment