Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 定时任务ESB接口,返回的expression字段不对 #2724 #2728

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public static ServiceTemplateNotificationDTO buildNotifyInfo(CronJobInfoDTO cron
// 结束前通知
notifyInfo.setTemplateCode(NotifyConsts.NOTIFY_TEMPLATE_CODE_BEFORE_CRON_JOB_END);
variableMap.put("cron_type", "周期执行");
String cronRuleStr = cronJobInfo.getCronExpression().substring(2).replace("?", "*");
String cronRuleStr = CronExpressionUtil.fixExpressionForUser(cronJobInfo.getCronExpression());
variableMap.put("cron_rule", cronRuleStr);
triggerTime = cronJobInfo.getEndTime() - cronJobInfo.getNotifyOffset();
variableMap.put("task.cron.repeat_freq", "周期执行");
Expand Down Expand Up @@ -445,7 +445,7 @@ public static ServiceTemplateNotificationDTO buildFailedNotifyInfo(CronJobInfoDT
if (StringUtils.isNotBlank(cronJobInfo.getCronExpression())) {
// 结束前通知
variableMap.put("task.cron.type", "周期执行");
String cronRuleStr = cronJobInfo.getCronExpression().substring(2).replace("?", "*");
String cronRuleStr = CronExpressionUtil.fixExpressionForUser(cronJobInfo.getCronExpression());
variableMap.put("task.cron.rule", cronRuleStr);
variableMap.put("task.cron.repeat_freq", "周期执行");
variableMap.put("task.cron.time_set", cronRuleStr);
Expand Down Expand Up @@ -483,7 +483,7 @@ public static EsbCronInfoV3DTO toEsbCronInfoV3(CronJobInfoDTO cronJobInfoDTO) {
esbCronInfoResponse.setStatus(cronJobInfoDTO.getEnable() ? 1 : 0);
if (StringUtils.isNotBlank(cronJobInfoDTO.getCronExpression())) {
esbCronInfoResponse.setCronExpression(
cronJobInfoDTO.getCronExpression().substring(2).replace("?", "*"));
CronExpressionUtil.fixExpressionForUser(cronJobInfoDTO.getCronExpression()));
}
esbCronInfoResponse.setCreator(cronJobInfoDTO.getCreator());
esbCronInfoResponse.setCreateTime(cronJobInfoDTO.getCreateTime());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.api.constant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* 定时任务状态
*/
public enum CronStatusEnum {
RUNNING(1), STOPPING(2);


@JsonValue
private final Integer status;

CronStatusEnum(Integer status) {
this.status = status;
}

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static CronStatusEnum valOf(int cronStatus) {
for (CronStatusEnum status : values()) {
if (status.getStatus() == cronStatus) {
return status;
}
}
return null;
}

public Integer getStatus() {
return status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ErrorCode {
public static final int ILLEGAL_PARAM_WITH_PARAM_NAME = 1241005; //请求参数[]不合法
public static final int MISSING_OR_ILLEGAL_PARAM = 1241006; //请求参数缺失或不合法
public static final int MISSING_OR_ILLEGAL_PARAM_WITH_PARAM_NAME = 1241007; //请求参数[]缺失或不合法
public static final int ILLEGAL_PARAM_WITH_PARAM_NAME_AND_REASON = 1241010; // 请求参数[0]不合法,原因:[1]


public static final int SCRIPT_NOT_EXIST = 1243001;//脚本不存在
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import com.tencent.bk.job.api.props.TestProps;
import com.tencent.bk.job.api.v3.constants.APIV3Urls;
import com.tencent.bk.job.api.v3.model.EsbAccountV3BasicDTO;
import com.tencent.bk.job.api.v3.model.EsbCronInfoV3DTO;
import com.tencent.bk.job.api.v3.model.EsbDangerousRuleV3DTO;
import com.tencent.bk.job.api.v3.model.EsbFileSourceV3DTO;
import com.tencent.bk.job.api.v3.model.EsbJobExecuteV3DTO;
import com.tencent.bk.job.api.v3.model.EsbPageDataV3;
import com.tencent.bk.job.api.v3.model.EsbPlanBasicInfoV3DTO;
import com.tencent.bk.job.api.v3.model.EsbScriptVersionDetailV3DTO;
import com.tencent.bk.job.api.v3.model.EsbServerV3DTO;
import com.tencent.bk.job.api.v3.model.HostDTO;
Expand All @@ -23,7 +26,9 @@
import com.tencent.bk.job.api.v3.model.request.EsbExecuteJobV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbFastExecuteScriptV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbFastTransferFileV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbGetPlanListV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbManageDangerousRuleV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbSaveCronV3Request;
import io.restassured.common.mapper.TypeRef;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -302,6 +307,54 @@ public static EsbJobExecuteV3DTO executePlanTask() {
.getData();
}

public static EsbCronInfoV3DTO createCron() {
Long planId = getTaskPlanId();
if (planId == null) {
return null;
}
EsbSaveCronV3Request req = new EsbSaveCronV3Request();
req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ));
req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue());
req.setName(TestValueGenerator.generateUniqueStrValue("cron_task", 50));
req.setCronExpression("* * * * *");
req.setPlanId(planId);
return given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.SAVE_CRON)
.then()
.statusCode(200)
.extract()
.body()
.as(new TypeRef<EsbResp<EsbCronInfoV3DTO>>() {
})
.getData();
}

public static Long getTaskPlanId() {
EsbGetPlanListV3Request req = new EsbGetPlanListV3Request();
req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ));
req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue());
req.setLength(1);
EsbPageDataV3<EsbPlanBasicInfoV3DTO> data = given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.GET_JOB_PLAN_LIST)
.then()
.statusCode(200)
.extract()
.body()
.as(new TypeRef<EsbResp<EsbPageDataV3<EsbPlanBasicInfoV3DTO>>>() {
})
.getData();
List<EsbPlanBasicInfoV3DTO> planList = data.getData();
if (planList != null && planList.size() > 0) {
EsbPlanBasicInfoV3DTO planBasicInfoV3DTO = planList.get(0);
return planBasicInfoV3DTO.getId();
}
return null;
}

private static String buildJobName() {
return "api.test." + DateUtils.formatLocalDateTime(LocalDateTime.now(), "yyyyMMddhhmmssSSS");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ public interface APIV3Urls {
String EXECUTE_JOB_PLAN = "/api/job/v3/job-execute/execute_job_plan";
String GET_STEP_INSTANCE_DETAIL = "/api/job/v3/job-execute/get_step_instance_detail";
String GET_STEP_INSTANCE_STATUS = "/api/job/v3/job-execute/get_step_instance_status";

String SAVE_CRON = "/api/job/v3/job-crontab/save_cron";
String GET_CRON_LIST = "/api/job/v3/job-crontab/get_cron_list";
String UPDATE_CRON_STATUS = "/api/job/v3/job-crontab/update_cron_status";
String GET_CRON_DETAIL = "/api/job/v3/job-crontab/get_cron_detail";

String GET_JOB_PLAN_LIST = "/api/job/v3/job-manage/get_job_plan_list";
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.tencent.bk.job.api.v3.model.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.api.model.BaseEsbReq;
import com.tencent.bk.job.api.model.EsbAppScopeReq;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class EsbBaseListRequest extends BaseEsbReq {
public class EsbBaseListRequest extends EsbAppScopeReq {

/**
* 业务 ID
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.api.v3.model.request;

import com.tencent.bk.job.api.model.EsbAppScopeReq;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @since 26/2/2020 16:29
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class EsbGetCronDetailV3Request extends EsbAppScopeReq {

/**
* 定时任务ID
* <p>
* 如果存在则忽略其他筛选条件,只查询这个指定的作业信息
*/
private Long id;

public boolean validate() {
if (id == null || id <= 0) {
return false;
}
return true;
}
}
Loading
Loading