Skip to content

Commit

Permalink
Remove the DataCenter validation logic when adding DataID to the blac…
Browse files Browse the repository at this point in the history
…klist in Meta
  • Loading branch information
hui-cha committed Dec 23, 2024
1 parent 593ab10 commit 6d4a920
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ public class DataInfoIDBlacklistResource {
@POST
@Path("add")
@Produces(MediaType.APPLICATION_JSON)
public Result addBlackList(@FormParam("dataCenter") String dataCenter,
@FormParam("dataId") String dataId,
public Result addBlackList(@FormParam("dataId") String dataId,
@FormParam("group") String group,
@FormParam("instanceId") String instanceId) {
try {
return process(dataCenter, dataId, group, instanceId, Operation.ADD);
return process(dataId, group, instanceId, Operation.ADD);
} catch (Throwable throwable) {
LOGGER.error("Save dataid black list exception", throwable);
return Result.failed("Save dataid black list exception");
Expand All @@ -68,28 +67,20 @@ public Result addBlackList(@FormParam("dataCenter") String dataCenter,
@POST
@Path("delete")
@Produces(MediaType.APPLICATION_JSON)
public Result deleteBlackList(@FormParam("dataCenter") String dataCenter,
@FormParam("dataId") String dataId,
public Result deleteBlackList(@FormParam("dataId") String dataId,
@FormParam("group") String group,
@FormParam("instanceId") String instanceId) {
try {
return process(dataCenter, dataId, group, instanceId, Operation.DELETE);
return process(dataId, group, instanceId, Operation.DELETE);
} catch (Throwable throwable) {
LOGGER.error("Delete dataid black list exception", throwable);
return Result.failed("Delete dataid black list exception");
}
}

private Result process(String dataCenter, String dataId, String group, String instanceId, Operation operation) {
private Result process(String dataId, String group, String instanceId, Operation operation) {
// 1. 参数检查
// 1.1. 检查 DataCenter 是否就是当前 Meta 的所属 DataCenter
String clusterId = defaultCommonConfig.getClusterId(TableEnum.PROVIDE_DATA.getTableName(), ValueConstants.SESSION_DATAID_BLACKLIST_DATA_ID);
if (!StringUtils.equals(dataCenter, clusterId)) {
// 给定的机房不是当前机房,那么拒绝添加黑名单,直接返回
return Result.failed("Invalid data center");
}

// 1.2. 检查要处理的 DataId 以及 Group 是否符合规则
// 检查要处理的 DataId 以及 Group 是否符合规则
DataInfo dataInfo = new DataInfo(instanceId, dataId, group);
Tuple<Boolean, String> checkResult = this.checkDataInfoId(dataInfo);
if (!checkResult.o1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ public void testAddAndDelete() {
ProvideDataService provideDataService = createProvideDataService();
DataInfoIDBlacklistResource resource = this.createDataIDBlacklistResource(provideDataService);

String dataCenter = "DEFAULT_DATACENTER";
String dataIdOne = "dataid.black.list.test";
String group = "dataid-black-list-test-group";
String instanceId = "DEFAULT_INSTANCE_ID";

// 添加了两个数据
Result resultOne = resource.addBlackList(dataCenter, dataIdOne, group, instanceId);
Result resultOne = resource.addBlackList(dataIdOne, group, instanceId);
Assert.assertTrue(resultOne.isSuccess());

String dataIdTwo = "dataid.black.list.test2";
Result resultTwo = resource.addBlackList(dataCenter, dataIdTwo, group, instanceId);
Result resultTwo = resource.addBlackList(dataIdTwo, group, instanceId);
Assert.assertTrue(resultTwo.isSuccess());

// 因此这里的查询结果也应该是两条
Expand All @@ -85,11 +84,11 @@ public void testAddAndDelete() {
Assert.assertTrue(data.contains(String.format("%s#@#%s#@#%s", dataIdTwo, instanceId, group)));

// 删除了第一条数据以及一条不存在的数据
Result deleteResultOne = resource.deleteBlackList(dataCenter, dataIdOne, group, instanceId);
Result deleteResultOne = resource.deleteBlackList(dataIdOne, group, instanceId);
Assert.assertTrue(deleteResultOne.isSuccess());

String notExistDataId = "not.exist";
Result deleteResultTwo = resource.deleteBlackList(dataCenter, notExistDataId, group, instanceId);
Result deleteResultTwo = resource.deleteBlackList(notExistDataId, group, instanceId);
Assert.assertTrue(deleteResultTwo.isSuccess());

// 因此这里的查询结果应该是只有一条数据,且是第二条数据
Expand All @@ -105,7 +104,6 @@ public void testAddAndDelete() {

@Test
public void testNotify() {
String dataCenter = "DEFAULT_DATACENTER";
String dataId = "dataid.black.list.test";
String group = "dataid-black-list-test-group";
String instanceId = "DEFAULT_INSTANCE_ID";
Expand All @@ -127,7 +125,7 @@ public void testNotify() {
counter.addAndGet(1);
});

Result result = resource.addBlackList(dataCenter, dataId, group, instanceId);
Result result = resource.addBlackList(dataId, group, instanceId);
Assert.assertTrue(result.isSuccess());
Assert.assertEquals(1, counter.get());
}
Expand Down

0 comments on commit 6d4a920

Please sign in to comment.