Browse Source

Fix alert plugin instance filter (#7172)

alert plugin could not filter by given
pattern, cause api server do not handle
parameter searchVal, This patch add parameter
`searchVal` for alert plugin.
2.0.7-release
Jiajie Zhong 3 years ago committed by GitHub
parent
commit
623d154a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java
  2. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java
  3. 18
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java
  4. 10
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.java
  5. 7
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml

7
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java

@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService; import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Map; import java.util.Map;
@ -213,12 +214,14 @@ public class AlertPluginInstanceController extends BaseController {
* paging query alert plugin instance group list * paging query alert plugin instance group list
* *
* @param loginUser login user * @param loginUser login user
* @param searchVal search value
* @param pageNo page number * @param pageNo page number
* @param pageSize page size * @param pageSize page size
* @return alert plugin instance list page * @return alert plugin instance list page
*/ */
@ApiOperation(value = "queryAlertPluginInstanceListPaging", notes = "QUERY_ALERT_PLUGIN_INSTANCE_LIST_PAGING_NOTES") @ApiOperation(value = "queryAlertPluginInstanceListPaging", notes = "QUERY_ALERT_PLUGIN_INSTANCE_LIST_PAGING_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"), @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20") @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "20")
}) })
@ -227,13 +230,15 @@ public class AlertPluginInstanceController extends BaseController {
@ApiException(LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR) @ApiException(LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo, @RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam("pageSize") Integer pageSize) {
Result result = checkPageParams(pageNo, pageSize); Result result = checkPageParams(pageNo, pageSize);
if (!result.checkResult()) { if (!result.checkResult()) {
return result; return result;
} }
return alertPluginInstanceService.queryPluginPage(pageNo, pageSize); searchVal = ParameterUtils.handleEscapes(searchVal);
return alertPluginInstanceService.listPaging(loginUser, searchVal, pageNo, pageSize);
} }
} }

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AlertPluginInstanceService.java

@ -82,9 +82,11 @@ public interface AlertPluginInstanceService {
/** /**
* queryPluginPage * queryPluginPage
* @param pageIndex page index * @param loginUser login user
* @param searchVal search value
* @param pageNo page index
* @param pageSize page size * @param pageSize page size
* @return plugins * @return plugins
*/ */
Result queryPluginPage(int pageIndex, int pageSize); Result listPaging(User loginUser, String searchVal, int pageNo, int pageSize);
} }

18
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertPluginInstanceServiceImpl.java

@ -188,14 +188,20 @@ public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements A
} }
@Override @Override
public Result queryPluginPage(int pageIndex, int pageSize) { public Result listPaging(User loginUser, String searchVal, int pageNo, int pageSize) {
IPage<AlertPluginInstance> pluginInstanceIPage = new Page<>(pageIndex, pageSize);
pluginInstanceIPage = alertPluginInstanceMapper.selectPage(pluginInstanceIPage, null);
PageInfo<AlertPluginInstanceVO> pageInfo = new PageInfo<>(pageIndex, pageSize);
pageInfo.setTotal((int) pluginInstanceIPage.getTotal());
pageInfo.setTotalList(buildPluginInstanceVOList(pluginInstanceIPage.getRecords()));
Result result = new Result(); Result result = new Result();
if (!isAdmin(loginUser)) {
putMsg(result,Status.USER_NO_OPERATION_PERM);
return result;
}
Page<AlertPluginInstance> page = new Page<>(pageNo, pageSize);
IPage<AlertPluginInstance> alertPluginInstanceIPage = alertPluginInstanceMapper.queryByInstanceNamePage(page, searchVal);
PageInfo<AlertPluginInstance> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) alertPluginInstanceIPage.getTotal());
pageInfo.setTotalList(alertPluginInstanceIPage.getRecords());
result.setData(pageInfo); result.setData(pageInfo);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;

10
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.java

@ -24,6 +24,8 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
public interface AlertPluginInstanceMapper extends BaseMapper<AlertPluginInstance> { public interface AlertPluginInstanceMapper extends BaseMapper<AlertPluginInstance> {
@ -42,7 +44,13 @@ public interface AlertPluginInstanceMapper extends BaseMapper<AlertPluginInstanc
*/ */
List<AlertPluginInstance> queryByIds(@Param("ids") List<Integer> ids); List<AlertPluginInstance> queryByIds(@Param("ids") List<Integer> ids);
List<AlertPluginInstance> queryByInstanceName(@Param("instanceName")String instanceName); /**
* Query alert plugin instance by given name
* @param page page
* @param instanceName Alert plugin name
* @return alertPluginInstance Ipage
*/
IPage<AlertPluginInstance> queryByInstanceNamePage(Page page, @Param("instanceName") String instanceName);
/** /**
* *

7
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapper.xml

@ -36,11 +36,14 @@
</foreach> </foreach>
</select> </select>
<select id="queryByInstanceName" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance"> <select id="queryByInstanceNamePage" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select select
* *
from t_ds_alert_plugin_instance from t_ds_alert_plugin_instance
where instance_name = #{instanceName} where 1 = 1
<if test="instanceName != null and instanceName != ''">
and instance_name like concat('%', #{instanceName}, '%')
</if>
</select> </select>
<select id="existInstanceName" resultType="java.lang.Boolean"> <select id="existInstanceName" resultType="java.lang.Boolean">

Loading…
Cancel
Save