Browse Source

Fix alert plugin instance filter (#7172) (#7210)

* 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.

fix: #7209

* Add test

* Recover AlertPluginInstanceVO
3.0.0/version-upgrade
Jiajie Zhong 3 years ago committed by GitHub
parent
commit
04805818c2
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
  6. 96
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java

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.utils.Result;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Map;
@ -213,12 +214,14 @@ public class AlertPluginInstanceController extends BaseController {
* paging query alert plugin instance group list
*
* @param loginUser login user
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
* @return alert plugin instance list page
*/
@ApiOperation(value = "queryAlertPluginInstanceListPaging", notes = "QUERY_ALERT_PLUGIN_INSTANCE_LIST_PAGING_NOTES")
@ApiImplicitParams({
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"),
@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)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result listPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
Result result = checkPageParams(pageNo, pageSize);
if (!result.checkResult()) {
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
* @param pageIndex page index
* @param loginUser login user
* @param searchVal search value
* @param pageNo page index
* @param pageSize page size
* @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
public Result queryPluginPage(int pageIndex, int pageSize) {
IPage<AlertPluginInstance> pluginInstanceIPage = new Page<>(pageIndex, pageSize);
pluginInstanceIPage = alertPluginInstanceMapper.selectPage(pluginInstanceIPage, null);
public Result listPaging(User loginUser, String searchVal, int pageNo, int pageSize) {
PageInfo<AlertPluginInstanceVO> pageInfo = new PageInfo<>(pageIndex, pageSize);
pageInfo.setTotal((int) pluginInstanceIPage.getTotal());
pageInfo.setTotalList(buildPluginInstanceVOList(pluginInstanceIPage.getRecords()));
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<AlertPluginInstanceVO> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) alertPluginInstanceIPage.getTotal());
pageInfo.setTotalList(buildPluginInstanceVOList(alertPluginInstanceIPage.getRecords()));
result.setData(pageInfo);
putMsg(result, Status.SUCCESS);
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 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> {
@ -42,7 +44,13 @@ public interface AlertPluginInstanceMapper extends BaseMapper<AlertPluginInstanc
*/
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>
</select>
<select id="queryByInstanceName" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
<select id="queryByInstanceNamePage" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select
*
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 id="existInstanceName" resultType="java.lang.Boolean">

96
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertPluginInstanceMapperTest.java

@ -17,9 +17,7 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.PluginDefine;
@ -29,6 +27,9 @@ import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/**
* AlertPluginInstanceMapper mapper test
*/
@ -40,73 +41,76 @@ public class AlertPluginInstanceMapperTest extends BaseDaoTest {
@Autowired
private PluginDefineMapper pluginDefineMapper;
@Autowired
private AlertGroupMapper alertGroupMapper;
/**
* Test function queryAllAlertPluginInstanceList behavior with different size.
*/
@Test
public void testQueryAllAlertPluginInstanceList() {
createAlertPluginInstance();
List<AlertPluginInstance> alertPluginInstanceList = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
Assert.assertTrue(alertPluginInstanceList.size() > 0);
}
List<AlertPluginInstance> withoutSingleOne = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
Assert.assertEquals(0, withoutSingleOne.size());
@Test
public void testQueryByAlertGroupId() {
createAlertPluginInstance();
List<AlertGroup> testAlertGroupList = alertGroupMapper.queryByGroupName("test_group_01");
Assert.assertNotNull(testAlertGroupList);
Assert.assertTrue(testAlertGroupList.size() > 0);
AlertGroup alertGroup = testAlertGroupList.get(0);
createAlertPluginInstance("test_instance_1");
List<AlertPluginInstance> withExactlyOne = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
Assert.assertEquals(1, withExactlyOne.size());
createAlertPluginInstance("test_instance_2");
List<AlertPluginInstance> withExactlyTwo = alertPluginInstanceMapper.queryAllAlertPluginInstanceList();
Assert.assertEquals(2, withExactlyTwo.size());
}
/**
* Test function existInstanceName with init status and single record status.
*/
@Test
public void testExistInstanceName() {
String instanceName = "test_instance";
Assert.assertNull(alertPluginInstanceMapper.existInstanceName(instanceName));
createAlertPluginInstance();
createAlertPluginInstance(instanceName);
Assert.assertTrue(alertPluginInstanceMapper.existInstanceName(instanceName));
}
/**
* insert
*
* @return AlertPluginInstance
* Test function queryByInstanceNamePage returning with different search variables.
*/
private AlertPluginInstance createAlertPluginInstance() {
@Test
public void testQueryByInstanceNamePage() {
createAlertPluginInstance("test_with_pattern_instance");
createAlertPluginInstance("test_no_instance");
PluginDefine pluginDefine = createPluginDefine();
AlertGroup alertGroup = createAlertGroup("test_group_01");
AlertPluginInstance alertPluginInstance = new AlertPluginInstance(pluginDefine.getId(), "", "test_instance");
alertPluginInstanceMapper.insert(alertPluginInstance);
return alertPluginInstance;
Page<AlertPluginInstance> page = new Page<>(1, 10);
IPage<AlertPluginInstance> matchTwoRecord = alertPluginInstanceMapper.queryByInstanceNamePage(page, "test");
Assert.assertEquals(2, matchTwoRecord.getTotal());
IPage<AlertPluginInstance> matchOneRecord = alertPluginInstanceMapper.queryByInstanceNamePage(page, "pattern");
Assert.assertEquals(1, matchOneRecord.getTotal());
}
/**
* insert
*
* @return PluginDefine
* Create alert plugin instance according to given alter plugin name.
*/
private PluginDefine createPluginDefine() {
PluginDefine pluginDefine = new PluginDefine("test plugin", "alert", "");
pluginDefineMapper.insert(pluginDefine);
return pluginDefine;
private void createAlertPluginInstance(String alterPluginInsName) {
PluginDefine pluginDefine = makeSurePluginDefineExists();
AlertPluginInstance alertPluginInstance = new AlertPluginInstance(pluginDefine.getId(), "", alterPluginInsName);
alertPluginInstanceMapper.insert(alertPluginInstance);
}
/**
* insert
* Make sure plugin define exists.
* <p>
* Create a new plugin define if not exists, else just return exists plugin define
*
* @return AlertGroup
* @return PluginDefine
*/
private AlertGroup createAlertGroup(String groupName) {
AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName(groupName);
alertGroup.setDescription("alert group 1");
alertGroup.setCreateTime(DateUtils.getCurrentDate());
alertGroup.setUpdateTime(DateUtils.getCurrentDate());
alertGroupMapper.insert(alertGroup);
return alertGroup;
private PluginDefine makeSurePluginDefineExists() {
String pluginName = "test plugin";
String pluginType = "alert";
PluginDefine pluginDefine = pluginDefineMapper.queryByNameAndType(pluginName, pluginType);
if (pluginDefine == null) {
PluginDefine newPluginDefine = new PluginDefine(pluginName, pluginType, "");
pluginDefineMapper.insert(newPluginDefine);
return newPluginDefine;
} else {
return pluginDefine;
}
}
}

Loading…
Cancel
Save