cluster_states.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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','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. */
  33. updateFromServer: function(){
  34. var url = App.apiPrefix + '/persist/' + this.get('key');
  35. jQuery.ajax(
  36. {
  37. url: url,
  38. context: this,
  39. async: false,
  40. success: function (response) {
  41. if (response) {
  42. var newValue = jQuery.parseJSON(response);
  43. if (newValue.clusterState) {
  44. this.set('clusterState', newValue.clusterState);
  45. }
  46. if (newValue.clusterName) {
  47. this.set('clusterName', newValue.clusterName);
  48. }
  49. if (newValue.wizardControllerName) {
  50. this.set('wizardControllerName', newValue.wizardControllerName);
  51. }
  52. if (newValue.localdb) {
  53. this.set('localdb', newValue.localdb);
  54. }
  55. } else {
  56. // default status already set
  57. }
  58. },
  59. error: function (xhr) {
  60. if (xhr.status == 404) {
  61. // default status already set
  62. console.log('Persist API did NOT find the key CLUSTER_CURRENT_STATUS');
  63. }
  64. },
  65. statusCode: require('data/statusCodes')
  66. }
  67. );
  68. },
  69. /**
  70. * update cluster status and post it on server
  71. * @param newValue
  72. * @return {*}
  73. */
  74. setClusterStatus: function(newValue){
  75. if (newValue) {
  76. //setter
  77. if (newValue.clusterState) {
  78. this.set('clusterState', newValue.clusterState);
  79. }
  80. if (newValue.clusterName) {
  81. this.set('clusterName', newValue.clusterName);
  82. }
  83. if (newValue.wizardControllerName) {
  84. this.set('wizardControllerName', newValue.wizardControllerName);
  85. }
  86. if (newValue.localdb) {
  87. this.set('localdb', newValue.localdb);
  88. }
  89. var url = App.apiPrefix + '/persist/';
  90. var keyValuePair = {};
  91. var val = {
  92. clusterName: this.get('clusterName'),
  93. clusterState: this.get('clusterState'),
  94. wizardControllerName: this.get('wizardControllerName'),
  95. localdb: this.get('localdb')
  96. };
  97. keyValuePair[this.get('key')] = JSON.stringify(val);
  98. jQuery.ajax({
  99. async: false,
  100. context: this,
  101. type: "POST",
  102. url: url,
  103. data: JSON.stringify(keyValuePair),
  104. beforeSend: function () {
  105. console.log('BeforeSend: persistKeyValues', keyValuePair);
  106. }
  107. });
  108. return newValue;
  109. }
  110. },
  111. /**
  112. * general info about cluster
  113. */
  114. value: function () {
  115. return {
  116. clusterName: this.get('clusterName'),
  117. clusterState: this.get('clusterState'),
  118. wizardControllerName: this.get('wizardControllerName'),
  119. localdb: this.get('localdb')
  120. };
  121. }.property('clusterName', 'clusterState', 'localdb', 'wizardControllerName')
  122. });