use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class CommonOperateService method checkGroupStatus.
/**
* Check whether the inlong group status is temporary
*
* @param groupId Inlong group id
* @return Inlong group entity, for caller reuse
*/
public InlongGroupEntity checkGroupStatus(String groupId, String operator) {
InlongGroupEntity inlongGroupEntity = groupMapper.selectByGroupId(groupId);
Preconditions.checkNotNull(inlongGroupEntity, "groupId is invalid");
List<String> managers = Arrays.asList(inlongGroupEntity.getInCharges().split(","));
Preconditions.checkTrue(managers.contains(operator), String.format(ErrorCodeEnum.USER_IS_NOT_MANAGER.getMessage(), operator, managers));
GroupState state = GroupState.forCode(inlongGroupEntity.getStatus());
// Add/modify/delete is not allowed under certain group state
if (GroupState.notAllowedUpdate(state)) {
LOGGER.error("inlong group status was not allowed to add/update/delete related info");
throw new BusinessException(ErrorCodeEnum.OPT_NOT_ALLOWED_BY_STATUS);
}
return inlongGroupEntity;
}
use of org.apache.inlong.manager.common.exceptions.BusinessException in project incubator-inlong by apache.
the class ClickHouseStreamSinkOperation method saveOpt.
@Override
public Integer saveOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_CLICKHOUSE.equals(sinkType), ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + sinkType);
ClickHouseSinkRequest sinkRequest = (ClickHouseSinkRequest) request;
StreamSinkEntity entity = CommonBeanUtils.copyProperties(sinkRequest, 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
ClickHouseSinkDTO dto = ClickHouseSinkDTO.getFromRequest(sinkRequest);
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 ClickHouseStreamSinkOperation method updateOpt.
@Override
public void updateOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_CLICKHOUSE.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_CLICKHOUSE, sinkType));
StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
ClickHouseSinkRequest sinkRequest = (ClickHouseSinkRequest) request;
CommonBeanUtils.copyProperties(sinkRequest, entity, true);
try {
ClickHouseSinkDTO dto = ClickHouseSinkDTO.getFromRequest(sinkRequest);
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, sinkRequest);
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 HiveStreamSinkOperation method saveOpt.
@Override
public Integer saveOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_HIVE.equals(sinkType), ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + sinkType);
HiveSinkRequest hiveRequest = (HiveSinkRequest) request;
StreamSinkEntity entity = CommonBeanUtils.copyProperties(hiveRequest, 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
HiveSinkDTO dto = HiveSinkDTO.getFromRequest(hiveRequest);
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 HiveStreamSinkOperation method updateOpt.
@Override
public void updateOpt(SinkRequest request, String operator) {
String sinkType = request.getSinkType();
Preconditions.checkTrue(Constant.SINK_HIVE.equals(sinkType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_HIVE, sinkType));
StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(request.getId());
Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
HiveSinkRequest hiveRequest = (HiveSinkRequest) request;
CommonBeanUtils.copyProperties(hiveRequest, entity, true);
try {
HiveSinkDTO dto = HiveSinkDTO.getFromRequest(hiveRequest);
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, hiveRequest);
LOGGER.info("success to update sink of type={}", sinkType);
}
Aggregations