use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class SourceFileServiceImpl method saveDetail.
@Override
public Integer saveDetail(SourceFileDetailInfo detailInfo, String operator) {
LOGGER.info("begin to save file data source detail={}", detailInfo);
Preconditions.checkNotNull(detailInfo, "file data source detail is empty");
Preconditions.checkNotNull(detailInfo.getInlongGroupId(), Constant.GROUP_ID_IS_EMPTY);
Preconditions.checkNotNull(detailInfo.getInlongStreamId(), Constant.STREAM_ID_IS_EMPTY);
// Check if it can be added
InlongGroupEntity inlongGroupEntity = this.checkGroupIsTempStatus(detailInfo.getInlongGroupId());
// If there are data sources under the same groupId, streamId, ip, username, the addition fails
String groupId = detailInfo.getInlongGroupId();
String streamId = detailInfo.getInlongStreamId();
String ip = detailInfo.getIp();
String username = detailInfo.getUsername();
Integer count = fileDetailMapper.selectDetailExist(groupId, streamId, ip, username);
if (count > 0) {
LOGGER.error("file data source already exists: groupId=" + groupId + ", streamId=" + streamId + ", ip=" + ip + ", username=" + username);
throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
}
detailInfo.setStatus(EntityStatus.AGENT_ADD.getCode());
SourceFileDetailEntity detailEntity = CommonBeanUtils.copyProperties(detailInfo, SourceFileDetailEntity::new);
detailEntity.setCreator(operator);
detailEntity.setModifier(operator);
Date now = new Date();
detailEntity.setCreateTime(now);
detailEntity.setModifyTime(now);
fileDetailMapper.insertSelective(detailEntity);
LOGGER.info("success to save file data source detail");
return detailEntity.getId();
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class SourceFileServiceImpl method updateBasic.
@Override
public boolean updateBasic(SourceFileBasicInfo basicInfo, String operator) {
LOGGER.info("begin to update file data source basic={}", basicInfo);
Preconditions.checkNotNull(basicInfo, "file data source basic is empty");
// The groupId may be modified, it is necessary to determine whether the inlong group status of
// the modified groupId supports modification
this.checkGroupIsTempStatus(basicInfo.getInlongGroupId());
// If id is empty, add
if (basicInfo.getId() == null) {
this.saveBasic(basicInfo, operator);
} else {
SourceFileBasicEntity basicEntity = fileBasicMapper.selectByPrimaryKey(basicInfo.getId());
if (basicEntity == null) {
LOGGER.error("file data source basic not found by id={}, update failed", basicInfo.getId());
throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
}
BeanUtils.copyProperties(basicInfo, basicEntity);
basicEntity.setModifier(operator);
fileBasicMapper.updateByPrimaryKeySelective(basicEntity);
}
LOGGER.info("success to update file data source basic");
return true;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class SourceFileServiceImpl method logicDeleteBasic.
@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
LOGGER.info("begin to delete file data source basic, id={}", id);
Preconditions.checkNotNull(id, "file data source basic's id is null");
SourceFileBasicEntity entity = fileBasicMapper.selectByPrimaryKey(id);
if (entity == null) {
LOGGER.error("file 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<SourceFileDetailEntity> detailEntities = fileDetailMapper.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 = fileBasicMapper.updateByPrimaryKey(entity);
LOGGER.info("success to delete file data source basic");
return resultCount >= 0;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class ThirdPartyClusterServiceImpl method getConfigV2.
/**
* query data proxy config by cluster name, result includes pulsar/tube cluster configs and topic etc
*/
@Override
public ThirdPartyClusterDTO getConfigV2(String clusterName) {
ThirdPartyClusterEntity clusterEntity = thirdPartyClusterMapper.selectByName(clusterName);
if (clusterEntity == null) {
throw new BusinessException("data proxy cluster not found by name=" + clusterName);
}
// TODO Optimize query conditions use dataProxyClusterId
List<InlongGroupEntity> groupEntityList = groupMapper.selectAll(GroupState.CONFIG_SUCCESSFUL.getCode());
if (CollectionUtils.isEmpty(groupEntityList)) {
String msg = "not found any inlong group with success status for proxy cluster name = " + clusterName;
LOGGER.warn(msg);
throw new BusinessException(msg);
}
// third-party-cluster type
String mqType = "";
if (!groupEntityList.isEmpty()) {
mqType = groupEntityList.get(0).getMiddlewareType();
}
// Get topic list by group id
List<DataProxyConfig> topicList = new ArrayList<>();
for (InlongGroupEntity groupEntity : groupEntityList) {
final String groupId = groupEntity.getInlongGroupId();
final String mqResource = groupEntity.getMqResourceObj();
if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
List<InlongStreamEntity> streamList = streamMapper.selectByGroupId(groupId);
for (InlongStreamEntity stream : streamList) {
DataProxyConfig topicConfig = new DataProxyConfig();
String streamId = stream.getInlongStreamId();
String topic = stream.getMqResourceObj();
String tenant = clusterBean.getDefaultTenant();
InlongGroupPulsarEntity pulsarEntity = pulsarEntityMapper.selectByGroupId(groupId);
if (pulsarEntity != null && StringUtils.isNotEmpty(pulsarEntity.getTenant())) {
tenant = pulsarEntity.getTenant();
}
topicConfig.setInlongGroupId(groupId + "/" + streamId);
topicConfig.setTopic("persistent://" + tenant + "/" + mqResource + "/" + topic);
topicList.add(topicConfig);
}
} else if (Constant.MIDDLEWARE_TUBE.equals(mqType)) {
DataProxyConfig topicConfig = new DataProxyConfig();
topicConfig.setInlongGroupId(groupId);
topicConfig.setTopic(mqResource);
topicList.add(topicConfig);
}
}
// construct pulsarSet info
List<ThirdPartyClusterInfo> mqSet = new ArrayList<>();
List<String> clusterType = Arrays.asList(Constant.CLUSTER_TUBE, Constant.CLUSTER_PULSAR, Constant.CLUSTER_TDMQ_PULSAR);
List<ThirdPartyClusterEntity> clusterList = thirdPartyClusterMapper.selectMQCluster(clusterEntity.getMqSetName(), clusterType);
for (ThirdPartyClusterEntity cluster : clusterList) {
ThirdPartyClusterInfo clusterInfo = new ThirdPartyClusterInfo();
clusterInfo.setUrl(cluster.getUrl());
clusterInfo.setToken(cluster.getToken());
Map<String, String> configParams = GSON.fromJson(cluster.getExtParams(), Map.class);
clusterInfo.setParams(configParams);
mqSet.add(clusterInfo);
}
ThirdPartyClusterDTO object = new ThirdPartyClusterDTO();
object.setMqSet(mqSet);
object.setTopicList(topicList);
return object;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class ThirdPartyClusterServiceImpl method update.
@Override
@Transactional(rollbackFor = Throwable.class)
public Boolean update(ClusterRequest request, String operator) {
Preconditions.checkNotNull(request, "cluster is empty");
Integer id = request.getId();
Preconditions.checkNotNull(id, "cluster id is empty");
ThirdPartyClusterEntity entity = thirdPartyClusterMapper.selectByPrimaryKey(id);
if (entity == null) {
LOGGER.error("cluster not found by id={}", id);
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
}
CommonBeanUtils.copyProperties(request, entity, true);
entity.setModifier(operator);
thirdPartyClusterMapper.updateByPrimaryKeySelective(entity);
LOGGER.info("success to update cluster={}", request);
return true;
}
Aggregations