1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | 1 1 1 1 1 1 751 751 61 61 1 1 16758 16758 363890 35 35 363855 363855 32945 32945 330910 16478 16478 363855 314430 49425 16475 16475 16475 16475 16475 18416 18416 16475 16475 16758 349326 349326 349326 350766 87 87 87 87 350679 350766 349326 1 1 1 1 6 6 6 30 12 4 4 18 6 19 19 19 19 19 19 4 15 39 39 39 15 24 9 15 6 6 18 18 17 | 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; ;require.register("mappers/server_data_mapper", function (exports, require, module) { /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var App = require('app'); /** * initialize common cache container for mappers * App.cache contains shared data, used for syncronizing incoming server data among mappers */ App.cache = { 'previousHostStatuses': {}, 'previousComponentStatuses': {}, 'previousComponentPassiveStates': {}, 'staleConfigsComponentHosts': {}, 'services': [], 'currentConfigVersions': {} }; App.cache.clear = function () { var clear = App.cache.clear; App.cache = { 'previousHostStatuses': {}, 'previousComponentStatuses': {}, 'previousComponentPassiveStates': {}, 'services': [], 'currentConfigVersions': {} }; App.cache.clear = clear; }; App.store.reopen({ safeLoadMany: function safeLoadMany(model, records) { try { this.loadMany(model, records); } catch (e) { console.debug('Resolve uncommitted records before load'); this.fastCommit(); this.loadMany(model, records); } }, safeLoad: function safeLoad(model, record) { try { this.load(model, record); } catch (e) { console.debug('Resolve uncommitted record before load'); this.fastCommit(); this.load(model, record); } }, /** * App.store.commit() - creates new transaction, * and them move all records from old to new transactions which is expensive * * We should use only defaultTransaction, * and then we can stub <code>removeCleanRecords</code> method, * because it would remove from and add records to the same (default) transaction */ fastCommit: function fastCommit() { console.time('store commit'); App.store.defaultTransaction.commit(); console.timeEnd('store commit'); } }); App.ServerDataMapper = Em.Object.extend({ jsonKey: false, map: function map(json) { if (json) { var model = this.get('model'); var jsonKey = this.get('jsonKey'); if (jsonKey && json[jsonKey]) { // if data come as { hdfs: {...} } json = json[jsonKey]; } $.each(json, function (field, value) { model.set(field, value); }); } } }); App.QuickDataMapper = App.ServerDataMapper.extend({ config: {}, model: null, map: function map(json) { if (!this.get('model')) { return; } if (json.items) { var result = []; json.items.forEach(function (item) { result.push(this.parseIt(item, this.config)); }, this); App.store.safeLoadMany(this.get('model'), result); } }, parseIt: function parseIt(data, config) { var result = {}; for (var i in config) { if (i.substr(0, 1) === '$') { i = i.substr(1, i.length); result[i] = config['$' + i]; } else { var isSpecial = false; if (i.substr(-5) == '_type') { var prefix = i.substr(0, i.length - 5); isSpecial = config[prefix + '_key'] != null; } else if (i.substr(-4) == '_key') { var prefix = i.substr(0, i.length - 4); isSpecial = config[prefix + '_type'] != null; } if (!isSpecial && typeof config[i] == 'string') { result[i] = this.getJsonProperty(data, config[i]); } else if (_typeof(config[i]) == 'object') { result[i] = []; var _data = this.getJsonProperty(data, config[i + '_key']); var _type = config[i + '_type']; var l = _data.length; for (var index = 0; index < l; index++) { Eif (_type == 'array') { result[i].push(this.getJsonProperty(_data[index], config[i].item)); } else { result[i].push(this.parseIt(_data[index], config[i])); } } // As for 'widgets', just show the original order Eif (_type == 'array' && i != 'widgets') { result[i] = result[i].sort(); } } } } return result; }, getJsonProperty: function getJsonProperty(json, path) { var pathArr = path.split('.'); var current = json; while (pathArr.length && current) { if (pathArr[0].substr(-1) == ']') { var index = parseInt(pathArr[0].substr(-2, 1)); var attr = pathArr[0].substr(0, pathArr[0].length - 3); Eif (attr in current) { current = current[attr][index]; } } else { current = current[pathArr[0]]; } pathArr.splice(0, 1); } return current; }, /** * properly delete record from model * @param item */ deleteRecord: function deleteRecord(item) { Eif (item.get('isLoaded')) { item.deleteRecord(); App.store.fastCommit(); item.get('stateManager').transitionTo('loading'); } }, /** * check mutable fields whether they have been changed and if positive * return host object only with properties, that contains new value * @param current * @param previous * @param fields * @return {*} */ getDiscrepancies: function getDiscrepancies(current, previous, fields) { var result = {}; Eif (previous) { fields.forEach(function (field) { if (Array.isArray(current[field])) { if (JSON.stringify(current[field]) !== JSON.stringify(previous[field])) { result[field] = current[field]; result.isLoadNeeded = true; } } else { if (current[field] != previous[field]) result[field] = current[field]; } }); return result; } return current; }, /** * Binary search <code>searchElement</code> in the array (should be sorted!) * @param {number[]|string[]} array * @param {number|string} searchElement * @returns {number} position of the needed element or negative value, if value wasn't found * @method binaryIndexOf */ binaryIndexOf: function binaryIndexOf(array, searchElement) { var minIndex = 0; var maxIndex = array.length - 1; var currentIndex; var currentElement; var resultIndex; if (array[0] > searchElement || array[array.length - 1] < searchElement) { return -1; } while (minIndex <= maxIndex) { resultIndex = currentIndex = (minIndex + maxIndex) / 2 | 0; currentElement = array[currentIndex]; if (currentElement < searchElement) { minIndex = currentIndex + 1; } else if (currentElement > searchElement) { maxIndex = currentIndex - 1; } else { return currentIndex; } } return ~maxIndex; }, /** * @param {Em.Object} record * @param {object} event * @param {object} config */ updatePropertiesByConfig: function updatePropertiesByConfig(record, event, config) { Eif (record.get('isLoaded')) { for (var internalProp in config) { var externalProp = config[internalProp]; if (!Em.isNone(event[externalProp])) { record.set(internalProp, event[externalProp]); } } } } }); }); |