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. 22
      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")
@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")
@ResponseStatus(HttpStatus.OK)
@ -210,8 +211,9 @@ public class ProcessDefinitionController extends BaseController {
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result verifyProcessDefinitionName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name) {
Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, name);
@RequestParam(value = "name", required = true) String name,
@RequestParam(value = "code", required = false, defaultValue = "0") long processDefinitionCode) {
Map<String, Object> result = processDefinitionService.verifyProcessDefinitionName(loginUser, projectCode, name, processDefinitionCode);
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
*/
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);
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 projectCode project code
* @param name name
* @param processDefinitionCode processDefinitionCode
* @return true if process definition name not exists, otherwise false
*/
Map<String, Object> verifyProcessDefinitionName(User loginUser,
long projectCode,
String name);
String name,
long processDefinitionCode);
/**
* 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
*/
@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);
// check user access for project
Map<String, Object> result =
@ -785,9 +785,13 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
processDefinitionMapper.verifyByDefineName(project.getCode(), name.trim());
if (processDefinition == null) {
putMsg(result, Status.SUCCESS);
} else {
putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST, name.trim());
return result;
}
if (processDefinitionCode != 0 && processDefinitionCode == processDefinition.getCode()) {
putMsg(result, Status.SUCCESS);
return result;
}
putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST, name.trim());
return result;
}
@ -1287,7 +1291,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
String importProcessDefinitionName = getNewName(processDefinitionName, IMPORT_SUFFIX);
// unique check
Map<String, Object> checkResult =
verifyProcessDefinitionName(loginUser, projectCode, importProcessDefinitionName);
verifyProcessDefinitionName(loginUser, projectCode, importProcessDefinitionName, 0);
if (Status.SUCCESS.equals(checkResult.get(Constants.STATUS))) {
putMsg(result, Status.SUCCESS);
} else {

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

@ -126,9 +126,9 @@ public class ProcessDefinitionControllerTest {
long projectCode = 1L;
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));
}

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);
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE)).thenReturn(result);
Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser,
projectCode, "test_pdf");
projectCode, "test_pdf", 0);
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS));
//project check auth success, process not exist
putMsg(result, Status.SUCCESS, projectCode);
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null);
Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser,
projectCode, "test_pdf");
projectCode, "test_pdf", 0);
Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS));
//process exist
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition());
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));
}

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({
url: `/projects/${code}/process-definition/verify-name`,
url: `/projects/${projectCode}/process-definition/verify-name`,
method: 'get',
params
})

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

@ -15,7 +15,15 @@
* 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 { useI18n } from 'vue-i18n'
import {
@ -136,8 +144,9 @@ export default defineComponent({
formRef.value.validate(async (valid: any) => {
if (!valid) {
const params = {
name: formValue.value.name
}
name: formValue.value.name,
code: props.definition?.processDefinition.code
} as { name: string; code?: number }
if (
props.definition?.processDefinition.name !== formValue.value.name
) {
@ -192,11 +201,14 @@ export default defineComponent({
<NForm model={formValue.value} rules={rule} ref={formRef}>
<NFormItem label={t('project.dag.workflow_name')} path='name'>
<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 label={t('project.dag.description')} path='description'>
<NInput
allowInput={trim}
allowInput={trim}
type='textarea'
v-model:value={formValue.value.description}
class='input-description'

Loading…
Cancel
Save