add portManage
This commit is contained in:
parent
a19f048427
commit
19c719e0fb
|
@ -84,7 +84,7 @@ public class AuthorizeActionController extends BaseActionController {
|
|||
model.addAttribute("accessToken",
|
||||
authorizeResponseModel.getAccessToken());
|
||||
model.addAttribute("username", user.getUsername());
|
||||
return new ModelAndView("admin", attrMap);
|
||||
return new ModelAndView("agentManage", attrMap);
|
||||
} else {
|
||||
model.addAttribute("rtmsg",
|
||||
"somthing is wrong with the password, please try again.");
|
||||
|
|
|
@ -7,12 +7,13 @@ import org.bench4q.web.communication.HttpRequester;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public abstract class BaseActionController {
|
||||
public static String SUCCESS = "success";
|
||||
public static String FAIL = "fail";
|
||||
public static String FAIL_WITH_EXCEPTION = "fail with exception";
|
||||
private HttpRequester httpRequester;
|
||||
protected final String masterIP = "133.133.12.1:8080/";
|
||||
protected final String AUTH_HEADER_PROPERTY = "Authorization";
|
||||
protected final String ACCES_TOCKEN_STARTER = "Bearer ";
|
||||
public static String SUCCESS = "success";
|
||||
public static String FAIL = "fail";
|
||||
|
||||
public HttpRequester getHttpRequester() {
|
||||
return httpRequester;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.bench4q.web.controller;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -11,6 +12,7 @@ import javax.xml.bind.JAXBException;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.bench4q.web.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.web.entity.fromMaster.Port;
|
||||
import org.bench4q.web.model.master.OrganizeRecordPortResponseModel;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
@ -31,7 +33,7 @@ public class RecordPortActionController extends BaseActionController {
|
|||
this.baseUrlString = baseUrlString;
|
||||
}
|
||||
|
||||
@RequestMapping("addPorttoPortPool")
|
||||
@RequestMapping("addPortToPortPool")
|
||||
public @ResponseBody
|
||||
String addPorttoPortPool(HttpServletRequest request,
|
||||
@ModelAttribute("accessToken") String accessToken) {
|
||||
|
@ -58,14 +60,14 @@ public class RecordPortActionController extends BaseActionController {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return FAIL;
|
||||
return FAIL_WITH_EXCEPTION;
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
return FAIL;
|
||||
return FAIL_WITH_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("removePortfromPortPool")
|
||||
@RequestMapping("removePortFromPortPool")
|
||||
public @ResponseBody
|
||||
String removePortfromPortPool(HttpServletRequest request,
|
||||
@ModelAttribute("accessToken") String accessToken) {
|
||||
|
@ -92,10 +94,10 @@ public class RecordPortActionController extends BaseActionController {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return FAIL;
|
||||
return FAIL_WITH_EXCEPTION;
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
return FAIL;
|
||||
return FAIL_WITH_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,4 +112,47 @@ public class RecordPortActionController extends BaseActionController {
|
|||
|
||||
}
|
||||
|
||||
@RequestMapping("loadPorts")
|
||||
@ResponseBody
|
||||
public String loadPorts(HttpServletRequest request,
|
||||
@ModelAttribute("accessToken") String accessToken) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendPost(
|
||||
this.getBaseUrlString() + "/loadPortList", null,
|
||||
this.makeAccessTockenMap(accessToken));
|
||||
OrganizeRecordPortResponseModel responseModel = extractOrganizeRecordPortResponseModel(httpResponse
|
||||
.getContent());
|
||||
if (responseModel.isSuccess()) {
|
||||
return listToJsonString(responseModel.getPorts());
|
||||
}
|
||||
return FAIL;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return FAIL_WITH_EXCEPTION;
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
return FAIL_WITH_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
private String listToJsonString(List<Port> portList) {
|
||||
String result = "";
|
||||
if (portList == null) {
|
||||
return result;
|
||||
}
|
||||
for (Port port : portList) {
|
||||
if (result.isEmpty()) {
|
||||
result = result + "[" + objectToJsonString(port);
|
||||
} else {
|
||||
result = result + "," + objectToJsonString(port);
|
||||
}
|
||||
}
|
||||
|
||||
return result + "]";
|
||||
}
|
||||
|
||||
private String objectToJsonString(Port port) {
|
||||
return "{" + "port:\"" + port.getPort() + "\",ID:\"" + port.getId()
|
||||
+ "\"}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Admin Page</title>
|
||||
<title>AgentManage Page</title>
|
||||
<link id="bs-css" href="style/bootstrap-cerulean.css" rel="stylesheet">
|
||||
<link href="css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="style/charisma-app.css" rel="stylesheet">
|
||||
|
@ -80,7 +80,7 @@
|
|||
<li><a class="ajax-link" href="admin.jsp"><i
|
||||
class="icon-home"></i><span class="hidden-tablet">Agent
|
||||
Manage</span></a></li>
|
||||
<li><a class="ajax-link" href="admin/portManage.jsp"><i
|
||||
<li><a class="ajax-link" href="portManage.jsp"><i
|
||||
class="icon-eye-open"></i><span class="hidden-tablet">Port
|
||||
Manage</span></a></li>
|
||||
</ul>
|
|
@ -0,0 +1,170 @@
|
|||
<%@page contentType="text/html"%>
|
||||
<%@ page isELIgnored="false"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>PortManage Page</title>
|
||||
<link id="bs-css" href="style/bootstrap-cerulean.css" rel="stylesheet">
|
||||
<link href="css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="style/charisma-app.css" rel="stylesheet">
|
||||
<link href="css/bootstrap-classic.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="logged_out wider windows env-production">
|
||||
<div class="navbar">
|
||||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="btn btn-navbar" data-toggle="collapse"
|
||||
data-target=".top-nav.nav-collapse,.sidebar-nav.nav-collapse">
|
||||
<span class="icon-bar"></span><span class="icon-bar"></span><span
|
||||
class="icon-bar"></span>
|
||||
</a><a class="brand" href="index.html"> <img alt="Charisma Logo"
|
||||
src="img/bench4q-1.png" /> <span>Bench4Q</span></a>
|
||||
<div class="btn-group pull-right theme-container">
|
||||
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="icon-tint"></i><span class="hidden-phone">Change
|
||||
Theme / Skin</span> <span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" id="themes">
|
||||
<li><a data-value="classic" href="#"><i
|
||||
class="icon-blank"></i>Classic</a></li>
|
||||
<li><a data-value="cerulean" href="#"><i
|
||||
class="icon-blank"></i>Cerulean</a></li>
|
||||
<li><a data-value="cyborg" href="#"><i class="icon-blank"></i>
|
||||
Cyborg</a></li>
|
||||
<li><a data-value="redy" href="#"><i class="icon-blank"></i>
|
||||
Redy</a></li>
|
||||
<li><a data-value="journal" href="#"><i
|
||||
class="icon-blank"></i>Journal</a></li>
|
||||
<li><a data-value="simplex" href="#"><i
|
||||
class="icon-blank"></i>Simplex</a></li>
|
||||
<li><a data-value="slate" href="#"><i class="icon-blank"></i>
|
||||
Slate</a></li>
|
||||
<li><a data-value="spacelab" href="#"><i
|
||||
class="icon-blank"></i>Spacelab</a></li>
|
||||
<li><a data-value="united" href="#"><i class="icon-blank"></i>
|
||||
United</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group pull-right">
|
||||
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="icon-user"></i><span class="hidden-phone">${userName}</span>
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#">Profile</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="login.html">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="top-nav nav-collapse">
|
||||
<ul class="nav">
|
||||
<li><a href="#">Visit Site</a></li>
|
||||
<li>
|
||||
<form class="navbar-search pull-left">
|
||||
<input placeholder="Search" class="search-query span2"
|
||||
name="query" type="text">
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<div class="row-fluid">
|
||||
<div class="span2 main-menu-span">
|
||||
<div class="well nav-collapse sidebar-nav">
|
||||
<ul class="nav nav-tabs nav-stacked main-menu">
|
||||
<li class="nav-header hidden-tablet">Main</li>
|
||||
<li><a class="ajax-link" href="admin.jsp"><i
|
||||
class="icon-home"></i><span class="hidden-tablet">Agent
|
||||
Manage</span></a></li>
|
||||
<li><a class="ajax-link" href="portManage.jsp"><i
|
||||
class="icon-eye-open"></i><span class="hidden-tablet">Port
|
||||
Manage</span></a></li>
|
||||
</ul>
|
||||
<label id="for-is-ajax" class="hidden-tablet" for="is-ajax">
|
||||
<input id="is-ajax" type="checkbox"> Ajax on menu
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="content" class="span10">
|
||||
<div>
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="#">Home</a> <span class="divider">/</span></li>
|
||||
<li><a href="#">Port Management</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="row-fluid sortable">
|
||||
<div class="box span12 center">
|
||||
<div class="box-header well" data-original-title>
|
||||
<h2>
|
||||
<i></i>Ports
|
||||
</h2>
|
||||
<div class="box-icon">
|
||||
<a href="#" class="btn btn-setting btn-round"><i
|
||||
class="icon-plus" onClick="addPort()"></i></a> <a href="#"
|
||||
class="btn btn-minimize btn-round"><i
|
||||
class="icon-chevron-up"></i></a> <a href="#"
|
||||
class="btn btn-close btn-round"><i class="icon-remove"></i></a>
|
||||
<a href="#" class="btn btn-round" onClick="loadPorts()"><i
|
||||
class="icon-list"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-content">
|
||||
<table id="portsTab"
|
||||
class="table table-striped table-bordered bootstrap-datatable datatable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>port</th>
|
||||
<th>isInUse</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<div class="modal hide fade" id="portParam">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><3E></button>
|
||||
<h3>Settings</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<tr>
|
||||
<td><label class="control-label" for="focusedInput">port</label>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<input class="input-xlarge focused" id="port" type="text"
|
||||
value="0">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</div>
|
||||
<div class="model-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal"
|
||||
onClick="addPortToDB()">Submit</button>
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<p class="pull-left">© Bench4Q 2013</p>
|
||||
<p class="pull-right">Powered by: Bench4Q</p>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
|
||||
<script
|
||||
src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
|
||||
<script
|
||||
src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/jquery-ui.min.js"></script>
|
||||
<script src="script/portManage.js"></script>
|
||||
<script src="js/bootstrap-modal.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,66 @@
|
|||
$(document).ready(function() {
|
||||
loadPorts();
|
||||
});
|
||||
|
||||
function loadPorts() {
|
||||
$('#portsTab').dataTable().fnClearTable();
|
||||
$.post("loadPorts", {}, function(data) {
|
||||
showPorts(data);
|
||||
});
|
||||
}
|
||||
|
||||
function showPorts(data) {
|
||||
var jsonObject = eval(data);
|
||||
var status = "NA";
|
||||
for ( var i = 0; i < jsonObject.length; i++) {
|
||||
if (json[i].isInUse) {
|
||||
status = "InUse";
|
||||
} else
|
||||
status = "InIdle";
|
||||
addtablerow(jsonObject[i].port, jsonObject[i].ID, status);
|
||||
$('#portsTab >tbody').children("tr").eq(i).attr("id", jsonObject[i].ID);
|
||||
$('#portsTab >tbody').children("tr").eq(i).attr("name",
|
||||
jsonObject[i].port);
|
||||
}
|
||||
}
|
||||
|
||||
function addtablerow(hostName, ID, port, status, maxLoad, remainLoad) {
|
||||
var html = "<a class='btn btn-info' onClick='editPort(this)'><i class='icon-edit icon-white'></i>Edit</a>"
|
||||
+ " "
|
||||
+ "<a class='btn btn-danger' href='#' onClick='deletetablerow(this)'><i class='icon-trash icon-white'></i>Delete</a>";
|
||||
$('#portsTab').dataTable().fnAddData(
|
||||
[ hostName, ID, port, status, maxLoad, remainLoad, html ]);
|
||||
}
|
||||
|
||||
function edittablerow(obj) {
|
||||
var row = obj.parentNode.parentNode;
|
||||
alert(row.rowIndex);
|
||||
}
|
||||
|
||||
function deletetablerow(obj) {
|
||||
var row = obj.parentNode.parentNode;
|
||||
var portId = $('#portsTab>tbody').children("tr").eq(row.rowIndex - 1).attr(
|
||||
"id");
|
||||
var port = $('#portsTab>tbody').children("tr").eq(row.rowIndex - 1).attr(
|
||||
"name");
|
||||
$.post("removePortFromPortPool", {
|
||||
portId : portId,
|
||||
port : port
|
||||
});
|
||||
$('#portsTab').dataTable().fnDeleteRow(row.rowIndex - 1);
|
||||
}
|
||||
|
||||
function addPort() {
|
||||
$("#port").val(0);
|
||||
$("#portParam").modal('show');
|
||||
}
|
||||
|
||||
function addPortToDB() {
|
||||
$.post("addPortToPool", {
|
||||
port : $("#port").val()
|
||||
}, function(data) {
|
||||
if (data == "success") {
|
||||
loadPorts();
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue