Search in sources :

Example 1 with ThirdPartyClusterEntity

use of org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity 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)

Example 2 with ThirdPartyClusterEntity

use of org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity in project incubator-inlong by apache.

the class ThirdPartyClusterServiceImpl method save.

@Override
@Transactional(rollbackFor = Throwable.class)
public Integer save(ClusterRequest request, String operator) {
    LOGGER.info("begin to insert a cluster info cluster={}", request);
    Preconditions.checkNotNull(request, "cluster is empty");
    ThirdPartyClusterEntity exist = thirdPartyClusterMapper.selectByName(request.getName());
    Preconditions.checkTrue(exist == null, "cluster name already exist");
    ThirdPartyClusterEntity entity = CommonBeanUtils.copyProperties(request, ThirdPartyClusterEntity::new);
    if (operator != null) {
        entity.setCreator(operator);
    }
    Preconditions.checkNotNull(entity.getCreator(), "cluster creator is empty");
    entity.setCreateTime(new Date());
    entity.setIsDeleted(Constant.UN_DELETED);
    thirdPartyClusterMapper.insert(entity);
    LOGGER.info("success to add a cluster");
    return entity.getId();
}
Also used : Date(java.util.Date) ThirdPartyClusterEntity(org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ThirdPartyClusterEntity

use of org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity in project incubator-inlong by apache.

the class ThirdPartyClusterServiceImpl method update.

@Override
@Transactional(rollbackFor = Throwable.class)
public Boolean update(ClusterRequest request, String operator) {
    Preconditions.checkNotNull(request, "cluster is empty");
    Integer id = request.getId();
    Preconditions.checkNotNull(id, "cluster id is empty");
    ThirdPartyClusterEntity entity = thirdPartyClusterMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("cluster not found by id={}", id);
        throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
    }
    CommonBeanUtils.copyProperties(request, entity, true);
    entity.setModifier(operator);
    thirdPartyClusterMapper.updateByPrimaryKeySelective(entity);
    LOGGER.info("success to update cluster={}", request);
    return true;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) ThirdPartyClusterEntity(org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ThirdPartyClusterEntity

use of org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity in project incubator-inlong by apache.

the class CommonOperateService method getPulsarClusterInfo.

/**
 * Get Pulsar cluster by the given type.
 *
 * @return Pulsar cluster info.
 */
public PulsarClusterInfo getPulsarClusterInfo(String type) {
    ThirdPartyClusterEntity clusterEntity = getMQCluster(type);
    if (clusterEntity == null || StringUtils.isBlank(clusterEntity.getExtParams())) {
        throw new BusinessException("pulsar cluster or pulsar ext params is empty");
    }
    Map<String, String> configParams = JsonUtils.parse(clusterEntity.getExtParams(), Map.class);
    PulsarClusterInfo pulsarClusterInfo = PulsarClusterInfo.builder().brokerServiceUrl(clusterEntity.getUrl()).token(clusterEntity.getToken()).build();
    String adminUrl = configParams.get(Constant.PULSAR_ADMINURL);
    Preconditions.checkNotNull(adminUrl, "adminUrl is empty, check third party cluster table");
    pulsarClusterInfo.setAdminUrl(adminUrl);
    pulsarClusterInfo.setType(clusterEntity.getType());
    return pulsarClusterInfo;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) PulsarClusterInfo(org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo) ThirdPartyClusterEntity(org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)

Example 5 with ThirdPartyClusterEntity

use of org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity in project incubator-inlong by apache.

the class CommonOperateService method getSpecifiedParam.

/**
 * query some third-party-cluster info according key, such as "pulsar_adminUrl", "cluster_tube_manager", etc.
 *
 * @param key Param name.
 * @return Value of key in database.
 */
public String getSpecifiedParam(String key) {
    String result = "";
    ThirdPartyClusterEntity clusterEntity;
    Gson gson = new Gson();
    Map<String, String> params;
    switch(key) {
        case Constant.PULSAR_SERVICEURL:
            {
                clusterEntity = getMQCluster(Constant.MIDDLEWARE_PULSAR);
                if (clusterEntity != null) {
                    result = clusterEntity.getUrl();
                }
                break;
            }
        case Constant.PULSAR_ADMINURL:
            {
                clusterEntity = getMQCluster(Constant.MIDDLEWARE_PULSAR);
                if (clusterEntity != null) {
                    params = gson.fromJson(clusterEntity.getExtParams(), Map.class);
                    result = params.get(key);
                }
                break;
            }
        case Constant.CLUSTER_TUBE_MANAGER:
        case Constant.CLUSTER_TUBE_CLUSTER_ID:
        case Constant.TUBE_MASTER_URL:
            {
                clusterEntity = getMQCluster(Constant.MIDDLEWARE_TUBE);
                if (clusterEntity != null) {
                    if (key.equals(Constant.TUBE_MASTER_URL)) {
                        result = clusterEntity.getUrl();
                    } else {
                        params = gson.fromJson(clusterEntity.getExtParams(), Map.class);
                        result = params.get(key);
                    }
                }
                break;
            }
    }
    return result;
}
Also used : Gson(com.google.gson.Gson) ThirdPartyClusterEntity(org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)

Aggregations

ThirdPartyClusterEntity (org.apache.inlong.manager.dao.entity.ThirdPartyClusterEntity)9 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)5 ArrayList (java.util.ArrayList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Gson (com.google.gson.Gson)1 Date (java.util.Date)1 DataProxyConfig (org.apache.inlong.common.pojo.dataproxy.DataProxyConfig)1 PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)1 ThirdPartyClusterDTO (org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterDTO)1 ThirdPartyClusterInfo (org.apache.inlong.common.pojo.dataproxy.ThirdPartyClusterInfo)1 ClusterPageRequest (org.apache.inlong.manager.common.pojo.cluster.ClusterPageRequest)1 ClusterResponse (org.apache.inlong.manager.common.pojo.cluster.ClusterResponse)1 DataProxyResponse (org.apache.inlong.manager.common.pojo.dataproxy.DataProxyResponse)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