11.10. Testing or Debugging a Process Template

Engineering Knowledge Manager

Administration Guide | Chapter 11: Scripts and Journals |

11.9. Running Python and BeanShell Scripts From a Command Window |  | 11.11. Viewing a Script Error Log
Prev |  | Next

## 11.10. Testing or Debugging a Process Template

Admin users can write scripts to test and debug a process template. The following APIs are used to accomplish this:

    public interface ProcessObjectInterface extends ModelObjectInterface{
            public void setVariableState(Map<String, Object> variableState);
            public TaskInterface getTask(String taskName);
            public Map<String, TaskInterface> getActiveTaskMap()();
            public Map<String, Object> getVariableState();
            public void reassignTask(String relativeTaskPath, String assignee, String assignmentNote);
            public void setBreakpointTasks(List<String> taskNames);
            public void removeBreakpointTasks();
    }

    public interface TaskInterface extends ModelObjectInterface{
            public void complete();
            public String getStatus();
            public String getAssignee();
    }

    //ProcessTemplateNode
    public interface ProcessTemplateTaskInterface extends TaskInterface {
            public ProcessObjectInterface getNestedProcess();
    }

    //BatchNode
    public interface BatchTaskInterface extends TaskInterface{
            public String getJobStatus();
            public boolean isJobStopped();
            public void execute();
    }

    //Auto node
    public interface AutoTaskInterface extends TaskInterface {
            public void execute();
    }

    //Custom Dialog Node
    public interface CustomDialogTaskInterface extends TaskInterface{
            public Map<String, Object> executeMacro(String macroName);
    }

Detailed documentation of the scripting interface is provided in the EKM_HOME/api folder. You can use the scripting Command Window to input scripts for testing.

The examples below demonstrate how to use these APIs to test or debug a process template.

### Manual Task

To launch a process template, use the API shown below. You need to specify the process template path, process name and location, and required variables map.

    ########### Create Process Object using specified process template and required variables ##########
    po = ekm.executeWorkflow("/Data/Shared Data/run-simulation.pt.xml", "test-run-simulation",
    "/Processes/Process Monitor", {"Disciplines":["Flow"]})

    ########### Get all the active tasks and set variables state in process object ##########
    activeTasks = po.getActiveTaskMap()
    variableState = {"Mesh Quality":"Coarse", "Dimension 1":6.5,
    "Geometry File":ekm.getObjectByPath("/Data/Shared Data/elbow.cas"), "Dimension 2":3.0,
    "Mesh Folder":ekm.getObjectByPath("/Administration/Users/jsmith/My Data")}
    po.setVariableState(variableState)

    ########### Get specified task and complete it with current variables state ###########
    setupTask = activeTasks["Setup"]
    setupTask.complete()

### Batch Task

If a batch task is set to start automatically, it will do so if it is the first task in the process, or when the prior task has been completed. You can launch a batch task and monitor the job’s progress using code similar to that shown below.

In this snippet, the task is set to complete itself automatically (`autoComplete` is `true`).

    #########  Monitor batch task till the job and task itself gets completed #############
    batchPreProcessTask = po.getTask("Batch Pre-process")
    try:
        while ((not batchPreProcessTask.isJobStopped()) or batchPreProcessTask.getStatus() != "active"):
            batchPreProcessTask = ekm.getObjectById(batchPreProcessTask.getId())
            if batchPreProcessTask == None :
                break
    except:
        print "Batch task exceuted"

If `autoComplete` is `false`, you must explicitly mark the batch task as complete once the job is executed:

    batchPreProcessTask.complete()

If `autoStart` is `false`, you must explicitly start the execution of batch task as follows:

    batchPreProcessTask.execute()

If `autoStart` is `true`, you can specify the task as a breakpoint task. The process will not execute further until the task is manually executed, either through a script or in the Process Monitor. Breakpoints can be added as follows:

    ##########Even if autostart = true, task will not proceed#########
    breakpointTasks = list()
    breakpointTasks.append('Batch Pre-process')
    po.setBreakpointTasks(breakpointTasks)
    To remove all breakpoints, user needs to call po.removeBreakpointTasks().

### Auto Task

Usually, auto tasks start executing automatically and complete themselves. You can, however, use scripting to define a breakpoint task that allows you to review or update inputs before the task executes. You can then execute the task manually using the Execute action in the Process Monitor or through scripting.

    po = ekm.executeWorkflow("/Data/Shared Data/Sample Files/process-templates/batch-monitor.pt.xml",
    "test-batch-monitor", "/Processes/Process Monitor", {})

    breakpointTasks = list()
    breakpointTasks.append('solve')
    po.setBreakpointTasks(breakpointTasks)

    activeTasks = po.getActiveTaskMap()()
    variableState = {"caseFile":ekm.getObjectByPath("/Data/Shared Data/test.xml), "count":3,
    "outputFolder":ekm.getObjectByPath("/Data/Shared Data")}
    po.setVariableState(variableState)
    setupTask = activeTasks["setup"]
    setupTask.complete()

Once the setup task is complete, the solve task is created but will not execute automatically because it is defined as a breakpoint task. Here you can review or update the variable state before the auto task is executed. Once updated, the auto task can be executed as follows:

    solveTask = po.getTask(solve)
    solveTask.execute()

You can even complete the task without executing a macro by issuing:

    solveTask.complete()

### Custom Dialog Task

Custom dialog boxes can have buttons and links that execute macros. For example, the Next button in a wizard can take you to the next wizard screen, while command links or buttons enable you to perform actions. These macros can be run explicitly using the scripting API as follows:

    po = ekm.executeWorkflow("/Data/Shared Data/Sample Files/process-templates/custom-dialog-node-process-templates
    /test-features/test-features.pt.xml", "test-custom-dialog", "/Processes/Process Monitor", {})
    task = po.getTask("Test Custom Dialog Workflow")
    task.executeMacro("action")

You can complete the custom dialog task as follows:

    task.complete()

This will execute the completion macro specified for the last step as well.

### Process Template Task

For tasks that contain a nested process template, you can retrieve the nested process using:

    task.getNestedProcess()

Once you have access to the process, you can complete the tasks contained within it. An example of this is shown in the sample script below.

    po = ekm.executeWorkflow("/Data/Shared Data/Sample Files/process-templates/nested-process-template
    /main-process-template.pt.xml", "test-nested", "/Processes/Process Monitor", {})

    activeTasks = po.getActiveTasks()
    variableState = {"outerVariable":True}
    po.setVariableState(variableState)
    beginTask = activeTasks["Begin"]
    beginTask.complete()

    nestedWorkflowTask = po.getTask("Nested Workflow")
    nestedPO = nestedWorkflowTask.getNestedProcess()
    nestedPO.getTask("Verify Variable").complete()

### Reassignment Task

Current and/or future tasks in a process can be reassigned to other users.

In a process template that contains no nested templates, you can reassign a task using the `reassignTask` method in the `ProcessObjectInterface` API as follows:

    po.reassignTask("End", "ekmadmin", "Please check mesh for approval")

In the example above, `“End”` is the task name, and `“ekmadmin”` is the user to whom the task is being reassigned. The note `"Please check mesh for approval"` will be displayed when the task is reassigned.

If a process template has another process template nested inside of it, and you want to reassign a task that resides in the nested template, you must specify the path to the task within the sequence of tasks, as shown in the example below:

    po.reassignTask("Nested Workflow/Run Simulation/Approve Mesh", "ekmadmin", "Please check mesh for approval")

In this example, `Nested Workflow`, `Run Simulation` and `Approve Mesh` are the sequential tasks in a nested process template, and `Approve Mesh` is the task that is being reassigned.

Once a task has been reassigned, the target user must sign in to EKM and accept the task to be able to complete it. This is accomplished using the `accept` method, as shown in the example below.

    po = ekm.executeWorkflow("/Data/Shared Data/run-simulation.pt.xml", "test-run-simulation",
    "/Processes/Process Monitor", {"Disciplines":["Flow"]})
    task=po.getTask("Setup")
    po.reassignTask("Setup", "ekmadmin", "dummy note")
    ekm.login("ekmadmin")
    task.accept()

Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Prev | Up / Contents | Next

Release 18.2 - © ANSYS, Inc. All rights reserved.