1
0
Fork 0

finished asymmetrical and symmetrical plan

This commit is contained in:
scottashton 2014-02-13 12:00:50 +01:00
parent d6f705f8b9
commit f196f4361d
6 changed files with 199 additions and 56 deletions

View File

@ -16,62 +16,44 @@
},
startPlan: function() {
var countDispatcher = 0;
$(".dispatcher").each(function(dispatcher) {
var isDBServer;
var isCoordinator;
var self = this;
var data = {dbServer : [], coordinator: []};
$(".dispatcher").each(function(i, dispatcher) {
var host = $(".host", dispatcher).val();
var port = $(".port", dispatcher).val();
if (!this.isSymmetric) {
var isDBServer = $(".isDBServer", dispatcher).val();
var isCoordinator = $(".isCoordinator", dispatcher).val();
if (!host || 0 === host.length || !port || 0 === port.length) {
return true;
}
if (host != null && !host.isEmpty() &&
port != null && !port.isEmpty() &&
(this.isSymmetric) || isDBServer || isCoordinator) {
countDispatcher++;
if (!self.isSymmetric) {
isDBServer = $(".isDBServer", dispatcher).val();
isCoordinator = $(".isCoordinator", dispatcher).val();
} else {
isDBServer = "true";
isCoordinator = "true";
}
isDBServer === "true" ? data.dbServer.push(host + ":" + port) : null;
isCoordinator === "true" ? data.coordinator.push(host + ":" + port) : null;
})
if (countDispatcher === 0) {
alert("Please provide at least one dispatcher");
if (data.dbServer.length === 0) {
if (!self.isSymmetric) {
alert("Please provide at least one DBServer");
return;
} else {
alert("Please provide at least one dispatcher");
return;
}
}
var type = this.isSymmetric ? "symmetricalSetup" : "asymmetricalSetup";
var h = $("#host").val(),
p = $("#port").val(),
c = $("#coordinators").val(),
d = $("#dbs").val();
if (!h) {
alert("Please define a Host");
return;
}
if (!p) {
alert("Please define a Port");
return;
}
if (!c) {
alert("Please define a number of Coordinators");
return;
}
if (!d) {
alert("Please define a number of DBServers");
return;
if (data.coordinator.length === 0) {
alert("Please provide at least one Coordinator");
return;
}
data.type = this.isSymmetric ? "symmetricalSetup" : "asymmetricalSetup";
$.ajax("cluster/plan", {
type: "POST",
data: {
type: "testSetup",
dispatcher: h + ":" + p,
numberDBServers: parseInt(d, 10),
numberCoordinators: parseInt(c, 10)
}
data: JSON.stringify(data)
});
},
@ -83,7 +65,7 @@
},
removeEntry: function(e) {
$(e.currentTarget).closest(".control-group").remove();
$(e.currentTarget).closest(".control-group").remove();
},
render: function(isSymmetric) {
@ -99,3 +81,4 @@
});
}());

View File

@ -191,10 +191,11 @@ module.exports = function(karma) {
//Views Planner
'plannerFrontend/js/views/planScenarioSelectorView.js',
'plannerFrontend/js/views/planSymmetricView.js',
'plannerFrontend/js/views/planTestView.js',
// Router
// Router
'frontend/js/routers/router.js',
'plannerFrontend/js/routers/plannerRouter.js',
@ -271,7 +272,11 @@ module.exports = function(karma) {
//Planner
//Router
'test/specs/planner/router/routerSpec.js'
'test/specs/planner/router/routerSpec.js',
//View
'test/specs/planner/views/planSymmetricViewSpec.js',
'test/specs/planner/views/planTestViewSpec.js',
'test/specs/planner/views/planScenarioSelectorViewSpec.js'
],

View File

@ -191,6 +191,7 @@ module.exports = function(karma) {
//Views Planner
'plannerFrontend/js/views/planScenarioSelectorView.js',
'plannerFrontend/js/views/planSymmetricView.js',
'plannerFrontend/js/views/planTestView.js',
@ -205,6 +206,9 @@ module.exports = function(karma) {
// GraphViewer
//Router
'test/specs/planner/router/routerSpec.js',
//View
'test/specs/planner/views/planSymmetricViewSpec.js',
'test/specs/planner/views/planTestViewSpec.js',
'test/specs/planner/views/planScenarioSelectorViewSpec.js'
],

View File

@ -110,7 +110,7 @@
it("should route to planScenarioSelector", function() {
simpleNavigationCheck(
{
url: "planScenarioSelector"
url: ""
},
"PlanScenarioSelectorView"
);

View File

@ -0,0 +1,152 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global runs, waitsFor, jasmine*/
/*global $, arangoCollection*/
(function() {
"use strict";
describe("Plan Symmetric/Asymmetric View", function() {
var myView, ip_base;
beforeEach(function() {
$('body').append('<div id="content" class="removeMe"></div>');
myView = new window.PlanSymmetricView();
myView.render(true);
ip_base = "123.456.78";
spyOn($, "ajax");
spyOn(window, "alert");
});
afterEach(function() {
$('.removeMe').remove();
});
it("should start a symmetrical cluster", function() {
myView.render(true);
$(".add").click();
$(".add").click();
$(".dispatcher").each(function (i, d) {
$(".host", d).val(ip_base + i);
$(".port", d).val(i);
});
$("#startPlan").click();
expect($.ajax).toHaveBeenCalledWith("cluster/plan", {
type: "POST",
data: JSON.stringify({
dbServer: [ip_base + "0:0", ip_base + "1:1", ip_base + "2:2"],
coordinator: [ip_base + "0:0", ip_base + "1:1", ip_base + "2:2"],
type: "symmetricalSetup"
})
});
});
it("should start a asymmetrical cluster", function() {
myView.render(false);
$(".add").click();
$(".add").click();
$(".dispatcher").each(function (i, d) {
$(".host", d).val(ip_base + i);
$(".port", d).val(i);
if (i === 0) {
$(".isDBServer", d).val(true);
$(".isCoordinator", d).val(false)
} else if (i === 1) {
$(".isDBServer", d).val(false);
$(".isCoordinator", d).val(true);
} else {
$(".isDBServer", d).val(true);
$(".isCoordinator", d).val(true);
}
});
$("#startPlan").click();
expect($.ajax).toHaveBeenCalledWith("cluster/plan", {
type: "POST",
data: JSON.stringify({
dbServer: [ip_base + "0:0", ip_base + "2:2"],
coordinator: [ ip_base + "1:1", ip_base + "2:2"],
type: "asymmetricalSetup"
})
});
});
it("should not start a symmetrical cluster because no complete host ist provided", function() {
myView.render(true);
$(".add").click();
$(".add").click();
$(".dispatcher").each(function (i, d) {
if (i === 0) {
$(".host", d).val(ip_base + i);
} else {
$(".port", d).val(i);
}
});
$("#startPlan").click();
expect($.ajax).not.toHaveBeenCalled();
expect(window.alert).toHaveBeenCalledWith("Please provide at least one dispatcher");
});
it("should not start an asymmetrical cluster because no dbserver and coordinator ist provided", function() {
myView.render(false);
$(".add").click();
$(".add").click();
$(".dispatcher").each(function (i, d) {
$(".host", d).val(ip_base + i);
$(".port", d).val(i);
if (i === 0) {
$(".isDBServer", d).val(false);
$(".isCoordinator", d).val(false)
} else if (i === 1) {
$(".isDBServer", d).val(false);
$(".isCoordinator", d).val(false);
} else {
$(".isDBServer", d).val(false);
$(".isCoordinator", d).val(false);
}
});
$("#startPlan").click();
expect($.ajax).not.toHaveBeenCalled();
expect(window.alert).toHaveBeenCalledWith("Please provide at least one DBServer");
});
it("should not start an asymmetrical cluster because no coordinator ist provided", function() {
myView.render(false);
$(".add").click();
$(".add").click();
$(".dispatcher").each(function (i, d) {
$(".host", d).val(ip_base + i);
$(".port", d).val(i);
if (i === 0) {
$(".isDBServer", d).val(true);
$(".isCoordinator", d).val(false)
} else if (i === 1) {
$(".isDBServer", d).val(false);
$(".isCoordinator", d).val(false);
} else {
$(".isDBServer", d).val(false);
$(".isCoordinator", d).val(false);
}
});
$("#startPlan").click();
expect($.ajax).not.toHaveBeenCalled();
expect(window.alert).toHaveBeenCalledWith("Please provide at least one Coordinator");
});
it("should be able to add 3 and remove 2 input lines for hosts", function() {
myView.render(false);
$(".add").click();
$(".add").click();
$(".add").click();
$(".dispatcher").each(function (i, d) {
if (i >= 2) {
$(".delete", d).click();
}
});
expect($(".dispatcher").length).toEqual(2);
});
});
}());

View File

@ -37,15 +37,14 @@
$("#startPlan").click();
expect($.ajax).toHaveBeenCalledWith("cluster/plan", {
type: "POST",
data: {
data: JSON.stringify({
type: "testSetup",
dispatcher: ip + ":" + port,
numberCoordinators: coords,
numberDBServers: dbs,
type: "testSetup"
}
numberCoordinators: coords
})
});
});
it("should not start a cluster if dispatcher port is missing", function() {
$("#host").val("");
$("#startPlan").click();