Search in sources :

Example 1 with JobContext

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;
}
Also used : JobContext(com.dangdang.ddframe.job.cloud.scheduler.context.JobContext) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with JobContext

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;
}
Also used : HashCode(com.google.common.hash.HashCode) CloudJobConfiguration(com.dangdang.ddframe.job.cloud.scheduler.config.job.CloudJobConfiguration) ArrayList(java.util.ArrayList) JobContext(com.dangdang.ddframe.job.cloud.scheduler.context.JobContext) HashSet(java.util.HashSet)

Example 3 with JobContext

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++;
    }
}
Also used : JobContext(com.dangdang.ddframe.job.cloud.scheduler.context.JobContext) Test(org.junit.Test)

Aggregations

JobContext (com.dangdang.ddframe.job.cloud.scheduler.context.JobContext)3 HashSet (java.util.HashSet)2 CloudJobConfiguration (com.dangdang.ddframe.job.cloud.scheduler.config.job.CloudJobConfiguration)1 HashCode (com.google.common.hash.HashCode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1