test
youys 3 years ago
parent 7b08bb77ba
commit 066d39344a

@ -46,6 +46,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>

@ -3,7 +3,9 @@ package net.educoder.ecsonar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@EnableAspectJAutoProxy
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class EcsonarApplication {

@ -0,0 +1,76 @@
package net.educoder.ecsonar.config;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
/**
* @author youys
* @data 2019/8/13
* @description
*/
@Aspect
@Component
public class RequestAop {
private Logger log = LoggerFactory.getLogger(RequestAop.class);
/**
* controller
*/
@Pointcut("execution(* net.educoder.ecsonar.controller.*.*(..))")
public void pointCut() {
}
@Around("pointCut()")
public Object pintLog(ProceedingJoinPoint pjp) throws Throwable {
Long startTime = System.currentTimeMillis();
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
String requestUrl = request.getRequestURL().toString();
// 打印请求内容
log.info("|===============请求内容 start ==============================|");
log.info("|请求地址:" + requestUrl);
log.info("|请求方式:" + request.getMethod());
log.info("|请求类方法:" + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
//获取所有参数
Enumeration<String> enu = request.getParameterNames();
StringBuilder params = new StringBuilder("【");
while (enu.hasMoreElements()) {
String paraName = enu.nextElement();
params.append(paraName).append("=").append(request.getParameter(paraName)).append(";");
}
params.append("】");
log.info("|请求方法参数:" + params.toString());
Enumeration<String> headersEnu = request.getHeaderNames();
StringBuilder headersParams = new StringBuilder("【");
while (headersEnu.hasMoreElements()) {
String headerName = headersEnu.nextElement();
headersParams.append(headerName).append("=").append(request.getHeader(headerName)).append(";");
}
headersParams.append("】");
log.info("|请求Header信息:{}", headersParams.toString());
log.info("|===============请求内容 end ================================|");
Object result = pjp.proceed();
long endTime = System.currentTimeMillis();
log.info("调用方法: {},返回结果response==>>{}", requestUrl, JSONObject.toJSONString(result));
log.info("调用方法: {},请求耗时==>> {} ms", requestUrl, endTime - startTime);
return result;
}
}

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

@ -1,12 +1,9 @@
package net.educoder.ecsonar.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.ArrayList;

@ -11,10 +11,10 @@ import java.util.List;
public class Constant {
public static final String JAVA = "JAVA";
public static final String C = "C";
public static final String CXX = "C++";
public static final String PYTHON = "PYTHON";
public static final String JAVA = "java";
public static final String C = "c";
public static final String CXX = "cpp";
public static final String PYTHON = "python";
public static final List<String> language = Arrays.asList(JAVA, C, CXX, PYTHON);
}

@ -1,10 +1,12 @@
package net.educoder.ecsonar.controller;
import com.alibaba.fastjson.JSONArray;
import net.educoder.ecsonar.constant.Constant;
import net.educoder.ecsonar.model.RollPage;
import net.educoder.ecsonar.model.api.QualityInspect;
import net.educoder.ecsonar.model.api.QualityInspectIsCompleted;
import net.educoder.ecsonar.model.api.QualityInspectResultData;
import net.educoder.ecsonar.model.vo.QualityInspectUserDataVO;
import net.educoder.ecsonar.model.vo.QualityInspectVO;
import net.educoder.ecsonar.services.QualityInspectService;
import net.educoder.ecsonar.utils.ResponseResult;
@ -12,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author: youys
* @Date: 2022/1/17
@ -32,7 +36,13 @@ public class QualityInspectController {
*/
@RequestMapping(value = "qualityInspect", method = RequestMethod.POST)
@ResponseBody
public ResponseResult<String> qualityInspect(@RequestBody QualityInspectVO qualityInspectVO){
public ResponseResult<String> qualityInspect(@RequestParam String language,
@RequestParam String homeworkId,
@RequestParam String userDatas){
List<QualityInspectUserDataVO> userDataVOList = JSONArray.parseArray(userDatas,QualityInspectUserDataVO.class);
QualityInspectVO qualityInspectVO = new QualityInspectVO(language, homeworkId, userDataVOList);
if (!Constant.language.contains(qualityInspectVO.getLanguage())) {
return ResponseResult.error("不支持的语言");
}

@ -20,7 +20,7 @@ public interface TaskInfoDetailDao {
*
* @param taskInfoDetail
*/
@Insert("insert into task_info_detail(id,task_id,project_name,student_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{name},#{codeIds})")
@Insert("insert into task_info_detail(id,task_id,project_name,student_id,user_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{userId} ,#{name},#{codeIds})")
void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);
/**
@ -47,7 +47,7 @@ public interface TaskInfoDetailDao {
* @param id
* @return
*/
@Select("select id,task_id taskId,project_name projectName,student_id studentId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
TaskInfoDetail selectById(String id);
/**
@ -69,6 +69,6 @@ public interface TaskInfoDetailDao {
* @param position
* @return
*/
@Select("select id,task_id taskId,project_name projectName,student_id studentId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
@Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
List<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("position") Integer position);
}

@ -13,6 +13,7 @@ public class TaskInfoDetail {
private String taskId;
private String projectName;
private String studentId;
private Long userId;
private String name;
private String codeIds;
/**
@ -55,6 +56,14 @@ public class TaskInfoDetail {
this.studentId = studentId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getName() {
return name;
}

@ -18,6 +18,11 @@ public class QualityInspectResultData {
*/
private String studentId;
/**
* id
*/
private Long userId;
/**
*
*/
@ -67,6 +72,14 @@ public class QualityInspectResultData {
this.studentId = studentId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getName() {
return name;
}

@ -1,5 +1,6 @@
package net.educoder.ecsonar.model.vo;
import java.io.Serializable;
import java.util.List;
/**
@ -7,12 +8,18 @@ import java.util.List;
* @Date: 2022/1/17
* @Description:
*/
public class QualityInspectUserDataVO {
public class QualityInspectUserDataVO implements Serializable {
/**
*
*/
private String studentId;
/**
* id
*/
private Long userId;
/**
*
*/
@ -46,4 +53,12 @@ public class QualityInspectUserDataVO {
public void setCodeIds(List<Long> codeIds) {
this.codeIds = codeIds;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
}

@ -1,5 +1,6 @@
package net.educoder.ecsonar.model.vo;
import java.io.Serializable;
import java.util.List;
/**
@ -7,12 +8,17 @@ import java.util.List;
* @Date: 2022/1/17
* @Description:
*/
public class QualityInspectVO {
public class QualityInspectVO implements Serializable {
private String language;
private String homeworkId;
private List<QualityInspectUserDataVO> userDatas;
public QualityInspectVO(String language, String homeworkId, List<QualityInspectUserDataVO> userDatas) {
this.language = language;
this.homeworkId = homeworkId;
this.userDatas = userDatas;
}
public String getLanguage() {
return language;

@ -89,6 +89,7 @@ public class QualityInspectService {
taskInfoDetail.setProjectName(String.format("%s-%s", qualityInspectVO.getHomeworkId(), userData.getStudentId()));
taskInfoDetail.setName(userData.getName());
taskInfoDetail.setStudentId(userData.getStudentId());
taskInfoDetail.setUserId(userData.getUserId());
taskInfoDetail.setCodeIds(userData.getCodeIds().toString());
taskInfoDetailDao.insertTaskInfoDetail(taskInfoDetail);
@ -130,6 +131,7 @@ public class QualityInspectService {
QualityInspectResultData resultData = new QualityInspectResultData();
resultData.setName(taskInfoDetail.getName());
resultData.setStudentId(taskInfoDetail.getStudentId());
resultData.setUserId(taskInfoDetail.getUserId());
Metrics metrics = reportService.getMetrics(taskInfoDetail.getProjectName());

@ -42,8 +42,8 @@ public class SonarService {
@Value("${sonar.url}")
String sonarUrl;
@Value("${sonar.token}")
String sonarToken;
// @Value("${sonar.token}")
// String sonarToken;
@Value("${extract.path}")
String extractProgramPath;
@ -60,7 +60,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
@ -71,7 +70,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.executeAndGetExitStatus(command);
@ -82,7 +80,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.executeAndGetExitStatus(command);
@ -93,10 +90,10 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + param.getProjectKey() + " " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.cxx.cppcheck.reportPath=" + param.getCppCheckReportPath() + " " +
"-Dsonar.projectBaseDir=" + param.getProjectPath();
SystemUtil.executeAndGetExitStatus(command);
SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
log.info("command:{}, result:{}", command, executeResp.getOutput());
});
}
@ -188,7 +185,6 @@ public class SonarService {
"-Dsonar.host.url=" + sonarUrl + " " +
"-Dsonar.sourceEncoding=utf-8 " +
"-Dsonar.projectKey=" + key + " " +
"-Dsonar.login=" + sonarToken + " " +
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);

@ -67,6 +67,10 @@ public class QualityInspectRunnable implements Runnable {
}
GameCodes gameCodes = dbOperateService.queryGameCodesById(codeId);
if(gameCodes == null){
LOGGER.error("projectName:{}, game_codes_id:{}找不到对应的学员代码",projectName, codeId);
continue;
}
FileUtil.writeString(gameCodes.getCode(), path + gameCodes.getPath(), Charset.forName("UTF-8"));
}

@ -29,7 +29,7 @@ public class ResponseResult<T> implements Serializable {
}
public static ResponseResult success(){
return new ResponseResult(1,"success");
return new ResponseResult(0,"success");
}

@ -12,10 +12,17 @@ spring.datasource.master.password=root
spring.datasource.master.driverClassName=org.postgresql.Driver
#### test ######
spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver
spring.datasource.readonly.url=jdbc:mysql://rm-bp1ht3504joktie83.mysql.rds.aliyuncs.com:3306/educoderweb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring.datasource.readonly.username=readonly
spring.datasource.readonly.password=readonly_20210901
spring.datasource.readonly.url=jdbc:mysql://rm-bp13v5020p7828r5rso.mysql.rds.aliyuncs.com:3306/preeducoderweb?userSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring.datasource.readonly.username=testeducoder
spring.datasource.readonly.password=TEST@123
#### prod ######
#spring.datasource.readonly.driverClassName=com.mysql.jdbc.Driver
#spring.datasource.readonly.url=jdbc:mysql://rm-bp1ht3504joktie83.mysql.rds.aliyuncs.com:3306/educoderweb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
#spring.datasource.readonly.username=readonly
#spring.datasource.readonly.password=readonly_20210901
# Hikari will use the above plus the following to setup connection pooling
#spring.datasource.type=com.zaxxer.hikari.HikariDataSource

Loading…
Cancel
Save