log
This commit is contained in:
parent
7a6b3770e2
commit
ade105cf3b
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.engine;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Engine {
|
||||
Long getStartTime();
|
||||
|
||||
|
@ -8,4 +10,6 @@ public interface Engine {
|
|||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
Map<String, String> log();
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ import io.metersphere.engine.docker.request.TestRequest;
|
|||
import io.metersphere.i18n.Translator;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DockerTestEngine extends AbstractEngine {
|
||||
|
@ -98,7 +100,22 @@ public class DockerTestEngine extends AbstractEngine {
|
|||
String uri = String.format(BASE_URL + "/jmeter/container/stop/" + testId, ip, port);
|
||||
restTemplate.postForObject(uri, request, String.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> log() {
|
||||
String testId = loadTest.getId();
|
||||
Map<String, String> logs = new HashMap<>();
|
||||
BaseRequest request = new BaseRequest();
|
||||
this.resourceList.forEach(r -> {
|
||||
NodeDTO node = JSON.parseObject(r.getConfiguration(), NodeDTO.class);
|
||||
String ip = node.getIp();
|
||||
Integer port = node.getPort();
|
||||
|
||||
String uri = String.format(BASE_URL + "/jmeter/container/log/" + testId, ip, port);
|
||||
String log = restTemplate.postForObject(uri, request, String.class);
|
||||
logs.put(node.getIp(), log);
|
||||
});
|
||||
return logs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import io.metersphere.i18n.Translator;
|
|||
import org.apache.commons.collections.MapUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class KubernetesTestEngine extends AbstractEngine {
|
||||
|
||||
|
@ -122,4 +123,23 @@ public class KubernetesTestEngine extends AbstractEngine {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> log() {
|
||||
Map<String, String> logs = new HashMap<>();
|
||||
resourceList.forEach(r -> {
|
||||
try {
|
||||
String configuration = r.getConfiguration();
|
||||
ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class);
|
||||
KubernetesProvider provider = new KubernetesProvider(JSON.toJSONString(clientCredential));
|
||||
provider.confirmNamespace(loadTest.getProjectId());
|
||||
String joblog = provider.getKubernetesClient().batch().jobs().inNamespace(loadTest.getProjectId()).withName("job-" + loadTest.getId()).getLog();
|
||||
logs.put(clientCredential.getMasterUrl(), joblog);
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
}
|
||||
|
||||
});
|
||||
return logs;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue