cluster_states.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('mixins/common/userPref');
  20. App.clusterStatus = Em.Object.create(App.UserPref, {
  21. clusterName: '',
  22. validStates: [
  23. 'DEFAULT',
  24. 'CLUSTER_NOT_CREATED_1',
  25. 'CLUSTER_DEPLOY_PREP_2',
  26. 'CLUSTER_INSTALLING_3',
  27. 'SERVICE_STARTING_3',
  28. 'CLUSTER_INSTALLED_4',
  29. 'ADD_HOSTS_DEPLOY_PREP_2',
  30. 'ADD_HOSTS_INSTALLING_3',
  31. 'ADD_HOSTS_INSTALLED_4',
  32. 'ADD_SERVICES_DEPLOY_PREP_2',
  33. 'ADD_SERVICES_INSTALLING_3',
  34. 'ADD_SERVICES_INSTALLED_4',
  35. 'STOPPING_SERVICES',
  36. 'STACK_UPGRADING',
  37. 'STACK_UPGRADE_FAILED',
  38. 'STACK_UPGRADED',
  39. 'ADD_SECURITY_STEP_1',
  40. 'ADD_SECURITY_STEP_2',
  41. 'ADD_SECURITY_STEP_3',
  42. 'ADD_SECURITY_STEP_4',
  43. 'DISABLE_SECURITY',
  44. 'HIGH_AVAILABILITY_DEPLOY',
  45. 'ROLLBACK_HIGH_AVAILABILITY'],
  46. clusterState: 'CLUSTER_NOT_CREATED_1',
  47. wizardControllerName: null,
  48. localdb: null,
  49. key: 'CLUSTER_CURRENT_STATUS',
  50. isInstalled: function(){
  51. var notInstalledStates = ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3'];
  52. return !notInstalledStates.contains(this.get('clusterState'));
  53. }.property('clusterState'),
  54. /**
  55. * get cluster data from server and update cluster status
  56. * @param {Boolean} isAsync set this to true if the call is to be made asynchronously. if unspecified, false is assumed
  57. * @param {Boolean} overrideLocaldb
  58. * @return promise object for the get call
  59. */
  60. updateFromServer: function(isAsync, overrideLocaldb) {
  61. // if isAsync is undefined, set it to false
  62. this.set('makeRequestAsync', isAsync || false);
  63. // if overrideLocaldb is undefined, set it to true
  64. this.set('additionalData', {
  65. user: App.db.getUser(),
  66. login: App.db.getLoginName(),
  67. overrideLocaldb: overrideLocaldb || true
  68. });
  69. return this.getUserPref(this.get('key'));
  70. },
  71. getUserPrefSuccessCallback: function (response, opt, params) {
  72. if (response) {
  73. if (response.clusterState) {
  74. this.set('clusterState', response.clusterState);
  75. }
  76. if (response.clusterName) {
  77. this.set('clusterName', response.clusterName);
  78. }
  79. if (response.wizardControllerName) {
  80. this.set('wizardControllerName', response.wizardControllerName);
  81. }
  82. if (response.localdb) {
  83. this.set('localdb', response.localdb);
  84. // restore HAWizard data if process was started
  85. var isHAWizardStarted = App.get('isAdmin') && !App.isEmptyObject(response.localdb.HighAvailabilityWizard);
  86. if (params.overrideLocaldb || isHAWizardStarted) {
  87. App.db.data = response.localdb;
  88. App.db.setLocalStorage();
  89. App.db.setUser(params.user);
  90. App.db.setLoginName(params.login);
  91. }
  92. }
  93. }
  94. // this is to ensure that the local storage namespaces are initialized with all expected namespaces.
  95. // after upgrading ambari, loading local storage data from the "persist" data saved via an older version of
  96. // Ambari can result in missing namespaces that are defined in the new version of Ambari.
  97. App.db.mergeStorage();
  98. },
  99. getUserPrefErrorCallback: function (request, ajaxOptions, error) {
  100. if (request.status == 404) {
  101. // default status already set
  102. console.log('Persist API did NOT find the key CLUSTER_CURRENT_STATUS');
  103. return;
  104. }
  105. App.ModalPopup.show({
  106. header: Em.I18n.t('common.error'),
  107. secondary: false,
  108. bodyClass: Em.View.extend({
  109. template: Em.Handlebars.compile('<p>{{t common.update.error}}</p>')
  110. })
  111. });
  112. },
  113. /**
  114. * update cluster status and post it on server
  115. * @param newValue
  116. * @return {*}
  117. */
  118. setClusterStatus: function(newValue){
  119. if(App.testMode) return false;
  120. var user = App.db.getUser();
  121. var login = App.db.getLoginName();
  122. var val = {clusterName: this.get('clusterName')};
  123. if (newValue) {
  124. //setter
  125. if (newValue.clusterName) {
  126. this.set('clusterName', newValue.clusterName);
  127. val.clusterName = newValue.clusterName;
  128. }
  129. if (newValue.clusterState) {
  130. this.set('clusterState', newValue.clusterState);
  131. val.clusterState = newValue.clusterState;
  132. }
  133. if (newValue.wizardControllerName) {
  134. this.set('wizardControllerName', newValue.wizardControllerName);
  135. val.wizardControllerName = newValue.wizardControllerName;
  136. }
  137. if (newValue.localdb) {
  138. if (newValue.localdb.app && newValue.localdb.app.user)
  139. delete newValue.localdb.app.user;
  140. if (newValue.localdb.app && newValue.localdb.app.loginName)
  141. delete newValue.localdb.app.loginName;
  142. this.set('localdb', newValue.localdb);
  143. val.localdb = newValue.localdb;
  144. } else {
  145. delete App.db.data.app.user;
  146. delete App.db.data.app.loginName;
  147. val.localdb = App.db.data;
  148. App.db.setUser(user);
  149. App.db.setLoginName(login);
  150. }
  151. this.set('makeRequestAsync', false);
  152. this.postUserPref(this.get('key'), val);
  153. return newValue;
  154. }
  155. },
  156. postUserPrefErrorCallback: function(request, ajaxOptions, error) {
  157. console.log("ERROR");
  158. var msg = '', doc;
  159. try {
  160. msg = 'Error ' + (request.status) + ' ';
  161. doc = $.parseXML(request.responseText);
  162. msg += $(doc).find("body p").text();
  163. } catch (e) {
  164. msg += JSON.parse(request.responseText).message;
  165. }
  166. App.ModalPopup.show({
  167. header: Em.I18n.t('common.error'),
  168. secondary: false,
  169. response: msg,
  170. bodyClass: Em.View.extend({
  171. template: Em.Handlebars.compile('<p>{{t common.persist.error}} {{response}}</p>')
  172. })
  173. });
  174. },
  175. /**
  176. * general info about cluster
  177. */
  178. value: function () {
  179. return {
  180. clusterName: this.get('clusterName'),
  181. clusterState: this.get('clusterState'),
  182. wizardControllerName: this.get('wizardControllerName'),
  183. localdb: this.get('localdb')
  184. };
  185. }.property('clusterName', 'clusterState', 'localdb', 'wizardControllerName')
  186. });