use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class InlongGroupServiceImpl method get.
@Override
public InlongGroupInfo get(String groupId) {
LOGGER.debug("begin to get inlong group info by groupId={}", groupId);
Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
if (entity == null) {
LOGGER.error("inlong group not found by groupId={}", groupId);
throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
}
InlongGroupInfo groupInfo = CommonBeanUtils.copyProperties(entity, InlongGroupInfo::new);
List<InlongGroupExtEntity> extEntityList = groupExtMapper.selectByGroupId(groupId);
List<InlongGroupExtInfo> extInfoList = CommonBeanUtils.copyListProperties(extEntityList, InlongGroupExtInfo::new);
groupInfo.setExtList(extInfoList);
// If the middleware is Pulsar, we need to encapsulate Pulsar related data
String mqType = entity.getMiddlewareType();
if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
InlongGroupPulsarEntity pulsarEntity = groupPulsarMapper.selectByGroupId(groupId);
Preconditions.checkNotNull(pulsarEntity, "Pulsar info not found by the groupId=" + groupId);
InlongGroupPulsarInfo pulsarInfo = CommonBeanUtils.copyProperties(pulsarEntity, InlongGroupPulsarInfo::new);
pulsarInfo.setMiddlewareType(mqType);
groupInfo.setMqExtInfo(pulsarInfo);
}
// For approved inlong group, encapsulate the cluster address of the middleware
if (GroupState.CONFIG_SUCCESSFUL == GroupState.forCode(groupInfo.getStatus())) {
if (Constant.MIDDLEWARE_TUBE.equalsIgnoreCase(mqType)) {
groupInfo.setTubeMaster(commonOperateService.getSpecifiedParam(Constant.TUBE_MASTER_URL));
} else if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
PulsarClusterInfo pulsarCluster = commonOperateService.getPulsarClusterInfo(mqType);
groupInfo.setPulsarAdminUrl(pulsarCluster.getAdminUrl());
groupInfo.setPulsarServiceUrl(pulsarCluster.getBrokerServiceUrl());
}
}
LOGGER.debug("success to get inlong group for groupId={}", groupId);
return groupInfo;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class InlongGroupServiceImpl method checkGroupCanUpdate.
/**
* Check whether modification is supported under the current inlong group status, and which fields can be modified.
*
* @param entity Original inlong group entity.
* @param groupInfo New inlong group info.
* @param operator Current operator.
*/
private void checkGroupCanUpdate(InlongGroupEntity entity, InlongGroupRequest groupInfo, String operator) {
if (entity == null || groupInfo == null) {
return;
}
// Only the person in charges can update
if (StringUtils.isEmpty(entity.getInCharges())) {
LOGGER.error("group [{}] has no inCharges", entity.getInlongGroupId());
throw new BusinessException(ErrorCodeEnum.GROUP_INFO_INCONSISTENT);
}
List<String> inCharges = Arrays.asList(entity.getInCharges().split(","));
if (!inCharges.contains(operator)) {
LOGGER.error("user [{}] has no privilege for the inlong group", operator);
throw new BusinessException(ErrorCodeEnum.GROUP_PERMISSION_DENIED);
}
// Check whether the current state supports modification
GroupState curState = GroupState.forCode(entity.getStatus());
if (GroupState.notAllowedUpdate(curState)) {
String errMsg = String.format("Current state=%s is not allowed to update", curState);
LOGGER.error(errMsg);
throw new BusinessException(ErrorCodeEnum.GROUP_UPDATE_NOT_ALLOWED, errMsg);
}
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class SourceDbServiceImpl method saveDetailOpt.
/**
* Save data source details
*/
@Transactional(rollbackFor = Throwable.class)
int saveDetailOpt(SourceDbDetailInfo detailInfo, String operator) {
// DB type judgment uniqueness: if the same groupId, streamId, dbName, connectionName
// correspond to the same data source
String groupId = detailInfo.getInlongGroupId();
String streamId = detailInfo.getInlongStreamId();
String dbName = detailInfo.getDbName();
String connectionName = detailInfo.getConnectionName();
Integer count = dbDetailMapper.selectDetailExist(groupId, streamId, dbName, connectionName);
if (count > 0) {
LOGGER.error("db source detail already exists, groupId={}, streamId={}, dbName={}, connectionName={}", groupId, streamId, dbName, connectionName);
throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
}
SourceDbDetailEntity dbEntity = CommonBeanUtils.copyProperties(detailInfo, SourceDbDetailEntity::new);
dbEntity.setStatus(EntityStatus.AGENT_ADD.getCode());
dbEntity.setCreator(operator);
dbEntity.setModifier(operator);
dbEntity.setCreateTime(new Date());
dbDetailMapper.insertSelective(dbEntity);
return dbEntity.getId();
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class SourceDbServiceImpl method logicDeleteBasic.
@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
LOGGER.info("begin to delete db data source basic, id={}", id);
Preconditions.checkNotNull(id, "db data source basic's id is null");
SourceDbBasicEntity entity = dbBasicMapper.selectByPrimaryKey(id);
if (entity == null) {
LOGGER.error("db data source basic not found by id={}, delete failed", id);
throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
}
String groupId = entity.getInlongGroupId();
String streamId = entity.getInlongStreamId();
// Check if it can be deleted
this.checkGroupIsTempStatus(groupId);
// If there are related data source details, it is not allowed to delete
List<SourceDbDetailEntity> detailEntities = dbDetailMapper.selectByIdentifier(groupId, streamId);
if (CollectionUtils.isNotEmpty(detailEntities)) {
LOGGER.error("the data source basic have [{}] details, delete failed", detailEntities.size());
throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_DELETE_HAS_DETAIL);
}
entity.setIsDeleted(1);
entity.setModifier(operator);
int resultCount = dbBasicMapper.updateByPrimaryKey(entity);
LOGGER.info("success to delete db data source basic");
return resultCount >= 0;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class SourceDbServiceImpl method getDetailById.
@Override
public SourceDbDetailInfo getDetailById(Integer id) {
LOGGER.info("begin to get db data source detail by id={}", id);
Preconditions.checkNotNull(id, "db data source detail's id is null");
SourceDbDetailEntity entity = dbDetailMapper.selectByPrimaryKey(id);
if (entity == null) {
LOGGER.error("db data source detail not found by id={}", id);
throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
}
SourceDbDetailInfo detailInfo = CommonBeanUtils.copyProperties(entity, SourceDbDetailInfo::new);
LOGGER.info("success to get db data source detail");
return detailInfo;
}
Aggregations