Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tencent/bk-job into issue…
Browse files Browse the repository at this point in the history
…_2631
  • Loading branch information
wangyu096 committed Jan 26, 2024
2 parents c6db8f0 + 4db7c68 commit 67352e8
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 3 deletions.
54 changes: 54 additions & 0 deletions docs/apidoc/bk-api-gateway/v3/zh/get_latest_service_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
### 功能描述

查询作业平台最新服务版本号

### 请求参数

{{ bkapi_authorization_description }}

#### Header参数

| 字段 | 类型 | 必选 | 描述 |
|-----------|------------|--------|------------|
| X-Bkapi-Authorization | string || 认证信息。详情参考[调用网关 API](https://github.com/TencentBlueKing/BKDocs/blob/master/ZH/7.0/APIGateway/apigateway/use-api/use-apigw-api.md) |
| Accept | string || 固定值。application/json|
| Content-Type | string || 固定值。application/json|

#### Query参数


### 请求参数示例

- GET
```json
/api/v3/get_latest_service_version
```

### 返回结果示例
```json
{
"result": true,
"code": 0,
"message": "success",
"data": {
"version": "3.6.4"
}
}
```

### 返回结果参数说明

| 字段 | 类型 | 描述 |
|-----------|-----------|-----------|
| result | bool | 请求成功与否。true:请求成功;false请求失败 |
| code | int | 错误编码。 0表示success,>0表示失败错误 |
| message | string | 请求失败返回的错误信息|
| data | object | 请求返回的数据|
| permission | object | 权限信息|

##### data

| 字段 | 类型 | 描述 |
|-----------|-----------|-----------|
| version | string |服务最新版本号|
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### Function Description

Query the latest service version

### Request Parameters

{{ common_args_desc }}

#### Interface parameters

null

### Example of request

```json
{
"bk_app_code": "esb_test",
"bk_app_secret": "xxx",
"bk_token": "xxx",
"bk_username": "admin"
}
```

### Example of responses

```json
{
"result": true,
"code": 0,
"message": "success",
"data": {
"version": "3.6.4"
}
}
```

### Response Description

#### response
| Fields | Type | Description |
|-----------|-----------|-----------|
| result | bool | Whether the request succeeded or not. True: request succeeded;False: request failed|
| code | int | Error code. 0 indicates success, >0 indicates failure|
| message | string |Error message|
| data | object |Data returned by request|
| permission | object |Permission information|
| request_id | string |Request chain id|

#### data

| Fields | Type | Description |
|-----------|-----------|-----------|
| version | string |The latest version number of the service|
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### 功能描述

查询作业平台最新的服务版本号。

### 请求参数

{{ common_args_desc }}

#### 接口参数


### 请求参数示例

```json
{
"bk_app_code": "esb_test",
"bk_app_secret": "xxx",
"bk_token": "xxx",
"bk_username": "admin"
}
```

### 返回结果示例

```json
{
"result": true,
"code": 0,
"message": "success",
"data": {
"version": "3.6.4"
}
}
```

### 返回结果参数说明

#### response

| 字段 | 类型 | 描述 |
| ---------- | ------ | ------------------------------------------ |
| result | bool | 请求成功与否。true:请求成功;false请求失败 |
| code | int | 错误编码。 0表示success,>0表示失败错误 |
| message | string | 请求失败返回的错误信息 |
| data | object | 请求返回的数据 |
| permission | object | 权限信息 |

#### data

| 字段 | 类型 | 描述 |
|-----------|-----------|-----------|
| version | string |服务最新版本号|
10 changes: 10 additions & 0 deletions docs/apidoc/esb/jobv3-confapis/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,13 @@
comp_codename: generic.v2.jobv3.job_component
dest_path: /api/job/v3/job-manage/check_script/
dest_http_method: POST

- path: /esb/api/v3/get_latest_service_version/
name: get_latest_service_version
label: 查询最新服务版本号
label_en: Get latest service version
suggest_method: POST
api_type: operate
comp_codename: generic.v2.jobv3.job_component
dest_path: /esb/api/v3/get_latest_service_version/
dest_http_method: POST
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private static int compareElement(String ele1, String ele2) {
* -1 : version1在version2之前
*/
public static int compareVersion(String version1, String version2) {
version1 = removeLeadingLetters(version1);
version2 = removeLeadingLetters(version2);
// 标准化为点分形式
version1 = version1.replace("-", ".").toLowerCase();
version2 = version2.replace("-", ".").toLowerCase();
Expand All @@ -118,8 +120,18 @@ public static int compareVersion(String version1, String version2) {
int result = compareElement(arr1[i].trim(), arr2[i].trim());
if (result != 0) return result;
}
if (len1 < len2) return -1;
else if (len1 > len2) return 1;
// 特殊情况处理,比如3.3.3>3.3.3-beta.1,3.3.3.1>3.3.3-beta.1
if (len1 < len2) {
if (!isNumberStr(arr2[shortLen])) {
return 1;
}
return -1;
} else if (len1 > len2) {
if (!isNumberStr(arr1[shortLen])) {
return -1;
}
return 1;
}
return 0;
}

Expand Down Expand Up @@ -148,4 +160,11 @@ public static int safeCompareNullBack(Comparable p1, Comparable p2) {
}
return p1.compareTo(p2);
}

/**
* 去掉版本号开头的字母,v1.0 -> 1.0
*/
public static String removeLeadingLetters(String version) {
return version.replaceFirst("^[a-zA-Z]+", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void testCompareVersion() {
assertThat(CompareUtil.compareVersion("3.3.3.beta.10", "3.3.3.rc")).isEqualTo(-1);
assertThat(CompareUtil.compareVersion("3.3.3.rc", "3.3.3.0")).isEqualTo(-1);
assertThat(CompareUtil.compareVersion("3.3.3.rc.2", "3.3.3.0")).isEqualTo(-1);
assertThat(CompareUtil.compareVersion("3.3.3", "3.3.3.alpha")).isEqualTo(-1);
assertThat(CompareUtil.compareVersion("3.3.3", "3.3.3.alpha")).isEqualTo(1);

assertThat(CompareUtil.compareVersion("3.3.3.10", "3.3.3.2")).isEqualTo(1);
assertThat(CompareUtil.compareVersion("3.3.3.alpha.1", "3.3.3.alpha")).isEqualTo(1);
Expand All @@ -84,5 +84,11 @@ void testCompareVersion() {
assertThat(CompareUtil.compareVersion("3.3.3-alpha.1", "3.3.3-alpha.1")).isEqualTo(0);
assertThat(CompareUtil.compareVersion("3.3.3.alpha", "3.3.3.alpha")).isEqualTo(0);
assertThat(CompareUtil.compareVersion("3.3.3.alpha.1", "3.3.3.alpha.1")).isEqualTo(0);

assertThat(CompareUtil.compareVersion("3.3.3", "3.3.3-alpha.1")).isEqualTo(1);
assertThat(CompareUtil.compareVersion("3.3.3-beta.1", "3.3.3-alpha.1")).isEqualTo(1);
assertThat(CompareUtil.compareVersion("3.3.3-rc.1", "3.3.3-alpha.1")).isEqualTo(1);
assertThat(CompareUtil.compareVersion("3.3.3", "3.3.3-rc.1")).isEqualTo(1);
assertThat(CompareUtil.compareVersion("v3.3.3", "3.3.3")).isEqualTo(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.manage.api.esb.v3;

import com.tencent.bk.job.common.annotation.EsbAPI;
import com.tencent.bk.job.common.constant.JobCommonHeaders;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.manage.model.esb.v3.response.EsbServiceVersionV3DTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 服务信息API-V3
*/
@RequestMapping("/esb/api/v3")
@RestController
@EsbAPI
public interface EsbServiceInfoV3Resource {

@GetMapping("/get_latest_service_version")
EsbResp<EsbServiceVersionV3DTO> getLatestServiceVersion(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode
);

@PostMapping("/get_latest_service_version")
EsbResp<EsbServiceVersionV3DTO> getLatestServiceVersionUsingPost(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.manage.model.esb.v3.response;

import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode
public class EsbServiceVersionV3DTO {
/**
* 服务版本号
*/
@JsonPropertyDescription("Service Version")
private String version;
}
Loading

0 comments on commit 67352e8

Please sign in to comment.