Search in sources :

Example 1 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.

the class JobSettingsAPIImpl method getJobSettings.

@Override
public JobSettings getJobSettings(final String jobName) {
    JobSettings result = new JobSettings();
    JobNodePath jobNodePath = new JobNodePath(jobName);
    LiteJobConfiguration liteJobConfig = LiteJobConfigurationGsonFactory.fromJson(regCenter.get(jobNodePath.getConfigNodePath()));
    String jobType = liteJobConfig.getTypeConfig().getJobType().name();
    buildSimpleJobSettings(jobName, result, liteJobConfig);
    if (JobType.DATAFLOW.name().equals(jobType)) {
        buildDataflowJobSettings(result, (DataflowJobConfiguration) liteJobConfig.getTypeConfig());
    }
    if (JobType.SCRIPT.name().equals(jobType)) {
        buildScriptJobSettings(result, (ScriptJobConfiguration) liteJobConfig.getTypeConfig());
    }
    return result;
}
Also used : JobSettings(com.dangdang.ddframe.job.lite.lifecycle.domain.JobSettings) LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) JobNodePath(com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)

Example 2 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.

the class ShardingService method shardingIfNecessary.

/**
     * 如果需要分片且当前节点为主节点, 则作业分片.
     * 如果当前无可用节点则不分片.
     */
public void shardingIfNecessary() {
    List<String> availableShardingServers = serverService.getAvailableShardingServers();
    if (availableShardingServers.isEmpty()) {
        clearShardingInfo();
        return;
    }
    if (!isNeedSharding()) {
        return;
    }
    if (!leaderElectionService.isLeader()) {
        blockUntilShardingCompleted();
        return;
    }
    LiteJobConfiguration liteJobConfig = configService.load(false);
    if (liteJobConfig.isMonitorExecution()) {
        waitingOtherJobCompleted();
    }
    log.debug("Job '{}' sharding begin.", jobName);
    jobNodeStorage.fillEphemeralJobNode(ShardingNode.PROCESSING, "");
    clearShardingInfo();
    JobShardingStrategy jobShardingStrategy = JobShardingStrategyFactory.getStrategy(liteJobConfig.getJobShardingStrategyClass());
    JobShardingStrategyOption option = new JobShardingStrategyOption(jobName, liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount());
    jobNodeStorage.executeInTransaction(new PersistShardingInfoTransactionExecutionCallback(jobShardingStrategy.sharding(availableShardingServers, option)));
    log.debug("Job '{}' sharding complete.", jobName);
}
Also used : JobShardingStrategyOption(com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption) LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) JobShardingStrategy(com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategy)

Example 3 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.

the class AbstractBaseStdJobTest method assertRegCenterCommonInfo.

private void assertRegCenterCommonInfo() {
    LiteJobConfiguration liteJobConfig = LiteJobConfigurationGsonFactory.fromJson(regCenter.get("/" + jobName + "/config"));
    assertThat(liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
    assertThat(liteJobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters(), is("0=A,1=B,2=C"));
    assertThat(liteJobConfig.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
    assertThat(regCenter.get("/" + jobName + "/servers/" + localHostService.getIp() + "/hostName"), is(localHostService.getHostName()));
    if (disabled) {
        assertTrue(regCenter.isExisted("/" + jobName + "/servers/" + localHostService.getIp() + "/disabled"));
        while (null != regCenter.get("/" + jobName + "/leader/election/host")) {
            BlockUtils.waitingShortTime();
        }
    } else {
        assertFalse(regCenter.isExisted("/" + jobName + "/servers/" + localHostService.getIp() + "/disabled"));
        assertThat(regCenter.get("/" + jobName + "/leader/election/host"), is(localHostService.getIp()));
    }
    assertFalse(regCenter.isExisted("/" + jobName + "/servers/" + localHostService.getIp() + "/paused"));
    assertThat(regCenter.get("/" + jobName + "/servers/" + localHostService.getIp() + "/status"), CoreMatchers.is(ServerStatus.READY.name()));
    regCenter.remove("/" + jobName + "/leader/election");
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)

Example 4 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.

the class ConfigurationServiceTest method assertLoadFromCacheButNull.

@Test
public void assertLoadFromCacheButNull() {
    when(jobNodeStorage.getJobNodeData(ConfigurationNode.ROOT)).thenReturn(null);
    when(jobNodeStorage.getJobNodeDataDirectly(ConfigurationNode.ROOT)).thenReturn(LiteJsonConstants.getJobJson());
    LiteJobConfiguration 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));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) Test(org.junit.Test)

Example 5 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.

the class ConfigurationServiceTest method assertLoadFromCache.

@Test
public void assertLoadFromCache() {
    when(jobNodeStorage.getJobNodeData(ConfigurationNode.ROOT)).thenReturn(LiteJsonConstants.getJobJson());
    LiteJobConfiguration 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));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) Test(org.junit.Test)

Aggregations

LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)21 Test (org.junit.Test)14 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)2 JobNodePath (com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)2 ElasticJob (com.dangdang.ddframe.job.api.ElasticJob)1 DataflowJob (com.dangdang.ddframe.job.api.dataflow.DataflowJob)1 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 SimpleJob (com.dangdang.ddframe.job.api.simple.SimpleJob)1 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)1 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)1 ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)1 ElasticJobListener (com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener)1 JobShardingStrategy (com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategy)1 JobShardingStrategyOption (com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption)1 TestDataflowJob (com.dangdang.ddframe.job.lite.fixture.TestDataflowJob)1 AbstractBaseStdJobAutoInitTest (com.dangdang.ddframe.job.lite.integrate.AbstractBaseStdJobAutoInitTest)1 JobBriefInfo (com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo)1 JobSettings (com.dangdang.ddframe.job.lite.lifecycle.domain.JobSettings)1 ShardingItemParameters (com.dangdang.ddframe.job.util.config.ShardingItemParameters)1 BeansException (org.springframework.beans.BeansException)1