Search in sources :

Example 1 with InlongGroupExtEntity

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

the class InlongGroupServiceTest method testSaveAndUpdateExt.

@Test
public void testSaveAndUpdateExt() {
    // check insert
    InlongGroupExtInfo groupExtInfo1 = new InlongGroupExtInfo();
    groupExtInfo1.setId(1);
    groupExtInfo1.setInlongGroupId(globalGroupId);
    groupExtInfo1.setKeyName("pulsar_url");
    groupExtInfo1.setKeyValue("http://127.0.0.1:8080");
    InlongGroupExtInfo groupExtInfo2 = new InlongGroupExtInfo();
    groupExtInfo2.setId(2);
    groupExtInfo2.setInlongGroupId(globalGroupId);
    groupExtInfo2.setKeyName("pulsar_secret");
    groupExtInfo2.setKeyValue("QWEASDZXC");
    List<InlongGroupExtInfo> groupExtInfoList = Arrays.asList(groupExtInfo1, groupExtInfo2);
    groupService.saveOrUpdateExt(globalGroupId, groupExtInfoList);
    List<InlongGroupExtEntity> extEntityList = groupExtMapper.selectByGroupId(globalGroupId);
    Assert.assertEquals(2, extEntityList.size());
    Assert.assertEquals("pulsar_url", extEntityList.get(0).getKeyName());
    Assert.assertEquals("http://127.0.0.1:8080", extEntityList.get(0).getKeyValue());
    // check update
    groupExtInfo1.setKeyValue("http://127.0.0.1:8081");
    groupService.saveOrUpdateExt(globalGroupId, groupExtInfoList);
    extEntityList = groupExtMapper.selectByGroupId(globalGroupId);
    Assert.assertEquals(2, extEntityList.size());
    Assert.assertEquals("http://127.0.0.1:8081", extEntityList.get(0).getKeyValue());
    groupExtInfo2.setKeyValue("qweasdzxc");
    groupService.saveOrUpdateExt(globalGroupId, groupExtInfoList);
    extEntityList = groupExtMapper.selectByGroupId(globalGroupId);
    Assert.assertEquals(2, extEntityList.size());
    Assert.assertEquals("qweasdzxc", extEntityList.get(1).getKeyValue());
}
Also used : InlongGroupExtEntity(org.apache.inlong.manager.dao.entity.InlongGroupExtEntity) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) Test(org.junit.Test)

Example 2 with InlongGroupExtEntity

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

the class InlongGroupServiceImpl method saveOrUpdateExt.

@Override
@Transactional(rollbackFor = Throwable.class)
public void saveOrUpdateExt(String groupId, List<InlongGroupExtInfo> infoList) {
    LOGGER.debug("begin to save or update inlong group ext info, groupId={}, ext={}", groupId, infoList);
    if (CollectionUtils.isEmpty(infoList)) {
        return;
    }
    List<InlongGroupExtEntity> entityList = CommonBeanUtils.copyListProperties(infoList, InlongGroupExtEntity::new);
    Date date = new Date();
    for (InlongGroupExtEntity entity : entityList) {
        entity.setInlongGroupId(groupId);
        entity.setModifyTime(date);
    }
    groupExtMapper.insertOnDuplicateKeyUpdate(entityList);
    LOGGER.info("success to save or update inlong group ext for groupId={}", groupId);
}
Also used : InlongGroupExtEntity(org.apache.inlong.manager.dao.entity.InlongGroupExtEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with InlongGroupExtEntity

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

the class InlongGroupServiceImpl method get.

@Override
public InlongGroupInfo get(String groupId) {
    LOGGER.debug("begin to get inlong group info by groupId={}", groupId);
    Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
    InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
    if (entity == null) {
        LOGGER.error("inlong group not found by groupId={}", groupId);
        throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
    }
    InlongGroupInfo groupInfo = CommonBeanUtils.copyProperties(entity, InlongGroupInfo::new);
    List<InlongGroupExtEntity> extEntityList = groupExtMapper.selectByGroupId(groupId);
    List<InlongGroupExtInfo> extInfoList = CommonBeanUtils.copyListProperties(extEntityList, InlongGroupExtInfo::new);
    groupInfo.setExtList(extInfoList);
    // If the middleware is Pulsar, we need to encapsulate Pulsar related data
    String mqType = entity.getMiddlewareType();
    if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
        InlongGroupPulsarEntity pulsarEntity = groupPulsarMapper.selectByGroupId(groupId);
        Preconditions.checkNotNull(pulsarEntity, "Pulsar info not found by the groupId=" + groupId);
        InlongGroupPulsarInfo pulsarInfo = CommonBeanUtils.copyProperties(pulsarEntity, InlongGroupPulsarInfo::new);
        pulsarInfo.setMiddlewareType(mqType);
        groupInfo.setMqExtInfo(pulsarInfo);
    }
    // For approved inlong group, encapsulate the cluster address of the middleware
    if (GroupState.CONFIG_SUCCESSFUL == GroupState.forCode(groupInfo.getStatus())) {
        if (Constant.MIDDLEWARE_TUBE.equalsIgnoreCase(mqType)) {
            groupInfo.setTubeMaster(commonOperateService.getSpecifiedParam(Constant.TUBE_MASTER_URL));
        } else if (Constant.MIDDLEWARE_PULSAR.equals(mqType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(mqType)) {
            PulsarClusterInfo pulsarCluster = commonOperateService.getPulsarClusterInfo(mqType);
            groupInfo.setPulsarAdminUrl(pulsarCluster.getAdminUrl());
            groupInfo.setPulsarServiceUrl(pulsarCluster.getBrokerServiceUrl());
        }
    }
    LOGGER.debug("success to get inlong group for groupId={}", groupId);
    return groupInfo;
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) InlongGroupExtEntity(org.apache.inlong.manager.dao.entity.InlongGroupExtEntity) InlongGroupPulsarEntity(org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity) PulsarClusterInfo(org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)

Aggregations

InlongGroupExtEntity (org.apache.inlong.manager.dao.entity.InlongGroupExtEntity)3 InlongGroupExtInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)2 Date (java.util.Date)1 PulsarClusterInfo (org.apache.inlong.common.pojo.dataproxy.PulsarClusterInfo)1 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)1 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)1 InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)1 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)1 InlongGroupPulsarEntity (org.apache.inlong.manager.dao.entity.InlongGroupPulsarEntity)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1