use of org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo in project incubator-inlong by apache.
the class InlongGroupServiceImpl method save.
@Transactional(rollbackFor = Throwable.class)
@Override
public String save(InlongGroupRequest groupInfo, String operator) {
LOGGER.debug("begin to save inlong group info={}", groupInfo);
Preconditions.checkNotNull(groupInfo, "inlong group info is empty");
String groupName = groupInfo.getName();
Preconditions.checkNotNull(groupName, "inlong group name is empty");
// groupId=b_name, cannot update
String groupId = "b_" + groupName.toLowerCase(Locale.ROOT);
Integer count = groupMapper.selectIdentifierExist(groupId);
if (count >= 1) {
LOGGER.error("groupId [{}] has already exists", groupId);
throw new BusinessException(ErrorCodeEnum.GROUP_DUPLICATE);
}
// Processing inlong group and extended information
InlongGroupEntity entity = CommonBeanUtils.copyProperties(groupInfo, InlongGroupEntity::new);
entity.setInlongGroupId(groupId);
if (StringUtils.isEmpty(entity.getMqResourceObj())) {
entity.setMqResourceObj(groupId);
}
// Only M0 is currently supported
entity.setSchemaName(Constant.SCHEMA_M0_DAY);
// After saving, the status is set to [GROUP_WAIT_SUBMIT]
entity.setStatus(GroupState.TO_BE_SUBMIT.getCode());
entity.setIsDeleted(EntityStatus.UN_DELETED.getCode());
if (StringUtils.isEmpty(entity.getCreator())) {
entity.setCreator(operator);
}
if (StringUtils.isEmpty(entity.getModifier())) {
entity.setModifier(operator);
}
entity.setCreateTime(new Date());
groupMapper.insertSelective(entity);
this.saveOrUpdateExt(groupId, groupInfo.getExtList());
String mqType = groupInfo.getMiddlewareType();
if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
InlongGroupPulsarInfo pulsarInfo = (InlongGroupPulsarInfo) groupInfo.getMqExtInfo();
Preconditions.checkNotNull(pulsarInfo, "Pulsar info cannot be empty, as the middleware is Pulsar");
// Pulsar params must meet: ackQuorum <= writeQuorum <= ensemble
Integer ackQuorum = pulsarInfo.getAckQuorum();
Integer writeQuorum = pulsarInfo.getWriteQuorum();
Preconditions.checkNotNull(ackQuorum, "Pulsar ackQuorum cannot be empty");
Preconditions.checkNotNull(writeQuorum, "Pulsar writeQuorum cannot be empty");
if (!(ackQuorum <= writeQuorum)) {
throw new BusinessException(ErrorCodeEnum.GROUP_SAVE_FAILED, "Pulsar params must meet: ackQuorum <= writeQuorum");
}
// The default value of ensemble is writeQuorum
pulsarInfo.setEnsemble(writeQuorum);
// Pulsar entity may already exist, such as unsuccessfully deleted, or modify the MQ type to Tube,
// need to delete and add the Pulsar entity with the same group id
InlongGroupPulsarEntity pulsarEntity = groupPulsarMapper.selectByGroupId(groupId);
if (pulsarEntity == null) {
pulsarEntity = CommonBeanUtils.copyProperties(pulsarInfo, InlongGroupPulsarEntity::new);
pulsarEntity.setIsDeleted(0);
pulsarEntity.setInlongGroupId(groupId);
groupPulsarMapper.insertSelective(pulsarEntity);
} else {
Integer id = pulsarEntity.getId();
pulsarEntity = CommonBeanUtils.copyProperties(pulsarInfo, InlongGroupPulsarEntity::new);
pulsarEntity.setId(id);
groupPulsarMapper.updateByPrimaryKeySelective(pulsarEntity);
}
}
LOGGER.debug("success to save inlong group info for groupId={}", groupId);
return groupId;
}
use of org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo in project incubator-inlong by apache.
the class InlongGroupTransfer method createPulsarInfo.
public static InlongGroupPulsarInfo createPulsarInfo(PulsarBaseConf pulsarBaseConf) {
InlongGroupPulsarInfo pulsarInfo = new InlongGroupPulsarInfo();
pulsarInfo.setMiddlewareType(pulsarBaseConf.getType().name());
pulsarInfo.setEnsemble(pulsarBaseConf.getEnsemble());
pulsarInfo.setAckQuorum(pulsarBaseConf.getAckQuorum());
pulsarInfo.setEnableCreateResource(pulsarBaseConf.isEnableCreateResource() ? 1 : 0);
pulsarInfo.setWriteQuorum(pulsarBaseConf.getWriteQuorum());
pulsarInfo.setRetentionSize(pulsarBaseConf.getRetentionSize());
pulsarInfo.setTenant(pulsarBaseConf.getTenant());
pulsarInfo.setRetentionTime(pulsarBaseConf.getRetentionTime());
pulsarInfo.setRetentionSizeUnit(pulsarBaseConf.getRetentionSizeUnit());
pulsarInfo.setRetentionTimeUnit(pulsarBaseConf.getRetentionTimeUnit());
pulsarInfo.setTtl(pulsarBaseConf.getTtl());
pulsarInfo.setTtlUnit(pulsarBaseConf.getTtlUnit());
return pulsarInfo;
}
use of org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo in project incubator-inlong by apache.
the class InlongParser method parseGroupForm.
public static Pair<InlongGroupApproveRequest, List<InlongStreamApproveRequest>> parseGroupForm(String formJson) {
JsonObject formData = GsonUtil.fromJson(formJson, JsonObject.class);
JsonObject groupJson = formData.getAsJsonObject(GROUP_INFO);
InlongGroupApproveRequest groupApproveInfo = GsonUtil.fromJson(groupJson.toString(), InlongGroupApproveRequest.class);
JsonObject mqExtInfo = groupJson.getAsJsonObject(MQ_EXT_INFO);
if (mqExtInfo != null && mqExtInfo.get(MIDDLEWARE_TYPE) != null) {
String middlewareType = mqExtInfo.get(MIDDLEWARE_TYPE).getAsString();
if (Constant.MIDDLEWARE_PULSAR.equals(middlewareType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(middlewareType)) {
InlongGroupPulsarInfo pulsarInfo = GsonUtil.fromJson(mqExtInfo.toString(), InlongGroupPulsarInfo.class);
groupApproveInfo.setAckQuorum(pulsarInfo.getAckQuorum());
groupApproveInfo.setEnsemble(pulsarInfo.getEnsemble());
groupApproveInfo.setWriteQuorum(pulsarInfo.getWriteQuorum());
groupApproveInfo.setRetentionTime(pulsarInfo.getRetentionTime());
groupApproveInfo.setRetentionTimeUnit(pulsarInfo.getRetentionTimeUnit());
groupApproveInfo.setTtl(pulsarInfo.getTtl());
groupApproveInfo.setTtlUnit(pulsarInfo.getTtlUnit());
groupApproveInfo.setRetentionSize(pulsarInfo.getRetentionSize());
groupApproveInfo.setRetentionSizeUnit(pulsarInfo.getRetentionSizeUnit());
}
}
JsonArray streamJson = formData.getAsJsonArray("streamInfoList");
List<InlongStreamApproveRequest> streamApproveList = GsonUtil.fromJson(streamJson.toString(), new TypeToken<List<InlongStreamApproveRequest>>() {
}.getType());
return Pair.of(groupApproveInfo, streamApproveList);
}
Aggregations