use of org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest 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.pojo.sink.hive.HiveSinkRequest 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);
}
use of org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest in project incubator-inlong by apache.
the class DisableZkForSortTest method createHiveSink.
public HiveSinkRequest createHiveSink(InlongStreamInfo streamInfo) {
HiveSinkRequest hiveSinkRequest = new HiveSinkRequest();
hiveSinkRequest.setInlongGroupId(streamInfo.getInlongGroupId());
hiveSinkRequest.setSinkType("HIVE");
hiveSinkRequest.setSinkName("HIVE");
hiveSinkRequest.setInlongStreamId(streamInfo.getInlongStreamId());
List<SinkFieldRequest> sinkFieldRequests = createStreamFields(streamInfo.getInlongGroupId(), streamInfo.getInlongStreamId()).stream().map(streamFieldInfo -> {
SinkFieldRequest fieldInfo = new SinkFieldRequest();
fieldInfo.setFieldName(streamFieldInfo.getFieldName());
fieldInfo.setFieldType(streamFieldInfo.getFieldType());
fieldInfo.setFieldComment(streamFieldInfo.getFieldComment());
return fieldInfo;
}).collect(Collectors.toList());
hiveSinkRequest.setFieldList(sinkFieldRequests);
hiveSinkRequest.setEnableCreateTable(0);
hiveSinkRequest.setUsername(OPERATOR);
hiveSinkRequest.setPassword("password");
hiveSinkRequest.setDbName("default");
hiveSinkRequest.setTableName("kip_test");
hiveSinkRequest.setJdbcUrl("jdbc:hive2://172.17.12.135:7001");
hiveSinkRequest.setFileFormat("TextFile");
hiveSinkRequest.setHdfsDefaultFs("hdfs://172.17.12.235:4007");
hiveSinkRequest.setWarehouseDir("/user/hive/warehouse");
hiveSinkRequest.setFileFormat(StandardCharsets.UTF_8.name());
hiveSinkRequest.setDataSeparator("124");
streamSinkService.save(hiveSinkRequest, OPERATOR);
return hiveSinkRequest;
}
use of org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest in project incubator-inlong by apache.
the class HiveStreamSinkServiceTest method testGetAndUpdate.
@Test
public void testGetAndUpdate() {
Integer id = this.saveSink();
SinkResponse response = sinkService.get(id, Constant.SINK_HIVE);
Assert.assertEquals(globalGroupId, response.getInlongGroupId());
HiveSinkResponse hiveResponse = (HiveSinkResponse) response;
hiveResponse.setEnableCreateResource(Constant.DISABLE_CREATE_RESOURCE);
HiveSinkRequest request = CommonBeanUtils.copyProperties(hiveResponse, HiveSinkRequest::new);
boolean result = sinkService.update(request, globalOperator);
Assert.assertTrue(result);
}
use of org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkRequest in project incubator-inlong by apache.
the class HiveStreamSinkServiceTest method saveSink.
public Integer saveSink() {
streamServiceTest.saveInlongStream(globalGroupId, globalStreamId, globalOperator);
HiveSinkRequest sinkInfo = new HiveSinkRequest();
sinkInfo.setInlongGroupId(globalGroupId);
sinkInfo.setInlongStreamId(globalStreamId);
sinkInfo.setSinkType(Constant.SINK_HIVE);
sinkInfo.setEnableCreateResource(Constant.DISABLE_CREATE_RESOURCE);
sinkInfo.setSinkName(sinkName);
return sinkService.save(sinkInfo, globalOperator);
}
Aggregations