alirezazamani commented on a change in pull request #1439:
URL: https://github.com/apache/helix/pull/1439#discussion_r504190529



##########
File path: helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
##########
@@ -526,6 +533,185 @@ public void enqueueJobs(final String queue, final 
List<String> jobs,
     }
   }
 
+  /**
+   * Add task to a running (IN-PROGRESS) job or a job which has not started 
yet. Timeout for this
+   * operation is the default timeout which is 5 minutes. {@link 
TaskDriver#DEFAULT_TIMEOUT}
+   * Note1: Task cannot be added if the job is in an illegal state. A job can 
accept
+   * new task if the job is in-progress or it has not started yet.
+   * Note2: The job can only be added to non-targeted jobs.
+   * Note3: The taskID for the new task should be unique. If not, this API 
throws an exception.
+   * Note4: In case of timeout exception, it is the user's responsibility to 
check whether the task
+   * has been successfully added or not.
+   * @param workflowName
+   * @param jobName
+   * @param taskConfig
+   * @throws Exception if there is an issue with the request or the operation. 
1-
+   *           IllegalArgumentException will be thrown if the inputs are 
invalid. 2- HelixException
+   *           will be thrown if the job is not in the states to accept a new 
task or if there is
+   *           any issue in updating jobConfig. 3- TimeoutException will be 
thrown if the outcome of
+   *           the task addition is unknown and cannot be verified.
+   */
+  public void addTask(String workflowName, String jobName, TaskConfig 
taskConfig) throws Exception {
+    addTask(workflowName, jobName, taskConfig, DEFAULT_TIMEOUT);
+  }
+
+  /**
+   * Add task to a running (IN-PROGRESS) job or a job which has not started yet
+   * Note1: Task cannot be added if the job is in an illegal state. A job can 
accept
+   * new task if the job is in-progress or it has not started yet.
+   * Note2: The job can only be added to non-targeted jobs.
+   * Note3: The taskID for the new task should be unique. If not, this API 
throws an exception.
+   * Note4: In case of timeout exception, it is the user's responsibility to 
check whether the task
+   * has been successfully added or not.
+   * Note5: timeout is the time that this API checks whether the task has been 
successfully added or
+   * not.
+   * @param workflowName
+   * @param jobName
+   * @param taskConfig
+   * @param timeoutMs
+   * @throws Exception if there is an issue with the request or the operation. 
1-
+   *           IllegalArgumentException will be thrown if the inputs are 
invalid. 2- HelixException
+   *           will be thrown if the job is not in the states to accept a new 
task or if there is
+   *           any issue in updating jobConfig. 3- TimeoutException will be 
thrown if the outcome of
+   *           the task addition is unknown and cannot be verified.
+   */
+  public void addTask(String workflowName, String jobName, TaskConfig 
taskConfig, long timeoutMs)
+      throws Exception {
+
+    if (timeoutMs < DEFAULT_SLEEP) {
+      throw new IllegalArgumentException(
+          String.format("Timeout is less than the minimum acceptable timeout 
value which is %s ms",
+              DEFAULT_SLEEP));
+    }
+
+    long endTime = System.currentTimeMillis() + timeoutMs;
+
+    validateAddTaskConfigs(workflowName, jobName, taskConfig);
+
+    String nameSpaceJobName = TaskUtil.getNamespacedJobName(workflowName, 
jobName);
+    WorkflowContext workflowContext = getWorkflowContext(workflowName);
+    JobContext jobContext = getJobContext(nameSpaceJobName);
+    if (workflowContext == null || jobContext == null) {
+      // Workflow context or job context is null. It means job has not been 
started. Hence task can
+      // be added to the job
+      addTaskToJobConfig(workflowName, jobName, taskConfig, endTime);
+      return;
+    }
+
+    TaskState jobState = workflowContext.getJobState(nameSpaceJobName);
+
+    if (jobState == null) {

Review comment:
       removed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to