Skip to content

Commit 167f0e8

Browse files
committed
[DSIP-22][TriggerPlugin] Introduce Trigger Plugin
1 parent 6862fe7 commit 167f0e8

File tree

14 files changed

+486
-0
lines changed

14 files changed

+486
-0
lines changed

dolphinscheduler-task-plugin/dolphinscheduler-task-all/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@
222222
<artifactId>dolphinscheduler-task-remoteshell</artifactId>
223223
<version>${project.version}</version>
224224
</dependency>
225+
<dependency>
226+
<groupId>org.apache.dolphinscheduler</groupId>
227+
<artifactId>dolphinscheduler-task-trigger</artifactId>
228+
<version>${project.version}</version>
229+
</dependency>
225230
</dependencies>
226231

227232
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>org.apache.dolphinscheduler</groupId>
23+
<artifactId>dolphinscheduler-task-plugin</artifactId>
24+
<version>dev-SNAPSHOT</version>
25+
</parent>
26+
27+
<artifactId>dolphinscheduler-task-trigger</artifactId>
28+
<packaging>jar</packaging>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.apache.dolphinscheduler</groupId>
33+
<artifactId>dolphinscheduler-spi</artifactId>
34+
<scope>provided</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.dolphinscheduler</groupId>
38+
<artifactId>dolphinscheduler-task-api</artifactId>
39+
<scope>provided</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.dolphinscheduler</groupId>
43+
<artifactId>dolphinscheduler-common</artifactId>
44+
<scope>provided</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.plugin.task.api.parameters.AbstractParameters;
21+
22+
import org.apache.commons.lang3.StringUtils;
23+
24+
import lombok.Getter;
25+
import lombok.NoArgsConstructor;
26+
import lombok.Setter;
27+
import lombok.ToString;
28+
29+
@Setter
30+
@Getter
31+
@NoArgsConstructor
32+
@ToString
33+
public class TriggerParameters extends AbstractParameters {
34+
35+
private String factoryName;
36+
private String resourceGroupName;
37+
private String pipelineName;
38+
private String runId;
39+
40+
@Override
41+
public boolean checkParameters() {
42+
return StringUtils.isNotEmpty(factoryName) && StringUtils.isNotEmpty(resourceGroupName)
43+
&& StringUtils.isNotEmpty(pipelineName);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
public enum TriggerStatus {
21+
22+
Queued,
23+
InProgress,
24+
Succeeded,
25+
Failed,
26+
Canceling,
27+
Cancelled,
28+
;
29+
30+
/**
31+
* Gets the status property: The status of a pipeline run. Possible values: Queued, InProgress, Succeeded, Failed,
32+
* Canceling, Cancelled.
33+
*
34+
* @return the status value.
35+
*/
36+
TriggerStatus() {
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.TaskChannel;
22+
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
23+
import org.apache.dolphinscheduler.plugin.task.api.parameters.AbstractParameters;
24+
import org.apache.dolphinscheduler.plugin.task.api.parameters.ParametersNode;
25+
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
26+
27+
public class TriggerTaskChannel implements TaskChannel {
28+
29+
@Override
30+
public void cancelApplication(boolean status) {
31+
}
32+
33+
@Override
34+
public TriggerTask createTask(TaskExecutionContext taskRequest) {
35+
return new TriggerTask(taskRequest);
36+
}
37+
38+
@Override
39+
public AbstractParameters parseParameters(ParametersNode parametersNode) {
40+
return JSONUtils.parseObject(parametersNode.getTaskParams(), TriggerParameters.class);
41+
}
42+
43+
@Override
44+
public ResourceParametersHelper getResources(String parameters) {
45+
return null;
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.plugin.task.api.TaskChannel;
21+
import org.apache.dolphinscheduler.plugin.task.api.TaskChannelFactory;
22+
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
23+
24+
import java.util.Collections;
25+
import java.util.List;
26+
27+
import com.google.auto.service.AutoService;
28+
29+
@AutoService(TaskChannelFactory.class)
30+
public class TriggerTaskChannelFactory implements TaskChannelFactory {
31+
32+
@Override
33+
public TaskChannel create() {
34+
return new TriggerTaskChannel();
35+
}
36+
37+
@Override
38+
public String getName() {
39+
return "TRIGGER";
40+
}
41+
42+
@Override
43+
public List<PluginParams> getParams() {
44+
return Collections.emptyList();
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 static org.mockito.ArgumentMatchers.any;
21+
import static org.mockito.Mockito.mock;
22+
import static org.mockito.Mockito.mockStatic;
23+
24+
import org.junit.jupiter.api.extension.ExtendWith;
25+
import org.mockito.junit.jupiter.MockitoExtension;
26+
27+
@ExtendWith(MockitoExtension.class)
28+
public class TriggerTaskTest {
29+
30+
31+
}

dolphinscheduler-task-plugin/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<module>dolphinscheduler-task-linkis</module>
6464
<module>dolphinscheduler-task-datafactory</module>
6565
<module>dolphinscheduler-task-remoteshell</module>
66+
<module>dolphinscheduler-task-trigger</module>
6667
</modules>
6768

6869
<dependencyManagement>

0 commit comments

Comments
 (0)