Search in sources :

Example 1 with ActionResult

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;
}
Also used : ActionResult(org.apache.hop.workflow.ActionResult)

Example 2 with ActionResult

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;
}
Also used : ActionResult(org.apache.hop.workflow.ActionResult) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Example 3 with ActionResult

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);
    }
}
Also used : ActionResult(org.apache.hop.workflow.ActionResult) WorkflowTracker(org.apache.hop.core.gui.WorkflowTracker)

Example 4 with ActionResult

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;
        });
    }
}
Also used : Session(org.neo4j.driver.Session) ActionMeta(org.apache.hop.workflow.action.ActionMeta) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IVariables(org.apache.hop.core.variables.IVariables) Date(java.util.Date) Defaults(org.apache.hop.neo4j.logging.Defaults) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ActionResult(org.apache.hop.workflow.ActionResult) TransactionWork(org.neo4j.driver.TransactionWork) Transaction(org.neo4j.driver.Transaction) NeoConnection(org.apache.hop.neo4j.shared.NeoConnection) Map(java.util.Map) LoggingCore(org.apache.hop.neo4j.logging.util.LoggingCore) IWorkflowEngine(org.apache.hop.workflow.engine.IWorkflowEngine) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta) Driver(org.neo4j.driver.Driver) ILogChannel(org.apache.hop.core.logging.ILogChannel) HopLogStore(org.apache.hop.core.logging.HopLogStore) LoggingObjectType(org.apache.hop.core.logging.LoggingObjectType) LoggingHierarchy(org.apache.hop.core.logging.LoggingHierarchy) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) List(java.util.List) Result(org.apache.hop.core.Result) IExecutionFinishedListener(org.apache.hop.pipeline.IExecutionFinishedListener) ILogChannel(org.apache.hop.core.logging.ILogChannel) Date(java.util.Date) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) ActionResult(org.apache.hop.workflow.ActionResult) Result(org.apache.hop.core.Result) ActionResult(org.apache.hop.workflow.ActionResult) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with ActionResult

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));
    }
}
Also used : ActionResult(org.apache.hop.workflow.ActionResult) TreeItem(org.eclipse.swt.widgets.TreeItem) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ActionResult(org.apache.hop.workflow.ActionResult) Result(org.apache.hop.core.Result)

Aggregations

ActionResult (org.apache.hop.workflow.ActionResult)6 Result (org.apache.hop.core.Result)3 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HopException (org.apache.hop.core.exception.HopException)1 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)1 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)1 WorkflowTracker (org.apache.hop.core.gui.WorkflowTracker)1 HopLogStore (org.apache.hop.core.logging.HopLogStore)1 ILogChannel (org.apache.hop.core.logging.ILogChannel)1 ILoggingObject (org.apache.hop.core.logging.ILoggingObject)1 LoggingHierarchy (org.apache.hop.core.logging.LoggingHierarchy)1 LoggingObjectType (org.apache.hop.core.logging.LoggingObjectType)1 IRowMeta (org.apache.hop.core.row.IRowMeta)1 RowMeta (org.apache.hop.core.row.RowMeta)1 IVariables (org.apache.hop.core.variables.IVariables)1