|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.dolphinscheduler.plugin.task.trigger; |
| 19 | + |
| 20 | +import org.apache.dolphinscheduler.common.utils.JSONUtils; |
| 21 | +import org.apache.dolphinscheduler.plugin.task.api.AbstractRemoteTask; |
| 22 | +import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; |
| 23 | +import org.apache.dolphinscheduler.plugin.task.api.TaskException; |
| 24 | +import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; |
| 25 | + |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +import lombok.Getter; |
| 30 | +import lombok.Setter; |
| 31 | +import lombok.extern.slf4j.Slf4j; |
| 32 | + |
| 33 | +@Setter |
| 34 | +@Getter |
| 35 | +@Slf4j |
| 36 | +public class TriggerTask extends AbstractRemoteTask { |
| 37 | + |
| 38 | + private final TaskExecutionContext taskExecutionContext; |
| 39 | + private TriggerParameters parameters; |
| 40 | + |
| 41 | + public TriggerTask(TaskExecutionContext taskExecutionContext) { |
| 42 | + super(taskExecutionContext); |
| 43 | + this.taskExecutionContext = taskExecutionContext; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public List<String> getApplicationIds() throws TaskException { |
| 48 | + return Collections.emptyList(); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void init() { |
| 53 | + parameters = JSONUtils.parseObject(taskExecutionContext.getTaskParams(), TriggerParameters.class); |
| 54 | + log.info("Initialize Datafactory task params {}", JSONUtils.toPrettyJsonString(parameters)); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void submitApplication() throws TaskException { |
| 59 | + try { |
| 60 | + // start task |
| 61 | + exitStatusCode = startDatafactoryTask(); |
| 62 | + setExitStatusCode(exitStatusCode); |
| 63 | + } catch (Exception e) { |
| 64 | + setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); |
| 65 | + throw new TaskException("data factory start task error", e); |
| 66 | + } |
| 67 | + // set runId to the appIds if start success |
| 68 | + setAppIds(parameters.getRunId()); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public void cancelApplication() throws TaskException { |
| 73 | + checkApplicationId(); |
| 74 | + exitStatusCode = TaskConstants.EXIT_CODE_KILL; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public void trackApplicationStatus() throws TaskException { |
| 79 | + checkApplicationId(); |
| 80 | + Boolean isFinishedSuccessfully = false; |
| 81 | + if (!isFinishedSuccessfully) { |
| 82 | + exitStatusCode = TaskConstants.EXIT_CODE_FAILURE; |
| 83 | + } else { |
| 84 | + exitStatusCode = TaskConstants.EXIT_CODE_SUCCESS; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * check datafactory applicationId or get it from appId |
| 90 | + */ |
| 91 | + private void checkApplicationId() { |
| 92 | + } |
| 93 | + |
| 94 | + public int startDatafactoryTask() { |
| 95 | + return 0; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public TriggerParameters getParameters() { |
| 100 | + return parameters; |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments