EricGao888 commented on code in PR #9327: URL: https://github.com/apache/dolphinscheduler/pull/9327#discussion_r843736354
########## dolphinscheduler-task-plugin/dolphinscheduler-task-zeppelin/src/main/java/org/apache/dolphinscheduler/plugin/task/zeppelin/ZeppelinTask.java: ########## @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.task.zeppelin; + +import org.apache.dolphinscheduler.plugin.task.api.AbstractTaskExecutor; +import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; +import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; +import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters; +import org.apache.dolphinscheduler.spi.utils.JSONUtils; +import org.apache.dolphinscheduler.spi.utils.PropertyUtils; +import org.apache.zeppelin.client.ClientConfig; +import org.apache.zeppelin.client.ParagraphResult; +import org.apache.zeppelin.client.Status; +import org.apache.zeppelin.client.ZeppelinClient; + + +public class ZeppelinTask extends AbstractTaskExecutor { + + /** + * taskExecutionContext + */ + private final TaskExecutionContext taskExecutionContext; + + /** + * zeppelin parameters + */ + private ZeppelinParameters zeppelinParameters; + + /** + * zeppelin api client + */ + private ZeppelinClient zClient; + + + /** + * constructor + * + * @param taskExecutionContext taskExecutionContext + */ + protected ZeppelinTask(TaskExecutionContext taskExecutionContext) { + super(taskExecutionContext); + this.taskExecutionContext = taskExecutionContext; + } + + @Override + public void init() { + final String taskParams = taskExecutionContext.getTaskParams(); + logger.info("zeppelin task params:{}", taskParams); + this.zeppelinParameters = JSONUtils.parseObject(taskParams, ZeppelinParameters.class); + if (this.zeppelinParameters == null || !this.zeppelinParameters.checkParameters()) { + throw new ZeppelinTaskException("zeppelin task params is not valid"); + } + this.zClient = getZeppelinClient(); + } + + @Override + public void handle() throws Exception { + try { + String noteId = this.zeppelinParameters.getNoteId(); + String paragraphId = this.zeppelinParameters.getParagraphId(); Review Comment: @zhuangchong Actually we could use http task node for most kinds of tasks using restful api, such as EMR task, etc. However, IMHO there are four main reasons we could use zeppelin task plugin for zeppelin tasks: 1. There are several different RESTful APIs we need to call during the process of executing / scheduling zeppelin tasks. It seems we cannot achieve this goal using http task plugin. 2. We could gain better control of the submitting / executing zeppelin tasks by using zeppelin task plugin. In the future PRs, I will improve the method of submitting zeppelin tasks in a non-blocking fashion. In this way, we could query the task execution progress (in percentile) through zeppelin client, which will give our users a better experience. 3. We could manage authentication easily with zeppelin task plugin, although authentication feature hasn't been implemented in this PR. It seems not very practical or convenient for users to use http task plugin to manage this. 4. We could control the result output from zeppelin task plugin. The raw output from zeppelin execution could contain a lot of information users do not really need to see. We filter useless output and only log key information through zeppelin task plugin. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
