Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-5285][Manager] Support custom query for group, stream, source and sink #5287

Merged
merged 3 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.inlong.manager.common.enums;

import org.apache.inlong.manager.common.beans.PageRequest;

/**
* The order field enumeration.
*/
public enum OrderFieldEnum {

CREATE_TIME,

MODIFY_TIME;

public static void checkOrderField(PageRequest pageRequest) {
for (OrderFieldEnum value : values()) {
if (value.name().equalsIgnoreCase(pageRequest.getOrderField())) {
pageRequest.setOrderField(value.name().toLowerCase());
return;
}
}
pageRequest.setOrderField(CREATE_TIME.name().toLowerCase());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.inlong.manager.common.enums;

import org.apache.inlong.manager.common.beans.PageRequest;

/**
* The order type enumeration.
*/
public enum OrderTypeEnum {

DESC,

ASC;

public static void checkOrderType(PageRequest pageRequest) {
for (OrderTypeEnum value : values()) {
if (value.name().equalsIgnoreCase(pageRequest.getOrderType())) {
pageRequest.setOrderType(value.name().toLowerCase());
return;
}
}
pageRequest.setOrderType(DESC.name().toLowerCase());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@
</foreach>
</if>
</where>
order by modify_time desc
<choose>
<when test="orderField != null and orderField != '' and orderType != null and orderType != ''">
order by ${orderField} ${orderType}
</when>
<otherwise>
order by create_time desc
</otherwise>
</choose>
</select>
<select id="selectBriefList" parameterType="org.apache.inlong.manager.pojo.group.InlongGroupPageRequest"
resultType="org.apache.inlong.manager.pojo.group.InlongGroupBriefInfo">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@
and stream.status = #{request.status, jdbcType=INTEGER}
</if>
</where>
order by stream.modify_time desc
<choose>
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
order by stream.${request.orderField} ${request.orderType}
</when>
<otherwise>
order by stream.create_time desc
</otherwise>
</choose>
</select>
<select id="selectBriefList" resultType="org.apache.inlong.manager.pojo.stream.InlongStreamBriefInfo">
select id, inlong_group_id, inlong_stream_id, name, mq_resource, modify_time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,15 @@
<if test="request.sortConsumerGroup != null and request.sortConsumerGroup != ''">
and sort_consumer_group = #{request.sortConsumerGroup, jdbcType=VARCHAR}
</if>
order by modify_time desc
</where>
<choose>
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
order by ${request.orderField} ${request.orderType}
</when>
<otherwise>
order by create_time desc
</otherwise>
</choose>
</select>
<select id="selectSummary"
resultType="org.apache.inlong.manager.pojo.sink.SinkBriefInfo">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@
<if test="request.status != null and request.status != ''">
and status = #{request.status, jdbcType=INTEGER}
</if>
order by modify_time desc
</where>
<choose>
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
order by ${request.orderField} ${request.orderType}
</when>
<otherwise>
order by create_time desc
</otherwise>
</choose>
</select>
<select id="selectByAgentIp" resultType="org.apache.inlong.manager.dao.entity.StreamSourceEntity">
select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,36 @@
@ApiModel(value = "Pagination request")
public class PageRequest {

@ApiModelProperty(value = "current page, default 1", required = true, example = "1")
@ApiModelProperty(value = "Current page number, default is 1")
private int pageNum = 1;

@ApiModelProperty(value = "page size, default 10", required = true, example = "10")
@ApiModelProperty(value = "Page size, default is 10")
private int pageSize = 10;

@ApiModelProperty(value = "Order field, support create_time and modify_time, default is create_time")
private String orderField = "create_time";

@ApiModelProperty(value = "Order type, only support asc and desc, default is desc")
private String orderType = "desc";

public String getOrderField() {
return orderField;
}

public PageRequest setOrderField(String orderField) {
this.orderField = orderField;
return this;
}

public String getOrderType() {
return orderType;
}

public PageRequest setOrderType(String orderType) {
this.orderType = orderType;
return this;
}

public int getPageNum() {
return pageNum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.enums.GroupStatus;
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
import org.apache.inlong.manager.common.enums.SourceType;
import org.apache.inlong.manager.common.exceptions.BusinessException;
import org.apache.inlong.manager.common.exceptions.WorkflowListenerException;
Expand Down Expand Up @@ -176,6 +178,8 @@ public PageInfo<InlongGroupBriefInfo> listBrief(InlongGroupPageRequest request)
request.setPageSize(MAX_PAGE_SIZE);
}
PageHelper.startPage(request.getPageNum(), request.getPageSize());
OrderFieldEnum.checkOrderField(request);
OrderTypeEnum.checkOrderType(request);
Page<InlongGroupEntity> entityPage = (Page<InlongGroupEntity>) groupMapper.selectByCondition(request);

List<InlongGroupBriefInfo> briefInfos = CommonBeanUtils.copyListProperties(entityPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.enums.GroupStatus;
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
import org.apache.inlong.manager.common.enums.SinkStatus;
import org.apache.inlong.manager.common.enums.SinkType;
import org.apache.inlong.manager.common.exceptions.BusinessException;
Expand Down Expand Up @@ -183,6 +185,8 @@ public PageInfo<? extends StreamSink> listByCondition(SinkPageRequest request) {
Preconditions.checkNotNull(request.getInlongGroupId(), ErrorCodeEnum.GROUP_ID_IS_EMPTY.getMessage());

PageHelper.startPage(request.getPageNum(), request.getPageSize());
OrderFieldEnum.checkOrderField(request);
OrderTypeEnum.checkOrderType(request);
List<StreamSinkEntity> entityPage = sinkMapper.selectByCondition(request);
Map<SinkType, Page<StreamSinkEntity>> sinkMap = Maps.newHashMap();
for (StreamSinkEntity streamSink : entityPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.enums.GroupStatus;
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
import org.apache.inlong.manager.common.enums.SourceStatus;
import org.apache.inlong.manager.common.enums.SourceType;
import org.apache.inlong.manager.common.exceptions.BusinessException;
Expand Down Expand Up @@ -171,6 +173,8 @@ public PageInfo<? extends StreamSource> listByCondition(SourcePageRequest reques
Preconditions.checkNotNull(request.getInlongGroupId(), ErrorCodeEnum.GROUP_ID_IS_EMPTY.getMessage());

PageHelper.startPage(request.getPageNum(), request.getPageSize());
OrderFieldEnum.checkOrderField(request);
OrderTypeEnum.checkOrderType(request);
List<StreamSourceEntity> entityList = sourceMapper.selectByCondition(request);

// Encapsulate the paging query results into the PageInfo object to obtain related paging information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.enums.GroupStatus;
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
import org.apache.inlong.manager.common.enums.StreamStatus;
import org.apache.inlong.manager.common.exceptions.BusinessException;
import org.apache.inlong.manager.pojo.sink.SinkBriefInfo;
Expand Down Expand Up @@ -201,6 +203,8 @@ public PageInfo<InlongStreamBriefInfo> listBrief(InlongStreamPageRequest request
LOGGER.debug("begin to list inlong stream page by {}", request);

PageHelper.startPage(request.getPageNum(), request.getPageSize());
OrderFieldEnum.checkOrderField(request);
OrderTypeEnum.checkOrderType(request);
Page<InlongStreamEntity> entityPage = (Page<InlongStreamEntity>) streamMapper.selectByCondition(request);
List<InlongStreamBriefInfo> streamList = CommonBeanUtils.copyListProperties(entityPage,
InlongStreamBriefInfo::new);
Expand Down