use of com.dangdang.ddframe.job.cloud.scheduler.context.JobContext in project elastic-job by dangdangdotcom.
the class LaunchingTasks method getIntegrityViolationJobs.
Collection<String> getIntegrityViolationJobs(final Collection<VMAssignmentResult> vmAssignmentResults) {
Map<String, Integer> assignedJobShardingTotalCountMap = getAssignedJobShardingTotalCountMap(vmAssignmentResults);
Collection<String> result = new HashSet<>(assignedJobShardingTotalCountMap.size(), 1);
for (Map.Entry<String, Integer> entry : assignedJobShardingTotalCountMap.entrySet()) {
JobContext jobContext = eligibleJobContextsMap.get(entry.getKey());
if (ExecutionType.FAILOVER != jobContext.getType() && !entry.getValue().equals(jobContext.getJobConfig().getTypeConfig().getCoreConfig().getShardingTotalCount())) {
log.warn("Job {} is not assigned at this time, because resources not enough to run all sharding instances.", entry.getKey());
result.add(entry.getKey());
}
}
return result;
}
use of com.dangdang.ddframe.job.cloud.scheduler.context.JobContext in project elastic-job by dangdangdotcom.
the class FailoverService method getAllEligibleJobContexts.
/**
* 从失效转移队列中获取所有有资格执行的作业上下文.
*
* @return 有资格执行的作业上下文集合
*/
public Collection<JobContext> getAllEligibleJobContexts() {
if (!regCenter.isExisted(FailoverNode.ROOT)) {
return Collections.emptyList();
}
List<String> jobNames = regCenter.getChildrenKeys(FailoverNode.ROOT);
Collection<JobContext> result = new ArrayList<>(jobNames.size());
Set<HashCode> assignedTasks = new HashSet<>(jobNames.size() * 10, 1);
for (String each : jobNames) {
List<String> taskIdList = regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath(each));
if (taskIdList.isEmpty()) {
regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
continue;
}
Optional<CloudJobConfiguration> jobConfig = configService.load(each);
if (!jobConfig.isPresent()) {
regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
continue;
}
List<Integer> assignedShardingItems = getAssignedShardingItems(each, taskIdList, assignedTasks);
if (!assignedShardingItems.isEmpty()) {
if (jobConfig.isPresent()) {
result.add(new JobContext(jobConfig.get(), assignedShardingItems, ExecutionType.FAILOVER));
}
}
}
return result;
}
use of com.dangdang.ddframe.job.cloud.scheduler.context.JobContext in project elastic-job by dangdangdotcom.
the class FacadeServiceTest method assertGetEligibleJobContext.
@Test
public void assertGetEligibleJobContext() {
Collection<JobContext> failoverJobContexts = Collections.singletonList(JobContext.from(CloudJobConfigurationBuilder.createCloudJobConfiguration("failover_job"), ExecutionType.FAILOVER));
Collection<JobContext> readyJobContexts = Collections.singletonList(JobContext.from(CloudJobConfigurationBuilder.createCloudJobConfiguration("ready_job"), ExecutionType.READY));
when(failoverService.getAllEligibleJobContexts()).thenReturn(failoverJobContexts);
when(readyService.getAllEligibleJobContexts(failoverJobContexts)).thenReturn(readyJobContexts);
Collection<JobContext> actual = facadeService.getEligibleJobContext();
assertThat(actual.size(), is(2));
int i = 0;
for (JobContext each : actual) {
switch(i) {
case 0:
assertThat(each.getJobConfig().getJobName(), is("failover_job"));
break;
case 1:
assertThat(each.getJobConfig().getJobName(), is("ready_job"));
break;
default:
break;
}
i++;
}
}
Aggregations