From 6bd43741de27a1b290d66ffba28e77791a3c73a2 Mon Sep 17 00:00:00 2001 From: jackgr Date: Tue, 26 May 2015 01:47:33 -0700 Subject: [PATCH] Made graph data service robust to missing endpoint. --- www/master/shared/config/production.json | 2 +- .../shared/js/modules/services/pollK8sData.js | 38 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/www/master/shared/config/production.json b/www/master/shared/config/production.json index bf02f7d84e1f..d86f0a8d8c86 100644 --- a/www/master/shared/config/production.json +++ b/www/master/shared/config/production.json @@ -1,7 +1,7 @@ { "k8sApiServer": "/api/v1beta2", "k8sApiv1beta3Server": "/api/v1beta3", - "k8sDataServer": "/cluster", + "k8sDataServer": "", "k8sDataPollMinIntervalSec": 10, "k8sDataPollMaxIntervalSec": 120, "k8sDataPollErrorThreshold": 5, diff --git a/www/master/shared/js/modules/services/pollK8sData.js b/www/master/shared/js/modules/services/pollK8sData.js index a8c8a1c422cb..7611f973fe25 100644 --- a/www/master/shared/js/modules/services/pollK8sData.js +++ b/www/master/shared/js/modules/services/pollK8sData.js @@ -12,7 +12,7 @@ var sampleDataFiles = ["shared/assets/sampleData1.json"]; this.setSampleDataFiles = function(value) { sampleDataFiles = value; }; - var dataServer = "http://localhost:5555/cluster"; + var dataServer = ""; this.setDataServer = function(value) { dataServer = value; }; var pollMinIntervalSec = 10; @@ -107,24 +107,26 @@ var pollOnce = function(scope, repeat) { var dataSource = (k8sdatamodel.useSampleData) ? getSampleDataFile() : dataServer; - $.getJSON(dataSource) - .done(function(newModel, jqxhr, textStatus) { - if (newModel && newModel.success) { - delete newModel.success; // Remove success indicator. - delete newModel.timestamp; // Remove changing timestamp. - updateModel(newModel); - scope.$apply(); + if (dataSource) { + $.getJSON(dataSource) + .done(function(newModel, jqxhr, textStatus) { + if (newModel && newModel.success) { + delete newModel.success; // Remove success indicator. + delete newModel.timestamp; // Remove changing timestamp. + updateModel(newModel); + scope.$apply(); + promise = repeat ? $timeout(function() { pollOnce(scope, true); }, pollInterval * 1000) : undefined; + return; + } + + bumpCounters(); promise = repeat ? $timeout(function() { pollOnce(scope, true); }, pollInterval * 1000) : undefined; - return; - } - - bumpCounters(); - promise = repeat ? $timeout(function() { pollOnce(scope, true); }, pollInterval * 1000) : undefined; - }) - .fail(function(jqxhr, textStatus, error) { - bumpCounters(); - promise = repeat ? $timeout(function() { pollOnce(scope, true); }, pollInterval * 1000) : undefined; - }); + }) + .fail(function(jqxhr, textStatus, error) { + bumpCounters(); + promise = repeat ? $timeout(function() { pollOnce(scope, true); }, pollInterval * 1000) : undefined; + }); + } }; var isPolling = function() { return promise ? true : false; };