cluster_states.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. App.clusterStatus = Ember.Object.create({
  20. clusterName: '',
  21. validStates: ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3', 'CLUSTER_INSTALLED_4', 'CLUSTER_STARTED_5',
  22. 'ADD_HOSTS_DEPLOY_PREP_2', 'ADD_HOSTS_INSTALLING_3', 'ADD_HOSTS_INSTALLED_4', 'ADD_HOSTS_COMPLETED_5',
  23. 'ADD_SERVICES_DEPLOY_PREP_2', 'ADD_SERVICES_INSTALLING_3', 'ADD_SERVICES_INSTALLED_4', 'ADD_SERVICES_COMPLETED_5',
  24. 'STOPPING_SERVICES', 'STACK_UPGRADING', 'STACK_UPGRADE_FAILED', 'STACK_UPGRADED', 'STACK_UPGRADE_COMPLETED', 'ADD_SECURITY_STEP_1',
  25. 'ADD_SECURITY_STEP_2', 'ADD_SECURITY_STEP_3', 'ADD_SECURITY_STEP_4', 'DISABLE_SECURITY', 'SECURITY_COMPLETED', 'HIGH_AVAILABILITY_DEPLOY',
  26. 'HIGH_AVAILABILITY_DISABLED', 'ROLLBACK_HIGH_AVAILABILITY'],
  27. clusterState: 'CLUSTER_NOT_CREATED_1',
  28. wizardControllerName: null,
  29. localdb: null,
  30. key: 'CLUSTER_CURRENT_STATUS',
  31. isInstalled: function(){
  32. var notInstalledStates = ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3'];
  33. return !notInstalledStates.contains(this.get('clusterState'));
  34. }.property('clusterState'),
  35. /**
  36. * get cluster data from server and update cluster status
  37. * @param isAsync: set this to true if the call is to be made asynchronously. if unspecified, false is assumed
  38. * @return promise object for the get call
  39. */
  40. updateFromServer: function(isAsync) {
  41. // if isAsync is undefined, set it to false
  42. isAsync = isAsync || false;
  43. var url = App.apiPrefix + '/persist/' + this.get('key');
  44. return jQuery.ajax(
  45. {
  46. url: url,
  47. context: this,
  48. async: isAsync,
  49. success: function (response) {
  50. if (response) {
  51. var newValue = jQuery.parseJSON(response);
  52. if (newValue.clusterState) {
  53. this.set('clusterState', newValue.clusterState);
  54. }
  55. if (newValue.clusterName) {
  56. this.set('clusterName', newValue.clusterName);
  57. }
  58. if (newValue.wizardControllerName) {
  59. this.set('wizardControllerName', newValue.wizardControllerName);
  60. }
  61. if (newValue.localdb) {
  62. this.set('localdb', newValue.localdb);
  63. }
  64. } else {
  65. // default status already set
  66. }
  67. },
  68. error: function (xhr) {
  69. if (xhr.status == 404) {
  70. // default status already set
  71. console.log('Persist API did NOT find the key CLUSTER_CURRENT_STATUS');
  72. return;
  73. }
  74. App.ModalPopup.show({
  75. header: Em.I18n.t('common.error'),
  76. secondary: false,
  77. onPrimary: function () {
  78. this.hide();
  79. },
  80. bodyClass: Ember.View.extend({
  81. template: Ember.Handlebars.compile('<p>{{t common.update.error}}</p>')
  82. })
  83. });
  84. },
  85. statusCode: require('data/statusCodes')
  86. }
  87. );
  88. },
  89. /**
  90. * update cluster status and post it on server
  91. * @param newValue
  92. * @return {*}
  93. */
  94. setClusterStatus: function(newValue){
  95. if(App.testMode) return false;
  96. if (newValue) {
  97. //setter
  98. if (newValue.clusterState) {
  99. this.set('clusterState', newValue.clusterState);
  100. }
  101. if (newValue.clusterName) {
  102. this.set('clusterName', newValue.clusterName);
  103. }
  104. if (newValue.wizardControllerName) {
  105. this.set('wizardControllerName', newValue.wizardControllerName);
  106. }
  107. if (newValue.localdb) {
  108. this.set('localdb', newValue.localdb);
  109. }
  110. var keyValuePair = {};
  111. var val = {
  112. clusterName: this.get('clusterName'),
  113. clusterState: this.get('clusterState'),
  114. wizardControllerName: this.get('wizardControllerName'),
  115. localdb: this.get('localdb')
  116. };
  117. keyValuePair[this.get('key')] = JSON.stringify(val);
  118. App.ajax.send({
  119. name: 'cluster.state',
  120. sender: this,
  121. data: {
  122. key: keyValuePair,
  123. newVal: newValue
  124. },
  125. beforeSend: 'clusterStatusBeforeSend',
  126. error: 'clusterStatusErrorCallBack'
  127. });
  128. return newValue;
  129. }
  130. },
  131. clusterStatusBeforeSend: function (keyValuePair) {
  132. console.log('BeforeSend: persistKeyValues', keyValuePair);
  133. },
  134. clusterStatusErrorCallBack: function(request, ajaxOptions, error, opt) {
  135. console.log("ERROR");
  136. if(opt.newValue.errorCallBack) {
  137. opt.newValue.errorCallBack();
  138. } else {
  139. var doc = $.parseXML(request.responseText);
  140. var msg = 'Error ' + (request.status) + ' ';
  141. msg += $(doc).find("body p").text();
  142. }
  143. App.ModalPopup.show({
  144. header: Em.I18n.t('common.error'),
  145. secondary: false,
  146. response: msg,
  147. onPrimary: function () {
  148. this.hide();
  149. },
  150. bodyClass: Ember.View.extend({
  151. template: Ember.Handlebars.compile('<p>{{t common.persist.error}} {{response}}</p>')
  152. })
  153. });
  154. },
  155. /**
  156. * general info about cluster
  157. */
  158. value: function () {
  159. return {
  160. clusterName: this.get('clusterName'),
  161. clusterState: this.get('clusterState'),
  162. wizardControllerName: this.get('wizardControllerName'),
  163. localdb: this.get('localdb')
  164. };
  165. }.property('clusterName', 'clusterState', 'localdb', 'wizardControllerName')
  166. });