Skip to content

Commit

Permalink
fix: tenant adapter (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Apr 1, 2024
1 parent 7a2f055 commit 1813f35
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public interface RequestContextAdapter {

<T> void queryWrapperTenantAdapt(QueryWrapper<T> queryWrapper, String tenant, String workspace);

void tenantAdapt(String tenant, String workspace);

<T> void queryWrapperTenantAdapt(QueryWrapper<T> queryWrapper, String tenant);

<T> void queryWrapperWorkspaceAdapt(QueryWrapper<T> queryWrapper, String workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public <T> void queryWrapperTenantAdapt(QueryWrapper<T> queryWrapper, String ten
}
}

@Override
public void tenantAdapt(String tenant, String workspace) {

}

@Override
public <T> void queryWrapperTenantAdapt(QueryWrapper<T> queryWrapper, String tenant) {
if (queryWrapper != null && StringUtils.isNotBlank(tenant)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public interface AlertGroupService extends IService<AlarmGroup> {

Boolean updateById(AlarmGroupDTO alarmGroupDTO);

AlarmGroupDTO queryById(Long id, String tenant);

AlarmGroupDTO queryById(Long id, String tenant, String workspace);

List<AlarmGroupDTO> getListByUserLike(String userId, String tenant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public List<AlarmMetric> queryByMetric(String metric, String tenant, String work

@Override
public List<AlarmMetric> queryByRuleId(Long ruleId, String tenant, String workspace) {
this.requestContextAdapter.tenantAdapt(tenant, workspace);
QueryWrapper<AlarmMetric> wrapper = new QueryWrapper<>();
wrapper.eq("deleted", 0);
if (StringUtils.isNotBlank(tenant)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ public MonitorPageResult<AlarmDingDingRobotDTO> getListByPage(
AlarmDingDingRobot alarmDingDingRobot =
alarmDingDingRobotConverter.dtoToDO(pageRequest.getTarget());

wrapper.eq("tenant", alarmDingDingRobot.getTenant());
if (StringUtils.isNotEmpty(alarmDingDingRobot.getWorkspace())) {
wrapper.eq("workspace", alarmDingDingRobot.getWorkspace());
}
requestContextAdapter.queryWrapperTenantAdapt(wrapper, alarmDingDingRobot.getTenant(),
alarmDingDingRobot.getWorkspace());

if (null != alarmDingDingRobot.getId()) {
wrapper.eq("id", alarmDingDingRobot.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public Boolean updateById(AlarmGroupDTO alarmGroupDTO) {
return this.updateById(alarmGroup);
}

@Override
public AlarmGroupDTO queryById(Long id, String tenant) {
return queryById(id, tenant, requestContextAdapter.getWorkspace(true));
}

@Override
public AlarmGroupDTO queryById(Long id, String tenant, String workspace) {
QueryWrapper<AlarmGroup> wrapper = new QueryWrapper<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void checkParameter() {
public void doManage() {

AlarmGroupDTO item = alarmGroupService.queryById(alarmGroup.getId(),
RequestContext.getContext().ms.getTenant());
RequestContext.getContext().ms.getTenant(), requestContextAdapter.getWorkspace(true));
if (null == item) {
throw new MonitorException("cannot find record: " + alarmGroup.getId());
}
Expand Down Expand Up @@ -233,8 +233,8 @@ public void checkParameter() {
@Override
public void doManage() {

AlarmGroupDTO save =
alarmGroupService.queryById(id, RequestContext.getContext().ms.getTenant());
AlarmGroupDTO save = alarmGroupService.queryById(id,
RequestContext.getContext().ms.getTenant(), requestContextAdapter.getWorkspace(true));
JsonResult.createSuccessResult(result, save);
}
});
Expand All @@ -256,7 +256,8 @@ public void checkParameter() {
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
boolean rtn = false;
AlarmGroupDTO alarmGroup = alarmGroupService.queryById(id, ms.getTenant());
AlarmGroupDTO alarmGroup = alarmGroupService.queryById(id, ms.getTenant(),
requestContextAdapter.getWorkspace(true));
if (alarmGroup != null && StringUtils.equals(alarmGroup.getTenant(), ms.getTenant())) {
rtn = alarmGroupService.removeById(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void checkParameter() {
@Override
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
AlertNotifyRecordDTO save = alertNotifyRecordService.queryByHistoryDetailId(historyDetailId,
ms.getTenant(), ms.getWorkspace());
AlertNotifyRecordDTO save =
alertNotifyRecordService.queryByHistoryDetailId(historyDetailId, tenant(), workspace());
JsonResult.createSuccessResult(result, save);
}
});
Expand All @@ -69,12 +69,13 @@ public void checkParameter() {

@Override
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
if (null != ms && !StringUtils.isEmpty(ms.tenant)) {
pageRequest.getTarget().setTenant(ms.tenant);
String tenant = tenant();
String workspace = workspace();
if (StringUtils.isNotEmpty(tenant)) {
pageRequest.getTarget().setTenant(tenant);
}
if (null != ms && !StringUtils.isEmpty(ms.workspace)) {
pageRequest.getTarget().setWorkspace(ms.workspace);
if (StringUtils.isNotEmpty(workspace)) {
pageRequest.getTarget().setWorkspace(workspace);
}
JsonResult.createSuccessResult(result, alertNotifyRecordService.getListByPage(pageRequest));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class AlarmRuleLevelAuthorizationChecker extends AbstractQueryChecker
"max", "count", "none", "SUM", "AVG", "MIX", "MAX", "COUNT", "NONE"));
private static final Set<String> metricTypes =
new HashSet<>(Arrays.asList("app", "cache", "log", "oss", "trace", "system", "metric",
"service", "function", "pg", "mongodb", "db", "miniProgram"));
"service", "function", "pg", "mongodb", "db", "miniProgram", "mysql"));
private static final Set<String> products = new HashSet<>(Arrays.asList("JVM", "Function",
"OceanBase", "Tbase", "PortCheck", "System", "MiniProgram", "Spanner", "IoT"));

Expand Down

0 comments on commit 1813f35

Please sign in to comment.