This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new d2664d0 Fixes delete listener event path (#1325)
d2664d0 is described below
commit d2664d0c85d5a4c117c1687ffd48d2b051927ea8
Author: Haoran Meng <[email protected]>
AuthorDate: Mon Aug 3 16:23:14 2020 +0800
Fixes delete listener event path (#1325)
---
.../scheduler/config/app/CloudAppConfigurationListener.java | 3 +--
.../scheduler/config/job/CloudJobConfigurationListener.java | 3 +--
.../scheduler/state/disable/app/CloudAppDisableListener.java | 2 +-
.../scheduler/state/disable/job/CloudJobDisableListener.java | 2 +-
.../scheduler/config/app/CloudAppConfigurationListenerTest.java | 9 ++++++---
.../scheduler/config/job/CloudJobConfigurationListenerTest.java | 6 ++++--
.../scheduler/state/disable/app/CloudAppDisableListenerTest.java | 9 ++++++---
.../scheduler/state/disable/job/CloudJobDisableListenerTest.java | 9 ++++++---
8 files changed, 26 insertions(+), 17 deletions(-)
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListener.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListener.java
index a501747..1e23626 100644
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListener.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListener.java
@@ -50,9 +50,8 @@ public final class CloudAppConfigurationListener implements
CuratorCacheListener
}
@Override
-
public void event(final Type type, final ChildData oldData, final
ChildData data) {
- String path = data.getPath();
+ String path = Type.NODE_DELETED == type ? oldData.getPath() :
data.getPath();
if (Type.NODE_DELETED == type && isJobAppConfigNode(path)) {
String appName =
path.substring(CloudAppConfigurationNode.ROOT.length() + 1);
stopExecutors(appName);
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListener.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListener.java
index 2bcef50..43d4464 100755
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListener.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListener.java
@@ -51,9 +51,8 @@ public final class CloudJobConfigurationListener implements
CuratorCacheListener
}
@Override
-
public void event(final Type type, final ChildData oldData, final
ChildData data) {
- String path = data.getPath();
+ String path = Type.NODE_DELETED == type ? oldData.getPath() :
data.getPath();
if (Type.NODE_CREATED == type && isJobConfigNode(path)) {
CloudJobConfigurationPOJO cloudJobConfig =
getCloudJobConfiguration(data);
if (null != cloudJobConfig) {
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListener.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListener.java
index 4610be7..8f30949 100644
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListener.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListener.java
@@ -47,7 +47,7 @@ public final class CloudAppDisableListener implements
CuratorCacheListener {
@Override
public void event(final Type type, final ChildData oldData, final
ChildData data) {
- String path = data.getPath();
+ String path = Type.NODE_DELETED == type ? oldData.getPath() :
data.getPath();
if (Type.NODE_CREATED == type && isAppDisableNode(path)) {
String appName = path.substring(DisableAppNode.ROOT.length() + 1);
if (Objects.nonNull(appName)) {
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListener.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListener.java
index c5800bc..52fd04e 100644
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListener.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListener.java
@@ -42,7 +42,7 @@ public final class CloudJobDisableListener implements
CuratorCacheListener {
@Override
public void event(final Type type, final ChildData oldData, final
ChildData data) {
- String path = data.getPath();
+ String path = Type.NODE_DELETED == type ? oldData.getPath() :
data.getPath();
if (Type.NODE_CREATED == type && isJobDisableNode(path)) {
String jobName = path.substring(DisableJobNode.ROOT.length() + 1);
if (Objects.nonNull(jobName)) {
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListenerTest.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListenerTest.java
index 2167b0c..2a5a005 100644
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListenerTest.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationListenerTest.java
@@ -73,21 +73,24 @@ public final class CloudAppConfigurationListenerTest {
@Test
public void assertRemoveWithInvalidPath() {
-
cloudAppConfigurationListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/other/test_app", null, "".getBytes()));
+
cloudAppConfigurationListener.event(CuratorCacheListener.Type.NODE_DELETED, new
ChildData("/other/test_app", null, "".getBytes()),
+ new ChildData("/other/test_app", null, "".getBytes()));
verify(mesosStateService, times(0)).executors(ArgumentMatchers.any());
verify(producerManager,
times(0)).sendFrameworkMessage(any(Protos.ExecutorID.class),
any(Protos.SlaveID.class), any());
}
@Test
public void assertRemoveWithNoAppNamePath() {
-
cloudAppConfigurationListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/config/app", null, "".getBytes()));
+
cloudAppConfigurationListener.event(CuratorCacheListener.Type.NODE_DELETED, new
ChildData("/config/app", null, "".getBytes()),
+ new ChildData("/config/app", null, "".getBytes()));
verify(mesosStateService, times(0)).executors(ArgumentMatchers.any());
verify(producerManager,
times(0)).sendFrameworkMessage(any(Protos.ExecutorID.class),
any(Protos.SlaveID.class), any());
}
@Test
public void assertRemoveApp() {
-
cloudAppConfigurationListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/config/app/test_app", null, "".getBytes()));
+
cloudAppConfigurationListener.event(CuratorCacheListener.Type.NODE_DELETED, new
ChildData("/config/app/test_app", null, "".getBytes()),
+ new ChildData("/config/app/test_app", null, "".getBytes()));
verify(mesosStateService).executors("test_app");
}
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
index 2c4d9e8..71011aa 100755
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
@@ -82,7 +82,8 @@ public final class CloudJobConfigurationListenerTest {
@Test
public void assertChildEventWhenIsRootConfigPath() {
- cloudJobConfigurationListener.event(Type.NODE_DELETED, null, new
ChildData("/config/job", null, "".getBytes()));
+ cloudJobConfigurationListener.event(Type.NODE_DELETED, new
ChildData("/config/job", null, "".getBytes()),
+ new ChildData("/config/job", null, "".getBytes()));
verify(producerManager, times(0)).schedule(ArgumentMatchers.any());
verify(producerManager, times(0)).reschedule(ArgumentMatchers.any());
verify(producerManager, times(0)).unschedule(ArgumentMatchers.any());
@@ -125,7 +126,8 @@ public final class CloudJobConfigurationListenerTest {
@Test
public void assertChildEventWhenStateIsRemovedAndIsJobConfigPath() {
- cloudJobConfigurationListener.event(Type.NODE_DELETED, null, new
ChildData("/config/job/test_job", null, "".getBytes()));
+ cloudJobConfigurationListener.event(Type.NODE_DELETED, new
ChildData("/config/job/test_job", null, "".getBytes()),
+ new ChildData("/config/job/test_job", null, "".getBytes()));
verify(producerManager).unschedule("test_job");
}
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListenerTest.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListenerTest.java
index 7788cb6..cecf197 100644
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListenerTest.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/app/CloudAppDisableListenerTest.java
@@ -91,21 +91,24 @@ public final class CloudAppDisableListenerTest {
@Test
public void assertEnableWithInvalidPath() {
- cloudAppDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/other/test_app", null, "".getBytes()));
+ cloudAppDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
new ChildData("/other/test_app", null, "".getBytes()),
+ new ChildData("/other/test_app", null, "".getBytes()));
verify(jobConfigService, times(0)).loadAll();
verify(producerManager, times(0)).reschedule(ArgumentMatchers.any());
}
@Test
public void assertEnableWithNoAppNamePath() {
- cloudAppDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/state/disable/app", null, "".getBytes()));
+ cloudAppDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
new ChildData("/state/disable/app", null, "".getBytes()),
+ new ChildData("/state/disable/app", null, "".getBytes()));
verify(jobConfigService, times(0)).loadAll();
verify(producerManager, times(0)).unschedule(ArgumentMatchers.any());
}
@Test
public void assertEnable() {
- cloudAppDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/state/disable/app/app_test", null, "".getBytes()));
+ cloudAppDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
new ChildData("/state/disable/app/app_test", null, "".getBytes()),
+ new ChildData("/state/disable/app/app_test", null,
"".getBytes()));
verify(jobConfigService).loadAll();
}
diff --git
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListenerTest.java
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListenerTest.java
index 5169a14..a0b51a4 100644
---
a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListenerTest.java
+++
b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/disable/job/CloudJobDisableListenerTest.java
@@ -87,21 +87,24 @@ public final class CloudJobDisableListenerTest {
@Test
public void assertEnableWithInvalidPath() {
- cloudJobDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/other/test_job", null, "".getBytes()));
+ cloudJobDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
new ChildData("/other/test_job", null, "".getBytes()),
+ new ChildData("/other/test_job", null, "".getBytes()));
verify(producerManager, times(0)).unschedule(ArgumentMatchers.any());
verify(producerManager, times(0)).reschedule(ArgumentMatchers.any());
}
@Test
public void assertEnableWithNoJobNamePath() {
- cloudJobDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/state/disable/job", null, "".getBytes()));
+ cloudJobDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
new ChildData("/state/disable/job", null, "".getBytes()),
+ new ChildData("/state/disable/job", null, "".getBytes()));
verify(producerManager, times(0)).unschedule(ArgumentMatchers.any());
verify(producerManager, times(0)).reschedule(ArgumentMatchers.any());
}
@Test
public void assertEnable() {
- cloudJobDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
null, new ChildData("/state/disable/job/job_test", null, "".getBytes()));
+ cloudJobDisableListener.event(CuratorCacheListener.Type.NODE_DELETED,
new ChildData("/state/disable/job/job_test", null, "".getBytes()),
+ new ChildData("/state/disable/job/job_test", null,
"".getBytes()));
verify(producerManager).reschedule(eq("job_test"));
}