From 451daaacf72c234527f162ed38530f6ad24b5b25 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Thu, 25 Jul 2013 16:14:42 +0800 Subject: [PATCH] add contact with monitor --- .../bench4q/master/api/AgentController.java | 48 +---- .../bench4q/master/api/MonitorController.java | 80 +++++++++ .../master/api/RecordScriptController.java | 1 - .../master/api/TestPlanController.java | 68 ++++++- .../master/api/model/AgentResponseModel.java | 21 ++- .../api/model/MonitorResponseModel.java | 41 +++++ .../master/communication/HttpRequester.java | 32 ++-- .../monitor/LogicalDiskModel.java | 170 ++++++++++++++++++ .../master/test/MonitorControllerTest.java | 125 +++++++++++++ .../bench4q/master/test/TestPlanTester.java | 5 +- 10 files changed, 521 insertions(+), 70 deletions(-) create mode 100644 src/main/java/org/bench4q/master/api/MonitorController.java create mode 100644 src/main/java/org/bench4q/master/api/model/MonitorResponseModel.java create mode 100644 src/main/java/org/bench4q/master/communication/monitor/LogicalDiskModel.java create mode 100644 src/test/java/org/bench4q/master/test/MonitorControllerTest.java diff --git a/src/main/java/org/bench4q/master/api/AgentController.java b/src/main/java/org/bench4q/master/api/AgentController.java index 69c6c6a9..86575248 100644 --- a/src/main/java/org/bench4q/master/api/AgentController.java +++ b/src/main/java/org/bench4q/master/api/AgentController.java @@ -1,19 +1,9 @@ package org.bench4q.master.api; -import java.io.ByteArrayInputStream; -import java.io.IOException; import java.util.Iterator; -import java.util.UUID; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - import org.bench4q.master.api.model.AgentResponseModel; import org.bench4q.master.communication.AgentStateService; import org.bench4q.master.communication.HttpRequester; -import org.bench4q.master.communication.HttpRequester.HttpResponse; -import org.bench4q.master.communication.agent.TestBriefStatusModel; import org.bench4q.master.entity.db.Agent; import org.bench4q.master.service.AgentService; import org.springframework.beans.factory.annotation.Autowired; @@ -70,8 +60,7 @@ public class AgentController extends BaseController { } @RequestMapping(value = "/RemoveAgentFromPool", method = RequestMethod.GET) - public AgentResponseModel removeAgentFromPool( -@RequestParam String hostName) { + public AgentResponseModel removeAgentFromPool(@RequestParam String hostName) { synchronized (this.getAgentPoolService().getAgentLock()) { if (!this.getAgentPoolService().removeAgentFromPool(hostName)) { return setAgentResponseModel(false, @@ -81,6 +70,13 @@ public class AgentController extends BaseController { } } + // TODO: + @RequestMapping(value = "/GetAgentList", method = RequestMethod.GET) + public AgentResponseModel getAgentList() { + // List list = this.getAgentPoolService().loadAgentPoolFromDB(); + return setAgentResponseModel(true, ""); + } + public int getLivingAgentCount() { int livingCount = 0; @@ -107,32 +103,4 @@ public class AgentController extends BaseController { return agentResponseModel; } - @RequestMapping(value = "/getBriefStatusModelFormAgent", method = RequestMethod.POST) - public TestBriefStatusModel getBriefStatusModelFromAgent(String hostString, - int port, UUID runId) { - TestBriefStatusModel resultModel = new TestBriefStatusModel(); - try { - HttpResponse httpResponse = httpRequester.sendGet(hostString + ":" - + port + "/test/brief/" + runId, null, null); - resultModel = extractTestBriefStatusModel(httpResponse.getContent()); - return resultModel; - } catch (IOException e) { - e.printStackTrace(); - return resultModel; - } catch (JAXBException e) { - e.printStackTrace(); - return resultModel; - } - } - - private TestBriefStatusModel extractTestBriefStatusModel(String content) - throws JAXBException { - TestBriefStatusModel resultModel = new TestBriefStatusModel(); - Unmarshaller ummarshaller = JAXBContext.newInstance( - resultModel.getClass()).createUnmarshaller(); - resultModel = (TestBriefStatusModel) ummarshaller - .unmarshal(new ByteArrayInputStream(content.getBytes())); - return resultModel; - } - } \ No newline at end of file diff --git a/src/main/java/org/bench4q/master/api/MonitorController.java b/src/main/java/org/bench4q/master/api/MonitorController.java new file mode 100644 index 00000000..baa38f5d --- /dev/null +++ b/src/main/java/org/bench4q/master/api/MonitorController.java @@ -0,0 +1,80 @@ +package org.bench4q.master.api; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + +import org.bench4q.master.api.model.MonitorResponseModel; +import org.bench4q.master.communication.HttpRequester; +import org.bench4q.master.communication.HttpRequester.HttpResponse; +import org.bench4q.master.communication.monitor.LogicalDiskModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping(value = "/monitorController") +public class MonitorController { + private HttpRequester httpRequester; + + public HttpRequester getHttpRequester() { + return httpRequester; + } + + @Autowired + public void setHttpRequester(HttpRequester httpRequester) { + this.httpRequester = httpRequester; + } + + @RequestMapping(value = "/logicDiskMonitorSUTInfo", method = RequestMethod.GET) + @ResponseBody + public MonitorResponseModel logicDiskMonitorSUTInfo(@RequestParam String url) { + try { + HttpResponse httpResponse = this.getHttpRequester().sendGet(url, + null, null); + if (httpResponse == null) { + return null; + } + LogicalDiskModel logicalModel = extractModel(httpResponse); + if (logicalModel == null) { + return null; + } + return setResponseModel(true, "", logicalModel); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + private MonitorResponseModel setResponseModel(boolean success, + String failCause, LogicalDiskModel logicalDiskModel) { + MonitorResponseModel result = new MonitorResponseModel(); + result.setSuccess(success); + result.setFailCause(failCause); + result.setLogicalDiskModel(logicalDiskModel); + return result; + } + + private LogicalDiskModel extractModel(HttpResponse httpResponse) { + LogicalDiskModel result = new LogicalDiskModel(); + Unmarshaller unmarshaller; + try { + unmarshaller = JAXBContext.newInstance(result.getClass()) + .createUnmarshaller(); + result = (LogicalDiskModel) unmarshaller + .unmarshal(new ByteArrayInputStream(httpResponse + .getContent().getBytes())); + return result; + } catch (JAXBException e) { + e.printStackTrace(); + return null; + } + + } +} diff --git a/src/main/java/org/bench4q/master/api/RecordScriptController.java b/src/main/java/org/bench4q/master/api/RecordScriptController.java index e491c883..180b99be 100644 --- a/src/main/java/org/bench4q/master/api/RecordScriptController.java +++ b/src/main/java/org/bench4q/master/api/RecordScriptController.java @@ -118,7 +118,6 @@ public class RecordScriptController extends BaseController { * returnResponseModel(false, "saveScriptToDB check your scope fail!"); * } */ - // TODO:save the content to DB this.getScriptService().saveScriptToDB(scriptName, 1, this.scriptCapturer.getScriptContent()); return returnResponseModel(true, "Save to DataBase!!"); diff --git a/src/main/java/org/bench4q/master/api/TestPlanController.java b/src/main/java/org/bench4q/master/api/TestPlanController.java index db2ed22e..23b38db0 100644 --- a/src/main/java/org/bench4q/master/api/TestPlanController.java +++ b/src/main/java/org/bench4q/master/api/TestPlanController.java @@ -6,6 +6,8 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.UUID; + import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -17,6 +19,7 @@ import org.bench4q.master.communication.HttpRequester; import org.bench4q.master.communication.HttpRequester.HttpResponse; import org.bench4q.master.communication.agent.RunScenarioModel; import org.bench4q.master.communication.agent.RunScenarioResultModel; +import org.bench4q.master.communication.agent.TestBriefStatusModel; import org.bench4q.master.entity.db.Agent; import org.bench4q.master.service.AgentService; import org.bench4q.master.service.ScriptService; @@ -71,7 +74,7 @@ public class TestPlanController extends BaseController { this.httpRequester = httpRequester; } - @RequestMapping(value = "/runTestPlanWithScriptId", method = RequestMethod.GET) + @RequestMapping(value = "/runTestPlanWithScriptId", method = RequestMethod.POST) @ResponseBody public TestPlanResponseModel runTestPlanWithScriptId( @RequestParam int scriptId, @RequestParam int requireLoad) { @@ -106,10 +109,13 @@ public class TestPlanController extends BaseController { Iterator iterator; Agent agent; List resulList = new ArrayList(); + RunScenarioResultModel runScenarioResultModel = new RunScenarioResultModel(); - // TODO:i think this should be done by HA and Ballancer + // TODO:i think this should be done by HA and Ballancer, now i just do + // the ballance + // by solo for (iterator = this.getAgentPoolService().loadAgentPoolFromDB() - .iterator(); iterator.hasNext();) { + .iterator(); iterator.hasNext() && requireLoad > 0;) { if (requireLoad <= 0) { break; } @@ -120,21 +126,37 @@ public class TestPlanController extends BaseController { continue; } - if (agent.getRemainLoad() > requireLoad) { + if (agent.getRemainLoad() < agent.getMaxLoad()) { + continue; + } - runScenarioModel.setPoolSize(agent.getMaxLoad()); + int remainLoadByStart = agent.getRemainLoad(); + + if (remainLoadByStart >= requireLoad) { + + runScenarioModel.setPoolSize(requireLoad); runScenarioModel.setTotalCount(requireLoad); this.getAgentPoolService().getLoadFromAgent( agent.getHostName(), requireLoad); - RunScenarioResultModel runScenarioResultModel = this - .sendScriptContentToAgent(agent.getHostName(), - agent.getPort(), - this.marShallRunScenarioModel(runScenarioModel)); + runScenarioResultModel = this.sendScriptContentToAgent( + agent.getHostName(), agent.getPort(), + this.marShallRunScenarioModel(runScenarioModel)); // TODO:for now, i just think it's stable resulList.add(runScenarioResultModel); requireLoad = 0; + } else { + runScenarioModel.setPoolSize(agent.getRemainLoad()); + runScenarioModel.setPoolSize(agent.getRemainLoad()); + this.getAgentPoolService().getLoadFromAgent( + agent.getHostName(), agent.getRemainLoad()); + runScenarioResultModel = this.sendScriptContentToAgent( + agent.getHostName(), agent.getPort(), + this.marShallRunScenarioModel(runScenarioModel)); + + resulList.add(runScenarioResultModel); + requireLoad -= remainLoadByStart; } } return resulList; @@ -189,4 +211,32 @@ public class TestPlanController extends BaseController { resultModel.setRunScenarioResultModels(list); return resultModel; } + + @RequestMapping(value = "/getBriefStatusModelFormAgent", method = RequestMethod.POST) + public TestBriefStatusModel getBriefStatusModelFromAgent(String hostName, + int port, UUID runId) { + TestBriefStatusModel resultModel = new TestBriefStatusModel(); + try { + HttpResponse httpResponse = httpRequester.sendGet(hostName + ":" + + port + "/test/brief/" + runId, null, null); + resultModel = extractTestBriefStatusModel(httpResponse.getContent()); + return resultModel; + } catch (IOException e) { + e.printStackTrace(); + return resultModel; + } catch (JAXBException e) { + e.printStackTrace(); + return resultModel; + } + } + + private TestBriefStatusModel extractTestBriefStatusModel(String content) + throws JAXBException { + TestBriefStatusModel resultModel = new TestBriefStatusModel(); + Unmarshaller ummarshaller = JAXBContext.newInstance( + resultModel.getClass()).createUnmarshaller(); + resultModel = (TestBriefStatusModel) ummarshaller + .unmarshal(new ByteArrayInputStream(content.getBytes())); + return resultModel; + } } diff --git a/src/main/java/org/bench4q/master/api/model/AgentResponseModel.java b/src/main/java/org/bench4q/master/api/model/AgentResponseModel.java index 5cde0baf..82098cdc 100644 --- a/src/main/java/org/bench4q/master/api/model/AgentResponseModel.java +++ b/src/main/java/org/bench4q/master/api/model/AgentResponseModel.java @@ -1,27 +1,44 @@ package org.bench4q.master.api.model; +import java.util.List; + import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; +import org.bench4q.master.entity.db.Agent; @XmlRootElement(name = "agentResponse") public class AgentResponseModel { private boolean isSuccess; private String failCauseString; - + private List agents; + @XmlElement public boolean isSuccess() { return isSuccess; } + public void setSuccess(boolean isSuccess) { this.isSuccess = isSuccess; } - + @XmlElement public String getFailCauseString() { return failCauseString; } + public void setFailCauseString(String failCauseString) { this.failCauseString = failCauseString; } + + @XmlElementWrapper(name = "AgentList") + @XmlElement(name = "agent") + public List getAgents() { + return agents; + } + + public void setAgents(List agents) { + this.agents = agents; + } } diff --git a/src/main/java/org/bench4q/master/api/model/MonitorResponseModel.java b/src/main/java/org/bench4q/master/api/model/MonitorResponseModel.java new file mode 100644 index 00000000..cbe28a86 --- /dev/null +++ b/src/main/java/org/bench4q/master/api/model/MonitorResponseModel.java @@ -0,0 +1,41 @@ +package org.bench4q.master.api.model; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.bench4q.master.communication.monitor.LogicalDiskModel; + +@XmlRootElement(name = "MonitorResponseModel") +public class MonitorResponseModel { + private boolean success; + private String failCause; + private LogicalDiskModel logicalDiskModel; + + @XmlElement(name = "success") + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + @XmlElement(name = "failCause") + public String getFailCause() { + return failCause; + } + + public void setFailCause(String failCause) { + this.failCause = failCause; + } + + @XmlElement(name = "logicalDisk") + public LogicalDiskModel getLogicalDiskModel() { + return logicalDiskModel; + } + + public void setLogicalDiskModel(LogicalDiskModel logicalDiskModel) { + this.logicalDiskModel = logicalDiskModel; + } + +} diff --git a/src/main/java/org/bench4q/master/communication/HttpRequester.java b/src/main/java/org/bench4q/master/communication/HttpRequester.java index 7932b139..3e18950d 100644 --- a/src/main/java/org/bench4q/master/communication/HttpRequester.java +++ b/src/main/java/org/bench4q/master/communication/HttpRequester.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; @@ -17,11 +18,10 @@ import org.springframework.stereotype.Component; public class HttpRequester { private String defaultContentEncoding; - public HttpRequester() - { + public HttpRequester() { this.setDefaultContentEncoding(Charset.defaultCharset().name()); } - + public String getDefaultContentEncoding() { return defaultContentEncoding; } @@ -29,27 +29,27 @@ public class HttpRequester { public void setDefaultContentEncoding(String defaultContentEncoding) { this.defaultContentEncoding = defaultContentEncoding; } - + public HttpResponse sendPost(String urlString, Map params) throws IOException { return this.send(urlString, "POST", params, "", null); } - - public HttpResponse sendPostXml(String urlString, String contentString) throws IOException - { + + public HttpResponse sendPostXml(String urlString, String contentString) + throws IOException { HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "application/xml"); return this.send(urlString, "POST", null, contentString, hashMap); } - + public HttpResponse sendGet(String urlString, Map params, Map properties) throws IOException { return this.send(urlString, "GET", params, "", properties); } private HttpResponse send(String urlString, String method, - Map parameters, String Content, Map propertys) - throws IOException { + Map parameters, String Content, + Map propertys) throws IOException { HttpURLConnection urlConnection = null; if (method.equalsIgnoreCase("GET") && parameters != null) { @@ -60,7 +60,9 @@ public class HttpRequester { param.append("?"); else param.append("&"); - param.append(key).append("=").append(parameters.get(key)); + String encodedValue = URLEncoder.encode(parameters.get(key), + "UTF-8"); + param.append(key).append("=").append(encodedValue); i++; } urlString += param; @@ -69,7 +71,6 @@ public class HttpRequester { if (!urlString.startsWith("http://")) { urlString = "http://" + urlString; } - //urlString = URLEncoder.encode(urlString, "UTF-8"); URL url = new URL(urlString); urlConnection = (HttpURLConnection) url.openConnection(); @@ -87,13 +88,14 @@ public class HttpRequester { StringBuffer param = new StringBuffer(); for (String key : parameters.keySet()) { param.append("&"); - param.append(key).append("=").append(parameters.get(key)); + String encodedValueString = URLEncoder.encode( + parameters.get(key), "UTF-8"); + param.append(key).append("=").append(encodedValueString); } urlConnection.getOutputStream().write(param.toString().getBytes()); urlConnection.getOutputStream().flush(); urlConnection.getOutputStream().close(); - } - else if (method.equalsIgnoreCase("POST") && !Content.isEmpty()) { + } else if (method.equalsIgnoreCase("POST") && !Content.isEmpty()) { urlConnection.getOutputStream().write(Content.getBytes()); urlConnection.getOutputStream().flush(); urlConnection.getOutputStream().close(); diff --git a/src/main/java/org/bench4q/master/communication/monitor/LogicalDiskModel.java b/src/main/java/org/bench4q/master/communication/monitor/LogicalDiskModel.java new file mode 100644 index 00000000..d7c806e0 --- /dev/null +++ b/src/main/java/org/bench4q/master/communication/monitor/LogicalDiskModel.java @@ -0,0 +1,170 @@ +package org.bench4q.master.communication.monitor; + +import java.util.Map; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author wxr + * + */ +@XmlRootElement(name = "LogicalDisk") +public class LogicalDiskModel { + + private String[] instances; + private Map freeSpacePercent; + private Map freeMegabytes; + + // 磁盘活动百分比 + private Map diskTimePercent; + private Map diskReadTimePercent; + private Map diskWriteTimePercent; + + // 磁盘平均活动时间 + private Map averageDiskTransferTimeInSecond; + private Map averageDiskReadTimeInSecond; + private Map averageDiskWriteTimeInSecond; + // 磁盘平均处理的字节 + private Map averageDiskBytesPerTransfer;// 可计算吞吐率 + private Map averageDiskBytesPerRead; + private Map averageDiskBytesPerWrite; + + // 空闲百分比 + private Map idleTimePercent; + // 平均队列长度 + private Map averageDiskQueueLength; + // 当前队列长度 + private Map currentDiskQueueLength; + + @XmlElement(name = "Instance") + public String[] getInstances() { + return instances; + } + + public void setInstances(String[] instances) { + this.instances = instances; + } + + @XmlElement(name = "FreeSpacePercent") + public Map getFreeSpacePercent() { + return freeSpacePercent; + } + + public void setFreeSpacePercent(Map freeSpacePercent) { + this.freeSpacePercent = freeSpacePercent; + } + + public Map getFreeMegabytes() { + return freeMegabytes; + } + + public void setFreeMegabytes(Map freeMegabytes) { + this.freeMegabytes = freeMegabytes; + } + + public Map getDiskTimePercent() { + return diskTimePercent; + } + + public void setDiskTimePercent(Map diskTimePercent) { + this.diskTimePercent = diskTimePercent; + } + + public Map getDiskReadTimePercent() { + return diskReadTimePercent; + } + + public void setDiskReadTimePercent(Map diskReadTimePercent) { + this.diskReadTimePercent = diskReadTimePercent; + } + + public Map getDiskWriteTimePercent() { + return diskWriteTimePercent; + } + + public void setDiskWriteTimePercent(Map diskWriteTimePercent) { + this.diskWriteTimePercent = diskWriteTimePercent; + } + + public Map getAverageDiskTransferTimeInSecond() { + return averageDiskTransferTimeInSecond; + } + + public void setAverageDiskTransferTimeInSecond( + Map averageDiskTransferTimeInSecond) { + this.averageDiskTransferTimeInSecond = averageDiskTransferTimeInSecond; + } + + public Map getAverageDiskReadTimeInSecond() { + return averageDiskReadTimeInSecond; + } + + public void setAverageDiskReadTimeInSecond( + Map averageDiskReadTimeInSecond) { + this.averageDiskReadTimeInSecond = averageDiskReadTimeInSecond; + } + + public Map getAverageDiskWriteTimeInSecond() { + return averageDiskWriteTimeInSecond; + } + + public void setAverageDiskWriteTimeInSecond( + Map averageDiskWriteTimeInSecond) { + this.averageDiskWriteTimeInSecond = averageDiskWriteTimeInSecond; + } + + public Map getAverageDiskBytesPerTransfer() { + return averageDiskBytesPerTransfer; + } + + public void setAverageDiskBytesPerTransfer( + Map averageDiskBytesPerTransfer) { + this.averageDiskBytesPerTransfer = averageDiskBytesPerTransfer; + } + + public Map getAverageDiskBytesPerRead() { + return averageDiskBytesPerRead; + } + + public void setAverageDiskBytesPerRead( + Map averageDiskBytesPerRead) { + this.averageDiskBytesPerRead = averageDiskBytesPerRead; + } + + public Map getAverageDiskBytesPerWrite() { + return averageDiskBytesPerWrite; + } + + public void setAverageDiskBytesPerWrite( + Map averageDiskBytesPerWrite) { + this.averageDiskBytesPerWrite = averageDiskBytesPerWrite; + } + + public Map getIdleTimePercent() { + return idleTimePercent; + } + + public void setIdleTimePercent(Map idleTimePercent) { + this.idleTimePercent = idleTimePercent; + } + + public Map getAverageDiskQueueLength() { + return averageDiskQueueLength; + } + + public void setAverageDiskQueueLength( + Map averageDiskQueueLength) { + this.averageDiskQueueLength = averageDiskQueueLength; + } + + public Map getCurrentDiskQueueLength() { + return currentDiskQueueLength; + } + + public void setCurrentDiskQueueLength( + Map currentDiskQueueLength) { + this.currentDiskQueueLength = currentDiskQueueLength; + } + +} diff --git a/src/test/java/org/bench4q/master/test/MonitorControllerTest.java b/src/test/java/org/bench4q/master/test/MonitorControllerTest.java new file mode 100644 index 00000000..30bf1d8f --- /dev/null +++ b/src/test/java/org/bench4q/master/test/MonitorControllerTest.java @@ -0,0 +1,125 @@ +package org.bench4q.master.test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + +import org.bench4q.master.api.model.MonitorResponseModel; +import org.bench4q.master.communication.HttpRequester; +import org.bench4q.master.communication.HttpRequester.HttpResponse; +import org.bench4q.master.communication.monitor.LogicalDiskModel; +import org.springframework.stereotype.Component; + +@Component(value = "monitorCotrollerTest") +public class MonitorControllerTest { + private HttpRequester httpRequester; + + public MonitorControllerTest() { + this.setHttpRequester(new HttpRequester()); + } + + public HttpRequester getHttpRequester() { + return httpRequester; + } + + public void setHttpRequester(HttpRequester httpRequester) { + this.httpRequester = httpRequester; + } + + public MonitorResponseModel testLogicalDiskInfo(String hostName, + String port, String request) throws IOException { + Map map = new HashMap(); + String url = hostName + ":" + port + request; + map.put("url", url); + HttpResponse httpResponse = this + .getHttpRequester() + .sendGet( + "http://localhost:8080/monitorController/logicDiskMonitorSUTInfo", + map, null); + if (httpResponse == null) { + System.out.println("HttpResponse is null!"); + } + MonitorResponseModel resultModel = extractModel(httpResponse); + return resultModel; + } + + private MonitorResponseModel extractModel(HttpResponse httpResponse) { + MonitorResponseModel result = new MonitorResponseModel(); + Unmarshaller unmarshaller; + try { + unmarshaller = JAXBContext.newInstance(result.getClass()) + .createUnmarshaller(); + if (httpResponse == null) { + return null; + } + result = (MonitorResponseModel) unmarshaller + .unmarshal(new ByteArrayInputStream(httpResponse + .getContent().getBytes())); + return result; + } catch (JAXBException e) { + e.printStackTrace(); + return null; + } + + } + + public void result(LogicalDiskModel logicalDiskModel) { + + for (String elem : logicalDiskModel.getInstances()) { + System.out.println(elem); + System.out.println("freeSpacePercent" + ": " + + logicalDiskModel.getFreeSpacePercent().get(elem)); + System.out.println("FreeMegabytes" + ": " + + logicalDiskModel.getFreeMegabytes().get(elem)); + System.out.println("diskTimePercent" + ": " + + logicalDiskModel.getDiskTimePercent().get(elem)); + System.out.println("diskReadTimePercent" + ": " + + logicalDiskModel.getDiskReadTimePercent().get(elem)); + System.out.println("diskWriteTimePercent" + ": " + + logicalDiskModel.getDiskWriteTimePercent().get(elem)); + System.out.println("averageDiskTransferTimeInSecond" + + ": " + + logicalDiskModel.getAverageDiskTransferTimeInSecond() + .get(elem)); + System.out.println("averageDiskReadTimeInSecond" + + ": " + + logicalDiskModel.getAverageDiskReadTimeInSecond().get( + elem)); + System.out.println("averageDiskWriteTimeInSecond" + + ": " + + logicalDiskModel.getAverageDiskWriteTimeInSecond().get( + elem)); + System.out.println("averageDiskBytesPerTransfer" + + ": " + + logicalDiskModel.getAverageDiskBytesPerTransfer().get( + elem)); + System.out.println("averageDiskBytesPerRead" + ": " + + logicalDiskModel.getAverageDiskBytesPerRead().get(elem)); + System.out.println("averageDiskBytesPerWrite" + ": " + + logicalDiskModel.getAverageDiskBytesPerWrite().get(elem)); + System.out.println("idelTimePercent" + ":" + + logicalDiskModel.getIdleTimePercent().get(elem)); + System.out.println("averageDiskQueueLength" + ":" + + logicalDiskModel.getAverageDiskQueueLength().get(elem)); + System.out.println("currentDiskQueueLength" + ":" + + logicalDiskModel.getCurrentDiskQueueLength().get(elem)); + + } + + } + + public static void main(String[] args) throws IOException { + MonitorControllerTest monirotControllerTest = new MonitorControllerTest(); + + MonitorResponseModel responseModel = monirotControllerTest + .testLogicalDiskInfo("localhost", "5555", + "/Monitor/LogicalDisk"); + monirotControllerTest.result(responseModel.getLogicalDiskModel()); + + } +} diff --git a/src/test/java/org/bench4q/master/test/TestPlanTester.java b/src/test/java/org/bench4q/master/test/TestPlanTester.java index f754263e..124c3d3e 100644 --- a/src/test/java/org/bench4q/master/test/TestPlanTester.java +++ b/src/test/java/org/bench4q/master/test/TestPlanTester.java @@ -8,7 +8,6 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; -import org.bench4q.master.api.AgentController; import org.bench4q.master.api.TestPlanController; import org.bench4q.master.communication.agent.ParameterModel; import org.bench4q.master.communication.agent.RunScenarioModel; @@ -22,7 +21,7 @@ public class TestPlanTester { public static void main(String[] args) throws JAXBException { // TODO: the load to be organized - System.out.println((new AgentService()).backLoadToAgent("133.133.12.6", + System.out.println((new AgentService()).backLoadToAgent("127.0.0.1", 100)); TestPlanController testPlanController = new TestPlanController(); @@ -87,7 +86,7 @@ public class TestPlanTester { RunScenarioResultModel runResultModel; while (iterator.hasNext()) { runResultModel = iterator.next(); - TestBriefStatusModel testBriefStatusModel = (new AgentController()) + TestBriefStatusModel testBriefStatusModel = testPlanController .getBriefStatusModelFromAgent(runResultModel.getHostName(), 6565, runResultModel.getRunId()); System.out.println(testBriefStatusModel.getAverageResponseTime());