add contact with monitor
This commit is contained in:
parent
57dfb3daa9
commit
451daaacf7
|
@ -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<Agent> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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!!");
|
||||
|
|
|
@ -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<Agent> iterator;
|
||||
Agent agent;
|
||||
List<RunScenarioResultModel> resulList = new ArrayList<RunScenarioResultModel>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Agent> 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<Agent> getAgents() {
|
||||
return agents;
|
||||
}
|
||||
|
||||
public void setAgents(List<Agent> agents) {
|
||||
this.agents = agents;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String, String> 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<String, String> hashMap = new HashMap<String, String>();
|
||||
hashMap.put("Content-Type", "application/xml");
|
||||
return this.send(urlString, "POST", null, contentString, hashMap);
|
||||
}
|
||||
|
||||
|
||||
public HttpResponse sendGet(String urlString, Map<String, String> params,
|
||||
Map<String, String> properties) throws IOException {
|
||||
return this.send(urlString, "GET", params, "", properties);
|
||||
}
|
||||
|
||||
private HttpResponse send(String urlString, String method,
|
||||
Map<String, String> parameters, String Content, Map<String, String> propertys)
|
||||
throws IOException {
|
||||
Map<String, String> parameters, String Content,
|
||||
Map<String, String> 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();
|
||||
|
|
|
@ -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<String, Double> freeSpacePercent;
|
||||
private Map<String, Double> freeMegabytes;
|
||||
|
||||
// 磁盘活动百分比
|
||||
private Map<String, Double> diskTimePercent;
|
||||
private Map<String, Double> diskReadTimePercent;
|
||||
private Map<String, Double> diskWriteTimePercent;
|
||||
|
||||
// 磁盘平均活动时间
|
||||
private Map<String, Double> averageDiskTransferTimeInSecond;
|
||||
private Map<String, Double> averageDiskReadTimeInSecond;
|
||||
private Map<String, Double> averageDiskWriteTimeInSecond;
|
||||
// 磁盘平均处理的字节
|
||||
private Map<String, Double> averageDiskBytesPerTransfer;// 可计算吞吐率
|
||||
private Map<String, Double> averageDiskBytesPerRead;
|
||||
private Map<String, Double> averageDiskBytesPerWrite;
|
||||
|
||||
// 空闲百分比
|
||||
private Map<String, Double> idleTimePercent;
|
||||
// 平均队列长度
|
||||
private Map<String, Double> averageDiskQueueLength;
|
||||
// 当前队列长度
|
||||
private Map<String, Double> currentDiskQueueLength;
|
||||
|
||||
@XmlElement(name = "Instance")
|
||||
public String[] getInstances() {
|
||||
return instances;
|
||||
}
|
||||
|
||||
public void setInstances(String[] instances) {
|
||||
this.instances = instances;
|
||||
}
|
||||
|
||||
@XmlElement(name = "FreeSpacePercent")
|
||||
public Map<String, Double> getFreeSpacePercent() {
|
||||
return freeSpacePercent;
|
||||
}
|
||||
|
||||
public void setFreeSpacePercent(Map<String, Double> freeSpacePercent) {
|
||||
this.freeSpacePercent = freeSpacePercent;
|
||||
}
|
||||
|
||||
public Map<String, Double> getFreeMegabytes() {
|
||||
return freeMegabytes;
|
||||
}
|
||||
|
||||
public void setFreeMegabytes(Map<String, Double> freeMegabytes) {
|
||||
this.freeMegabytes = freeMegabytes;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskTimePercent() {
|
||||
return diskTimePercent;
|
||||
}
|
||||
|
||||
public void setDiskTimePercent(Map<String, Double> diskTimePercent) {
|
||||
this.diskTimePercent = diskTimePercent;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskReadTimePercent() {
|
||||
return diskReadTimePercent;
|
||||
}
|
||||
|
||||
public void setDiskReadTimePercent(Map<String, Double> diskReadTimePercent) {
|
||||
this.diskReadTimePercent = diskReadTimePercent;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskWriteTimePercent() {
|
||||
return diskWriteTimePercent;
|
||||
}
|
||||
|
||||
public void setDiskWriteTimePercent(Map<String, Double> diskWriteTimePercent) {
|
||||
this.diskWriteTimePercent = diskWriteTimePercent;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskTransferTimeInSecond() {
|
||||
return averageDiskTransferTimeInSecond;
|
||||
}
|
||||
|
||||
public void setAverageDiskTransferTimeInSecond(
|
||||
Map<String, Double> averageDiskTransferTimeInSecond) {
|
||||
this.averageDiskTransferTimeInSecond = averageDiskTransferTimeInSecond;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskReadTimeInSecond() {
|
||||
return averageDiskReadTimeInSecond;
|
||||
}
|
||||
|
||||
public void setAverageDiskReadTimeInSecond(
|
||||
Map<String, Double> averageDiskReadTimeInSecond) {
|
||||
this.averageDiskReadTimeInSecond = averageDiskReadTimeInSecond;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskWriteTimeInSecond() {
|
||||
return averageDiskWriteTimeInSecond;
|
||||
}
|
||||
|
||||
public void setAverageDiskWriteTimeInSecond(
|
||||
Map<String, Double> averageDiskWriteTimeInSecond) {
|
||||
this.averageDiskWriteTimeInSecond = averageDiskWriteTimeInSecond;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskBytesPerTransfer() {
|
||||
return averageDiskBytesPerTransfer;
|
||||
}
|
||||
|
||||
public void setAverageDiskBytesPerTransfer(
|
||||
Map<String, Double> averageDiskBytesPerTransfer) {
|
||||
this.averageDiskBytesPerTransfer = averageDiskBytesPerTransfer;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskBytesPerRead() {
|
||||
return averageDiskBytesPerRead;
|
||||
}
|
||||
|
||||
public void setAverageDiskBytesPerRead(
|
||||
Map<String, Double> averageDiskBytesPerRead) {
|
||||
this.averageDiskBytesPerRead = averageDiskBytesPerRead;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskBytesPerWrite() {
|
||||
return averageDiskBytesPerWrite;
|
||||
}
|
||||
|
||||
public void setAverageDiskBytesPerWrite(
|
||||
Map<String, Double> averageDiskBytesPerWrite) {
|
||||
this.averageDiskBytesPerWrite = averageDiskBytesPerWrite;
|
||||
}
|
||||
|
||||
public Map<String, Double> getIdleTimePercent() {
|
||||
return idleTimePercent;
|
||||
}
|
||||
|
||||
public void setIdleTimePercent(Map<String, Double> idleTimePercent) {
|
||||
this.idleTimePercent = idleTimePercent;
|
||||
}
|
||||
|
||||
public Map<String, Double> getAverageDiskQueueLength() {
|
||||
return averageDiskQueueLength;
|
||||
}
|
||||
|
||||
public void setAverageDiskQueueLength(
|
||||
Map<String, Double> averageDiskQueueLength) {
|
||||
this.averageDiskQueueLength = averageDiskQueueLength;
|
||||
}
|
||||
|
||||
public Map<String, Double> getCurrentDiskQueueLength() {
|
||||
return currentDiskQueueLength;
|
||||
}
|
||||
|
||||
public void setCurrentDiskQueueLength(
|
||||
Map<String, Double> currentDiskQueueLength) {
|
||||
this.currentDiskQueueLength = currentDiskQueueLength;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String, String> map = new HashMap<String, String>();
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue