mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 11:52:08 +08:00
权限调整
This commit is contained in:
@@ -11,6 +11,7 @@ import com.xiaojukeji.kafka.manager.common.entity.ao.topic.MineTopicSummary;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.TopicDO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.TopicExpiredDO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.TopicStatisticsDO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.gateway.AuthorityDO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -130,5 +131,12 @@ public interface TopicManagerService {
|
||||
* @return
|
||||
*/
|
||||
ResultStatus addTopicQuota(TopicQuota topicQuota);
|
||||
|
||||
/**
|
||||
* topic权限调整
|
||||
* @param authorityDO topic权限
|
||||
* @return
|
||||
*/
|
||||
ResultStatus addAuthority(AuthorityDO authorityDO);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.xiaojukeji.kafka.manager.common.entity.pojo.gateway.AuthorityDO;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.DateUtils;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.JsonUtils;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.NumberUtils;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.SpringTool;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
|
||||
import com.xiaojukeji.kafka.manager.common.zookeeper.znode.brokers.TopicMetadata;
|
||||
import com.xiaojukeji.kafka.manager.common.zookeeper.znode.config.TopicQuotaData;
|
||||
@@ -653,6 +654,38 @@ public class TopicManagerServiceImpl implements TopicManagerService {
|
||||
return ResultStatus.MYSQL_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultStatus addAuthority(AuthorityDO authorityDO) {
|
||||
// 查询该用户拥有的应用
|
||||
List<AppDO> appDOs = appService.getByPrincipal(SpringTool.getUserName());
|
||||
if (ValidateUtils.isEmptyList(appDOs)) {
|
||||
// 该用户无应用,需要先申请应用
|
||||
return ResultStatus.APP_NOT_EXIST;
|
||||
}
|
||||
List<Long> appIds = appDOs.stream().map(AppDO::getId).collect(Collectors.toList());
|
||||
if (!appIds.contains(authorityDO.getAppId())) {
|
||||
// 入参中的appId,该用户未拥有
|
||||
return ResultStatus.APP_NOT_EXIST;
|
||||
}
|
||||
// 获取物理集群id
|
||||
Long physicalClusterId = logicalClusterMetadataManager.getPhysicalClusterId(authorityDO.getClusterId());
|
||||
if (ValidateUtils.isNull(physicalClusterId)) {
|
||||
// 集群不存在
|
||||
return ResultStatus.CLUSTER_NOT_EXIST;
|
||||
}
|
||||
TopicDO topic = getByTopicName(physicalClusterId, authorityDO.getTopicName());
|
||||
if (ValidateUtils.isNull(topic)) {
|
||||
// topic不存在
|
||||
return ResultStatus.TOPIC_NOT_EXIST;
|
||||
}
|
||||
// 设置物理集群id
|
||||
authorityDO.setClusterId(physicalClusterId);
|
||||
if (authorityService.addAuthority(authorityDO) > 0) {
|
||||
return ResultStatus.SUCCESS;
|
||||
}
|
||||
return ResultStatus.MYSQL_ERROR;
|
||||
}
|
||||
|
||||
private RdTopicBasic convert2RdTopicBasic(ClusterDO clusterDO,
|
||||
String topicName,
|
||||
TopicDO topicDO,
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TopicAuthorityDTO extends ClusterTopicDTO {
|
||||
@ApiModelProperty(value = "appId")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "0:无权限, 1:读, 2:写, 3:读写")
|
||||
@ApiModelProperty(value = "0:无权限, 1:读, 2:写, 3:读写, 4:可管理")
|
||||
private Integer access;
|
||||
|
||||
public String getAppId() {
|
||||
|
||||
@@ -14,12 +14,14 @@ import com.xiaojukeji.kafka.manager.common.entity.vo.normal.consumer.ConsumerGro
|
||||
import com.xiaojukeji.kafka.manager.common.entity.vo.normal.topic.TopicAuthorizedAppVO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.vo.normal.topic.TopicRequestTimeDetailVO;
|
||||
import com.xiaojukeji.kafka.manager.common.zookeeper.znode.brokers.TopicMetadata;
|
||||
import com.xiaojukeji.kafka.manager.openapi.common.dto.TopicAuthorityDTO;
|
||||
import com.xiaojukeji.kafka.manager.openapi.common.vo.TopicOffsetChangedVO;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.ClusterDO;
|
||||
import com.xiaojukeji.kafka.manager.service.cache.PhysicalClusterMetadataManager;
|
||||
import com.xiaojukeji.kafka.manager.service.service.*;
|
||||
import com.xiaojukeji.kafka.manager.common.constant.ApiPrefix;
|
||||
import com.xiaojukeji.kafka.manager.web.converters.AuthorityConverter;
|
||||
import com.xiaojukeji.kafka.manager.web.converters.CommonModelConverter;
|
||||
import com.xiaojukeji.kafka.manager.web.converters.ConsumerModelConverter;
|
||||
import com.xiaojukeji.kafka.manager.web.converters.TopicModelConverter;
|
||||
@@ -147,4 +149,14 @@ public class ThirdPartTopicController {
|
||||
return Result.buildFrom(topicManagerService.addTopicQuota(TopicQuota.buildFrom(dto)));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "权限调整",notes = "权限调整")
|
||||
@RequestMapping(value = "{topics/authority/add}",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result addAuthority(@RequestBody TopicAuthorityDTO dto) {
|
||||
//非空校验
|
||||
if (ValidateUtils.isNull(dto) || !dto.paramLegal()) {
|
||||
return Result.buildFrom(ResultStatus.PARAM_ILLEGAL);
|
||||
}
|
||||
return Result.buildFrom(topicManagerService.addAuthority(AuthorityConverter.convert2AuthorityDO(dto)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xiaojukeji.kafka.manager.web.converters;
|
||||
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.gateway.AuthorityDO;
|
||||
import com.xiaojukeji.kafka.manager.openapi.common.dto.TopicAuthorityDTO;
|
||||
|
||||
public class AuthorityConverter {
|
||||
public static AuthorityDO convert2AuthorityDO(TopicAuthorityDTO dto) {
|
||||
AuthorityDO authorityDO = new AuthorityDO();
|
||||
authorityDO.setAppId(dto.getAppId());
|
||||
authorityDO.setClusterId(dto.getClusterId());
|
||||
authorityDO.setTopicName(dto.getTopicName());
|
||||
authorityDO.setAccess(dto.getAccess());
|
||||
return authorityDO;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user