Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
xiaofang li
MeterSphere
Commits
26d7a007
Commit
26d7a007
authored
4 years ago
by
Captain.B
Committed by
刘瑞斌
4 years ago
Browse files
Options
Download
Email Patches
Plain Diff
refactor(性能测试): 同步各个节点的启动时间
parent
41b387b8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java
+1
-0
...rc/main/java/io/metersphere/commons/utils/ShiroUtils.java
backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java
+20
-2
...ersphere/performance/controller/JmeterFileController.java
backend/src/main/java/io/metersphere/performance/engine/EngineContext.java
+0
-9
...java/io/metersphere/performance/engine/EngineContext.java
backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java
+1
-2
...java/io/metersphere/performance/engine/EngineFactory.java
backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java
+0
-1
...erformance/parse/xml/reader/jmx/JmeterDocumentParser.java
backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java
+2
-2
...io/metersphere/performance/service/JmeterFileService.java
with
24 additions
and
16 deletions
+24
-16
backend/src/main/java/io/metersphere/commons/utils/ShiroUtils.java
+
1
-
0
View file @
26d7a007
...
...
@@ -29,6 +29,7 @@ public class ShiroUtils {
filterChainDefinitionMap
.
put
(
"/display/file/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/jmeter/download/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/jmeter/ping"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/jmeter/ready/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/authsource/list/allenable"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/sso/signin"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/sso/callback"
,
"anon"
);
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java
+
20
-
2
View file @
26d7a007
package
io.metersphere.performance.controller
;
import
io.metersphere.commons.utils.WeakConcurrentHashMap
;
import
io.metersphere.controller.handler.annotation.NoResultHolder
;
import
io.metersphere.performance.service.JmeterFileService
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
...
...
@@ -12,25 +14,41 @@ import org.springframework.web.bind.annotation.RestController;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"jmeter"
)
public
class
JmeterFileController
{
@Resource
private
JmeterFileService
jmeterFileService
;
private
final
WeakConcurrentHashMap
<
String
,
List
<
Double
>>
readyMap
=
new
WeakConcurrentHashMap
<>(
600_000
);
// 默认保留10分钟
@GetMapping
(
"ping"
)
public
String
checkStatus
()
{
return
"PONG"
;
}
@GetMapping
(
"ready"
)
@NoResultHolder
public
long
ready
(
@RequestParam
(
"reportId"
)
String
reportId
,
@RequestParam
(
"ratio"
)
String
ratio
,
@RequestParam
(
"resourceIndex"
)
int
resourceIndex
)
{
try
{
List
<
Double
>
ratios
=
readyMap
.
getOrDefault
(
reportId
,
Arrays
.
stream
(
ratio
.
split
(
","
)).
map
(
Double:
:
parseDouble
).
collect
(
Collectors
.
toList
()));
ratios
.
set
(
resourceIndex
,
-
1.0
);
readyMap
.
put
(
reportId
,
ratios
);
return
ratios
.
stream
().
filter
(
r
->
r
>
0
).
count
();
}
catch
(
Exception
e
)
{
return
0
;
}
}
@GetMapping
(
"download"
)
public
ResponseEntity
<
byte
[]>
downloadJmeterFiles
(
@RequestParam
(
"testId"
)
String
testId
,
@RequestParam
(
"resourceId"
)
String
resourceId
,
@RequestParam
(
"ratio"
)
String
ratio
,
@RequestParam
(
"reportId"
)
String
reportId
,
@RequestParam
(
"resourceIndex"
)
int
resourceIndex
)
{
long
startTime
=
System
.
currentTimeMillis
();
double
[]
ratios
=
Arrays
.
stream
(
ratio
.
split
(
","
)).
mapToDouble
(
Double:
:
parseDouble
).
toArray
();
byte
[]
bytes
=
jmeterFileService
.
downloadZip
(
testId
,
ratios
,
startTime
,
reportId
,
resourceIndex
);
byte
[]
bytes
=
jmeterFileService
.
downloadZip
(
testId
,
ratios
,
reportId
,
resourceIndex
);
return
ResponseEntity
.
ok
()
.
contentType
(
MediaType
.
parseMediaType
(
"application/octet-stream"
))
.
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=\""
+
testId
+
".zip\""
)
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/performance/engine/EngineContext.java
+
0
-
9
View file @
26d7a007
...
...
@@ -10,7 +10,6 @@ public class EngineContext {
private
String
fileType
;
private
String
content
;
private
String
resourcePoolId
;
private
Long
startTime
;
private
String
reportId
;
private
Integer
resourceIndex
;
private
Map
<
String
,
Object
>
properties
=
new
HashMap
<>();
...
...
@@ -76,14 +75,6 @@ public class EngineContext {
this
.
resourcePoolId
=
resourcePoolId
;
}
public
Long
getStartTime
()
{
return
startTime
;
}
public
void
setStartTime
(
Long
startTime
)
{
this
.
startTime
=
startTime
;
}
public
String
getReportId
()
{
return
reportId
;
}
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/performance/engine/EngineFactory.java
+
1
-
2
View file @
26d7a007
...
...
@@ -88,7 +88,7 @@ public class EngineFactory {
return
null
;
}
public
static
EngineContext
createContext
(
LoadTestWithBLOBs
loadTest
,
double
[]
ratios
,
long
startTime
,
String
reportId
,
int
resourceIndex
)
{
public
static
EngineContext
createContext
(
LoadTestWithBLOBs
loadTest
,
double
[]
ratios
,
String
reportId
,
int
resourceIndex
)
{
final
List
<
FileMetadata
>
fileMetadataList
=
performanceTestService
.
getFileMetadataByTestId
(
loadTest
.
getId
());
if
(
org
.
springframework
.
util
.
CollectionUtils
.
isEmpty
(
fileMetadataList
))
{
MSException
.
throwException
(
Translator
.
get
(
"run_load_test_file_not_found"
)
+
loadTest
.
getId
());
...
...
@@ -104,7 +104,6 @@ public class EngineFactory {
engineContext
.
setNamespace
(
loadTest
.
getProjectId
());
engineContext
.
setFileType
(
FileType
.
JMX
.
name
());
engineContext
.
setResourcePoolId
(
loadTest
.
getTestResourcePoolId
());
engineContext
.
setStartTime
(
startTime
);
engineContext
.
setReportId
(
reportId
);
engineContext
.
setResourceIndex
(
resourceIndex
);
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java
+
0
-
1
View file @
26d7a007
...
...
@@ -655,7 +655,6 @@ public class JmeterDocumentParser implements DocumentParser {
// 添加关联关系 test.id test.name test.startTime test.reportId
collectionProp
.
appendChild
(
createKafkaProp
(
document
,
"test.id"
,
context
.
getTestId
()));
collectionProp
.
appendChild
(
createKafkaProp
(
document
,
"test.name"
,
context
.
getTestName
()));
collectionProp
.
appendChild
(
createKafkaProp
(
document
,
"test.startTime"
,
context
.
getStartTime
().
toString
()));
collectionProp
.
appendChild
(
createKafkaProp
(
document
,
"test.reportId"
,
context
.
getReportId
()));
elementProp
.
appendChild
(
collectionProp
);
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java
+
2
-
2
View file @
26d7a007
...
...
@@ -29,10 +29,10 @@ public class JmeterFileService {
@Resource
private
ExtLoadTestReportMapper
extLoadTestReportMapper
;
public
byte
[]
downloadZip
(
String
testId
,
double
[]
ratios
,
long
startTime
,
String
reportId
,
int
resourceIndex
)
{
public
byte
[]
downloadZip
(
String
testId
,
double
[]
ratios
,
String
reportId
,
int
resourceIndex
)
{
try
{
LoadTestWithBLOBs
loadTest
=
loadTestMapper
.
selectByPrimaryKey
(
testId
);
EngineContext
context
=
EngineFactory
.
createContext
(
loadTest
,
ratios
,
startTime
,
reportId
,
resourceIndex
);
EngineContext
context
=
EngineFactory
.
createContext
(
loadTest
,
ratios
,
reportId
,
resourceIndex
);
return
zipFilesToByteArray
(
context
);
}
catch
(
MSException
e
)
{
LogUtil
.
error
(
e
.
getMessage
(),
e
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment