add the sut info on the result.jsp;

this version encounter a error in result.js: unexpected token <;
This commit is contained in:
fanfuxiaoran 2013-09-17 17:39:47 +08:00
parent 42e1613ee3
commit 403759578f
3 changed files with 223 additions and 96 deletions

View File

@ -62,6 +62,7 @@ public class HttpRequester {
param.append("?");
else
param.append("&");
String encodedValue = URLEncoder.encode(parameters.get(key),
"UTF-8");
param.append(key).append("=").append(encodedValue);

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -16,16 +17,21 @@ import javax.xml.bind.Unmarshaller;
import net.sf.json.JSONObject;
import org.bench4q.web.model.master.OperateScriptServerResponseModel;
import org.bench4q.web.communication.HttpRequester;
import org.bench4q.web.communication.HttpRequester.HttpResponse;
import org.bench4q.web.entity.fromMaster.Port;
import org.bench4q.web.entity.fromMaster.Script;
import org.bench4q.web.model.master.MonitorModel;
import org.bench4q.web.model.master.MonitorProcessorResponseModel;
import org.bench4q.web.model.master.RunningScriptModel;
import org.bench4q.web.model.master.ScriptBriefResultModel;
import org.bench4q.web.model.master.TestPlanModel;
import org.bench4q.web.model.master.TestPlanResultModel;
import org.bench4q.web.model.master.TestScriptConfig;
import org.bench4q.web.model.monitor.ProcessorModel;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
@ -143,23 +149,37 @@ public class TestPlanActionController extends BaseActionController {
properties);
TestPlanResultModel testPlanResultModel = extractRunTestPlanResultModel(httpResponse
.getContent());
List<RunningScriptModel> list = testPlanResultModel
List<RunningScriptModel> scriptList = testPlanResultModel
.getRunningScriptModels();
Iterator<RunningScriptModel> it = list.iterator();
List<MonitorModel> monitorList = testPlanResultModel.getMonitorModels();
Iterator<RunningScriptModel> scriptItr = scriptList.iterator();
Iterator<MonitorModel> monitorItr = monitorList.iterator();
RunningScriptModel script;
String str = "";
while (it.hasNext()) {
while (scriptItr.hasNext()) {
script = it.next();
script = scriptItr.next();
String scriptName = getScriptNameById(script.getScriptId(),
accessToken);
if (str.isEmpty()) {
str = str + script.getScriptId() + ";" + scriptName;
str = str + script.getScriptId() + "," + scriptName;
} else {
str = str + "," + script.getScriptId() + ";" + scriptName;
str = str + ";" + script.getScriptId() + "," + scriptName;
}
}
boolean flag = false;
while (monitorItr.hasNext()) {
MonitorModel monitorModel = monitorItr.next();
if (!flag) {
str = str + "_" + monitorModel.getHostName() + ","
+ monitorModel.getPort();
flag = true;
} else {
str = str + ";" + monitorModel.getHostName() + ","
+ monitorModel.getPort();
}
}
System.out.println(str);
return str;
}
@ -206,6 +226,44 @@ public class TestPlanActionController extends BaseActionController {
}
@RequestMapping("getProcessorStatus")
public @ResponseBody
ProcessorModel getPeocessStatus(HttpServletRequest request,
@ModelAttribute("accessToken") String accessToken,
@ModelAttribute("testplanID") String testplanID) {
System.out.println("enter getProcessorStatus");
Map<String, String> params = new HashMap<String, String>();
String ip = request.getParameter("ip");
String port = request.getParameter("port");
params.put("hostName", ip);
params.put("port", port);
String urlString = masterIP + "monitorController/processorSUTInfo";
HttpResponse httpResponse = null;
MonitorProcessorResponseModel monitorProcessorResponseModel;
try {
httpResponse = this.getHttpRequester().sendGet(urlString, params,
this.makeAccessTockenMap(accessToken));
if (httpResponse == null)
return null;
monitorProcessorResponseModel= extractProcessorModel(httpResponse.getContent());
} catch (Exception e) {
System.out
.println("The response of getting processorStatus is wong: "
+ e.toString());
return null;
}
if(monitorProcessorResponseModel.isSuccess()){
System.out.println(monitorProcessorResponseModel.getProcessorModel().toString());
return monitorProcessorResponseModel.getProcessorModel();
}
else
{
System.out.println(monitorProcessorResponseModel.getFailCause());
return null;
}
}
private OperateScriptServerResponseModel extractoperateScriptServerResponseModel(
String content) throws JAXBException {
OperateScriptServerResponseModel resultModel = new OperateScriptServerResponseModel();
@ -217,6 +275,16 @@ public class TestPlanActionController extends BaseActionController {
}
private MonitorProcessorResponseModel extractProcessorModel(String content)
throws JAXBException {
MonitorProcessorResponseModel resultModel = new MonitorProcessorResponseModel();
Unmarshaller ummarshaller = JAXBContext.newInstance(
resultModel.getClass()).createUnmarshaller();
resultModel = (MonitorProcessorResponseModel) ummarshaller
.unmarshal(new ByteArrayInputStream(content.getBytes()));
return resultModel;
}
private String getScriptNameById(int scriptId, String accessToken) {
Integer script_id = scriptId;
@ -252,4 +320,29 @@ public class TestPlanActionController extends BaseActionController {
return null;
}
public String listToString(List<Script> scripts) {
if (scripts == null) {
return "";
}
Iterator<Script> it = scripts.iterator();
Script script;
String str = "";
while (it.hasNext()) {
script = it.next();
if (str.isEmpty()) {
str = str + "[{" + "name:\"" + script.getName()
+ "\",createDateTime:\""
+ script.getCreateDateTime().getTime() + "\",ID:\""
+ script.getId() + "\"}";
} else {
str = str + ",{" + "name:\"" + script.getName()
+ "\",createDateTime:\""
+ script.getCreateDateTime().getTime() + "\",ID:\""
+ script.getId() + "\"}";
}
}
return str + "]";
}
}

View File

@ -9,38 +9,53 @@ $(document)
.post(
"getRunningInfo",
function(data) {
scripts = data.split(",");
var script_ip = data.split("_");
scripts=script_ip[0].split(";");
monitor=script_ip[1].split(";");
for ( var i = 0; i < scripts.length; i++) {
scriptRecord = scripts[i]
.split(";");
scriptRecord = scripts[i].split(",");
scriptId = scriptRecord[0];
scriptName = scriptRecord[1];
addScriptToContainer(scriptName);
addscript(scriptName, scriptId);
// alert("ready()");
// highchart(scriptId, scriptName);
addContainer(scriptName);
addNodeToTree(scriptName, scriptId,"scripts");
}
for(i=0;i<monitor.length;i++){
monitorRecord=monitor[i].split(",");
ip=monitorRecord[0];
port=monitorRecord[1];
addNodeToTree(ip, ip,"sut");
for(i=0;i<=3;i++)
ip=ip.replace(".","_");
addContainer(ip);
}
for ( var i = 0; i < scripts.length; i++) {
scriptRecord = scripts[i]
.split(";");
scriptRecord = scripts[i].split(",");
scriptId = scriptRecord[0];
scriptName = scriptRecord[1];
highchart(scriptId, scriptName);
highchart(scriptId, scriptName,1);
}
for ( var i = 0; i < monitor.length; i++) {
monitorRecord = monitor[i].split(",");
var ip=monitorRecord[0];
for(var j=0;j<=3;j++)
ip=ip.replace(".","_");
highchart(monitor[i], ip,2);
}
});
});
function addscript(scriptName, scriptId) {
function addNodeToTree(name, id,treeNode) {
var branches;
branches = $(
"<ul><li><span onClick='scriptClick(this)' id=" + scriptId
+ " name=" + scriptName + ">" + scriptName
+ "</span></li></ul>").appendTo("#scripts");
$("#scripts").treeview({
"<ul><li><span onClick='scriptClick(this)' id=" +id
+ " name=" + name + ">" + name
+ "</span></li></ul>").appendTo("#"+treeNode);
$("#"+treeNode).treeview({
add : branches
});
}
function scriptClick(obj) {
var chartName = obj.getAttribute("name");
for ( var i = 0; i < scripts.length; i++) {
@ -53,64 +68,26 @@ function scriptClick(obj) {
$('#text' + chartName).show();
}
var scripts;
function highchart(scriptId, containerName) {
var monitor;
var finish_all=false;
var scriptFinishCount=0;
function highchart(params, containerName, type) {
$('#' + containerName)
.highcharts(
{
chart : {
type : 'spline',
animation : Highcharts.svg, // don't
// animate
// in
// old
// IE
animation : Highcharts.svg, // don't nimate in old IE
marginRight : 10,
events : {
load : function() {
var finish = false;
var series = this.series[0];
var intervalID = setInterval(
function() {
// var
// jsonObject=getJsonObject(scriptId);
// alert('jsonObject:'+jsonObject);
$
.post(
"getScriptBriefStatus",
{
scriptID : scriptId
},
function(data) {
if (data != null) {
var jsonObject = eval("("
+ data
+ ")");
finish = jsonObject.finished;
var x = (new Date())
.getTime(); // current
// time
// var y
// =
// parseFloat(jsonobeject.averageResponseTime);
var y = parseInt(jsonObject.averageElapsedTime);
// alert(jsonObject.totalSuccessCount);
series
.addPoint(
[
x,
y ],
true,
false);
getSciptBrief(containerName,jsonObject);
if (finish == true)
clearInterval(intervalID);
}// if
}); // setInterval
}, 2000);
if(type==1)
scriptLoadFuncion(params,containerName,series);
else
sutLoadFunction(params,containerName,series);
}// load function
}
// event------
@ -164,37 +141,94 @@ function highchart(scriptId, containerName) {
})()
} ]
});// hihtChats----------
});// highChats----------
}
function loadFuncion() {
function scriptLoadFuncion(params,containerName,series) {
var scriptId=params;
var finish = false;
var series = this.series[0];
var intervalID = null;
intervalID = setInterval(function() {
var jsonObject = getJsonObject();
finish = jsonobeject.finished;
var x = (new Date()).getTime(); // current time
// var y = parseFloat(jsonobeject.averageResponseTime);
var y = parseFloat(jsonObject.totalSuccessCount);
series.addPoint([ x, y ], true, false);
if (finish == true)
clearInterval(intervalID);
var intervalId = null;
intervalId = setInterval(function() {
$.post("getScriptBriefStatus", {
scriptID : scriptId
}, function(data) {
if (data != null) {
var jsonObject = eval("(" + data + ")");
finish = jsonObject.finished;
var x = (new Date()).getTime(); // current time
var y = parseFloat(jsonObject.averageResponseTime);
series.addPoint([ x, y ], true, false);
outputSciptBrief(containerName,jsonObject);
if (finish == true){
clearInterval(intervalId);
scriptFinishCount++;
if(scriptFinishCount==scripts.length)
finish_all=true;
}
}// if
}// function
);
}, 2000);
}
function getJsonObject(scriptId) {
$.post("getScriptBriefStatus", {
scriptID : scriptId
}, function(data) {
if (data != null) {
var jsonObject = eval("(" + data + ")");
}// if
}// function
);
function sutLoadFunction(params,containerName,series){
var sutRecord=params.split(",");
var ip=sutRecord[0];
var port=sutRecord[1];
var intervalId = null;
intervalId = setInterval(function() {
$.ajax({
url :"getProcessorStatus",
data:"ip="+ip+"&port="+port,
type : "GET",
cache : false,
dataType : "json",
success : function(data, status) {
alter(data);
var processorList=data.processorModelList;
for(var i=0;i<processorList.length;i++){
var processorModelChild=processorList[i];
var x = (new Date()).getTime(); // current time
var y=0;
if(processorTimePercent!=="NaN")
y = parseFloat(processorModelChild.processorTimePercent);
series.addPoint([ x, y ], true, false);
}
if (finish_all== true)
clearInterval(intervalId);
},
error : function(request, status, error) {
alert("An error occurred while loading the sut data:"+error);
}
});
}
/*$.post("getProcessorStatus", {
ip:ip,
port:port
}, function(data) {
if(data!=null){
$(data).find('processorModelChild').each(function(i){
var instance=$(this).children('instance').text();
var privilegedTimePercent=$(this).children('privilegedTimePercent').text();
var processorTimePercent=$(this).children('processorTimePercent').text();
var userTimePercent=$(this).children('userTimePercent').text();
var x = (new Date()).getTime(); // current time
if(processorTimePercent!=="NaN")
var y = parseFloat(processorTimePercent);
else var y=0;
alert(y);
series.addPoint([ x, y ], true, false);
});
}*/
// outputSciptBrief(containerName,jsonObject);
, 2000);
}
function getSciptBrief(containerName,jsonObject){
function outputSciptBrief(containerName,jsonObject){
var name="sut";
if(containerName!=name)
var scriptBrief = "averageElapsedTime: "
@ -216,11 +250,10 @@ function getSciptBrief(containerName,jsonObject){
$(
'#text'
+ containerName)
.html(
scriptBrief);
.html(scriptBrief);
}
function addScriptToContainer(scriptName){
function addContainer(scriptName){
var html = "<div class='div-left' id="
+ scriptName