<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>Insert title here</title>
+<title>Go DB Hammer</title>
</head>
<body>
+<h2>Go DB Hammer</h2>
+<script type="text/javascript">
+//function doPost {
+$(function() {
+ var frm = $(document.dbsetsform);
+ var dat = JSON.stringify(frm.serializeArray());
+ //alert("I am about to POST this:\n\n" + dat);
+ $.post(
+ frm.attr("action"),
+ dat,
+ function(data) {
+ alert("Response: " + data);
+ }
+ );
+ });
+//}
+
+function bollocks() {
+$.getJSON("http://localhost:22222/json", function(json) {
+ $.each(json, function(i,j){
+ //$("div").html("pissant: " + i + j);
+ if(i=="status") {
+ if(j == 1) {
+ $(".submitbody").toggle(true);
+ $(".setupbody").toggle(false);
+ $(".beginbody").toggle(false);
+ $(".reportbody").toggle(false);
+ $(".loadingbody").toggle(false);
+ }
+ if(j == 2) {
+ $(".submitbody").toggle(false);
+ $(".setupbody").toggle(true);
+ $(".beginbody").toggle(false);
+ $(".reportbody").toggle(false);
+ $(".loadingbody").toggle(false);
+ }
+
+ }
+ });
+ });
+ setTimeout('bollocks()', 5000);
+}
+
+setTimeout('bollocks()', 2000);
+
+
+</script>
+
+<div class="submitbody">
+<form method="post" action="/json" name="dbsetsform">
+<table>
+<tr><td>Database Type</td><td><input type="text" name="dbtype"></td></tr>
+<tr><td>Database Host</td><td><input type="text" name="dbtype"></td></tr>
+<tr><td>Database Username</td><td><input type="text" name="dbtype"></td></tr>
+<tr><td>Database Password</td><td><input type="text" name="dbtype"></td></tr>
+<tr><td>Database</td><td><input type="text" name="dbtype"></td></tr>
+<tr><td>Data Multiplier</td><td><input type="text" name="dbtype"></td></tr>
+<tr><td>Number of Clients</td><td><input type="text" name="dbtype"></td></tr>
+</table>
+<input type="submit" name="Go" value="Go">
+</form>
+</div>
+<div class="setupbody">I am a setup body</div>
+<div class="beginbody">I am a submit body</div>
+<div class="reportbody">I am a report body</div>
+<div class="loadingbody">Status loading....</div>
+
+<script type="text/javascript">
+
+$(".submitbody").toggle(false);
+$(".setupbody").toggle(false);
+$(".beginbody").toggle(false);
+$(".reportbody").toggle(false);
+$(".loadingbody").toggle(true);
+</script>
</body>
</html>
\ No newline at end of file
{
//stat := <- cominstatus;
- j, _, _ := json.StringToJson("{\"somestring\":\"somevalue\"}");
+ if(req.Method == "GET") {
- io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j)));
-
- /*if ret {
- fmt.Printf("err was true\n");
- } else {
- fmt.Printf("err was false\n");
- }*/
-
- //fmt.Printf("errto %s\n", errto);
-
-}
-
-
-// hello world, the web server
-func ServerResponder(c *http.Conn, req *http.Request) {
- //comout <- 2;
- //comout <- 3;
- //comout <- 1;
- fmt.Printf("lk: %s %s %s\n", req.Method, req.RawURL, req.URL);
- if req.RawURL == "/" {
- mainPage(c, req);
- }
-
- if req.RawURL == "/confirm" {
- confirmPage(c, req);
- }
-
- if req.RawURL == "/begin" {
- beginPage(c, req);
- }
-
- //k := <- comin;
- //fmt.Printf("%d\n", k);
-}
-
-func beginPage(c *http.Conn, req *http.Request)
-{
-
- if req.Method != "GET" {
- http.Redirect(c, "/begin", 301);
- } else {
- header(c);
- io.WriteString(c, "<h1>Starting hammer</h1>");
- //dbhost := req.FormValue("dbhost");
- //dbuser := req.FormValue("dbuser");
- //dbpass := req.FormValue("dbpass");
- //dbname := req.FormValue("dbname");
- //nthreads := req.FormValue("nthreads");
- //dbmult := req.FormValue("dbmult");
- comout <- "begin:setup";
+ j, _, _ := json.StringToJson("{\"status\":1, \"complete\":90}");
- footer(c);
+ io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j)));
+ fmt.Printf("i got a get\n");
+ }
+ if(req.Method == "POST") {
+ fmt.Printf("i got a post...\n");
+ http.Redirect(c, "/", 301);
}
}
-func confirmPage(c *http.Conn, req *http.Request)
-{
- header(c);
- io.WriteString(c, "<h1>Confirm</h1>");
- dbhost := req.FormValue("dbhost");
- dbuser := req.FormValue("dbuser");
- dbpass := req.FormValue("dbpass");
- dbname := req.FormValue("dbname");
- nthreads := req.FormValue("nthreads");
- dbmult := req.FormValue("dbmult");
- var dbtype string;
-
- io.WriteString(c, "You are trying to perform a benchmark with the following values:<br>");
- io.WriteString(c, "<table border=\"1\">");
- io.WriteString(c, fmt.Sprintf("<tr><td>Host</td><td>%s</td></tr>", dbhost));
- io.WriteString(c, fmt.Sprintf("<tr><td>User</td><td>%s</td></tr>", dbuser));
- io.WriteString(c, fmt.Sprintf("<tr><td>Password</td><td>%s</td></tr>", dbpass));
- io.WriteString(c, fmt.Sprintf("<tr><td>Database</td><td>%s</td></tr>", dbname));
- io.WriteString(c, fmt.Sprintf("<tr><td>Data Multiplier</td><td>%s</td></tr>", dbmult));
- io.WriteString(c, fmt.Sprintf("<tr><td>Number of Threads</td><td>%s</td></tr>", nthreads));
- io.WriteString(c, "</table>");
- io.WriteString(c, "<form method=\"post\" action=\"/begin\">");
- io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbhost\" value=\"%s\">",dbhost));
- io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbuser\" value=\"%s\">",dbuser));
- io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbpass\" value=\"%s\">",dbpass));
- io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbname\" value=\"%s\">",dbname));
- io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"nthreads\" value=\"%s\">",nthreads));
- io.WriteString(c, fmt.Sprintf("<input type=\"hidden\" name=\"dbmult\" value=\"%s\">",dbmult));
- io.WriteString(c, "<input type=\"submit\" name=\"Begin\" value=\"Begin\">");
- io.WriteString(c, "</form>");
-
- dbtype = "mysql";
-
- footer(c);
- comout <- fmt.Sprintf("configure:%s:%s:%s:%s:%s:%s:%s", dbtype, dbhost, dbuser, dbpass, dbname, dbmult, nthreads);
-
-}
-
-func mainPage(c *http.Conn, req *http.Request)
-{
- header(c);
- io.WriteString(c, "<h1>goDBHammer</h1><br>");
- io.WriteString(c, "Welcome to goDBHammer, the go based database benchmarking tool<br>");
- io.WriteString(c, "<form method=\"post\" action=\"/confirm\">");
- io.WriteString(c, "<table><tr><td>Database Type</td><td><input type=\"text\" name=\"dbtype\" value=\"ignored for now\"></td></tr>");
- io.WriteString(c, "<tr><td>Database Host</td><td><input type=\"text\" name=\"dbhost\"></td></tr>");
- io.WriteString(c, "<tr><td>Database User</td><td><input type=\"text\" name=\"dbuser\"></td></tr>");
- io.WriteString(c, "<tr><td>Database Password</td><td><input type=\"text\" name=\"dbpass\"></td></tr>");
- io.WriteString(c, "<tr><td>Database</td><td><input type=\"text\" name=\"dbname\"></td></tr>");
- io.WriteString(c, "<tr><td>Data Multiplier</td><td><input type=\"text\" name=\"dbmult\"></td></tr>");
- io.WriteString(c, "<tr><td>Number of Clients</td><td><input type=\"text\" name=\"nthreads\"></td></tr>");
- io.WriteString(c, "<tr><td><input type=\"submit\" name=\"Setup\" value=\"Setup\"></td></tr>");
- io.WriteString(c, "</table>");
- io.WriteString(c, "</form>");
- fmt.Printf("%s\n", req.FormValue("dbhost"));
- footer(c);
-}
func header(c *http.Conn)
{
bc := benchcontroller.CreateController();
go benchcontroller.MainLoop(bc, comout, comin, cominstatus);
- http.Handle("/", http.FileServer("./web", "/web"));
+ http.Handle("/", http.FileServer("./web/", "/"));
http.Handle("/json", http.HandlerFunc(JSONResponder));
err := http.ListenAndServe(":22222", nil);
if err != nil {