diff --git a/elastic-job-doc/content/post/release_notes.md b/elastic-job-doc/content/post/release_notes.md index 7d3e6c5c8c..c6cdd14b67 100644 --- a/elastic-job-doc/content/post/release_notes.md +++ b/elastic-job-doc/content/post/release_notes.md @@ -21,6 +21,7 @@ weight=1 1. [ISSUE #266](https://github.com/dangdangdotcom/elastic-job/issues/266) Elastic-Job-Lite启动脚本指定端口无效 1. [ISSUE #269](https://github.com/dangdangdotcom/elastic-job/issues/269) EventTrace失败记录不受采样率影响并且记录失败时间 +1. [ISSUE #272](https://github.com/dangdangdotcom/elastic-job/issues/272) Elastic-Job-Lite界面作业维度,只有全部服务器被禁用时,才应显示为被禁用 ## 2.1.0 diff --git a/elastic-job-lite/elastic-job-lite-lifecycle/src/main/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java b/elastic-job-lite/elastic-job-lite-lifecycle/src/main/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java index 2a5d77cd91..b60c71ad15 100644 --- a/elastic-job-lite/elastic-job-lite-lifecycle/src/main/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java +++ b/elastic-job-lite/elastic-job-lite-lifecycle/src/main/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImpl.java @@ -96,12 +96,14 @@ private JobStatus getJobStatus(final String jobName) { if (!instances.containsAll(shardingInstances) || shardingInstances.isEmpty()) { return JobStatus.SHARDING_ERROR; } - for (String each : regCenter.getChildrenKeys(jobNodePath.getServerNodePath())) { + List serversPath = regCenter.getChildrenKeys(jobNodePath.getServerNodePath()); + int disabledServerCount = 0; + for (String each : serversPath) { if ("DISABLED".equals(regCenter.get(jobNodePath.getServerNodePath(each)))) { - return JobStatus.DISABLED; + disabledServerCount++; } } - return JobStatus.OK; + return disabledServerCount == serversPath.size() ? JobStatus.DISABLED : JobStatus.OK; } private int getJobInstanceCount(final String jobName) { diff --git a/elastic-job-lite/elastic-job-lite-lifecycle/src/test/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImplTest.java b/elastic-job-lite/elastic-job-lite-lifecycle/src/test/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImplTest.java index 1df491ebd5..c0a5f662ac 100644 --- a/elastic-job-lite/elastic-job-lite-lifecycle/src/test/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImplTest.java +++ b/elastic-job-lite/elastic-job-lite-lifecycle/src/test/java/com/dangdang/ddframe/job/lite/lifecycle/internal/statistics/JobStatisticsAPIImplTest.java @@ -54,7 +54,7 @@ public void assertGetJobsTotalCount() { } @Test - public void assertGetJobBriefInfo() { + public void assertGetOKJobBriefInfo() { 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")); @@ -73,12 +73,27 @@ public void assertGetJobBriefInfo() { assertThat(jobBrief.getStatus(), is(JobStatus.OK)); } + @Test + public void assertGetOKJobBriefInfoWithPartialDisabledServer() { + 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")).thenReturn("DISABLED"); + when(regCenter.getChildrenKeys("/test_job/instances")).thenReturn(Arrays.asList("ip1@-@defaultInstance", "ip2@-@defaultInstance")); + when(regCenter.getChildrenKeys("/test_job/sharding")).thenReturn(Arrays.asList("0", "1")); + when(regCenter.get("/test_job/sharding/0/instance")).thenReturn("ip1@-@defaultInstance"); + when(regCenter.get("/test_job/sharding/1/instance")).thenReturn("ip2@-@defaultInstance"); + JobBriefInfo jobBrief = jobStatisticsAPI.getJobBriefInfo("test_job"); + assertThat(jobBrief.getStatus(), is(JobStatus.OK)); + } + @Test public void assertGetDisabledJobBriefInfo() { 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")).thenReturn("DISABLED"); + when(regCenter.get("/test_job/servers/ip2")).thenReturn("DISABLED"); when(regCenter.getChildrenKeys("/test_job/instances")).thenReturn(Arrays.asList("ip1@-@defaultInstance", "ip2@-@defaultInstance")); when(regCenter.getChildrenKeys("/test_job/sharding")).thenReturn(Arrays.asList("0", "1")); when(regCenter.get("/test_job/sharding/0/instance")).thenReturn("ip1@-@defaultInstance");