step3_controller.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. App.KerberosWizardStep3Controller = App.KerberosProgressPageController.extend({
  19. name: 'kerberosWizardStep3Controller',
  20. clusterDeployState: 'KERBEROS_DEPLOY',
  21. serviceName: 'KERBEROS',
  22. componentName: 'KERBEROS_CLIENT',
  23. ignore: undefined,
  24. heartBeatLostHosts: [],
  25. commands: ['installKerberos', 'testKerberos'],
  26. loadStep: function () {
  27. this._super();
  28. this.enableDisablePreviousSteps();
  29. },
  30. clearStep: function() {
  31. this.get('heartBeatLostHosts').clear();
  32. this._super();
  33. },
  34. installKerberos: function() {
  35. var self = this;
  36. this.getKerberosClientState().done(function(data) {
  37. if (data.ServiceComponentInfo.state === 'INIT') {
  38. App.ajax.send({
  39. name: 'common.services.update',
  40. sender: self,
  41. data: {
  42. context: Em.I18n.t('requestInfo.kerberosService'),
  43. ServiceInfo: {"state": "INSTALLED"},
  44. urlParams: "ServiceInfo/state=INSTALLED&ServiceInfo/service_name=KERBEROS"
  45. },
  46. success: 'startPolling',
  47. error: 'onTaskError'
  48. });
  49. } else {
  50. var hostNames = App.get('allHostNames');
  51. self.updateComponent('KERBEROS_CLIENT', hostNames, "KERBEROS", "Install");
  52. }
  53. });
  54. },
  55. /**
  56. * Get hosts with HEARTBEAT_LOST state.
  57. *
  58. * @return {$.Deferred.promise} promise
  59. */
  60. getHeartbeatLostHosts: function() {
  61. return App.ajax.send({
  62. name: 'hosts.heartbeat_lost',
  63. sender: this,
  64. data: {
  65. clusterName: App.get('clusterName')
  66. }
  67. });
  68. },
  69. getKerberosClientState: function() {
  70. return App.ajax.send({
  71. name: 'common.service_component.info',
  72. sender: this,
  73. data: {
  74. serviceName: this.get('serviceName'),
  75. componentName: this.get('componentName'),
  76. urlParams: "fields=ServiceComponentInfo/state"
  77. }
  78. });
  79. },
  80. testKerberos: function() {
  81. var self = this;
  82. App.ajax.send({
  83. 'name': 'service.item.smoke',
  84. 'sender': this,
  85. 'success': 'startPolling',
  86. 'error': 'onTestKerberosError',
  87. 'kdcCancelHandler': function() {
  88. App.router.get(self.get('content.controllerName')).setStepsEnable();
  89. self.get('tasks').objectAt(self.get('currentTaskId')).set('status', 'FAILED');
  90. },
  91. 'data': {
  92. 'serviceName': this.serviceName,
  93. 'displayName': App.format.role(this.serviceName, true),
  94. 'actionName': this.serviceName + '_SERVICE_CHECK',
  95. 'operationLevel': {
  96. "level": "CLUSTER",
  97. "cluster_name": App.get('clusterName')
  98. }
  99. }
  100. });
  101. },
  102. onTestKerberosError: function (jqXHR, ajaxOptions, error, opt) {
  103. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  104. this.onTaskError(jqXHR, ajaxOptions, error, opt);
  105. },
  106. /**
  107. * Enable or disable previous steps according to tasks statuses
  108. */
  109. enableDisablePreviousSteps: function () {
  110. var wizardController = App.router.get(this.get('content.controllerName'));
  111. if (this.get('tasks').someProperty('status', 'FAILED')) {
  112. wizardController.setStepsEnable();
  113. } else {
  114. wizardController.setLowerStepsDisable(3);
  115. }
  116. }.observes('tasks.@each.status'),
  117. /**
  118. * Show or hide warning to ignore errors and continue with the install
  119. */
  120. showIgnore: Em.computed.someBy('tasks', 'showRetry', true),
  121. /**
  122. * Enable or disable next button if ignore checkbox ticked
  123. */
  124. ignoreAndProceed: function() {
  125. if (this.get('showIgnore')) {
  126. this.set('isSubmitDisabled', !this.get('ignore'));
  127. }
  128. }.observes('ignore', 'showIgnore'),
  129. retryTask: function() {
  130. this._super();
  131. // retry from the first task (installKerberos) if there is any host in HEARTBEAT_LOST state.
  132. if (this.get('heartBeatLostHosts').length) {
  133. this.get('tasks').setEach('status', 'PENDING');
  134. this.get('tasks').setEach('showRetry', false);
  135. this.get('heartBeatLostHosts').clear();
  136. }
  137. },
  138. /**
  139. * Check for complete status and determines:
  140. * - if there are any hosts in HEARTBEAT_LOST state. In this case warn about hosts and make step FAILED.
  141. *
  142. * @return {undefined}
  143. */
  144. statusDidChange: function() {
  145. var self = this;
  146. if (this.get('completedStatuses').contains(this.get('status'))) {
  147. this.getHeartbeatLostHosts().then(function(data) {
  148. var hostNames = Em.getWithDefault(data || {}, 'items', []).mapProperty('Hosts.host_name');
  149. if (hostNames.length) {
  150. self.set('heartBeatLostHosts', hostNames.uniq());
  151. self.get('tasks').objectAt(0).set('status', 'FAILED');
  152. }
  153. });
  154. }
  155. }.observes('status')
  156. });