item.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.MainServiceItemController = Em.Controller.extend({
  20. name: 'mainServiceItemController',
  21. isAdmin: function(){
  22. return App.db.getUser().admin;
  23. }.property('App.router.loginController.loginName'),
  24. /**
  25. * Send specific command to server
  26. * @param url
  27. * @param data Object to send
  28. */
  29. sendCommandToServer : function(url, method, postData, callback){
  30. var url = (App.testMode) ?
  31. '/data/wizard/deploy/poll_1.json' : //content is the same as ours
  32. App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
  33. method = App.testMode ? 'GET' : method;
  34. $.ajax({
  35. type: method,
  36. url: url,
  37. data: (postData != null) ? JSON.stringify(postData) : null,
  38. dataType: 'json',
  39. timeout: App.timeout,
  40. success: function(data){
  41. if(data && data.Requests){
  42. callback(data.Requests.id);
  43. } else{
  44. callback(null);
  45. console.log('cannot get request id from ', data);
  46. }
  47. },
  48. error: function (request, ajaxOptions, error) {
  49. //do something
  50. callback(null);
  51. console.log('error on change component host status')
  52. },
  53. statusCode: require('data/statusCodes')
  54. });
  55. },
  56. /**
  57. * On click callback for <code>start service</code> button
  58. * @param event
  59. */
  60. startService: function (event) {
  61. if($(event.target).hasClass('disabled')){
  62. return;
  63. }
  64. var self = this;
  65. App.ModalPopup.show({
  66. header: Em.I18n.t('services.service.confirmation.header'),
  67. body: Em.I18n.t('services.service.confirmation.body'),
  68. primary: 'Yes',
  69. secondary: 'No',
  70. onPrimary: function () {
  71. self.sendCommandToServer('/services/' + self.get('content.serviceName').toUpperCase(), "PUT", {
  72. ServiceInfo: {
  73. state: 'STARTED'
  74. }
  75. }, function (requestId) {
  76. if (!requestId) {
  77. return;
  78. }
  79. console.log('Send request for STARTING successfully');
  80. if (App.testMode) {
  81. self.content.set('workStatus', App.Service.Health.starting);
  82. setTimeout(function () {
  83. self.content.set('workStatus', App.Service.Health.live);
  84. }, 10000);
  85. } else {
  86. App.router.get('clusterController').loadUpdatedStatus();
  87. App.router.get('backgroundOperationsController.eventsArray').push({
  88. "when": function (controller) {
  89. var result = (controller.getOperationsForRequestId(requestId).length == 0);
  90. console.log('startService.when = ', result)
  91. return result;
  92. },
  93. "do": function () {
  94. App.router.get('clusterController').loadUpdatedStatus();
  95. }
  96. });
  97. }
  98. App.router.get('backgroundOperationsController').showPopup();
  99. });
  100. this.hide();
  101. },
  102. onSecondary: function() {
  103. this.hide();
  104. }
  105. });
  106. },
  107. /**
  108. * On click callback for <code>stop service</code> button
  109. * @param event
  110. */
  111. stopService: function (event) {
  112. if($(event.target).hasClass('disabled')){
  113. return;
  114. }
  115. var self = this;
  116. App.ModalPopup.show({
  117. header: Em.I18n.t('services.service.confirmation.header'),
  118. body: Em.I18n.t('services.service.confirmation.body'),
  119. primary: 'Yes',
  120. secondary: 'No',
  121. onPrimary: function() {
  122. self.sendCommandToServer('/services/' + self.get('content.serviceName').toUpperCase(), "PUT",{
  123. ServiceInfo:{
  124. state: 'INSTALLED'
  125. }
  126. }, function (requestId) {
  127. if (!requestId) {
  128. return
  129. }
  130. console.log('Send request for STOPPING successfully');
  131. if (App.testMode) {
  132. self.content.set('workStatus', App.Service.Health.stopping);
  133. setTimeout(function () {
  134. self.content.set('workStatus', App.Service.Health.dead);
  135. }, 10000);
  136. } else {
  137. App.router.get('clusterController').loadUpdatedStatus();
  138. App.router.get('backgroundOperationsController.eventsArray').push({
  139. "when": function (controller) {
  140. var result = (controller.getOperationsForRequestId(requestId).length == 0);
  141. console.log('stopService.when = ', result)
  142. return result;
  143. },
  144. "do": function () {
  145. App.router.get('clusterController').loadUpdatedStatus();
  146. }
  147. });
  148. }
  149. App.router.get('backgroundOperationsController').showPopup();
  150. });
  151. this.hide();
  152. },
  153. onSecondary: function () {
  154. this.hide();
  155. }
  156. });
  157. },
  158. runRebalancer: function (event) {
  159. var self = this;
  160. App.ModalPopup.show({
  161. header: Em.I18n.t('services.service.confirmation.header'),
  162. body: Em.I18n.t('services.service.confirmation.body'),
  163. primary: 'Yes',
  164. secondary: 'No',
  165. onPrimary: function() {
  166. self.content.set('runRebalancer', true);
  167. App.router.get('backgroundOperationsController').showPopup();
  168. this.hide();
  169. },
  170. onSecondary: function() {
  171. this.hide();
  172. }
  173. });
  174. },
  175. runCompaction: function (event) {
  176. var self = this;
  177. App.ModalPopup.show({
  178. header: Em.I18n.t('services.service.confirmation.header'),
  179. body: Em.I18n.t('services.service.confirmation.body'),
  180. primary: 'Yes',
  181. secondary: 'No',
  182. onPrimary: function() {
  183. self.content.set('runCompaction', true);
  184. App.router.get('backgroundOperationsController').showPopup();
  185. this.hide();
  186. },
  187. onSecondary: function() {
  188. this.hide();
  189. }
  190. });
  191. },
  192. runSmokeTest: function (event) {
  193. var self = this;
  194. App.ModalPopup.show({
  195. header: Em.I18n.t('services.service.confirmation.header'),
  196. body: Em.I18n.t('services.service.confirmation.body'),
  197. primary: 'Yes',
  198. secondary: 'No',
  199. onPrimary: function() {
  200. var serviceName = self.get('content.serviceName').toUpperCase();
  201. var smokeName = serviceName + "_SERVICE_CHECK";
  202. self.sendCommandToServer('/services/' + serviceName + '/actions/' + smokeName, "POST",
  203. null,
  204. function (requestId) {
  205. if (!requestId) {
  206. return;
  207. }
  208. self.content.set('runSmokeTest', true);
  209. App.router.get('backgroundOperationsController').showPopup();
  210. }
  211. );
  212. this.hide();
  213. },
  214. onSecondary: function () {
  215. this.hide();
  216. }
  217. });
  218. },
  219. doAction: function (event) {
  220. var methodName = event.context;
  221. switch (methodName) {
  222. case 'runRebalancer':
  223. this.runRebalancer();
  224. break;
  225. case 'runCompaction':
  226. this.runCompaction();
  227. break;
  228. case 'runSmokeTest':
  229. this.runSmokeTest();
  230. break;
  231. }
  232. }
  233. })