Search in sources :

Example 1 with JobConfiguration

use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.

the class CloudJobFacade method loadJobConfiguration.

@Override
public JobConfiguration loadJobConfiguration(final boolean fromCache) {
    JobConfiguration result = JobConfiguration.newBuilder(jobConfig.getJobName(), jobConfig.getShardingTotalCount()).cron(jobConfig.getCron()).shardingItemParameters(jobConfig.getShardingItemParameters()).jobParameter(jobConfig.getJobParameter()).failover(jobConfig.isFailover()).misfire(jobConfig.isMisfire()).description(jobConfig.getDescription()).jobExecutorServiceHandlerType(jobConfig.getJobExecutorServiceHandlerType()).jobErrorHandlerType(jobConfig.getJobErrorHandlerType()).build();
    result.getProps().putAll(jobConfig.getProps());
    return result;
}
Also used : JobConfiguration(org.apache.shardingsphere.elasticjob.api.JobConfiguration)

Example 2 with JobConfiguration

use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.

the class ExecutorServiceReloadableTest method assertReload.

@Test
public void assertReload() {
    ExecutorServiceReloadable executorServiceReloadable = new ExecutorServiceReloadable();
    setField(executorServiceReloadable, "jobExecutorServiceHandlerType", "mock");
    setField(executorServiceReloadable, "executorService", mockExecutorService);
    JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).build();
    executorServiceReloadable.reloadIfNecessary(jobConfig);
    verify(mockExecutorService).shutdown();
    ExecutorService actual = executorServiceReloadable.getInstance();
    assertFalse(actual.isShutdown());
    assertFalse(actual.isTerminated());
    actual.shutdown();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) JobConfiguration(org.apache.shardingsphere.elasticjob.api.JobConfiguration) Test(org.junit.Test)

Example 3 with JobConfiguration

use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.

the class ExecutorServiceReloadableTest method assertInitialize.

@Test
public void assertInitialize() {
    ExecutorServiceReloadable executorServiceReloadable = new ExecutorServiceReloadable();
    String jobExecutorServiceHandlerType = "SINGLE_THREAD";
    JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).build();
    assertNull(executorServiceReloadable.getInstance());
    executorServiceReloadable.init(jobConfig);
    ExecutorService actual = executorServiceReloadable.getInstance();
    assertNotNull(actual);
    assertFalse(actual.isShutdown());
    assertFalse(actual.isTerminated());
    actual.shutdown();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) JobConfiguration(org.apache.shardingsphere.elasticjob.api.JobConfiguration) Test(org.junit.Test)

Example 4 with JobConfiguration

use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.

the class JobConfigurationPOJOTest method assertFromJobConfiguration.

@Test
public void assertFromJobConfiguration() {
    JobConfiguration jobConfiguration = JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").shardingItemParameters("0=A,1=B,2=C").jobParameter("param").monitorExecution(true).failover(true).misfire(true).jobShardingStrategyType("AVG_ALLOCATION").jobExecutorServiceHandlerType("CPU").jobErrorHandlerType("IGNORE").jobListenerTypes("LOG").description("Job description").setProperty("key", "value").disabled(true).overwrite(true).build();
    JobConfigurationPOJO actual = JobConfigurationPOJO.fromJobConfiguration(jobConfiguration);
    assertThat(actual.getJobName(), is("test_job"));
    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"));
    assertTrue(actual.isMonitorExecution());
    assertTrue(actual.isFailover());
    assertTrue(actual.isMisfire());
    assertThat(actual.getJobShardingStrategyType(), is("AVG_ALLOCATION"));
    assertThat(actual.getJobExecutorServiceHandlerType(), is("CPU"));
    assertThat(actual.getJobErrorHandlerType(), is("IGNORE"));
    assertThat(actual.getJobListenerTypes(), hasItem("LOG"));
    assertThat(actual.getDescription(), is("Job description"));
    assertThat(actual.getProps().getProperty("key"), is("value"));
    assertTrue(actual.isDisabled());
    assertTrue(actual.isOverwrite());
}
Also used : JobConfiguration(org.apache.shardingsphere.elasticjob.api.JobConfiguration) Test(org.junit.Test)

Example 5 with JobConfiguration

use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.

the class JobConfigurationPOJO method toJobConfiguration.

/**
 * Convert to job configuration.
 *
 * @return job configuration
 */
public JobConfiguration toJobConfiguration() {
    JobConfiguration result = JobConfiguration.newBuilder(jobName, shardingTotalCount).cron(cron).timeZone(timeZone).shardingItemParameters(shardingItemParameters).jobParameter(jobParameter).monitorExecution(monitorExecution).failover(failover).misfire(misfire).maxTimeDiffSeconds(maxTimeDiffSeconds).reconcileIntervalMinutes(reconcileIntervalMinutes).jobShardingStrategyType(jobShardingStrategyType).jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).jobErrorHandlerType(jobErrorHandlerType).jobListenerTypes(jobListenerTypes.toArray(new String[] {})).description(description).disabled(disabled).overwrite(overwrite).label(label).staticSharding(staticSharding).build();
    jobExtraConfigurations.stream().map(YamlConfiguration::toConfiguration).forEach(result.getExtraConfigurations()::add);
    for (Object each : props.keySet()) {
        result.getProps().setProperty(each.toString(), props.get(each.toString()).toString());
    }
    return result;
}
Also used : JobConfiguration(org.apache.shardingsphere.elasticjob.api.JobConfiguration)

Aggregations

JobConfiguration (org.apache.shardingsphere.elasticjob.api.JobConfiguration)32 Test (org.junit.Test)18 OneOffJobBootstrap (org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap)5 ScheduleJobBootstrap (org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap)4 ExecutorService (java.util.concurrent.ExecutorService)3 ElasticJob (org.apache.shardingsphere.elasticjob.api.ElasticJob)3 IgnoreJobErrorHandler (org.apache.shardingsphere.elasticjob.error.handler.general.IgnoreJobErrorHandler)3 LogJobErrorHandler (org.apache.shardingsphere.elasticjob.error.handler.general.LogJobErrorHandler)3 JobConfigurationPOJO (org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO)3 JavaOccurErrorJob (org.apache.shardingsphere.elasticjob.lite.example.job.simple.JavaOccurErrorJob)3 ShardingContexts (org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts)2 Properties (java.util.Properties)1 CloudJobConfiguration (org.apache.shardingsphere.elasticjob.cloud.config.CloudJobConfiguration)1 JobErrorHandler (org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler)1 ShardingItemParameters (org.apache.shardingsphere.elasticjob.infra.context.ShardingItemParameters)1 JobExecutionEnvironmentException (org.apache.shardingsphere.elasticjob.infra.exception.JobExecutionEnvironmentException)1 JobInstance (org.apache.shardingsphere.elasticjob.infra.handler.sharding.JobInstance)1 JobShardingStrategy (org.apache.shardingsphere.elasticjob.infra.handler.sharding.JobShardingStrategy)1 JobNodePath (org.apache.shardingsphere.elasticjob.lite.internal.storage.JobNodePath)1 JobBriefInfo (org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.JobBriefInfo)1