mirror of
https://github.com/didi/KnowStreaming.git
synced 2026-01-10 09:04:26 +08:00
v2.1版本更新
This commit is contained in:
@@ -6,23 +6,24 @@ package com.xiaojukeji.kafka.manager.bpm.common;
|
||||
* @date 19/6/23
|
||||
*/
|
||||
public enum OrderTypeEnum {
|
||||
APPLY_TOPIC (00, "Topic申请", "applyTopicOrder"),
|
||||
DELETE_TOPIC (10, "Topic下线", "deleteTopicOrder"),
|
||||
APPLY_TOPIC (00, "Topic申请", "applyTopicOrder"),
|
||||
DELETE_TOPIC (10, "Topic下线", "deleteTopicOrder"),
|
||||
THIRD_PART_DELETE_TOPIC (20, "第三方Topic下线申请", "thirdPartDeleteTopicOrder"),
|
||||
|
||||
APPLY_APP (01, "应用申请", "applyAppOrder"),
|
||||
DELETE_APP (11, "应用下线", "deleteAppOrder"),
|
||||
APPLY_APP (01, "应用申请", "applyAppOrder"),
|
||||
DELETE_APP (11, "应用下线", "deleteAppOrder"),
|
||||
|
||||
APPLY_QUOTA (02, "配额申请", "applyQuotaOrder"),
|
||||
APPLY_PARTITION (12, "分区申请", "applyPartitionOrder"),
|
||||
APPLY_QUOTA (02, "配额申请", "applyQuotaOrder"),
|
||||
APPLY_PARTITION (12, "分区申请", "applyPartitionOrder"),
|
||||
|
||||
APPLY_AUTHORITY (03, "权限申请", "applyAuthorityOrder"),
|
||||
DELETE_AUTHORITY (13, "权限删除", "deleteAuthorityOrder"),
|
||||
APPLY_AUTHORITY (03, "权限申请", "applyAuthorityOrder"),
|
||||
DELETE_AUTHORITY (13, "权限删除", "deleteAuthorityOrder"),
|
||||
|
||||
APPLY_CLUSTER (04, "集群申请", "applyClusterOrder"),
|
||||
DELETE_CLUSTER (14, "集群下线", "deleteClusterOrder"),
|
||||
APPLY_CLUSTER (04, "集群申请", "applyClusterOrder"),
|
||||
DELETE_CLUSTER (14, "集群下线", "deleteClusterOrder"),
|
||||
|
||||
APPLY_EXPAND_CLUSTER(05, "集群扩容", "modifyClusterOrder"),
|
||||
APPLY_REDUCE_CLUSTER(15, "集群缩容", "modifyClusterOrder"),
|
||||
APPLY_EXPAND_CLUSTER (05, "集群扩容", "modifyClusterOrder"),
|
||||
APPLY_REDUCE_CLUSTER (15, "集群缩容", "modifyClusterOrder"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.xiaojukeji.kafka.manager.bpm.common.entry.apply;
|
||||
|
||||
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/12/2
|
||||
*/
|
||||
public class OrderExtensionThirdPartDeleteTopicDTO {
|
||||
private Long clusterId;
|
||||
|
||||
private String topicName;
|
||||
|
||||
private String appId;
|
||||
|
||||
private String password;
|
||||
|
||||
public Long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
public void setClusterId(Long clusterId) {
|
||||
this.clusterId = clusterId;
|
||||
}
|
||||
|
||||
public String getTopicName() {
|
||||
return topicName;
|
||||
}
|
||||
|
||||
public void setTopicName(String topicName) {
|
||||
this.topicName = topicName;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrderExtensionThirdPartDeleteTopicDTO{" +
|
||||
"clusterId=" + clusterId +
|
||||
", topicName='" + topicName + '\'' +
|
||||
", appId='" + appId + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public boolean paramLegal() {
|
||||
if (ValidateUtils.isNull(clusterId)
|
||||
|| ValidateUtils.isBlank(topicName)
|
||||
|| ValidateUtils.isBlank(appId)
|
||||
|| ValidateUtils.isBlank(password)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,8 @@ package com.xiaojukeji.kafka.manager.bpm.component;
|
||||
import com.xiaojukeji.kafka.manager.bpm.common.OrderStatusEnum;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.OrderDO;
|
||||
import com.xiaojukeji.kafka.manager.common.events.OrderApplyEvent;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.SpringTool;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
|
||||
import com.xiaojukeji.kafka.manager.dao.OrderDao;
|
||||
import com.xiaojukeji.kafka.manager.service.utils.ConfigUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -27,17 +24,12 @@ public class LocalStorageService extends AbstractOrderStorageService {
|
||||
@Autowired
|
||||
private OrderDao orderDao;
|
||||
|
||||
@Autowired
|
||||
private ConfigUtils configUtils;
|
||||
|
||||
@Override
|
||||
public ResultStatus directSaveHandledOrder(OrderDO orderDO) {
|
||||
try {
|
||||
if (orderDao.directSaveHandledOrder(orderDO) <= 0) {
|
||||
return ResultStatus.MYSQL_ERROR;
|
||||
}
|
||||
// 无需进行通知
|
||||
// SpringTool.publish(new OrderApplyEvent(this, orderDO, configUtils.getIdc()));
|
||||
return ResultStatus.SUCCESS;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("add order failed, orderDO:{}.", orderDO, e);
|
||||
@@ -52,7 +44,6 @@ public class LocalStorageService extends AbstractOrderStorageService {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpringTool.publish(new OrderApplyEvent(this, orderDO, configUtils.getIdc()));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("add order failed, orderDO:{}.", orderDO, e);
|
||||
|
||||
@@ -261,6 +261,14 @@ public class OrderServiceImpl implements OrderService {
|
||||
resultList.add(new OrderResult(id, Result.buildFrom(ResultStatus.ORDER_NOT_EXIST)));
|
||||
continue;
|
||||
}
|
||||
// topic申请、topic分区申请不支持批量审批通过.
|
||||
if (orderDO.getType().equals(OrderTypeEnum.APPLY_TOPIC.getCode())
|
||||
|| orderDO.getType().equals(OrderTypeEnum.APPLY_PARTITION.getCode())) {
|
||||
if (OrderStatusEnum.PASSED.getCode().equals(reqObj.getStatus())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
orderDOList.add(orderDO);
|
||||
}
|
||||
// 根据创建时间排序
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.xiaojukeji.kafka.manager.bpm.order.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xiaojukeji.kafka.manager.bpm.common.OrderTypeEnum;
|
||||
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.OrderExtensionThirdPartDeleteTopicDTO;
|
||||
import com.xiaojukeji.kafka.manager.bpm.common.entry.detail.AbstractOrderDetailData;
|
||||
import com.xiaojukeji.kafka.manager.bpm.common.entry.detail.OrderDetailDeleteTopicDTO;
|
||||
import com.xiaojukeji.kafka.manager.bpm.common.handle.OrderHandleBaseDTO;
|
||||
import com.xiaojukeji.kafka.manager.bpm.order.AbstractTopicOrder;
|
||||
import com.xiaojukeji.kafka.manager.common.constant.Constant;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.Result;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.ao.topic.TopicConnection;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.ClusterDO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.OrderDO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.TopicDO;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.gateway.AppDO;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.ListUtils;
|
||||
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
|
||||
import com.xiaojukeji.kafka.manager.service.cache.LogicalClusterMetadataManager;
|
||||
import com.xiaojukeji.kafka.manager.service.cache.PhysicalClusterMetadataManager;
|
||||
import com.xiaojukeji.kafka.manager.service.service.AdminService;
|
||||
import com.xiaojukeji.kafka.manager.service.service.ClusterService;
|
||||
import com.xiaojukeji.kafka.manager.service.service.TopicManagerService;
|
||||
import com.xiaojukeji.kafka.manager.service.service.gateway.AppService;
|
||||
import com.xiaojukeji.kafka.manager.service.service.gateway.TopicConnectionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/12/2
|
||||
*/
|
||||
@Component("thirdPartDeleteTopicOrder")
|
||||
public class ThirdPartDeleteTopicOrder extends AbstractTopicOrder {
|
||||
@Autowired
|
||||
private LogicalClusterMetadataManager logicalClusterMetadataManager;
|
||||
|
||||
@Autowired
|
||||
private AppService appService;
|
||||
|
||||
@Autowired
|
||||
private ClusterService clusterService;
|
||||
|
||||
@Autowired
|
||||
private AdminService adminService;
|
||||
|
||||
@Autowired
|
||||
private TopicManagerService topicManagerService;
|
||||
|
||||
@Autowired
|
||||
private TopicConnectionService connectionService;
|
||||
|
||||
@Override
|
||||
public AbstractOrderDetailData getOrderExtensionDetailData(String extensions) {
|
||||
OrderDetailDeleteTopicDTO orderDetailDTO = new OrderDetailDeleteTopicDTO();
|
||||
OrderExtensionThirdPartDeleteTopicDTO orderExtensionDTO = JSONObject.parseObject(
|
||||
extensions,
|
||||
OrderExtensionThirdPartDeleteTopicDTO.class);
|
||||
orderDetailDTO.setTopicName(orderExtensionDTO.getTopicName());
|
||||
ClusterDO clusterDO = clusterService.getById(orderExtensionDTO.getClusterId());
|
||||
if (!ValidateUtils.isNull(clusterDO)) {
|
||||
orderDetailDTO.setPhysicalClusterId(clusterDO.getId());
|
||||
orderDetailDTO.setPhysicalClusterName(clusterDO.getClusterName());
|
||||
}
|
||||
|
||||
List<TopicConnection> connectionDTOList = connectionService.getByTopicName(
|
||||
clusterDO.getId(),
|
||||
orderExtensionDTO.getTopicName(),
|
||||
new Date(System.currentTimeMillis() - Constant.TOPIC_CONNECTION_LATEST_TIME_MS),
|
||||
new Date());
|
||||
orderDetailDTO.setConnectionList(connectionDTOList);
|
||||
|
||||
TopicDO topicDO = topicManagerService.getByTopicName(clusterDO.getId(), orderExtensionDTO.getTopicName());
|
||||
if (ValidateUtils.isNull(topicDO)) {
|
||||
return orderDetailDTO;
|
||||
}
|
||||
|
||||
AppDO appDO = appService.getByAppId(topicDO.getAppId());
|
||||
if (ValidateUtils.isNull(appDO)) {
|
||||
return orderDetailDTO;
|
||||
}
|
||||
orderDetailDTO.setAppId(appDO.getAppId());
|
||||
orderDetailDTO.setAppName(appDO.getName());
|
||||
orderDetailDTO.setAppPrincipals(appDO.getPrincipals());
|
||||
return orderDetailDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> checkExtensionFieldsAndGenerateTitle(String extensions) {
|
||||
OrderExtensionThirdPartDeleteTopicDTO orderExtensionDTO = JSONObject.parseObject(
|
||||
extensions,
|
||||
OrderExtensionThirdPartDeleteTopicDTO.class);
|
||||
if (!orderExtensionDTO.paramLegal()) {
|
||||
return Result.buildFrom(ResultStatus.PARAM_ILLEGAL);
|
||||
}
|
||||
Long physicalClusterId = logicalClusterMetadataManager.getPhysicalClusterId(orderExtensionDTO.getClusterId(), true);
|
||||
if (ValidateUtils.isNull(physicalClusterId)) {
|
||||
return Result.buildFrom(ResultStatus.CLUSTER_NOT_EXIST);
|
||||
}
|
||||
if (!PhysicalClusterMetadataManager.isTopicExist(physicalClusterId, orderExtensionDTO.getTopicName())) {
|
||||
return Result.buildFrom(ResultStatus.TOPIC_NOT_EXIST);
|
||||
}
|
||||
AppDO appDO = appService.getByAppId(orderExtensionDTO.getAppId());
|
||||
if (ValidateUtils.isNull(appDO)) {
|
||||
return Result.buildFrom(ResultStatus.APP_NOT_EXIST);
|
||||
}
|
||||
if (!appDO.getPassword().equals(orderExtensionDTO.getPassword())) {
|
||||
return Result.buildFrom(ResultStatus.USER_WITHOUT_AUTHORITY);
|
||||
}
|
||||
|
||||
String title = String.format(
|
||||
"%s-%d-%s",
|
||||
OrderTypeEnum.DELETE_TOPIC.getMessage(),
|
||||
orderExtensionDTO.getClusterId(),
|
||||
orderExtensionDTO.getTopicName()
|
||||
);
|
||||
return new Result<>(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultStatus handleOrderDetail(OrderDO orderDO,
|
||||
OrderHandleBaseDTO orderHandleBaseDTO,
|
||||
String userName) {
|
||||
OrderExtensionThirdPartDeleteTopicDTO extensionDTO = JSONObject.parseObject(orderDO.getExtensions(),
|
||||
OrderExtensionThirdPartDeleteTopicDTO.class);
|
||||
Long physicalClusterId = logicalClusterMetadataManager.getPhysicalClusterId(extensionDTO.getClusterId(), true);
|
||||
if (ValidateUtils.isNull(physicalClusterId)) {
|
||||
return ResultStatus.CLUSTER_NOT_EXIST;
|
||||
}
|
||||
ClusterDO clusterDO = clusterService.getById(physicalClusterId);
|
||||
if (!PhysicalClusterMetadataManager.isTopicExistStrictly(physicalClusterId, extensionDTO.getTopicName())) {
|
||||
return ResultStatus.TOPIC_NOT_EXIST;
|
||||
}
|
||||
if (connectionService.isExistConnection(
|
||||
physicalClusterId,
|
||||
extensionDTO.getTopicName(),
|
||||
new Date(System.currentTimeMillis() - Constant.TOPIC_CONNECTION_LATEST_TIME_MS),
|
||||
new Date())
|
||||
) {
|
||||
return ResultStatus.OPERATION_FORBIDDEN;
|
||||
}
|
||||
|
||||
// 检查申请人是否在应用负责人里面
|
||||
AppDO appDO = appService.getByAppId(extensionDTO.getAppId());
|
||||
if (ValidateUtils.isNull(appDO)) {
|
||||
return ResultStatus.APP_NOT_EXIST;
|
||||
}
|
||||
if (!appDO.getPassword().equals(extensionDTO.getPassword())
|
||||
|| !ListUtils.string2StrList(appDO.getPrincipals()).contains(orderDO.getApplicant())) {
|
||||
// 密码错误 or 申请人不在应用负责人里面, 则返回错误
|
||||
return ResultStatus.USER_WITHOUT_AUTHORITY;
|
||||
}
|
||||
|
||||
ResultStatus resultStatus = adminService.deleteTopic(clusterDO, extensionDTO.getTopicName(), userName);
|
||||
if (!ResultStatus.SUCCESS.equals(resultStatus)) {
|
||||
return resultStatus;
|
||||
}
|
||||
return resultStatus;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user