use of org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest 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);
}
}
use of org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest 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();
}
use of org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest in project incubator-inlong by apache.
the class InlongGroupImpl method init.
@Override
public InlongGroupContext init() throws Exception {
InlongGroupInfo groupInfo = this.groupContext.getGroupInfo();
WorkflowResult initWorkflowResult = managerClient.initInlongGroup(groupInfo.genRequest());
List<TaskResponse> taskViews = initWorkflowResult.getNewTasks();
AssertUtil.notEmpty(taskViews, "Init business info failed");
TaskResponse taskView = taskViews.get(0);
final int taskId = taskView.getId();
ProcessResponse processView = initWorkflowResult.getProcessInfo();
AssertUtil.isTrue(ProcessStatus.PROCESSING == processView.getStatus(), String.format("Business info state : %s is not corrected , should be PROCESSING", processView.getStatus()));
String formData = GsonUtil.toJson(processView.getFormData());
Pair<InlongGroupApproveRequest, List<InlongStreamApproveRequest>> initMsg = InlongParser.parseGroupForm(formData);
groupContext.setInitMsg(initMsg);
WorkflowResult startWorkflowResult = managerClient.startInlongGroup(taskId, initMsg);
processView = startWorkflowResult.getProcessInfo();
AssertUtil.isTrue(ProcessStatus.COMPLETED == processView.getStatus(), String.format("Business info state : %s is not corrected , should be COMPLETED", processView.getStatus()));
return generateSnapshot();
}
use of org.apache.inlong.manager.common.pojo.group.InlongGroupApproveRequest 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);
}
Aggregations