mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-05 21:59:29 +08:00
[Fix-5511]: the updateSchedule interface, projectName -> projectCode (#5761)
* fix: createSchedule interface, process definition id -> process definition code * fix: add junit * fix junit * fix: projectName -> projectCode * fix UT * Optimize variable type * fix: the updateSchedule interface, projectName -> projectCode * fix comment Co-authored-by: wen-hemin <wenhemin@apache.com>
This commit is contained in:
parent
d382a7ba8c
commit
cfa22d7c89
@ -76,7 +76,6 @@ public class SchedulerController extends BaseController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SchedulerService schedulerService;
|
private SchedulerService schedulerService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create schedule
|
* create schedule
|
||||||
*
|
*
|
||||||
@ -125,7 +124,7 @@ public class SchedulerController extends BaseController {
|
|||||||
* updateProcessInstance schedule
|
* updateProcessInstance schedule
|
||||||
*
|
*
|
||||||
* @param loginUser login user
|
* @param loginUser login user
|
||||||
* @param projectName project name
|
* @param projectCode project code
|
||||||
* @param id scheduler id
|
* @param id scheduler id
|
||||||
* @param schedule scheduler
|
* @param schedule scheduler
|
||||||
* @param warningType warning type
|
* @param warningType warning type
|
||||||
@ -149,7 +148,7 @@ public class SchedulerController extends BaseController {
|
|||||||
@ApiException(UPDATE_SCHEDULE_ERROR)
|
@ApiException(UPDATE_SCHEDULE_ERROR)
|
||||||
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
|
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
|
||||||
public Result updateSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
|
public Result updateSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
|
||||||
@ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName,
|
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||||
@RequestParam(value = "id") Integer id,
|
@RequestParam(value = "id") Integer id,
|
||||||
@RequestParam(value = "schedule") String schedule,
|
@RequestParam(value = "schedule") String schedule,
|
||||||
@RequestParam(value = "warningType", required = false, defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType,
|
@RequestParam(value = "warningType", required = false, defaultValue = DEFAULT_WARNING_TYPE) WarningType warningType,
|
||||||
@ -158,8 +157,8 @@ public class SchedulerController extends BaseController {
|
|||||||
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup,
|
@RequestParam(value = "workerGroup", required = false, defaultValue = "default") String workerGroup,
|
||||||
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) {
|
@RequestParam(value = "processInstancePriority", required = false) Priority processInstancePriority) {
|
||||||
|
|
||||||
Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectName, id, schedule,
|
Map<String, Object> result = schedulerService.updateSchedule(loginUser, projectCode, id, schedule,
|
||||||
warningType, warningGroupId, failureStrategy, null, processInstancePriority, workerGroup);
|
warningType, warningGroupId, failureStrategy, processInstancePriority, workerGroup);
|
||||||
return returnDataList(result);
|
return returnDataList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public interface SchedulerService {
|
|||||||
* updateProcessInstance schedule
|
* updateProcessInstance schedule
|
||||||
*
|
*
|
||||||
* @param loginUser login user
|
* @param loginUser login user
|
||||||
* @param projectName project name
|
* @param projectCode project code
|
||||||
* @param id scheduler id
|
* @param id scheduler id
|
||||||
* @param scheduleExpression scheduler
|
* @param scheduleExpression scheduler
|
||||||
* @param warningType warning type
|
* @param warningType warning type
|
||||||
@ -66,17 +66,15 @@ public interface SchedulerService {
|
|||||||
* @param failureStrategy failure strategy
|
* @param failureStrategy failure strategy
|
||||||
* @param workerGroup worker group
|
* @param workerGroup worker group
|
||||||
* @param processInstancePriority process instance priority
|
* @param processInstancePriority process instance priority
|
||||||
* @param scheduleStatus schedule status
|
|
||||||
* @return update result code
|
* @return update result code
|
||||||
*/
|
*/
|
||||||
Map<String, Object> updateSchedule(User loginUser,
|
Map<String, Object> updateSchedule(User loginUser,
|
||||||
String projectName,
|
long projectCode,
|
||||||
Integer id,
|
Integer id,
|
||||||
String scheduleExpression,
|
String scheduleExpression,
|
||||||
WarningType warningType,
|
WarningType warningType,
|
||||||
int warningGroupId,
|
int warningGroupId,
|
||||||
FailureStrategy failureStrategy,
|
FailureStrategy failureStrategy,
|
||||||
ReleaseState scheduleStatus,
|
|
||||||
Priority processInstancePriority,
|
Priority processInstancePriority,
|
||||||
String workerGroup);
|
String workerGroup);
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
|
|||||||
* updateProcessInstance schedule
|
* updateProcessInstance schedule
|
||||||
*
|
*
|
||||||
* @param loginUser login user
|
* @param loginUser login user
|
||||||
* @param projectName project name
|
* @param projectCode project code
|
||||||
* @param id scheduler id
|
* @param id scheduler id
|
||||||
* @param scheduleExpression scheduler
|
* @param scheduleExpression scheduler
|
||||||
* @param warningType warning type
|
* @param warningType warning type
|
||||||
@ -203,18 +203,17 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = RuntimeException.class)
|
@Transactional(rollbackFor = RuntimeException.class)
|
||||||
public Map<String, Object> updateSchedule(User loginUser,
|
public Map<String, Object> updateSchedule(User loginUser,
|
||||||
String projectName,
|
long projectCode,
|
||||||
Integer id,
|
Integer id,
|
||||||
String scheduleExpression,
|
String scheduleExpression,
|
||||||
WarningType warningType,
|
WarningType warningType,
|
||||||
int warningGroupId,
|
int warningGroupId,
|
||||||
FailureStrategy failureStrategy,
|
FailureStrategy failureStrategy,
|
||||||
ReleaseState scheduleStatus,
|
|
||||||
Priority processInstancePriority,
|
Priority processInstancePriority,
|
||||||
String workerGroup) {
|
String workerGroup) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
Project project = projectMapper.queryByName(projectName);
|
Project project = projectMapper.queryByCode(projectCode);
|
||||||
|
|
||||||
// check project auth
|
// check project auth
|
||||||
boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result);
|
boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result);
|
||||||
@ -273,9 +272,6 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
|
|||||||
schedule.setFailureStrategy(failureStrategy);
|
schedule.setFailureStrategy(failureStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scheduleStatus != null) {
|
|
||||||
schedule.setReleaseState(scheduleStatus);
|
|
||||||
}
|
|
||||||
schedule.setWorkerGroup(workerGroup);
|
schedule.setWorkerGroup(workerGroup);
|
||||||
schedule.setUpdateTime(now);
|
schedule.setUpdateTime(now);
|
||||||
schedule.setProcessInstancePriority(processInstancePriority);
|
schedule.setProcessInstancePriority(processInstancePriority);
|
||||||
|
@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.api.controller;
|
|||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.api.ApiApplicationServer;
|
import org.apache.dolphinscheduler.api.ApiApplicationServer;
|
||||||
@ -93,6 +94,13 @@ public class AbstractControllerTest {
|
|||||||
Assert.assertTrue(StringUtils.isNotEmpty(session));
|
Assert.assertTrue(StringUtils.isNotEmpty(session));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> successResult() {
|
||||||
|
Map<String, Object> serviceResult = new HashMap<>();
|
||||||
|
putMsg(serviceResult, Status.SUCCESS);
|
||||||
|
serviceResult.put(Constants.DATA_LIST, "{}");
|
||||||
|
return serviceResult;
|
||||||
|
}
|
||||||
|
|
||||||
public void putMsg(Map<String, Object> result, Status status, Object... statusParams) {
|
public void putMsg(Map<String, Object> result, Status status, Object... statusParams) {
|
||||||
result.put(Constants.STATUS, status);
|
result.put(Constants.STATUS, status);
|
||||||
if (statusParams != null && statusParams.length > 0) {
|
if (statusParams != null && statusParams.length > 0) {
|
||||||
|
@ -23,13 +23,9 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.api.enums.Status;
|
import org.apache.dolphinscheduler.api.enums.Status;
|
||||||
import org.apache.dolphinscheduler.api.service.SchedulerService;
|
import org.apache.dolphinscheduler.api.service.SchedulerService;
|
||||||
import org.apache.dolphinscheduler.api.utils.Result;
|
import org.apache.dolphinscheduler.api.utils.Result;
|
||||||
import org.apache.dolphinscheduler.common.Constants;
|
|
||||||
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
|
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
|
||||||
import org.apache.dolphinscheduler.common.enums.Priority;
|
import org.apache.dolphinscheduler.common.enums.Priority;
|
||||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||||
@ -69,13 +65,9 @@ public class SchedulerControllerTest extends AbstractControllerTest {
|
|||||||
paramsMap.add("workerGroupId","1");
|
paramsMap.add("workerGroupId","1");
|
||||||
paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH));
|
paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH));
|
||||||
|
|
||||||
Map<String, Object> serviceResult = new HashMap<>();
|
|
||||||
putMsg(serviceResult, Status.SUCCESS);
|
|
||||||
serviceResult.put(Constants.DATA_LIST, 1);
|
|
||||||
|
|
||||||
Mockito.when(schedulerService.insertSchedule(isA(User.class), isA(Long.class), isA(Long.class),
|
Mockito.when(schedulerService.insertSchedule(isA(User.class), isA(Long.class), isA(Long.class),
|
||||||
isA(String.class), isA(WarningType.class), isA(int.class), isA(FailureStrategy.class),
|
isA(String.class), isA(WarningType.class), isA(int.class), isA(FailureStrategy.class),
|
||||||
isA(Priority.class), isA(String.class))).thenReturn(serviceResult);
|
isA(Priority.class), isA(String.class))).thenReturn(successResult());
|
||||||
|
|
||||||
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/create",123)
|
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/create",123)
|
||||||
.header(SESSION_ID, sessionId)
|
.header(SESSION_ID, sessionId)
|
||||||
@ -89,7 +81,6 @@ public class SchedulerControllerTest extends AbstractControllerTest {
|
|||||||
logger.info(mvcResult.getResponse().getContentAsString());
|
logger.info(mvcResult.getResponse().getContentAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateSchedule() throws Exception {
|
public void testUpdateSchedule() throws Exception {
|
||||||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||||
@ -103,7 +94,11 @@ public class SchedulerControllerTest extends AbstractControllerTest {
|
|||||||
paramsMap.add("workerGroupId","1");
|
paramsMap.add("workerGroupId","1");
|
||||||
paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH));
|
paramsMap.add("processInstancePriority",String.valueOf(Priority.HIGH));
|
||||||
|
|
||||||
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/update","cxc_1113")
|
Mockito.when(schedulerService.updateSchedule(isA(User.class), isA(Long.class), isA(Integer.class),
|
||||||
|
isA(String.class), isA(WarningType.class), isA(Integer.class), isA(FailureStrategy.class),
|
||||||
|
isA(Priority.class), isA(String.class))).thenReturn(successResult());
|
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/update",123)
|
||||||
.header(SESSION_ID, sessionId)
|
.header(SESSION_ID, sessionId)
|
||||||
.params(paramsMap))
|
.params(paramsMap))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
@ -616,7 +616,7 @@ export default {
|
|||||||
*/
|
*/
|
||||||
updateSchedule ({ state }, payload) {
|
updateSchedule ({ state }, payload) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
io.post(`projects/${state.projectName}/schedule/update`, payload, res => {
|
io.post(`projects/${state.projectCode}/schedule/update`, payload, res => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
reject(e)
|
reject(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user