Browse Source

[Fix-5763]: The scheduler online/offline interface, projectName -> projectCode (#5764)

* 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

* fix: The scheduler online/offline interface, projectName -> projectCode

* fix UT

Co-authored-by: wen-hemin <wenhemin@apache.com>
2.0.7-release
wen-hemin 4 years ago committed by GitHub
parent
commit
e4f427a8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
  2. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java
  3. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
  4. 12
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
  5. 29
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java
  6. 4
      dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js

12
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java

@ -166,7 +166,7 @@ public class SchedulerController extends BaseController {
* publish schedule setScheduleState * publish schedule setScheduleState
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param id scheduler id * @param id scheduler id
* @return publish result code * @return publish result code
*/ */
@ -178,9 +178,9 @@ public class SchedulerController extends BaseController {
@ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR) @ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result online(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result online(@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("id") Integer id) { @RequestParam("id") Integer id) {
Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.ONLINE); Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectCode, id, ReleaseState.ONLINE);
return returnDataList(result); return returnDataList(result);
} }
@ -188,7 +188,7 @@ public class SchedulerController extends BaseController {
* offline schedule * offline schedule
* *
* @param loginUser login user * @param loginUser login user
* @param projectName project name * @param projectCode project code
* @param id schedule id * @param id schedule id
* @return operation result code * @return operation result code
*/ */
@ -200,10 +200,10 @@ public class SchedulerController extends BaseController {
@ApiException(OFFLINE_SCHEDULE_ERROR) @ApiException(OFFLINE_SCHEDULE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result offline(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result offline(@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("id") Integer id) { @RequestParam("id") Integer id) {
Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectName, id, ReleaseState.OFFLINE); Map<String, Object> result = schedulerService.setScheduleState(loginUser, projectCode, id, ReleaseState.OFFLINE);
return returnDataList(result); return returnDataList(result);
} }

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

@ -83,13 +83,13 @@ public interface SchedulerService {
* set schedule online or offline * set schedule online or offline
* *
* @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 scheduleStatus schedule status * @param scheduleStatus schedule status
* @return publish result code * @return publish result code
*/ */
Map<String, Object> setScheduleState(User loginUser, Map<String, Object> setScheduleState(User loginUser,
String projectName, long projectCode,
Integer id, Integer id,
ReleaseState scheduleStatus); ReleaseState scheduleStatus);

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java

@ -293,7 +293,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
* set schedule online or offline * set schedule online or offline
* *
* @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 scheduleStatus schedule status * @param scheduleStatus schedule status
* @return publish result code * @return publish result code
@ -301,12 +301,12 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
@Override @Override
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public Map<String, Object> setScheduleState(User loginUser, public Map<String, Object> setScheduleState(User loginUser,
String projectName, long projectCode,
Integer id, Integer id,
ReleaseState scheduleStatus) { ReleaseState scheduleStatus) {
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);
if (!hasProjectAndPerm) { if (!hasProjectAndPerm) {

12
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java

@ -28,6 +28,7 @@ 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.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.ReleaseState;
import org.apache.dolphinscheduler.common.enums.WarningType; import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
@ -115,7 +116,10 @@ public class SchedulerControllerTest extends AbstractControllerTest {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("id","37"); paramsMap.add("id","37");
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/online","cxc_1113") Mockito.when(schedulerService.setScheduleState(isA(User.class), isA(Long.class), isA(Integer.class),
isA(ReleaseState.class))).thenReturn(successResult());
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/online",123)
.header(SESSION_ID, sessionId) .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
@ -127,13 +131,15 @@ public class SchedulerControllerTest extends AbstractControllerTest {
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
@Test @Test
public void testOffline() throws Exception { public void testOffline() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("id","28"); paramsMap.add("id","28");
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/offline","cxc_1113") Mockito.when(schedulerService.setScheduleState(isA(User.class), isA(Long.class), isA(Integer.class),
isA(ReleaseState.class))).thenReturn(successResult());
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/offline",123)
.header(SESSION_ID, sessionId) .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())

29
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java

@ -91,12 +91,12 @@ public class SchedulerServiceTest {
@Test @Test
public void testSetScheduleState() { public void testSetScheduleState() {
String projectName = "test"; String projectName = "test";
long projectCode = 1L;
User loginUser = new User(); User loginUser = new User();
loginUser.setId(1); loginUser.setId(1);
Map<String, Object> result = new HashMap<String, Object>(); Map<String, Object> result = new HashMap<String, Object>();
Project project = getProject(projectName); Project project = getProject(projectName, projectCode);
ProcessDefinition processDefinition = new ProcessDefinition(); ProcessDefinition processDefinition = new ProcessDefinition();
@ -110,49 +110,50 @@ public class SchedulerServiceTest {
Mockito.when(scheduleMapper.selectById(1)).thenReturn(schedule); Mockito.when(scheduleMapper.selectById(1)).thenReturn(schedule);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project);
Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition); Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition);
//hash no auth //hash no auth
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE);
Mockito.when(projectService.hasProjectAndPerm(loginUser, project, result)).thenReturn(true); Mockito.when(projectService.hasProjectAndPerm(loginUser, project, result)).thenReturn(true);
//schedule not exists //schedule not exists
result = schedulerService.setScheduleState(loginUser, projectName, 2, ReleaseState.ONLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 2, ReleaseState.ONLINE);
Assert.assertEquals(Status.SCHEDULE_CRON_NOT_EXISTS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SCHEDULE_CRON_NOT_EXISTS, result.get(Constants.STATUS));
//SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE //SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.OFFLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.OFFLINE);
Assert.assertEquals(Status.SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE, result.get(Constants.STATUS)); Assert.assertEquals(Status.SCHEDULE_CRON_REALEASE_NEED_NOT_CHANGE, result.get(Constants.STATUS));
//PROCESS_DEFINE_NOT_EXIST //PROCESS_DEFINE_NOT_EXIST
schedule.setProcessDefinitionId(2); schedule.setProcessDefinitionId(2);
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE);
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, result.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, result.get(Constants.STATUS));
schedule.setProcessDefinitionId(1); schedule.setProcessDefinitionId(1);
// PROCESS_DEFINE_NOT_RELEASE // PROCESS_DEFINE_NOT_RELEASE
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE);
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_RELEASE, result.get(Constants.STATUS)); Assert.assertEquals(Status.PROCESS_DEFINE_NOT_RELEASE, result.get(Constants.STATUS));
processDefinition.setReleaseState(ReleaseState.ONLINE); processDefinition.setReleaseState(ReleaseState.ONLINE);
Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition); Mockito.when(processService.findProcessDefineById(1)).thenReturn(processDefinition);
//MASTER_NOT_EXISTS //MASTER_NOT_EXISTS
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE);
Assert.assertEquals(Status.MASTER_NOT_EXISTS, result.get(Constants.STATUS)); Assert.assertEquals(Status.MASTER_NOT_EXISTS, result.get(Constants.STATUS));
//set master //set master
Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(masterServers); Mockito.when(monitorService.getServerListFromRegistry(true)).thenReturn(masterServers);
//SUCCESS //SUCCESS
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.ONLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.ONLINE);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
//OFFLINE //OFFLINE
Mockito.when(quartzExecutors.deleteJob(null, null)).thenReturn(true); Mockito.when(quartzExecutors.deleteJob(null, null)).thenReturn(true);
result = schedulerService.setScheduleState(loginUser, projectName, 1, ReleaseState.OFFLINE); result = schedulerService.setScheduleState(loginUser, project.getCode(), 1, ReleaseState.OFFLINE);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} }
@ -174,9 +175,17 @@ public class SchedulerServiceTest {
} }
private Project getProject(String name) { private Project getProject(String name) {
Project project = new Project();
project.setName(name);
project.setUserId(1);
return project;
}
private Project getProject(String name, long code) {
Project project = new Project(); Project project = new Project();
project.setName(name); project.setName(name);
project.setCode(code);
project.setUserId(1); project.setUserId(1);
return project; return project;

4
dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js

@ -592,7 +592,7 @@ export default {
*/ */
scheduleOffline ({ state }, payload) { scheduleOffline ({ state }, payload) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
io.post(`projects/${state.projectName}/schedule/offline`, payload, res => { io.post(`projects/${state.projectCode}/schedule/offline`, payload, res => {
resolve(res) resolve(res)
}).catch(e => { }).catch(e => {
reject(e) reject(e)
@ -604,7 +604,7 @@ export default {
*/ */
scheduleOnline ({ state }, payload) { scheduleOnline ({ state }, payload) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
io.post(`projects/${state.projectName}/schedule/online`, payload, res => { io.post(`projects/${state.projectCode}/schedule/online`, payload, res => {
resolve(res) resolve(res)
}).catch(e => { }).catch(e => {
reject(e) reject(e)

Loading…
Cancel
Save