Skip to content

Commit 7b4285d

Browse files
ciscozhoubruceneenhl
authored andcommitted
[INLONG-5285][Manager] Support custom query for group, stream, source and sink (apache#5287)
1 parent 3223f73 commit 7b4285d

File tree

11 files changed

+156
-6
lines changed

11 files changed

+156
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.inlong.manager.common.enums;
19+
20+
import org.apache.inlong.manager.common.beans.PageRequest;
21+
22+
/**
23+
* The order field enumeration.
24+
*/
25+
public enum OrderFieldEnum {
26+
27+
CREATE_TIME,
28+
29+
MODIFY_TIME;
30+
31+
public static void checkOrderField(PageRequest pageRequest) {
32+
for (OrderFieldEnum value : values()) {
33+
if (value.name().equalsIgnoreCase(pageRequest.getOrderField())) {
34+
pageRequest.setOrderField(value.name().toLowerCase());
35+
return;
36+
}
37+
}
38+
pageRequest.setOrderField(CREATE_TIME.name().toLowerCase());
39+
}
40+
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.inlong.manager.common.enums;
19+
20+
import org.apache.inlong.manager.common.beans.PageRequest;
21+
22+
/**
23+
* The order type enumeration.
24+
*/
25+
public enum OrderTypeEnum {
26+
27+
DESC,
28+
29+
ASC;
30+
31+
public static void checkOrderType(PageRequest pageRequest) {
32+
for (OrderTypeEnum value : values()) {
33+
if (value.name().equalsIgnoreCase(pageRequest.getOrderType())) {
34+
pageRequest.setOrderType(value.name().toLowerCase());
35+
return;
36+
}
37+
}
38+
pageRequest.setOrderType(DESC.name().toLowerCase());
39+
}
40+
41+
}

inlong-manager/manager-dao/src/main/resources/mappers/InlongGroupEntityMapper.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@
154154
</foreach>
155155
</if>
156156
</where>
157-
order by modify_time desc
157+
<choose>
158+
<when test="orderField != null and orderField != '' and orderType != null and orderType != ''">
159+
order by ${orderField} ${orderType}
160+
</when>
161+
<otherwise>
162+
order by create_time desc
163+
</otherwise>
164+
</choose>
158165
</select>
159166
<select id="selectBriefList" parameterType="org.apache.inlong.manager.pojo.group.InlongGroupPageRequest"
160167
resultType="org.apache.inlong.manager.pojo.group.InlongGroupBriefInfo">

inlong-manager/manager-dao/src/main/resources/mappers/InlongStreamEntityMapper.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,14 @@
262262
and stream.status = #{request.status, jdbcType=INTEGER}
263263
</if>
264264
</where>
265-
order by stream.modify_time desc
265+
<choose>
266+
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
267+
order by stream.${request.orderField} ${request.orderType}
268+
</when>
269+
<otherwise>
270+
order by stream.create_time desc
271+
</otherwise>
272+
</choose>
266273
</select>
267274
<select id="selectBriefList" resultType="org.apache.inlong.manager.pojo.stream.InlongStreamBriefInfo">
268275
select id, inlong_group_id, inlong_stream_id, name, mq_resource, modify_time

inlong-manager/manager-dao/src/main/resources/mappers/StreamSinkEntityMapper.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,15 @@
235235
<if test="request.sortConsumerGroup != null and request.sortConsumerGroup != ''">
236236
and sort_consumer_group = #{request.sortConsumerGroup, jdbcType=VARCHAR}
237237
</if>
238-
order by modify_time desc
239238
</where>
239+
<choose>
240+
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
241+
order by ${request.orderField} ${request.orderType}
242+
</when>
243+
<otherwise>
244+
order by create_time desc
245+
</otherwise>
246+
</choose>
240247
</select>
241248
<select id="selectSummary"
242249
resultType="org.apache.inlong.manager.pojo.sink.SinkBriefInfo">

inlong-manager/manager-dao/src/main/resources/mappers/StreamSourceEntityMapper.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,15 @@
125125
<if test="request.status != null and request.status != ''">
126126
and status = #{request.status, jdbcType=INTEGER}
127127
</if>
128-
order by modify_time desc
129128
</where>
129+
<choose>
130+
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
131+
order by ${request.orderField} ${request.orderType}
132+
</when>
133+
<otherwise>
134+
order by create_time desc
135+
</otherwise>
136+
</choose>
130137
</select>
131138
<select id="selectByAgentIp" resultType="org.apache.inlong.manager.dao.entity.StreamSourceEntity">
132139
select

inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/common/PageRequest.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,36 @@
2626
@ApiModel(value = "Pagination request")
2727
public class PageRequest {
2828

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

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

35+
@ApiModelProperty(value = "Order field, support create_time and modify_time, default is create_time")
36+
private String orderField = "create_time";
37+
38+
@ApiModelProperty(value = "Order type, only support asc and desc, default is desc")
39+
private String orderType = "desc";
40+
41+
public String getOrderField() {
42+
return orderField;
43+
}
44+
45+
public PageRequest setOrderField(String orderField) {
46+
this.orderField = orderField;
47+
return this;
48+
}
49+
50+
public String getOrderType() {
51+
return orderType;
52+
}
53+
54+
public PageRequest setOrderType(String orderType) {
55+
this.orderType = orderType;
56+
return this;
57+
}
58+
3559
public int getPageNum() {
3660
return pageNum;
3761
}

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.inlong.manager.common.consts.InlongConstants;
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
30+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
31+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
3032
import org.apache.inlong.manager.common.enums.SourceType;
3133
import org.apache.inlong.manager.common.exceptions.BusinessException;
3234
import org.apache.inlong.manager.common.exceptions.WorkflowListenerException;
@@ -176,6 +178,8 @@ public PageInfo<InlongGroupBriefInfo> listBrief(InlongGroupPageRequest request)
176178
request.setPageSize(MAX_PAGE_SIZE);
177179
}
178180
PageHelper.startPage(request.getPageNum(), request.getPageSize());
181+
OrderFieldEnum.checkOrderField(request);
182+
OrderTypeEnum.checkOrderType(request);
179183
Page<InlongGroupEntity> entityPage = (Page<InlongGroupEntity>) groupMapper.selectByCondition(request);
180184

181185
List<InlongGroupBriefInfo> briefInfos = CommonBeanUtils.copyListProperties(entityPage,

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/StreamSinkServiceImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.inlong.manager.common.consts.InlongConstants;
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
30+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
31+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
3032
import org.apache.inlong.manager.common.enums.SinkStatus;
3133
import org.apache.inlong.manager.common.enums.SinkType;
3234
import org.apache.inlong.manager.common.exceptions.BusinessException;
@@ -183,6 +185,8 @@ public PageInfo<? extends StreamSink> listByCondition(SinkPageRequest request) {
183185
Preconditions.checkNotNull(request.getInlongGroupId(), ErrorCodeEnum.GROUP_ID_IS_EMPTY.getMessage());
184186

185187
PageHelper.startPage(request.getPageNum(), request.getPageSize());
188+
OrderFieldEnum.checkOrderField(request);
189+
OrderTypeEnum.checkOrderType(request);
186190
List<StreamSinkEntity> entityPage = sinkMapper.selectByCondition(request);
187191
Map<SinkType, Page<StreamSinkEntity>> sinkMap = Maps.newHashMap();
188192
for (StreamSinkEntity streamSink : entityPage) {

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/source/StreamSourceServiceImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.inlong.manager.common.consts.InlongConstants;
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
30+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
31+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
3032
import org.apache.inlong.manager.common.enums.SourceStatus;
3133
import org.apache.inlong.manager.common.enums.SourceType;
3234
import org.apache.inlong.manager.common.exceptions.BusinessException;
@@ -171,6 +173,8 @@ public PageInfo<? extends StreamSource> listByCondition(SourcePageRequest reques
171173
Preconditions.checkNotNull(request.getInlongGroupId(), ErrorCodeEnum.GROUP_ID_IS_EMPTY.getMessage());
172174

173175
PageHelper.startPage(request.getPageNum(), request.getPageSize());
176+
OrderFieldEnum.checkOrderField(request);
177+
OrderTypeEnum.checkOrderType(request);
174178
List<StreamSourceEntity> entityList = sourceMapper.selectByCondition(request);
175179

176180
// Encapsulate the paging query results into the PageInfo object to obtain related paging information

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/stream/InlongStreamServiceImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.apache.inlong.manager.common.consts.InlongConstants;
2626
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2727
import org.apache.inlong.manager.common.enums.GroupStatus;
28+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
29+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
2830
import org.apache.inlong.manager.common.enums.StreamStatus;
2931
import org.apache.inlong.manager.common.exceptions.BusinessException;
3032
import org.apache.inlong.manager.pojo.sink.SinkBriefInfo;
@@ -201,6 +203,8 @@ public PageInfo<InlongStreamBriefInfo> listBrief(InlongStreamPageRequest request
201203
LOGGER.debug("begin to list inlong stream page by {}", request);
202204

203205
PageHelper.startPage(request.getPageNum(), request.getPageSize());
206+
OrderFieldEnum.checkOrderField(request);
207+
OrderTypeEnum.checkOrderType(request);
204208
Page<InlongStreamEntity> entityPage = (Page<InlongStreamEntity>) streamMapper.selectByCondition(request);
205209
List<InlongStreamBriefInfo> streamList = CommonBeanUtils.copyListProperties(entityPage,
206210
InlongStreamBriefInfo::new);

0 commit comments

Comments
 (0)