use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class IcebergStreamSinkOperation method updateOpt.
@Override
public void updateOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_ICEBERG.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_ICEBERG, sinkType));
StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
IcebergSinkRequest icebergSinkRequest = (IcebergSinkRequest) request;
CommonBeanUtils.copyProperties(icebergSinkRequest, entity, true);
try {
IcebergSinkDTO dto = IcebergSinkDTO.getFromRequest(icebergSinkRequest);
entity.setExtParams(objectMapper.writeValueAsString(dto));
} catch (Exception e) {
throw new BusinessException(ErrorCodeEnum.SINK_INFO_INCORRECT.getMessage());
}
entity.setPreviousStatus(entity.getStatus());
entity.setStatus(EntityStatus.GROUP_CONFIG_ING.getCode());
entity.setModifier(operator);
entity.setModifyTime(new Date());
sinkMapper.updateByPrimaryKeySelective(entity);
boolean onlyAdd = EntityStatus.SINK_CONFIG_SUCCESSFUL.getCode().equals(entity.getPreviousStatus());
this.updateFieldOpt(onlyAdd, icebergSinkRequest);
LOGGER.info("success to update sink of type={}", sinkType);
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class KafkaStreamSourceOperation method setTargetEntity.
@Override
protected void setTargetEntity(SourceRequest request, StreamSourceEntity targetEntity) {
KafkaSourceRequest sourceRequest = (KafkaSourceRequest) request;
CommonBeanUtils.copyProperties(sourceRequest, targetEntity, true);
try {
KafkaSourceDTO dto = KafkaSourceDTO.getFromRequest(sourceRequest);
targetEntity.setExtParams(objectMapper.writeValueAsString(dto));
} catch (Exception e) {
throw new BusinessException(ErrorCodeEnum.SOURCE_INFO_INCORRECT.getMessage());
}
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class KafkaStreamSinkOperation method saveOpt.
@Override
public Integer saveOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_KAFKA.equals(sinkType), ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + sinkType);
KafkaSinkRequest kafkaSinkRequest = (KafkaSinkRequest) request;
StreamSinkEntity entity = CommonBeanUtils.copyProperties(kafkaSinkRequest, StreamSinkEntity::new);
entity.setStatus(EntityStatus.SINK_NEW.getCode());
entity.setIsDeleted(EntityStatus.UN_DELETED.getCode());
entity.setCreator(operator);
entity.setModifier(operator);
Date now = new Date();
entity.setCreateTime(now);
entity.setModifyTime(now);
// get the ext params
KafkaSinkDTO dto = KafkaSinkDTO.getFromRequest(kafkaSinkRequest);
try {
entity.setExtParams(objectMapper.writeValueAsString(dto));
} catch (Exception e) {
throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED);
}
sinkMapper.insert(entity);
Integer sinkId = entity.getId();
request.setId(sinkId);
this.saveFieldOpt(request);
return sinkId;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class InlongGroupServiceImpl method updateStatus.
@Override
@Transactional(rollbackFor = Throwable.class, isolation = Isolation.REPEATABLE_READ)
public boolean updateStatus(String groupId, Integer status, String operator) {
LOGGER.info("begin to update group status to [{}] by groupId={}, username={}", status, groupId, operator);
Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
InlongGroupEntity entity = groupMapper.selectByGroupIdForUpdate(groupId);
if (entity == null) {
LOGGER.error("inlong group not found by groupId={}", groupId);
throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
}
GroupState curState = GroupState.forCode(entity.getStatus());
GroupState nextState = GroupState.forCode(status);
if (GroupState.notAllowedTransition(curState, nextState)) {
String errorMsg = String.format("Current state=%s is not allowed to transfer to state=%s", curState, nextState);
LOGGER.error(errorMsg);
throw new BusinessException(errorMsg);
}
groupMapper.updateStatus(groupId, status, operator);
LOGGER.info("success to update inlong group status to [{}] for groupId={}", status, groupId);
return true;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class InlongGroupServiceImpl method delete.
@Transactional(rollbackFor = Throwable.class)
@Override
public boolean delete(String groupId, String operator) {
LOGGER.debug("begin to delete inlong group, 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);
}
// Determine whether the current status can be deleted
GroupState curState = GroupState.forCode(entity.getStatus());
if (GroupState.notAllowedTransition(curState, GroupState.DELETED)) {
String errMsg = String.format("Current state=%s was not allowed to delete", curState);
LOGGER.error(errMsg);
throw new BusinessException(ErrorCodeEnum.GROUP_DELETE_NOT_ALLOWED, errMsg);
}
// [DRAFT] [GROUP_WAIT_SUBMIT] status, all associated data can be logically deleted directly
if (GroupState.isAllowedLogicDel(curState)) {
// Logically delete inlong streams, data sources and data sink information
streamService.logicDeleteAll(entity.getInlongGroupId(), operator);
} else {
// In other status, you need to delete the associated "inlong stream" first.
// When deleting a inlong stream, you also need to check whether there are
// some associated "data source" and "stream sink"
int count = streamService.selectCountByGroupId(groupId);
if (count >= 1) {
LOGGER.error("groupId={} have [{}] inlong streams, deleted failed", groupId, count);
throw new BusinessException(ErrorCodeEnum.GROUP_HAS_STREAM);
}
}
entity.setIsDeleted(entity.getId());
entity.setStatus(GroupState.DELETED.getCode());
entity.setModifier(operator);
groupMapper.updateByIdentifierSelective(entity);
// To logically delete the associated extension table
groupExtMapper.logicDeleteAllByGroupId(groupId);
// To logically delete the associated pulsar table
groupPulsarMapper.logicDeleteByGroupId(groupId);
LOGGER.info("success to delete inlong group and inlong group ext property for groupId={}", groupId);
return true;
}
Aggregations