Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
GOODBOY008 committed Jul 4, 2024
1 parent 2fecd5d commit 8732723
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,69 +26,69 @@
@AllArgsConstructor
public class RestResponse<T> {

private Integer code;
private Integer code;

private String message;
private String message;

private T data;

/**
* return success.
*
* @return {@linkplain RestResponse}
*/
public static RestResponse<Object> success() {
* return success.
*
* @return {@linkplain RestResponse}
*/
public static RestResponse<Object> success() {
return success("");
}

/**
* return success.
*
* @param msg msg
* @return {@linkplain RestResponse}
*/
public static RestResponse<Object> success(final String msg) {
* return success.
*
* @param msg msg
* @return {@linkplain RestResponse}
*/
public static RestResponse<Object> success(final String msg) {
return success(msg, null);
}

/**
* return success.
*
* @param data this is result data.
* @return {@linkplain RestResponse}
*/
public static <T> RestResponse<T> success(final T data) {
* return success.
*
* @param data this is result data.
* @return {@linkplain RestResponse}
*/
public static <T> RestResponse<T> 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 <T> RestResponse<T> 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 <T> RestResponse<T> 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<Object> error(final String msg) {
* return error.
*
* @param msg error msg
* @return {@linkplain RestResponse}
*/
public static RestResponse<Object> 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<Object> error(final int code, final String msg) {
return new RestResponse<>(code, msg, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public interface FlinkClusterService extends IService<FlinkCluster> {
*/
List<FlinkCluster> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public interface SettingService extends IService<Setting> {
*/
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
Expand All @@ -117,13 +117,13 @@ public interface SettingService extends IService<Setting> {
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public interface YarnQueueService extends IService<YarnQueue> {
*/
IPage<YarnQueue> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ public List<FlinkCluster> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
@Value("${streampark.project.max-build:6}")
private Long maxProjectBuildNum;

@Override
public RestResponse create(Project project) {
LambdaQueryWrapper<Project> queryWrapper =
new LambdaQueryWrapper<Project>().eq(Project::getName, project.getName());
long count = count(queryWrapper);
@Override
public RestResponse create(Project project) {
LambdaQueryWrapper<Project> queryWrapper =
new LambdaQueryWrapper<Project>().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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public IPage<YarnQueue> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 8732723

Please sign in to comment.