Updated Branches: refs/heads/trunk 859ba4b49 -> 629bd3e5f
AMBARI-3581 Js error occurs after deleting host Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/629bd3e5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/629bd3e5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/629bd3e5 Branch: refs/heads/trunk Commit: 629bd3e5f202b5d45f1440fa2893bb2c2dc40a7b Parents: 859ba4b Author: aBabiichuk <[email protected]> Authored: Wed Oct 23 15:55:14 2013 +0300 Committer: aBabiichuk <[email protected]> Committed: Wed Oct 23 16:30:16 2013 +0300 ---------------------------------------------------------------------- ambari-web/app/mappers/hosts_mapper.js | 21 +++++++++++---------- ambari-web/app/mappers/service_mapper.js | 23 +++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/629bd3e5/ambari-web/app/mappers/hosts_mapper.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mappers/hosts_mapper.js b/ambari-web/app/mappers/hosts_mapper.js index 25f799f..cd87744 100644 --- a/ambari-web/app/mappers/hosts_mapper.js +++ b/ambari-web/app/mappers/hosts_mapper.js @@ -53,34 +53,35 @@ App.hostsMapper = App.QuickDataMapper.create({ if (json.items) { var result = this.parse(json.items); var clientHosts = App.Host.find(); - if (clientHosts != null && clientHosts.get('length') !== result.length) { - var serverHostIds = {}; + if (clientHosts != null && clientHosts.get('length') < result.length) { result.forEach(function (host) { - serverHostIds[host.id] = host.id; cacheData[host.id] = host; }); + } else if (clientHosts != null && clientHosts.get('length') > result.length) { var hostsToDelete = []; clientHosts.forEach(function (host) { - if (host !== null && !serverHostIds[host.get('hostName')]) { + if (host !== null && result.filterProperty('host_name',host.get('hostName')).length === 0) { // Delete old ones as new ones will be // loaded by loadMany(). hostsToDelete.push(host); + delete cacheData[host.get('hostName')]; } }); hostsToDelete.forEach(function (host) { host.deleteRecord(); + host.get('stateManager').transitionTo('loading'); }); } //restore properties from cache instead request them from server result.forEach(function (host) { var cacheHost = cacheData[host.id]; if (cacheHost) { - host.ip = cacheHost.ip; - host.os_arch = cacheHost.os_arch; - host.os_type = cacheHost.os_type; - host.public_host_name = cacheHost.public_host_name; - host.memory = cacheHost.memory; - host.cpu = cacheHost.cpu; + host.ip ? cacheHost.ip = host.ip : host.ip = cacheHost.ip; + host.os_arch ? cacheHost.os_arch = host.os_arch : host.os_arch = cacheHost.os_arch; + host.os_type ? cacheHost.os_type = host.os_type : host.os_type = cacheHost.os_type; + host.public_host_name ? cacheHost.public_host_name = host.public_host_name : host.public_host_name = cacheHost.public_host_name; + host.memory ? cacheHost.memory = host.memory : host.memory = cacheHost.memory; + host.cpu ? cacheHost.cpu = host.cpu : host.cpu = cacheHost.cpu; } }); App.store.loadMany(this.get('model'), result); http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/629bd3e5/ambari-web/app/mappers/service_mapper.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mappers/service_mapper.js b/ambari-web/app/mappers/service_mapper.js index 9cbc894..a99bed0 100644 --- a/ambari-web/app/mappers/service_mapper.js +++ b/ambari-web/app/mappers/service_mapper.js @@ -263,17 +263,20 @@ App.servicesMapper = App.QuickDataMapper.create({ var currentComponentNameHostNames = {}; var doHostComponentsLoad = false; oldHostComponents.forEach(function (item) { - if (item && !hostComponentsMap[item.get('id')]) { - item.deleteRecord(); - } else { - var componentName = item.get('componentName'); - if (componentName) { - currentHCWithComponentNames[item.get('id')] = item.get('id'); - } - if (!currentComponentNameHostNames[componentName]) { - currentComponentNameHostNames[componentName] = []; + if (item) { + if (!hostComponentsMap[item.get('id')]) { + item.deleteRecord(); + item.get('stateManager').transitionTo('loading'); + } else { + var componentName = item.get('componentName'); + if (componentName) { + currentHCWithComponentNames[item.get('id')] = item.get('id'); + } + if (!currentComponentNameHostNames[componentName]) { + currentComponentNameHostNames[componentName] = []; + } + currentComponentNameHostNames[componentName].pushObject(item.get('host.hostName')); } - currentComponentNameHostNames[componentName].pushObject(item.get('host.hostName')); } }, this);
