Skip to content

Commit

Permalink
Merge pull request #126 from jsonwan/github_feature/file_source_api
Browse files Browse the repository at this point in the history
feature: 提供文件源管理、凭据管理相关ESB API #92
  • Loading branch information
wangyu096 authored Jul 28, 2021
2 parents ec8e9b3 + 5870850 commit b271b3f
Show file tree
Hide file tree
Showing 56 changed files with 1,413 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@
1246003=删除作业执行日志失败
##业务错误-文件网关服务(job-file-gateway)
1260001=文件源不存在:{0}
1260002=接入点响应异常:ListBucket,详情:{0}
1260003=接入点响应异常:ListObjects,详情:{0}
1260008=接入点响应异常:DeleteBucket,详情:{0}
1260009=接入点响应异常:DeleteBucketFile,详情:{0}
1260002=接入点响应异常:ListFileNode,详情:{0}
1260003=接入点响应异常:FileAvailable,详情:{0}
1260008=接入点响应异常:ExecuteAction,详情:{0}
1260004=文件源别名已存在:{0}
1260005=无法匹配到有效接入点,请检查文件源配置
1260006=接入点响应异常:ClearTaskFiles,详情:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@
1246003=Failed to delete execution log
## Business error (job-file-gateway)
1260001=FileSource does not exist:{0}
1260002=FileWorker response error:ListBucket, Detail:{0}
1260003=FileWorker response error:ListObjects, Detail:{0}
1260008=FileWorker response error:DeleteBucket, Detail:{0}
1260009=FileWorker response error:DeleteBucketFile, Detail:{0}
1260002=FileWorker response error:ListFileNode, Detail:{0}
1260003=FileWorker response error:FileAvailable, Detail:{0}
1260008=FileWorker response error:ExecuteAction, Detail:{0}
1260004=FileSource alias already exists:{0}
1260005=Cannot find available file worker, please check configuration of fileSource
1260006=FileWorker response error:ClearTaskFiles, Detail:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@
1246003=Failed to delete execution log
## Business error (job-file-gateway)
1260001=FileSource does not exist:{0}
1260002=FileWorker response error:ListBucket, Detail:{0}
1260003=FileWorker response error:ListObjects, Detail:{0}
1260008=FileWorker response error:DeleteBucket, Detail:{0}
1260009=FileWorker response error:DeleteBucketFile, Detail:{0}
1260002=FileWorker response error:ListFileNode, Detail:{0}
1260003=FileWorker response error:FileAvailable, Detail:{0}
1260008=FileWorker response error:ExecuteAction, Detail:{0}
1260004=FileSource alias already exists:{0}
1260005=Cannot find available file worker, please check configuration of fileSource
1260006=FileWorker response error:ClearTaskFiles, Detail:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@
1246003=删除作业执行日志失败
##业务错误-文件网关服务(job-file-gateway)
1260001=文件源不存在:{0}
1260002=接入点响应异常:ListBucket,详情:{0}
1260003=接入点响应异常:ListObjects,详情:{0}
1260008=接入点响应异常:DeleteBucket,详情:{0}
1260009=接入点响应异常:DeleteBucketFile,详情:{0}
1260002=接入点响应异常:ListFileNode,详情:{0}
1260003=接入点响应异常:FileAvailable,详情:{0}
1260008=接入点响应异常:ExecuteAction,详情:{0}
1260004=文件源别名已存在:{0}
1260005=无法匹配到有效接入点,请检查文件源配置
1260006=接入点响应异常:ClearTaskFiles,详情:{0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@
1246003=删除作业执行日志失败
##业务错误-文件网关服务(job-file-gateway)
1260001=文件源不存在:{0}
1260002=接入点响应异常:ListBucket,详情:{0}
1260003=接入点响应异常:ListObjects,详情:{0}
1260008=接入点响应异常:DeleteBucket,详情:{0}
1260009=接入点响应异常:DeleteBucketFile,详情:{0}
1260002=接入点响应异常:ListFileNode,详情:{0}
1260003=接入点响应异常:FileAvailable,详情:{0}
1260008=接入点响应异常:ExecuteAction,详情:{0}
1260004=文件源别名已存在:{0}
1260005=无法匹配到有效接入点,请检查文件源配置
1260006=接入点响应异常:ClearTaskFiles,详情:{0}
Expand Down
1 change: 1 addition & 0 deletions src/backend/commons/common-web/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation project(":commons:common-spring-ext")
implementation project(":commons:esb-sdk")
implementation project(":commons:common-iam")
implementation 'io.springfox:springfox-swagger2'
implementation "org.hibernate.validator:hibernate-validator"
implementation('jakarta.validation:jakarta.validation-api')
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.web.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.constant.ErrorCode;
import com.tencent.bk.job.common.exception.ServiceException;
import com.tencent.bk.job.common.i18n.service.MessageI18nService;
import com.tencent.bk.job.common.iam.model.AuthResult;
import com.tencent.bk.job.common.model.ValidateResult;
import com.tencent.bk.job.common.model.error.ErrorDetail;
import com.tencent.bk.job.common.util.ApplicationContextRegister;
import com.tencent.bk.job.common.util.JobContextUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
@Getter
@Setter
@ToString
@NoArgsConstructor
@ApiModel("服务间调用通用返回结构")
public class InnerServiceResponse<T> {
public static final Integer SUCCESS_CODE = 0;
public static final Integer COMMON_FAIL_CODE = 1;
private static volatile MessageI18nService i18nService;

@ApiModelProperty("是否成功")
private boolean success;

@ApiModelProperty("返回码")
private Integer code;

@ApiModelProperty("错误信息")
private String errorMsg;

@ApiModelProperty("请求成功返回的数据")
private T data;

@ApiModelProperty("请求 ID")
private String requestId;

@ApiModelProperty("鉴权结果,当返回码为1238001时,该字段有值")
@JsonProperty("authResult")
private AuthResult authResult;

@ApiModelProperty("错误详情")
@JsonProperty("errorDetail")
private ErrorDetail errorDetail;

public InnerServiceResponse(Integer code, String errorMsg, T data) {
this.code = code;
this.errorMsg = errorMsg;
this.data = data;
this.requestId = JobContextUtil.getRequestId();
}

private static MessageI18nService getI18nService() {
if (i18nService == null) {
synchronized (InnerServiceResponse.class) {
if (i18nService == null) {
i18nService = ApplicationContextRegister.getBean(MessageI18nService.class);
}
}
}
return i18nService;
}

public static <T> InnerServiceResponse<T> buildSuccessResp(T data) {
InnerServiceResponse<T> resp = new InnerServiceResponse<>(SUCCESS_CODE, null, data);
resp.success = true;
return resp;
}

public static <T> InnerServiceResponse<T> buildAuthFailResp(AuthResult authResult) {
MessageI18nService i18nService = getI18nService();
String message = null;
if (i18nService != null) {
message = i18nService.getI18n(String.valueOf(ErrorCode.USER_NO_PERMISSION_COMMON));
} else {
log.warn("cannot find available i18nService");
}
InnerServiceResponse<T> resp = new InnerServiceResponse<T>(ErrorCode.USER_NO_PERMISSION_COMMON, message, null);
resp.success = false;
resp.authResult = authResult;
return resp;
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(String msg) {
InnerServiceResponse<T> resp = new InnerServiceResponse<>(COMMON_FAIL_CODE, msg, null);
resp.success = false;
return resp;
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(Integer errorCode, String msg) {
InnerServiceResponse<T> resp = new InnerServiceResponse<>(errorCode, msg, null);
resp.success = false;
return resp;
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(Integer errorCode) {
try {
getI18nService();
} catch (Exception e) {
log.warn("cannot get i18nService from spring context");
}
String errorMsg = null;
if (i18nService != null) {
errorMsg = i18nService.getI18n(errorCode.toString());
}
InnerServiceResponse<T> resp = new InnerServiceResponse<>(errorCode, errorMsg, null);
resp.success = false;
return resp;
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(Integer errorCode, MessageI18nService i18nService) {
String errorMsg = i18nService.getI18n(String.valueOf(errorCode));
if (StringUtils.isEmpty(errorMsg)) {
errorMsg = String.valueOf(errorCode);
}
InnerServiceResponse<T> resp = new InnerServiceResponse<>(errorCode, errorMsg, null);
resp.success = false;
return resp;
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(Integer errorCode, Object[] params) {
getI18nService();
return buildCommonFailResp(errorCode, params, i18nService);
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(Integer errorCode, Object[] params,
MessageI18nService i18nService) {
String errorMsg = "";
if (params != null && params.length > 0) {
errorMsg = i18nService.getI18nWithArgs(String.valueOf(errorCode), params);
} else {
errorMsg = i18nService.getI18n(String.valueOf(errorCode));
}
if (StringUtils.isEmpty(errorMsg)) {
errorMsg = String.valueOf(errorCode);
}
InnerServiceResponse<T> resp = new InnerServiceResponse<>(errorCode, errorMsg, null);
resp.success = false;
return resp;
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(ServiceException e, MessageI18nService i18nService) {
log.info("exception: {}|{}|{}", e.getErrorCode(), e.getErrorMsg(), e.getErrorParams());
int errorCode = e.getErrorCode();
String errorMsg = e.getErrorMsg();
if (StringUtils.isEmpty(errorMsg)) {
errorMsg = i18nService.getI18nWithArgs(String.valueOf(errorCode), e.getErrorParams());
log.info("{}", errorMsg);
}
if (StringUtils.isEmpty(errorMsg)) {
errorMsg = String.valueOf(errorCode);
}
return new InnerServiceResponse<>(e.getErrorCode(), errorMsg, null);
}

public static <T> InnerServiceResponse<T> buildValidateFailResp(MessageI18nService i18nService,
ValidateResult validateResult) {
if (validateResult.getErrorParams() != null && validateResult.getErrorParams().length > 0) {
return InnerServiceResponse.buildCommonFailResp(validateResult.getErrorCode(),
i18nService.getI18nWithArgs(String.valueOf(validateResult.getErrorCode()),
validateResult.getErrorParams()));
} else {
return InnerServiceResponse.buildCommonFailResp(validateResult.getErrorCode(),
i18nService.getI18n(String.valueOf(validateResult.getErrorCode())));
}
}

public static <T> InnerServiceResponse<T> buildCommonFailResp(int errorCode, ErrorDetail errorDetail,
MessageI18nService i18nService) {
String errorMsg = i18nService.getI18n(String.valueOf(errorCode));
InnerServiceResponse<T> esbResp = new InnerServiceResponse<>(errorCode, errorMsg, null);
esbResp.setErrorDetail(errorDetail);
return esbResp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,12 @@ public class ErrorCode {
// 文件网关 start
// 文件源不存在:{0}
public static final int FILE_SOURCE_NOT_EXIST = 1260001;
// 接入点响应异常:ListBucket,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_LIST_BUCKET = 1260002;
// 接入点响应异常:ListObjects,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_LIST_OBJECTS = 1260003;
// 接入点响应异常:DeleteBucket,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_DELETE_BUCKET = 1260008;
// 接入点响应异常:DeleteBucketFile,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_DELETE_BUCKET_FILE = 1260009;
// 接入点响应异常:ListFileNode,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_LIST_FILE_NODE = 1260002;
// 接入点响应异常:FileAvailable,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_FILE_AVAILABLE = 1260003;
// 接入点响应异常:ExecuteAction,详情:{0}
public static final int FAIL_TO_REQUEST_FILE_WORKER_EXECUTE_ACTION = 1260008;

// 文件源别名已存在:{0}
public static final int FILE_SOURCE_ALIAS_ALREADY_EXISTS = 1260004;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
compile project(':commons:common')
compile project(':commons:common-i18n')
compile project(':commons:common-iam')
compile project(':commons:esb-sdk')
compile project(":job-logsvr:api-job-logsvr")
compile project(":job-file-gateway:api-job-file-gateway-worker")
implementation "org.springframework:spring-web"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.file_gateway.api.esb;

import com.tencent.bk.job.common.annotation.EsbAPI;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbCreateOrUpdateFileSourceV3Req;
import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceSimpleInfoV3DTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 文件源API-V3
*/
@RequestMapping("/esb/api/v3")
@RestController
@EsbAPI
public interface EsbFileSourceV3Resource {

@PostMapping("/create_file_source")
EsbResp<EsbFileSourceSimpleInfoV3DTO> createFileSource(
@RequestBody EsbCreateOrUpdateFileSourceV3Req req);

@PostMapping("/update_file_source")
EsbResp<EsbFileSourceSimpleInfoV3DTO> updateFileSource(
@RequestBody EsbCreateOrUpdateFileSourceV3Req req);

}
Loading

0 comments on commit b271b3f

Please sign in to comment.