Search in sources :

Example 6 with InlongGroupExtInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo in project incubator-inlong by apache.

the class InlongGroupTransfer method parsePulsarConf.

private static PulsarBaseConf parsePulsarConf(InlongGroupResponse groupResponse) {
    PulsarBaseConf pulsarBaseConf = new PulsarBaseConf();
    pulsarBaseConf.setNamespace(groupResponse.getMqResourceObj());
    InlongGroupPulsarInfo inlongGroupPulsarInfo = (InlongGroupPulsarInfo) groupResponse.getMqExtInfo();
    pulsarBaseConf.setAckQuorum(inlongGroupPulsarInfo.getAckQuorum());
    pulsarBaseConf.setWriteQuorum(inlongGroupPulsarInfo.getWriteQuorum());
    pulsarBaseConf.setEnsemble(inlongGroupPulsarInfo.getEnsemble());
    pulsarBaseConf.setTtl(inlongGroupPulsarInfo.getTtl());
    pulsarBaseConf.setTenant(inlongGroupPulsarInfo.getTenant());
    pulsarBaseConf.setRetentionTime(inlongGroupPulsarInfo.getRetentionTime());
    pulsarBaseConf.setRetentionSize(inlongGroupPulsarInfo.getRetentionSize());
    pulsarBaseConf.setRetentionSizeUnit(inlongGroupPulsarInfo.getRetentionSizeUnit());
    pulsarBaseConf.setRetentionTimeUnit(inlongGroupPulsarInfo.getRetentionTimeUnit());
    pulsarBaseConf.setEnableCreateResource(inlongGroupPulsarInfo.getEnableCreateResource() == 1 ? true : false);
    List<InlongGroupExtInfo> groupExtInfos = groupResponse.getExtList();
    for (InlongGroupExtInfo extInfo : groupExtInfos) {
        if (extInfo.getKeyName().equals(InlongGroupSettings.PULSAR_ADMIN_URL)) {
            pulsarBaseConf.setPulsarAdminUrl(extInfo.getKeyValue());
        }
        if (extInfo.getKeyName().equals(InlongGroupSettings.PULSAR_SERVICE_URL)) {
            pulsarBaseConf.setPulsarServiceUrl(extInfo.getKeyValue());
        }
    }
    return pulsarBaseConf;
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) PulsarBaseConf(org.apache.inlong.manager.client.api.PulsarBaseConf) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)

Example 7 with InlongGroupExtInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo in project incubator-inlong by apache.

the class CreateSortConfigListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws Exception {
    LOGGER.info("Create sort config for context={}", context);
    ProcessForm form = context.getProcessForm();
    if (form instanceof UpdateGroupProcessForm) {
        UpdateGroupProcessForm updateGroupProcessForm = (UpdateGroupProcessForm) form;
        OperateType operateType = updateGroupProcessForm.getOperateType();
        if (operateType == OperateType.SUSPEND || operateType == OperateType.DELETE) {
            return ListenerResult.success();
        }
    }
    InlongGroupInfo groupInfo = this.getGroupInfo(form);
    String groupId = groupInfo.getInlongGroupId();
    if (StringUtils.isEmpty(groupId)) {
        LOGGER.warn("GroupId is null for context={}", context);
        return ListenerResult.success();
    }
    List<SinkResponse> sinkResponseList = streamSinkService.listSink(groupId, null);
    if (CollectionUtils.isEmpty(sinkResponseList)) {
        LOGGER.warn("Sink not found by groupId={}", groupId);
        return ListenerResult.success();
    }
    Map<String, DataFlowInfo> dataFlowInfoMap = sinkResponseList.stream().map(sink -> {
        DataFlowInfo flowInfo = commonOperateService.createDataFlow(groupInfo, sink);
        return Pair.of(sink.getInlongStreamId(), flowInfo);
    }).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
    String dataFlows = OBJECT_MAPPER.writeValueAsString(dataFlowInfoMap);
    InlongGroupExtInfo extInfo = new InlongGroupExtInfo();
    extInfo.setInlongGroupId(groupId);
    extInfo.setKeyName(InlongGroupSettings.DATA_FLOW);
    extInfo.setKeyValue(dataFlows);
    if (groupInfo.getExtList() == null) {
        groupInfo.setExtList(Lists.newArrayList());
    }
    upsertDataFlow(groupInfo, extInfo);
    return ListenerResult.success();
}
Also used : ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) CommonOperateService(org.apache.inlong.manager.service.CommonOperateService) StreamSinkService(org.apache.inlong.manager.service.sink.StreamSinkService) TaskEvent(org.apache.inlong.manager.workflow.event.task.TaskEvent) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper) Map(java.util.Map) OperateType(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) InlongGroupSettings(org.apache.inlong.manager.common.settings.InlongGroupSettings) Logger(org.slf4j.Logger) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) Collectors(java.util.stream.Collectors) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) ListenerResult(org.apache.inlong.manager.workflow.event.ListenerResult) Component(org.springframework.stereotype.Component) List(java.util.List) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) SortOperateListener(org.apache.inlong.manager.workflow.event.task.SortOperateListener) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) SinkResponse(org.apache.inlong.manager.common.pojo.sink.SinkResponse) ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) GroupResourceProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm) UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) OperateType(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo)

Example 8 with InlongGroupExtInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo 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 9 with InlongGroupExtInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo 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)

Example 10 with InlongGroupExtInfo

use of org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo in project incubator-inlong by apache.

the class PulsarUtilsTest method testGetPulsarAdmin.

@Test
public void testGetPulsarAdmin() {
    InlongGroupExtInfo groupExtInfo1 = new InlongGroupExtInfo();
    groupExtInfo1.setId(1);
    groupExtInfo1.setInlongGroupId("group1");
    groupExtInfo1.setKeyName(InlongGroupSettings.PULSAR_ADMIN_URL);
    groupExtInfo1.setKeyValue("http://127.0.0.1:8080");
    InlongGroupExtInfo groupExtInfo2 = new InlongGroupExtInfo();
    groupExtInfo2.setId(2);
    groupExtInfo2.setInlongGroupId("group1");
    groupExtInfo2.setKeyName(InlongGroupSettings.PULSAR_AUTHENTICATION);
    groupExtInfo2.setKeyValue("QWEASDZXC");
    ArrayList<InlongGroupExtInfo> groupExtInfoList = Lists.newArrayList(groupExtInfo1, groupExtInfo2);
    InlongGroupInfo groupInfo = new InlongGroupInfo();
    groupInfo.setExtList(groupExtInfoList);
    final String defaultServiceUrl = "http://127.0.0.1:10080";
    try {
        PulsarAdmin admin = PulsarUtils.getPulsarAdmin(defaultServiceUrl);
        Assert.assertEquals("http://127.0.0.1:8080", admin.getServiceUrl());
        Field auth = ReflectionUtils.findField(PulsarAdminImpl.class, "auth");
        assert auth != null;
        auth.setAccessible(true);
        Authentication authentication = (Authentication) auth.get(admin);
        Assert.assertNotNull(authentication);
        InlongGroupExtInfo groupExtInfo3 = new InlongGroupExtInfo();
        groupExtInfo3.setId(3);
        groupExtInfo3.setInlongGroupId("group1");
        groupExtInfo3.setKeyName(InlongGroupSettings.PULSAR_AUTHENTICATION_TYPE);
        groupExtInfo3.setKeyValue("token1");
        groupExtInfoList.add(groupExtInfo3);
        try {
            admin = PulsarUtils.getPulsarAdmin(defaultServiceUrl);
        } catch (Exception e) {
            if (e instanceof IllegalArgumentException) {
                Assert.assertTrue(e.getMessage().contains("illegal authentication type"));
            }
        }
        groupExtInfoList = new ArrayList<>();
        groupInfo.setExtList(groupExtInfoList);
        admin = PulsarUtils.getPulsarAdmin(defaultServiceUrl);
        Assert.assertEquals("http://127.0.0.1:10080", admin.getServiceUrl());
        auth = ReflectionUtils.findField(PulsarAdminImpl.class, "auth");
        assert auth != null;
        auth.setAccessible(true);
        authentication = (Authentication) auth.get(admin);
        Assert.assertTrue(authentication instanceof AuthenticationDisabled);
    } catch (PulsarClientException | IllegalAccessException e) {
        Assert.fail();
    }
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) PulsarAdminImpl(org.apache.pulsar.client.admin.internal.PulsarAdminImpl) InlongGroupExtInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) Field(java.lang.reflect.Field) Authentication(org.apache.pulsar.client.api.Authentication) AuthenticationDisabled(org.apache.pulsar.client.impl.auth.AuthenticationDisabled) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) Test(org.junit.Test)

Aggregations

InlongGroupExtInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)14 ArrayList (java.util.ArrayList)5 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)4 InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)3 TypeToken (com.google.gson.reflect.TypeToken)2 List (java.util.List)2 FlinkSortBaseConf (org.apache.inlong.manager.client.api.FlinkSortBaseConf)2 PulsarBaseConf (org.apache.inlong.manager.client.api.PulsarBaseConf)2 SortType (org.apache.inlong.manager.client.api.SortBaseConf.SortType)2 TubeBaseConf (org.apache.inlong.manager.client.api.TubeBaseConf)2 UserDefinedSortConf (org.apache.inlong.manager.client.api.UserDefinedSortConf)2 Authentication (org.apache.inlong.manager.client.api.auth.Authentication)2 AuthType (org.apache.inlong.manager.client.api.auth.Authentication.AuthType)2 SecretTokenAuthentication (org.apache.inlong.manager.client.api.auth.SecretTokenAuthentication)2 TokenAuthentication (org.apache.inlong.manager.client.api.auth.TokenAuthentication)2 InlongGroupExtEntity (org.apache.inlong.manager.dao.entity.InlongGroupExtEntity)2 Lists (com.google.common.collect.Lists)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1