This commit is contained in:
parent
9badb2d2fb
commit
8123bc4464
|
|
@ -18,7 +18,9 @@
|
|||
package org.apache.dolphinscheduler.api.service.impl;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.CMD_PARAM_SUB_PROCESS_DEFINE_CODE;
|
||||
import static org.apache.dolphinscheduler.common.Constants.COPY_SUFFIX;
|
||||
import static org.apache.dolphinscheduler.common.Constants.DEFAULT_WORKER_GROUP;
|
||||
import static org.apache.dolphinscheduler.common.Constants.IMPORT_SUFFIX;
|
||||
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.COMPLEX_TASK_TYPES;
|
||||
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.TASK_TYPE_SQL;
|
||||
|
||||
|
|
@ -927,7 +929,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|||
if (index > 0) {
|
||||
processDefinitionName = processDefinitionName.substring(0, index);
|
||||
}
|
||||
processDefinitionName = processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp();
|
||||
processDefinitionName = getNewName(processDefinitionName, IMPORT_SUFFIX);
|
||||
|
||||
ProcessDefinition processDefinition;
|
||||
List<TaskDefinitionLog> taskDefinitionList = new ArrayList<>();
|
||||
|
|
@ -1123,8 +1125,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|||
|
||||
// generate import processDefinitionName
|
||||
String processDefinitionName = recursionProcessDefinitionName(projectCode, processDefinition.getName(), 1);
|
||||
String importProcessDefinitionName = processDefinitionName + "_import_" + DateUtils.getCurrentTimeStamp();
|
||||
|
||||
String importProcessDefinitionName = getNewName(processDefinitionName, IMPORT_SUFFIX);
|
||||
//unique check
|
||||
Map<String, Object> checkResult = verifyProcessDefinitionName(loginUser, projectCode, importProcessDefinitionName);
|
||||
if (Status.SUCCESS.equals(checkResult.get(Constants.STATUS))) {
|
||||
|
|
@ -1751,7 +1752,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|||
}
|
||||
processDefinition.setId(0);
|
||||
processDefinition.setUserId(loginUser.getId());
|
||||
processDefinition.setName(processDefinition.getName() + "_copy_" + DateUtils.getCurrentTimeStamp());
|
||||
processDefinition.setName(getNewName(processDefinition.getName(), COPY_SUFFIX));
|
||||
final Date date = new Date();
|
||||
processDefinition.setCreateTime(date);
|
||||
processDefinition.setUpdateTime(date);
|
||||
|
|
@ -1785,6 +1786,28 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get new Task name or Process name when copy or import operate
|
||||
* @param originalName Task or Process original name
|
||||
* @param suffix "_copy_" or "_import_"
|
||||
* @return
|
||||
*/
|
||||
public String getNewName(String originalName, String suffix) {
|
||||
StringBuilder newName = new StringBuilder();
|
||||
String regex = String.format(".*%s\\d{17}$", suffix);
|
||||
if (originalName.matches(regex)) {
|
||||
//replace timestamp of originalName
|
||||
return newName.append(originalName, 0, originalName.lastIndexOf(suffix))
|
||||
.append(suffix)
|
||||
.append(DateUtils.getCurrentTimeStamp())
|
||||
.toString();
|
||||
}
|
||||
return newName.append(originalName)
|
||||
.append(suffix)
|
||||
.append(DateUtils.getCurrentTimeStamp())
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* switch the defined process definition version
|
||||
*
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.dolphinscheduler.common.enums.ReleaseState;
|
|||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
import org.apache.dolphinscheduler.common.graph.DAG;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.DagData;
|
||||
import org.apache.dolphinscheduler.dao.entity.DataSource;
|
||||
|
|
@ -714,6 +715,19 @@ public class ProcessDefinitionServiceTest {
|
|||
Assert.assertEquals(result.get(Constants.STATUS), Status.SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNewProcessName() {
|
||||
String processName1 = "test_copy_" + DateUtils.getCurrentTimeStamp();
|
||||
final String newName1 = processDefinitionService.getNewName(processName1, Constants.COPY_SUFFIX);
|
||||
Assert.assertEquals(2, newName1.split(Constants.COPY_SUFFIX).length);
|
||||
String processName2 = "wf_copy_all_ods_data_to_d";
|
||||
final String newName2 = processDefinitionService.getNewName(processName2, Constants.COPY_SUFFIX);
|
||||
Assert.assertEquals(3, newName2.split(Constants.COPY_SUFFIX).length);
|
||||
String processName3 = "test_import_" + DateUtils.getCurrentTimeStamp();
|
||||
final String newName3 = processDefinitionService.getNewName(processName3, Constants.IMPORT_SUFFIX);
|
||||
Assert.assertEquals(2, newName3.split(Constants.IMPORT_SUFFIX).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* get mock processDefinition
|
||||
*
|
||||
|
|
|
|||
|
|
@ -215,6 +215,10 @@ public final class Constants {
|
|||
* date format of yyyyMMddHHmmssSSS
|
||||
*/
|
||||
public static final String YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
|
||||
|
||||
public static final String IMPORT_SUFFIX = "_import_";
|
||||
|
||||
public static final String COPY_SUFFIX = "_copy_";
|
||||
/**
|
||||
* http connect time out
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue