Search in sources :

Example 1 with OperateType

use of org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType 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 2 with OperateType

use of org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType in project incubator-inlong by apache.

the class UpdateGroupCompleteListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws Exception {
    UpdateGroupProcessForm form = (UpdateGroupProcessForm) context.getProcessForm();
    String username = context.getApplicant();
    OperateType operateType = form.getOperateType();
    InlongGroupInfo groupInfo = form.getGroupInfo();
    Integer nextStatus;
    switch(operateType) {
        case RESTART:
            nextStatus = GroupState.RESTARTED.getCode();
            break;
        case SUSPEND:
            nextStatus = GroupState.SUSPENDED.getCode();
            break;
        case DELETE:
            nextStatus = GroupState.DELETED.getCode();
            break;
        default:
            throw new RuntimeException(String.format("Unsupported operation=%s for Inlong group", operateType));
    }
    // Update inlong group status and other info
    groupService.updateStatus(groupInfo.getInlongGroupId(), nextStatus, username);
    groupService.update(groupInfo.genRequest(), username);
    return ListenerResult.success();
}
Also used : 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)

Example 3 with OperateType

use of org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType in project incubator-inlong by apache.

the class UpdateGroupListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws Exception {
    UpdateGroupProcessForm form = (UpdateGroupProcessForm) context.getProcessForm();
    InlongGroupInfo groupInfo = groupService.get(context.getProcessForm().getInlongGroupId());
    OperateType operateType = form.getOperateType();
    String username = context.getApplicant();
    if (groupInfo != null) {
        switch(operateType) {
            case SUSPEND:
                groupService.updateStatus(groupInfo.getInlongGroupId(), GroupState.SUSPENDING.getCode(), username);
                break;
            case RESTART:
                groupService.updateStatus(groupInfo.getInlongGroupId(), GroupState.RESTARTING.getCode(), username);
                break;
            case DELETE:
                groupService.updateStatus(groupInfo.getInlongGroupId(), GroupState.DELETING.getCode(), username);
                break;
            default:
                break;
        }
        form.setGroupInfo(groupInfo);
    } else {
        throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND);
    }
    return ListenerResult.success();
}
Also used : UpdateGroupProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) InlongGroupInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupInfo) OperateType(org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType)

Aggregations

InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)3 UpdateGroupProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm)3 OperateType (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm.OperateType)3 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ObjectMapper (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper)1 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)1 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)1 InlongGroupExtInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupExtInfo)1 SinkResponse (org.apache.inlong.manager.common.pojo.sink.SinkResponse)1 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)1 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)1 InlongGroupSettings (org.apache.inlong.manager.common.settings.InlongGroupSettings)1 CommonOperateService (org.apache.inlong.manager.service.CommonOperateService)1 StreamSinkService (org.apache.inlong.manager.service.sink.StreamSinkService)1