Skip to content

Commit

Permalink
HopGuiWorkflowGridDelegate does not stop timer for auto refresh when
Browse files Browse the repository at this point in the history
  • Loading branch information
nadment committed Sep 29, 2024
1 parent 6ee4b73 commit 9b3abc6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
16 changes: 11 additions & 5 deletions engine/src/main/java/org/apache/hop/workflow/Workflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ public abstract class Workflow extends Variables
IExtensionData,
IWorkflowEngine<WorkflowMeta> {
protected static final Class<?> PKG = Workflow.class;
private static final String CONST_WORKFLOW_FINISHED = "Workflow.Comment.WorkflowFinished";
private static final String CONST_REASON_STARTED = "Workflow.Reason.Started";
private static final String CONST_WORKFLOW_STARTED = "Workflow.Comment.WorkflowStarted";
private static final String CONST_WORKFLOW_FINISHED = "Workflow.Comment.WorkflowFinished";
private static final String CONST_ACTION_STARTED = "Workflow.Comment.ActionStarted";
private static final String CONST_ACTION_FINISHED = "Workflow.Comment.ActionFinished";

public static final String CONFIGURATION_IN_EXPORT_FILENAME =
"__workflow_execution_configuration__.xml";
Expand Down Expand Up @@ -129,7 +131,7 @@ public abstract class Workflow extends Variables
* Keep a list of the actions that were executed.
* org.apache.hop.core.logging.CentralLogStore.getInstance()
*/
protected WorkflowTracker workflowTracker;
protected WorkflowTracker<?> workflowTracker;

/** A flat list of results in THIS workflow, in the order of execution of actions */
protected final LinkedList<ActionResult> actionResults = new LinkedList<>();
Expand Down Expand Up @@ -293,6 +295,10 @@ public Result startExecution() {
this.log = new LogChannel(this, parentLoggingObject, isGatheringMetrics(), true);
this.logLevel = log.getLogLevel();

// Update the tracker, not always fully initialized
this.workflowTracker.setWorkflowName(workflowMeta.getName());
this.workflowTracker.setWorkflowFilename(workflowMeta.getFilename());

executionStartDate = new Date();
setStopped(false);
setFinished(false);
Expand Down Expand Up @@ -717,15 +723,15 @@ private Result executeFromStart(
new ActionResult(
null,
null,
BaseMessages.getString(PKG, CONST_WORKFLOW_STARTED),
BaseMessages.getString(PKG, CONST_ACTION_STARTED),
reason,
actionMeta.getName(),
resolve(actionMeta.getAction().getFilename()));
workflowTracker.addWorkflowTracker(new WorkflowTracker(workflowMeta, jerBefore));

ClassLoader cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(action.getClass().getClassLoader());
// Execute this entry...
// Execute this action..
IAction cloneJei = (IAction) action.clone();
cloneJei.copyFrom(this);
cloneJei.getLogChannel().setLogLevel(getLogLevel());
Expand Down Expand Up @@ -772,7 +778,7 @@ private Result executeFromStart(
new ActionResult(
newResult,
cloneJei.getLogChannel().getLogChannelId(),
BaseMessages.getString(PKG, CONST_WORKFLOW_FINISHED),
BaseMessages.getString(PKG, CONST_ACTION_FINISHED),
null,
actionMeta.getName(),
resolve(actionMeta.getAction().getFilename()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ActionCategory.Category.XML=XML
Workflow.Comment.FollowedFailure=Followed link after failure
Workflow.Comment.FollowedSuccess=Followed link after success
Workflow.Comment.FollowedUnconditional=Followed unconditional link
Workflow.Comment.ActionFinished=End of action
Workflow.Comment.ActionStarted=Start of action
Workflow.Comment.WorkflowFinished=Workflow execution finished
Workflow.Comment.WorkflowStarted=Start of workflow execution
Workflow.Log.CounldNotFindStartingPoint=Couldn''t find starting point in this workflow.
Expand All @@ -46,8 +48,8 @@ Workflow.Log.StopWorkflowExecution=Stop workflow execution
Workflow.Log.UnexpectedError=Unexpected error occurred while launching entry [{0}]
Workflow.Log.UnexpectedErrorWhileWaitingForAction=Unexpected error while waiting for action [{0}] to finish.
Workflow.Log.UniqueWorkflowName=The workflow needs a name to uniquely identify it by on the remote server.
Workflow.Reason.Finished=finished
Workflow.Reason.Started=start
Workflow.Reason.Finished=Finished
Workflow.Reason.Started=Start
Workflow.Reason.StartOfAction=Start of action
WorkflowHopMeta.Exception.UnableToLoadHopInfo=Unable to load hop metadata
WorkflowHopMeta.Exception.UnableToLoadHopInfoXML=Unable to load workflow hop info from XML node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3698,9 +3698,9 @@ public synchronized void start(WorkflowExecutionConfiguration executionConfigura
log.logBasic(BaseMessages.getString(PKG, "WorkflowLog.Log.StartingWorkflow"));
workflowThread = new Thread(() -> workflow.startExecution());
workflowThread.start();
workflowGridDelegate.previousNrItems = -1;
// Link to the new workflowTracker!
workflowGridDelegate.workflowTracker = workflow.getWorkflowTracker();

// Link to the new workflow tracker
workflowGridDelegate.setWorkflowTracker(workflow.getWorkflowTracker());

updateGui();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hop.core.gui.plugin.GuiPlugin;
import org.apache.hop.core.util.Utils;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.gui.GuiResource;
import org.apache.hop.ui.core.widget.TreeMemory;
import org.apache.hop.ui.hopgui.HopGui;
Expand Down Expand Up @@ -56,8 +57,8 @@ public class HopGuiWorkflowGridDelegate {
private CTabItem workflowGridTab;
private Tree wTree;

public WorkflowTracker workflowTracker;
public int previousNrItems;
private WorkflowTracker<?> workflowTracker;
private int previousNrItems;

private int nrRow = 0;

Expand Down Expand Up @@ -104,6 +105,7 @@ private void addControls() {
// Create the tree table...
wTree = new Tree(workflowGraph.extraViewTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
wTree.setHeaderVisible(true);
PropsUi.setLook(wTree);
TreeMemory.addTreeListener(wTree, STRING_CHEF_LOG_TREE_NAME);

TreeColumn column1 = new TreeColumn(wTree, SWT.LEFT);
Expand All @@ -124,15 +126,15 @@ private void addControls() {

TreeColumn column5 = new TreeColumn(wTree, SWT.LEFT);
column5.setText(BaseMessages.getString(PKG, "WorkflowLog.Column.Filename"));
column5.setWidth(200);
column5.setWidth(300);

TreeColumn column6 = new TreeColumn(wTree, SWT.RIGHT);
column6.setText(BaseMessages.getString(PKG, "WorkflowLog.Column.Nr"));
column6.setWidth(50);

TreeColumn column7 = new TreeColumn(wTree, SWT.RIGHT);
column7.setText(BaseMessages.getString(PKG, "WorkflowLog.Column.LogDate"));
column7.setWidth(120);
column7.setWidth(150);

FormData fdTree = new FormData();
fdTree.left = new FormAttachment(0, 0);
Expand All @@ -141,8 +143,8 @@ private void addControls() {
fdTree.bottom = new FormAttachment(100, 0);
wTree.setLayoutData(fdTree);

final Timer tim = new Timer("JobGrid: " + workflowGraph.getMeta().getName());
TimerTask timtask =
final Timer timer = new Timer("WorkflowGridAutoRefresh: " + workflowGraph.getName());
TimerTask refreshTask =
new TimerTask() {
@Override
public void run() {
Expand All @@ -162,12 +164,9 @@ public void run() {
}
}
};
tim.schedule(timtask, 10L, 2000L); // refresh every 2 seconds...
timer.schedule(refreshTask, 10L, 2000L); // refresh every 2 seconds...

workflowGraph
.workflowLogDelegate
.getWorkflowLogTab()
.addDisposeListener(disposeEvent -> tim.cancel());
wTree.addListener(SWT.Dispose, event -> timer.cancel());
}

/** Refresh the data in the tree-table... Use the data from the WorkflowTracker in the workflow */
Expand All @@ -176,7 +175,7 @@ private void refreshTreeTable() {
int nrItems = workflowTracker.getTotalNumberOfItems();

if (nrItems != previousNrItems) {
// Allow some flickering for now ;-)
wTree.setRedraw(false);
wTree.removeAll();

// Re-populate this...
Expand All @@ -193,27 +192,38 @@ private void refreshTreeTable() {
}
}
treeItem.setText(0, workflowName);
treeItem.setText(4, Const.NVL(workflowTracker.getWorfkflowFilename(), ""));

TreeMemory.getInstance()
.storeExpanded(STRING_CHEF_LOG_TREE_NAME, new String[] {workflowName}, true);

nrRow = 1;
for (int i = 0; i < workflowTracker.nrWorkflowTrackers(); i++) {
addTrackerToTree(workflowTracker.getWorkflowTracker(i), treeItem);
}
previousNrItems = nrItems;

TreeMemory.setExpandedFromMemory(wTree, STRING_CHEF_LOG_TREE_NAME);
wTree.setRedraw(true);
}
}
}

private void addTrackerToTree(WorkflowTracker workflowTracker, TreeItem parentItem) {
private void addTrackerToTree(WorkflowTracker<?> workflowTracker, TreeItem parentItem) {
try {
if (workflowTracker != null) {
TreeItem treeItem = new TreeItem(parentItem, SWT.NONE);

// Alternate color
if (nrRow % 2 != 0) {
treeItem.setBackground(GuiResource.getInstance().getColorBlueCustomGrid());
if (PropsUi.getInstance().isDarkMode()) {
treeItem.setBackground(GuiResource.getInstance().getColorDemoGray());
} else {
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(
Expand All @@ -228,9 +238,9 @@ private void addTrackerToTree(WorkflowTracker workflowTracker, TreeItem parentIt
} else {
ActionResult result = workflowTracker.getActionResult();
if (result != null) {
String jobEntryName = result.getActionName();
if (!Utils.isEmpty(jobEntryName)) {
treeItem.setText(0, jobEntryName);
String actionName = result.getActionName();
if (!Utils.isEmpty(actionName)) {
treeItem.setText(0, actionName);
treeItem.setText(4, Const.NVL(result.getActionFilename(), ""));
} else {
treeItem.setText(
Expand All @@ -251,8 +261,10 @@ private void addTrackerToTree(WorkflowTracker workflowTracker, TreeItem parentIt
: BaseMessages.getString(PKG, "WorkflowLog.Tree.Failure"));
treeItem.setText(5, Long.toString(res.getEntryNr()));
if (res.getResult()) {
treeItem.setForeground(GuiResource.getInstance().getColorSuccessGreen());
treeItem.setImage(2, GuiResource.getInstance().getImageSuccess());
treeItem.setForeground(2, GuiResource.getInstance().getColorSuccessGreen());
} else {
treeItem.setImage(2, GuiResource.getInstance().getImageFailure());
treeItem.setForeground(GuiResource.getInstance().getColorRed());
}
}
Expand All @@ -277,7 +289,10 @@ public CTabItem getWorkflowGridTab() {
return workflowGridTab;
}

public void setWorkflowTracker(WorkflowTracker workflowTracker) {
public void setWorkflowTracker(WorkflowTracker<?> workflowTracker) {
this.workflowTracker = workflowTracker;

// Reset nr of items
this.previousNrItems = -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ public boolean remove(IHopFileTypeHandler typeHandler) {
//
items.remove(tabItemHandler);
CTabItem tabItem = tabItemHandler.getTabItem();
tabItem.getControl().dispose();
tabItem.dispose();

// Also remove the keyboard shortcuts for this handler
Expand Down

0 comments on commit 9b3abc6

Please sign in to comment.