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;
}
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);
}
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");
}
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));
}
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));
}
Aggregations