Skip to content

Commit 475e0fc

Browse files
feat:add tips when calling lossless deregister method. (#527)
1 parent 7ab9af4 commit 475e0fc

File tree

2 files changed

+12
-6
lines changed
  • polaris-plugins

2 files changed

+12
-6
lines changed

polaris-plugins/polaris-plugin-api/src/main/java/com/tencent/polaris/api/plugin/lossless/LosslessPolicy.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,34 @@ public interface LosslessPolicy extends Plugin, SortableAware {
3636

3737
String OFFLINE_PATH = "/offline";
3838

39+
String REPS_TEXT_ONLY_LOCALHOST = "only localhost can call this path";
40+
3941
String REPS_TEXT_NO_ACTION = "no action";
4042

43+
String REPS_TEXT_NO_POLICY = "no policy";
44+
4145
String REPS_TEXT_OK = "ok";
4246

4347
String REPS_TEXT_FAILED = "failed";
4448

4549
/**
4650
* build or modify the instance properties
51+
*
4752
* @param instanceProperties properties, for the callback register to set into instance
4853
*/
4954
void buildInstanceProperties(InstanceProperties instanceProperties);
5055

5156
/**
5257
* do lossless register
53-
* @param instance instance to lossless register
58+
*
59+
* @param instance instance to lossless register
5460
* @param instanceProperties properties, for the callback register to set into instance
5561
*/
5662
void losslessRegister(BaseInstance instance, InstanceProperties instanceProperties);
5763

5864
/**
5965
* do lossless deregister
66+
*
6067
* @param instance instance to lossless deregister
6168
*/
6269
void losslessDeregister(BaseInstance instance);

polaris-plugins/polaris-plugins-lossless/lossless-deregister/src/main/java/com/tencent/polaris/plugin/lossless/deregister/DeregisterLosslessPolicy.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.tencent.polaris.api.plugin.lossless.LosslessPolicy;
3333
import com.tencent.polaris.api.plugin.lossless.RegisterStatus;
3434
import com.tencent.polaris.api.pojo.BaseInstance;
35-
import com.tencent.polaris.api.rpc.BaseEntity;
3635
import com.tencent.polaris.api.utils.CollectionUtils;
3736
import com.tencent.polaris.client.pojo.Event;
3837
import com.tencent.polaris.client.util.HttpServerUtils;
@@ -93,8 +92,8 @@ public void handle(HttpExchange exchange) throws IOException {
9392
InetSocketAddress remoteAddress = exchange.getRemoteAddress();
9493
LOG.info("[LosslessDeregister] received lossless deregister request from {}", remoteAddress);
9594
if (!remoteAddress.getAddress().isLoopbackAddress()) {
96-
exchange.sendResponseHeaders(403, 0);
97-
exchange.close();
95+
LOG.warn("[LosslessDeRegister] only loop-back address (like localhost or 127.0.0.1) can call this path");
96+
HttpServerUtils.writeTextToHttpServer(exchange, REPS_TEXT_ONLY_LOCALHOST, 403);
9897
return;
9998
}
10099
Map<BaseInstance, LosslessActionProvider> actionProviders = valueContext.getValue(LosslessActionProvider.CTX_KEY);
@@ -106,8 +105,8 @@ public void handle(HttpExchange exchange) throws IOException {
106105

107106
List<LosslessPolicy> losslessPolicies = extensions.getLosslessPolicies();
108107
if (CollectionUtils.isEmpty(losslessPolicies)) {
109-
LOG.warn("lossless is disabled, no losslessDeregister will do");
110-
exchange.sendResponseHeaders(500, 0);
108+
LOG.warn("[LosslessDeRegister] lossless is disabled, no losslessDeregister will do");
109+
HttpServerUtils.writeTextToHttpServer(exchange, REPS_TEXT_NO_POLICY, 500);
111110
exchange.close();
112111
return;
113112
}

0 commit comments

Comments
 (0)