Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#2663 from wangyu096/issue_2643
Browse files Browse the repository at this point in the history
feature: 轻量化部署优化 TencentBlueKing#2643
  • Loading branch information
wangyu096 authored Feb 2, 2024
2 parents dbc08fd + c63bb5f commit e1e13c1
Show file tree
Hide file tree
Showing 43 changed files with 124 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ public IamAppTransferAspect(AppScopeMappingService appScopeMappingService) {
this.appScopeMappingService = appScopeMappingService;
}

@Pointcut("execution (* com.tencent.bk.job.common.iam.service.impl.BusinessAuthServiceImpl.auth*(..))")
@Pointcut("within(com.tencent.bk.job.common.iam.service.impl.BusinessAuthServiceImpl) " +
"&& execution (* com.tencent.bk.job.common.iam.service.impl.BusinessAuthServiceImpl.auth*(..))")
public void processAuthBusinessAction() {
}

@Pointcut("execution (* com.tencent.bk.job.*.auth..impl.*.auth*(..))")
@Pointcut("within(com.tencent.bk.job..*) " +
"&& execution (* com.tencent.bk.job.*.auth..impl.*.auth*(..))")
public void processAuthResourceAction() {
}

@Pointcut("execution (* com.tencent.bk.job.*.auth..impl.*.batchAuth*(..))")
@Pointcut("within(com.tencent.bk.job..*) " +
"&& execution (* com.tencent.bk.job.*.auth..impl.*.batchAuth*(..))")
public void processBatchAuthResourceAction() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class IamCallbackAspect {
public IamCallbackAspect() {
}

@Pointcut("execution (* com.tencent.bk.job.*.api.iam.impl.*.callback(..))")
@Pointcut("within(com.tencent.bk.job..*) && execution (* com.tencent.bk.job.*.api.iam.impl.*.callback(..))")
public void processCallbackRequest() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
@Aspect
public class IamExceptionHandleAspect {

@Pointcut("execution (* com.tencent.bk.sdk.iam.service.impl.PolicyServiceImpl.*(..))")
@Pointcut("within(com.tencent.bk.sdk.iam.service.impl.PolicyServiceImpl) " +
"&& execution (* com.tencent.bk.sdk.iam.service.impl.PolicyServiceImpl.*(..))")
public void processPolicyServiceAction() {
}

@Pointcut("execution (* com.tencent.bk.sdk.iam.helper.AuthHelper.isAllowed(..))")
@Pointcut("within(com.tencent.bk.sdk.iam.helper.AuthHelper) " +
"&& execution (* com.tencent.bk.sdk.iam.helper.AuthHelper.isAllowed(..))")
public void processIsAllowedAction() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.mysql.config;
package com.tencent.bk.job.common.mysql;

import org.jooq.DSLContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
/**
* Job 自定义事务注解
*/
@Transactional
public @interface JobTransactional {
@AliasFor(annotation = Transactional.class)
String transactionManager();

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(DSLContext.class)
@ConditionalOnBean(DataSource.class)
public class JobMySQLAutoConfiguration {
@AliasFor(annotation = Transactional.class)
Class<? extends Throwable>[] rollbackFor() default {Throwable.class};

@AliasFor(annotation = Transactional.class)
int timeout() default TransactionDefinition.TIMEOUT_DEFAULT;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public EsbAppResourceScopeReqAspect(AppScopeMappingService appScopeMappingServic
this.appScopeMappingService = appScopeMappingService;
}

@Before("execution(* com.tencent.bk.job.*.api.esb..*.*(..)))")
@Before("within(com.tencent.bk.job..*) && execution(* com.tencent.bk.job.*.api.esb..*.*(..)))")
public void handleAppScopeReq(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
for (Object arg : args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Tag exception(Throwable exception) {
return EXCEPTION_NONE;
}

@Around("execution (@com.tencent.bk.job.common.esb.metrics.EsbApiTimed * *.*(..))")
@Around("within(com.tencent.bk.job..*) && execution (@com.tencent.bk.job.common.esb.metrics.EsbApiTimed * *.*(..))")
public Object timedMethod(ProceedingJoinPoint pjp) throws Throwable {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
HttpServletRequest request = null;
Expand Down
1 change: 1 addition & 0 deletions src/backend/job-crontab/service-job-crontab/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
api project(":commons:common-redis")
api project(":commons:common-web")
api project(':commons:common-security')
api project(':commons:common-mysql')
api project(":job-execute:api-job-execute")
api project(":job-manage:api-job-manage")
api project(":job-crontab:api-job-crontab")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.tencent.bk.job.common.exception.InvalidParamException;
import com.tencent.bk.job.common.model.BaseSearchCondition;
import com.tencent.bk.job.common.model.InternalResponse;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.util.JobContextUtil;
import com.tencent.bk.job.common.util.date.DateUtils;
import com.tencent.bk.job.common.util.json.JsonUtils;
Expand All @@ -43,7 +44,6 @@
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
Expand Down Expand Up @@ -116,7 +116,7 @@ public InternalResponse<Map<Long, List<CronJobVO>>> batchListCronJobByPlanIds(Lo
}

@Override
@Transactional(value = "jobCrontabTransactionManager", rollbackFor = {Throwable.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
public InternalResponse<Long> saveCronJobWithId(String username, Long appId, Long cronJobId, Long createTime,
Long lastModifyTime, String lastModifyUser,
CronJobCreateUpdateReq cronJobCreateUpdateReq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

package com.tencent.bk.job.crontab.service.impl;

import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.crontab.model.dto.CronJobBasicInfoDTO;
import com.tencent.bk.job.crontab.service.CronJobBatchLoadService;
import com.tencent.bk.job.crontab.service.CronJobService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -48,7 +48,7 @@ public CronJobBatchLoadServiceImpl(CronJobService cronJobService) {
}

@Override
@Transactional(rollbackFor = {Exception.class, Error.class}, timeout = 30)
@JobTransactional(transactionManager = "jobCrontabTransactionManager", timeout = 30)
public CronLoadResult batchLoadCronToQuartz(int start, int limit) {
int successNum = 0;
int failedNum = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.tencent.bk.job.common.model.PageData;
import com.tencent.bk.job.common.model.dto.AppResourceScope;
import com.tencent.bk.job.common.model.dto.HostDTO;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.util.JobContextUtil;
import com.tencent.bk.job.common.util.date.DateUtils;
import com.tencent.bk.job.common.util.json.JsonUtils;
Expand Down Expand Up @@ -84,7 +85,6 @@
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.time.Instant;
Expand Down Expand Up @@ -200,7 +200,7 @@ public boolean updateCronJobErrorById(CronJobInfoDTO cronJobErrorInfo) {
}

@Override
@Transactional(value = "jobCrontabTransactionManager", rollbackFor = {Exception.class, Error.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
@ActionAuditRecord(
actionId = ActionId.CREATE_CRON,
instance = @AuditInstanceRecord(
Expand All @@ -227,7 +227,7 @@ public CronJobInfoDTO createCronJobInfo(String username, CronJobInfoDTO cronJobI
}

@Override
@Transactional(rollbackFor = {Exception.class, Error.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
@ActionAuditRecord(
actionId = ActionId.MANAGE_CRON,
instance = @AuditInstanceRecord(
Expand Down Expand Up @@ -393,7 +393,7 @@ public Boolean deleteCronJobInfo(String username, Long appId, Long cronJobId) {
}

@Override
@Transactional(value = "jobCrontabTransactionManager", rollbackFor = {Exception.class, Error.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
@ActionAuditRecord(
actionId = ActionId.MANAGE_CRON,
instance = @AuditInstanceRecord(
Expand Down Expand Up @@ -452,7 +452,7 @@ public Boolean changeCronJobEnableStatus(String username, Long appId, Long cronJ
}

@Override
@Transactional(value = "jobCrontabTransactionManager", rollbackFor = {Exception.class, Error.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
public Boolean disableExpiredCronJob(Long appId, Long cronJobId, String lastModifyUser, Long lastModifyTime) {
CronJobInfoDTO cronJobInfo = new CronJobInfoDTO();
cronJobInfo.setAppId(appId);
Expand Down Expand Up @@ -508,7 +508,7 @@ public Map<Long, List<CronJobInfoDTO>> listCronJobByPlanIds(Long appId, List<Lon
}

@Override
@Transactional(value = "jobCrontabTransactionManager", rollbackFor = {Error.class, Exception.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
public Boolean addInnerJob(ServiceAddInnerCronJobRequestDTO request) {
if (!request.validate()) {
return false;
Expand Down Expand Up @@ -600,7 +600,7 @@ public Boolean deleteInnerCronJob(String systemId, String jobKey) {
}

@Override
@Transactional(value = "jobCrontabTransactionManager", rollbackFor = {Exception.class, Error.class})
@JobTransactional(transactionManager = "jobCrontabTransactionManager")
@ActionAuditRecord(
actionId = ActionId.MANAGE_CRON,
instance = @AuditInstanceRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import com.tencent.bk.job.common.constant.ErrorCode;
import com.tencent.bk.job.common.exception.InternalException;
import com.tencent.bk.job.common.util.file.FileUtil;
import com.tencent.bk.job.common.util.JobUUID;
import com.tencent.bk.job.common.util.file.FileUtil;
import com.tencent.bk.job.execute.engine.consts.FileDirTypeConf;
import com.tencent.bk.job.execute.engine.util.NFSUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import com.tencent.bk.job.common.artifactory.model.dto.NodeDTO;
import com.tencent.bk.job.common.artifactory.sdk.ArtifactoryClient;
import com.tencent.bk.job.common.util.file.FileUtil;
import com.tencent.bk.job.common.util.TimeUtil;
import com.tencent.bk.job.common.util.file.FileUtil;
import com.tencent.bk.job.common.util.file.PathUtil;
import com.tencent.bk.job.execute.constants.Consts;
import com.tencent.bk.job.execute.model.FileDetailDTO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
dependencies {
api project(":commons:common-web")
api project(":commons:common-redis")
api project(":commons:common-mysql")
api project(":job-manage:api-job-manage")
api project(":job-file-worker-sdk:api-job-file-worker-sdk")
api project(":job-file-gateway:api-job-file-gateway")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.tencent.bk.job.common.exception.ServiceException;
import com.tencent.bk.job.common.model.Response;
import com.tencent.bk.job.common.model.http.HttpReq;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.util.http.JobHttpClient;
import com.tencent.bk.job.common.util.json.JsonUtils;
import com.tencent.bk.job.file_gateway.consts.TaskCommandEnum;
Expand All @@ -56,7 +57,6 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -110,7 +110,7 @@ public TaskInfoDTO startFileSourceDownloadTask(String username, Long appId, Long
fileSourceId, filePathList, null);
}

@Transactional(value = "jobFileGatewayTransactionManager", rollbackFor = {Throwable.class})
@JobTransactional(transactionManager = "jobFileGatewayTransactionManager")
public TaskInfoDTO startFileSourceDownloadTaskWithId(String username, Long appId, Long stepInstanceId,
Integer executeCount, String batchTaskId,
Integer fileSourceId, List<String> filePathList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.tencent.bk.job.common.constant.ErrorCode;
import com.tencent.bk.job.common.exception.NotFoundException;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.util.ArrayUtil;
import com.tencent.bk.job.common.util.file.FileSizeUtil;
import com.tencent.bk.job.common.util.file.PathUtil;
Expand Down Expand Up @@ -53,7 +54,6 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -95,7 +95,7 @@ public void addFileTaskStatusChangeListener(FileTaskStatusChangeListener listene
}

@Override
@Transactional(value = "jobFileGatewayTransactionManager", rollbackFor = {Throwable.class})
@JobTransactional(transactionManager = "jobFileGatewayTransactionManager")
public String updateFileSourceTask(String batchTaskId,
String fileSourceTaskId,
Long fileTaskId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.tencent.bk.job.file_gateway.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.util.json.JsonUtils;
import com.tencent.bk.job.file_gateway.config.FileGatewayConfig;
import com.tencent.bk.job.file_gateway.consts.WorkerSelectScopeEnum;
Expand All @@ -41,7 +42,6 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -71,7 +71,7 @@ public FileWorkerServiceImpl(FileWorkerDAO fileWorkerDAO,
}

@Override
@Transactional(value = "jobFileGatewayTransactionManager", rollbackFor = Throwable.class)
@JobTransactional(transactionManager = "jobFileGatewayTransactionManager")
public Long heartBeat(FileWorkerDTO fileWorkerDTO) {
Long id;
String configStr = fileWorkerDTO.getConfigStr();
Expand Down
1 change: 1 addition & 0 deletions src/backend/job-manage/service-job-manage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
api project(":commons:esb-sdk")
api project(":commons:gse-sdk")
api project(":commons:cmdb-sdk")
api project(":commons:common-mysql")
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-jdbc"
implementation "org.springframework.boot:spring-boot-starter-jooq"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.tencent.bk.job.common.model.InternalResponse;
import com.tencent.bk.job.common.model.Response;
import com.tencent.bk.job.common.model.dto.AppResourceScope;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.service.AppScopeMappingService;
import com.tencent.bk.job.common.util.ArrayUtil;
import com.tencent.bk.job.common.util.date.DateUtils;
Expand All @@ -45,7 +46,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
Expand Down Expand Up @@ -135,7 +135,7 @@ private ServiceAccountDTO toServiceAccountDTO(AccountDTO accountDTO) {
}

@Override
@Transactional(value = "jobManageTransactionManager", rollbackFor = {Throwable.class})
@JobTransactional(transactionManager = "jobManageTransactionManager")
public InternalResponse<ServiceAccountDTO> saveOrGetAccount(String username, Long createTime, Long lastModifyTime,
String lastModifyUser, Long appId,
AccountCreateUpdateReq accountCreateUpdateReq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.tencent.bk.job.common.exception.NotFoundException;
import com.tencent.bk.job.common.i18n.service.MessageI18nService;
import com.tencent.bk.job.common.model.InternalResponse;
import com.tencent.bk.job.common.mysql.JobTransactional;
import com.tencent.bk.job.common.util.ArrayUtil;
import com.tencent.bk.job.manage.api.common.ScriptDTOBuilder;
import com.tencent.bk.job.manage.api.inner.ServiceScriptResource;
Expand All @@ -41,7 +42,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -99,7 +99,7 @@ public InternalResponse<ServiceScriptDTO> getScriptByScriptVersionId(Long script
}

@Override
@Transactional(value = "jobManageTransactionManager", rollbackFor = {Throwable.class})
@JobTransactional(transactionManager = "jobManageTransactionManager")
public InternalResponse<Pair<String, Long>> createScriptWithVersionId(String username, Long createTime,
Long lastModifyTime, String lastModifyUser,
Integer scriptStatus, Long appId,
Expand Down
Loading

0 comments on commit e1e13c1

Please sign in to comment.