Skip to content

Commit

Permalink
feat: Job Open API 支持容器执行 TencentBlueKing#2774
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Mar 19, 2024
1 parent 562914f commit 546a25c
Show file tree
Hide file tree
Showing 11 changed files with 520 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@

| 字段 | 类型 | 必选 | 描述 |
|-----------|------------|--------|------------|
| pod_name_list | array || pod 名称列表 |
| pod_name_list | array || pod 名称列表 |
| label_selector | array || label 选择计算表达式列表,多个表达式之间为 AND 关系。表达式 见 lable_select_expr 定义 |

##### lable_select_expr

| 字段 | 类型 | 必选 | 描述 |
|-----------|------------|--------|------------|
| label_key | string || lable key |
| operator | string || 计算操作符, 支持 equals、not_equals、in、not_in、exists |
| label_value | string || lable value, 当计算操作符为 equals、not_equals 时候需要设置 |
| label_values | string || lable value 列表, 当计算操作符为 in、not_in 时候需要设置 |

##### kube_container_prop_filter

Expand Down Expand Up @@ -180,6 +190,21 @@
"pod_name_list": [
"bk-job-execute-6fcd8cf5c7-jvctq",
"bk-job-manage-6fcd8cf5c7-abues"
],
"label_selector": [
{
"lable_key": "application",
"operator": "in",
"lable_values": [
"job-execute",
"job-manage"
]
},
{
"lable_key": "env",
"operator": "equals",
"lable_value": "prod"
}
]
},
"kube_container_prop_filter": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.cc.constants;

/**
* 容器拓扑节点资源类型
*/
public enum KubeTopoNodeTypeEnum {
CLUSTER("cluster"),
NAMESPACE("namespace"),
DEPLOYMENT("deployment"),
DAEMON_SET("daemonSet"),
STATEFUL_SET("statefulSet"),
CRON_JOB("cronJob"),
JOB("job");

private final String value;

KubeTopoNodeTypeEnum(String val) {
this.value = val;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.tencent.bk.job.common.cc.model;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -51,4 +52,8 @@ public class PropertyFilterDTO {
public void addRule(IRule rule) {
this.rules.add(rule);
}

public boolean hasRule() {
return CollectionUtils.isNotEmpty(rules);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.cc.model.query;

import lombok.Getter;
import lombok.ToString;

import java.util.List;

/**
* 容器集群查询
*/
@Getter
@ToString
public class KubeClusterQuery {
private final Long bizId;

private final List<Long> ids;

private final List<String> bkClusterUIDs;

private KubeClusterQuery(Builder builder) {
bizId = builder.bizId;
ids = builder.ids;
bkClusterUIDs = builder.bkClusterUIDs;
}


public static final class Builder {
private final Long bizId;
private List<Long> ids;
private List<String> bkClusterUIDs;

private Builder(long bizId) {
this.bizId = bizId;
}

public static Builder builder(long bizId) {
return new Builder(bizId);
}

public Builder ids(List<Long> ids) {
this.ids = ids;
return this;
}

public Builder bkClusterUIDs(List<String> bkClusterUIDs) {
this.bkClusterUIDs = bkClusterUIDs;
return this;
}

public KubeClusterQuery build() {
return new KubeClusterQuery(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.cc.model.query;

import lombok.Getter;
import lombok.ToString;

import java.util.List;

/**
* namespace 查询
*/
@Getter
@ToString
public class NamespaceQuery {
private final Long bizId;

private final List<Long> ids;

private final List<String> names;

private final List<Long> bkClusterIds;

private NamespaceQuery(Builder builder) {
bizId = builder.bizId;
ids = builder.ids;
names = builder.names;
bkClusterIds = builder.bkClusterIds;
}


public static final class Builder {
private final Long bizId;
private List<Long> ids;
private List<String> names;
private List<Long> bkClusterIds;

private Builder(long bizId) {
this.bizId = bizId;
}

public static Builder builder(long bizId) {
return new Builder(bizId);
}

public Builder ids(List<Long> ids) {
this.ids = ids;
return this;
}

public Builder names(List<String> names) {
this.names = names;
return this;
}

public Builder bkClusterIds(List<Long> bkClusterIds) {
this.bkClusterIds = bkClusterIds;
return this;
}

public NamespaceQuery build() {
return new NamespaceQuery(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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.cc.model.query;

import lombok.Getter;
import lombok.ToString;

import java.util.List;

/**
* workload 查询
*/
@Getter
@ToString
public class WorkloadQuery {
private final Long bizId;

private final List<Long> ids;

private final List<String> names;

private final List<Long> bkClusterIds;

private final List<Long> bkNamespaceIds;

private final String kind;

private WorkloadQuery(Builder builder) {
bizId = builder.bizId;
ids = builder.ids;
names = builder.names;
bkClusterIds = builder.bkClusterIds;
bkNamespaceIds = builder.bkNamespaceIds;
kind = builder.kind;
}


public static final class Builder {
private final Long bizId;
private List<Long> ids;
private List<String> names;
private List<Long> bkClusterIds;
private List<Long> bkNamespaceIds;
private final String kind;

private Builder(long bizId, String kind) {
this.bizId = bizId;
this.kind = kind;
}

public static Builder builder(long bizId, String kind) {
return new Builder(bizId, kind);
}

public Builder ids(List<Long> ids) {
this.ids = ids;
return this;
}

public Builder names(List<String> names) {
this.names = names;
return this;
}

public Builder bkClusterIds(List<Long> bkClusterIds) {
this.bkClusterIds = bkClusterIds;
return this;
}

public Builder bkNamespaceIds(List<Long> bkNamespaceIds) {
this.bkNamespaceIds = bkNamespaceIds;
return this;
}

public WorkloadQuery build() {
return new WorkloadQuery(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public class BaseCmdbApiClient {
protected static final String LIST_KUBE_CONTAINER_BY_TOPO = "/api/v3/findmany/kube/container/by_topo";
protected static final String GET_BIZ_KUBE_CACHE_TOPO = "/api/v3/cache/find/biz/kube/topo";
protected static final String LIST_KUBE_CLUSTER = "/api/v3/findmany/kube/cluster";
protected static final String LIST_KUBE_NAMESPACE = "/api/v3/cache/find/biz/kube/namespace";
protected static final String LIST_KUBE_WORKLOAD = "/api/v3/cache/find/biz/kube/workload";
protected static final String LIST_KUBE_NAMESPACE = "/api/v3/findmany/kube/namespace";
protected static final String LIST_KUBE_WORKLOAD = "/api/v3/findmany/kube/workload/{kind}";

// 业务集相关 API
protected static final String SEARCH_BUSINESS_SET = "/api/c/compapi/v2/cc/list_business_set/";
Expand Down
Loading

0 comments on commit 546a25c

Please sign in to comment.