refactor
This commit is contained in:
parent
d922460310
commit
8e11cdc79b
|
@ -30,13 +30,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.lowagie.text.Document;
|
||||
import com.lowagie.text.Element;
|
||||
import com.lowagie.text.Paragraph;
|
||||
|
||||
@Component
|
||||
public class MonitorReportService {
|
||||
public static String Processor = "ProcessorTimePercent";
|
||||
public static String Memory = "Memory";
|
||||
public static String logical_Disk = "logicalDisk";
|
||||
public static String network_Interface = "networkInterface";
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanService testPlanService;
|
||||
private MonitorResultService monitorResultService;
|
||||
|
@ -146,11 +146,21 @@ public class MonitorReportService {
|
|||
|
||||
private void createSUTImage(String hostName,
|
||||
MonitorResultContainerModel container, Document document) {
|
||||
createLogicalDiskImage(container.getLogicalDiskResponseModels(),
|
||||
document);
|
||||
createMemoryImage(container.getMemoryResponseModels(), document);
|
||||
createNetworkImage(container.getNetWorkReponseModels(), document);
|
||||
createProcessorImage(container.getProcessorResponseModels(), document);
|
||||
try {
|
||||
ReportService.addParagraph(logical_Disk, document);
|
||||
createLogicalDiskImage(container.getLogicalDiskResponseModels(),
|
||||
document);
|
||||
ReportService.addParagraph(Memory, document);
|
||||
createMemoryImage(container.getMemoryResponseModels(), document);
|
||||
ReportService.addParagraph(network_Interface, document);
|
||||
createNetworkImage(container.getNetWorkReponseModels(), document);
|
||||
ReportService.addParagraph(Processor, document);
|
||||
createProcessorImage(container.getProcessorResponseModels(),
|
||||
document);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createProcessorImage(List<MonitorProcessorResponseModel> list,
|
||||
|
@ -158,37 +168,26 @@ public class MonitorReportService {
|
|||
if (list == null || list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
int processorCount = list.get(0).getProcessorModel()
|
||||
int seriesCount = list.get(0).getProcessorModel()
|
||||
.getProcessorModelList().size();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
|
||||
TimeSeries[] timeSeriesArray = new TimeSeries[processorCount];
|
||||
for (int i = 0; i < timeSeriesArray.length; i++) {
|
||||
timeSeriesArray[i] = new TimeSeries("Processor-" + i);
|
||||
}
|
||||
|
||||
TimeSeries[] timeSeriesArray = ReportService.buildSeries(seriesCount,
|
||||
Processor);
|
||||
|
||||
for (MonitorProcessorResponseModel model : list) {
|
||||
for (int i = 0; i < processorCount; i++) {
|
||||
for (int i = 0; i < seriesCount; i++) {
|
||||
timeSeriesArray[i].add(new Second(model.getCreateDatetime()),
|
||||
model.getProcessorModel().getProcessorModelList()
|
||||
.get(i).getProcessorTimePercent());
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < timeSeriesArray.length; i++) {
|
||||
lineDataset.addSeries(timeSeriesArray[i]);
|
||||
}
|
||||
|
||||
JFreeChart chart = ChartFactory.createTimeSeriesChart(Processor,
|
||||
ReportService.Time, Processor, lineDataset, true, true, true);
|
||||
chart.setBackgroundPaint(java.awt.Color.white);
|
||||
try {
|
||||
ChartUtilities.writeChartAsPNG(outputStream, chart, 400, 300);
|
||||
Paragraph paragraph = new Paragraph(Processor);
|
||||
paragraph.setAlignment(Element.ALIGN_CENTER);
|
||||
document.add(paragraph);
|
||||
ReportService.writeImageIntoPdf(outputStream.toByteArray(),
|
||||
document);
|
||||
ReportService
|
||||
.writeImageIntoPdf(
|
||||
ReportService.buildChartStream(document,
|
||||
seriesCount, timeSeriesArray, Processor)
|
||||
.toByteArray(), document);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -213,9 +212,6 @@ public class MonitorReportService {
|
|||
chart.setBackgroundPaint(java.awt.Color.white);
|
||||
try {
|
||||
ChartUtilities.writeChartAsPNG(outputStream, chart, 400, 300);
|
||||
Paragraph paragraph = new Paragraph(Memory);
|
||||
paragraph.setAlignment(Element.ALIGN_CENTER);
|
||||
document.add(paragraph);
|
||||
ReportService.writeImageIntoPdf(outputStream.toByteArray(),
|
||||
document);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
package org.bench4q.master.report;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartUtilities;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.data.time.TimeSeries;
|
||||
import org.jfree.data.time.TimeSeriesCollection;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.lowagie.text.Document;
|
||||
import com.lowagie.text.DocumentException;
|
||||
import com.lowagie.text.Element;
|
||||
import com.lowagie.text.Image;
|
||||
import com.lowagie.text.Paragraph;
|
||||
import com.lowagie.text.pdf.PdfWriter;
|
||||
|
||||
@Component
|
||||
|
@ -53,6 +62,45 @@ public class ReportService {
|
|||
}
|
||||
}
|
||||
|
||||
static void addParagraph(String content, Document document)
|
||||
throws DocumentException {
|
||||
Paragraph paragraph = new Paragraph(content);
|
||||
paragraph.setAlignment(Element.ALIGN_CENTER);
|
||||
document.add(paragraph);
|
||||
}
|
||||
|
||||
static ByteArrayOutputStream buildChartStream(Document document,
|
||||
int seriesCount, TimeSeries[] timeSeriesArray, String value)
|
||||
throws IOException {
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JFreeChart chart = ChartFactory.createTimeSeriesChart(value,
|
||||
ReportService.Time, value, buildDataSet(timeSeriesArray), true,
|
||||
true, true);
|
||||
chart.setBackgroundPaint(java.awt.Color.white);
|
||||
ChartUtilities.writeChartAsPNG(outputStream, chart, 400, 300);
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
static TimeSeries[] buildSeries(int seriesCount, String mainTitle) {
|
||||
TimeSeries[] timeSeriesArray = new TimeSeries[seriesCount];
|
||||
for (int i = 0; i < seriesCount; i++) {
|
||||
timeSeriesArray[i] = new TimeSeries(mainTitle + "-" + i);
|
||||
}
|
||||
return timeSeriesArray;
|
||||
}
|
||||
|
||||
static TimeSeriesCollection buildDataSet(final TimeSeries[] timeSeriesArray) {
|
||||
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
|
||||
if (timeSeriesArray == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < timeSeriesArray.length; i++) {
|
||||
lineDataset.addSeries(timeSeriesArray[i]);
|
||||
}
|
||||
return lineDataset;
|
||||
}
|
||||
|
||||
static void writeImageIntoPdf(byte[] buffer, Document document)
|
||||
throws Exception {
|
||||
Image image = Image.getInstance(buffer);
|
||||
|
|
|
@ -26,6 +26,8 @@ public class TestPlanTester extends TestBase {
|
|||
private TestPlanModel testPlan = new TestPlanModel();
|
||||
private String _url = TestBase.BASE_URL + "/testPlan";
|
||||
private static int SCRIPTID = 3;
|
||||
private static String Monitor_Host_Name = "127.0.0.1";
|
||||
private static String monitor_port = "5556";
|
||||
|
||||
public UUID testWithTestPlanModel() throws JAXBException, IOException {
|
||||
String content;
|
||||
|
@ -129,17 +131,29 @@ public class TestPlanTester extends TestBase {
|
|||
return properties;
|
||||
}
|
||||
|
||||
public void getMonitorResult(UUID testPlanId, String hostName, String port)
|
||||
public void getMonitorMemoryResult(UUID testPlanId, String hostName,
|
||||
String port) throws IOException {
|
||||
getMonitorResult(testPlanId, hostName, port,
|
||||
"/monitorController/memorySUTInfo");
|
||||
|
||||
}
|
||||
|
||||
public void getProcessorResult(UUID testPlanId, String hostName, String port)
|
||||
throws IOException {
|
||||
getMonitorResult(testPlanId, hostName, port,
|
||||
"/monitorController/processorSUTInfo");
|
||||
}
|
||||
|
||||
private void getMonitorResult(UUID testPlanId, String hostName,
|
||||
String port, String relativePath) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunId", testPlanId.toString());
|
||||
params.put("hostName", hostName);
|
||||
params.put("port", port);
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
TestBase.BASE_URL + "/monitorController/memorySUTInfo", params,
|
||||
TestBase.BASE_URL + relativePath, params,
|
||||
this.createAccessTokenMap());
|
||||
System.out.println(httpResponse.getContent());
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws JAXBException, IOException,
|
||||
|
@ -185,10 +199,13 @@ public class TestPlanTester extends TestBase {
|
|||
Thread.sleep(10000);
|
||||
|
||||
this.getScriptBrief(testPlanID, SCRIPTID);
|
||||
this.getMonitorResult(testPlanID, "127.0.0.1", "5556");
|
||||
this.getMonitorMemoryResult(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
Thread.sleep(6000);
|
||||
this.getMonitorResult(testPlanID, "127.0.0.1", "5556");
|
||||
this.getMonitorMemoryResult(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
Thread.sleep(1000);
|
||||
this.getProcessorResult(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
Thread.sleep(1000);
|
||||
this.getProcessorResult(testPlanID, Monitor_Host_Name, monitor_port);
|
||||
this.getTestPlanReport(testPlanID);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue