Search in sources :

Example 1 with JobBriefInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImplTest method assertGetAllJobsBriefInfo.

@Test
public void assertGetAllJobsBriefInfo() {
    when(regCenter.getChildrenKeys("/")).thenReturn(Arrays.asList("test_job_1", "test_job_2"));
    when(regCenter.get("/test_job_1/config")).thenReturn(LifecycleJsonConstants.getSimpleJobJson("test_job_1", "desc1"));
    when(regCenter.get("/test_job_2/config")).thenReturn(LifecycleJsonConstants.getSimpleJobJson("test_job_2", "desc2"));
    when(regCenter.getChildrenKeys("/test_job_1/servers")).thenReturn(Arrays.asList("ip1", "ip2"));
    when(regCenter.getChildrenKeys("/test_job_2/servers")).thenReturn(Arrays.asList("ip3", "ip4"));
    when(regCenter.get("/test_job_1/servers/ip1/status")).thenReturn("RUNNING");
    when(regCenter.get("/test_job_1/servers/ip2/status")).thenReturn("READY");
    when(regCenter.isExisted("/test_job_1/servers/ip2/disabled")).thenReturn(true);
    when(regCenter.isExisted("/test_job_2/servers/ip3/paused")).thenReturn(true);
    when(regCenter.isExisted("/test_job_2/servers/ip4/shutdown")).thenReturn(true);
    int i = 0;
    for (JobBriefInfo each : jobStatisticsAPI.getAllJobsBriefInfo()) {
        i++;
        assertThat(each.getJobName(), is("test_job_" + i));
        assertThat(each.getDescription(), is("desc" + i));
        assertThat(each.getCron(), is("0/1 * * * * ?"));
        assertThat(each.getJobType(), is("SIMPLE"));
        switch(i) {
            case 1:
                assertThat(each.getStatus(), is(JobBriefInfo.JobStatus.DISABLED));
                break;
            case 2:
                assertThat(each.getStatus(), is(JobBriefInfo.JobStatus.ALL_CRASHED));
                break;
            default:
                fail();
        }
    }
}
Also used : JobBriefInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo) Test(org.junit.Test)

Example 2 with JobBriefInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImpl method getAllJobsBriefInfo.

@Override
public Collection<JobBriefInfo> getAllJobsBriefInfo() {
    List<String> jobNames = regCenter.getChildrenKeys("/");
    List<JobBriefInfo> result = new ArrayList<>(jobNames.size());
    for (String each : jobNames) {
        JobBriefInfo jobBriefInfo = getJobBriefInfo(each);
        if (null != jobBriefInfo) {
            result.add(jobBriefInfo);
        }
    }
    Collections.sort(result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) JobBriefInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo)

Example 3 with JobBriefInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImpl method getJobBriefInfo.

@Override
public JobBriefInfo getJobBriefInfo(final String jobName) {
    JobNodePath jobNodePath = new JobNodePath(jobName);
    JobBriefInfo result = new JobBriefInfo();
    result.setJobName(jobName);
    String liteJobConfigJson = regCenter.get(jobNodePath.getConfigNodePath());
    if (null == liteJobConfigJson) {
        return null;
    }
    LiteJobConfiguration liteJobConfig = LiteJobConfigurationGsonFactory.fromJson(liteJobConfigJson);
    result.setJobType(liteJobConfig.getTypeConfig().getJobType().name());
    result.setDescription(liteJobConfig.getTypeConfig().getCoreConfig().getDescription());
    result.setStatus(getJobStatus(jobName));
    result.setCron(liteJobConfig.getTypeConfig().getCoreConfig().getCron());
    return result;
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) JobBriefInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo) JobNodePath(com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)

Example 4 with JobBriefInfo

use of com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo in project elastic-job by dangdangdotcom.

the class JobStatisticsAPIImplTest method assertGetJobBriefInfo.

@Test
public void assertGetJobBriefInfo() {
    when(regCenter.getChildrenKeys("/")).thenReturn(Lists.newArrayList("test_job"));
    when(regCenter.get("/test_job/config")).thenReturn(LifecycleJsonConstants.getSimpleJobJson("test_job", "desc"));
    when(regCenter.getChildrenKeys("/test_job/servers")).thenReturn(Arrays.asList("ip1", "ip2"));
    when(regCenter.get("/test_job/servers/ip1/status")).thenReturn("RUNNING");
    when(regCenter.get("/test_job/servers/ip2/status")).thenReturn("READY");
    when(regCenter.isExisted("/test_job/servers/ip2/disabled")).thenReturn(true);
    JobBriefInfo jobBrief = jobStatisticsAPI.getJobBriefInfo("test_job");
    assertThat(jobBrief.getJobName(), is("test_job"));
    assertThat(jobBrief.getDescription(), is("desc"));
    assertThat(jobBrief.getCron(), is("0/1 * * * * ?"));
    assertThat(jobBrief.getJobType(), is("SIMPLE"));
    assertThat(jobBrief.getStatus(), is(JobBriefInfo.JobStatus.DISABLED));
}
Also used : JobBriefInfo(com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo) Test(org.junit.Test)

Aggregations

JobBriefInfo (com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo)4 Test (org.junit.Test)2 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1 JobNodePath (com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)1 ArrayList (java.util.ArrayList)1