add_controller.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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.AddServiceController = App.WizardController.extend({
  20. name: 'addServiceController',
  21. serviceConfigs:require('data/service_configs'),
  22. totalSteps: 7,
  23. /**
  24. * Used for hiding back button in wizard
  25. */
  26. hideBackButton: true,
  27. /**
  28. * All wizards data will be stored in this variable
  29. *
  30. * cluster - cluster name
  31. * installOptions - ssh key, repo info, etc.
  32. * services - services list
  33. * hosts - list of selected hosts
  34. * slaveComponentHosts, - info about slave hosts
  35. * masterComponentHosts - info about master hosts
  36. * config??? - to be described later
  37. */
  38. content: Em.Object.create({
  39. cluster: null,
  40. hosts: null,
  41. installOptions: null,
  42. services: null,
  43. slaveComponentHosts: null,
  44. masterComponentHosts: null,
  45. serviceConfigProperties: null,
  46. advancedServiceConfig: null,
  47. controllerName: 'addServiceController',
  48. configGroups: []
  49. }),
  50. setCurrentStep: function (currentStep, completed) {
  51. this._super(currentStep, completed);
  52. App.clusterStatus.setClusterStatus({
  53. wizardControllerName: this.get('name'),
  54. localdb: App.db.data
  55. });
  56. },
  57. /**
  58. * return new object extended from clusterStatusTemplate
  59. * @return Object
  60. */
  61. getCluster: function(){
  62. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  63. },
  64. /**
  65. * Load confirmed hosts.
  66. * Will be used at <code>Assign Masters(step5)</code> step
  67. */
  68. loadConfirmedHosts: function(){
  69. var hosts = this.getDBProperty('hosts');
  70. if(!hosts){
  71. var hosts = {};
  72. App.Host.find().forEach(function(item){
  73. hosts[item.get('id')] = {
  74. name: item.get('id'),
  75. cpu: item.get('cpu'),
  76. memory: item.get('memory'),
  77. disk_info: item.get('diskInfo'),
  78. bootStatus: "REGISTERED",
  79. isInstalled: true
  80. };
  81. });
  82. this.setDBProperty('hosts', hosts);
  83. }
  84. this.set('content.hosts', hosts);
  85. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  86. },
  87. /**
  88. * Load services data from server.
  89. */
  90. loadServicesFromServer: function() {
  91. if(this.getDBProperty('service')){
  92. return;
  93. }
  94. var apiService = this.loadServiceComponents();
  95. //
  96. apiService.forEach(function(item, index){
  97. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  98. apiService[index].isDisabled = apiService[index].isSelected;
  99. apiService[index].isInstalled = apiService[index].isSelected;
  100. });
  101. this.set('content.services', apiService);
  102. this.setDBProperty('service', apiService);
  103. },
  104. /**
  105. * Load services data. Will be used at <code>Select services(step4)</code> step
  106. */
  107. loadServices: function () {
  108. var servicesInfo = this.getDBProperty('service');
  109. servicesInfo.forEach(function (item, index) {
  110. servicesInfo[index] = Em.Object.create(item);
  111. });
  112. this.set('content.services', servicesInfo);
  113. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  114. var serviceNames = servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  115. console.log('selected services ', serviceNames);
  116. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE') && !serviceNames.contains('STORM') && !serviceNames.contains('YARN'));
  117. if (this.get('content.skipSlavesStep')) {
  118. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  119. }
  120. },
  121. /**
  122. * Save data to model
  123. * @param stepController App.WizardStep4Controller
  124. */
  125. saveServices: function (stepController) {var serviceNames = [];
  126. this.setDBProperty('service', stepController.get('content'));
  127. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  128. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  129. serviceNames.push(item.serviceName);
  130. });
  131. this.set('content.selectedServiceNames', serviceNames);
  132. this.setDBProperty('selectedServiceNames',serviceNames);
  133. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  134. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE') && !serviceNames.contains('STORM') && !serviceNames.contains('YARN'));
  135. if (this.get('content.skipSlavesStep')) {
  136. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  137. }
  138. },
  139. /**
  140. * Save Master Component Hosts data to Main Controller
  141. * @param stepController App.WizardStep5Controller
  142. */
  143. saveMasterComponentHosts: function (stepController) {
  144. var obj = stepController.get('selectedServicesMasters');
  145. var masterComponentHosts = [];
  146. var installedComponents = App.HostComponent.find();
  147. obj.forEach(function (_component) {
  148. masterComponentHosts.push({
  149. display_name: _component.display_name,
  150. component: _component.component_name,
  151. hostName: _component.selectedHost,
  152. serviceId: _component.serviceId,
  153. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  154. });
  155. });
  156. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  157. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  158. this.set('content.masterComponentHosts', masterComponentHosts);
  159. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  160. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  161. },
  162. /**
  163. * Load master component hosts data for using in required step controllers
  164. */
  165. loadMasterComponentHosts: function () {
  166. this._super();
  167. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  168. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  169. },
  170. /**
  171. * Does service have any configs
  172. * @param {string} serviceName
  173. * @returns {boolean}
  174. */
  175. isServiceConfigurable: function(serviceName) {
  176. return this.get('serviceConfigs').mapProperty('serviceName').contains(serviceName);
  177. },
  178. /**
  179. * Should Config Step be skipped (based on selected services list)
  180. * @returns {boolean}
  181. */
  182. skipConfigStep: function() {
  183. var skipConfigStep = true;
  184. var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  185. selectedServices.map(function(serviceName) {
  186. skipConfigStep = skipConfigStep && !this.isServiceConfigurable(serviceName);
  187. }, this);
  188. return skipConfigStep;
  189. },
  190. loadServiceConfigProperties: function() {
  191. this._super();
  192. if (!this.get('content.services')) {
  193. this.loadServices();
  194. }
  195. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  196. this.set('content.skipConfigStep', this.skipConfigStep());
  197. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  198. }
  199. },
  200. saveServiceConfigProperties: function(stepController) {
  201. this._super(stepController);
  202. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  203. this.set('content.skipConfigStep', this.skipConfigStep());
  204. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  205. }
  206. },
  207. /**
  208. * Load master component hosts data for using in required step controllers
  209. */
  210. loadSlaveComponentHosts: function () {
  211. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts');
  212. if(!slaveComponentHosts){
  213. slaveComponentHosts = this.getSlaveComponentHosts();
  214. }
  215. this.set("content.slaveComponentHosts", slaveComponentHosts);
  216. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  217. },
  218. /**
  219. * Generate clients list for selected services and save it to model
  220. * @param stepController step4WizardController
  221. */
  222. saveClients: function(stepController){
  223. var clients = [];
  224. var serviceComponents = App.StackServiceComponent.find();
  225. var hostComponents = App.HostComponent.find();
  226. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  227. var client = serviceComponents.filterProperty('serviceName', _service.serviceName).findProperty('isClient', true);
  228. if (client) {
  229. clients.pushObject({
  230. component_name: client.get('componentName'),
  231. display_name: client.get('displayName'),
  232. isInstalled: hostComponents.filterProperty('componentName', client.get('componentName')).length > 0
  233. });
  234. }
  235. }, this);
  236. this.setDBProperty('clientInfo', clients);
  237. this.set('content.clients', clients);
  238. console.log("AddServiceController.saveClients: saved list ", clients);
  239. },
  240. /**
  241. * Load data for all steps until <code>current step</code>
  242. */
  243. loadAllPriorSteps: function () {
  244. var step = this.get('currentStep');
  245. switch (step) {
  246. case '7':
  247. case '6':
  248. case '5':
  249. this.load('cluster');
  250. case '4':
  251. this.loadServiceConfigGroups();
  252. this.loadServiceConfigProperties();
  253. case '3':
  254. this.loadServices();
  255. this.loadClients();
  256. this.loadSlaveComponentHosts();//depends on loadServices
  257. case '2':
  258. this.loadMasterComponentHosts();
  259. this.loadConfirmedHosts();
  260. case '1':
  261. this.loadServices();
  262. }
  263. },
  264. /**
  265. * Remove all loaded data.
  266. * Created as copy for App.router.clearAllSteps
  267. */
  268. clearAllSteps: function () {
  269. this.clearInstallOptions();
  270. // clear temporary information stored during the install
  271. this.set('content.cluster', this.getCluster());
  272. },
  273. /**
  274. * Clear all temporary data
  275. */
  276. finish: function () {
  277. this.setCurrentStep('1');
  278. this.clearAllSteps();
  279. this.clearStorageData();
  280. App.router.get('updateController').updateAll();
  281. },
  282. installServices: function (isRetry) {
  283. this.set('content.cluster.oldRequestsId', []);
  284. var clusterName = this.get('content.cluster.name');
  285. var data;
  286. var name;
  287. if (isRetry) {
  288. this.getFailedHostComponents();
  289. console.log('failedHostComponents', this.get('failedHostComponents'));
  290. name = 'wizard.install_services.installer_controller.is_retry';
  291. data = {
  292. "RequestInfo": {
  293. "context" : Em.I18n.t('requestInfo.installComponents'),
  294. "query": "HostRoles/component_name.in(" + this.get('failedHostComponents').join(',') + ")"
  295. },
  296. "Body": {
  297. "HostRoles": {
  298. "state": "INSTALLED"
  299. }
  300. }
  301. };
  302. data = JSON.stringify(data);
  303. }
  304. else {
  305. name = 'wizard.install_services.installer_controller.not_is_retry';
  306. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  307. }
  308. App.ajax.send({
  309. name: name,
  310. sender: this,
  311. data: {
  312. data: data,
  313. cluster: clusterName
  314. },
  315. success: 'installServicesSuccessCallback',
  316. error: 'installServicesErrorCallback'
  317. });
  318. },
  319. /**
  320. * List of failed to install HostComponents while adding Service
  321. */
  322. failedHostComponents: [],
  323. getFailedHostComponents: function() {
  324. App.ajax.send({
  325. name: 'wizard.install_services.add_service_controller.get_failed_host_components',
  326. sender: this,
  327. success: 'getFailedHostComponentsSuccessCallback',
  328. error: 'getFailedHostComponentsErrorCallback'
  329. });
  330. },
  331. /**
  332. * Parse all failed components and filter out installed earlier components (based on selected to install services)
  333. * @param {Object} json
  334. */
  335. getFailedHostComponentsSuccessCallback: function(json) {
  336. var allFailed = json.items.filterProperty('HostRoles.state', 'INSTALL_FAILED');
  337. var currentFailed = [];
  338. var selectedServices = this.getDBProperty('service').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  339. allFailed.forEach(function(failed) {
  340. if (selectedServices.contains(failed.component[0].ServiceComponentInfo.service_name)) {
  341. currentFailed.push(failed.HostRoles.component_name);
  342. }
  343. });
  344. this.set('failedHostComponents', currentFailed);
  345. },
  346. getFailedHostComponentsErrorCallback: function(request, ajaxOptions, error) {
  347. console.warn(error);
  348. }
  349. });