Wenjun Ruan
3 years ago
committed by
GitHub
27 changed files with 483 additions and 247 deletions
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ 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. |
||||
--> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler-scheduler-plugin</artifactId> |
||||
<version>dev-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dolphinscheduler-scheduler-api</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler-dao</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
@ -0,0 +1,56 @@
|
||||
/* |
||||
* 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.scheduler.api; |
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.Schedule; |
||||
|
||||
/** |
||||
* This is the interface for scheduler, contains methods to operate schedule task. |
||||
*/ |
||||
public interface SchedulerApi extends AutoCloseable{ |
||||
|
||||
/** |
||||
* Start the scheduler, if not start, the scheduler will not execute task. |
||||
* |
||||
* @throws SchedulerException if start failed. |
||||
*/ |
||||
void start() throws SchedulerException; |
||||
|
||||
/** |
||||
* @param projectId project id, the schedule task belongs to. |
||||
* @param schedule schedule metadata. |
||||
* @throws SchedulerException if insert/update failed. |
||||
*/ |
||||
void insertOrUpdateScheduleTask(int projectId, Schedule schedule) throws SchedulerException; |
||||
|
||||
/** |
||||
* Delete a schedule task. |
||||
* |
||||
* @param projectId project id, the schedule task belongs to. |
||||
* @param scheduleId schedule id. |
||||
* @throws SchedulerException if delete failed. |
||||
*/ |
||||
void deleteScheduleTask(int projectId, int scheduleId) throws SchedulerException; |
||||
|
||||
/** |
||||
* Close the scheduler and release the resource. |
||||
* |
||||
* @throws SchedulerException if close failed. |
||||
*/ |
||||
void close() throws Exception; |
||||
} |
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ 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. |
||||
--> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler-scheduler-plugin</artifactId> |
||||
<version>dev-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>dolphinscheduler-scheduler-quartz</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler-scheduler-api</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler-service</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<artifactId>dolphinscheduler-meter</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-quartz</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.quartz-scheduler</groupId> |
||||
<artifactId>quartz</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>com.mchange</groupId> |
||||
<artifactId>c3p0</artifactId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<groupId>com.mchange</groupId> |
||||
<artifactId>mchange-commons-java</artifactId> |
||||
</exclusion> |
||||
<exclusion> |
||||
<groupId>com.zaxxer</groupId> |
||||
<artifactId>HikariCP-java7</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.cronutils</groupId> |
||||
<artifactId>cron-utils</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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.scheduler.quartz; |
||||
|
||||
import org.apache.dolphinscheduler.scheduler.api.SchedulerApi; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
public class QuartzSchedulerConfiguration { |
||||
|
||||
@Bean |
||||
public SchedulerApi schedulerApi() { |
||||
return new QuartzScheduler(); |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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.scheduler.quartz.utils; |
||||
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||
import org.apache.dolphinscheduler.dao.entity.Schedule; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.quartz.JobKey; |
||||
|
||||
public final class QuartzTaskUtils { |
||||
|
||||
public static final String QUARTZ_JOB_PREFIX = "job"; |
||||
public static final String QUARTZ_JOB_GROUP_PREFIX = "jobgroup"; |
||||
public static final String UNDERLINE = "_"; |
||||
public static final String PROJECT_ID = "projectId"; |
||||
public static final String SCHEDULE_ID = "scheduleId"; |
||||
public static final String SCHEDULE = "schedule"; |
||||
|
||||
/** |
||||
* @param schedulerId scheduler id |
||||
* @return quartz job name |
||||
*/ |
||||
public static JobKey getJobKey(int schedulerId, int projectId) { |
||||
String jobName = QUARTZ_JOB_PREFIX + UNDERLINE + schedulerId; |
||||
String jobGroup = QUARTZ_JOB_GROUP_PREFIX + UNDERLINE + projectId; |
||||
return new JobKey(jobName, jobGroup); |
||||
} |
||||
|
||||
/** |
||||
* create quartz job data, include projectId and scheduleId, schedule. |
||||
*/ |
||||
public static Map<String, Object> buildDataMap(int projectId, Schedule schedule) { |
||||
Map<String, Object> dataMap = new HashMap<>(8); |
||||
dataMap.put(PROJECT_ID, projectId); |
||||
dataMap.put(SCHEDULE_ID, schedule.getId()); |
||||
dataMap.put(SCHEDULE, JSONUtils.toJsonString(schedule)); |
||||
|
||||
return dataMap; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ 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. |
||||
--> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>dolphinscheduler</artifactId> |
||||
<groupId>org.apache.dolphinscheduler</groupId> |
||||
<version>dev-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<packaging>pom</packaging> |
||||
|
||||
<artifactId>dolphinscheduler-scheduler-plugin</artifactId> |
||||
|
||||
<modules> |
||||
<module>dolphinscheduler-scheduler-api</module> |
||||
<module>dolphinscheduler-scheduler-quartz</module> |
||||
</modules> |
||||
</project> |
Loading…
Reference in new issue