cluster_states.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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'],
  26. clusterState: 'CLUSTER_NOT_CREATED_1',
  27. wizardControllerName: null,
  28. localdb: null,
  29. key: 'CLUSTER_CURRENT_STATUS',
  30. /**
  31. * get cluster data from server and update cluster status
  32. * @param isAsync: set this to true if the call is to be made asynchronously. if unspecified, false is assumed
  33. * @return promise object for the get call
  34. */
  35. updateFromServer: function(isAsync) {
  36. // if isAsync is undefined, set it to false
  37. isAsync = isAsync || false;
  38. var url = App.apiPrefix + '/persist/' + this.get('key');
  39. return jQuery.ajax(
  40. {
  41. url: url,
  42. context: this,
  43. async: isAsync,
  44. success: function (response) {
  45. if (response) {
  46. var newValue = jQuery.parseJSON(response);
  47. if (newValue.clusterState) {
  48. this.set('clusterState', newValue.clusterState);
  49. }
  50. if (newValue.clusterName) {
  51. this.set('clusterName', newValue.clusterName);
  52. }
  53. if (newValue.wizardControllerName) {
  54. this.set('wizardControllerName', newValue.wizardControllerName);
  55. }
  56. if (newValue.localdb) {
  57. this.set('localdb', newValue.localdb);
  58. }
  59. } else {
  60. // default status already set
  61. }
  62. },
  63. error: function (xhr) {
  64. if (xhr.status == 404) {
  65. // default status already set
  66. console.log('Persist API did NOT find the key CLUSTER_CURRENT_STATUS');
  67. return;
  68. }
  69. App.ModalPopup.show({
  70. header: Em.I18n.t('common.error'),
  71. secondary: false,
  72. onPrimary: function () {
  73. this.hide();
  74. },
  75. bodyClass: Ember.View.extend({
  76. template: Ember.Handlebars.compile('<p>{{t common.update.error}}</p>')
  77. })
  78. });
  79. },
  80. statusCode: require('data/statusCodes')
  81. }
  82. );
  83. },
  84. /**
  85. * update cluster status and post it on server
  86. * @param newValue
  87. * @return {*}
  88. */
  89. setClusterStatus: function(newValue){
  90. if(App.testMode) return false;
  91. if (newValue) {
  92. //setter
  93. if (newValue.clusterState) {
  94. this.set('clusterState', newValue.clusterState);
  95. }
  96. if (newValue.clusterName) {
  97. this.set('clusterName', newValue.clusterName);
  98. }
  99. if (newValue.wizardControllerName) {
  100. this.set('wizardControllerName', newValue.wizardControllerName);
  101. }
  102. if (newValue.localdb) {
  103. this.set('localdb', newValue.localdb);
  104. }
  105. var url = App.apiPrefix + '/persist/';
  106. var keyValuePair = {};
  107. var val = {
  108. clusterName: this.get('clusterName'),
  109. clusterState: this.get('clusterState'),
  110. wizardControllerName: this.get('wizardControllerName'),
  111. localdb: this.get('localdb')
  112. };
  113. keyValuePair[this.get('key')] = JSON.stringify(val);
  114. jQuery.ajax({
  115. async: false,
  116. context: this,
  117. type: "POST",
  118. url: url,
  119. data: JSON.stringify(keyValuePair),
  120. beforeSend: function () {
  121. console.log('BeforeSend: persistKeyValues', keyValuePair);
  122. },
  123. error: function () {
  124. console.log("ERROR");
  125. if(newValue.errorCallBack) {
  126. newValue.errorCallBack();
  127. } else {
  128. this.clusterStatusErrorCallBack();
  129. }
  130. },
  131. statusCode: require('data/statusCodes')
  132. });
  133. return newValue;
  134. }
  135. },
  136. clusterStatusErrorCallBack: function() {
  137. App.ModalPopup.show({
  138. header: Em.I18n.t('common.error'),
  139. secondary: false,
  140. onPrimary: function () {
  141. this.hide();
  142. },
  143. bodyClass: Ember.View.extend({
  144. template: Ember.Handlebars.compile('<p>{{t common.persist.error}}</p>')
  145. })
  146. });
  147. },
  148. /**
  149. * general info about cluster
  150. */
  151. value: function () {
  152. return {
  153. clusterName: this.get('clusterName'),
  154. clusterState: this.get('clusterState'),
  155. wizardControllerName: this.get('wizardControllerName'),
  156. localdb: this.get('localdb')
  157. };
  158. }.property('clusterName', 'clusterState', 'localdb', 'wizardControllerName')
  159. });