CLI: Add options --blame and --root-cause

This commit is contained in:
Dominik Seidel 2019-11-20 15:50:22 +01:00 committed by Eric Lippmann
parent 8ee87ec1f6
commit 1414e76d94
2 changed files with 44 additions and 0 deletions

View file

@ -75,6 +75,12 @@ class ProcessCommand extends Command
* --state-type <type> Define which state type to look at. Could be * --state-type <type> Define which state type to look at. Could be
* either soft or hard, overrides an eventually * either soft or hard, overrides an eventually
* configured default * configured default
* --blame Show problem details as a tree reduced to the
* nodes which have the same state as the business
* process
* --root-cause Used in combination with --blame. Only shows
* the path of the nodes which are responsible for
* the state of the business process
*/ */
public function checkAction() public function checkAction()
{ {
@ -110,6 +116,12 @@ class ProcessCommand extends Command
if ($this->params->shift('details')) { if ($this->params->shift('details')) {
echo $this->renderProblemTree($node->getProblemTree(), $this->params->shift('colors')); echo $this->renderProblemTree($node->getProblemTree(), $this->params->shift('colors'));
} }
if ($this->params->shift('blame')) {
echo $this->renderProblemTree(
$node->getProblemTreeBlame($this->params->shift('root-cause')),
$this->params->shift('colors')
);
}
exit($node->getState()); exit($node->getState());
} }

View file

@ -175,6 +175,38 @@ class BpNode extends Node
return $tree; return $tree;
} }
/**
* Get the problem nodes as tree reduced to the nodes which have the same state as the business process
*
* @param bool $rootCause Reduce nodes to the nodes which are responsible for the state of the business process
*
* @return array
*/
public function getProblemTreeBlame($rootCause = false)
{
$tree = [];
$nodeState = $this->getState();
if ($nodeState !== 0) {
foreach ($this->getChildren() as $child) {
$childState = $rootCause ? $child->getSortingState() : $child->getState();
if (($rootCause ? $this->getSortingState() : $nodeState) === $childState) {
$name = $child->getName();
$tree[$name] = [
'children' => [],
'node' => $child
];
if ($child instanceof BpNode) {
$tree[$name]['children'] = $child->getProblemTreeBlame($rootCause);
}
}
}
}
return $tree;
}
public function isMissing() public function isMissing()
{ {
if ($this->missing === null) { if ($this->missing === null) {