Search in sources :

Example 11 with InlongGroupPulsarInfo

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;
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) InlongGroupPulsarEntity(org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with InlongGroupPulsarInfo

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;
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)

Example 13 with InlongGroupPulsarInfo

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);
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) JsonArray(com.google.gson.JsonArray) InlongStreamApproveRequest(org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest) TypeToken(com.google.common.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) InlongGroupApproveRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest)

Aggregations

InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)13 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)4 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)3 InlongGroupExtInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)3 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)3 InlongGroupPulsarEntity (org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity)3 JsonObject (com.google.gson.JsonObject)2 PulsarBaseConf (org.apache.inlong.manager.client.api.PulsarBaseConf)2 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)2 Transactional (org.springframework.transaction.annotation.Transactional)2 TypeToken (com.google.common.reflect.TypeToken)1 JsonArray (com.google.gson.JsonArray)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)1 FlinkSortBaseConf (org.apache.inlong.manager.client.api.FlinkSortBaseConf)1 MqBaseConf (org.apache.inlong.manager.client.api.MqBaseConf)1 SortBaseConf (org.apache.inlong.manager.client.api.SortBaseConf)1 SortType (org.apache.inlong.manager.client.api.SortBaseConf.SortType)1