提交 52ead84a 编写于 作者: C chenjianxing

merge

......@@ -26,6 +26,7 @@ yarn-error.log*
src/main/resources/static
src/main/resources/templates
src/test/
target
.settings
.project
......
......@@ -39,6 +39,12 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
......@@ -60,6 +66,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
......@@ -128,12 +135,6 @@
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.1</version>
</dependency>
<!-- jmeter -->
<!-- <dependency>-->
<!-- <groupId>org.apache.jmeter</groupId>-->
......@@ -255,6 +256,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.3.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
......
......@@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.PropertySource;
@SpringBootApplication(exclude = {QuartzAutoConfiguration.class})
@ServletComponentScan
......@@ -14,6 +15,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
KafkaProperties.class,
JmeterProperties.class
})
@PropertySource(value = {"file:/opt/metersphere/conf/metersphere.properties"}, encoding = "UTF-8", ignoreResourceNotFound = true)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
......
package io.metersphere.api.jmeter;
import org.apache.jmeter.assertions.AssertionResult;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import java.io.Serializable;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class APIBackendListenerClient extends AbstractBackendListenerClient implements Serializable {
private final AtomicInteger count = new AtomicInteger();
@Override
public void handleSampleResults(List<SampleResult> sampleResults, BackendListenerContext context) {
System.out.println(context.getParameter("id"));
sampleResults.forEach(result -> {
for (AssertionResult assertionResult : result.getAssertionResults()) {
System.out.println(assertionResult.getName() + ": " + assertionResult.isError());
System.out.println(assertionResult.getName() + ": " + assertionResult.isFailure());
System.out.println(assertionResult.getName() + ": " + assertionResult.getFailureMessage());
}
println("getSampleLabel", result.getSampleLabel());
println("getErrorCount", result.getErrorCount());
println("getRequestHeaders", result.getRequestHeaders());
println("getResponseHeaders", result.getResponseHeaders());
println("getSampleLabel", result.getSampleLabel());
println("getSampleLabel", result.getSampleLabel());
println("getResponseCode", result.getResponseCode());
println("getResponseCode size", result.getResponseData().length);
println("getLatency", result.getLatency());
println("end - start", result.getEndTime() - result.getStartTime());
println("getTimeStamp", result.getTimeStamp());
println("getTime", result.getTime());
});
System.err.println(count.addAndGet(sampleResults.size()));
}
private void println(String name, Object value) {
System.out.println(name + ": " + value);
}
}
package io.metersphere.api.jmeter;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.lang.reflect.Field;
@Service
public class JMeterService {
public void run(InputStream is) {
JMeterUtils.loadJMeterProperties("/Users/q4speed/Downloads/apache-jmeter-5.2.1/bin/jmeter.properties");
JMeterUtils.setJMeterHome("/Users/q4speed/Downloads/apache-jmeter-5.2.1");
try {
Object scriptWrapper = SaveService.loadElement(is);
HashTree testPlan = getHashTree(scriptWrapper);
LocalRunner runner = new LocalRunner(testPlan);
runner.run();
} catch (Exception e) {
MSException.throwException(Translator.get("api_load_script_error"));
}
}
public HashTree getHashTree(Object scriptWrapper) throws Exception {
Field field = scriptWrapper.getClass().getDeclaredField("testPlan");
field.setAccessible(true);
return (HashTree) field.get(scriptWrapper);
}
}
package io.metersphere.api.jmeter;
import org.apache.jmeter.engine.JMeterEngine;
import org.apache.jmeter.engine.JMeterEngineException;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jorphan.collections.HashTree;
public class LocalRunner {
private final HashTree jmxTree;
public LocalRunner(HashTree jmxTree) {
this.jmxTree = jmxTree;
}
public void run() {
JMeterEngine engine = new StandardJMeterEngine();
engine.configure(jmxTree);
try {
engine.runTest();
} catch (JMeterEngineException e) {
engine.stopTest(true);
}
}
}
......@@ -4,6 +4,7 @@ import io.metersphere.api.dto.APITestResult;
import io.metersphere.api.dto.DeleteAPITestRequest;
import io.metersphere.api.dto.QueryAPITestRequest;
import io.metersphere.api.dto.SaveAPITestRequest;
import io.metersphere.api.jmeter.JMeterService;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiTestFileMapper;
import io.metersphere.base.mapper.ApiTestMapper;
......@@ -18,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
......@@ -36,6 +38,8 @@ public class ApiTestService {
private ApiTestFileMapper apiTestFileMapper;
@Resource
private FileService fileService;
@Resource
private JMeterService jMeterService;
public List<APITestResult> list(QueryAPITestRequest request) {
return extApiTestMapper.list(request);
......@@ -47,7 +51,7 @@ public class ApiTestService {
}
public String save(SaveAPITestRequest request, List<MultipartFile> files) {
if (files == null) {
if (files == null || files.isEmpty()) {
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
}
......@@ -75,11 +79,26 @@ public class ApiTestService {
}
public void delete(DeleteAPITestRequest request) {
deleteFileByTestId(request.getId());
apiTestMapper.deleteByPrimaryKey(request.getId());
}
public String run(SaveAPITestRequest request, List<MultipartFile> files) {
return save(request, files);
String id = save(request, files);
try {
changeStatus(request.getId(), APITestStatus.Running);
jMeterService.run(files.get(0).getInputStream());
} catch (IOException e) {
MSException.throwException(Translator.get("api_load_script_error"));
}
return id;
}
public void changeStatus(String id, APITestStatus status) {
ApiTestWithBLOBs apiTest = new ApiTestWithBLOBs();
apiTest.setId(id);
apiTest.setStatus(status.name());
apiTestMapper.updateByPrimaryKeySelective(apiTest);
}
private ApiTestWithBLOBs updateTest(SaveAPITestRequest request) {
......@@ -113,7 +132,7 @@ public class ApiTestService {
return test;
}
public void deleteFileByTestId(String testId) {
private void deleteFileByTestId(String testId) {
ApiTestFileExample ApiTestFileExample = new ApiTestFileExample();
ApiTestFileExample.createCriteria().andTestIdEqualTo(testId);
final List<ApiTestFile> ApiTestFiles = apiTestFileMapper.selectByExample(ApiTestFileExample);
......@@ -121,9 +140,20 @@ public class ApiTestService {
if (!CollectionUtils.isEmpty(ApiTestFiles)) {
final List<String> fileIds = ApiTestFiles.stream().map(ApiTestFile::getFileId).collect(Collectors.toList());
fileService.deleteFileByIds(fileIds);
}
}
private ApiTestFile getFileByTestId(String testId) {
ApiTestFileExample ApiTestFileExample = new ApiTestFileExample();
ApiTestFileExample.createCriteria().andTestIdEqualTo(testId);
final List<ApiTestFile> ApiTestFiles = apiTestFileMapper.selectByExample(ApiTestFileExample);
apiTestFileMapper.selectByExample(ApiTestFileExample);
if (!CollectionUtils.isEmpty(ApiTestFiles)) {
return ApiTestFiles.get(0);
} else {
return null;
}
}
}
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApiTest implements Serializable {
private String id;
......@@ -18,60 +21,4 @@ public class ApiTest implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId == null ? null : projectId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApiTestFile implements Serializable {
private String testId;
private String fileId;
private static final long serialVersionUID = 1L;
public String getTestId() {
return testId;
}
public void setTestId(String testId) {
this.testId = testId == null ? null : testId.trim();
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId == null ? null : fileId.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApiTestReport implements Serializable {
private String id;
......@@ -20,68 +23,4 @@ public class ApiTestReport implements Serializable {
private String content;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getTestId() {
return testId;
}
public void setTestId(String testId) {
this.testId = testId == null ? null : testId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ApiTestWithBLOBs extends ApiTest implements Serializable {
private String scenarioDefinition;
private String schedule;
private static final long serialVersionUID = 1L;
public String getScenarioDefinition() {
return scenarioDefinition;
}
public void setScenarioDefinition(String scenarioDefinition) {
this.scenarioDefinition = scenarioDefinition == null ? null : scenarioDefinition.trim();
}
public String getSchedule() {
return schedule;
}
public void setSchedule(String schedule) {
this.schedule = schedule == null ? null : schedule.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class FileContent implements Serializable {
private String fileId;
private byte[] file;
private static final long serialVersionUID = 1L;
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId == null ? null : fileId.trim();
}
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class FileMetadata implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class FileMetadata implements Serializable {
private Long size;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type == null ? null : type.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTest implements Serializable {
private String id;
......@@ -20,68 +23,4 @@ public class LoadTest implements Serializable {
private String testResourcePoolId;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId == null ? null : projectId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getTestResourcePoolId() {
return testResourcePoolId;
}
public void setTestResourcePoolId(String testResourcePoolId) {
this.testResourcePoolId = testResourcePoolId == null ? null : testResourcePoolId.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTestFile implements Serializable {
private String testId;
private String fileId;
private static final long serialVersionUID = 1L;
public String getTestId() {
return testId;
}
public void setTestId(String testId) {
this.testId = testId == null ? null : testId.trim();
}
public String getFileId() {
return fileId;
}
public void setFileId(String fileId) {
this.fileId = fileId == null ? null : fileId.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTestReport implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class LoadTestReport implements Serializable {
private String status;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getTestId() {
return testId;
}
public void setTestId(String testId) {
this.testId = testId == null ? null : testId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTestReportDetail implements Serializable {
private String reportId;
private String content;
private static final long serialVersionUID = 1L;
public String getReportId() {
return reportId;
}
public void setReportId(String reportId) {
this.reportId = reportId == null ? null : reportId.trim();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTestReportLog implements Serializable {
private Long id;
......@@ -12,36 +15,4 @@ public class LoadTestReportLog implements Serializable {
private String content;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getReportId() {
return reportId;
}
public void setReportId(String reportId) {
this.reportId = reportId == null ? null : reportId.trim();
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId == null ? null : resourceId.trim();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTestReportResult implements Serializable {
private Long id;
......@@ -12,36 +15,4 @@ public class LoadTestReportResult implements Serializable {
private String reportValue;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getReportId() {
return reportId;
}
public void setReportId(String reportId) {
this.reportId = reportId == null ? null : reportId.trim();
}
public String getReportKey() {
return reportKey;
}
public void setReportKey(String reportKey) {
this.reportKey = reportKey == null ? null : reportKey.trim();
}
public String getReportValue() {
return reportValue;
}
public void setReportValue(String reportValue) {
this.reportValue = reportValue == null ? null : reportValue.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class LoadTestReportWithBLOBs extends LoadTestReport implements Serializable {
private String description;
private String content;
private static final long serialVersionUID = 1L;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class LoadTestWithBLOBs extends LoadTest implements Serializable {
private String loadConfiguration;
......@@ -10,28 +17,4 @@ public class LoadTestWithBLOBs extends LoadTest implements Serializable {
private String schedule;
private static final long serialVersionUID = 1L;
public String getLoadConfiguration() {
return loadConfiguration;
}
public void setLoadConfiguration(String loadConfiguration) {
this.loadConfiguration = loadConfiguration == null ? null : loadConfiguration.trim();
}
public String getAdvancedConfiguration() {
return advancedConfiguration;
}
public void setAdvancedConfiguration(String advancedConfiguration) {
this.advancedConfiguration = advancedConfiguration == null ? null : advancedConfiguration.trim();
}
public String getSchedule() {
return schedule;
}
public void setSchedule(String schedule) {
this.schedule = schedule == null ? null : schedule.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class Organization implements Serializable {
private String id;
......@@ -14,44 +17,4 @@ public class Organization implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class Project implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class Project implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getWorkspaceId() {
return workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId == null ? null : workspaceId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class Role implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class Role implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type == null ? null : type.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class SystemParameter implements Serializable {
private String paramKey;
......@@ -12,36 +15,4 @@ public class SystemParameter implements Serializable {
private Integer sort;
private static final long serialVersionUID = 1L;
public String getParamKey() {
return paramKey;
}
public void setParamKey(String paramKey) {
this.paramKey = paramKey == null ? null : paramKey.trim();
}
public String getParamValue() {
return paramValue;
}
public void setParamValue(String paramValue) {
this.paramValue = paramValue == null ? null : paramValue.trim();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type == null ? null : type.trim();
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestCase implements Serializable {
private String id;
......@@ -28,100 +31,4 @@ public class TestCase implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public Integer getNodeId() {
return nodeId;
}
public void setNodeId(Integer nodeId) {
this.nodeId = nodeId;
}
public String getNodePath() {
return nodePath;
}
public void setNodePath(String nodePath) {
this.nodePath = nodePath == null ? null : nodePath.trim();
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId == null ? null : projectId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type == null ? null : type.trim();
}
public String getMaintainer() {
return maintainer;
}
public void setMaintainer(String maintainer) {
this.maintainer = maintainer == null ? null : maintainer.trim();
}
public String getPriority() {
return priority;
}
public void setPriority(String priority) {
this.priority = priority == null ? null : priority.trim();
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method == null ? null : method.trim();
}
public String getPrerequisite() {
return prerequisite;
}
public void setPrerequisite(String prerequisite) {
this.prerequisite = prerequisite == null ? null : prerequisite.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestCaseNode implements Serializable {
private Integer id;
......@@ -18,60 +21,4 @@ public class TestCaseNode implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId == null ? null : projectId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public Integer getpId() {
return pId;
}
public void setpId(Integer pId) {
this.pId = pId;
}
public Integer getLevel() {
return level;
}
public void setLevel(Integer level) {
this.level = level;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class TestCaseReport implements Serializable {
private Long id;
......@@ -16,52 +18,4 @@ public class TestCaseReport implements Serializable {
private String content;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getPlanId() {
return planId;
}
public void setPlanId(String planId) {
this.planId = planId == null ? null : planId.trim();
}
public Long getStartTime() {
return startTime;
}
public void setStartTime(Long startTime) {
this.startTime = startTime;
}
public Long getEndTime() {
return endTime;
}
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class TestCaseReportTemplate implements Serializable {
private Long id;
......@@ -16,52 +18,4 @@ public class TestCaseReportTemplate implements Serializable {
private String content;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getWorkspaceId() {
return workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId == null ? null : workspaceId.trim();
}
public Long getStartTime() {
return startTime;
}
public void setStartTime(Long startTime) {
this.startTime = startTime;
}
public Long getEndTime() {
return endTime;
}
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TestCaseWithBLOBs extends TestCase implements Serializable {
private String remark;
private String steps;
private static final long serialVersionUID = 1L;
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public String getSteps() {
return steps;
}
public void setSteps(String steps) {
this.steps = steps == null ? null : steps.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestPlan implements Serializable {
private String id;
......@@ -30,108 +33,4 @@ public class TestPlan implements Serializable {
private String tags;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId == null ? null : projectId.trim();
}
public String getWorkspaceId() {
return workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId == null ? null : workspaceId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getStage() {
return stage;
}
public void setStage(String stage) {
this.stage = stage == null ? null : stage.trim();
}
public String getPrincipal() {
return principal;
}
public void setPrincipal(String principal) {
this.principal = principal == null ? null : principal.trim();
}
public String getTestCaseMatchRule() {
return testCaseMatchRule;
}
public void setTestCaseMatchRule(String testCaseMatchRule) {
this.testCaseMatchRule = testCaseMatchRule == null ? null : testCaseMatchRule.trim();
}
public String getExecutorMatchRule() {
return executorMatchRule;
}
public void setExecutorMatchRule(String executorMatchRule) {
this.executorMatchRule = executorMatchRule == null ? null : executorMatchRule.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags == null ? null : tags.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestPlanTestCase implements Serializable {
private Integer id;
......@@ -22,76 +25,4 @@ public class TestPlanTestCase implements Serializable {
private String results;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPlanId() {
return planId;
}
public void setPlanId(String planId) {
this.planId = planId == null ? null : planId.trim();
}
public String getCaseId() {
return caseId;
}
public void setCaseId(String caseId) {
this.caseId = caseId == null ? null : caseId.trim();
}
public String getExecutor() {
return executor;
}
public void setExecutor(String executor) {
this.executor = executor == null ? null : executor.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getResults() {
return results;
}
public void setResults(String results) {
this.results = results == null ? null : results.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestResource implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class TestResource implements Serializable {
private String configuration;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getTestResourcePoolId() {
return testResourcePoolId;
}
public void setTestResourcePoolId(String testResourcePoolId) {
this.testResourcePoolId = testResourcePoolId == null ? null : testResourcePoolId.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getConfiguration() {
return configuration;
}
public void setConfiguration(String configuration) {
this.configuration = configuration == null ? null : configuration.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class TestResourcePool implements Serializable {
private String id;
......@@ -18,60 +21,4 @@ public class TestResourcePool implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type == null ? null : type.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class User implements Serializable {
private String id;
......@@ -26,92 +29,4 @@ public class User implements Serializable {
private String phone;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password == null ? null : password.trim();
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language == null ? null : language.trim();
}
public String getLastWorkspaceId() {
return lastWorkspaceId;
}
public void setLastWorkspaceId(String lastWorkspaceId) {
this.lastWorkspaceId = lastWorkspaceId == null ? null : lastWorkspaceId.trim();
}
public String getLastOrganizationId() {
return lastOrganizationId;
}
public void setLastOrganizationId(String lastOrganizationId) {
this.lastOrganizationId = lastOrganizationId == null ? null : lastOrganizationId.trim();
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone == null ? null : phone.trim();
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class UserRole implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class UserRole implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId == null ? null : userId.trim();
}
public String getRoleId() {
return roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId == null ? null : roleId.trim();
}
public String getSourceId() {
return sourceId;
}
public void setSourceId(String sourceId) {
this.sourceId = sourceId == null ? null : sourceId.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class Workspace implements Serializable {
private String id;
......@@ -16,52 +19,4 @@ public class Workspace implements Serializable {
private Long updateTime;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public String getOrganizationId() {
return organizationId;
}
public void setOrganizationId(String organizationId) {
this.organizationId = organizationId == null ? null : organizationId.trim();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description == null ? null : description.trim();
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
......@@ -102,22 +102,19 @@
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.TestCaseNode">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into test_case_node (project_id, name, p_id,
level, create_time, update_time
)
values (#{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{pId,jdbcType=INTEGER},
#{level,jdbcType=INTEGER}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}
)
insert into test_case_node (id, project_id, name,
p_id, level, create_time,
update_time)
values (#{id,jdbcType=INTEGER}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{pId,jdbcType=INTEGER}, #{level,jdbcType=INTEGER}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.TestCaseNode">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into test_case_node
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="projectId != null">
project_id,
</if>
......@@ -138,6 +135,9 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="projectId != null">
#{projectId,jdbcType=VARCHAR},
</if>
......
package io.metersphere.base.mapper.ext;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.TestResourcePoolDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtTestReourcePoolMapper {
List<TestResourcePoolDTO> listResourcePools(@Param("request") QueryResourcePoolRequest request);
// List<TestResource> listResourcesByPoolId(@Param("poolId") String poolId);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper">
<resultMap id="TestReourcePoolResultMap" type="io.metersphere.dto.TestResourcePoolDTO">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
<result column="update_time" jdbcType="BIGINT" property="updateTime"/>
<collection property="resources" column="id" ofType="io.metersphere.base.domain.TestResource"
select="io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper.listResourcesByPoolId">
</collection>
</resultMap>
<select id="listResourcePools" resultMap="TestReourcePoolResultMap">
SELECT * FROM test_resource_pool
<where>
<if test="request.name != null">
and test_resource_pool.name like CONCAT('%', #{request.name},'%')
</if>
</where>
</select>
<select id="listResourcesByPoolId" resultType="io.metersphere.base.domain.TestResource">
SELECT * FROM test_resource WHERE test_resource_pool_id = #{id}
</select>
</mapper>
\ No newline at end of file
package io.metersphere.commons.utils;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class MybatisInterceptorConfig {
private String modelName;
private String attrName;
......@@ -9,7 +14,6 @@ public class MybatisInterceptorConfig {
private String undoClass;
private String undoMethod;
public MybatisInterceptorConfig() {
}
......@@ -17,100 +21,25 @@ public class MybatisInterceptorConfig {
* 用时需谨慎!!!!!
* 主要配置多个的时候,参数少一点
*
* @param modelName
* @param modelClass
* @param attrName
*/
public MybatisInterceptorConfig(String modelName, String attrName) {
this.modelName = modelName;
public MybatisInterceptorConfig(Class<?> modelClass, String attrName) {
this.modelName = modelClass.getName();
this.attrName = attrName;
this.interceptorClass = "io.metersphere.commons.utils.EncryptUtils";
this.interceptorClass = EncryptUtils.class.getName();
this.interceptorMethod = "aesEncrypt";
this.undoClass = "io.metersphere.commons.utils.EncryptUtils";
this.undoClass = EncryptUtils.class.getName();
this.undoMethod = "aesDecrypt";
}
public MybatisInterceptorConfig(String modelName, String attrName, String attrNameForList) {
this.modelName = modelName;
this.attrName = attrName;
this.attrNameForList = attrNameForList;
this.interceptorClass = "io.metersphere.commons.utils.EncryptUtils";
this.interceptorMethod = "aesEncrypt";
this.undoClass = "io.metersphere.commons.utils.EncryptUtils";
this.undoMethod = "aesDecrypt";
}
public MybatisInterceptorConfig(String modelName, String attrName, String interceptorClass, String interceptorMethod, String undoMethod) {
this.modelName = modelName;
this.attrName = attrName;
this.interceptorClass = interceptorClass;
this.interceptorMethod = interceptorMethod;
this.undoClass = interceptorClass;
this.undoMethod = undoMethod;
}
public MybatisInterceptorConfig(String modelName, String attrName, String attrNameForList, String interceptorClass, String interceptorMethod, String undoMethod) {
this.modelName = modelName;
this.attrName = attrName;
this.attrNameForList = attrNameForList;
this.interceptorClass = interceptorClass;
this.interceptorMethod = interceptorMethod;
this.undoClass = interceptorClass;
this.undoMethod = undoMethod;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getAttrName() {
return attrName;
}
public void setAttrName(String attrName) {
public MybatisInterceptorConfig(Class<?> modelClass, String attrName, Class<?> interceptorClass, String interceptorMethod, String undoMethod) {
this.modelName = modelClass.getName();
this.attrName = attrName;
}
public String getAttrNameForList() {
return attrNameForList;
}
public void setAttrNameForList(String attrNameForList) {
this.attrNameForList = attrNameForList;
}
public String getInterceptorMethod() {
return interceptorMethod;
}
public void setInterceptorMethod(String interceptorMethod) {
this.interceptorClass = interceptorClass.getName();
this.interceptorMethod = interceptorMethod;
}
public String getUndoMethod() {
return undoMethod;
}
public void setUndoMethod(String undoMethod) {
this.undoClass = interceptorClass.getName();
this.undoMethod = undoMethod;
}
public String getInterceptorClass() {
return interceptorClass;
}
public void setInterceptorClass(String interceptorClass) {
this.interceptorClass = interceptorClass;
}
public String getUndoClass() {
return undoClass;
}
public void setUndoClass(String undoClass) {
this.undoClass = undoClass;
}
}
......@@ -8,7 +8,7 @@ public class JmeterProperties {
public static final String JMETER_PREFIX = "jmeter";
private String image = "registry.fit2cloud.com/metersphere/jmeter-master:0.0.3";
private String image;
public String getImage() {
return image;
......
package io.metersphere.config;
import com.github.pagehelper.PageInterceptor;
import io.metersphere.base.domain.FileContent;
import io.metersphere.base.domain.TestResource;
import io.metersphere.commons.utils.CompressUtils;
import io.metersphere.commons.utils.MybatisInterceptorConfig;
import io.metersphere.interceptor.MybatisInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import java.util.ArrayList;
......@@ -17,7 +19,6 @@ import java.util.Properties;
@Configuration
@MapperScan(basePackages = "io.metersphere.base.mapper", sqlSessionFactoryRef = "sqlSessionFactory")
@EnableTransactionManagement
@PropertySource(value = {"file:/opt/fit2cloud/conf/metersphere.properties"}, encoding = "UTF-8", ignoreResourceNotFound = true)
public class MybatisConfig {
@Bean
......@@ -39,7 +40,8 @@ public class MybatisConfig {
public MybatisInterceptor dbInterceptor() {
MybatisInterceptor interceptor = new MybatisInterceptor();
List<MybatisInterceptorConfig> configList = new ArrayList<>();
configList.add(new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip"));
configList.add(new MybatisInterceptorConfig(FileContent.class, "file", CompressUtils.class, "zip", "unzip"));
configList.add(new MybatisInterceptorConfig(TestResource.class, "configuration"));
interceptor.setInterceptorConfigList(configList);
return interceptor;
}
......
......@@ -54,10 +54,10 @@ public class LoginController {
List<UserRole> org = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("org")).collect(Collectors.toList());
if (test.size() > 0) {
String wsId = test.get(0).getSourceId();
userService.switchUserRole(user, "workspace", wsId);
userService.switchUserRole("workspace", wsId);
} else if (org.size() > 0) {
String orgId = org.get(0).getSourceId();
userService.switchUserRole(user, "organization", orgId);
userService.switchUserRole("organization", orgId);
}
}
// 返回 userDTO
......
......@@ -129,16 +129,14 @@ public class UserController {
@PostMapping("/switch/source/org/{sourceId}")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user,"organization",sourceId);
userService.switchUserRole("organization",sourceId);
return SessionUtils.getUser();
}
@PostMapping("/switch/source/ws/{sourceId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.TEST_VIEWER,RoleConstants.TEST_USER}, logical = Logical.OR)
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user, "workspace", sourceId);
userService.switchUserRole("workspace", sourceId);
return SessionUtils.getUser();
}
......
......@@ -27,6 +27,7 @@ public class WorkspaceController {
@PostMapping("add")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public Workspace addWorkspace(@RequestBody Workspace workspace) {
workspaceService.checkWorkspaceOwnerByOrgAdmin(workspace.getId());
return workspaceService.saveWorkspace(workspace);
}
......
package io.metersphere.report.base;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ChartsData {
/**
......@@ -52,20 +55,4 @@ public class ChartsData {
public void setyAxis2(BigDecimal yAxis2) {
this.yAxis2 = yAxis2;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
package io.metersphere.report.base;
import lombok.Data;
@Data
public class Errors {
private String errorType;
private String errorNumber;
private String precentOfErrors;
private String precentOfAllSamples;
public String getErrorType() {
return errorType;
}
public void setErrorType(String errorType) {
this.errorType = errorType;
}
public String getErrorNumber() {
return errorNumber;
}
public void setErrorNumber(String errorNumber) {
this.errorNumber = errorNumber;
}
public String getPrecentOfErrors() {
return precentOfErrors;
}
public void setPrecentOfErrors(String precentOfErrors) {
this.precentOfErrors = precentOfErrors;
}
public String getPrecentOfAllSamples() {
return precentOfAllSamples;
}
private String percentOfErrors;
private String percentOfAllSamples;
public void setPrecentOfAllSamples(String precentOfAllSamples) {
this.precentOfAllSamples = precentOfAllSamples;
}
}
package io.metersphere.report.base;
import lombok.Data;
@Data
public class ErrorsTop5 {
private String sample;
......@@ -16,107 +19,4 @@ public class ErrorsTop5 {
private String error5;
private String error5Size;
public String getSample() {
return sample;
}
public void setSample(String sample) {
this.sample = sample;
}
public String getSamples() {
return samples;
}
public void setSamples(String samples) {
this.samples = samples;
}
public String getErrorsAllSize() {
return errorsAllSize;
}
public void setErrorsAllSize(String errorsAllSize) {
this.errorsAllSize = errorsAllSize;
}
public String getError1() {
return error1;
}
public void setError1(String error1) {
this.error1 = error1;
}
public String getError1Size() {
return error1Size;
}
public void setError1Size(String error1Size) {
this.error1Size = error1Size;
}
public String getError2() {
return error2;
}
public void setError2(String error2) {
this.error2 = error2;
}
public String getError2Size() {
return error2Size;
}
public void setError2Size(String error2Size) {
this.error2Size = error2Size;
}
public String getError3() {
return error3;
}
public void setError3(String error3) {
this.error3 = error3;
}
public String getError3Size() {
return error3Size;
}
public void setError3Size(String error3Size) {
this.error3Size = error3Size;
}
public String getError4() {
return error4;
}
public void setError4(String error4) {
this.error4 = error4;
}
public String getError4Size() {
return error4Size;
}
public void setError4Size(String error4Size) {
this.error4Size = error4Size;
}
public String getError5() {
return error5;
}
public void setError5(String error5) {
this.error5 = error5;
}
public String getError5Size() {
return error5Size;
}
public void setError5Size(String error5Size) {
this.error5Size = error5Size;
}
}
package io.metersphere.report.base;
import com.opencsv.bean.CsvBindByName;
public class Metric {
// timestamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
@CsvBindByName(column = "timestamp") // 访问开始时间
private String timestamp;
@CsvBindByName(column = "elapsed") // 访问开始到结束的用时 - 响应时间
private String elapsed;
@CsvBindByName(column = "label") // 请求的标签
private String label;
@CsvBindByName(column = "responseCode") // 响应码
private String responseCode;
@CsvBindByName(column = "responseMessage") // 响应信息
private String responseMessage;
@CsvBindByName(column = "threadName") // 请求所属线程
private String threadName;
@CsvBindByName(column = "dataType") // 数据类型
private String dataType;
@CsvBindByName(column = "success") // 访问是否成功
private String success;
@CsvBindByName(column = "failureMessage") // 访问失败信息
private String failureMessage;
@CsvBindByName(column = "bytes") //
private String bytes;
@CsvBindByName(column = "sentBytes") //
private String sentBytes;
@CsvBindByName(column = "grpThreads") // 线程组
private String grpThreads;
@CsvBindByName(column = "allThreads") //
private String allThreads;
@CsvBindByName(column = "URL") //
private String url;
@CsvBindByName(column = "Latency") // 延时
private String latency;
@CsvBindByName(column = "IdleTime") // 闲置时间
private String idleTime;
@CsvBindByName(column = "Connect") //
private String connect;
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getElapsed() {
return elapsed;
}
public void setElapsed(String elapsed) {
this.elapsed = elapsed;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
public String getResponseMessage() {
return responseMessage;
}
public void setResponseMessage(String responseMessage) {
this.responseMessage = responseMessage;
}
public String getThreadName() {
return threadName;
}
public void setThreadName(String threadName) {
this.threadName = threadName;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public String getFailureMessage() {
return failureMessage;
}
public void setFailureMessage(String failureMessage) {
this.failureMessage = failureMessage;
}
public String getBytes() {
return bytes;
}
public void setBytes(String bytes) {
this.bytes = bytes;
}
public String getSentBytes() {
return sentBytes;
}
public void setSentBytes(String sentBytes) {
this.sentBytes = sentBytes;
}
public String getGrpThreads() {
return grpThreads;
}
public void setGrpThreads(String grpThreads) {
this.grpThreads = grpThreads;
}
public String getAllThreads() {
return allThreads;
}
public void setAllThreads(String allThreads) {
this.allThreads = allThreads;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getLatency() {
return latency;
}
public void setLatency(String latency) {
this.latency = latency;
}
public String getIdleTime() {
return idleTime;
}
public void setIdleTime(String idleTime) {
this.idleTime = idleTime;
}
public String getConnect() {
return connect;
}
public void setConnect(String connect) {
this.connect = connect;
}
}
package io.metersphere.report.base;
import lombok.Data;
@Data
public class ReportTimeInfo {
private String duration;
private String startTime;
private String endTime;
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}
package io.metersphere.report.base;
import lombok.Data;
@Data
public class Statistics {
private String label;
......@@ -28,107 +31,4 @@ public class Statistics {
private String sent;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getSamples() {
return samples;
}
public void setSamples(String samples) {
this.samples = samples;
}
public String getKo() {
return ko;
}
public void setKo(String ko) {
this.ko = ko;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getAverage() {
return average;
}
public void setAverage(String average) {
this.average = average;
}
public String getMin() {
return min;
}
public void setMin(String min) {
this.min = min;
}
public String getMax() {
return max;
}
public void setMax(String max) {
this.max = max;
}
public String getTp90() {
return tp90;
}
public void setTp90(String tp90) {
this.tp90 = tp90;
}
public String getTp95() {
return tp95;
}
public void setTp95(String tp95) {
this.tp95 = tp95;
}
public String getTp99() {
return tp99;
}
public void setTp99(String tp99) {
this.tp99 = tp99;
}
public String getTransactions() {
return transactions;
}
public void setTransactions(String transactions) {
this.transactions = transactions;
}
public String getSent() {
return sent;
}
public void setSent(String sent) {
this.sent = sent;
}
public String getReceived() {
return received;
}
public void setReceived(String received) {
this.received = received;
}
}
package io.metersphere.report.base;
import lombok.Data;
@Data
public class TestOverview {
private String maxUsers;
......@@ -9,51 +12,4 @@ public class TestOverview {
private String responseTime90;
private String avgBandwidth;
public String getMaxUsers() {
return maxUsers;
}
public void setMaxUsers(String maxUsers) {
this.maxUsers = maxUsers;
}
public String getAvgThroughput() {
return avgThroughput;
}
public void setAvgThroughput(String avgThroughput) {
this.avgThroughput = avgThroughput;
}
public String getErrors() {
return errors;
}
public void setErrors(String errors) {
this.errors = errors;
}
public String getAvgResponseTime() {
return avgResponseTime;
}
public void setAvgResponseTime(String avgResponseTime) {
this.avgResponseTime = avgResponseTime;
}
public String getResponseTime90() {
return responseTime90;
}
public void setResponseTime90(String responseTime90) {
this.responseTime90 = responseTime90;
}
public String getAvgBandwidth() {
return avgBandwidth;
}
public void setAvgBandwidth(String avgBandwidth) {
this.avgBandwidth = avgBandwidth;
}
}
......@@ -67,7 +67,7 @@ public class ShiroDBRealm extends AuthorizingRealm {
UserDTO user = userService.getUserDTO(userId);
String msg;
if (user == null) {
msg = "not exist user is trying to login, user:" + userId;
msg = "The user does not exist: " + userId;
logger.warn(msg);
throw new UnknownAccountException(msg);
}
......
......@@ -4,12 +4,14 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.OrganizationMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.WorkspaceMapper;
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.OrganizationRequest;
import io.metersphere.dto.OrganizationMemberDTO;
import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.user.SessionUser;
......@@ -39,6 +41,12 @@ public class OrganizationService {
private UserMapper userMapper;
@Resource
private ExtOrganizationMapper extOrganizationMapper;
@Resource
private WorkspaceMapper workspaceMapper;
@Resource
private WorkspaceService workspaceService;
@Resource
private UserService userService;
public Organization addOrganization(Organization organization) {
long currentTimeMillis = System.currentTimeMillis();
......@@ -59,6 +67,23 @@ public class OrganizationService {
}
public void deleteOrganization(String organizationId) {
WorkspaceExample example = new WorkspaceExample();
WorkspaceExample.Criteria criteria = example.createCriteria();
criteria.andOrganizationIdEqualTo(organizationId);
// delete workspace
List<Workspace> workspaces = workspaceMapper.selectByExample(example);
List<String> workspaceIdList = workspaces.stream().map(Workspace::getId).collect(Collectors.toList());
for (String workspaceId : workspaceIdList) {
workspaceService.deleteWorkspace(workspaceId);
}
// delete organization member
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andSourceIdEqualTo(organizationId);
userRoleMapper.deleteByExample(userRoleExample);
// delete org
organizationMapper.deleteByPrimaryKey(organizationId);
}
......@@ -123,7 +148,8 @@ public class OrganizationService {
}
public void checkOrgOwner(String organizationId) {
SessionUser user = SessionUtils.getUser();
SessionUser sessionUser = SessionUtils.getUser();
UserDTO user = userService.getUserDTO(sessionUser.getId());
List<String> collect = user.getUserRoles().stream()
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
.map(UserRole::getSourceId)
......
......@@ -50,13 +50,35 @@ public class PerformanceTestService {
@Resource
private LoadTestReportLogMapper loadTestReportLogMapper;
@Resource
private LoadTestReportResultMapper loadTestReportResultMapper;
@Resource
private TestResourceService testResourceService;
@Resource
private ReportService reportService;
public List<LoadTestDTO> list(QueryTestPlanRequest request) {
return extLoadTestMapper.list(request);
}
public void delete(DeleteTestPlanRequest request) {
String testId = request.getId();
LoadTestReportExample loadTestReportExample = new LoadTestReportExample();
loadTestReportExample.createCriteria().andTestIdEqualTo(testId);
List<LoadTestReport> loadTestReports = loadTestReportMapper.selectByExample(loadTestReportExample);
List<String> reportIdList = loadTestReports.stream().map(LoadTestReport::getId).collect(Collectors.toList());
// delete load_test_report_result
LoadTestReportResultExample loadTestReportResultExample = new LoadTestReportResultExample();
loadTestReportResultExample.createCriteria().andReportIdIn(reportIdList);
loadTestReportResultMapper.deleteByExample(loadTestReportResultExample);
// delete load_test_report, delete load_test_report_detail
reportIdList.forEach(reportId -> {
loadTestReportDetailMapper.deleteByPrimaryKey(reportId);
reportService.deleteReport(reportId);
});
// delete load_test
loadTestMapper.deleteByPrimaryKey(request.getId());
deleteFileByTestId(request.getId());
......
package io.metersphere.service;
import io.metersphere.base.domain.LoadTest;
import io.metersphere.base.domain.LoadTestExample;
import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectExample;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.controller.request.testplan.DeleteTestPlanRequest;
import io.metersphere.dto.ProjectDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.user.SessionUtils;
......@@ -16,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
......@@ -24,6 +29,10 @@ public class ProjectService {
private ProjectMapper projectMapper;
@Resource
private ExtProjectMapper extProjectMapper;
@Resource
private PerformanceTestService performanceTestService;
@Resource
private LoadTestMapper loadTestMapper;
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
......@@ -54,11 +63,27 @@ public class ProjectService {
}
public void deleteProject(String projectId) {
// delete test
LoadTestExample loadTestExample = new LoadTestExample();
loadTestExample.createCriteria().andProjectIdEqualTo(projectId);
List<LoadTest> loadTests = loadTestMapper.selectByExample(loadTestExample);
List<String> loadTestIdList = loadTests.stream().map(LoadTest::getId).collect(Collectors.toList());
loadTestIdList.forEach(loadTestId -> {
DeleteTestPlanRequest deleteTestPlanRequest = new DeleteTestPlanRequest();
deleteTestPlanRequest.setId(loadTestId);
performanceTestService.delete(deleteTestPlanRequest);
});
// TODO 删除项目下 测试跟踪 相关
// TODO 删除项目下 接口测试 相关
// delete project
projectMapper.deleteByPrimaryKey(projectId);
}
public void updateProject(Project project) {
project.setCreateTime(null);// 创建时间禁止修改
project.setCreateTime(null);
project.setUpdateTime(System.currentTimeMillis());
projectMapper.updateByPrimaryKeySelective(project);
}
......
package io.metersphere.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.LoadTestReportLogMapper;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.LoadTestReportResultMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
......@@ -20,8 +22,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
......@@ -35,6 +39,10 @@ public class ReportService {
private LoadTestMapper loadTestMapper;
@Resource
private LoadTestReportResultMapper loadTestReportResultMapper;
@Resource
private LoadTestReportLogMapper loadTestReportLogMapper;
@Resource
private TestResourceService testResourceService;
public List<ReportDTO> getRecentReportList(ReportRequest request) {
return extLoadTestReportMapper.getReportList(request);
......@@ -150,7 +158,34 @@ public class ReportService {
}
public Map<String, String> log(String reportId) {
// todo 查询日志
return null;
Map<String, String> logMap = new HashMap<>();
LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId);
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
loadTestReportLogs.stream().map(log -> {
Map<String, String> result = new HashMap<>();
TestResource testResource = testResourceService.getTestResource(log.getResourceId());
if (testResource == null) {
result.put(log.getResourceId(), log.getContent());
return result;
}
String configuration = testResource.getConfiguration();
JSONObject object = JSON.parseObject(configuration);
if (StringUtils.isNotBlank(object.getString("masterUrl"))) {
result.put(object.getString("masterUrl"), log.getContent());
return result;
}
if (StringUtils.isNotBlank(object.getString("ip"))) {
result.put(object.getString("ip"), log.getContent());
return result;
}
result.put(log.getResourceId(), log.getContent());
return result;
}).forEach(log -> logMap.putAll(log.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
);
return logMap;
}
}
......@@ -92,7 +92,7 @@ public class TestCaseNodeService {
List<TestCaseNodeDTO> childrens = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>());
lowerNodes.forEach(node -> {
if (node.getpId().equals(rootNode.getId())){
if (node.getPId().equals(rootNode.getId())){
childrens.add(buildNodeTree(nodeLevelMap, node));
nodeTree.setChildren(childrens);
}
......@@ -327,7 +327,7 @@ public class TestCaseNodeService {
private Integer insertTestCaseNode(String nodeName, Integer pId, String projectId, Integer level) {
TestCaseNode testCaseNode = new TestCaseNode();
testCaseNode.setName(nodeName.trim());
testCaseNode.setpId(pId);
testCaseNode.setPId(pId);
testCaseNode.setProjectId(projectId);
testCaseNode.setCreateTime(System.currentTimeMillis());
testCaseNode.setUpdateTime(System.currentTimeMillis());
......
......@@ -7,15 +7,16 @@ import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.base.domain.TestResourcePoolExample;
import io.metersphere.base.mapper.TestResourceMapper;
import io.metersphere.base.mapper.TestResourcePoolMapper;
import io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.NodeDTO;
import io.metersphere.dto.TestResourcePoolDTO;
import io.metersphere.engine.kubernetes.provider.KubernetesProvider;
import io.metersphere.i18n.Translator;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
......@@ -25,10 +26,13 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID;
import static io.metersphere.commons.constants.ResourceStatusEnum.VALID;
/**
......@@ -45,8 +49,6 @@ public class TestResourcePoolService {
@Resource
private TestResourceMapper testResourceMapper;
@Resource
private ExtTestReourcePoolMapper extTestReourcePoolMapper;
@Resource
private RestTemplate restTemplate;
public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) {
......@@ -71,7 +73,27 @@ public class TestResourcePoolService {
}
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
return extTestReourcePoolMapper.listResourcePools(request);
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(request.getName())) {
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
}
List<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example);
List<TestResourcePoolDTO> testResourcePoolDTOS = new ArrayList<>();
testResourcePools.forEach(pool -> {
TestResourceExample example2 = new TestResourceExample();
example2.createCriteria().andTestResourcePoolIdEqualTo(pool.getId());
List<TestResource> testResources = testResourceMapper.selectByExampleWithBLOBs(example2);
TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO();
try {
BeanUtils.copyProperties(testResourcePoolDTO, pool);
testResourcePoolDTO.setResources(testResources);
testResourcePoolDTOS.add(testResourcePoolDTO);
} catch (IllegalAccessException | InvocationTargetException e) {
LogUtil.error(e);
}
});
return testResourcePoolDTOS;
}
private void validateTestResourcePool(TestResourcePoolDTO testResourcePool) {
......@@ -98,6 +120,7 @@ public class TestResourcePoolService {
if (nodeIps.size() < testResourcePool.getResources().size()) {
MSException.throwException(Translator.get("duplicate_node_ip"));
}
testResourcePool.setStatus(VALID.name());
for (TestResource resource : testResourcePool.getResources()) {
NodeDTO nodeDTO = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
boolean isValidate = validateNode(nodeDTO);
......@@ -134,6 +157,7 @@ public class TestResourcePoolService {
KubernetesProvider provider = new KubernetesProvider(testResource.getConfiguration());
provider.validateCredential();
testResource.setStatus(VALID.name());
testResourcePool.setStatus(VALID.name());
} catch (Exception e) {
testResource.setStatus(ResourceStatusEnum.INVALID.name());
testResourcePool.setStatus(ResourceStatusEnum.INVALID.name());
......@@ -161,6 +185,18 @@ public class TestResourcePoolService {
}
public List<TestResourcePool> listValidResourcePools() {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
List<TestResourcePoolDTO> testResourcePools = listResourcePools(request);
// 重新校验 pool
for (TestResourcePoolDTO pool : testResourcePools) {
try {
updateTestResourcePool(pool);
} catch (MSException e) {
pool.setStatus(INVALID.name());
pool.setUpdateTime(System.currentTimeMillis());
testResourcePoolMapper.updateByPrimaryKeySelective(pool);
}
}
TestResourcePoolExample example = new TestResourcePoolExample();
example.createCriteria().andStatusEqualTo(ResourceStatusEnum.VALID.name());
return testResourcePoolMapper.selectByExample(example);
......
......@@ -47,4 +47,8 @@ public class TestResourceService {
example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
return testResourceMapper.selectByExampleWithBLOBs(example);
}
public TestResource getTestResource(String resourceId) {
return testResourceMapper.selectByPrimaryKey(resourceId);
}
}
......@@ -128,7 +128,11 @@ public class UserService {
userMapper.updateByPrimaryKeySelective(user);
}
public void switchUserRole(UserDTO user, String sign, String sourceId) {
public void switchUserRole(String sign, String sourceId) {
SessionUser sessionUser = SessionUtils.getUser();
// 获取最新UserDTO
UserDTO user = getUserDTO(sessionUser.getId());
User newUser = new User();
if (StringUtils.equals("organization", sign)) {
user.setLastOrganizationId(sourceId);
......
package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.WorkspaceMapper;
......@@ -10,6 +11,7 @@ import io.metersphere.base.mapper.ext.ExtWorkspaceMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.WorkspaceRequest;
import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.dto.WorkspaceDTO;
import io.metersphere.dto.WorkspaceMemberDTO;
......@@ -41,6 +43,12 @@ public class WorkspaceService {
private UserMapper userMapper;
@Resource
private ExtOrganizationMapper extOrganizationMapper;
@Resource
private ProjectService projectService;
@Resource
private ProjectMapper projectMapper;
@Resource
private UserService userService;
public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) {
......@@ -89,6 +97,21 @@ public class WorkspaceService {
}
public void deleteWorkspace(String workspaceId) {
// delete project
ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
List<Project> projectList = projectMapper.selectByExample(projectExample);
List<String> projectIdList = projectList.stream().map(Project::getId).collect(Collectors.toList());
projectIdList.forEach(projectId -> {
projectService.deleteProject(projectId);
});
// delete workspace member
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andSourceIdEqualTo(workspaceId);
userRoleMapper.deleteByExample(userRoleExample);
// delete workspace
workspaceMapper.deleteByPrimaryKey(workspaceId);
}
......@@ -98,7 +121,8 @@ public class WorkspaceService {
public void checkWorkspaceOwnerByOrgAdmin(String workspaceId) {
checkWorkspaceIsExist(workspaceId);
WorkspaceExample example = new WorkspaceExample();
SessionUser user = SessionUtils.getUser();
SessionUser sessionUser = SessionUtils.getUser();
UserDTO user = userService.getUserDTO(sessionUser.getId());
List<String> orgIds = user.getUserRoles().stream()
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
.map(UserRole::getSourceId)
......@@ -114,7 +138,8 @@ public class WorkspaceService {
public void checkWorkspaceOwner(String workspaceId) {
checkWorkspaceIsExist(workspaceId);
WorkspaceExample example = new WorkspaceExample();
SessionUser user = SessionUtils.getUser();
SessionUser sessionUser = SessionUtils.getUser();
UserDTO user = userService.getUserDTO(sessionUser.getId());
List<String> orgIds = user.getUserRoles().stream()
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
.map(UserRole::getSourceId)
......
......@@ -22,7 +22,7 @@ mybatis.configuration.use-column-label=true
mybatis.configuration.auto-mapping-behavior=full
mybatis.configuration.default-statement-timeout=25000
logging.file.path=/opt/fit2cloud/logs/${spring.application.name}
logging.file.path=/opt/metersphere/logs/${spring.application.name}
# view
spring.resources.static-locations=classpath:/templates/,classpath:/static/
......@@ -36,4 +36,31 @@ spring.flyway.baseline-version=0
spring.flyway.encoding=UTF-8
spring.flyway.validate-on-migrate=false
spring.messages.basename=i18n/messages
\ No newline at end of file
spring.messages.basename=i18n/messages
# kafka
kafka.acks=1
kafka.fields=
kafka.timestamp=yyyy-MM-dd'T'HH:mm:ss.SSSZZ
kafka.sample-filter=
kafka.test-mode=info
kafka.parse-all-req-headers=false
kafka.parse-all-res-headers=false
kafka.compression-type=
kafka.batch-size=16384
kafka.client-id=JMeterKafkaBackendListener
kafka.connections-max-idle-ms=180000
kafka.ssl.enabled=false
kafka.ssl.key-password=
kafka.ssl.keystore-location=
kafka.ssl.keystore-password=
kafka.ssl.truststore-location=
kafka.ssl.truststore-password=
kafka.ssl.enabled-protocols=TLSv1.2,TLSv1.1,TLSv1
kafka.ssl.keystore-type=JKS
kafka.ssl.protocol=TLS
kafka.ssl.provider=
kafka.ssl.truststore-type=
# jmeter
jmeter.image=registry.fit2cloud.com/metersphere/jmeter-master:0.0.4
\ No newline at end of file
......@@ -3,14 +3,27 @@
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
<!--配置数据库连接的位置-->
<properties url="file:///opt/fit2cloud/conf/metersphere.properties"/>
<properties url="file:///opt/metersphere/conf/metersphere.properties"/>
<!-- 设置mysql驱动路径 -->
<!--<classPathEntry location="/Users/liuruibin/.m2/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar"/>-->
<!-- 此处指定生成针对MyBatis3的DAO -->
<context id="mysql" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<!-- Lombok插件 -->
<plugin type="com.itfsw.mybatis.generator.plugins.LombokPlugin">
<!-- @Data 默认开启,同时插件会对子类自动附加@EqualsAndHashCode(callSuper = true),@ToString(callSuper = true) -->
<property name="@Data" value="true"/>
<!-- @Builder 必须在 Lombok 版本 >= 1.18.2 的情况下开启,对存在继承关系的类自动替换成@SuperBuilder -->
<property name="@Builder" value="false"/>
<!-- @NoArgsConstructor 和 @AllArgsConstructor 使用规则和Lombok一致 -->
<property name="@AllArgsConstructor" value="false"/>
<property name="@NoArgsConstructor" value="false"/>
<!-- @Getter、@Setter、@Accessors 等使用规则参见官方文档 -->
<property name="@Accessors(chain = true)" value="false"/>
<!-- 临时解决IDEA工具对@SuperBuilder的不支持问题,开启后(默认未开启)插件在遇到@SuperBuilder注解时会调用ModelBuilderPlugin来生成相应的builder代码 -->
<property name="supportSuperBuilderForIdea" value="false"/>
</plugin>
<!-- 用来除去时间信息的,这在配合类似subversion的代码管理工具时使用很有效,因为可以减少没有必要的注释迁入 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
......@@ -46,15 +59,6 @@
<!--要生成的数据库表 -->
<!--<table tableName="api_test"/>-->
<!--<table tableName="api_test_file"/>-->
<!--<table tableName="api_test_report"/>-->
<!--<table tableName="test_case_node">-->
<!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--</table>-->
<!--<table tableName="test_case"/>-->
<!--<table tableName="test_plan_test_case"/>-->
<table tableName="test_case_report_template">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
......
......@@ -28,4 +28,6 @@ user_email_already_exists=User email already exists
user_name_is_null=User name cannot be null
user_email_is_null=User email cannot be null
password_is_null=Password cannot be null
workspace_not_exists=Workspace is not exists
\ No newline at end of file
workspace_not_exists=Workspace is not exists
#api
api_load_script_error="Load script error"
\ No newline at end of file
......@@ -28,4 +28,6 @@ user_email_already_exists=用户邮箱已存在
user_name_is_null=用户名不能为空
user_email_is_null=用户邮箱不能为空
password_is_null=密码不能为空
workspace_not_exists=工作空间不存在
\ No newline at end of file
workspace_not_exists=工作空间不存在
#api
api_load_script_error="读取脚本失败"
\ No newline at end of file
package io.metersphere;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.utils.CompressUtils;
import io.metersphere.service.RegistryParamService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApplicationTests {
@Resource
UserMapper userMapper;
@Resource
private RegistryParamService registryParamService;
@Test
public void test1() {
final Object test = CompressUtils.zip("test".getBytes());
final Object unzip = CompressUtils.unzip(test);
System.out.println(new String((byte[]) unzip));
}
@Test
public void test2() {
List<SystemParameter> registry = registryParamService.getRegistry(ParamConstants.Classify.REGISTRY.getValue());
System.out.println(registry);
for (SystemParameter sp : registry) {
if ("registry.password".equals(sp.getParamKey())) {
sp.setParamValue("Calong@2015");
}
if ("registry.url".equals(sp.getParamKey())) {
sp.setParamValue("registry.fit2cloud.com");
}
if ("registry.repo".equals(sp.getParamKey())) {
sp.setParamValue("metersphere");
}
if ("registry.username".equals(sp.getParamKey())) {
sp.setParamValue("developer");
}
}
registryParamService.updateRegistry(registry);
}
}
package io.metersphere;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.junit.Before;
import org.junit.Test;
public class BaseTest {
protected KubernetesClient kubernetesClient;
@Before
public void before() {
try {
ConfigBuilder configBuilder = new ConfigBuilder();
configBuilder.withMasterUrl("https://172.16.10.93:6443");
kubernetesClient = new DefaultKubernetesClient(configBuilder.build());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@Test
public void test1() {
PodList list = kubernetesClient.pods().list();
for (Pod item : list.getItems()) {
System.out.println(item);
}
}
}
package io.metersphere;
import com.opencsv.bean.CsvToBean;
import com.opencsv.bean.CsvToBeanBuilder;
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
import io.metersphere.base.domain.LoadTestReportDetail;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.mapper.LoadTestReportDetailMapper;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.report.base.Metric;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.io.Reader;
import java.io.StringReader;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ReportContentTests {
@Resource
private LoadTestReportDetailMapper loadTestReportDetailMapper;
@Resource
private LoadTestReportMapper loadTestReportMapper;
@Test
public void test1() {
String reportId = "ba972086-7d74-4f58-99b0-9c014114fd99";
LoadTestReportDetail loadTestReportDetail = loadTestReportDetailMapper.selectByPrimaryKey(reportId);
LoadTestReportWithBLOBs loadTestReportWithBLOBs = loadTestReportMapper.selectByPrimaryKey(reportId);
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
ms.setType(Metric.class);
try (Reader reader = new StringReader(loadTestReportDetail.getContent())) {
CsvToBean<Metric> cb = new CsvToBeanBuilder<Metric>(reader)
.withType(Metric.class)
.withSkipLines(0)
.withMappingStrategy(ms)
.withIgnoreLeadingWhiteSpace(true)
.build();
System.out.println(cb.parse().size());
} catch (Exception ex) {
ex.printStackTrace();
}
try (Reader reader = new StringReader(loadTestReportWithBLOBs.getContent())) {
CsvToBean<Metric> cb = new CsvToBeanBuilder<Metric>(reader)
.withType(Metric.class)
.withSkipLines(0)
.withMappingStrategy(ms)
.withIgnoreLeadingWhiteSpace(true)
.build();
System.out.println(cb.parse().size());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
package io.metersphere.service;
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.dto.TestResourcePoolDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TestResourcePoolServiceTest {
@Resource
private TestResourcePoolService testResourcePoolService;
@Test
public void listResourcePools() {
List<TestResourcePoolDTO> list = testResourcePoolService.listResourcePools(new QueryResourcePoolRequest());
System.out.println(list.size());
}
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册