test
youys 3 years ago
parent 3487d0739f
commit 7b08bb77ba

@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletRequest;
public class CustomExceptionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomExceptionHandler.class);
/**
* Exception
*
@ -61,7 +62,7 @@ public class CustomExceptionHandler {
@ExceptionHandler(BusinessException.class)
@ResponseBody
public ResponseResult handleException(HttpServletRequest request, BusinessException e) {
LOGGER.error("接口:"+request.getRequestURI()+",BusinessException异常:",e);
LOGGER.error("接口:" + request.getRequestURI() + ",BusinessException异常:", e);
return ResponseResult.error(e.getMessage());
}

@ -26,7 +26,7 @@ public class DynamicDataSourceConfig {
public static final String MASTER = "master";
public static final String READONLY = "readonly";
private static final List INIT_SQLS= Arrays.asList("SET NAMES utf8mb4");
private static final List INIT_SQLS = Arrays.asList("SET NAMES utf8mb4");
@Value("${spring.datasource.master.driverClassName}")
private String masterDriverClass;

@ -11,24 +11,26 @@ public class DynamicDataSourceContextHolder {
*
*/
private static final ThreadLocal<String> DATASOURCE_CONTEXT_KEY_HOLDER = new ThreadLocal<>();
/**
* /
*/
public static void setContextKey(String key){
public static void setContextKey(String key) {
DATASOURCE_CONTEXT_KEY_HOLDER.set(key);
}
/**
*
*/
public static String getContextKey(){
public static String getContextKey() {
String key = DATASOURCE_CONTEXT_KEY_HOLDER.get();
return key == null? DynamicDataSourceConfig.MASTER: key;
return key == null ? DynamicDataSourceConfig.MASTER : key;
}
/**
*
*/
public static void removeContextKey(){
public static void removeContextKey() {
DATASOURCE_CONTEXT_KEY_HOLDER.remove();
}

@ -22,7 +22,7 @@ public class ThreadPoolConfig {
@Bean("sonarQueryResultPool")
public ExecutorService queryResultPool() {
ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarScanner-pool-");
ThreadFactory sonarQueryResultPool = new CustomizableThreadFactory("sonarQueryResult-pool-");
return new ThreadPoolExecutor(5, 10, 60,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000),
sonarQueryResultPool,

@ -45,10 +45,6 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
supportedMediaTypes.add(MediaType.TEXT_XML);
fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
// FastJsonConfig fastJsonConfig = new FastJsonConfig();
// fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteMapNullValue);
//
// fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
converters.add(0,fastJsonHttpMessageConverter);
}
}

@ -82,12 +82,12 @@ public class QualityInspectRunnable implements Runnable {
}
// 调用sonar服务
LOGGER.info("projectName:{}, detailId:{} 开始调用sonar分析,语言:{}", projectName,taskInfoDetail.getId(),language);
LOGGER.info("projectName:{}, detailId:{} 开始调用sonar分析,语言:{}", projectName, taskInfoDetail.getId(), language);
sonarService.sonar(language, param);
// 提交一个查结果的任务
SonarQueryResultRunnable queryResultRunnable = new SonarQueryResultRunnable(projectName, taskInfoDetail.getId(), dbOperateService);
LOGGER.info("projectName:{}, detailId:{} 提交了查询结果的任务", projectName,taskInfoDetail.getId());
LOGGER.info("projectName:{}, detailId:{} 提交了查询结果的任务", projectName, taskInfoDetail.getId());
queryResultPool.execute(queryResultRunnable);
}

@ -1,9 +1,7 @@
package net.educoder.ecsonar.task;
import net.educoder.ecsonar.model.api.Person;
import net.educoder.ecsonar.model.api.SonarRequest;
import net.educoder.ecsonar.services.SonarService;
import net.educoder.ecsonar.utils.UrlUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,7 +12,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
/**
* @Author: youys

@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
/**
* @Author: youys
* @Date: 2022/1/18
* @Description:
* @Description:
*/
public class SonarQueryResultRunnable implements Runnable {
@ -29,13 +29,13 @@ public class SonarQueryResultRunnable implements Runnable {
@Override
public void run() {
int count = 0;
String status;
while((status = dbOperateService.queryCeActivityStatus(projectName)) == null){
while((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <=120){
LOGGER.info("detailId:[{}],sonar还未执行完,次数:{}", detailId, count);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
LOGGER.info("detailId:[{}],sonar还未执行完", detailId);
}
// 查询
LOGGER.info("detailId:[{}], 查询sonar执行状态[{}]", detailId, status);

Loading…
Cancel
Save