From 8732723279543861f414184bd9bf8053f21e8f13 Mon Sep 17 00:00:00 2001 From: gongzhongqiang <764629910@qq.com> Date: Fri, 5 Jul 2024 00:15:47 +0800 Subject: [PATCH] polish --- .../console/base/domain/RestResponse.java | 76 +++++++++---------- .../controller/FlinkClusterController.java | 2 +- .../core/controller/SettingController.java | 4 +- .../core/controller/YarnQueueController.java | 4 +- .../core/service/FlinkClusterService.java | 12 +-- .../console/core/service/SettingService.java | 28 +++---- .../core/service/YarnQueueService.java | 12 +-- .../service/impl/FlinkClusterServiceImpl.java | 26 +++---- .../core/service/impl/ProjectServiceImpl.java | 10 +-- .../core/service/impl/SettingServiceImpl.java | 48 ++++++------ .../service/impl/YarnQueueServiceImpl.java | 14 ++-- .../controller/AccessTokenController.java | 22 +++--- .../system/controller/UserController.java | 2 +- .../core/service/SettingServiceTest.java | 4 +- .../console/core/service/UserServiceTest.java | 54 ++++++------- .../core/service/YarnQueueServiceTest.java | 22 +++--- 16 files changed, 170 insertions(+), 170 deletions(-) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java index c11b2eedf3..4f0b5678ed 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/RestResponse.java @@ -26,69 +26,69 @@ @AllArgsConstructor public class RestResponse { - private Integer code; + private Integer code; - private String message; + private String message; private T data; /** - * return success. - * - * @return {@linkplain RestResponse} - */ - public static RestResponse success() { + * return success. + * + * @return {@linkplain RestResponse} + */ + public static RestResponse success() { return success(""); } /** - * return success. - * - * @param msg msg - * @return {@linkplain RestResponse} - */ - public static RestResponse success(final String msg) { + * return success. + * + * @param msg msg + * @return {@linkplain RestResponse} + */ + public static RestResponse success(final String msg) { return success(msg, null); } /** - * return success. - * - * @param data this is result data. - * @return {@linkplain RestResponse} - */ - public static RestResponse success(final T data) { + * return success. + * + * @param data this is result data. + * @return {@linkplain RestResponse} + */ + public static RestResponse success(final T data) { return success(null, data); } /** - * return success. - * - * @param msg this ext msg. - * @param data this is result data. - * @return {@linkplain RestResponse} - */ - public static RestResponse success(final String msg, final T data) { + * return success. + * + * @param msg this ext msg. + * @param data this is result data. + * @return {@linkplain RestResponse} + */ + public static RestResponse success(final String msg, final T data) { return new RestResponse<>(ResponseCode.CODE_SUCCESS, msg, data); } /** - * return error. - * - * @param msg error msg - * @return {@linkplain RestResponse} - */ - public static RestResponse error(final String msg) { + * return error. + * + * @param msg error msg + * @return {@linkplain RestResponse} + */ + public static RestResponse error(final String msg) { return error(ResponseCode.CODE_FAIL, msg); } /** - * return error. - * - * @param code error code - * @param msg error msg - * @return {@linkplain RestResponse} - */ + * return error. + * + * @param code error code + * @param msg error msg + * @return {@linkplain RestResponse} + */ public static RestResponse error(final int code, final String msg) { return new RestResponse<>(code, msg, null); } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkClusterController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkClusterController.java index a6a6f18eaf..d6020db9a3 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkClusterController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkClusterController.java @@ -68,7 +68,7 @@ public RestResponse remoteUrl(Long id) { @PostMapping("check") public RestResponse check(FlinkCluster cluster) { flinkClusterService.check(cluster); - return RestResponse.success(); + return RestResponse.success(); } @PostMapping("create") diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/SettingController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/SettingController.java index 220c8d3abe..9096ff2676 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/SettingController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/SettingController.java @@ -79,7 +79,7 @@ public RestResponse docker() { @RequiresPermissions("setting:view") public RestResponse checkDocker(DockerConfig dockerConfig) { settingService.checkDocker(dockerConfig); - return RestResponse.success(); + return RestResponse.success(); } @PostMapping("update/docker") @@ -100,7 +100,7 @@ public RestResponse email() { @RequiresPermissions("setting:view") public RestResponse checkEmail(SenderEmail senderEmail) { settingService.checkEmail(senderEmail); - return RestResponse.success(); + return RestResponse.success(); } @PostMapping("update/email") diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/YarnQueueController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/YarnQueueController.java index 5a23e8cccd..545206ed07 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/YarnQueueController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/YarnQueueController.java @@ -57,8 +57,8 @@ public RestResponse list(RestRequest restRequest, YarnQueue yarnQueue) { @PostMapping("check") public RestResponse check(YarnQueue yarnQueue) { yarnQueueService.checkYarnQueue(yarnQueue); - return RestResponse.success(); - } + return RestResponse.success(); + } @PostMapping("create") @RequiresPermissions("yarnQueue:create") diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkClusterService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkClusterService.java index 334442bb20..87a31d3ea9 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkClusterService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkClusterService.java @@ -36,12 +36,12 @@ public interface FlinkClusterService extends IService { */ List listAvailableCluster(); - /** - * Check the flink cluster status - * - * @param flinkCluster FlinkCluster To be check - */ - void check(FlinkCluster flinkCluster); + /** + * Check the flink cluster status + * + * @param flinkCluster FlinkCluster To be check + */ + void check(FlinkCluster flinkCluster); /** * Create flink cluster diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/SettingService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/SettingService.java index ec5b941b3f..247bd393ba 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/SettingService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/SettingService.java @@ -94,13 +94,13 @@ public interface SettingService extends IService { */ String getIngressModeDefault(); - /** - * Before updating the Docker settings, verify that the parameters are filled in correctly, We - * check whether it is correct or not by concatenating the given registration URL. - * - * @param dockerConfig Docker config to be checked - */ - void checkDocker(DockerConfig dockerConfig); + /** + * Before updating the Docker settings, verify that the parameters are filled in correctly, We + * check whether it is correct or not by concatenating the given registration URL. + * + * @param dockerConfig Docker config to be checked + */ + void checkDocker(DockerConfig dockerConfig); /** * update docker config @@ -117,13 +117,13 @@ public interface SettingService extends IService { */ SenderEmail getSenderEmail(); - /** - * Before updating the email settings, verify that the parameters are filled in correctly, We - * check whether it is correct or not by concatenating the given host. - * - * @param senderEmail email config to be checked - */ - void checkEmail(SenderEmail senderEmail); + /** + * Before updating the email settings, verify that the parameters are filled in correctly, We + * check whether it is correct or not by concatenating the given host. + * + * @param senderEmail email config to be checked + */ + void checkEmail(SenderEmail senderEmail); /** * update docker config diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/YarnQueueService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/YarnQueueService.java index 0f4cfaeab2..36daaf6721 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/YarnQueueService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/YarnQueueService.java @@ -36,12 +36,12 @@ public interface YarnQueueService extends IService { */ IPage getPage(YarnQueue yarnQueue, RestRequest restRequest); - /** - * Check the correctness of yarnQueue - * - * @param yarnQueue YarnQueue - */ - void checkYarnQueue(YarnQueue yarnQueue); + /** + * Check the correctness of yarnQueue + * + * @param yarnQueue YarnQueue + */ + void checkYarnQueue(YarnQueue yarnQueue); /** * Create a YarnQueue by entering parameters diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkClusterServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkClusterServiceImpl.java index cf0ec60159..aa0326e9c5 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkClusterServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkClusterServiceImpl.java @@ -101,20 +101,20 @@ public List listAvailableCluster() { public void check(FlinkCluster cluster) { AssertUtils.required( this.existsByClusterName(cluster.getClusterName(), cluster.getId()), - "ClusterName already exists, please check!"); - if (StringUtils.isNotBlank(cluster.getClusterId())) { - AssertUtils.required( - !this.existsByClusterId(cluster.getClusterId(), cluster.getId()), - "The clusterId " + cluster.getClusterId() + " already exists, please check!"); - AssertUtils.required( - !(FlinkExecutionMode.isRemoteMode(cluster.getFlinkExecutionModeEnum()) - && !flinkClusterWatcher.verifyClusterConnection(cluster)), - "The remote cluster connection failed, please check!"); + "ClusterName already exists, please check!"); + if (StringUtils.isNotBlank(cluster.getClusterId())) { AssertUtils.required( - !(FlinkExecutionMode.isYarnMode(cluster.getFlinkExecutionModeEnum()) - && !flinkClusterWatcher.verifyClusterConnection(cluster)), - "The flink cluster connection failed, please check!"); - } + !this.existsByClusterId(cluster.getClusterId(), cluster.getId()), + "The clusterId " + cluster.getClusterId() + " already exists, please check!"); + AssertUtils.required( + !(FlinkExecutionMode.isRemoteMode(cluster.getFlinkExecutionModeEnum()) + && !flinkClusterWatcher.verifyClusterConnection(cluster)), + "The remote cluster connection failed, please check!"); + AssertUtils.required( + !(FlinkExecutionMode.isYarnMode(cluster.getFlinkExecutionModeEnum()) + && !flinkClusterWatcher.verifyClusterConnection(cluster)), + "The flink cluster connection failed, please check!"); + } } @Override diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java index d6195c611f..e31e2c6686 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProjectServiceImpl.java @@ -99,11 +99,11 @@ public class ProjectServiceImpl extends ServiceImpl @Value("${streampark.project.max-build:6}") private Long maxProjectBuildNum; - @Override - public RestResponse create(Project project) { - LambdaQueryWrapper queryWrapper = - new LambdaQueryWrapper().eq(Project::getName, project.getName()); - long count = count(queryWrapper); + @Override + public RestResponse create(Project project) { + LambdaQueryWrapper queryWrapper = + new LambdaQueryWrapper().eq(Project::getName, project.getName()); + long count = count(queryWrapper); ApiAlertException.throwIfTrue(count > 0, "project name already exists, add project failed"); if (StringUtils.isNotBlank(project.getPassword())) { diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SettingServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SettingServiceImpl.java index bb1e2bd760..3c0ef134e1 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SettingServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SettingServiceImpl.java @@ -130,27 +130,27 @@ public void checkDocker(DockerConfig dockerConfig) { new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).build(); try (DockerClient dockerClient = DockerClientImpl.getInstance(config, httpClient)) { - AuthConfig authConfig = - new AuthConfig() - .withUsername(dockerConfig.getUsername()) - .withPassword(dockerConfig.getPassword()) - .withRegistryAddress(dockerConfig.getAddress()); - AuthResponse response = dockerClient.authCmd().withAuthConfig(authConfig).exec(); - AssertUtils.required( - response.getStatus().equals("Login Succeeded"), - "Docker login failed, status: " + response.getStatus()); - } catch (Exception e) { - log.warn("Failed to validate Docker registry.", e); + AuthConfig authConfig = + new AuthConfig() + .withUsername(dockerConfig.getUsername()) + .withPassword(dockerConfig.getPassword()) + .withRegistryAddress(dockerConfig.getAddress()); + AuthResponse response = dockerClient.authCmd().withAuthConfig(authConfig).exec(); + AssertUtils.required( + response.getStatus().equals("Login Succeeded"), + "Docker login failed, status: " + response.getStatus()); + } catch (Exception e) { + log.warn("Failed to validate Docker registry.", e); if (e.getMessage().contains("LastErrorException")) { throw new ApiAlertException( - "Please check the Docker service is running and the address is correct."); + "Please check the Docker service is running and the address is correct."); } else if (e.getMessage().contains("Status 401")) { throw new ApiAlertException( "Failed to validate Docker registry, unauthorized: incorrect username or password "); } else { throw new ApiAlertException("Failed to validate Docker registry, error: " + e.getMessage()); - } - } + } + } } @Override @@ -202,17 +202,17 @@ public void checkEmail(SenderEmail senderEmail) { props.put("mail.smtp.host", senderEmail.getHost()); props.put("mail.smtp.port", senderEmail.getPort()); - Session session = Session.getInstance(props); - try { - Transport transport = session.getTransport("smtp"); - transport.connect( - senderEmail.getHost(), senderEmail.getUserName(), senderEmail.getPassword()); - transport.close(); - } catch (MessagingException e) { - throw new ApiAlertException( - "Failed to validate email configuration, error: " + e.getMessage()); + Session session = Session.getInstance(props); + try { + Transport transport = session.getTransport("smtp"); + transport.connect( + senderEmail.getHost(), senderEmail.getUserName(), senderEmail.getPassword()); + transport.close(); + } catch (MessagingException e) { + throw new ApiAlertException( + "Failed to validate email configuration, error: " + e.getMessage()); + } } - } @Override public boolean updateEmail(SenderEmail senderEmail) { diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java index f3d6b294a1..6f4eb5baaa 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/YarnQueueServiceImpl.java @@ -91,13 +91,13 @@ public IPage getPage(YarnQueue yarnQueue, RestRequest request) { @Override public void checkYarnQueue(YarnQueue yarnQueue) { - AssertUtils.notNull(yarnQueue, "Yarn queue mustn't be empty."); - AssertUtils.notNull(yarnQueue.getTeamId(), "Team id mustn't be null."); - AssertUtils.required(!StringUtils.isBlank(yarnQueue.getQueueLabel()), QUEUE_EMPTY_HINT); - AssertUtils.required(isValid(yarnQueue.getQueueLabel()), ERR_FORMAT_HINTS); - AssertUtils.required( - !this.baseMapper.existsByQueueLabel(yarnQueue), QUEUE_EXISTED_IN_TEAM_HINT); - } + AssertUtils.notNull(yarnQueue, "Yarn queue mustn't be empty."); + AssertUtils.notNull(yarnQueue.getTeamId(), "Team id mustn't be null."); + AssertUtils.required(!StringUtils.isBlank(yarnQueue.getQueueLabel()), QUEUE_EMPTY_HINT); + AssertUtils.required(isValid(yarnQueue.getQueueLabel()), ERR_FORMAT_HINTS); + AssertUtils.required( + !this.baseMapper.existsByQueueLabel(yarnQueue), QUEUE_EXISTED_IN_TEAM_HINT); + } @Override public boolean createYarnQueue(YarnQueue yarnQueue) { diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/AccessTokenController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/AccessTokenController.java index e3378045e8..93a0ced61c 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/AccessTokenController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/AccessTokenController.java @@ -61,17 +61,17 @@ public RestResponse createToken( public RestResponse verifyToken() { Long userId = serviceHelper.getUserId(); AccessTokenStateEnum restResponse; - if (userId != null) { - AccessToken accessToken = accessTokenService.getByUserId(userId); - if (accessToken == null) { - restResponse = AccessTokenStateEnum.NULL; - } else if (AccessToken.STATUS_DISABLE.equals(accessToken.getFinalStatus())) { - restResponse = AccessTokenStateEnum.INVALID; - } else { - restResponse = AccessTokenStateEnum.OK; - } - } else { - restResponse = AccessTokenStateEnum.INVALID; + if (userId != null) { + AccessToken accessToken = accessTokenService.getByUserId(userId); + if (accessToken == null) { + restResponse = AccessTokenStateEnum.NULL; + } else if (AccessToken.STATUS_DISABLE.equals(accessToken.getFinalStatus())) { + restResponse = AccessTokenStateEnum.INVALID; + } else { + restResponse = AccessTokenStateEnum.OK; + } + } else { + restResponse = AccessTokenStateEnum.INVALID; } return RestResponse.success(restResponse); } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java index 8e665df0e6..a55a05a540 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java @@ -141,7 +141,7 @@ public RestResponse setTeam(Long teamId) { Team team = teamService.getById(teamId); if (team == null) { return RestResponse.error( - ResponseCode.CODE_FAIL_ALERT, "TeamId is invalid, set team failed."); + ResponseCode.CODE_FAIL_ALERT, "TeamId is invalid, set team failed."); } User user = serviceHelper.getLoginUser(); ApiAlertException.throwIfNull(user, "Current login user is null, set team failed."); diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/SettingServiceTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/SettingServiceTest.java index 6c9ccb9f37..be999f1781 100644 --- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/SettingServiceTest.java +++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/SettingServiceTest.java @@ -98,7 +98,7 @@ void checkEmailTest() { senderEmail.setSsl(false); senderEmail.setPort(25); assertDoesNotThrow(() -> settingService.checkEmail(senderEmail)); - } + } @Test void checkDockerTest() { @@ -112,5 +112,5 @@ void checkDockerTest() { dockerConfig.setNamespace("streampark"); assertDoesNotThrow(() -> settingService.checkDocker(dockerConfig)); - } + } } diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/UserServiceTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/UserServiceTest.java index ba3ab1f910..8f62012313 100644 --- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/UserServiceTest.java +++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/UserServiceTest.java @@ -48,35 +48,35 @@ class UserServiceTest extends SpringUnitTestBase { @Autowired private ResourceService resourceService; - @Test - @SuppressWarnings("unchecked") - void testLockUser() throws Exception { - User user = new User(); - user.setUsername("test"); - user.setNickName("test"); - user.setPassword("test"); - user.setUserType(UserTypeEnum.USER); - user.setStatus(User.STATUS_VALID); - userService.createUser(user); - // lock user - user.setStatus(User.STATUS_LOCK); - Map data = (Map) userService.updateUser(user).getData(); - Assertions.assertNotEquals(true, data.get("needTransferResource")); - // unlock user - user.setStatus(User.STATUS_VALID); - Map data1 = (Map) userService.updateUser(user).getData(); + @Test + @SuppressWarnings("unchecked") + void testLockUser() throws Exception { + User user = new User(); + user.setUsername("test"); + user.setNickName("test"); + user.setPassword("test"); + user.setUserType(UserTypeEnum.USER); + user.setStatus(User.STATUS_VALID); + userService.createUser(user); + // lock user + user.setStatus(User.STATUS_LOCK); + Map data = (Map) userService.updateUser(user).getData(); + Assertions.assertNotEquals(true, data.get("needTransferResource")); + // unlock user + user.setStatus(User.STATUS_VALID); + Map data1 = (Map) userService.updateUser(user).getData(); Assertions.assertNotEquals(true, data1.get("needTransferResource")); - Resource resource = new Resource(); - resource.setResourceName("test"); - resource.setResourceType(ResourceTypeEnum.FLINK_APP); - resource.setEngineType(EngineTypeEnum.FLINK); - resource.setTeamId(1L); - resource.setCreatorId(user.getUserId()); - resourceService.save(resource); - // lock user when has resource - user.setStatus(User.STATUS_LOCK); - Map data2 = (Map) userService.updateUser(user).getData(); + Resource resource = new Resource(); + resource.setResourceName("test"); + resource.setResourceType(ResourceTypeEnum.FLINK_APP); + resource.setEngineType(EngineTypeEnum.FLINK); + resource.setTeamId(1L); + resource.setCreatorId(user.getUserId()); + resourceService.save(resource); + // lock user when has resource + user.setStatus(User.STATUS_LOCK); + Map data2 = (Map) userService.updateUser(user).getData(); Assertions.assertEquals(true, data2.get("needTransferResource")); } diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/YarnQueueServiceTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/YarnQueueServiceTest.java index 22dda2f5c6..be751b254a 100644 --- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/YarnQueueServiceTest.java +++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/YarnQueueServiceTest.java @@ -115,16 +115,16 @@ void testCheckYarnQueue() { // Test for error format with non-empty. YarnQueue yarnQueue = mockYarnQueue(1L, "queue@"); yarnQueueService.checkYarnQueue(yarnQueue); - assertThatThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)) - .isInstanceOf(ApiAlertException.class) - .hasMessage(ERR_FORMAT_HINTS); + assertThatThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)) + .isInstanceOf(ApiAlertException.class) + .hasMessage(ERR_FORMAT_HINTS); // Test for error format with empty. yarnQueue.setQueueLabel(""); yarnQueueService.checkYarnQueue(yarnQueue); - assertThatThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)) - .isInstanceOf(ApiAlertException.class) - .hasMessage(QUEUE_EMPTY_HINT); + assertThatThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)) + .isInstanceOf(ApiAlertException.class) + .hasMessage(QUEUE_EMPTY_HINT); // Test for existed yarnQueue.setQueueLabel("queue1@label1"); @@ -137,20 +137,20 @@ void testCheckYarnQueue() { // QueueLabel updated yarnQueue.setQueueLabel("queue2@label1"); yarnQueueService.checkYarnQueue(yarnQueue); - assertThatNoException().isThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)); + assertThatNoException().isThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)); // new record but same QueueLabel yarnQueue.setId(null); yarnQueue.setQueueLabel("queue1@label1"); assertThatThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)) - .isInstanceOf(ApiAlertException.class) - .hasMessage(YarnQueueServiceImpl.QUEUE_EXISTED_IN_TEAM_HINT); + .isInstanceOf(ApiAlertException.class) + .hasMessage(YarnQueueServiceImpl.QUEUE_EXISTED_IN_TEAM_HINT); // Test for normal cases. yarnQueue.setQueueLabel("q1"); assertThatThrownBy(() -> yarnQueueService.checkYarnQueue(yarnQueue)) - .isInstanceOf(ApiAlertException.class) - .hasMessage(YarnQueueServiceImpl.QUEUE_AVAILABLE_HINT); + .isInstanceOf(ApiAlertException.class) + .hasMessage(YarnQueueServiceImpl.QUEUE_AVAILABLE_HINT); } /**