diff --git a/src/main/webapp/html/eskimoMarathonServicesConfig.html b/src/main/webapp/html/eskimoMarathonServicesConfig.html index 469772a1..0c04b45c 100644 --- a/src/main/webapp/html/eskimoMarathonServicesConfig.html +++ b/src/main/webapp/html/eskimoMarathonServicesConfig.html @@ -68,18 +68,17 @@

Marathon Services configuration

-
-
-
diff --git a/src/main/webapp/scripts/eskimoMain.js b/src/main/webapp/scripts/eskimoMain.js index 506b660c..dcee73cf 100644 --- a/src/main/webapp/scripts/eskimoMain.js +++ b/src/main/webapp/scripts/eskimoMain.js @@ -354,7 +354,7 @@ eskimo.Main = function() { eskimoServicesConfig = new eskimo.ServicesConfig(); // loadServicesConfig -> load-services-config - eskimoMarathonServicesConfig = new eskimo.MarathonServicesConfig(); + eskimoMarathonServicesConfig = new eskimo.MarathonServicesConfig({eskimoMain: this}); // loadMarathonServices -> get-marathon-services eskimoOperationsCommand = new eskimo.OperationsCommand(); diff --git a/src/main/webapp/scripts/eskimoMarathonServicesConfig.js b/src/main/webapp/scripts/eskimoMarathonServicesConfig.js index c68e735c..31e30e6e 100644 --- a/src/main/webapp/scripts/eskimoMarathonServicesConfig.js +++ b/src/main/webapp/scripts/eskimoMarathonServicesConfig.js @@ -35,7 +35,10 @@ Software. if (typeof eskimo === "undefined" || eskimo == null) { window.eskimo = {} } -eskimo.MarathonServicesConfig = function() { +eskimo.MarathonServicesConfig = function(constructorObject) { + + // will be injected eventually from constructorObject + this.eskimoMain = null; var that = this; @@ -56,19 +59,37 @@ eskimo.MarathonServicesConfig = function() { console.log(setupConfig); try { - checkMarathonSetup(setupConfig, eskimoMain.getNodesConfig().getServicesDependencies(), + checkMarathonSetup(setupConfig, that.eskimoMain.getNodesConfig().getServicesDependencies(), function () { // callback if setup is OK proceedWithMarathonInstallation(setupConfig); }); } catch (error) { - alert ("error"); + alert ("error : " + error); } e.preventDefault(); return false; }); + $("#reinstall-marathon-servicesbtn").click(function (e) { + showReinstallSelection(); + e.preventDefault(); + return false; + }); + + $("#select-all-marathon-servicesconfig").click(function (e) { + selectAll(); + e.preventDefault(); + return false; + }); + + $("#reset-marathon-servicesconfig").click(function (e) { + showMarathonServicesConfig(); + e.preventDefault(); + return false; + }); + loadMarathonServices(); @@ -112,7 +133,7 @@ eskimo.MarathonServicesConfig = function() { return MARATHON_SERVICES; }; - this.selectAll = function() { + function selectAll(){ var allSelected = true; @@ -127,7 +148,8 @@ eskimo.MarathonServicesConfig = function() { for (var i = 0; i < MARATHON_SERVICES.length; i++) { $('#' + MARATHON_SERVICES[i] + "_install").get(0).checked = !allSelected; } - }; + } + this.selectAll = selectAll; this.renderMarathonConfig = function (marathonConfig) { @@ -139,7 +161,7 @@ eskimo.MarathonServicesConfig = function() { marathonServiceRow += ''+ '' + - '' + + '' + ''+ ''+ MARATHON_SERVICES[i]+ @@ -174,9 +196,9 @@ eskimo.MarathonServicesConfig = function() { }; - this.showReinstallSelection = function() { + function showReinstallSelection() { - eskimoMain.getMarathonServicesSelection().showMarathonServiceSelection(); + that.eskimoMain.getMarathonServicesSelection().showMarathonServiceSelection(); var marathonServicesSelectionHTML = $('#marathon-services-container-table').html(); marathonServicesSelectionHTML = marathonServicesSelectionHTML.replace(/marathon\-services/g, "marathon-services-selection"); @@ -186,18 +208,18 @@ eskimo.MarathonServicesConfig = function() { '
' + marathonServicesSelectionHTML + '
'); - - }; + } + this.showReinstallSelection = showReinstallSelection; function showMarathonServicesConfig () { - if (!eskimoMain.isSetupDone()) { - eskimoMain.showSetupNotDone("Cannot configure marathon services as long as initial setup is not completed"); + if (!that.eskimoMain.isSetupDone()) { + that.eskimoMain.showSetupNotDone("Cannot configure marathon services as long as initial setup is not completed"); return; } - if (eskimoMain.isOperationInProgress()) { - eskimoMain.showProgressbar(); + if (that.eskimoMain.isOperationInProgress()) { + that.eskimoMain.showProgressbar(); } $.ajax({ @@ -222,7 +244,7 @@ eskimo.MarathonServicesConfig = function() { } else if (data.clear == "setup"){ - eskimoMain.handleSetupNotCompleted(); + that.eskimoMain.handleSetupNotCompleted(); } @@ -231,7 +253,7 @@ eskimo.MarathonServicesConfig = function() { error: errorHandler }); - eskimoMain.showOnlyContent("marathon-services-config"); + that.eskimoMain.showOnlyContent("marathon-services-config"); } this.showMarathonServicesConfig = showMarathonServicesConfig; @@ -253,7 +275,7 @@ eskimo.MarathonServicesConfig = function() { function proceedWithMarathonInstallation(model, reinstall) { - eskimoMain.showProgressbar(); + that.eskimoMain.showProgressbar(); // 1 hour timeout $.ajax({ @@ -265,7 +287,7 @@ eskimo.MarathonServicesConfig = function() { data: JSON.stringify(model), success: function (data, status, jqXHR) { - eskimoMain.hideProgressbar(); + that.eskimoMain.hideProgressbar(); // OK console.log(data); @@ -278,18 +300,23 @@ eskimo.MarathonServicesConfig = function() { if (!data.command) { alert ("Expected pending operations command but got none !"); } else { - eskimoMain.getMarathonOperationsCommand().showCommand (data.command); + that.eskimoMain.getMarathonOperationsCommand().showCommand (data.command); } } }, error: function (jqXHR, status) { - eskimoMain.hideProgressbar(); + that.eskimoMain.hideProgressbar(); errorHandler (jqXHR, status); } }); } + // inject constructor object in the end + if (constructorObject != null) { + $.extend(this, constructorObject); + } + // call constructor this.initialize(); }; diff --git a/src/test/javawebtests/ch/niceideas/eskimo/html/AbstractWebTest.java b/src/test/javawebtests/ch/niceideas/eskimo/html/AbstractWebTest.java index ef83430a..93d2e63c 100644 --- a/src/test/javawebtests/ch/niceideas/eskimo/html/AbstractWebTest.java +++ b/src/test/javawebtests/ch/niceideas/eskimo/html/AbstractWebTest.java @@ -188,6 +188,7 @@ public void init() throws Exception { page.executeJavaScript("var nodesConfig = {};"); page.executeJavaScript("nodesConfig.getServiceLogoPath = function (serviceName){ return serviceName + '-logo.png'; };"); page.executeJavaScript("nodesConfig.getServiceIconPath = function (serviceName){ return serviceName + '-icon.png'; };"); + page.executeJavaScript("nodesConfig.getServicesDependencies = function () { return {}; };"); page.executeJavaScript("nodesConfig.isServiceUnique = function (serviceName){ " + "return (serviceName == 'mesos-master' " + " || serviceName == 'zookeeper' " + diff --git a/src/test/javawebtests/ch/niceideas/eskimo/html/EskimoMarathonServicesConfigTest.java b/src/test/javawebtests/ch/niceideas/eskimo/html/EskimoMarathonServicesConfigTest.java index 69d1a07f..876dbb0a 100644 --- a/src/test/javawebtests/ch/niceideas/eskimo/html/EskimoMarathonServicesConfigTest.java +++ b/src/test/javawebtests/ch/niceideas/eskimo/html/EskimoMarathonServicesConfigTest.java @@ -36,14 +36,13 @@ import ch.niceideas.common.utils.ResourceUtils; import ch.niceideas.common.utils.StreamUtils; -import ch.niceideas.eskimo.model.NodesConfigWrapper; -import ch.niceideas.eskimo.services.StandardSetupHelpers; +import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertNotNull; public class EskimoMarathonServicesConfigTest extends AbstractWebTest { @@ -69,7 +68,7 @@ public void setUp() throws Exception { */ // instantiate test object - page.executeJavaScript("eskimoMarathonServicesConfig = new eskimo.MarathonServicesConfig();"); + page.executeJavaScript("eskimoMarathonServicesConfig = new eskimo.MarathonServicesConfig({eskimoMain: eskimoMain});"); waitForElementIdInDOM("reset-marathon-servicesconfig"); @@ -82,11 +81,34 @@ public void setUp() throws Exception { " \"spark-history-server\",\n" + " \"zeppelin\"\n" + " ]);"); + + page.executeJavaScript("$('#inner-content-marathon-services-config').css('display', 'inherit')"); + page.executeJavaScript("$('#inner-content-marathon-services-config').css('visibility', 'visible')"); } @Test public void testSaveMarathonServicesButtonClick() throws Exception { - fail ("To Be Implemented"); + + testRenderMarathonConfig(); + + page.executeJavaScript("function checkMarathonSetup (marathonConfig) {" + + " console.log (marathonConfig);" + + " window.savedMarathonConfig = JSON.stringify (marathonConfig);" + + "};"); + + page.getElementById("save-marathon-servicesbtn").click(); + + JSONObject expectedConfig = new JSONObject("" + + "{\"cerebro_install\":\"on\"," + + "\"gdash_install\":\"on\"," + + "\"grafana_install\":\"on\"," + + "\"kafka-manager_install\":\"on\"," + + "\"kibana_install\":\"on\"," + + "\"spark-history-server_install\":\"on\"," + + "\"zeppelin_install\":\"on\"}"); + + JSONObject actualConfig = new JSONObject((String)page.executeJavaScript("window.savedMarathonConfig").getJavaScriptResult()); + assertTrue(expectedConfig.similar(actualConfig)); } @Test