Rick Cheng
1 year ago
committed by
GitHub
17 changed files with 520 additions and 20 deletions
@ -0,0 +1,23 @@
|
||||
# Project-level Parameter |
||||
|
||||
## Scope |
||||
|
||||
Project-level parameters are valid for all task nodes under the entire project. |
||||
|
||||
## Usage |
||||
|
||||
### Define project-level parameters |
||||
|
||||
On the project page, click Project Parameters and Create Parameters, and fill in the parameter name and parameter value. As shown below: |
||||
|
||||
![project-parameter01](../../../../img/new_ui/dev/parameter/project_parameter01.png) |
||||
|
||||
### Use project-level parameters |
||||
|
||||
Take the shell task as an example, enter `echo ${param}` in the script content, where `param` is the project-level parameter created in the previous step. |
||||
|
||||
![project-parameter02](../../../../img/new_ui/dev/parameter/project_parameter02.png) |
||||
|
||||
Run the shell task. On the task instance page, you can view the task log to verify whether the parameters are valid. |
||||
|
||||
![project-parameter03](../../../../img/new_ui/dev/parameter/project_parameter03.png) |
@ -0,0 +1,23 @@
|
||||
# 项目级别参数 |
||||
|
||||
## 作用域 |
||||
|
||||
项目级别参数是针对整个项目下的所有任务节点都有效的参数。 |
||||
|
||||
## 使用方式 |
||||
|
||||
### 定义项目级别参数 |
||||
|
||||
在项目管理页面,点击项目级别参数,点击创建项目级别参数,填写参数名称和参数值。如下图所示: |
||||
|
||||
![project-parameter01](../../../../img/new_ui/dev/parameter/project_parameter01.png) |
||||
|
||||
### 使用项目级别参数 |
||||
|
||||
以shell任务为例,在脚本内容中输入`echo ${param}`,其中`param`为上一步创建的项目级别参数。 |
||||
|
||||
![project-parameter02](../../../../img/new_ui/dev/parameter/project_parameter02.png) |
||||
|
||||
运行该shell任务,在任务实例页面,可以查看任务日志,验证参数是否有效。 |
||||
|
||||
![project-parameter03](../../../../img/new_ui/dev/parameter/project_parameter03.png) |
After Width: | Height: | Size: 3.1 MiB |
After Width: | Height: | Size: 3.3 MiB |
After Width: | Height: | Size: 3.7 MiB |
@ -0,0 +1,121 @@
|
||||
/* |
||||
* 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.dolphinscheduler.api.controller; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status; |
||||
import org.apache.dolphinscheduler.api.service.impl.ProjectParameterServiceImpl; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.common.enums.UserType; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.mockito.junit.jupiter.MockitoSettings; |
||||
import org.mockito.quality.Strictness; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
@MockitoSettings(strictness = Strictness.LENIENT) |
||||
public class ProjectParameterControllerTest { |
||||
|
||||
@InjectMocks |
||||
private ProjectParameterController projectParameterController; |
||||
|
||||
@Mock |
||||
private ProjectParameterServiceImpl projectParameterService; |
||||
|
||||
@Test |
||||
public void testCreateProjectParameter() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
Mockito.when(projectParameterService.createProjectParameter(Mockito.any(), Mockito.anyLong(), Mockito.any(), |
||||
Mockito.any())).thenReturn(getSuccessResult()); |
||||
Result result = projectParameterController.createProjectParameter(loginUser, 1, "key", "value"); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdateProjectParameter() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
Mockito.when(projectParameterService.updateProjectParameter(Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), |
||||
Mockito.any(), Mockito.any())).thenReturn(getSuccessResult()); |
||||
Result result = projectParameterController.updateProjectParameter(loginUser, 1, 1L, "key", "value"); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testDeleteProjectParametersByCode() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
Mockito.when(projectParameterService.deleteProjectParametersByCode(Mockito.any(), Mockito.anyLong(), |
||||
Mockito.anyLong())).thenReturn(getSuccessResult()); |
||||
Result result = projectParameterController.deleteProjectParametersByCode(loginUser, 1, 1); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testBatchDeleteProjectParametersByCodes() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
Mockito.when(projectParameterService.batchDeleteProjectParametersByCodes(Mockito.any(), Mockito.anyLong(), |
||||
Mockito.any())).thenReturn(getSuccessResult()); |
||||
Result result = projectParameterController.batchDeleteProjectParametersByCodes(loginUser, 1, "1"); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryProjectParameterListPaging() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
Mockito.when(projectParameterService.queryProjectParameterListPaging(Mockito.any(), Mockito.anyLong(), |
||||
Mockito.anyInt(), Mockito.anyInt(), Mockito.any())).thenReturn(getSuccessResult()); |
||||
Result result = projectParameterController.queryProjectParameterListPaging(loginUser, 1, "1", 1, 10); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryProjectParameterByCode() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
Mockito.when(projectParameterService.queryProjectParameterByCode(Mockito.any(), Mockito.anyLong(), |
||||
Mockito.anyLong())).thenReturn(getSuccessResult()); |
||||
Result result = projectParameterController.queryProjectParameterByCode(loginUser, 1, 1); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
private User getGeneralUser() { |
||||
User loginUser = new User(); |
||||
loginUser.setUserType(UserType.GENERAL_USER); |
||||
loginUser.setUserName("userName"); |
||||
loginUser.setId(1); |
||||
return loginUser; |
||||
} |
||||
|
||||
private Result getSuccessResult() { |
||||
Result result = new Result(); |
||||
result.setCode(Status.SUCCESS.getCode()); |
||||
result.setMsg(Status.SUCCESS.getMsg()); |
||||
return result; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,166 @@
|
||||
/* |
||||
* 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.dolphinscheduler.api.service; |
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status; |
||||
import org.apache.dolphinscheduler.api.service.impl.ProjectParameterServiceImpl; |
||||
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
||||
import org.apache.dolphinscheduler.api.utils.Result; |
||||
import org.apache.dolphinscheduler.common.enums.UserType; |
||||
import org.apache.dolphinscheduler.dao.entity.Project; |
||||
import org.apache.dolphinscheduler.dao.entity.ProjectParameter; |
||||
import org.apache.dolphinscheduler.dao.entity.User; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
||||
import org.apache.dolphinscheduler.dao.mapper.ProjectParameterMapper; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.mockito.junit.jupiter.MockitoSettings; |
||||
import org.mockito.quality.Strictness; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
@MockitoSettings(strictness = Strictness.LENIENT) |
||||
public class ProjectParameterServiceTest { |
||||
|
||||
@InjectMocks |
||||
private ProjectParameterServiceImpl projectParameterService; |
||||
|
||||
@Mock |
||||
private ProjectMapper projectMapper; |
||||
|
||||
@Mock |
||||
private ProjectParameterMapper projectParameterMapper; |
||||
|
||||
@Mock |
||||
private ProjectServiceImpl projectService; |
||||
|
||||
protected final static long projectCode = 1L; |
||||
|
||||
@Test |
||||
public void testCreateProjectParameter() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
// PROJECT_PARAMETER_ALREADY_EXISTS
|
||||
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
||||
Mockito.when(projectParameterMapper.selectOne(Mockito.any())).thenReturn(getProjectParameter()); |
||||
Mockito.when(projectService.hasProjectAndWritePerm(Mockito.any(), Mockito.any(), Mockito.any(Result.class))) |
||||
.thenReturn(true); |
||||
Result result = projectParameterService.createProjectParameter(loginUser, projectCode, "key", "value"); |
||||
Assertions.assertEquals(Status.PROJECT_PARAMETER_ALREADY_EXISTS.getCode(), result.getCode()); |
||||
|
||||
// SUCCESS
|
||||
Mockito.when(projectParameterMapper.selectOne(Mockito.any())).thenReturn(null); |
||||
Mockito.when(projectParameterMapper.insert(Mockito.any())).thenReturn(1); |
||||
result = projectParameterService.createProjectParameter(loginUser, projectCode, "key1", "value"); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdateProjectParameter() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
// PROJECT_PARAMETER_NOT_EXISTS
|
||||
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
||||
Mockito.when(projectService.hasProjectAndWritePerm(Mockito.any(), Mockito.any(), Mockito.any(Result.class))) |
||||
.thenReturn(true); |
||||
Mockito.when(projectParameterMapper.queryByCode(Mockito.anyLong())).thenReturn(null); |
||||
Result result = projectParameterService.updateProjectParameter(loginUser, projectCode, 1, "key", "value"); |
||||
Assertions.assertEquals(Status.PROJECT_PARAMETER_NOT_EXISTS.getCode(), result.getCode()); |
||||
|
||||
// PROJECT_PARAMETER_ALREADY_EXISTS
|
||||
Mockito.when(projectParameterMapper.queryByCode(Mockito.anyLong())).thenReturn(getProjectParameter()); |
||||
Mockito.when(projectParameterMapper.selectOne(Mockito.any())).thenReturn(getProjectParameter()); |
||||
result = projectParameterService.updateProjectParameter(loginUser, projectCode, 1, "key", "value"); |
||||
Assertions.assertEquals(Status.PROJECT_PARAMETER_ALREADY_EXISTS.getCode(), result.getCode()); |
||||
|
||||
// SUCCESS
|
||||
Mockito.when(projectParameterMapper.selectOne(Mockito.any())).thenReturn(null); |
||||
Mockito.when(projectParameterMapper.updateById(Mockito.any())).thenReturn(1); |
||||
result = projectParameterService.updateProjectParameter(loginUser, projectCode, 1, "key1", "value"); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testDeleteProjectParametersByCode() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
// PROJECT_PARAMETER_NOT_EXISTS
|
||||
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
||||
Mockito.when(projectService.hasProjectAndWritePerm(Mockito.any(), Mockito.any(), Mockito.any(Result.class))) |
||||
.thenReturn(true); |
||||
Mockito.when(projectParameterMapper.queryByCode(Mockito.anyLong())).thenReturn(null); |
||||
Result result = projectParameterService.deleteProjectParametersByCode(loginUser, projectCode, 1); |
||||
Assertions.assertEquals(Status.PROJECT_PARAMETER_NOT_EXISTS.getCode(), result.getCode()); |
||||
|
||||
// SUCCESS
|
||||
Mockito.when(projectParameterMapper.queryByCode(Mockito.anyLong())).thenReturn(getProjectParameter()); |
||||
Mockito.when(projectParameterMapper.deleteById(Mockito.anyInt())).thenReturn(1); |
||||
result = projectParameterService.deleteProjectParametersByCode(loginUser, projectCode, 1); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryProjectParameterByCode() { |
||||
User loginUser = getGeneralUser(); |
||||
|
||||
// PROJECT_PARAMETER_NOT_EXISTS
|
||||
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
||||
Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), Mockito.any(Result.class), |
||||
Mockito.any())).thenReturn(true); |
||||
Mockito.when(projectParameterMapper.queryByCode(Mockito.anyLong())).thenReturn(null); |
||||
Result result = projectParameterService.queryProjectParameterByCode(loginUser, projectCode, 1); |
||||
Assertions.assertEquals(Status.PROJECT_PARAMETER_NOT_EXISTS.getCode(), result.getCode()); |
||||
|
||||
// SUCCESS
|
||||
Mockito.when(projectParameterMapper.queryByCode(Mockito.anyLong())).thenReturn(getProjectParameter()); |
||||
result = projectParameterService.queryProjectParameterByCode(loginUser, projectCode, 1); |
||||
Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode()); |
||||
} |
||||
|
||||
private User getGeneralUser() { |
||||
User loginUser = new User(); |
||||
loginUser.setUserType(UserType.GENERAL_USER); |
||||
loginUser.setUserName("userName"); |
||||
loginUser.setId(1); |
||||
return loginUser; |
||||
} |
||||
|
||||
private Project getProject(long projectCode) { |
||||
Project project = new Project(); |
||||
project.setCode(projectCode); |
||||
project.setId(1); |
||||
project.setName("test"); |
||||
project.setUserId(1); |
||||
return project; |
||||
} |
||||
|
||||
private ProjectParameter getProjectParameter() { |
||||
ProjectParameter projectParameter = new ProjectParameter(); |
||||
projectParameter.setId(1); |
||||
projectParameter.setCode(1); |
||||
projectParameter.setProjectCode(1); |
||||
projectParameter.setParamName("key"); |
||||
projectParameter.setParamValue("value"); |
||||
return projectParameter; |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
/* |
||||
* 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.dolphinscheduler.dao.mapper; |
||||
|
||||
import org.apache.dolphinscheduler.dao.BaseDaoTest; |
||||
import org.apache.dolphinscheduler.dao.entity.ProjectParameter; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
|
||||
public class ProjectParameterMapperTest extends BaseDaoTest { |
||||
|
||||
@Autowired |
||||
private ProjectParameterMapper projectParameterMapper; |
||||
|
||||
private ProjectParameter insertOne(long code, String name, long projectCode) { |
||||
ProjectParameter projectParameter = new ProjectParameter(); |
||||
projectParameter.setCode(code); |
||||
projectParameter.setParamName(name); |
||||
projectParameter.setProjectCode(projectCode); |
||||
projectParameter.setParamValue("value"); |
||||
projectParameter.setCreateTime(new Date()); |
||||
projectParameter.setUpdateTime(new Date()); |
||||
projectParameter.setUserId(1); |
||||
projectParameterMapper.insert(projectParameter); |
||||
return projectParameter; |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdate() { |
||||
ProjectParameter projectParameter = insertOne(1, "name", 1); |
||||
projectParameter.setUpdateTime(new Date()); |
||||
|
||||
int update = projectParameterMapper.updateById(projectParameter); |
||||
Assertions.assertEquals(1, update); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryByCode() { |
||||
ProjectParameter projectParameter = insertOne(1, "name", 1); |
||||
ProjectParameter res = projectParameterMapper.queryByCode(projectParameter.getCode()); |
||||
Assertions.assertEquals(projectParameter.getCode(), res.getCode()); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryByCodes() { |
||||
insertOne(1, "name1", 1); |
||||
insertOne(2, "name2", 1); |
||||
|
||||
List<ProjectParameter> res = projectParameterMapper.queryByCodes(Arrays.asList(1L, 2L)); |
||||
Assertions.assertEquals(2, res.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryByProjectCode() { |
||||
insertOne(1, "name1", 1); |
||||
insertOne(2, "name2", 2); |
||||
|
||||
List<ProjectParameter> res = projectParameterMapper.queryByProjectCode(1); |
||||
Assertions.assertEquals(1, res.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryProjectParameterListPaging() { |
||||
insertOne(1, "name1", 1); |
||||
insertOne(2, "name2", 2); |
||||
|
||||
Page<ProjectParameter> page = new Page(1, 3); |
||||
IPage<ProjectParameter> res = projectParameterMapper.queryProjectParameterListPaging(page, 1, null, null); |
||||
Assertions.assertEquals(1, res.getRecords().size()); |
||||
} |
||||
} |
Loading…
Reference in new issue