Skip to content

Commit

Permalink
WIP - refactoring javascript for better dependency injection, fixed a…
Browse files Browse the repository at this point in the history
… bug with services reaching retry policy occuring when services vanish
  • Loading branch information
jerome-netguardians committed May 2, 2020
1 parent 6eaff12 commit d2ee117
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 22 deletions.
9 changes: 4 additions & 5 deletions src/main/webapp/html/eskimoMarathonServicesSelection.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" onclick="javascript:eskimoMain.getServicesSelection().cancelServicesSelection();">&times;</button>
<button type="button" class="close" id="marathon-services-select-header-cancel">&times;</button>
<h4 class="modal-title">Select Marathon Services</h4>
</div>
<div id="marathon-services-selection-body" class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button id="select-all-marathon-services-button" type="button" class="btn btn-default"
onclick="javascript:eskimoMain.getMarathonServicesSelection().marathonServicesSelectionSelectAll();">SelectAll</button>
<button type="button" class="btn btn-default" onclick="javascript:eskimoMain.getMarathonServicesSelection().cancelMarathonServicesSelection();">Cancel</button>
<button type="button" class="btn btn-primary" onclick="javascript:eskimoMain.getMarathonServicesSelection().validateMarathonServicesSelection();">OK</button>
<button id="select-all-marathon-services-button" type="button" class="btn btn-default">SelectAll</button>
<button type="button" class="btn btn-default" id="marathon-services-select-button-cancel">Cancel</button>
<button type="button" class="btn btn-primary" id="marathon-services-select-button-validate">OK</button>
</div>
</div>

Expand Down
7 changes: 5 additions & 2 deletions src/main/webapp/scripts/eskimoMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,17 @@ eskimo.Main = function() {
// loadServicesConfig -> get-services-config
// - initModalServicesConfig()

eskimoMarathonServicesSelection = new eskimo.MarathonServicesSelection();

eskimoServicesConfig = new eskimo.ServicesConfig();
// loadServicesConfig -> load-services-config

eskimoMarathonServicesConfig = new eskimo.MarathonServicesConfig({eskimoMain: this});
// loadMarathonServices -> get-marathon-services

eskimoMarathonServicesSelection = new eskimo.MarathonServicesSelection({
eskimoMarathonServicesConfig: eskimoMarathonServicesConfig
});
// (nothing)

eskimoOperationsCommand = new eskimo.OperationsCommand();
// (nothing)

Expand Down
23 changes: 19 additions & 4 deletions src/main/webapp/scripts/eskimoMarathonServicesSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ Software.
if (typeof eskimo === "undefined" || eskimo == null) {
window.eskimo = {}
}
eskimo.MarathonServicesSelection = function() {
eskimo.MarathonServicesSelection = function(constructorObject) {

// will be injected eventually from constructorObject
this.eskimoMarathonServicesConfig = null;

var that = this;

Expand All @@ -50,7 +53,13 @@ eskimo.MarathonServicesSelection = function() {

if (statusTxt == "success") {

// nothing to do
$("#marathon-services-select-header-cancel").click(cancelMarathonServicesSelection);

$("#select-all-marathon-services-button").click(marathonServicesSelectionSelectAll);

$("#marathon-services-select-button-cancel").click(cancelMarathonServicesSelection);

$("#marathon-services-select-button-validate").click(validateMarathonServicesSelection);

} else if (statusTxt == "error") {
alert("Error: " + jqXHR.status + " " + jqXHR.statusText);
Expand All @@ -67,7 +76,7 @@ eskimo.MarathonServicesSelection = function() {

var allSelected = true;

var marathonServices = eskimoMain.getMarathonServicesConfig().getMarathonServices();
var marathonServices = eskimoMarathonServicesConfig.getMarathonServices();

// are they all selected already
for (var i = 0; i < marathonServices.length; i++) {
Expand All @@ -94,10 +103,16 @@ eskimo.MarathonServicesSelection = function() {

var reinstallConfig = $("form#marathon-servicesreinstall").serializeObject();

eskimoMain.getMarathonServicesConfig().proceedWithReinstall (reinstallConfig);
eskimoMarathonServicesConfig.proceedWithReinstall (reinstallConfig);
}
this.validateMarathonServicesSelection = validateMarathonServicesSelection;


// inject constructor object in the end
if (constructorObject != null) {
$.extend(this, constructorObject);
}

// call constructor
this.initialize();
};
25 changes: 22 additions & 3 deletions src/main/webapp/scripts/eskimoServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,22 @@ eskimo.Services = function () {
}
}

function handleServiceIsUp(effUIConfig) {
function removeFromRetry (uiConfig) {
// remove from retry list
for (var j = 0; j < uiConfigsToRetry.length; j++) {
if (uiConfigsToRetry[j] == effUIConfig) {
if (uiConfigsToRetry[j] == uiConfig) {
//console.trace();
console.log("removing from retry " + uiConfigsToRetry[j].service);
uiConfigsToRetry.splice(j, 1);
break;
}
}
}

function handleServiceIsUp(effUIConfig) {

// remove from retry list
removeFromRetry (effUIConfig);

// schedule usual refresh
setTimeout(function (otherUIConfig) {
Expand Down Expand Up @@ -323,8 +330,10 @@ eskimo.Services = function () {

this.handleServiceHiding = function (service, uiConfig) {

if (!uiConfig || uiConfig == null) {
var comingFromMenuHook = true;
if (!uiConfig || uiConfig == null) { // if coming from eskimoMain.serviceMenuClear()
uiConfig = UI_SERVICES_CONFIG[service];
comingFromMenuHook = false;
}

if (uiConfig == null) {
Expand All @@ -347,6 +356,16 @@ eskimo.Services = function () {
uiConfig.actualUrl = null;
}

// comingFromMenuHook is false if the hiding is triggered by the periodic menu cleaning in prealable of service
// injection (eskimoMain.serviceMenuClear())
// => in this case we don't want to mess with retry yet (not as long as we don't know newest status)
if (comingFromMenuHook) {
// If there as a retry running on service, drop it
// (remove from retry list)
removeFromRetry(uiConfig);
uiConfig.refreshWaiting = false;
}

// if service was displayed, show Status
if (eskimoMain.isCurrentDisplayedService(service)) {
eskimoMain.getSystemStatus().showStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ public void init() throws Exception {

waitForDefinition("$.fn");



// override jquery load
page.executeJavaScript("$.fn._internalLoad = $.fn.load;");
page.executeJavaScript("$.fn.load = function (resource, callback) { return this._internalLoad ('../../src/main/webapp/'+resource, callback); };");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import ch.niceideas.common.utils.ResourceUtils;
import ch.niceideas.common.utils.StreamUtils;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -46,11 +47,20 @@ public class EskimoMarathonServicesSelectionTest extends AbstractWebTest {
@Before
public void setUp() throws Exception {

loadScript(page, "bootstrap.js");
loadScript(page, "eskimoUtils.js");
loadScript(page, "eskimoMarathonServicesSelection.js");

page.executeJavaScript("eskimoMarathonServicesConfig = {};");

// leaving gdash out intentionally
page.executeJavaScript("eskimoMarathonServicesConfig.getMarathonServices = function() {return ['cerebro', 'kibana', 'kafka-manager', 'spark-history-server', 'grafana', 'zeppelin']};");


// instantiate test object
page.executeJavaScript("eskimoMarathonServicesSelection = new eskimo.MarathonServicesSelection();");
page.executeJavaScript("eskimoMarathonServicesSelection = new eskimo.MarathonServicesSelection({" +
" eskimoMarathonServicesConfig: eskimoMarathonServicesConfig" +
"});");


waitForElementIdInDOM("marathon-services-selection-body");
Expand All @@ -67,16 +77,42 @@ public void testNominal() throws Exception {

// this is just to ensure everything has been properly loaded by setup
assertNotNull (page.getElementById("select-all-marathon-services-button"));

page.executeJavaScript("eskimoMarathonServicesSelection.showMarathonServiceSelection()");

Thread.sleep(10);

assertCssValue("#marathon-services-selection-modal", "display", "block");
assertCssValue("#marathon-services-selection-modal", "visibility", "visible");
}

@Test
public void testSelectAll() throws Exception {
public void testClickButtonValidate() throws Exception {

page.executeJavaScript("eskimoMain.marathonServicesConfig = {};");
page.executeJavaScript("eskimoMain.getMarathonServicesConfig = function () { return eskimoMain.marathonServicesConfig;} ");
testNominal();

// leaving gdash out intentionally
page.executeJavaScript("eskimoMain.getMarathonServicesConfig().getMarathonServices = function() {return ['cerebro', 'kibana', 'kafka-manager', 'spark-history-server', 'grafana', 'zeppelin']};");
page.executeJavaScript("eskimoMarathonServicesConfig.proceedWithReinstall = function (reinstallConfig) {" +
" window.reinstallConfig = JSON.stringify (reinstallConfig);" +
"}");

testSelectAll();

page.getElementById("marathon-services-select-button-validate").click();

JSONObject expectedResult = new JSONObject("{" +
"\"cerebro_reinstall\":\"on\"," +
"\"grafana_reinstall\":\"on\"," +
"\"kafka-manager_reinstall\":\"on\"," +
"\"kibana_reinstall\":\"on\"," +
"\"spark-history-server_reinstall\":\"on\"," +
"\"zeppelin_reinstall\":\"on\"}");

JSONObject actualResult = new JSONObject((String)page.executeJavaScript("window.reinstallConfig").getJavaScriptResult());
assertTrue(expectedResult.similar(actualResult));
}

@Test
public void testSelectAll() throws Exception {

page.executeJavaScript("eskimoMarathonServicesSelection.marathonServicesSelectionSelectAll();");

Expand Down

0 comments on commit d2ee117

Please sign in to comment.