123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /**
- * 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');
- require('mixins/common/userPref');
- App.clusterStatus = Em.Object.create(App.UserPref, {
- /**
- * 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: function () {
- var notInstalledStates = ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3'];
- return !notInstalledStates.contains(this.get('clusterState'));
- }.property('clusterState'),
- /**
- * 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 (overrideLocaldb) {
- // if overrideLocaldb is undefined, set it to true
- this.set('additionalData', {
- user: App.db.getUser(),
- login: App.db.getLoginName(),
- 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 (response, opt, params) {
- if (response) {
- if (response.clusterState) {
- this.set('clusterState', response.clusterState);
- }
- if (response.clusterName) {
- this.set('clusterName', response.clusterName);
- }
- if (response.wizardControllerName) {
- this.set('wizardControllerName', response.wizardControllerName);
- }
- if (response.localdb) {
- this.set('localdb', response.localdb);
- // restore HAWizard data if process was started
- var isHAWizardStarted = App.get('isAdmin') && !App.isEmptyObject(response.localdb.HighAvailabilityWizard);
- if (params.data.overrideLocaldb || isHAWizardStarted) {
- var localdbTables = (App.db.data.app && App.db.data.app.tables) ? App.db.data.app.tables : {};
- App.db.data = response.localdb;
- App.db.setLocalStorage();
- App.db.setUser(params.data.user);
- App.db.setLoginName(params.data.login);
- 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 (request, ajaxOptions, error) {
- if (request.status == 404) {
- // default status already set
- console.log('Persist API did NOT find the key CLUSTER_CURRENT_STATUS');
- 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
- * @param {object} newValue
- * @param {object} opt - used for additional ajax request options, by default ajax used synchronous mode
- * @method setClusterStatus
- * @return {*}
- */
- setClusterStatus: function (newValue, opt) {
- if (App.get('testMode')) return false;
- var user = App.db.getUser();
- var login = App.db.getLoginName();
- var val = {clusterName: this.get('clusterName')};
- if (newValue) {
- App.db.cleanTmp();
- //setter
- if (newValue.clusterName) {
- this.set('clusterName', newValue.clusterName);
- val.clusterName = newValue.clusterName;
- }
- if (newValue.clusterState) {
- this.set('clusterState', newValue.clusterState);
- val.clusterState = newValue.clusterState;
- }
- if (newValue.wizardControllerName) {
- this.set('wizardControllerName', newValue.wizardControllerName);
- val.wizardControllerName = newValue.wizardControllerName;
- }
- if (newValue.localdb) {
- if (newValue.localdb.app && newValue.localdb.app.user)
- delete newValue.localdb.app.user;
- if (newValue.localdb.app && newValue.localdb.app.loginName)
- delete newValue.localdb.app.loginName;
- if (newValue.localdb.app && newValue.localdb.app.tables)
- delete newValue.localdb.app.tables;
- this.set('localdb', newValue.localdb);
- val.localdb = newValue.localdb;
- } else {
- delete App.db.data.app.user;
- delete App.db.data.app.loginName;
- delete App.db.data.app.tables;
- val.localdb = App.db.data;
- App.db.setUser(user);
- App.db.setLoginName(login);
- }
- if (opt) {
- var keyValuePair = {};
- keyValuePair[this.get('key')] = JSON.stringify(val);
- App.ajax.send({
- name: 'settings.post.user_pref',
- sender: opt.sender || this,
- data: {
- keyValuePair: keyValuePair
- },
- success: opt.success,
- beforeSend: opt.beforeSend,
- error: opt.error
- });
- }
- else {
- this.postUserPref(this.get('key'), val);
- }
- return newValue;
- }
- },
- /**
- * Error callback for post-persist request
- * @param {object} request
- * @param {object} ajaxOptions
- * @param {string} error
- * @method postUserPrefErrorCallback
- */
- postUserPrefErrorCallback: function (request, ajaxOptions, error) {
- console.log("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;
- }
- 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>')
- })
- });
- }
- });
|