Search in sources :

Example 1 with InlongStreamApproveRequest

use of org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest in project incubator-inlong by apache.

the class InnerInlongManagerClient method startInlongGroup.

public WorkflowResult startInlongGroup(int taskId, Pair<InlongGroupApproveRequest, List<InlongStreamApproveRequest>> initMsg) {
    JSONObject workflowTaskOperation = new JSONObject();
    workflowTaskOperation.put("transferTo", Lists.newArrayList());
    workflowTaskOperation.put("remark", "approved by system");
    JSONObject inlongGroupApproveForm = new JSONObject();
    inlongGroupApproveForm.put("groupApproveInfo", initMsg.getKey());
    inlongGroupApproveForm.put("streamApproveInfoList", initMsg.getValue());
    inlongGroupApproveForm.put("formName", "InlongGroupApproveForm");
    workflowTaskOperation.put("form", inlongGroupApproveForm);
    String operationData = GsonUtil.toJson(workflowTaskOperation);
    final String path = HTTP_PATH + "/workflow/approve/" + taskId;
    final String url = formatUrl(path);
    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), operationData);
    Request request = new Request.Builder().url(url).method("POST", requestBody).build();
    Call call = httpClient.newCall(request);
    try {
        Response response = call.execute();
        assert response.body() != null;
        String body = response.body().string();
        AssertUtil.isTrue(response.isSuccessful(), String.format("Inlong request failed: %s", body));
        org.apache.inlong.manager.common.beans.Response responseBody = InlongParser.parseResponse(body);
        AssertUtil.isTrue(responseBody.getErrMsg() == null, String.format("Inlong request failed: %s", responseBody.getErrMsg()));
        return InlongParser.parseWorkflowResult(responseBody);
    } catch (Exception e) {
        throw new RuntimeException(String.format("Inlong group start failed: %s", e.getMessage()), e);
    }
}
Also used : Call(okhttp3.Call) SinkRequest(org.apache.inlong.manager.common.pojo.sink.SinkRequest) Request(okhttp3.Request) InlongStreamApproveRequest(org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest) InlongGroupRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupRequest) SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) InlongGroupApproveRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest) Response(okhttp3.Response) InlongStreamConfigLogListResponse(org.apache.inlong.manager.common.pojo.stream.InlongStreamConfigLogListResponse) SinkListResponse(org.apache.inlong.manager.common.pojo.sink.SinkListResponse) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse) InlongGroupListResponse(org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse) InlongGroupResponse(org.apache.inlong.manager.common.pojo.group.InlongGroupResponse) FullStreamResponse(org.apache.inlong.manager.common.pojo.stream.FullStreamResponse) JSONObject(com.alibaba.fastjson.JSONObject) RequestBody(okhttp3.RequestBody)

Example 2 with InlongStreamApproveRequest

use of org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest in project incubator-inlong by apache.

the class GroupPassTaskListener method listen.

@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
    // Save the data format selected at the time of approval and the cluster information of the inlong stream
    InlongGroupApproveForm form = (InlongGroupApproveForm) context.getActionContext().getForm();
    InlongGroupApproveRequest approveInfo = form.getGroupApproveInfo();
    // Only the [Wait approval] status allowed the passing operation
    String groupId = approveInfo.getInlongGroupId();
    InlongGroupEntity entity = groupMapper.selectByGroupId(groupId);
    if (entity == null) {
        throw new WorkflowListenerException("inlong group not found with group id=" + groupId);
    }
    if (!Objects.equals(GroupState.TO_BE_APPROVAL.getCode(), entity.getStatus())) {
        throw new WorkflowListenerException("inlong group status is [wait_approval], not allowed to approve again");
    }
    // Save the inlong group information after approval
    groupService.updateAfterApprove(approveInfo, context.getApplicant());
    // Save inlong stream information after approval
    List<InlongStreamApproveRequest> streamApproveInfoList = form.getStreamApproveInfoList();
    streamService.updateAfterApprove(streamApproveInfoList, context.getApplicant());
    return ListenerResult.success();
}
Also used : InlongGroupApproveForm(org.apache.inlong.manager.common.pojo.workflow.form.InlongGroupApproveForm) InlongStreamApproveRequest(org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) WorkflowListenerException(org.apache.inlong.manager.common.exceptions.WorkflowListenerException) InlongGroupApproveRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest)

Example 3 with InlongStreamApproveRequest

use of org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest in project incubator-inlong by apache.

the class InlongStreamServiceImpl method updateAfterApprove.

@Override
public boolean updateAfterApprove(List<InlongStreamApproveRequest> streamApproveList, String operator) {
    if (CollectionUtils.isEmpty(streamApproveList)) {
        return true;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("begin to update stream after approve={}", streamApproveList);
    }
    String groupId = null;
    for (InlongStreamApproveRequest info : streamApproveList) {
        // Modify the inlong stream info after approve
        InlongStreamEntity streamEntity = new InlongStreamEntity();
        // these groupIds are all the same
        groupId = info.getInlongGroupId();
        streamEntity.setInlongGroupId(groupId);
        streamEntity.setInlongStreamId(info.getInlongStreamId());
        streamEntity.setStatus(EntityStatus.STREAM_CONFIG_ING.getCode());
        streamMapper.updateByIdentifierSelective(streamEntity);
        // Modify the sink info after approve, such as update cluster info
        sinkService.updateAfterApprove(info.getSinkList(), operator);
    }
    LOGGER.info("success to update stream after approve for groupId={}", groupId);
    return true;
}
Also used : InlongStreamApproveRequest(org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest) InlongStreamEntity(org.apache.inlong.manager.dao.entity.InlongStreamEntity)

Example 4 with InlongStreamApproveRequest

use of org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest in project incubator-inlong by apache.

the class InlongParser method parseGroupForm.

public static Pair<InlongGroupApproveRequest, List<InlongStreamApproveRequest>> parseGroupForm(String formJson) {
    JsonObject formData = GsonUtil.fromJson(formJson, JsonObject.class);
    JsonObject groupJson = formData.getAsJsonObject(GROUP_INFO);
    InlongGroupApproveRequest groupApproveInfo = GsonUtil.fromJson(groupJson.toString(), InlongGroupApproveRequest.class);
    JsonObject mqExtInfo = groupJson.getAsJsonObject(MQ_EXT_INFO);
    if (mqExtInfo != null && mqExtInfo.get(MIDDLEWARE_TYPE) != null) {
        String middlewareType = mqExtInfo.get(MIDDLEWARE_TYPE).getAsString();
        if (Constant.MIDDLEWARE_PULSAR.equals(middlewareType) || Constant.MIDDLEWARE_TDMQ_PULSAR.equals(middlewareType)) {
            InlongGroupPulsarInfo pulsarInfo = GsonUtil.fromJson(mqExtInfo.toString(), InlongGroupPulsarInfo.class);
            groupApproveInfo.setAckQuorum(pulsarInfo.getAckQuorum());
            groupApproveInfo.setEnsemble(pulsarInfo.getEnsemble());
            groupApproveInfo.setWriteQuorum(pulsarInfo.getWriteQuorum());
            groupApproveInfo.setRetentionTime(pulsarInfo.getRetentionTime());
            groupApproveInfo.setRetentionTimeUnit(pulsarInfo.getRetentionTimeUnit());
            groupApproveInfo.setTtl(pulsarInfo.getTtl());
            groupApproveInfo.setTtlUnit(pulsarInfo.getTtlUnit());
            groupApproveInfo.setRetentionSize(pulsarInfo.getRetentionSize());
            groupApproveInfo.setRetentionSizeUnit(pulsarInfo.getRetentionSizeUnit());
        }
    }
    JsonArray streamJson = formData.getAsJsonArray("streamInfoList");
    List<InlongStreamApproveRequest> streamApproveList = GsonUtil.fromJson(streamJson.toString(), new TypeToken<List<InlongStreamApproveRequest>>() {
    }.getType());
    return Pair.of(groupApproveInfo, streamApproveList);
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) JsonArray(com.google.gson.JsonArray) InlongStreamApproveRequest(org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest) TypeToken(com.google.common.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) InlongGroupApproveRequest(org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest)

Aggregations

InlongStreamApproveRequest (org.apache.inlong.manager.common.pojo.stream.InlongStreamApproveRequest)4 InlongGroupApproveRequest (org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest)3 JSONObject (com.alibaba.fastjson.JSONObject)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Call (okhttp3.Call)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1 Response (okhttp3.Response)1 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)1 InlongGroupListResponse (org.apache.inlong.manager.common.pojo.group.InlongGroupListResponse)1 InlongGroupPulsarInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo)1 InlongGroupRequest (org.apache.inlong.manager.common.pojo.group.InlongGroupRequest)1 InlongGroupResponse (org.apache.inlong.manager.common.pojo.group.InlongGroupResponse)1 SinkListResponse (org.apache.inlong.manager.common.pojo.sink.SinkListResponse)1 SinkRequest (org.apache.inlong.manager.common.pojo.sink.SinkRequest)1 SourceListResponse (org.apache.inlong.manager.common.pojo.source.SourceListResponse)1 SourceRequest (org.apache.inlong.manager.common.pojo.source.SourceRequest)1 FullStreamResponse (org.apache.inlong.manager.common.pojo.stream.FullStreamResponse)1