public StepInstanceActionResponse terminate(
      String workflowId,
      long workflowInstanceId,
      String stepId,
      User user,
      Actions.StepInstanceAction action,
      boolean blocking) {
    WorkflowInstance instance =
        instanceDao.getLatestWorkflowInstanceRun(workflowId, workflowInstanceId);
    if (instance.getStatus().isTerminal()) {
      throw new MaestroInvalidStatusException(
          "Cannot manually %s the step [%s] as the workflow instance %s is in a terminal state [%s]",
          action.name(), stepId, instance.getIdentity(), instance.getStatus());
    }
    return actionDao.terminate(instance, stepId, user, action, blocking);
  }
@Test
  public void testTerminate() {
    when(instance.getStatus()).thenReturn(WorkflowInstance.Status.IN_PROGRESS);
    stepActionHandler.terminate("sample-minimal-wf", 1, "job1", user, STOP, true);
    verify(actionDao, times(1)).terminate(instance, "job1", user, STOP, true);
    when(instance.getStatus()).thenReturn(WorkflowInstance.Status.FAILED);
    AssertHelper.assertThrows(
        "Cannot manually terminate the step",
        MaestroInvalidStatusException.class,
        "Cannot manually STOP the step [job1] as the workflow instance",
        () -> stepActionHandler.terminate("sample-minimal-wf", 1, "job1", user, STOP, true));
  }