use of org.apache.inlong.manager.dao.entity.StreamSinkEntity 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.dao.entity.StreamSinkEntity 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.dao.entity.StreamSinkEntity in project incubator-inlong by apache.
the class HiveStreamSinkOperation method getById.
@Override
public SinkResponse getById(@NotNull String sinkType, @NotNull Integer id) {
StreamSinkEntity entity = sinkMapper.selectByPrimaryKey(id);
Preconditions.checkNotNull(entity, ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
String existType = entity.getSinkType();
Preconditions.checkTrue(Constant.SINK_HIVE.equals(existType), String.format(Constant.SINK_TYPE_NOT_SAME, Constant.SINK_HIVE, existType));
SinkResponse response = this.getFromEntity(entity, HiveSinkResponse::new);
List<StreamSinkFieldEntity> entities = sinkFieldMapper.selectBySinkId(id);
List<SinkFieldResponse> infos = CommonBeanUtils.copyListProperties(entities, SinkFieldResponse::new);
response.setFieldList(infos);
return response;
}
use of org.apache.inlong.manager.dao.entity.StreamSinkEntity 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.dao.entity.StreamSinkEntity 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