From c3395f8e7a4f5e14356365bf8033a5de12f181f6 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Mon, 29 Nov 2021 22:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=8D=E5=81=A5=E5=BA=B7=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E6=8E=A5=E5=8F=A3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApplicationController.java | 6 +++++ .../discovery/core/BaseInstanceRegistry.java | 25 +++++++++++++++++++ .../discovery/core/InstanceRegistry.java | 7 ++++++ 3 files changed, 38 insertions(+) diff --git a/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/controller/ApplicationController.java b/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/controller/ApplicationController.java index 5a986fa4..514f4932 100644 --- a/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/controller/ApplicationController.java +++ b/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/controller/ApplicationController.java @@ -52,4 +52,10 @@ public class ApplicationController { return Results.success(); } + @PostMapping("/remove") + public Result remove(@RequestBody InstanceInfo instanceInfo) { + instanceRegistry.remove(instanceInfo); + return Results.success(); + } + } diff --git a/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/BaseInstanceRegistry.java b/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/BaseInstanceRegistry.java index b9a45ee5..857c7229 100644 --- a/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/BaseInstanceRegistry.java +++ b/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/BaseInstanceRegistry.java @@ -135,6 +135,31 @@ public class BaseInstanceRegistry implements InstanceRegistry { return true; } + @Override + public void remove(InstanceInfo info) { + ReentrantReadWriteLock.WriteLock writeLock = readWriteLock.writeLock(); + writeLock.lock(); + try { + String appName = info.getAppName(); + String instanceId = info.getInstanceId(); + Map> leaseMap = registry.get(appName); + if (CollectionUtils.isEmpty(leaseMap)) { + log.warn("Failed to remove unhealthy node, no application found :: {}", appName); + return; + } + + Lease remove = leaseMap.remove(instanceId); + if (remove == null) { + log.warn("Failed to remove unhealthy node, no instance found :: {}", instanceId); + return; + } + + log.info("Remove unhealthy node, node ID :: {}", instanceId); + } finally { + writeLock.unlock(); + } + } + static class CircularQueue extends AbstractQueue { private final ArrayBlockingQueue delegate; diff --git a/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/InstanceRegistry.java b/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/InstanceRegistry.java index 2045ec64..dc2f75af 100644 --- a/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/InstanceRegistry.java +++ b/hippo4j-discovery/src/main/java/cn/hippo4j/discovery/core/InstanceRegistry.java @@ -35,4 +35,11 @@ public interface InstanceRegistry { */ boolean renew(InstanceInfo.InstanceRenew instanceRenew); + /** + * Remove. + * + * @param info + */ + void remove(T info); + }