use of org.apache.hop.workflow.ActionResult in project hop by apache.
the class WorkflowTracker method findWorkflowTracker.
/**
* Finds the WorkflowTracker for the action specified. Use this to
*
* @param actionMeta The action to search the workflow tracker for
* @return The WorkflowTracker of null if none could be found...
*/
public WorkflowTracker findWorkflowTracker(ActionMeta actionMeta) {
if (actionMeta.getName() == null) {
return null;
}
lock.readLock().lock();
try {
ListIterator<WorkflowTracker> it = workflowTrackers.listIterator(workflowTrackers.size());
while (it.hasPrevious()) {
WorkflowTracker tracker = it.previous();
ActionResult result = tracker.getActionResult();
if (result != null && actionMeta.getName().equals(result.getActionName())) {
return tracker;
}
}
} finally {
lock.readLock().unlock();
}
return null;
}
use of org.apache.hop.workflow.ActionResult in project hop by apache.
the class WorkflowTrackerTest method createTracker.
private static WorkflowTracker createTracker(String actionName) {
WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
WorkflowTracker workflowTracker = new WorkflowTracker(workflowMeta);
if (actionName != null) {
ActionResult result = mock(ActionResult.class);
when(result.getActionName()).thenReturn(actionName);
workflowTracker.setActionResult(result);
}
return workflowTracker;
}
use of org.apache.hop.workflow.ActionResult in project hop by apache.
the class ActionMail method addBacktracking.
private void addBacktracking(WorkflowTracker workflowTracker, StringBuilder messageText, int level) {
int nr = workflowTracker.nrWorkflowTrackers();
messageText.append(Const.rightPad(" ", level * 2));
messageText.append(Const.NVL(workflowTracker.getWorkflowName(), "-"));
ActionResult jer = workflowTracker.getActionResult();
if (jer != null) {
messageText.append(" : ");
if (jer.getActionName() != null) {
messageText.append(" : ");
messageText.append(jer.getActionName());
}
if (jer.getResult() != null) {
messageText.append(" : ");
messageText.append("[" + jer.getResult().toString() + "]");
}
if (jer.getReason() != null) {
messageText.append(" : ");
messageText.append(jer.getReason());
}
if (jer.getComment() != null) {
messageText.append(" : ");
messageText.append(jer.getComment());
}
if (jer.getLogDate() != null) {
messageText.append(" (");
messageText.append(XmlHandler.date2string(jer.getLogDate()));
messageText.append(')');
}
}
messageText.append(Const.CR);
for (int i = 0; i < nr; i++) {
WorkflowTracker jt = workflowTracker.getWorkflowTracker(i);
addBacktracking(jt, messageText, level + 1);
}
}
use of org.apache.hop.workflow.ActionResult in project hop by apache.
the class WorkflowLoggingExtensionPoint method logEndOfWorkflow.
private void logEndOfWorkflow(final ILogChannel log, final Session session, final NeoConnection connection, final IWorkflowEngine<WorkflowMeta> workflow) throws HopException {
log.logDetailed("Logging execution end of workflow to Neo4j connection : " + connection.getName());
final WorkflowMeta workflowMeta = workflow.getWorkflowMeta();
synchronized (session) {
session.writeTransaction((TransactionWork<Void>) transaction -> {
try {
ILogChannel channel = workflow.getLogChannel();
Result workflowResult = workflow.getResult();
String workflowLogChannelId = workflow.getLogChannelId();
String workflowLoggingText = HopLogStore.getAppender().getBuffer(workflowLogChannelId, true).toString();
Date endDate = new Date();
workflow.getExtensionDataMap().put(WORKFLOW_END_DATE, new Date());
Date startDate = (Date) workflow.getExtensionDataMap().get(WORKFLOW_START_DATE);
Map<String, Object> workflowPars = new HashMap<>();
workflowPars.put("workflowName", workflowMeta.getName());
workflowPars.put("type", EXECUTION_TYPE_WORKFLOW);
workflowPars.put("id", channel.getLogChannelId());
workflowPars.put("executionEnd", new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss").format(endDate));
workflowPars.put("durationMs", endDate.getTime() - startDate.getTime());
workflowPars.put("errors", workflowResult.getNrErrors());
workflowPars.put("linesInput", workflowResult.getNrLinesInput());
workflowPars.put("linesOutput", workflowResult.getNrLinesOutput());
workflowPars.put("linesRead", workflowResult.getNrLinesRead());
workflowPars.put("linesWritten", workflowResult.getNrLinesWritten());
workflowPars.put("linesRejected", workflowResult.getNrLinesRejected());
workflowPars.put("loggingText", workflowLoggingText);
workflowPars.put("result", workflowResult.getResult());
workflowPars.put("nrResultRows", workflowResult.getRows().size());
workflowPars.put("nrResultFiles", workflowResult.getResultFilesList().size());
StringBuilder execCypher = new StringBuilder();
execCypher.append("MERGE (e:Execution { name : $workflowName, type : $type, id : $id } ) ");
execCypher.append("SET ");
execCypher.append(" e.executionEnd = $executionEnd ");
execCypher.append(", e.durationMs = $durationMs ");
execCypher.append(", e.errors = $errors ");
execCypher.append(", e.linesInput = $linesInput ");
execCypher.append(", e.linesOutput = $linesOutput ");
execCypher.append(", e.linesRead = $linesRead ");
execCypher.append(", e.linesWritten = $linesWritten ");
execCypher.append(", e.linesRejected = $linesRejected ");
execCypher.append(", e.loggingText = $loggingText ");
execCypher.append(", e.result = $result ");
execCypher.append(", e.nrResultRows = $nrResultRows ");
execCypher.append(", e.nrResultFiles = $nrResultFiles ");
transaction.run(execCypher.toString(), workflowPars);
StringBuilder relCypher = new StringBuilder();
relCypher.append("MATCH (w:Workflow { name : $workflowName } ) ");
relCypher.append("MATCH (e:Execution { name : $workflowName, type : $type, id : $id } ) ");
relCypher.append("MERGE (e)-[r:EXECUTION_OF_WORKFLOW]->(w) ");
transaction.run(relCypher.toString(), workflowPars);
List<ActionResult> actionResults = workflow.getActionResults();
for (ActionResult actionResult : actionResults) {
String actionLogChannelId = actionResult.getLogChannelId();
String transformLoggingText = HopLogStore.getAppender().getBuffer(actionLogChannelId, true).toString();
Result result = actionResult.getResult();
Map<String, Object> actionPars = new HashMap<>();
actionPars.put("workflowName", workflowMeta.getName());
actionPars.put("name", actionResult.getActionName());
actionPars.put("type", EXECUTION_TYPE_ACTION);
actionPars.put("id", actionLogChannelId);
actionPars.put("workflowId", workflowLogChannelId);
actionPars.put("comment", actionResult.getComment());
actionPars.put("reason", actionResult.getReason());
actionPars.put("loggingText", transformLoggingText);
actionPars.put("errors", result.getNrErrors());
actionPars.put("linesRead", result.getNrLinesRead());
actionPars.put("linesWritten", result.getNrLinesWritten());
actionPars.put("linesInput", result.getNrLinesInput());
actionPars.put("linesOutput", result.getNrLinesOutput());
actionPars.put("linesRejected", result.getNrLinesRejected());
StringBuilder actionExecCypher = new StringBuilder();
actionExecCypher.append("MERGE (e:Execution { name : $name, type : $type, id : $id } ) ");
actionExecCypher.append("SET ");
actionExecCypher.append(" e.workflowId = $workflowId ");
actionExecCypher.append(", e.loggingText = $loggingText ");
actionExecCypher.append(", e.comment = $comment ");
actionExecCypher.append(", e.reason = $reason ");
actionExecCypher.append(", e.linesRead = $linesRead ");
actionExecCypher.append(", e.linesWritten = $linesWritten ");
actionExecCypher.append(", e.linesInput = $linesInput ");
actionExecCypher.append(", e.linesOutput = $linesOutput ");
actionExecCypher.append(", e.linesRejected = $linesRejected ");
transaction.run(actionExecCypher.toString(), actionPars);
StringBuilder actionRelCypher = new StringBuilder();
actionRelCypher.append("MATCH (a:Action { workflowName : $workflowName, name : $name } ) ");
actionRelCypher.append("MATCH (e:Execution { name : $name, type : $type, id : $id } ) ");
actionRelCypher.append("MERGE (e)-[r:EXECUTION_OF_ACTION]->(a) ");
transaction.run(actionRelCypher.toString(), actionPars);
}
transaction.commit();
} catch (Exception e) {
log.logError("Error logging workflow end", e);
transaction.rollback();
}
return null;
});
}
}
use of org.apache.hop.workflow.ActionResult in project hop by apache.
the class HopGuiWorkflowGridDelegate method addTrackerToTree.
private void addTrackerToTree(WorkflowTracker workflowTracker, TreeItem parentItem) {
try {
if (workflowTracker != null) {
TreeItem treeItem = new TreeItem(parentItem, SWT.NONE);
if (nrRow % 2 != 0) {
treeItem.setBackground(GuiResource.getInstance().getColorBlueCustomGrid());
}
nrRow++;
if (workflowTracker.nrWorkflowTrackers() > 0) {
// This is a sub-workflow: display the name at the top of the list...
treeItem.setText(0, BaseMessages.getString(PKG, "WorkflowLog.Tree.WorkflowPrefix") + workflowTracker.getWorkflowName());
// then populate the sub-actions ...
for (int i = 0; i < workflowTracker.nrWorkflowTrackers(); i++) {
addTrackerToTree(workflowTracker.getWorkflowTracker(i), treeItem);
}
} else {
ActionResult result = workflowTracker.getActionResult();
if (result != null) {
String jobEntryName = result.getActionName();
if (!Utils.isEmpty(jobEntryName)) {
treeItem.setText(0, jobEntryName);
treeItem.setText(4, Const.NVL(result.getActionFilename(), ""));
} else {
treeItem.setText(0, BaseMessages.getString(PKG, "WorkflowLog.Tree.WorkflowPrefix2") + workflowTracker.getWorkflowName());
}
String comment = result.getComment();
if (comment != null) {
treeItem.setText(1, comment);
}
Result res = result.getResult();
if (res != null) {
treeItem.setText(2, res.getResult() ? BaseMessages.getString(PKG, "WorkflowLog.Tree.Success") : BaseMessages.getString(PKG, "WorkflowLog.Tree.Failure"));
treeItem.setText(5, Long.toString(res.getEntryNr()));
if (res.getResult()) {
treeItem.setForeground(GuiResource.getInstance().getColorSuccessGreen());
} else {
treeItem.setForeground(GuiResource.getInstance().getColorRed());
}
}
String reason = result.getReason();
if (reason != null) {
treeItem.setText(3, reason);
}
Date logDate = result.getLogDate();
if (logDate != null) {
treeItem.setText(6, new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(logDate));
}
}
}
treeItem.setExpanded(true);
}
} catch (Exception e) {
workflowGraph.getLogChannel().logError(Const.getStackTracker(e));
}
}
Aggregations