Browse Source

[Fix-11616] Workflow Definition Name Change Validation Optimization. (#11617)

* Workflow Definition Name Change Validation Optimization

* [Fix][UI] Add the workflow code entry to the verify name interface.

* Update dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

Co-authored-by: caishunfeng <caishunfeng2021@gmail.com>

* processDefinitionCode param name change

Co-authored-by: Amy <amywang0104@163.com>
Co-authored-by: caishunfeng <caishunfeng2021@gmail.com>
3.1.0-release
JiPeng Wang 2 years ago committed by GitHub
parent
commit
cf3b4424d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
  2. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
  3. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
  4. 12
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  5. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java
  6. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  7. 7
      dolphinscheduler-ui/src/service/modules/process-definition/index.ts
  8. 20
      dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java

@ -202,7 +202,8 @@ public class ProcessDefinitionController extends BaseController {
*/ */
@ApiOperation(value = "verify-name", notes = "VERIFY_PROCESS_DEFINITION_NAME_NOTES") @ApiOperation(value = "verify-name", notes = "VERIFY_PROCESS_DEFINITION_NAME_NOTES")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, dataTypeClass = String.class) @ApiImplicitParam(name = "name", value = "PROCESS_DEFINITION_NAME", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "code", value = "PROCESS_DEFINITION_CODE", required = false, dataTypeClass = Long.class),
}) })
@GetMapping(value = "/verify-name") @GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@ -210,8 +211,9 @@ public class ProcessDefinitionController extends BaseController {
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name) { @RequestParam(value = "name", required = true) String name,
Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, name); @RequestParam(value = "code", required = false, defaultValue = "0") long processDefinitionCode) {
Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, name, processDefinitionCode);
return returnDataList(result); return returnDataList(result);
} }

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java

@ -266,7 +266,7 @@ public class PythonGateway {
* @param processDefinitionName process definition name * @param processDefinitionName process definition name
*/ */
private ProcessDefinition getProcessDefinition(User user, long projectCode, String processDefinitionName) { private ProcessDefinition getProcessDefinition(User user, long projectCode, String processDefinitionName) {
Map<String, Object> verifyProcessDefinitionExists = processDefinitionService.verifyProcessDefinitionName(user, projectCode, processDefinitionName); Map<String, Object> verifyProcessDefinitionExists = processDefinitionService.verifyProcessDefinitionName(user, projectCode, processDefinitionName, 0);
Status verifyStatus = (Status) verifyProcessDefinitionExists.get(Constants.STATUS); Status verifyStatus = (Status) verifyProcessDefinitionExists.get(Constants.STATUS);
ProcessDefinition processDefinition = null; ProcessDefinition processDefinition = null;

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

@ -194,11 +194,13 @@ public interface ProcessDefinitionService {
* @param loginUser login user * @param loginUser login user
* @param projectCode project code * @param projectCode project code
* @param name name * @param name name
* @param processDefinitionCode processDefinitionCode
* @return true if process definition name not exists, otherwise false * @return true if process definition name not exists, otherwise false
*/ */
Map<String, Object> verifyProcessDefinitionName(User loginUser, Map<String, Object> verifyProcessDefinitionName(User loginUser,
long projectCode, long projectCode,
String name); String name,
long processDefinitionCode);
/** /**
* delete process definition by code * delete process definition by code

12
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -773,7 +773,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
* @return true if process definition name not exists, otherwise false * @return true if process definition name not exists, otherwise false
*/ */
@Override @Override
public Map<String, Object> verifyProcessDefinitionName(User loginUser, long projectCode, String name) { public Map<String, Object> verifyProcessDefinitionName(User loginUser, long projectCode, String name, long processDefinitionCode) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check user access for project // check user access for project
Map<String, Object> result = Map<String, Object> result =
@ -785,9 +785,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinitionMapper.verifyByDefineName(project.getCode(), name.trim()); processDefinitionMapper.verifyByDefineName(project.getCode(), name.trim());
if (processDefinition == null) { if (processDefinition == null) {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} else { return result;
putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST, name.trim());
} }
if (processDefinitionCode != 0 && processDefinitionCode == processDefinition.getCode()) {
putMsg(result, Status.SUCCESS);
return result;
}
putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST, name.trim());
return result; return result;
} }
@ -1287,7 +1291,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
String importProcessDefinitionName = getNewName(processDefinitionName, IMPORT_SUFFIX); String importProcessDefinitionName = getNewName(processDefinitionName, IMPORT_SUFFIX);
// unique check // unique check
Map<String, Object> checkResult = Map<String, Object> checkResult =
verifyProcessDefinitionName(loginUser, projectCode, importProcessDefinitionName); verifyProcessDefinitionName(loginUser, projectCode, importProcessDefinitionName, 0);
if (Status.SUCCESS.equals(checkResult.get(Constants.STATUS))) { if (Status.SUCCESS.equals(checkResult.get(Constants.STATUS))) {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} else { } else {

4
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionControllerTest.java

@ -126,9 +126,9 @@ public class ProcessDefinitionControllerTest {
long projectCode = 1L; long projectCode = 1L;
String name = "dag_test"; String name = "dag_test";
Mockito.when(processDefinitionService.verifyProcessDefinitionName(user, projectCode, name)).thenReturn(result); Mockito.when(processDefinitionService.verifyProcessDefinitionName(user, projectCode, name, 0)).thenReturn(result);
Result response = processDefinitionController.verifyProcessDefinitionName(user, projectCode, name); Result response = processDefinitionController.verifyProcessDefinitionName(user, projectCode, name, 0);
Assert.assertTrue(response.isStatus(Status.PROCESS_DEFINITION_NAME_EXIST)); Assert.assertTrue(response.isStatus(Status.PROCESS_DEFINITION_NAME_EXIST));
} }

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java

@ -508,20 +508,20 @@ public class ProcessDefinitionServiceTest {
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); putMsg(result, Status.PROJECT_NOT_FOUND, projectCode);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE)).thenReturn(result); Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE)).thenReturn(result);
Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser, Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser,
projectCode, "test_pdf"); projectCode, "test_pdf", 0);
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS));
//project check auth success, process not exist //project check auth success, process not exist
putMsg(result, Status.SUCCESS, projectCode); putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null);
Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser,
projectCode, "test_pdf"); projectCode, "test_pdf", 0);
Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS));
//process exist //process exist
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition()); Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition());
Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser,
projectCode, "test_pdf"); projectCode, "test_pdf", 0);
Assert.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST, processExistRes.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST, processExistRes.get(Constants.STATUS));
} }

7
dolphinscheduler-ui/src/service/modules/process-definition/index.ts

@ -137,9 +137,12 @@ export function querySimpleList(code: number): any {
}) })
} }
export function verifyName(params: NameReq, code: number): any { export function verifyName(
params: { name: string; workflowCode?: number },
projectCode: number
): any {
return axios({ return axios({
url: `/projects/${code}/process-definition/verify-name`, url: `/projects/${projectCode}/process-definition/verify-name`,
method: 'get', method: 'get',
params params
}) })

20
dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag-save-modal.tsx

@ -15,7 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
import { defineComponent, PropType, ref, computed, onMounted, watch, getCurrentInstance } from 'vue' import {
defineComponent,
PropType,
ref,
computed,
onMounted,
watch,
getCurrentInstance
} from 'vue'
import Modal from '@/components/modal' import Modal from '@/components/modal'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { import {
@ -136,8 +144,9 @@ export default defineComponent({
formRef.value.validate(async (valid: any) => { formRef.value.validate(async (valid: any) => {
if (!valid) { if (!valid) {
const params = { const params = {
name: formValue.value.name name: formValue.value.name,
} code: props.definition?.processDefinition.code
} as { name: string; code?: number }
if ( if (
props.definition?.processDefinition.name !== formValue.value.name props.definition?.processDefinition.name !== formValue.value.name
) { ) {
@ -192,7 +201,10 @@ export default defineComponent({
<NForm model={formValue.value} rules={rule} ref={formRef}> <NForm model={formValue.value} rules={rule} ref={formRef}>
<NFormItem label={t('project.dag.workflow_name')} path='name'> <NFormItem label={t('project.dag.workflow_name')} path='name'>
<NInput <NInput
allowInput={trim} v-model:value={formValue.value.name} class='input-name' /> allowInput={trim}
v-model:value={formValue.value.name}
class='input-name'
/>
</NFormItem> </NFormItem>
<NFormItem label={t('project.dag.description')} path='description'> <NFormItem label={t('project.dag.description')} path='description'>
<NInput <NInput

Loading…
Cancel
Save