服务端添加清理不健康注册实例接口.

pull/12/head
chen.ma 3 years ago
parent 394a2caba0
commit c3395f8e7a

@ -52,4 +52,10 @@ public class ApplicationController {
return Results.success();
}
@PostMapping("/remove")
public Result remove(@RequestBody InstanceInfo instanceInfo) {
instanceRegistry.remove(instanceInfo);
return Results.success();
}
}

@ -135,6 +135,31 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
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<String, Lease<InstanceInfo>> leaseMap = registry.get(appName);
if (CollectionUtils.isEmpty(leaseMap)) {
log.warn("Failed to remove unhealthy node, no application found :: {}", appName);
return;
}
Lease<InstanceInfo> 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<E> extends AbstractQueue<E> {
private final ArrayBlockingQueue<E> delegate;

@ -35,4 +35,11 @@ public interface InstanceRegistry<T> {
*/
boolean renew(InstanceInfo.InstanceRenew instanceRenew);
/**
* Remove.
*
* @param info
*/
void remove(T info);
}

Loading…
Cancel
Save