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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | 1 1 1 1 1 1 4 4 2 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 1 1 1 1 1 1 1 1 1 7 7 | '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("models/cluster_states", 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'); var LZString = require('utils/lz-string'); App.clusterStatus = Em.Object.create(App.Persist, { /** * Cluster name * @type {string} */ clusterName: '', /** * List valid cluster states * @type {string[]} */ validStates: ['DEFAULT', 'CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3', 'CLUSTER_INSTALLED_4', 'ADD_HOSTS_DEPLOY_PREP_2', 'ADD_HOSTS_INSTALLING_3', 'ADD_HOSTS_INSTALLED_4', 'ADD_SERVICES_DEPLOY_PREP_2', 'ADD_SERVICES_INSTALLING_3', 'ADD_SERVICES_INSTALLED_4', 'STOPPING_SERVICES', 'STACK_UPGRADING', 'STACK_UPGRADE_FAILED', 'STACK_UPGRADED', 'ADD_SECURITY_STEP_1', 'ADD_SECURITY_STEP_2', 'ADD_SECURITY_STEP_3', 'ADD_SECURITY_STEP_4', 'DISABLE_SECURITY', 'HIGH_AVAILABILITY_DEPLOY', 'ROLLBACK_HIGH_AVAILABILITY'], /** * Default cluster state * @type {string} */ clusterState: 'CLUSTER_NOT_CREATED_1', /** * Current used wizard <code>controller.name</code> * @type {string|null} */ wizardControllerName: null, /** * Local DB * @type {object|null} */ localdb: null, /** * Persist key * @type {string} */ key: 'CLUSTER_CURRENT_STATUS', /** * Is cluster installed * @type {bool} */ isInstalled: Em.computed.notExistsIn('clusterState', ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3']), /** * Stores instance of <code>App.ModalPopup</code> created by <code>postUserPrefErrorCallback</code> * @property {App.ModalPopup|null} */ persistErrorModal: null, /** * General info about cluster * @type {{clusterName: string, clusterState: string, wizardControllerName: string, localdb: object}} */ value: function () { return { clusterName: this.get('clusterName'), clusterState: this.get('clusterState'), wizardControllerName: this.get('wizardControllerName'), localdb: this.get('localdb') }; }.property('clusterName', 'clusterState', 'localdb', 'wizardControllerName'), /** * get cluster data from server and update cluster status * @param {bool} overrideLocaldb * @return promise object for the get call * @method updateFromServer */ updateFromServer: function updateFromServer(overrideLocaldb) { this.set('additionalData', { user: App.db.getUser(), login: App.db.getLoginName(), auth: App.db.getAuth(), overrideLocaldb: !overrideLocaldb }); return this.getUserPref(this.get('key')); }, /** * Success callback for get-persist request * @param {object} response * @param {object} opt * @param {object} params * @method getUserPrefSuccessCallback */ getUserPrefSuccessCallback: function getUserPrefSuccessCallback(response, opt, params) { Eif (response) { // decompress response if ((typeof response === 'undefined' ? 'undefined' : _typeof(response)) != 'object') { response = JSON.parse(LZString.decompressFromBase64(response)); } Eif (response.clusterState) { this.set('clusterState', response.clusterState); } Eif (response.clusterName) { this.set('clusterName', response.clusterName); } Iif (response.wizardControllerName) { this.set('wizardControllerName', response.wizardControllerName); } Iif (response.localdb && !$.isEmptyObject(response.localdb)) { this.set('localdb', response.localdb); // restore HAWizard data if process was started var isHAWizardStarted = App.isAuthorized('SERVICE.ENABLE_HA') && !App.isEmptyObject(response.localdb.HighAvailabilityWizard); // restore Kerberos Wizard is started var isKerberosWizardStarted = App.isAuthorized('CLUSTER.TOGGLE_KERBEROS') && !App.isEmptyObject(response.localdb.KerberosWizard); if (params.data.overrideLocaldb || isHAWizardStarted || isKerberosWizardStarted) { var localdbTables = App.db.data.app && App.db.data.app.tables ? App.db.data.app.tables : {}; var authenticated = Em.get(App, 'db.data.app.authenticated') || false; App.db.data = response.localdb; App.db.setLocalStorage(); App.db.setUser(params.data.user); App.db.setLoginName(params.data.login); App.db.setAuth(params.data.auth); App.db.setAuthenticated(authenticated); App.db.data.app.tables = localdbTables; } } } // this is to ensure that the local storage namespaces are initialized with all expected namespaces. // after upgrading ambari, loading local storage data from the "persist" data saved via an older version of // Ambari can result in missing namespaces that are defined in the new version of Ambari. App.db.mergeStorage(); }, /** * Error callback for get-persist request * @param {object} request * @param {object} ajaxOptions * @param {string} error * @method getUserPrefErrorCallback */ getUserPrefErrorCallback: function getUserPrefErrorCallback(request, ajaxOptions, error) { if (request.status == 404) { // default status already set return; } App.ModalPopup.show({ header: Em.I18n.t('common.error'), secondary: false, bodyClass: Em.View.extend({ template: Em.Handlebars.compile('<p>{{t common.update.error}}</p>') }) }); }, /** * update cluster status and post it on server. * This function should always be called by admin user * @param {object} newValue * @param {object} opt - Can have additional params for ajax callBacks and sender * opt.successCallback * opt.successCallbackData * opt.errorCallback * opt.errorCallbackData * opt.alwaysCallback * opt.alwaysCallbackData * opt.sender * @method setClusterStatus * @return {*} */ setClusterStatus: function setClusterStatus(newValue, opt) { Iif (App.get('testMode')) return false; var user = App.db.getUser(); var auth = App.db.getAuth(); var login = App.db.getLoginName(); var val = { clusterName: this.get('clusterName') }; Eif (newValue) { App.db.cleanTmp(); //setter Eif (newValue.clusterName) { this.set('clusterName', newValue.clusterName); val.clusterName = newValue.clusterName; } Eif (newValue.clusterState) { this.set('clusterState', newValue.clusterState); val.clusterState = newValue.clusterState; } Eif (newValue.wizardControllerName) { this.set('wizardControllerName', newValue.wizardControllerName); val.wizardControllerName = newValue.wizardControllerName; } if (newValue.localdb) { Iif (newValue.localdb.app && newValue.localdb.app.user) delete newValue.localdb.app.user; Iif (newValue.localdb.app && newValue.localdb.app.auth) delete newValue.localdb.app.auth; Iif (newValue.localdb.app && newValue.localdb.app.loginName) delete newValue.localdb.app.loginName; Eif (newValue.localdb.app && newValue.localdb.app.tables) delete newValue.localdb.app.tables; Iif (newValue.localdb.app && newValue.localdb.app.authenticated) delete newValue.localdb.app.authenticated; this.set('localdb', newValue.localdb); val.localdb = newValue.localdb; } else { delete App.db.data.app.user; delete App.db.data.app.auth; delete App.db.data.app.loginName; delete App.db.data.app.tables; delete App.db.data.app.authenticated; val.localdb = App.db.data; App.db.setUser(user); App.db.setAuth(auth); App.db.setLoginName(login); } Iif (!$.mocho) { // compress val val = LZString.compressToBase64(JSON.stringify(val)); this.postUserPref(this.get('key'), val).done(function () { !!opt && Em.typeOf(opt.successCallback) === 'function' && opt.successCallback.call(opt.sender || this, opt.successCallbackData); }).fail(function () { !!opt && Em.typeOf(opt.errorCallback) === 'function' && opt.errorCallback.call(opt.sender || this, opt.errorCallbackData); }).always(function () { !!opt && Em.typeOf(opt.alwaysCallback) === 'function' && opt.alwaysCallback.call(opt.sender || this, opt.alwaysCallbackData); }); } return newValue; } }, /** * Error callback for post-persist request * @param {object} request * @param {object} ajaxOptions * @param {string} error * @method postUserPrefErrorCallback */ postUserPrefErrorCallback: function postUserPrefErrorCallback(request, ajaxOptions, error) { var msg = '', doc; try { msg = 'Error ' + request.status + ' '; doc = $.parseXML(request.responseText); msg += $(doc).find("body p").text(); } catch (e) { msg += JSON.parse(request.responseText).message; } if (this.get('persistErrorModal')) { if (this.get('persistErrorModal').get('state') === 'destroyed') { this.set('persistErrorModal', null); } else { this.get('persistErrorModal').onPrimary(); this.set('persistErrorModal', null); } } var modal = App.ModalPopup.show({ header: Em.I18n.t('common.error'), secondary: false, response: msg, bodyClass: Em.View.extend({ template: Em.Handlebars.compile('<p>{{t common.persist.error}} {{response}}</p>') }) }); this.set('persistErrorModal', modal); } }); }); |