You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/06/27 15:19:41 UTC
[shardingsphere-elasticjob-lite] branch master updated: Simplify
Job API level, merge configuration object to single (#850)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new d96ee73 Simplify Job API level, merge configuration object to single (#850)
d96ee73 is described below
commit d96ee73a159b70f8628796b85d35cb7e2a957721
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jun 27 23:19:29 2020 +0800
Simplify Job API level, merge configuration object to single (#850)
* Add props for JobConfiguration
* Remove ScriptJobConfiguration.scriptCommandLine
* Remove ScriptJobConfiguration.scriptCommandLine
* Remove useless fields for job configuration
* Add JobConfiguration.jobType
* Remove JobTypeConfiguration.jobType
* Move jobType into JobCoreConfiguration
* Move props into JobCoreConfiguration
* Remove XXXobConfiguration
* Remove JobTypeConfiguration
* Remove JobCoreConfiguration
---
.../elasticjob/lite/api/JobScheduler.java | 4 +-
.../elasticjob/lite/config/JobConfiguration.java | 253 +++++++++++++++++----
.../lite/config/JobCoreConfiguration.java | 204 -----------------
.../lite/config/JobTypeConfiguration.java | 40 ----
.../config/dataflow/DataflowJobConfiguration.java | 38 ----
.../lite/config/script/ScriptJobConfiguration.java | 38 ----
.../lite/config/simple/SimpleJobConfiguration.java | 36 ---
.../lite/executor/ElasticJobExecutor.java | 8 +-
.../executor/type/impl/DataflowJobExecutor.java | 6 +-
.../lite/executor/type/impl/ScriptJobExecutor.java | 5 +-
.../internal/config/RescheduleListenerManager.java | 2 +-
.../json/JobConfigurationGsonTypeAdapter.java | 120 +++++-----
.../config/json/JobConfigurationJsonEnum.java | 14 +-
.../lite/internal/guarantee/GuaranteeService.java | 4 +-
.../lite/internal/schedule/LiteJobFacade.java | 20 +-
.../internal/sharding/ExecutionContextService.java | 10 +-
.../lite/internal/sharding/ExecutionService.java | 2 +-
.../internal/sharding/ShardingListenerManager.java | 2 +-
.../lite/internal/sharding/ShardingService.java | 6 +-
.../elasticjob/lite/api/JobSchedulerTest.java | 4 +-
.../lite/config/JobConfigurationTest.java | 68 ++++--
.../lite/config/JobCoreConfigurationTest.java | 84 -------
.../type/impl/DataflowJobExecutorTest.java | 7 +-
.../executor/type/impl/ScriptJobExecutorTest.java | 7 +-
.../executor/type/impl/SimpleJobExecutorTest.java | 9 +-
.../executor/type/impl/WrongJobExecutorTest.java | 8 +-
.../lite/fixture/util/JobConfigurationUtil.java | 7 +-
.../lite/integrate/AbstractBaseStdJobTest.java | 37 +--
.../std/dataflow/OneOffDataflowElasticJobTest.java | 5 +-
...ingDataflowElasticJobForExecuteFailureTest.java | 2 +-
...lowElasticJobForExecuteThrowsExceptionTest.java | 2 +-
...ngDataflowElasticJobForMultipleThreadsTest.java | 2 +-
...reamingDataflowElasticJobForNotMonitorTest.java | 3 +-
.../dataflow/StreamingDataflowElasticJobTest.java | 2 +-
.../integrate/std/script/ScriptElasticJobTest.java | 6 +-
.../internal/config/ConfigurationServiceTest.java | 12 +-
.../config/JobConfigurationGsonFactoryTest.java | 64 +++---
.../failover/FailoverListenerManagerTest.java | 18 +-
.../internal/guarantee/GuaranteeServiceTest.java | 11 +-
.../internal/reconcile/ReconcileServiceTest.java | 6 +-
.../lite/internal/schedule/LiteJobFacadeTest.java | 39 ++--
.../internal/schedule/SchedulerFacadeTest.java | 7 +-
.../sharding/ExecutionContextServiceTest.java | 16 +-
.../internal/sharding/ExecutionServiceTest.java | 37 ++-
.../internal/sharding/ShardingServiceTest.java | 17 +-
.../internal/settings/JobSettingsAPIImpl.java | 38 ++--
.../internal/statistics/JobStatisticsAPIImpl.java | 6 +-
.../common/AbstractJobBeanDefinitionParser.java | 47 ++--
.../dataflow/DataflowJobBeanDefinitionParser.java | 22 +-
.../script/ScriptJobBeanDefinitionParser.java | 22 +-
.../simple/SimpleJobBeanDefinitionParser.java | 18 +-
.../elasticjob/lite/example/JavaMain.java | 22 +-
.../lite/example/config/DataflowJobConfig.java | 8 +-
.../lite/example/config/SimpleJobConfig.java | 6 +-
54 files changed, 596 insertions(+), 885 deletions(-)
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java
index aeecb70..2256ecd 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/JobScheduler.java
@@ -99,11 +99,11 @@ public final class JobScheduler {
*/
public void init() {
JobConfiguration jobConfigFromRegCenter = schedulerFacade.updateJobConfiguration(null == elasticJob ? ScriptJob.class.getName() : elasticJob.getClass().getName(), jobConfig);
- JobRegistry.getInstance().setCurrentShardingTotalCount(jobConfigFromRegCenter.getJobName(), jobConfigFromRegCenter.getTypeConfig().getCoreConfig().getShardingTotalCount());
+ JobRegistry.getInstance().setCurrentShardingTotalCount(jobConfigFromRegCenter.getJobName(), jobConfigFromRegCenter.getShardingTotalCount());
JobScheduleController jobScheduleController = new JobScheduleController(createScheduler(), createJobDetail(elasticJob), jobConfigFromRegCenter.getJobName());
JobRegistry.getInstance().registerJob(jobConfigFromRegCenter.getJobName(), jobScheduleController, regCenter);
schedulerFacade.registerStartUpInfo(!jobConfigFromRegCenter.isDisabled());
- jobScheduleController.scheduleJob(jobConfigFromRegCenter.getTypeConfig().getCoreConfig().getCron());
+ jobScheduleController.scheduleJob(jobConfigFromRegCenter.getCron());
}
private Scheduler createScheduler() {
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfiguration.java
index 5a5361f..ddf868f 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfiguration.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfiguration.java
@@ -17,10 +17,15 @@
package org.apache.shardingsphere.elasticjob.lite.config;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
+
+import java.util.Properties;
/**
* ElasticJob configuration.
@@ -29,82 +34,147 @@ import lombok.RequiredArgsConstructor;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public final class JobConfiguration {
- private final JobTypeConfiguration typeConfig;
+ private final String jobName;
+
+ private final JobType jobType;
+
+ private final String cron;
+
+ private final int shardingTotalCount;
+
+ private final String shardingItemParameters;
+
+ private final String jobParameter;
private final boolean monitorExecution;
+ private final boolean failover;
+
+ private final boolean misfire;
+
private final int maxTimeDiffSeconds;
+ private final int reconcileIntervalMinutes;
+
private final int monitorPort;
private final String jobShardingStrategyType;
- private final int reconcileIntervalMinutes;
+ private final String jobExecutorServiceHandlerType;
+
+ private final String jobErrorHandlerType;
+
+ private final String description;
+
+ private final Properties props;
private final boolean disabled;
private final boolean overwrite;
/**
- * Get job name.
- *
- * @return job name
- */
- public String getJobName() {
- return typeConfig.getCoreConfig().getJobName();
- }
-
- /**
- * Get is enable or disable failover.
+ * Create ElasticJob configuration builder.
*
- * @return is enable failover
- */
- public boolean isFailover() {
- return typeConfig.getCoreConfig().isFailover();
- }
-
- /**
- * Create ElasticJob lite configuration builder.
- *
- * @param jobConfig job configuration
- * @return ElasticJob lite configuration builder
+ * @param jobName job name
+ * @param jobType job type
+ * @param cron cron expression for job trigger
+ * @param shardingTotalCount sharding total count
+ * @return ElasticJob configuration builder
*/
- public static Builder newBuilder(final JobTypeConfiguration jobConfig) {
- return new Builder(jobConfig);
+ public static Builder newBuilder(final String jobName, final JobType jobType, final String cron, final int shardingTotalCount) {
+ return new Builder(jobName, jobType, cron, shardingTotalCount);
}
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public static class Builder {
- private final JobTypeConfiguration jobConfig;
-
+ private final String jobName;
+
+ private final JobType jobType;
+
+ private final String cron;
+
+ private final int shardingTotalCount;
+
+ private String shardingItemParameters = "";
+
+ private String jobParameter = "";
+
private boolean monitorExecution = true;
+ private boolean failover;
+
+ private boolean misfire = true;
+
private int maxTimeDiffSeconds = -1;
+ private int reconcileIntervalMinutes = 10;
+
private int monitorPort = -1;
private String jobShardingStrategyType = "";
+ private String jobExecutorServiceHandlerType;
+
+ private String jobErrorHandlerType;
+
+ private String description = "";
+
+ private final Properties props = new Properties();
+
private boolean disabled;
private boolean overwrite;
- private int reconcileIntervalMinutes = 10;
-
+ /**
+ * Set mapper of sharding items and sharding parameters.
+ *
+ * <p>
+ * sharding item and sharding parameter split by =, multiple sharding items and sharding parameters split by comma, just like map.
+ * Sharding item start from zero, cannot equal to great than sharding total count.
+ *
+ * For example:
+ * 0=a,1=b,2=c
+ * </p>
+ *
+ * @param shardingItemParameters mapper of sharding items and sharding parameters
+ *
+ * @return job configuration builder
+ */
+ public Builder shardingItemParameters(final String shardingItemParameters) {
+ if (null != shardingItemParameters) {
+ this.shardingItemParameters = shardingItemParameters;
+ }
+ return this;
+ }
+
+ /**
+ * Set job parameter.
+ *
+ * @param jobParameter job parameter
+ *
+ * @return job configuration builder
+ */
+ public Builder jobParameter(final String jobParameter) {
+ if (null != jobParameter) {
+ this.jobParameter = jobParameter;
+ }
+ return this;
+ }
+
/**
* Set enable or disable monitor execution.
*
* <p>
* For short interval job, it is better to disable monitor execution to improve performance.
* It can't guarantee repeated data fetch and can't failover if disable monitor execution, please keep idempotence in job.
- *
+ *
* For long interval job, it is better to enable monitor execution to guarantee fetch data exactly once.
* </p>
*
* @param monitorExecution monitor job execution status
*
- * @return ElasticJob lite configuration builder
+ * @return ElasticJob configuration builder
*/
public Builder monitorExecution(final boolean monitorExecution) {
this.monitorExecution = monitorExecution;
@@ -112,6 +182,34 @@ public final class JobConfiguration {
}
/**
+ * Set enable failover.
+ *
+ * <p>
+ * Only for `monitorExecution` enabled.
+ * </p>
+ *
+ * @param failover enable or disable failover
+ *
+ * @return job configuration builder
+ */
+ public Builder failover(final boolean failover) {
+ this.failover = failover;
+ return this;
+ }
+
+ /**
+ * Set enable misfire.
+ *
+ * @param misfire enable or disable misfire
+ *
+ * @return job configuration builder
+ */
+ public Builder misfire(final boolean misfire) {
+ this.misfire = misfire;
+ return this;
+ }
+
+ /**
* Set max tolerate time different seconds between job server and registry center.
*
* <p>
@@ -121,7 +219,7 @@ public final class JobConfiguration {
*
* @param maxTimeDiffSeconds max tolerate time different seconds between job server and registry center
*
- * @return ElasticJob lite configuration builder
+ * @return ElasticJob configuration builder
*/
public Builder maxTimeDiffSeconds(final int maxTimeDiffSeconds) {
this.maxTimeDiffSeconds = maxTimeDiffSeconds;
@@ -129,11 +227,27 @@ public final class JobConfiguration {
}
/**
+ * Set reconcile interval minutes for job sharding status.
+ *
+ * <p>
+ * Monitor the status of the job server at regular intervals, and resharding if incorrect.
+ * </p>
+ *
+ * @param reconcileIntervalMinutes reconcile interval minutes for job sharding status
+ *
+ * @return ElasticJob configuration builder
+ */
+ public Builder reconcileIntervalMinutes(final int reconcileIntervalMinutes) {
+ this.reconcileIntervalMinutes = reconcileIntervalMinutes;
+ return this;
+ }
+
+ /**
* Set job monitor port.
- *
+ *
* @param monitorPort job monitor port
*
- * @return ElasticJob lite configuration builder
+ * @return ElasticJob configuration builder
*/
public Builder monitorPort(final int monitorPort) {
this.monitorPort = monitorPort;
@@ -149,7 +263,7 @@ public final class JobConfiguration {
*
* @param jobShardingStrategyType job sharding sharding type
*
- * @return ElasticJob lite configuration builder
+ * @return ElasticJob configuration builder
*/
public Builder jobShardingStrategyType(final String jobShardingStrategyType) {
if (null != jobShardingStrategyType) {
@@ -157,20 +271,55 @@ public final class JobConfiguration {
}
return this;
}
-
+
/**
- * Set reconcile interval minutes for job sharding status.
+ * Set job executor service handler type.
*
- * <p>
- * Monitor the status of the job server at regular intervals, and resharding if incorrect.
- * </p>
+ * @param jobExecutorServiceHandlerType job executor service handler type
*
- * @param reconcileIntervalMinutes reconcile interval minutes for job sharding status
+ * @return job configuration builder
+ */
+ public Builder jobExecutorServiceHandlerType(final String jobExecutorServiceHandlerType) {
+ this.jobExecutorServiceHandlerType = jobExecutorServiceHandlerType;
+ return this;
+ }
+
+ /**
+ * Set job error handler type.
+ *
+ * @param jobErrorHandlerType job error handler type
*
- * @return ElasticJob lite configuration builder
+ * @return job configuration builder
*/
- public Builder reconcileIntervalMinutes(final int reconcileIntervalMinutes) {
- this.reconcileIntervalMinutes = reconcileIntervalMinutes;
+ public Builder jobErrorHandlerType(final String jobErrorHandlerType) {
+ this.jobErrorHandlerType = jobErrorHandlerType;
+ return this;
+ }
+
+ /**
+ * Set job description.
+ *
+ * @param description job description
+ *
+ * @return job configuration builder
+ */
+ public Builder description(final String description) {
+ if (null != description) {
+ this.description = description;
+ }
+ return this;
+ }
+
+ /**
+ * Set property.
+ *
+ * @param key property key
+ * @param value property value
+ *
+ * @return job configuration builder
+ */
+ public Builder setProperty(final String key, final String value) {
+ props.setProperty(key, value);
return this;
}
@@ -183,7 +332,7 @@ public final class JobConfiguration {
*
* @param disabled whether disable job when start
*
- * @return ElasticJob lite configuration builder
+ * @return ElasticJob configuration builder
*/
public Builder disabled(final boolean disabled) {
this.disabled = disabled;
@@ -199,7 +348,7 @@ public final class JobConfiguration {
*
* @param overwrite whether overwrite local configuration to registry center when job startup
*
- * @return ElasticJob lite configuration builder
+ * @return ElasticJob configuration builder
*/
public Builder overwrite(final boolean overwrite) {
this.overwrite = overwrite;
@@ -207,12 +356,18 @@ public final class JobConfiguration {
}
/**
- * Build ElasticJob lite configuration.
+ * Build ElasticJob configuration.
*
- * @return ElasticJob lite configuration
+ * @return ElasticJob configuration
*/
public final JobConfiguration build() {
- return new JobConfiguration(jobConfig, monitorExecution, maxTimeDiffSeconds, monitorPort, jobShardingStrategyType, reconcileIntervalMinutes, disabled, overwrite);
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(jobName), "jobName can not be empty.");
+ Preconditions.checkNotNull(jobType, "jobType can not be null.");
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(cron), "cron can not be empty.");
+ Preconditions.checkArgument(shardingTotalCount > 0, "shardingTotalCount should larger than zero.");
+ return new JobConfiguration(jobName, jobType, cron, shardingTotalCount, shardingItemParameters, jobParameter,
+ monitorExecution, failover, misfire, maxTimeDiffSeconds, reconcileIntervalMinutes, monitorPort, jobShardingStrategyType, jobExecutorServiceHandlerType, jobErrorHandlerType,
+ description, props, disabled, overwrite);
}
}
}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobCoreConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobCoreConfiguration.java
deleted file mode 100644
index 3de40e2..0000000
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobCoreConfiguration.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.config;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Job core configuration.
- */
-@AllArgsConstructor(access = AccessLevel.PRIVATE)
-@Getter
-public final class JobCoreConfiguration {
-
- private final String jobName;
-
- private final String cron;
-
- private final int shardingTotalCount;
-
- private final String shardingItemParameters;
-
- private final String jobParameter;
-
- private final boolean failover;
-
- private final boolean misfire;
-
- private final String jobExecutorServiceHandlerType;
-
- private final String jobErrorHandlerType;
-
- private final String description;
-
- /**
- * Create simple job configuration builder.
- *
- * @param jobName job name
- * @param cron cron expression for job trigger
- * @param shardingTotalCount sharding total count
- * @return simple job configuration builder
- */
- public static Builder newBuilder(final String jobName, final String cron, final int shardingTotalCount) {
- return new Builder(jobName, cron, shardingTotalCount);
- }
-
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
- public static class Builder {
-
- private final String jobName;
-
- private final String cron;
-
- private final int shardingTotalCount;
-
- private String shardingItemParameters = "";
-
- private String jobParameter = "";
-
- private boolean failover;
-
- private boolean misfire = true;
-
- private String jobExecutorServiceHandlerType;
-
- private String jobErrorHandlerType;
-
- private String description = "";
-
- /**
- * Set mapper of sharding items and sharding parameters.
- *
- * <p>
- * sharding item and sharding parameter split by =, multiple sharding items and sharding parameters split by comma, just like map.
- * Sharding item start from zero, cannot equal to great than sharding total count.
- *
- * For example:
- * 0=a,1=b,2=c
- * </p>
- *
- * @param shardingItemParameters mapper of sharding items and sharding parameters
- *
- * @return job configuration builder
- */
- public Builder shardingItemParameters(final String shardingItemParameters) {
- if (null != shardingItemParameters) {
- this.shardingItemParameters = shardingItemParameters;
- }
- return this;
- }
-
- /**
- * Set job parameter.
- *
- * @param jobParameter job parameter
- *
- * @return job configuration builder
- */
- public Builder jobParameter(final String jobParameter) {
- if (null != jobParameter) {
- this.jobParameter = jobParameter;
- }
- return this;
- }
-
- /**
- * Set enable failover.
- *
- * <p>
- * Only for `monitorExecution` enabled.
- * </p>
- *
- * @param failover enable or disable failover
- *
- * @return job configuration builder
- */
- public Builder failover(final boolean failover) {
- this.failover = failover;
- return this;
- }
-
- /**
- * Set enable misfire.
- *
- * @param misfire enable or disable misfire
- *
- * @return job configuration builder
- */
- public Builder misfire(final boolean misfire) {
- this.misfire = misfire;
- return this;
- }
-
- /**
- * Set job error handler type.
- *
- * @param jobErrorHandlerType job error handler type
- *
- * @return job configuration builder
- */
- public Builder jobErrorHandlerType(final String jobErrorHandlerType) {
- this.jobErrorHandlerType = jobErrorHandlerType;
- return this;
- }
-
- /**
- * Set job executor service handler type.
- *
- * @param jobExecutorServiceHandlerType job executor service handler type
- *
- * @return job configuration builder
- */
- public Builder jobExecutorServiceHandlerType(final String jobExecutorServiceHandlerType) {
- this.jobExecutorServiceHandlerType = jobExecutorServiceHandlerType;
- return this;
- }
-
- /**
- * Set job description.
- *
- * @param description job description
- *
- * @return job configuration builder
- */
- public Builder description(final String description) {
- if (null != description) {
- this.description = description;
- }
- return this;
- }
-
- /**
- * Build Job.
- *
- * @return job configuration builder
- */
- public final JobCoreConfiguration build() {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(jobName), "jobName can not be empty.");
- Preconditions.checkArgument(!Strings.isNullOrEmpty(cron), "cron can not be empty.");
- Preconditions.checkArgument(shardingTotalCount > 0, "shardingTotalCount should larger than zero.");
- return new JobCoreConfiguration(
- jobName, cron, shardingTotalCount, shardingItemParameters, jobParameter, failover, misfire, jobExecutorServiceHandlerType, jobErrorHandlerType, description);
- }
- }
-}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobTypeConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobTypeConfiguration.java
deleted file mode 100644
index 0ac0650..0000000
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/JobTypeConfiguration.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.config;
-
-import org.apache.shardingsphere.elasticjob.lite.api.JobType;
-
-/**
- * Job type configuration.
- */
-public interface JobTypeConfiguration {
-
- /**
- * Get job type.
- *
- * @return job type
- */
- JobType getJobType();
-
- /**
- * Get job core configuration.
- *
- * @return job core configuration
- */
- JobCoreConfiguration getCoreConfig();
-}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/dataflow/DataflowJobConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/dataflow/DataflowJobConfiguration.java
deleted file mode 100644
index 5906772..0000000
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/dataflow/DataflowJobConfiguration.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.config.dataflow;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.elasticjob.lite.api.JobType;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
-
-/**
- * Dataflow job configuration.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DataflowJobConfiguration implements JobTypeConfiguration {
-
- private final JobCoreConfiguration coreConfig;
-
- private final JobType jobType = JobType.DATAFLOW;
-
- private final boolean streamingProcess;
-}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/script/ScriptJobConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/script/ScriptJobConfiguration.java
deleted file mode 100644
index 5c274fb..0000000
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/script/ScriptJobConfiguration.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.config.script;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.elasticjob.lite.api.JobType;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
-
-/**
- * Script job configuration.
- */
-@RequiredArgsConstructor
-@Getter
-public final class ScriptJobConfiguration implements JobTypeConfiguration {
-
- private final JobCoreConfiguration coreConfig;
-
- private final JobType jobType = JobType.SCRIPT;
-
- private final String scriptCommandLine;
-}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/simple/SimpleJobConfiguration.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/simple/SimpleJobConfiguration.java
deleted file mode 100644
index 208b7eb..0000000
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/config/simple/SimpleJobConfiguration.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.config.simple;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.elasticjob.lite.api.JobType;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
-
-/**
- * Simple job configuration.
- */
-@RequiredArgsConstructor
-@Getter
-public final class SimpleJobConfiguration implements JobTypeConfiguration {
-
- private final JobCoreConfiguration coreConfig;
-
- private final JobType jobType = JobType.SIMPLE;
-}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/ElasticJobExecutor.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/ElasticJobExecutor.java
index a147b34..874e770 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/ElasticJobExecutor.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/ElasticJobExecutor.java
@@ -71,10 +71,10 @@ public final class ElasticJobExecutor {
this.jobFacade = jobFacade;
jobItemExecutor = getJobItemExecutor(elasticJob);
jobConfig = jobFacade.loadJobConfiguration(true);
- jobName = jobConfig.getTypeConfig().getCoreConfig().getJobName();
- executorService = JobExecutorServiceHandlerFactory.getHandler(jobConfig.getTypeConfig().getCoreConfig().getJobExecutorServiceHandlerType()).createExecutorService(jobName);
- jobErrorHandler = JobErrorHandlerFactory.getHandler(jobConfig.getTypeConfig().getCoreConfig().getJobErrorHandlerType());
- itemErrorMessages = new ConcurrentHashMap<>(jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), 1);
+ jobName = jobConfig.getJobName();
+ executorService = JobExecutorServiceHandlerFactory.getHandler(jobConfig.getJobExecutorServiceHandlerType()).createExecutorService(jobName);
+ jobErrorHandler = JobErrorHandlerFactory.getHandler(jobConfig.getJobErrorHandlerType());
+ itemErrorMessages = new ConcurrentHashMap<>(jobConfig.getShardingTotalCount(), 1);
}
@SuppressWarnings("unchecked")
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutor.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutor.java
index 2f815b5..bdb5a7b 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutor.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutor.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.elasticjob.lite.executor.type.impl;
import org.apache.shardingsphere.elasticjob.lite.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.lite.api.dataflow.DataflowJob;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.JobFacade;
import org.apache.shardingsphere.elasticjob.lite.executor.type.JobItemExecutor;
@@ -31,10 +30,11 @@ import java.util.List;
*/
public final class DataflowJobExecutor implements JobItemExecutor<DataflowJob> {
+ public static final String STREAM_PROCESS_KEY = "streaming.process";
+
@Override
public void process(final DataflowJob elasticJob, final JobConfiguration jobConfig, final JobFacade jobFacade, final ShardingContext shardingContext) {
- DataflowJobConfiguration dataflowConfig = (DataflowJobConfiguration) jobConfig.getTypeConfig();
- if (dataflowConfig.isStreamingProcess()) {
+ if (Boolean.parseBoolean(jobConfig.getProps().getOrDefault(STREAM_PROCESS_KEY, false).toString())) {
streamingExecute(elasticJob, jobFacade, shardingContext);
} else {
oneOffExecute(elasticJob, shardingContext);
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutor.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutor.java
index f866794..d4c01d5 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutor.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutor.java
@@ -23,7 +23,6 @@ import org.apache.commons.exec.DefaultExecutor;
import org.apache.shardingsphere.elasticjob.lite.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.lite.api.script.ScriptJob;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.exception.JobConfigurationException;
import org.apache.shardingsphere.elasticjob.lite.executor.JobFacade;
import org.apache.shardingsphere.elasticjob.lite.executor.type.JobItemExecutor;
@@ -36,9 +35,11 @@ import java.io.IOException;
*/
public final class ScriptJobExecutor implements JobItemExecutor<ScriptJob> {
+ public static final String SCRIPT_KEY = "script.command.line";
+
@Override
public void process(final ScriptJob elasticJob, final JobConfiguration jobConfig, final JobFacade jobFacade, final ShardingContext shardingContext) {
- String scriptCommandLine = ((ScriptJobConfiguration) jobConfig.getTypeConfig()).getScriptCommandLine();
+ String scriptCommandLine = jobConfig.getProps().getProperty(SCRIPT_KEY);
if (Strings.isNullOrEmpty(scriptCommandLine)) {
throw new JobConfigurationException("Cannot find script command line for job '%s', job is not executed.", shardingContext.getJobName());
}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/RescheduleListenerManager.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/RescheduleListenerManager.java
index 2c15236..9513956 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/RescheduleListenerManager.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/RescheduleListenerManager.java
@@ -49,7 +49,7 @@ public final class RescheduleListenerManager extends AbstractListenerManager {
@Override
protected void dataChanged(final String path, final Type eventType, final String data) {
if (configNode.isConfigPath(path) && Type.NODE_UPDATED == eventType && !JobRegistry.getInstance().isShutdown(jobName)) {
- JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob(JobConfigurationGsonFactory.fromJson(data).getTypeConfig().getCoreConfig().getCron());
+ JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob(JobConfigurationGsonFactory.fromJson(data).getCron());
}
}
}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationGsonTypeAdapter.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationGsonTypeAdapter.java
index d85cec0..0071513 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationGsonTypeAdapter.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationGsonTypeAdapter.java
@@ -17,18 +17,15 @@
package org.apache.shardingsphere.elasticjob.lite.internal.config.json;
-import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import org.apache.shardingsphere.elasticjob.lite.api.JobType;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration.Builder;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import java.io.IOException;
import java.util.HashMap;
@@ -61,60 +58,53 @@ public final class JobConfigurationGsonTypeAdapter extends TypeAdapter<JobConfig
}
}
in.endObject();
- JobCoreConfiguration coreConfig = createJobCoreConfiguration((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_NAME.getJsonName()),
- (String) jsonValueMap.get(JobConfigurationJsonEnum.CRON.getJsonName()), (int) jsonValueMap.getOrDefault(JobConfigurationJsonEnum.SHARDING_TOTAL_COUNT.getJsonName(), 0),
- (String) jsonValueMap.get(JobConfigurationJsonEnum.SHARDING_ITEM_PARAMETERS.getJsonName()), (String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_PARAMETER.getJsonName()),
- (boolean) jsonValueMap.getOrDefault(JobConfigurationJsonEnum.FAILOVER.getJsonName(), false),
- (boolean) jsonValueMap.getOrDefault(JobConfigurationJsonEnum.MISFIRE.getJsonName(), false),
- (String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_EXECUTOR_SERVICE_HANDLER_TYPE.getJsonName()),
- (String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_ERROR_HANDLER_TYPE.getJsonName()),
- (String) jsonValueMap.get(JobConfigurationJsonEnum.DESCRIPTION.getJsonName()));
- JobTypeConfiguration typeConfig = createJobTypeConfiguration(coreConfig, JobType.valueOf((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_TYPE.getJsonName())),
- (boolean) jsonValueMap.getOrDefault(JobConfigurationJsonEnum.STREAMING_PROCESS.getJsonName(), false),
- (String) jsonValueMap.getOrDefault(JobConfigurationJsonEnum.SCRIPT_COMMAND_LINE.getJsonName(), ""));
- return createJobRootConfiguration(typeConfig, jsonValueMap);
+ return createJobConfiguration(jsonValueMap);
}
- private JobCoreConfiguration createJobCoreConfiguration(final String jobName, final String cron, final int shardingTotalCount,
- final String shardingItemParameters, final String jobParameter, final boolean failover,
- final boolean misfire, final String jobExecutorServiceHandlerType, final String jobErrorHandlerType, final String description) {
- return JobCoreConfiguration.newBuilder(jobName, cron, shardingTotalCount)
- .shardingItemParameters(shardingItemParameters).jobParameter(jobParameter).failover(failover).misfire(misfire).description(description)
- .jobExecutorServiceHandlerType(jobExecutorServiceHandlerType)
- .jobErrorHandlerType(jobErrorHandlerType)
- .build();
- }
-
- private JobTypeConfiguration createJobTypeConfiguration(final JobCoreConfiguration coreConfig, final JobType jobType, final boolean streamingProcess, final String scriptCommandLine) {
- Preconditions.checkNotNull(jobType, "jobType cannot be null.");
- switch (jobType) {
- case SIMPLE:
- return new SimpleJobConfiguration(coreConfig);
- case DATAFLOW:
- return new DataflowJobConfiguration(coreConfig, streamingProcess);
- case SCRIPT:
- return new ScriptJobConfiguration(coreConfig, scriptCommandLine);
- default:
- throw new UnsupportedOperationException(String.valueOf(jobType));
+ private JobConfiguration createJobConfiguration(final Map<String, Object> jsonValueMap) {
+ JobType jobType = JobType.valueOf((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_TYPE.getJsonName()));
+ Builder builder = JobConfiguration.newBuilder((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_NAME.getJsonName()), jobType,
+ (String) jsonValueMap.get(JobConfigurationJsonEnum.CRON.getJsonName()), (int) jsonValueMap.getOrDefault(JobConfigurationJsonEnum.SHARDING_TOTAL_COUNT.getJsonName(), 0));
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.SHARDING_ITEM_PARAMETERS.getJsonName())) {
+ builder.shardingItemParameters(jsonValueMap.get(JobConfigurationJsonEnum.SHARDING_ITEM_PARAMETERS.getJsonName()).toString());
+ }
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.JOB_PARAMETER.getJsonName())) {
+ builder.jobParameter(jsonValueMap.get(JobConfigurationJsonEnum.JOB_PARAMETER.getJsonName()).toString());
}
- }
-
- private JobConfiguration createJobRootConfiguration(final JobTypeConfiguration typeConfig, final Map<String, Object> jsonValueMap) {
- JobConfiguration.Builder builder = JobConfiguration.newBuilder(typeConfig);
if (jsonValueMap.containsKey(JobConfigurationJsonEnum.MONITOR_EXECUTION.getJsonName())) {
builder.monitorExecution((boolean) jsonValueMap.get(JobConfigurationJsonEnum.MONITOR_EXECUTION.getJsonName()));
}
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.FAILOVER.getJsonName())) {
+ builder.failover((boolean) jsonValueMap.get(JobConfigurationJsonEnum.FAILOVER.getJsonName()));
+ }
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.MISFIRE.getJsonName())) {
+ builder.misfire((boolean) jsonValueMap.get(JobConfigurationJsonEnum.MISFIRE.getJsonName()));
+ }
if (jsonValueMap.containsKey(JobConfigurationJsonEnum.MAX_TIME_DIFF_SECONDS.getJsonName())) {
builder.maxTimeDiffSeconds((int) jsonValueMap.get(JobConfigurationJsonEnum.MAX_TIME_DIFF_SECONDS.getJsonName()));
}
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.RECONCILE_INTERVAL_MINUTES.getJsonName())) {
+ builder.reconcileIntervalMinutes((int) jsonValueMap.get(JobConfigurationJsonEnum.RECONCILE_INTERVAL_MINUTES.getJsonName()));
+ }
if (jsonValueMap.containsKey(JobConfigurationJsonEnum.MONITOR_PORT.getJsonName())) {
builder.monitorPort((int) jsonValueMap.get(JobConfigurationJsonEnum.MONITOR_PORT.getJsonName()));
}
if (jsonValueMap.containsKey(JobConfigurationJsonEnum.JOB_SHARDING_STRATEGY_TYPE.getJsonName())) {
builder.jobShardingStrategyType((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_SHARDING_STRATEGY_TYPE.getJsonName()));
}
- if (jsonValueMap.containsKey(JobConfigurationJsonEnum.RECONCILE_INTERVAL_MINUTES.getJsonName())) {
- builder.reconcileIntervalMinutes((int) jsonValueMap.get(JobConfigurationJsonEnum.RECONCILE_INTERVAL_MINUTES.getJsonName()));
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.JOB_EXECUTOR_SERVICE_HANDLER_TYPE.getJsonName())) {
+ builder.jobExecutorServiceHandlerType((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_EXECUTOR_SERVICE_HANDLER_TYPE.getJsonName()));
+ }
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.JOB_ERROR_HANDLER_TYPE.getJsonName())) {
+ builder.jobErrorHandlerType((String) jsonValueMap.get(JobConfigurationJsonEnum.JOB_ERROR_HANDLER_TYPE.getJsonName()));
+ }
+ if (jsonValueMap.containsKey(JobConfigurationJsonEnum.DESCRIPTION.getJsonName())) {
+ builder.description((String) jsonValueMap.get(JobConfigurationJsonEnum.DESCRIPTION.getJsonName()));
+ }
+ if (JobType.DATAFLOW == jobType) {
+ builder.setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, jsonValueMap.getOrDefault(JobConfigurationJsonEnum.STREAMING_PROCESS.getJsonName(), false).toString());
+ } else if (JobType.SCRIPT == jobType) {
+ builder.setProperty(ScriptJobExecutor.SCRIPT_KEY, jsonValueMap.getOrDefault(JobConfigurationJsonEnum.SCRIPT_COMMAND_LINE.getJsonName(), "").toString());
}
if (jsonValueMap.containsKey(JobConfigurationJsonEnum.DISABLED.getJsonName())) {
builder.disabled((boolean) jsonValueMap.get(JobConfigurationJsonEnum.DISABLED.getJsonName()));
@@ -128,26 +118,26 @@ public final class JobConfigurationGsonTypeAdapter extends TypeAdapter<JobConfig
@Override
public void write(final JsonWriter out, final JobConfiguration value) throws IOException {
out.beginObject();
- out.name(JobConfigurationJsonEnum.JOB_NAME.getJsonName()).value(value.getTypeConfig().getCoreConfig().getJobName());
- out.name(JobConfigurationJsonEnum.JOB_TYPE.getJsonName()).value(value.getTypeConfig().getJobType().name());
- out.name(JobConfigurationJsonEnum.CRON.getJsonName()).value(value.getTypeConfig().getCoreConfig().getCron());
- out.name(JobConfigurationJsonEnum.SHARDING_TOTAL_COUNT.getJsonName()).value(value.getTypeConfig().getCoreConfig().getShardingTotalCount());
- out.name(JobConfigurationJsonEnum.SHARDING_ITEM_PARAMETERS.getJsonName()).value(value.getTypeConfig().getCoreConfig().getShardingItemParameters());
- out.name(JobConfigurationJsonEnum.JOB_PARAMETER.getJsonName()).value(value.getTypeConfig().getCoreConfig().getJobParameter());
- out.name(JobConfigurationJsonEnum.FAILOVER.getJsonName()).value(value.getTypeConfig().getCoreConfig().isFailover());
- out.name(JobConfigurationJsonEnum.MISFIRE.getJsonName()).value(value.getTypeConfig().getCoreConfig().isMisfire());
- if (!Strings.isNullOrEmpty(value.getTypeConfig().getCoreConfig().getJobExecutorServiceHandlerType())) {
- out.name(JobConfigurationJsonEnum.JOB_EXECUTOR_SERVICE_HANDLER_TYPE.getJsonName()).value(value.getTypeConfig().getCoreConfig().getJobExecutorServiceHandlerType());
- }
- if (!Strings.isNullOrEmpty(value.getTypeConfig().getCoreConfig().getJobErrorHandlerType())) {
- out.name(JobConfigurationJsonEnum.JOB_ERROR_HANDLER_TYPE.getJsonName()).value(value.getTypeConfig().getCoreConfig().getJobErrorHandlerType());
- }
- out.name(JobConfigurationJsonEnum.DESCRIPTION.getJsonName()).value(value.getTypeConfig().getCoreConfig().getDescription());
- if (value.getTypeConfig().getJobType() == JobType.DATAFLOW) {
- out.name(JobConfigurationJsonEnum.STREAMING_PROCESS.getJsonName()).value(((DataflowJobConfiguration) value.getTypeConfig()).isStreamingProcess());
- } else if (value.getTypeConfig().getJobType() == JobType.SCRIPT) {
- ScriptJobConfiguration scriptJobConfig = (ScriptJobConfiguration) value.getTypeConfig();
- out.name(JobConfigurationJsonEnum.SCRIPT_COMMAND_LINE.getJsonName()).value(scriptJobConfig.getScriptCommandLine());
+ out.name(JobConfigurationJsonEnum.JOB_NAME.getJsonName()).value(value.getJobName());
+ out.name(JobConfigurationJsonEnum.JOB_TYPE.getJsonName()).value(value.getJobType().name());
+ out.name(JobConfigurationJsonEnum.CRON.getJsonName()).value(value.getCron());
+ out.name(JobConfigurationJsonEnum.SHARDING_TOTAL_COUNT.getJsonName()).value(value.getShardingTotalCount());
+ out.name(JobConfigurationJsonEnum.SHARDING_ITEM_PARAMETERS.getJsonName()).value(value.getShardingItemParameters());
+ out.name(JobConfigurationJsonEnum.JOB_PARAMETER.getJsonName()).value(value.getJobParameter());
+ out.name(JobConfigurationJsonEnum.FAILOVER.getJsonName()).value(value.isFailover());
+ out.name(JobConfigurationJsonEnum.MISFIRE.getJsonName()).value(value.isMisfire());
+ if (!Strings.isNullOrEmpty(value.getJobExecutorServiceHandlerType())) {
+ out.name(JobConfigurationJsonEnum.JOB_EXECUTOR_SERVICE_HANDLER_TYPE.getJsonName()).value(value.getJobExecutorServiceHandlerType());
+ }
+ if (!Strings.isNullOrEmpty(value.getJobErrorHandlerType())) {
+ out.name(JobConfigurationJsonEnum.JOB_ERROR_HANDLER_TYPE.getJsonName()).value(value.getJobErrorHandlerType());
+ }
+ out.name(JobConfigurationJsonEnum.DESCRIPTION.getJsonName()).value(value.getDescription());
+ if (JobType.DATAFLOW == value.getJobType()) {
+ out.name(JobConfigurationJsonEnum.STREAMING_PROCESS.getJsonName()).value(
+ Boolean.valueOf(value.getProps().getOrDefault(DataflowJobExecutor.STREAM_PROCESS_KEY, false).toString()));
+ } else if (JobType.SCRIPT == value.getJobType()) {
+ out.name(JobConfigurationJsonEnum.SCRIPT_COMMAND_LINE.getJsonName()).value(value.getProps().getProperty(ScriptJobExecutor.SCRIPT_KEY));
}
out.name(JobConfigurationJsonEnum.MONITOR_EXECUTION.getJsonName()).value(value.isMonitorExecution());
out.name(JobConfigurationJsonEnum.MAX_TIME_DIFF_SECONDS.getJsonName()).value(value.getMaxTimeDiffSeconds());
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationJsonEnum.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationJsonEnum.java
index 11eaea2..4e17403 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationJsonEnum.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/config/json/JobConfigurationJsonEnum.java
@@ -42,23 +42,23 @@ public enum JobConfigurationJsonEnum {
JOB_PARAMETER("jobParameter", String.class),
+ MONITOR_EXECUTION("monitorExecution", boolean.class),
+
FAILOVER("failover", boolean.class),
MISFIRE("misfire", boolean.class),
- JOB_EXECUTOR_SERVICE_HANDLER_TYPE("jobExecutorServiceHandlerType", String.class),
-
- JOB_ERROR_HANDLER_TYPE("jobErrorHandlerType", String.class),
-
- MONITOR_EXECUTION("monitorExecution", boolean.class),
-
MAX_TIME_DIFF_SECONDS("maxTimeDiffSeconds", int.class),
+ RECONCILE_INTERVAL_MINUTES("reconcileIntervalMinutes", int.class),
+
MONITOR_PORT("monitorPort", int.class),
JOB_SHARDING_STRATEGY_TYPE("jobShardingStrategyType", String.class),
- RECONCILE_INTERVAL_MINUTES("reconcileIntervalMinutes", int.class),
+ JOB_EXECUTOR_SERVICE_HANDLER_TYPE("jobExecutorServiceHandlerType", String.class),
+
+ JOB_ERROR_HANDLER_TYPE("jobErrorHandlerType", String.class),
DESCRIPTION("description", String.class),
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeService.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeService.java
index b1e28c9..e6db406 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeService.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeService.java
@@ -55,7 +55,7 @@ public final class GuaranteeService {
*/
public boolean isAllStarted() {
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.STARTED_ROOT)
- && configService.load(false).getTypeConfig().getCoreConfig().getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.STARTED_ROOT).size();
+ && configService.load(false).getShardingTotalCount() == jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.STARTED_ROOT).size();
}
/**
@@ -83,7 +83,7 @@ public final class GuaranteeService {
*/
public boolean isAllCompleted() {
return jobNodeStorage.isJobNodeExisted(GuaranteeNode.COMPLETED_ROOT)
- && configService.load(false).getTypeConfig().getCoreConfig().getShardingTotalCount() <= jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.COMPLETED_ROOT).size();
+ && configService.load(false).getShardingTotalCount() <= jobNodeStorage.getJobNodeChildrenKeys(GuaranteeNode.COMPLETED_ROOT).size();
}
/**
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacade.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacade.java
index d3ec631..1bcf81e 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacade.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacade.java
@@ -19,24 +19,25 @@ package org.apache.shardingsphere.elasticjob.lite.internal.schedule;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.api.listener.ElasticJobListener;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.lite.tracing.JobEventBus;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent.Source;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent.State;
import org.apache.shardingsphere.elasticjob.lite.exception.JobExecutionEnvironmentException;
import org.apache.shardingsphere.elasticjob.lite.executor.JobFacade;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.failover.FailoverService;
import org.apache.shardingsphere.elasticjob.lite.internal.sharding.ExecutionContextService;
import org.apache.shardingsphere.elasticjob.lite.internal.sharding.ExecutionService;
import org.apache.shardingsphere.elasticjob.lite.internal.sharding.ShardingService;
import org.apache.shardingsphere.elasticjob.lite.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.lite.tracing.JobEventBus;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent.Source;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent.State;
import java.util.Collection;
import java.util.List;
@@ -131,14 +132,15 @@ public final class LiteJobFacade implements JobFacade {
@Override
public boolean isExecuteMisfired(final Collection<Integer> shardingItems) {
- return isEligibleForJobRunning() && configService.load(true).getTypeConfig().getCoreConfig().isMisfire() && !executionService.getMisfiredJobItems(shardingItems).isEmpty();
+ return isEligibleForJobRunning() && configService.load(true).isMisfire() && !executionService.getMisfiredJobItems(shardingItems).isEmpty();
}
@Override
public boolean isEligibleForJobRunning() {
JobConfiguration jobConfig = configService.load(true);
- if (jobConfig.getTypeConfig() instanceof DataflowJobConfiguration) {
- return !shardingService.isNeedSharding() && ((DataflowJobConfiguration) jobConfig.getTypeConfig()).isStreamingProcess();
+ if (JobType.DATAFLOW == jobConfig.getJobType()) {
+ return !shardingService.isNeedSharding()
+ && Boolean.parseBoolean(jobConfig.getProps().getOrDefault(DataflowJobExecutor.STREAM_PROCESS_KEY, false).toString());
}
return !shardingService.isNeedSharding();
}
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java
index 67a80ca..4daa702 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextService.java
@@ -60,12 +60,12 @@ public final class ExecutionContextService {
JobConfiguration jobConfig = configService.load(false);
removeRunningIfMonitorExecution(jobConfig.isMonitorExecution(), shardingItems);
if (shardingItems.isEmpty()) {
- return new ShardingContexts(buildTaskId(jobConfig, shardingItems), jobConfig.getJobName(), jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(),
- jobConfig.getTypeConfig().getCoreConfig().getJobParameter(), Collections.emptyMap());
+ return new ShardingContexts(buildTaskId(jobConfig, shardingItems), jobConfig.getJobName(), jobConfig.getShardingTotalCount(),
+ jobConfig.getJobParameter(), Collections.emptyMap());
}
- Map<Integer, String> shardingItemParameterMap = new ShardingItemParameters(jobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters()).getMap();
- return new ShardingContexts(buildTaskId(jobConfig, shardingItems), jobConfig.getJobName(), jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(),
- jobConfig.getTypeConfig().getCoreConfig().getJobParameter(), getAssignedShardingItemParameterMap(shardingItems, shardingItemParameterMap));
+ Map<Integer, String> shardingItemParameterMap = new ShardingItemParameters(jobConfig.getShardingItemParameters()).getMap();
+ return new ShardingContexts(buildTaskId(jobConfig, shardingItems), jobConfig.getJobName(), jobConfig.getShardingTotalCount(),
+ jobConfig.getJobParameter(), getAssignedShardingItemParameterMap(shardingItems, shardingItemParameterMap));
}
private String buildTaskId(final JobConfiguration jobConfig, final List<Integer> shardingItems) {
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionService.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionService.java
index 910b982..2add54a 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionService.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionService.java
@@ -122,7 +122,7 @@ public final class ExecutionService {
}
private List<Integer> getAllItems() {
- int shardingTotalCount = configService.load(true).getTypeConfig().getCoreConfig().getShardingTotalCount();
+ int shardingTotalCount = configService.load(true).getShardingTotalCount();
List<Integer> result = new ArrayList<>(shardingTotalCount);
for (int i = 0; i < shardingTotalCount; i++) {
result.add(i);
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingListenerManager.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingListenerManager.java
index 037c6fd..821f828 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingListenerManager.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingListenerManager.java
@@ -62,7 +62,7 @@ public final class ShardingListenerManager extends AbstractListenerManager {
@Override
protected void dataChanged(final String path, final Type eventType, final String data) {
if (configNode.isConfigPath(path) && 0 != JobRegistry.getInstance().getCurrentShardingTotalCount(jobName)) {
- int newShardingTotalCount = JobConfigurationGsonFactory.fromJson(data).getTypeConfig().getCoreConfig().getShardingTotalCount();
+ int newShardingTotalCount = JobConfigurationGsonFactory.fromJson(data).getShardingTotalCount();
if (newShardingTotalCount != JobRegistry.getInstance().getCurrentShardingTotalCount(jobName)) {
shardingService.setReshardingFlag();
JobRegistry.getInstance().setCurrentShardingTotalCount(jobName, newShardingTotalCount);
diff --git a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingService.java b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingService.java
index 83cf11b..5551b5c 100644
--- a/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingService.java
+++ b/elastic-job-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingService.java
@@ -109,7 +109,7 @@ public final class ShardingService {
}
waitingOtherShardingItemCompleted();
JobConfiguration jobConfig = configService.load(false);
- int shardingTotalCount = jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount();
+ int shardingTotalCount = jobConfig.getShardingTotalCount();
log.debug("Job '{}' sharding begin.", jobName);
jobNodeStorage.fillEphemeralJobNode(ShardingNode.PROCESSING, "");
resetShardingInfo(shardingTotalCount);
@@ -157,7 +157,7 @@ public final class ShardingService {
return Collections.emptyList();
}
List<Integer> result = new LinkedList<>();
- int shardingTotalCount = configService.load(true).getTypeConfig().getCoreConfig().getShardingTotalCount();
+ int shardingTotalCount = configService.load(true).getShardingTotalCount();
for (int i = 0; i < shardingTotalCount; i++) {
if (jobInstance.getJobInstanceId().equals(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(i)))) {
result.add(i);
@@ -185,7 +185,7 @@ public final class ShardingService {
*/
public boolean hasShardingInfoInOfflineServers() {
List<String> onlineInstances = jobNodeStorage.getJobNodeChildrenKeys(InstanceNode.ROOT);
- int shardingTotalCount = configService.load(true).getTypeConfig().getCoreConfig().getShardingTotalCount();
+ int shardingTotalCount = configService.load(true).getShardingTotalCount();
for (int i = 0; i < shardingTotalCount; i++) {
if (!onlineInstances.contains(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(i)))) {
return true;
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/api/JobSchedulerTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/api/JobSchedulerTest.java
index ca63db5..2f3790f 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/api/JobSchedulerTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/api/JobSchedulerTest.java
@@ -17,9 +17,7 @@
package org.apache.shardingsphere.elasticjob.lite.api;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.fixture.TestSimpleJob;
import org.apache.shardingsphere.elasticjob.lite.handler.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
@@ -58,7 +56,7 @@ public final class JobSchedulerTest {
@Before
public void setUp() {
JobRegistry.getInstance().addJobInstance("test_job", new JobInstance("127.0.0.1@-@0"));
- jobConfig = JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "* * 0/10 * * ? 2050", 3).build())).build();
+ jobConfig = JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "* * 0/10 * * ? 2050", 3).build();
jobScheduler = new JobScheduler(regCenter, new TestSimpleJob(), jobConfig);
ReflectionUtils.setFieldValue(jobScheduler, "regCenter", regCenter);
ReflectionUtils.setFieldValue(jobScheduler, "schedulerFacade", schedulerFacade);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfigurationTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfigurationTest.java
index d67aa69..a780f00 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfigurationTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobConfigurationTest.java
@@ -17,11 +17,12 @@
package org.apache.shardingsphere.elasticjob.lite.config;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -29,44 +30,75 @@ public final class JobConfigurationTest {
@Test
public void assertBuildAllProperties() {
- JobConfiguration actual = JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build()))
- .monitorExecution(false).maxTimeDiffSeconds(1000).monitorPort(8888).jobShardingStrategyType("AVG_ALLOCATION").disabled(true).overwrite(true).reconcileIntervalMinutes(60).build();
+ JobConfiguration actual = JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3)
+ .shardingItemParameters("0=a,1=b,2=c").jobParameter("param")
+ .monitorExecution(false).failover(true).misfire(false)
+ .maxTimeDiffSeconds(1000).reconcileIntervalMinutes(60).monitorPort(8888)
+ .jobShardingStrategyType("AVG_ALLOCATION").jobExecutorServiceHandlerType("SINGLE_THREAD").jobErrorHandlerType("IGNORE")
+ .description("desc").setProperty("key", "value")
+ .disabled(true).overwrite(true).build();
+ assertThat(actual.getJobName(), is("test_job"));
+ assertThat(actual.getJobType(), is(JobType.SIMPLE));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
+ assertThat(actual.getShardingItemParameters(), is("0=a,1=b,2=c"));
+ assertThat(actual.getJobParameter(), is("param"));
assertFalse(actual.isMonitorExecution());
+ assertTrue(actual.isFailover());
+ assertFalse(actual.isMisfire());
assertThat(actual.getMaxTimeDiffSeconds(), is(1000));
+ assertThat(actual.getReconcileIntervalMinutes(), is(60));
assertThat(actual.getMonitorPort(), is(8888));
assertThat(actual.getJobShardingStrategyType(), is("AVG_ALLOCATION"));
+ assertThat(actual.getJobExecutorServiceHandlerType(), is("SINGLE_THREAD"));
+ assertThat(actual.getJobErrorHandlerType(), is("IGNORE"));
+ assertThat(actual.getDescription(), is("desc"));
+ assertThat(actual.getProps().getProperty("key"), is("value"));
assertTrue(actual.isDisabled());
assertTrue(actual.isOverwrite());
- assertThat(actual.getReconcileIntervalMinutes(), is(60));
}
@Test
public void assertBuildRequiredProperties() {
- JobConfiguration actual = JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build();
+ JobConfiguration actual = JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build();
+ assertThat(actual.getJobName(), is("test_job"));
+ assertThat(actual.getJobType(), is(JobType.SIMPLE));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
+ assertThat(actual.getShardingItemParameters(), is(""));
+ assertThat(actual.getJobParameter(), is(""));
assertTrue(actual.isMonitorExecution());
+ assertFalse(actual.isFailover());
+ assertTrue(actual.isMisfire());
assertThat(actual.getMaxTimeDiffSeconds(), is(-1));
+ assertThat(actual.getReconcileIntervalMinutes(), is(10));
assertThat(actual.getMonitorPort(), is(-1));
assertThat(actual.getJobShardingStrategyType(), is(""));
+ assertNull(actual.getJobExecutorServiceHandlerType());
+ assertNull(actual.getJobErrorHandlerType());
+ assertThat(actual.getDescription(), is(""));
+ assertTrue(actual.getProps().isEmpty());
assertFalse(actual.isDisabled());
assertFalse(actual.isOverwrite());
}
- @Test
- public void assertBuildWhenOptionalParametersIsNull() {
- assertThat(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder(
- "test_job", "0/1 * * * * ?", 3).build())).jobShardingStrategyType(null).build().getJobShardingStrategyType(), is(""));
+ @Test(expected = IllegalArgumentException.class)
+ public void assertBuildWithEmptyJobName() {
+ JobConfiguration.newBuilder("", JobType.SIMPLE, "0/1 * * * * ?", 3).build();
}
- @Test
- public void assertIsNotFailover() {
- assertFalse(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build())).monitorExecution(false).build().isFailover());
+ @Test(expected = NullPointerException.class)
+ public void assertBuildWithNullJobType() {
+ JobConfiguration.newBuilder("test_job", null, "0/1 * * * * ?", 3).build();
}
- @Test
- public void assertIsFailover() {
- assertTrue(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).monitorExecution(true).build().isFailover());
+ @Test(expected = IllegalArgumentException.class)
+ public void assertBuildWithEmptyCron() {
+ JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "", 3).build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void assertBuildWithInvalidShardingTotalCount() {
+ JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", -1).build();
}
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobCoreConfigurationTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobCoreConfigurationTest.java
deleted file mode 100644
index 0d93f25..0000000
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/config/JobCoreConfigurationTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.shardingsphere.elasticjob.lite.config;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class JobCoreConfigurationTest {
-
- @Test
- public void assertBuildAllProperties() {
- JobCoreConfiguration actual = JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3)
- .shardingItemParameters("0=a,1=b,2=c").jobParameter("param").failover(true).misfire(false).jobErrorHandlerType("IGNORE").description("desc").build();
- assertRequiredProperties(actual);
- assertThat(actual.getShardingItemParameters(), is("0=a,1=b,2=c"));
- assertThat(actual.getJobParameter(), is("param"));
- assertTrue(actual.isFailover());
- assertFalse(actual.isMisfire());
- assertThat(actual.getDescription(), is("desc"));
- }
-
- @Test
- public void assertBuildRequiredProperties() {
- JobCoreConfiguration actual = JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build();
- assertRequiredProperties(actual);
- assertDefaultValues(actual);
- }
-
- @Test
- public void assertBuildWhenOptionalParametersIsNull() {
- //noinspection NullArgumentToVariableArgMethod
- JobCoreConfiguration actual = JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).shardingItemParameters(null).jobParameter(null).description(null).build();
- assertRequiredProperties(actual);
- assertDefaultValues(actual);
- }
-
- private void assertRequiredProperties(final JobCoreConfiguration actual) {
- assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getShardingTotalCount(), is(3));
- }
-
- private void assertDefaultValues(final JobCoreConfiguration actual) {
- assertThat(actual.getShardingItemParameters(), is(""));
- assertThat(actual.getJobParameter(), is(""));
- assertFalse(actual.isFailover());
- assertTrue(actual.isMisfire());
- assertThat(actual.getDescription(), is(""));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWhenJobNameIsNull() {
- JobCoreConfiguration.newBuilder(null, "0/1 * * * * ?", 3).build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWhenCronIsNull() {
- JobCoreConfiguration.newBuilder("test_job", null, 3).build();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void assertBuildWhenTotalSHardingCountIsNegative() {
- JobCoreConfiguration.newBuilder(null, "0/1 * * * * ?", -1).build();
- }
-}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutorTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutorTest.java
index 6dc0efd..4c22e1e 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutorTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/DataflowJobExecutorTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.elasticjob.lite.executor.type.impl;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.ElasticJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.executor.JobFacade;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
@@ -171,8 +170,8 @@ public final class DataflowJobExecutorTest {
private void setUp(final boolean isStreamingProcess, final ShardingContexts shardingContexts) {
this.shardingContexts = shardingContexts;
- JobConfiguration jobConfig = JobConfiguration.newBuilder(
- new DataflowJobConfiguration(JobCoreConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, "0/1 * * * * ?", 3).jobErrorHandlerType("IGNORE").build(), isStreamingProcess)).build();
+ JobConfiguration jobConfig = JobConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, JobType.DATAFLOW, "0/1 * * * * ?", 3)
+ .jobErrorHandlerType("IGNORE").setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.toString(isStreamingProcess)).build();
when(jobFacade.loadJobConfiguration(true)).thenReturn(jobConfig);
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
elasticJobExecutor = new ElasticJobExecutor(new TestDataflowJob(jobCaller), jobFacade);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutorTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutorTest.java
index 9f9d4b7..c4371ad 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutorTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/ScriptJobExecutorTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.elasticjob.lite.executor.type.impl;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.exception.JobSystemException;
import org.apache.shardingsphere.elasticjob.lite.executor.ElasticJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.executor.JobFacade;
@@ -85,7 +84,7 @@ public final class ScriptJobExecutorTest {
}
private JobConfiguration createJobConfiguration(final String scriptCommandLine, final String jobErrorHandlerType) {
- return JobConfiguration.newBuilder(new ScriptJobConfiguration(
- JobCoreConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, "0/1 * * * * ?", 3).jobErrorHandlerType(jobErrorHandlerType).build(), scriptCommandLine)).build();
+ return JobConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, JobType.SCRIPT, "0/1 * * * * ?", 3)
+ .jobErrorHandlerType(jobErrorHandlerType).setProperty(ScriptJobExecutor.SCRIPT_KEY, scriptCommandLine).build();
}
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/SimpleJobExecutorTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/SimpleJobExecutorTest.java
index fade827..cac00b5 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/SimpleJobExecutorTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/SimpleJobExecutorTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.elasticjob.lite.executor.type.impl;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.exception.JobExecutionEnvironmentException;
import org.apache.shardingsphere.elasticjob.lite.exception.JobSystemException;
import org.apache.shardingsphere.elasticjob.lite.executor.ElasticJobExecutor;
@@ -65,9 +64,9 @@ public final class SimpleJobExecutorTest {
}
private JobConfiguration createJobConfiguration(final String jobExecutorServiceHandlerType, final String jobErrorHandlerType) {
- return JobConfiguration.newBuilder(new SimpleJobConfiguration(
- JobCoreConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, "0/1 * * * * ?", 3).shardingItemParameters("0=A,1=B,2=C").jobParameter("param")
- .failover(true).misfire(false).jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).jobErrorHandlerType(jobErrorHandlerType).description("desc").build())).build();
+ return JobConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, JobType.SIMPLE, "0/1 * * * * ?", 3)
+ .shardingItemParameters("0=A,1=B,2=C").jobParameter("param").failover(true).misfire(false)
+ .jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).jobErrorHandlerType(jobErrorHandlerType).description("desc").build();
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/WrongJobExecutorTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/WrongJobExecutorTest.java
index 64dd9b0..86f94aa 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/WrongJobExecutorTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/executor/type/impl/WrongJobExecutorTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.elasticjob.lite.executor.type.impl;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.ElasticJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.executor.JobFacade;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
@@ -53,9 +52,8 @@ public final class WrongJobExecutorTest {
}
private JobConfiguration createJobConfiguration() {
- return JobConfiguration.newBuilder(new SimpleJobConfiguration(
- JobCoreConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, "0/1 * * * * ?", 3).shardingItemParameters("0=A,1=B,2=C").jobParameter("param")
- .failover(true).misfire(false).jobExecutorServiceHandlerType(null).jobErrorHandlerType("THROW").description("desc").build())).build();
+ return JobConfiguration.newBuilder(ShardingContextsBuilder.JOB_NAME, JobType.SIMPLE, "0/1 * * * * ?", 3)
+ .shardingItemParameters("0=A,1=B,2=C").jobParameter("param").failover(true).misfire(false).jobErrorHandlerType("THROW").description("desc").build();
}
@Test(expected = RuntimeException.class)
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/util/JobConfigurationUtil.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/util/JobConfigurationUtil.java
index 722de9a..731418f 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/util/JobConfigurationUtil.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/util/JobConfigurationUtil.java
@@ -19,9 +19,8 @@ package org.apache.shardingsphere.elasticjob.lite.fixture.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class JobConfigurationUtil {
@@ -32,7 +31,7 @@ public final class JobConfigurationUtil {
* @return job configuration
*/
public static JobConfiguration createSimpleJobConfiguration() {
- return JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build();
+ return JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build();
}
/**
@@ -42,6 +41,6 @@ public final class JobConfigurationUtil {
* @return job configuration
*/
public static JobConfiguration createSimpleJobConfiguration(final boolean overwrite) {
- return JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).overwrite(overwrite).build();
+ return JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).overwrite(overwrite).build();
}
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/AbstractBaseStdJobTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/AbstractBaseStdJobTest.java
index 1276ee6..98743f7 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/AbstractBaseStdJobTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/AbstractBaseStdJobTest.java
@@ -22,17 +22,16 @@ import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.lite.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.api.dataflow.DataflowJob;
import org.apache.shardingsphere.elasticjob.lite.api.listener.AbstractDistributeOnceElasticJobListener;
import org.apache.shardingsphere.elasticjob.lite.api.listener.ElasticJobListener;
import org.apache.shardingsphere.elasticjob.lite.api.script.ScriptJob;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.JobTypeConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration.Builder;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.fixture.EmbedTestingServer;
import org.apache.shardingsphere.elasticjob.lite.internal.config.json.JobConfigurationGsonFactory;
import org.apache.shardingsphere.elasticjob.lite.internal.election.LeaderService;
@@ -116,16 +115,24 @@ public abstract class AbstractBaseStdJobTest {
String cron = "0/1 * * * * ?";
int totalShardingCount = 3;
String shardingParameters = "0=A,1=B,2=C";
- JobCoreConfiguration jobCoreConfig = JobCoreConfiguration.newBuilder(jobName, cron, totalShardingCount).shardingItemParameters(shardingParameters).jobErrorHandlerType("IGNORE").build();
- JobTypeConfiguration jobTypeConfig;
+ Builder builder = JobConfiguration.newBuilder(jobName, getJobType(elasticJobClass), cron, totalShardingCount).shardingItemParameters(shardingParameters).monitorPort(monitorPort)
+ .jobErrorHandlerType("IGNORE").disabled(disabled).overwrite(true);
if (DataflowJob.class.isAssignableFrom(elasticJobClass)) {
- jobTypeConfig = new DataflowJobConfiguration(jobCoreConfig, false);
+ builder.setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString());
} else if (ScriptJob.class.isAssignableFrom(elasticJobClass)) {
- jobTypeConfig = new ScriptJobConfiguration(jobCoreConfig, AbstractBaseStdJobTest.class.getResource("/script/test.sh").getPath());
- } else {
- jobTypeConfig = new SimpleJobConfiguration(jobCoreConfig);
+ builder.setProperty(ScriptJobExecutor.SCRIPT_KEY, AbstractBaseStdJobTest.class.getResource("/script/test.sh").getPath());
+ }
+ return builder.build();
+ }
+
+ private JobType getJobType(final Class<? extends ElasticJob> elasticJobClass) {
+ if (DataflowJob.class.isAssignableFrom(elasticJobClass)) {
+ return JobType.DATAFLOW;
+ }
+ if (ScriptJob.class.isAssignableFrom(elasticJobClass)) {
+ return JobType.SCRIPT;
}
- return JobConfiguration.newBuilder(jobTypeConfig).monitorPort(monitorPort).disabled(disabled).overwrite(true).build();
+ return JobType.SIMPLE;
}
@BeforeClass
@@ -163,9 +170,9 @@ public abstract class AbstractBaseStdJobTest {
assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(jobName), is(3));
assertThat(JobRegistry.getInstance().getJobInstance(jobName).getIp(), is(IpUtils.getIp()));
JobConfiguration jobConfig = JobConfigurationGsonFactory.fromJson(regCenter.get("/" + jobName + "/config"));
- assertThat(jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
- assertThat(jobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters(), is("0=A,1=B,2=C"));
- assertThat(jobConfig.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
+ assertThat(jobConfig.getShardingTotalCount(), is(3));
+ assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C"));
+ assertThat(jobConfig.getCron(), is("0/1 * * * * ?"));
if (disabled) {
assertThat(regCenter.get("/" + jobName + "/servers/" + JobRegistry.getInstance().getJobInstance(jobName).getIp()), is(ServerStatus.DISABLED.name()));
while (null != regCenter.get("/" + jobName + "/leader/election/instance")) {
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/OneOffDataflowElasticJobTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/OneOffDataflowElasticJobTest.java
index b25a56d..db78ed2 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/OneOffDataflowElasticJobTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/OneOffDataflowElasticJobTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.elasticjob.lite.integrate.std.dataflow;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.integrate.AbstractBaseStdJobAutoInitTest;
import org.apache.shardingsphere.elasticjob.lite.integrate.WaitingUtils;
import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.dataflow.OneOffDataflowElasticJob;
@@ -42,8 +43,8 @@ public final class OneOffDataflowElasticJobTest extends AbstractBaseStdJobAutoIn
@Override
protected void setJobConfiguration(final JobConfiguration jobConfig) {
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig().getCoreConfig(), "misfire", false);
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig(), "streamingProcess", false);
+ ReflectionUtils.setFieldValue(jobConfig, "misfire", false);
+ jobConfig.getProps().setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.FALSE.toString());
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteFailureTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteFailureTest.java
index e17fd46..75b439f 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteFailureTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteFailureTest.java
@@ -42,7 +42,7 @@ public final class StreamingDataflowElasticJobForExecuteFailureTest extends Abst
@Override
protected void setJobConfiguration(final JobConfiguration jobConfig) {
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig(), "streamingProcess", true);
+ ReflectionUtils.setFieldValue(jobConfig, "streamingProcess", true);
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteThrowsExceptionTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteThrowsExceptionTest.java
index 5a005ff..1ee9c2d 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteThrowsExceptionTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForExecuteThrowsExceptionTest.java
@@ -42,7 +42,7 @@ public final class StreamingDataflowElasticJobForExecuteThrowsExceptionTest exte
@Override
protected void setJobConfiguration(final JobConfiguration jobConfig) {
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig(), "streamingProcess", true);
+ ReflectionUtils.setFieldValue(jobConfig, "streamingProcess", true);
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForMultipleThreadsTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForMultipleThreadsTest.java
index 15c005c..22b32d5 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForMultipleThreadsTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForMultipleThreadsTest.java
@@ -42,7 +42,7 @@ public final class StreamingDataflowElasticJobForMultipleThreadsTest extends Abs
@Override
protected void setJobConfiguration(final JobConfiguration jobConfig) {
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig(), "streamingProcess", true);
+ ReflectionUtils.setFieldValue(jobConfig, "streamingProcess", true);
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForNotMonitorTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForNotMonitorTest.java
index 6edbdb6..1b4da28 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForNotMonitorTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobForNotMonitorTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.elasticjob.lite.integrate.std.dataflow;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.integrate.AbstractBaseStdJobAutoInitTest;
import org.apache.shardingsphere.elasticjob.lite.integrate.WaitingUtils;
import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.dataflow.StreamingDataflowElasticJob;
@@ -43,7 +44,7 @@ public final class StreamingDataflowElasticJobForNotMonitorTest extends Abstract
@Override
protected void setJobConfiguration(final JobConfiguration jobConfig) {
ReflectionUtils.setFieldValue(jobConfig, "monitorExecution", false);
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig(), "streamingProcess", true);
+ jobConfig.getProps().setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString());
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobTest.java
index ad33a7e..3bfd135 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/dataflow/StreamingDataflowElasticJobTest.java
@@ -42,7 +42,7 @@ public final class StreamingDataflowElasticJobTest extends AbstractBaseStdJobAut
@Override
protected void setJobConfiguration(final JobConfiguration jobConfig) {
- ReflectionUtils.setFieldValue(jobConfig.getTypeConfig(), "streamingProcess", true);
+ ReflectionUtils.setFieldValue(jobConfig, "streamingProcess", true);
}
@Test
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/script/ScriptElasticJobTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/script/ScriptElasticJobTest.java
index b1b0d1e..ec200b5 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/script/ScriptElasticJobTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/std/script/ScriptElasticJobTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.elasticjob.lite.integrate.std.script;
import org.apache.shardingsphere.elasticjob.lite.api.script.ScriptJob;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.fixture.util.ScriptElasticJobUtil;
import org.apache.shardingsphere.elasticjob.lite.integrate.AbstractBaseStdJobAutoInitTest;
import org.apache.shardingsphere.elasticjob.lite.integrate.WaitingUtils;
@@ -41,8 +41,8 @@ public final class ScriptElasticJobTest extends AbstractBaseStdJobAutoInitTest {
public void assertJobInit() throws IOException {
ScriptElasticJobUtil.buildScriptCommandLine();
WaitingUtils.waitingShortTime();
- String scriptCommandLine = ((ScriptJobConfiguration) getJobConfiguration().getTypeConfig()).getScriptCommandLine();
+ String scriptCommandLine = getJobConfiguration().getProps().getProperty(ScriptJobExecutor.SCRIPT_KEY);
JobConfiguration jobConfig = JobConfigurationGsonFactory.fromJson(getRegCenter().get("/" + getJobName() + "/config"));
- assertThat(((ScriptJobConfiguration) jobConfig.getTypeConfig()).getScriptCommandLine(), is(scriptCommandLine));
+ assertThat(jobConfig.getProps().getProperty(ScriptJobExecutor.SCRIPT_KEY), is(scriptCommandLine));
}
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/ConfigurationServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/ConfigurationServiceTest.java
index 29c5bd0..b6b0b34 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/ConfigurationServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/ConfigurationServiceTest.java
@@ -55,8 +55,8 @@ public final class ConfigurationServiceTest {
when(jobNodeStorage.getJobNodeDataDirectly(ConfigurationNode.ROOT)).thenReturn(LiteJsonConstants.getJobJson());
JobConfiguration actual = configService.load(false);
assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
}
@Test
@@ -64,8 +64,8 @@ public final class ConfigurationServiceTest {
when(jobNodeStorage.getJobNodeData(ConfigurationNode.ROOT)).thenReturn(LiteJsonConstants.getJobJson());
JobConfiguration actual = configService.load(true);
assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
}
@Test
@@ -74,8 +74,8 @@ public final class ConfigurationServiceTest {
when(jobNodeStorage.getJobNodeDataDirectly(ConfigurationNode.ROOT)).thenReturn(LiteJsonConstants.getJobJson());
JobConfiguration actual = configService.load(true);
assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
}
@Test(expected = JobConfigurationException.class)
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/JobConfigurationGsonFactoryTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/JobConfigurationGsonFactoryTest.java
index 1831b46..1cd8e68 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/JobConfigurationGsonFactoryTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/config/JobConfigurationGsonFactoryTest.java
@@ -18,11 +18,9 @@
package org.apache.shardingsphere.elasticjob.lite.internal.config;
import org.apache.shardingsphere.elasticjob.lite.api.JobType;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.internal.config.json.JobConfigurationGsonFactory;
import org.junit.Test;
@@ -54,20 +52,20 @@ public final class JobConfigurationGsonFactoryTest {
@Test
public void assertToJsonForSimpleJob() {
- JobConfiguration actual = JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).misfire(false).build()))
+ JobConfiguration actual = JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).misfire(false)
.monitorExecution(false).maxTimeDiffSeconds(1000).monitorPort(8888).jobShardingStrategyType("AVG_ALLOCATION").disabled(true).overwrite(true).reconcileIntervalMinutes(15).build();
assertThat(JobConfigurationGsonFactory.toJson(actual), is(simpleJobJson));
}
@Test
public void assertToJsonForDataflowJob() {
- JobConfiguration actual = JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), true)).build();
+ JobConfiguration actual = JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).build();
assertThat(JobConfigurationGsonFactory.toJson(actual), is(dataflowJobJson));
}
@Test
public void assertToJsonForScriptJob() {
- JobConfiguration actual = JobConfiguration.newBuilder(new ScriptJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), "test.sh")).build();
+ JobConfiguration actual = JobConfiguration.newBuilder("test_job", JobType.SCRIPT, "0/1 * * * * ?", 3).setProperty(ScriptJobExecutor.SCRIPT_KEY, "test.sh").build();
assertThat(JobConfigurationGsonFactory.toJson(actual), is(scriptJobJson));
}
@@ -75,14 +73,14 @@ public final class JobConfigurationGsonFactoryTest {
public void assertFromJsonForSimpleJob() {
JobConfiguration actual = JobConfigurationGsonFactory.fromJson(simpleJobJson);
assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getTypeConfig().getJobType(), is(JobType.SIMPLE));
- assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingItemParameters(), is(""));
- assertThat(actual.getTypeConfig().getCoreConfig().getJobParameter(), is(""));
- assertTrue(actual.getTypeConfig().getCoreConfig().isFailover());
- assertFalse(actual.getTypeConfig().getCoreConfig().isMisfire());
- assertThat(actual.getTypeConfig().getCoreConfig().getDescription(), is(""));
+ assertThat(actual.getJobType(), is(JobType.SIMPLE));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
+ assertThat(actual.getShardingItemParameters(), is(""));
+ assertThat(actual.getJobParameter(), is(""));
+ assertTrue(actual.isFailover());
+ assertFalse(actual.isMisfire());
+ assertThat(actual.getDescription(), is(""));
assertFalse(actual.isMonitorExecution());
assertThat(actual.getMaxTimeDiffSeconds(), is(1000));
assertThat(actual.getMonitorPort(), is(8888));
@@ -96,14 +94,14 @@ public final class JobConfigurationGsonFactoryTest {
public void assertFromJsonForDataflowJob() {
JobConfiguration actual = JobConfigurationGsonFactory.fromJson(dataflowJobJson);
assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getTypeConfig().getJobType(), is(JobType.DATAFLOW));
- assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingItemParameters(), is(""));
- assertThat(actual.getTypeConfig().getCoreConfig().getJobParameter(), is(""));
- assertFalse(actual.getTypeConfig().getCoreConfig().isFailover());
- assertTrue(actual.getTypeConfig().getCoreConfig().isMisfire());
- assertThat(actual.getTypeConfig().getCoreConfig().getDescription(), is(""));
+ assertThat(actual.getJobType(), is(JobType.DATAFLOW));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
+ assertThat(actual.getShardingItemParameters(), is(""));
+ assertThat(actual.getJobParameter(), is(""));
+ assertFalse(actual.isFailover());
+ assertTrue(actual.isMisfire());
+ assertThat(actual.getDescription(), is(""));
assertTrue(actual.isMonitorExecution());
assertThat(actual.getMaxTimeDiffSeconds(), is(-1));
assertThat(actual.getMonitorPort(), is(-1));
@@ -111,21 +109,21 @@ public final class JobConfigurationGsonFactoryTest {
assertThat(actual.getReconcileIntervalMinutes(), is(10));
assertFalse(actual.isDisabled());
assertFalse(actual.isOverwrite());
- assertTrue(((DataflowJobConfiguration) actual.getTypeConfig()).isStreamingProcess());
+ assertTrue(Boolean.parseBoolean(actual.getProps().get(DataflowJobExecutor.STREAM_PROCESS_KEY).toString()));
}
@Test
public void assertFromJsonForScriptJob() {
JobConfiguration actual = JobConfigurationGsonFactory.fromJson(scriptJobJson);
assertThat(actual.getJobName(), is("test_job"));
- assertThat(actual.getTypeConfig().getJobType(), is(JobType.SCRIPT));
- assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
- assertThat(actual.getTypeConfig().getCoreConfig().getShardingItemParameters(), is(""));
- assertThat(actual.getTypeConfig().getCoreConfig().getJobParameter(), is(""));
- assertFalse(actual.getTypeConfig().getCoreConfig().isFailover());
- assertTrue(actual.getTypeConfig().getCoreConfig().isMisfire());
- assertThat(actual.getTypeConfig().getCoreConfig().getDescription(), is(""));
+ assertThat(actual.getJobType(), is(JobType.SCRIPT));
+ assertThat(actual.getCron(), is("0/1 * * * * ?"));
+ assertThat(actual.getShardingTotalCount(), is(3));
+ assertThat(actual.getShardingItemParameters(), is(""));
+ assertThat(actual.getJobParameter(), is(""));
+ assertFalse(actual.isFailover());
+ assertTrue(actual.isMisfire());
+ assertThat(actual.getDescription(), is(""));
assertTrue(actual.isMonitorExecution());
assertThat(actual.getMaxTimeDiffSeconds(), is(-1));
assertThat(actual.getMonitorPort(), is(-1));
@@ -133,6 +131,6 @@ public final class JobConfigurationGsonFactoryTest {
assertThat(actual.getReconcileIntervalMinutes(), is(10));
assertFalse(actual.isDisabled());
assertFalse(actual.isOverwrite());
- assertThat(((ScriptJobConfiguration) actual.getTypeConfig()).getScriptCommandLine(), is("test.sh"));
+ assertThat(actual.getProps().getProperty(ScriptJobExecutor.SCRIPT_KEY), is("test.sh"));
}
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/failover/FailoverListenerManagerTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/failover/FailoverListenerManagerTest.java
index f7afeb8..59498cd 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/failover/FailoverListenerManagerTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/failover/FailoverListenerManagerTest.java
@@ -18,9 +18,8 @@
package org.apache.shardingsphere.elasticjob.lite.internal.failover;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.fixture.LiteJsonConstants;
import org.apache.shardingsphere.elasticjob.lite.handler.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
@@ -82,16 +81,14 @@ public final class FailoverListenerManagerTest {
@Test
public void assertJobCrashedJobListenerWhenIsNotNodeRemoved() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).build());
failoverListenerManager.new JobCrashedJobListener().dataChanged("/test_job/instances/127.0.0.1@-@0", Type.NODE_ADDED, "");
verify(failoverService, times(0)).failoverIfNecessary();
}
@Test
public void assertJobCrashedJobListenerWhenIsNotInstancesPath() {
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).build());
failoverListenerManager.new JobCrashedJobListener().dataChanged("/test_job/other/127.0.0.1@-@0", Type.NODE_REMOVED, "");
verify(failoverService, times(0)).failoverIfNecessary();
}
@@ -99,8 +96,7 @@ public final class FailoverListenerManagerTest {
@Test
public void assertJobCrashedJobListenerWhenIsSameInstance() {
JobRegistry.getInstance().addJobInstance("test_job", new JobInstance("127.0.0.1@-@0"));
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).build());
failoverListenerManager.new JobCrashedJobListener().dataChanged("/test_job/instances/127.0.0.1@-@0", Type.NODE_REMOVED, "");
verify(failoverService, times(0)).failoverIfNecessary();
JobRegistry.getInstance().shutdown("test_job");
@@ -109,8 +105,7 @@ public final class FailoverListenerManagerTest {
@Test
public void assertJobCrashedJobListenerWhenIsOtherInstanceCrashed() {
JobRegistry.getInstance().addJobInstance("test_job", new JobInstance("127.0.0.1@-@0"));
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).build());
when(shardingService.getShardingItems("127.0.0.1@-@1")).thenReturn(Arrays.asList(0, 2));
failoverListenerManager.new JobCrashedJobListener().dataChanged("/test_job/instances/127.0.0.1@-@1", Type.NODE_REMOVED, "");
verify(failoverService).setCrashedFailoverFlag(0);
@@ -122,8 +117,7 @@ public final class FailoverListenerManagerTest {
@Test
public void assertJobCrashedJobListenerWhenIsOtherFailoverInstanceCrashed() {
JobRegistry.getInstance().addJobInstance("test_job", new JobInstance("127.0.0.1@-@0"));
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).build());
when(failoverService.getFailoverItems("127.0.0.1@-@1")).thenReturn(Collections.singletonList(1));
failoverListenerManager.new JobCrashedJobListener().dataChanged("/test_job/instances/127.0.0.1@-@1", Type.NODE_REMOVED, "");
verify(failoverService).setCrashedFailoverFlag(1);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeServiceTest.java
index 0ac8ce8..71b8225 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/guarantee/GuaranteeServiceTest.java
@@ -17,10 +17,9 @@
package org.apache.shardingsphere.elasticjob.lite.internal.guarantee;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.storage.JobNodeStorage;
import org.apache.shardingsphere.elasticjob.lite.util.ReflectionUtils;
@@ -70,7 +69,7 @@ public final class GuaranteeServiceTest {
@Test
public void assertIsNotAllStarted() {
when(configService.load(false)).thenReturn(
- JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), true)).build());
+ JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).build());
when(jobNodeStorage.isJobNodeExisted("guarantee/started")).thenReturn(true);
when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/started")).thenReturn(Arrays.asList("0", "1"));
assertFalse(guaranteeService.isAllStarted());
@@ -79,7 +78,7 @@ public final class GuaranteeServiceTest {
@Test
public void assertIsAllStarted() {
when(jobNodeStorage.isJobNodeExisted("guarantee/started")).thenReturn(true);
- when(configService.load(false)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/started")).thenReturn(Arrays.asList("0", "1", "2"));
assertTrue(guaranteeService.isAllStarted());
}
@@ -112,7 +111,7 @@ public final class GuaranteeServiceTest {
@Test
public void assertIsAllCompleted() {
when(jobNodeStorage.isJobNodeExisted("guarantee/completed")).thenReturn(true);
- when(configService.load(false)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/completed")).thenReturn(Arrays.asList("0", "1", "2"));
assertTrue(guaranteeService.isAllCompleted());
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/reconcile/ReconcileServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/reconcile/ReconcileServiceTest.java
index a888375..54709d7 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/reconcile/ReconcileServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/reconcile/ReconcileServiceTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.elasticjob.lite.internal.reconcile;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.handler.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.election.LeaderService;
@@ -61,8 +60,7 @@ public final class ReconcileServiceTest {
@Test
public void assertReconcile() {
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).reconcileIntervalMinutes(1).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).reconcileIntervalMinutes(1).build());
when(shardingService.isNeedSharding()).thenReturn(false);
when(shardingService.hasShardingInfoInOfflineServers()).thenReturn(true);
when(leaderService.isLeaderUntilBlock()).thenReturn(true);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacadeTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacadeTest.java
index 0e2121b..613a9f9 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacadeTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJobFacadeTest.java
@@ -18,20 +18,19 @@
package org.apache.shardingsphere.elasticjob.lite.internal.schedule;
import com.google.common.collect.Lists;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.api.listener.fixture.ElasticJobListenerCaller;
import org.apache.shardingsphere.elasticjob.lite.api.listener.fixture.TestElasticJobListener;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.tracing.JobEventBus;
import org.apache.shardingsphere.elasticjob.lite.exception.JobExecutionEnvironmentException;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.failover.FailoverService;
import org.apache.shardingsphere.elasticjob.lite.internal.sharding.ExecutionContextService;
import org.apache.shardingsphere.elasticjob.lite.internal.sharding.ExecutionService;
import org.apache.shardingsphere.elasticjob.lite.internal.sharding.ShardingService;
+import org.apache.shardingsphere.elasticjob.lite.tracing.JobEventBus;
import org.apache.shardingsphere.elasticjob.lite.util.ReflectionUtils;
import org.junit.Before;
import org.junit.Test;
@@ -86,7 +85,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertLoad() {
- JobConfiguration expected = JobConfiguration.newBuilder(null).build();
+ JobConfiguration expected = JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build();
when(configService.load(true)).thenReturn(expected);
assertThat(liteJobFacade.loadJobConfiguration(true), is(expected));
}
@@ -99,16 +98,14 @@ public final class LiteJobFacadeTest {
@Test
public void assertFailoverIfUnnecessary() {
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(false).build());
liteJobFacade.failoverIfNecessary();
verify(failoverService, times(0)).failoverIfNecessary();
}
@Test
public void assertFailoverIfNecessary() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).monitorExecution(true).build());
liteJobFacade.failoverIfNecessary();
verify(failoverService).failoverIfNecessary();
}
@@ -123,8 +120,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertRegisterJobCompletedWhenFailoverDisabled() {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap());
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(false).build());
liteJobFacade.registerJobCompleted(shardingContexts);
verify(executionService).registerJobCompleted(shardingContexts);
verify(failoverService, times(0)).updateFailoverComplete(shardingContexts.getShardingItemParameters().keySet());
@@ -133,8 +129,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertRegisterJobCompletedWhenFailoverEnabled() {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap());
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).monitorExecution(true).build());
liteJobFacade.registerJobCompleted(shardingContexts);
verify(executionService).registerJobCompleted(shardingContexts);
verify(failoverService).updateFailoverComplete(shardingContexts.getShardingItemParameters().keySet());
@@ -143,8 +138,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertGetShardingContextWhenIsFailoverEnableAndFailover() {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap());
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).monitorExecution(true).build());
when(failoverService.getLocalFailoverItems()).thenReturn(Collections.singletonList(1));
when(executionContextService.getJobShardingContext(Collections.singletonList(1))).thenReturn(shardingContexts);
assertThat(liteJobFacade.getShardingContexts(), is(shardingContexts));
@@ -154,8 +148,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertGetShardingContextWhenIsFailoverEnableAndNotFailover() {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap());
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(
- new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(true).monitorExecution(true).build());
when(failoverService.getLocalFailoverItems()).thenReturn(Collections.emptyList());
when(shardingService.getLocalShardingItems()).thenReturn(Lists.newArrayList(0, 1));
when(failoverService.getLocalTakeOffItems()).thenReturn(Collections.singletonList(0));
@@ -167,8 +160,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertGetShardingContextWhenIsFailoverDisable() {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap());
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(false).build());
when(shardingService.getLocalShardingItems()).thenReturn(Lists.newArrayList(0, 1));
when(executionContextService.getJobShardingContext(Lists.newArrayList(0, 1))).thenReturn(shardingContexts);
assertThat(liteJobFacade.getShardingContexts(), is(shardingContexts));
@@ -178,8 +170,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertGetShardingContextWhenHasDisabledItems() {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap());
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).failover(false).build());
when(shardingService.getLocalShardingItems()).thenReturn(Lists.newArrayList(0, 1));
when(executionService.getDisabledItems(Lists.newArrayList(0, 1))).thenReturn(Collections.singletonList(1));
when(executionContextService.getJobShardingContext(Lists.newArrayList(0))).thenReturn(shardingContexts);
@@ -220,7 +211,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertNotEligibleForJobRunningWhenNeedSharding() {
when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), true)).build());
+ JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).build());
when(shardingService.isNeedSharding()).thenReturn(true);
assertThat(liteJobFacade.isEligibleForJobRunning(), is(false));
verify(shardingService).isNeedSharding();
@@ -229,7 +220,7 @@ public final class LiteJobFacadeTest {
@Test
public void assertNotEligibleForJobRunningWhenUnStreamingProcess() {
when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), false)).build());
+ JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.FALSE.toString()).build());
assertThat(liteJobFacade.isEligibleForJobRunning(), is(false));
verify(configService).load(true);
}
@@ -238,7 +229,7 @@ public final class LiteJobFacadeTest {
public void assertEligibleForJobRunningWhenNotNeedShardingAndStreamingProcess() {
when(shardingService.isNeedSharding()).thenReturn(false);
when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), true)).build());
+ JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).build());
assertThat(liteJobFacade.isEligibleForJobRunning(), is(true));
verify(shardingService).isNeedSharding();
verify(configService).load(true);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/SchedulerFacadeTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/SchedulerFacadeTest.java
index 25e9f05..d182768 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/SchedulerFacadeTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/SchedulerFacadeTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.elasticjob.lite.internal.schedule;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.fixture.TestDataflowJob;
import org.apache.shardingsphere.elasticjob.lite.handler.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
@@ -97,7 +97,8 @@ public final class SchedulerFacadeTest {
@Test
public void assertUpdateJobConfiguration() {
- JobConfiguration jobConfig = JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), false)).build();
+ JobConfiguration jobConfig = JobConfiguration.newBuilder(
+ "test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).build();
when(configService.load(false)).thenReturn(jobConfig);
assertThat(schedulerFacade.updateJobConfiguration(TestDataflowJob.class.getName(), jobConfig), is(jobConfig));
verify(configService).persist(TestDataflowJob.class.getName(), jobConfig);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextServiceTest.java
index aa61cf2..4e96961 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionContextServiceTest.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.elasticjob.lite.internal.sharding;
import com.google.common.collect.Lists;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.handler.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
@@ -63,8 +63,8 @@ public final class ExecutionContextServiceTest {
@Test
public void assertGetShardingContextWhenNotAssignShardingItem() {
- when(configService.load(false)).thenReturn(
- JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), true)).monitorExecution(false).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3)
+ .setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).monitorExecution(false).build());
ShardingContexts shardingContexts = executionContextService.getJobShardingContext(Collections.emptyList());
assertTrue(shardingContexts.getTaskId().startsWith("test_job@-@@-@READY@-@"));
assertThat(shardingContexts.getShardingTotalCount(), is(3));
@@ -72,8 +72,8 @@ public final class ExecutionContextServiceTest {
@Test
public void assertGetShardingContextWhenAssignShardingItems() {
- when(configService.load(false)).thenReturn(JobConfiguration.newBuilder(
- new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).shardingItemParameters("0=A,1=B,2=C").build(), true)).monitorExecution(false).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3)
+ .shardingItemParameters("0=A,1=B,2=C").setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).monitorExecution(false).build());
Map<Integer, String> map = new HashMap<>(3);
map.put(0, "A");
map.put(1, "B");
@@ -83,8 +83,8 @@ public final class ExecutionContextServiceTest {
@Test
public void assertGetShardingContextWhenHasRunningItems() {
- when(configService.load(false)).thenReturn(JobConfiguration.newBuilder(
- new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).shardingItemParameters("0=A,1=B,2=C").build(), true)).monitorExecution(true).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.DATAFLOW, "0/1 * * * * ?", 3)
+ .shardingItemParameters("0=A,1=B,2=C").setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).monitorExecution(true).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(true);
Map<Integer, String> map = new HashMap<>(1, 1);
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionServiceTest.java
index f4cce61..5e85a67 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ExecutionServiceTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.elasticjob.lite.internal.sharding;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
@@ -70,8 +69,7 @@ public final class ExecutionServiceTest {
@Test
public void assertRegisterJobBeginWithoutMonitorExecution() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(false).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(false).build());
executionService.registerJobBegin(getShardingContext());
verify(jobNodeStorage, times(0)).fillEphemeralJobNode(any(), any());
assertTrue(JobRegistry.getInstance().isJobRunning("test_job"));
@@ -79,8 +77,7 @@ public final class ExecutionServiceTest {
@Test
public void assertRegisterJobBeginWithMonitorExecution() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
executionService.registerJobBegin(getShardingContext());
verify(jobNodeStorage).fillEphemeralJobNode("sharding/0/running", "");
verify(jobNodeStorage).fillEphemeralJobNode("sharding/1/running", "");
@@ -91,8 +88,7 @@ public final class ExecutionServiceTest {
@Test
public void assertRegisterJobCompletedWithoutMonitorExecution() {
JobRegistry.getInstance().setJobRunning("test_job", true);
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(false).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(false).build());
executionService.registerJobCompleted(new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap()));
verify(jobNodeStorage, times(0)).removeJobNodeIfExisted(any());
verify(jobNodeStorage, times(0)).createJobNodeIfNeeded(any());
@@ -102,8 +98,7 @@ public final class ExecutionServiceTest {
@Test
public void assertRegisterJobCompletedWithMonitorExecution() {
JobRegistry.getInstance().setJobRunning("test_job", true);
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
executionService.registerJobCompleted(getShardingContext());
verify(jobNodeStorage).removeJobNodeIfExisted("sharding/0/running");
verify(jobNodeStorage).removeJobNodeIfExisted("sharding/1/running");
@@ -113,8 +108,7 @@ public final class ExecutionServiceTest {
@Test
public void assertClearAllRunningInfo() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(false).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(false).build());
executionService.clearAllRunningInfo();
verify(jobNodeStorage).removeJobNodeIfExisted("sharding/0/running");
verify(jobNodeStorage).removeJobNodeIfExisted("sharding/1/running");
@@ -130,15 +124,13 @@ public final class ExecutionServiceTest {
@Test
public void assertNotHaveRunningItemsWithoutMonitorExecution() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(false).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(false).build());
assertFalse(executionService.hasRunningItems(Arrays.asList(0, 1, 2)));
}
@Test
public void assertHasRunningItemsWithMonitorExecution() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(true);
assertTrue(executionService.hasRunningItems(Arrays.asList(0, 1, 2)));
@@ -146,8 +138,7 @@ public final class ExecutionServiceTest {
@Test
public void assertNotHaveRunningItems() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/2/running")).thenReturn(false);
@@ -156,7 +147,7 @@ public final class ExecutionServiceTest {
@Test
public void assertHasRunningItemsForAll() {
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(true);
assertTrue(executionService.hasRunningItems());
@@ -164,7 +155,7 @@ public final class ExecutionServiceTest {
@Test
public void assertNotHaveRunningItemsForAll() {
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/2/running")).thenReturn(false);
@@ -173,8 +164,7 @@ public final class ExecutionServiceTest {
@Test
public void assertMisfireIfNotRunning() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/2/running")).thenReturn(false);
@@ -183,8 +173,7 @@ public final class ExecutionServiceTest {
@Test
public void assertMisfireIfRunning() {
- when(configService.load(true)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
when(jobNodeStorage.isJobNodeExisted("sharding/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("sharding/1/running")).thenReturn(true);
assertTrue(executionService.misfireIfHasRunningItems(Arrays.asList(0, 1, 2)));
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingServiceTest.java
index f38237e..1bbf755 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/sharding/ShardingServiceTest.java
@@ -21,9 +21,8 @@ import org.apache.curator.framework.api.transaction.CuratorTransactionBridge;
import org.apache.curator.framework.api.transaction.CuratorTransactionFinal;
import org.apache.curator.framework.api.transaction.TransactionCreateBuilder;
import org.apache.curator.framework.api.transaction.TransactionDeleteBuilder;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.handler.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.lite.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.lite.internal.election.LeaderService;
@@ -138,8 +137,7 @@ public final class ShardingServiceTest {
when(instanceService.getAvailableJobInstances()).thenReturn(Collections.singletonList(new JobInstance("127.0.0.1@-@0")));
when(jobNodeStorage.isJobNodeExisted("leader/sharding/necessary")).thenReturn(true);
when(leaderService.isLeaderUntilBlock()).thenReturn(true);
- when(configService.load(false)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(true).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(true).build());
when(executionService.hasRunningItems()).thenReturn(true, false);
when(jobNodeStorage.getJobNodeChildrenKeys(ShardingNode.ROOT)).thenReturn(Arrays.asList("0", "1"));
shardingService.shardingIfNecessary();
@@ -159,8 +157,7 @@ public final class ShardingServiceTest {
when(instanceService.getAvailableJobInstances()).thenReturn(Collections.singletonList(new JobInstance("127.0.0.1@-@0")));
when(jobNodeStorage.isJobNodeExisted("leader/sharding/necessary")).thenReturn(true);
when(leaderService.isLeaderUntilBlock()).thenReturn(true);
- when(configService.load(false)).thenReturn(
- JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).monitorExecution(false).build());
+ when(configService.load(false)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).monitorExecution(false).build());
when(jobNodeStorage.getJobNodeChildrenKeys(ShardingNode.ROOT)).thenReturn(Arrays.asList("0", "1", "2", "3"));
shardingService.shardingIfNecessary();
verify(jobNodeStorage).removeJobNodeIfExisted("sharding/0/instance");
@@ -184,7 +181,7 @@ public final class ShardingServiceTest {
public void assertGetShardingItemsWithEnabledServer() {
JobRegistry.getInstance().registerJob("test_job", jobScheduleController, regCenter);
when(serverService.isAvailableServer("127.0.0.1")).thenReturn(true);
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.getJobNodeData("sharding/0/instance")).thenReturn("127.0.0.1@-@0");
when(jobNodeStorage.getJobNodeData("sharding/1/instance")).thenReturn("127.0.0.1@-@1");
when(jobNodeStorage.getJobNodeData("sharding/2/instance")).thenReturn("127.0.0.1@-@0");
@@ -208,7 +205,7 @@ public final class ShardingServiceTest {
public void assertGetLocalShardingItemsWithEnabledServer() {
JobRegistry.getInstance().registerJob("test_job", jobScheduleController, regCenter);
when(serverService.isAvailableServer("127.0.0.1")).thenReturn(true);
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.getJobNodeData("sharding/0/instance")).thenReturn("127.0.0.1@-@0");
when(jobNodeStorage.getJobNodeData("sharding/1/instance")).thenReturn("127.0.0.1@-@1");
when(jobNodeStorage.getJobNodeData("sharding/2/instance")).thenReturn("127.0.0.1@-@0");
@@ -219,7 +216,7 @@ public final class ShardingServiceTest {
@Test
public void assertHasShardingInfoInOfflineServers() {
when(jobNodeStorage.getJobNodeChildrenKeys(InstanceNode.ROOT)).thenReturn(Arrays.asList("host0@-@0", "host0@-@1"));
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(0))).thenReturn("host0@-@0");
when(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(1))).thenReturn("host0@-@1");
when(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(2))).thenReturn("host0@-@2");
@@ -229,7 +226,7 @@ public final class ShardingServiceTest {
@Test
public void assertHasNotShardingInfoInOfflineServers() {
when(jobNodeStorage.getJobNodeChildrenKeys(InstanceNode.ROOT)).thenReturn(Arrays.asList("host0@-@0", "host0@-@1"));
- when(configService.load(true)).thenReturn(JobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build())).build());
+ when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", JobType.SIMPLE, "0/1 * * * * ?", 3).build());
when(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(0))).thenReturn("host0@-@0");
when(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(1))).thenReturn("host0@-@1");
when(jobNodeStorage.getJobNodeData(ShardingNode.getInstanceNode(2))).thenReturn("host0@-@0");
diff --git a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/settings/JobSettingsAPIImpl.java b/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/settings/JobSettingsAPIImpl.java
index 707cb4e..ddbebe4 100644
--- a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/settings/JobSettingsAPIImpl.java
+++ b/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/settings/JobSettingsAPIImpl.java
@@ -22,8 +22,8 @@ import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.internal.config.json.JobConfigurationGsonFactory;
import org.apache.shardingsphere.elasticjob.lite.internal.storage.JobNodePath;
import org.apache.shardingsphere.elasticjob.lite.lifecycle.api.JobSettingsAPI;
@@ -43,42 +43,42 @@ public final class JobSettingsAPIImpl implements JobSettingsAPI {
JobSettings result = new JobSettings();
JobNodePath jobNodePath = new JobNodePath(jobName);
JobConfiguration jobConfig = JobConfigurationGsonFactory.fromJson(regCenter.get(jobNodePath.getConfigNodePath()));
- String jobType = jobConfig.getTypeConfig().getJobType().name();
+ String jobType = jobConfig.getJobType().name();
buildSimpleJobSettings(jobName, result, jobConfig);
if (JobType.DATAFLOW.name().equals(jobType)) {
- buildDataflowJobSettings(result, (DataflowJobConfiguration) jobConfig.getTypeConfig());
+ buildDataflowJobSettings(result, jobConfig);
}
if (JobType.SCRIPT.name().equals(jobType)) {
- buildScriptJobSettings(result, (ScriptJobConfiguration) jobConfig.getTypeConfig());
+ buildScriptJobSettings(result, jobConfig);
}
return result;
}
private void buildSimpleJobSettings(final String jobName, final JobSettings jobSettings, final JobConfiguration jobConfig) {
jobSettings.setJobName(jobName);
- jobSettings.setJobType(jobConfig.getTypeConfig().getJobType().name());
- jobSettings.setShardingTotalCount(jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount());
- jobSettings.setCron(jobConfig.getTypeConfig().getCoreConfig().getCron());
- jobSettings.setShardingItemParameters(jobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters());
- jobSettings.setJobParameter(jobConfig.getTypeConfig().getCoreConfig().getJobParameter());
+ jobSettings.setJobType(jobConfig.getJobType().name());
+ jobSettings.setShardingTotalCount(jobConfig.getShardingTotalCount());
+ jobSettings.setCron(jobConfig.getCron());
+ jobSettings.setShardingItemParameters(jobConfig.getShardingItemParameters());
+ jobSettings.setJobParameter(jobConfig.getJobParameter());
jobSettings.setMonitorExecution(jobConfig.isMonitorExecution());
jobSettings.setMaxTimeDiffSeconds(jobConfig.getMaxTimeDiffSeconds());
jobSettings.setMonitorPort(jobConfig.getMonitorPort());
- jobSettings.setFailover(jobConfig.getTypeConfig().getCoreConfig().isFailover());
- jobSettings.setMisfire(jobConfig.getTypeConfig().getCoreConfig().isMisfire());
+ jobSettings.setFailover(jobConfig.isFailover());
+ jobSettings.setMisfire(jobConfig.isMisfire());
jobSettings.setJobShardingStrategyType(jobConfig.getJobShardingStrategyType());
- jobSettings.setJobExecutorServiceHandlerType(jobConfig.getTypeConfig().getCoreConfig().getJobExecutorServiceHandlerType());
- jobSettings.setJobErrorHandlerType(jobConfig.getTypeConfig().getCoreConfig().getJobErrorHandlerType());
+ jobSettings.setJobExecutorServiceHandlerType(jobConfig.getJobExecutorServiceHandlerType());
+ jobSettings.setJobErrorHandlerType(jobConfig.getJobErrorHandlerType());
jobSettings.setReconcileIntervalMinutes(jobConfig.getReconcileIntervalMinutes());
- jobSettings.setDescription(jobConfig.getTypeConfig().getCoreConfig().getDescription());
+ jobSettings.setDescription(jobConfig.getDescription());
}
- private void buildDataflowJobSettings(final JobSettings result, final DataflowJobConfiguration config) {
- result.setStreamingProcess(config.isStreamingProcess());
+ private void buildDataflowJobSettings(final JobSettings jobSettings, final JobConfiguration config) {
+ jobSettings.setStreamingProcess(Boolean.parseBoolean(config.getProps().getOrDefault(DataflowJobExecutor.STREAM_PROCESS_KEY, false).toString()));
}
- private void buildScriptJobSettings(final JobSettings result, final ScriptJobConfiguration config) {
- result.setScriptCommandLine(config.getScriptCommandLine());
+ private void buildScriptJobSettings(final JobSettings jobSettings, final JobConfiguration config) {
+ jobSettings.setScriptCommandLine(config.getProps().getProperty(ScriptJobExecutor.SCRIPT_KEY));
}
@Override
diff --git a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java b/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java
index 98153b7..2329178 100644
--- a/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java
+++ b/elastic-job-lite-lifecycle/src/main/java/org/apache/shardingsphere/elasticjob/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java
@@ -69,10 +69,10 @@ public final class JobStatisticsAPIImpl implements JobStatisticsAPI {
return null;
}
JobConfiguration jobConfig = JobConfigurationGsonFactory.fromJson(jobConfigJson);
- result.setDescription(jobConfig.getTypeConfig().getCoreConfig().getDescription());
- result.setCron(jobConfig.getTypeConfig().getCoreConfig().getCron());
+ result.setDescription(jobConfig.getDescription());
+ result.setCron(jobConfig.getCron());
result.setInstanceCount(getJobInstanceCount(jobName));
- result.setShardingTotalCount(jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount());
+ result.setShardingTotalCount(jobConfig.getShardingTotalCount());
result.setStatus(getJobStatus(jobName));
return result;
}
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java
index 7c2f26f..d6f3c47 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/common/AbstractJobBeanDefinitionParser.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.tracing.api.TracingConfiguration;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -33,6 +33,7 @@ import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import java.util.List;
+import java.util.Properties;
/**
* Job bean definition parser.
@@ -46,7 +47,7 @@ public abstract class AbstractJobBeanDefinitionParser extends AbstractBeanDefini
factory.setInitMethodName("init");
factory.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.REGISTRY_CENTER_REF_ATTRIBUTE));
factory.addConstructorArgReference(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_REF_ATTRIBUTE));
- factory.addConstructorArgValue(createJobConfiguration(parserContext, element));
+ factory.addConstructorArgValue(createJobConfiguration(element));
BeanDefinition tracingConfig = createTracingConfiguration(element);
if (null != tracingConfig) {
factory.addConstructorArgValue(tracingConfig);
@@ -55,40 +56,34 @@ public abstract class AbstractJobBeanDefinitionParser extends AbstractBeanDefini
return factory.getBeanDefinition();
}
- protected abstract BeanDefinition getJobTypeConfigurationBeanDefinition(ParserContext parserContext, BeanDefinition jobCoreConfigurationBeanDefinition, Element element);
-
- private BeanDefinition createJobConfiguration(final ParserContext parserContext, final Element element) {
- return createJobConfigurationBeanDefinition(parserContext, element, createJobCoreBeanDefinition(element));
+ private BeanDefinition createJobConfiguration(final Element element) {
+ return createJobConfigurationBeanDefinition(element);
}
- private BeanDefinition createJobConfigurationBeanDefinition(final ParserContext parserContext, final Element element, final BeanDefinition jobCoreBeanDefinition) {
+ private BeanDefinition createJobConfigurationBeanDefinition(final Element element) {
BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(JobConfiguration.class);
- result.addConstructorArgValue(getJobTypeConfigurationBeanDefinition(parserContext, jobCoreBeanDefinition, element));
+ result.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE));
+ result.addConstructorArgValue(getJobType());
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.CRON_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.SHARDING_TOTAL_COUNT_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.SHARDING_ITEM_PARAMETERS_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_PARAMETER_ATTRIBUTE));
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.MONITOR_EXECUTION_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.FAILOVER_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.MISFIRE_ATTRIBUTE));
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.MAX_TIME_DIFF_SECONDS_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.RECONCILE_INTERVAL_MINUTES));
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.MONITOR_PORT_ATTRIBUTE));
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_SHARDING_STRATEGY_TYPE_ATTRIBUTE));
- result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.RECONCILE_INTERVAL_MINUTES));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_EXECUTOR_SERVICE_HANDLER_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_ERROR_HANDLER_ATTRIBUTE));
+ result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.DESCRIPTION_ATTRIBUTE));
+ result.addConstructorArgValue(getProps(element));
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.DISABLED_ATTRIBUTE));
result.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.OVERWRITE_ATTRIBUTE));
return result.getBeanDefinition();
}
- private BeanDefinition createJobCoreBeanDefinition(final Element element) {
- BeanDefinitionBuilder jobCoreBeanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(JobCoreConfiguration.class);
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.CRON_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.SHARDING_TOTAL_COUNT_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.SHARDING_ITEM_PARAMETERS_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_PARAMETER_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.FAILOVER_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.MISFIRE_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_EXECUTOR_SERVICE_HANDLER_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.JOB_ERROR_HANDLER_ATTRIBUTE));
- jobCoreBeanDefinitionBuilder.addConstructorArgValue(element.getAttribute(BaseJobBeanDefinitionParserTag.DESCRIPTION_ATTRIBUTE));
- return jobCoreBeanDefinitionBuilder.getBeanDefinition();
- }
-
private BeanDefinition createTracingConfiguration(final Element element) {
String eventTraceDataSourceName = element.getAttribute(BaseJobBeanDefinitionParserTag.EVENT_TRACE_RDB_DATA_SOURCE_ATTRIBUTE);
if (Strings.isNullOrEmpty(eventTraceDataSourceName)) {
@@ -123,4 +118,8 @@ public abstract class AbstractJobBeanDefinitionParser extends AbstractBeanDefini
protected boolean shouldGenerateId() {
return true;
}
+
+ protected abstract Properties getProps(Element element);
+
+ protected abstract JobType getJobType();
}
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java
index 42fc7d9..355540d 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/dataflow/DataflowJobBeanDefinitionParser.java
@@ -17,23 +17,27 @@
package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.dataflow;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
+import java.util.Properties;
+
/**
* Dataflow job bean definition parser.
*/
public final class DataflowJobBeanDefinitionParser extends AbstractJobBeanDefinitionParser {
@Override
- protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
- BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(DataflowJobConfiguration.class);
- result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
- result.addConstructorArgValue(element.getAttribute(DataflowJobBeanDefinitionParserTag.STREAMING_PROCESS_ATTRIBUTE));
- return result.getBeanDefinition();
+ protected Properties getProps(final Element element) {
+ Properties result = new Properties();
+ result.setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, element.getAttribute(DataflowJobBeanDefinitionParserTag.STREAMING_PROCESS_ATTRIBUTE));
+ return result;
+ }
+
+ @Override
+ protected JobType getJobType() {
+ return JobType.DATAFLOW;
}
}
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/script/ScriptJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/script/ScriptJobBeanDefinitionParser.java
index c212502..1fa06da 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/script/ScriptJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/script/ScriptJobBeanDefinitionParser.java
@@ -17,23 +17,27 @@
package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.script;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
+import java.util.Properties;
+
/**
* Script job bean definition parser.
*/
public final class ScriptJobBeanDefinitionParser extends AbstractJobBeanDefinitionParser {
@Override
- protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
- BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(ScriptJobConfiguration.class);
- result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
- result.addConstructorArgValue(element.getAttribute(ScriptJobBeanDefinitionParserTag.SCRIPT_COMMAND_LINE_ATTRIBUTE));
- return result.getBeanDefinition();
+ protected Properties getProps(final Element element) {
+ Properties result = new Properties();
+ result.setProperty(ScriptJobExecutor.SCRIPT_KEY, element.getAttribute(ScriptJobBeanDefinitionParserTag.SCRIPT_COMMAND_LINE_ATTRIBUTE));
+ return result;
+ }
+
+ @Override
+ protected JobType getJobType() {
+ return JobType.SCRIPT;
}
}
diff --git a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java
index 635336a..145af7f 100644
--- a/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java
+++ b/elastic-job-lite-spring/src/main/java/org/apache/shardingsphere/elasticjob/lite/spring/job/parser/simple/SimpleJobBeanDefinitionParser.java
@@ -17,22 +17,24 @@
package org.apache.shardingsphere.elasticjob.lite.spring.job.parser.simple;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.spring.job.parser.common.AbstractJobBeanDefinitionParser;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
+import java.util.Properties;
+
/**
* Simple job bean definition parser.
*/
public final class SimpleJobBeanDefinitionParser extends AbstractJobBeanDefinitionParser {
@Override
- protected BeanDefinition getJobTypeConfigurationBeanDefinition(final ParserContext parserContext, final BeanDefinition jobCoreConfigurationBeanDefinition, final Element element) {
- BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(SimpleJobConfiguration.class);
- result.addConstructorArgValue(jobCoreConfigurationBeanDefinition);
- return result.getBeanDefinition();
+ protected Properties getProps(final Element element) {
+ return new Properties();
+ }
+
+ @Override
+ protected JobType getJobType() {
+ return JobType.SIMPLE;
}
}
diff --git a/examples/elastic-job-example-lite-java/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/JavaMain.java b/examples/elastic-job-example-lite-java/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/JavaMain.java
index 178068d..66ad6e7 100644
--- a/examples/elastic-job-example-lite-java/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/JavaMain.java
+++ b/examples/elastic-job-example-lite-java/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/JavaMain.java
@@ -19,13 +19,12 @@ package org.apache.shardingsphere.elasticjob.lite.example;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.script.ScriptJobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.example.job.dataflow.JavaDataflowJob;
import org.apache.shardingsphere.elasticjob.lite.example.job.simple.JavaSimpleJob;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.ScriptJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.lite.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.lite.reg.zookeeper.ZookeeperRegistryCenter;
@@ -86,21 +85,18 @@ public final class JavaMain {
}
private static void setUpSimpleJob(final CoordinatorRegistryCenter regCenter, final TracingConfiguration tracingConfig) {
- JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("javaSimpleJob", "0/5 * * * * ?", 3).shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build();
- SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(coreConfig);
- new JobScheduler(regCenter, new JavaSimpleJob(), JobConfiguration.newBuilder(simpleJobConfig).build(), tracingConfig).init();
+ new JobScheduler(regCenter, new JavaSimpleJob(), JobConfiguration.newBuilder("javaSimpleJob", JobType.SIMPLE, "0/5 * * * * ?", 3)
+ .shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build(), tracingConfig).init();
}
private static void setUpDataflowJob(final CoordinatorRegistryCenter regCenter, final TracingConfiguration tracingConfig) {
- JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("javaDataflowElasticJob", "0/5 * * * * ?", 3).shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build();
- DataflowJobConfiguration dataflowJobConfig = new DataflowJobConfiguration(coreConfig, true);
- new JobScheduler(regCenter, new JavaDataflowJob(), JobConfiguration.newBuilder(dataflowJobConfig).build(), tracingConfig).init();
+ new JobScheduler(regCenter, new JavaDataflowJob(), JobConfiguration.newBuilder("javaDataflowElasticJob", JobType.DATAFLOW, "0/5 * * * * ?", 3)
+ .shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).build(), tracingConfig).init();
}
private static void setUpScriptJob(final CoordinatorRegistryCenter regCenter, final TracingConfiguration tracingConfig) throws IOException {
- JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("scriptElasticJob", "0/5 * * * * ?", 3).build();
- ScriptJobConfiguration scriptJobConfig = new ScriptJobConfiguration(coreConfig, buildScriptCommandLine());
- new JobScheduler(regCenter, null, JobConfiguration.newBuilder(scriptJobConfig).build(), tracingConfig).init();
+ new JobScheduler(regCenter, null, JobConfiguration.newBuilder("scriptElasticJob", JobType.SCRIPT, "0/5 * * * * ?", 3)
+ .setProperty(ScriptJobExecutor.SCRIPT_KEY, buildScriptCommandLine()).build(), tracingConfig).init();
}
private static String buildScriptCommandLine() throws IOException {
diff --git a/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/DataflowJobConfig.java b/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/DataflowJobConfig.java
index 0775aa8..6520cfd 100644
--- a/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/DataflowJobConfig.java
+++ b/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/DataflowJobConfig.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.elasticjob.lite.example.config;
import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.api.dataflow.DataflowJob;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.dataflow.DataflowJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.example.job.dataflow.SpringDataflowJob;
+import org.apache.shardingsphere.elasticjob.lite.executor.type.impl.DataflowJobExecutor;
import org.apache.shardingsphere.elasticjob.lite.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.lite.tracing.api.TracingConfiguration;
import org.springframework.beans.factory.annotation.Value;
@@ -52,7 +52,7 @@ public class DataflowJobConfig {
}
private JobConfiguration getJobConfiguration(final Class<? extends DataflowJob> jobClass, final String cron, final int shardingTotalCount, final String shardingItemParameters) {
- return JobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder(
- jobClass.getName(), cron, shardingTotalCount).shardingItemParameters(shardingItemParameters).build(), true)).overwrite(true).build();
+ return JobConfiguration.newBuilder(jobClass.getName(), JobType.DATAFLOW, cron, shardingTotalCount)
+ .shardingItemParameters(shardingItemParameters).setProperty(DataflowJobExecutor.STREAM_PROCESS_KEY, Boolean.TRUE.toString()).overwrite(true).build();
}
}
diff --git a/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/SimpleJobConfig.java b/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/SimpleJobConfig.java
index 4848abd..49c5f29 100644
--- a/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/SimpleJobConfig.java
+++ b/examples/elastic-job-example-lite-springboot/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/config/SimpleJobConfig.java
@@ -18,10 +18,9 @@
package org.apache.shardingsphere.elasticjob.lite.example.config;
import org.apache.shardingsphere.elasticjob.lite.api.JobScheduler;
+import org.apache.shardingsphere.elasticjob.lite.api.JobType;
import org.apache.shardingsphere.elasticjob.lite.api.simple.SimpleJob;
-import org.apache.shardingsphere.elasticjob.lite.config.JobCoreConfiguration;
import org.apache.shardingsphere.elasticjob.lite.config.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.lite.config.simple.SimpleJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.example.job.simple.SpringSimpleJob;
import org.apache.shardingsphere.elasticjob.lite.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.lite.tracing.api.TracingConfiguration;
@@ -52,7 +51,6 @@ public class SimpleJobConfig {
}
private JobConfiguration getJobConfiguration(final Class<? extends SimpleJob> jobClass, final String cron, final int shardingTotalCount, final String shardingItemParameters) {
- return JobConfiguration.newBuilder(new SimpleJobConfiguration(
- JobCoreConfiguration.newBuilder(jobClass.getName(), cron, shardingTotalCount).shardingItemParameters(shardingItemParameters).build())).overwrite(true).build();
+ return JobConfiguration.newBuilder(jobClass.getName(), JobType.SIMPLE, cron, shardingTotalCount).shardingItemParameters(shardingItemParameters).overwrite(true).build();
}
}