From d1de98fdcda7de6d1b131c68116626c796ed98e2 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Mon, 24 Jun 2024 13:43:36 +0800 Subject: [PATCH] feat:add tips when calling lossless deregister method. --- .../polaris/api/plugin/lossless/LosslessPolicy.java | 9 ++++++++- .../lossless/deregister/DeregisterLosslessPolicy.java | 9 ++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/lossless/LosslessPolicy.java b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/lossless/LosslessPolicy.java index 537540084..a498e91b9 100644 --- a/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/lossless/LosslessPolicy.java +++ b/polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/lossless/LosslessPolicy.java @@ -36,27 +36,34 @@ public interface LosslessPolicy extends Plugin, SortableAware { String OFFLINE_PATH = "/offline"; + String REPS_TEXT_ONLY_LOCALHOST = "only localhost can call this path"; + String REPS_TEXT_NO_ACTION = "no action"; + String REPS_TEXT_NO_POLICY = "no policy"; + String REPS_TEXT_OK = "ok"; String REPS_TEXT_FAILED = "failed"; /** * build or modify the instance properties + * * @param instanceProperties properties, for the callback register to set into instance */ void buildInstanceProperties(InstanceProperties instanceProperties); /** * do lossless register - * @param instance instance to lossless register + * + * @param instance instance to lossless register * @param instanceProperties properties, for the callback register to set into instance */ void losslessRegister(BaseInstance instance, InstanceProperties instanceProperties); /** * do lossless deregister + * * @param instance instance to lossless deregister */ void losslessDeregister(BaseInstance instance); diff --git a/polaris-plugins/polaris-plugins-lossless/lossless-deregister/src/main/java/com/tencent/polaris/plugin/lossless/deregister/DeregisterLosslessPolicy.java b/polaris-plugins/polaris-plugins-lossless/lossless-deregister/src/main/java/com/tencent/polaris/plugin/lossless/deregister/DeregisterLosslessPolicy.java index eb057e3bf..cd6cb05e1 100644 --- a/polaris-plugins/polaris-plugins-lossless/lossless-deregister/src/main/java/com/tencent/polaris/plugin/lossless/deregister/DeregisterLosslessPolicy.java +++ b/polaris-plugins/polaris-plugins-lossless/lossless-deregister/src/main/java/com/tencent/polaris/plugin/lossless/deregister/DeregisterLosslessPolicy.java @@ -32,7 +32,6 @@ import com.tencent.polaris.api.plugin.lossless.LosslessPolicy; import com.tencent.polaris.api.plugin.lossless.RegisterStatus; import com.tencent.polaris.api.pojo.BaseInstance; -import com.tencent.polaris.api.rpc.BaseEntity; import com.tencent.polaris.api.utils.CollectionUtils; import com.tencent.polaris.client.pojo.Event; import com.tencent.polaris.client.util.HttpServerUtils; @@ -93,8 +92,8 @@ public void handle(HttpExchange exchange) throws IOException { InetSocketAddress remoteAddress = exchange.getRemoteAddress(); LOG.info("[LosslessDeregister] received lossless deregister request from {}", remoteAddress); if (!remoteAddress.getAddress().isLoopbackAddress()) { - exchange.sendResponseHeaders(403, 0); - exchange.close(); + LOG.warn("[LosslessDeRegister] only loop-back address (like localhost or 127.0.0.1) can call this path"); + HttpServerUtils.writeTextToHttpServer(exchange, REPS_TEXT_ONLY_LOCALHOST, 403); return; } Map actionProviders = valueContext.getValue(LosslessActionProvider.CTX_KEY); @@ -106,8 +105,8 @@ public void handle(HttpExchange exchange) throws IOException { List losslessPolicies = extensions.getLosslessPolicies(); if (CollectionUtils.isEmpty(losslessPolicies)) { - LOG.warn("lossless is disabled, no losslessDeregister will do"); - exchange.sendResponseHeaders(500, 0); + LOG.warn("[LosslessDeRegister] lossless is disabled, no losslessDeregister will do"); + HttpServerUtils.writeTextToHttpServer(exchange, REPS_TEXT_NO_POLICY, 500); exchange.close(); return; }