Search in sources :

Example 1 with ThirdPartyClusterInfo

use of org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterInfo in project incubator-inlong by apache.

the class ThirdPartyClusterServiceImpl method getConfigV2.

/**
 * query data proxy config by cluster name, result includes pulsar/tube cluster configs and topic etc
 */
@Override
public ThirdPartyClusterDTO getConfigV2(String clusterName) {
    ThirdPartyClusterEntity clusterEntity = thirdPartyClusterMapper.selectByName(clusterName);
    if (clusterEntity == null) {
        throw new BusinessException("data proxy cluster not found by name=" + clusterName);
    }
    // TODO Optimize query conditions use dataProxyClusterId
    List<InlongGroupEntity> groupEntityList = groupMapper.selectAll(GroupState.CONFIG_SUCCESSFUL.getCode());
    if (CollectionUtils.isEmpty(groupEntityList)) {
        String msg = "not found any inlong group with success status for proxy cluster name = " + clusterName;
        LOGGER.warn(msg);
        throw new BusinessException(msg);
    }
    // third-party-cluster type
    String mqType = "";
    if (!groupEntityList.isEmpty()) {
        mqType = groupEntityList.get(0).getMiddlewareType();
    }
    // Get topic list by group id
    List<DataProxyConfig> topicList = new ArrayList<>();
    for (InlongGroupEntity groupEntity : groupEntityList) {
        final String groupId = groupEntity.getInlongGroupId();
        final String mqResource = groupEntity.getMqResourceObj();
        if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
            List<InlongStreamEntity> streamList = streamMapper.selectByGroupId(groupId);
            for (InlongStreamEntity stream : streamList) {
                DataProxyConfig topicConfig = new DataProxyConfig();
                String streamId = stream.getInlongStreamId();
                String topic = stream.getMqResourceObj();
                String tenant = clusterBean.getDefaultTenant();
                InlongGroupPulsarEntity pulsarEntity = pulsarEntityMapper.selectByGroupId(groupId);
                if (pulsarEntity != null && StringUtils.isNotEmpty(pulsarEntity.getTenant())) {
                    tenant = pulsarEntity.getTenant();
                }
                topicConfig.setInlongGroupId(groupId + "/" + streamId);
                topicConfig.setTopic("persistent://" + tenant + "/" + mqResource + "/" + topic);
                topicList.add(topicConfig);
            }
        } else if (Constant.MIDDLEWARE_TUBE.equals(mqType)) {
            DataProxyConfig topicConfig = new DataProxyConfig();
            topicConfig.setInlongGroupId(groupId);
            topicConfig.setTopic(mqResource);
            topicList.add(topicConfig);
        }
    }
    // construct pulsarSet info
    List<ThirdPartyClusterInfo> mqSet = new ArrayList<>();
    List<String> clusterType = Arrays.asList(Constant.CLUSTER_TUBE, Constant.CLUSTER_PULSAR, Constant.CLUSTER_TDMQ_PULSAR);
    List<ThirdPartyClusterEntity> clusterList = thirdPartyClusterMapper.selectMQCluster(clusterEntity.getMqSetName(), clusterType);
    for (ThirdPartyClusterEntity cluster : clusterList) {
        ThirdPartyClusterInfo clusterInfo = new ThirdPartyClusterInfo();
        clusterInfo.setUrl(cluster.getUrl());
        clusterInfo.setToken(cluster.getToken());
        Map<String, String> configParams = GSON.fromJson(cluster.getExtParams(), Map.class);
        clusterInfo.setParams(configParams);
        mqSet.add(clusterInfo);
    }
    ThirdPartyClusterDTO object = new ThirdPartyClusterDTO();
    object.setMqSet(mqSet);
    object.setTopicList(topicList);
    return object;
}
Also used : InlongGroupPulsarEntity(org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity) ThirdPartyClusterInfo(org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterInfo) ArrayList(java.util.ArrayList) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) ThirdPartyClusterDTO(org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterDTO) InlongStreamEntity(org.apache.inlong.manager.dao.entity.InlongStreamEntity) DataProxyConfig(org.apache.inlong.common.pojo.dataproxy.DataProxyConfig) ThirdPartyClusterEntity(org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)

Aggregations

ArrayList (java.util.ArrayList)1 DataProxyConfig (org.apache.inlong.common.pojo.dataproxy.DataProxyConfig)1 ThirdPartyClusterDTO (org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterDTO)1 ThirdPartyClusterInfo (org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterInfo)1 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)1 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)1 InlongGroupPulsarEntity (org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity)1 InlongStreamEntity (org.apache.inlong.manager.dao.entity.InlongStreamEntity)1 ThirdPartyClusterEntity (org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)1