add_controller.js 15 KB

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