lei-xia commented on a change in pull request #1439:
URL: https://github.com/apache/helix/pull/1439#discussion_r500473048
##########
File path: helix-core/src/main/java/org/apache/helix/task/TaskDriver.java
##########
@@ -526,6 +524,123 @@ public void enqueueJobs(final String queue, final
List<String> jobs,
}
}
+ /**
+ * Add task to a running (IN-PROGRESS) job with default timeout
+ * @param taskConfig
+ * @param workflowName
+ * @param jobName
+ * @throws Exception
+ */
+ public void addTask(TaskConfig taskConfig, String workflowName, String
jobName) throws Exception {
+ addTask(taskConfig, workflowName, jobName, DEFAULT_TIMEOUT);
+ }
+
+ /**
+ * Add task to a running (IN-PROGRESS) job
+ * @param taskConfig
+ * @param workflowName
+ * @param jobName
+ * @param timeout
+ * @throws Exception
+ */
+ public void addTask(TaskConfig taskConfig, String workflowName, String
jobName, long timeout)
+ throws Exception {
+ WorkflowConfig workflowConfig = TaskUtil.getWorkflowConfig(_accessor,
workflowName);
+ long endTime = System.currentTimeMillis() + timeout;
+
+ if (workflowConfig == null) {
+ throw new HelixException("Workflow " + workflowName + " config does not
exist!");
+ }
+
+ String nameSpaceJobName = TaskUtil.getNamespacedJobName(workflowName,
jobName);
+ JobConfig jobConfig = TaskUtil.getJobConfig(_accessor, nameSpaceJobName);
+ if (jobConfig == null) {
+ throw new HelixException("Job " + nameSpaceJobName + " config does not
exist!");
+ }
+
+ if (jobConfig.getTargetResource() != null) {
+ throw new HelixException(
+ "Job " + nameSpaceJobName + " is a targeted job. New task cannot be
added to this job!");
+ }
+
+ WorkflowContext workflowContext = getWorkflowContext(workflowName);
+ if (workflowContext == null) {
+ throw new HelixException("Workflow " + workflowName + " context does not
exist!");
+ }
+
+ if (taskConfig == null) {
+ throw new IllegalArgumentException("Task cannot be added because
taskConfig is null!");
+ }
+
+ if (taskConfig.getId() == null) {
+ throw new HelixException(
+ "Task cannot be added because taskID is null!");
+ }
+
+ if (taskConfig.getCommand() == null && jobConfig.getCommand() == null) {
+ throw new HelixException(
+ "Task cannot be added because both of the job and task have null
command!");
+ }
+
+ if (taskConfig.getCommand() != null && jobConfig.getCommand() != null) {
+ throw new HelixException(
+ "Task cannot be added because command existed for both of job and
task!");
+ }
+
Review comment:
Can we wrap this logic to a separate (private) method, such as
validateTaskConfig(). Also, you may want to put this check at the beginning of
the method (to avoid non-necessary ZK read if the input itself is not valid).
----------------------------------------------------------------
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]