add_controller.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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.AddHostController = App.WizardController.extend({
  20. name: 'addHostController',
  21. totalSteps: 7,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. /**
  27. * All wizards data will be stored in this variable
  28. *
  29. * cluster - cluster name
  30. * hosts - hosts, ssh key, repo info, etc.
  31. * services - services list
  32. * hostsInfo - list of selected hosts
  33. * slaveComponentHosts, hostSlaveComponents - info about slave hosts
  34. * masterComponentHosts - info about master hosts
  35. * config??? - to be described later
  36. */
  37. content: Em.Object.create({
  38. cluster: null,
  39. hosts: null,
  40. installOptions: null,
  41. services: null,
  42. slaveComponentHosts: null,
  43. masterComponentHosts: null,
  44. serviceConfigProperties: null,
  45. advancedServiceConfig: null,
  46. controllerName: 'addHostController',
  47. isWizard: true
  48. }),
  49. components:require('data/service_components'),
  50. /**
  51. * return new object extended from clusterStatusTemplate
  52. * @return Object
  53. */
  54. getCluster: function(){
  55. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  56. },
  57. /**
  58. * return new object extended from installOptionsTemplate
  59. * @return Object
  60. */
  61. getInstallOptions: function(){
  62. return jQuery.extend({}, this.get('installOptionsTemplate'));
  63. },
  64. /**
  65. * return empty hosts array
  66. * @return Array
  67. */
  68. getHosts: function(){
  69. return [];
  70. },
  71. /**
  72. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  73. * @param hosts Array of hosts, which we want to delete
  74. */
  75. removeHosts: function (hosts) {
  76. //todo Replace this code with real logic
  77. App.db.removeHosts(hosts);
  78. },
  79. /**
  80. * Save data, which user filled, to main controller
  81. * @param stepController App.WizardStep3Controller
  82. */
  83. saveConfirmedHosts: function (stepController) {
  84. var hostInfo = {};
  85. stepController.get('content.hosts').forEach(function (_host) {
  86. hostInfo[_host.name] = {
  87. name: _host.name,
  88. cpu: _host.cpu,
  89. memory: _host.memory,
  90. disk_info: _host.disk_info,
  91. bootStatus: _host.bootStatus,
  92. isInstalled: false
  93. };
  94. });
  95. console.log('addHostController:saveConfirmedHosts: save hosts ', hostInfo);
  96. App.db.setHosts(hostInfo);
  97. this.set('content.hosts', hostInfo);
  98. },
  99. /**
  100. * Save data after installation to main controller
  101. * @param stepController App.WizardStep9Controller
  102. */
  103. saveInstalledHosts: function (stepController) {
  104. var hosts = stepController.get('hosts');
  105. var hostInfo = App.db.getHosts();
  106. for (var index in hostInfo) {
  107. var host = hosts.findProperty('name', hostInfo[index].name);
  108. if (host) {
  109. hostInfo[index].status = host.status;
  110. //tasks should be empty because they loads from the server
  111. //hostInfo[index].tasks = host.tasks;
  112. hostInfo[index].message = host.message;
  113. hostInfo[index].progress = host.progress;
  114. }
  115. }
  116. App.db.setHosts(hostInfo);
  117. this.set('content.hosts', hostInfo);
  118. console.log('addHostController:saveInstalledHosts: save hosts ', hostInfo);
  119. },
  120. /**
  121. * Load services data from server.
  122. */
  123. loadServicesFromServer: function() {
  124. var displayOrderConfig = require('data/services');
  125. var apiUrl = App.get('stackVersionURL');
  126. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  127. //
  128. apiService.forEach(function(item, index){
  129. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  130. apiService[index].isDisabled = apiService[index].isSelected;
  131. apiService[index].isInstalled = apiService[index].isSelected;
  132. });
  133. this.set('content.services', apiService);
  134. App.db.setService(apiService);
  135. },
  136. /**
  137. * Load services data. Will be used at <code>Select services(step4)</code> step
  138. */
  139. loadServices: function () {
  140. var servicesInfo = App.db.getService();
  141. servicesInfo.forEach(function (item, index) {
  142. servicesInfo[index] = Em.Object.create(item);
  143. });
  144. this.set('content.services', servicesInfo);
  145. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  146. var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  147. console.log('selected services ', serviceNames);
  148. this.set('content.missMasterStep', !serviceNames.contains('HBASE') && !serviceNames.contains('ZOOKEEPER'));
  149. },
  150. /**
  151. * Load master component hosts data for using in required step controllers
  152. */
  153. loadMasterComponentHosts: function () {
  154. var masterComponentHosts = App.db.getMasterComponentHosts();
  155. if (!masterComponentHosts) {
  156. masterComponentHosts = [];
  157. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  158. masterComponentHosts.push({
  159. component: item.get('componentName'),
  160. hostName: item.get('host.hostName'),
  161. isInstalled: true,
  162. serviceId: item.get('service.id'),
  163. display_name: item.get('displayName')
  164. })
  165. });
  166. App.db.setMasterComponentHosts(masterComponentHosts);
  167. }
  168. this.set("content.masterComponentHosts", masterComponentHosts);
  169. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  170. },
  171. /**
  172. * Save HBase and ZooKeeper to main controller
  173. * @param stepController
  174. */
  175. saveHbZk: function(stepController) {
  176. var self = this;
  177. var hosts = stepController.get('hosts');
  178. var headers = stepController.get('headers');
  179. var masterComponentHosts = App.db.getMasterComponentHosts();
  180. headers.forEach(function(header) {
  181. var rm = masterComponentHosts.filterProperty('component', header.get('name'));
  182. if(rm) {
  183. masterComponentHosts.removeObjects(rm);
  184. }
  185. });
  186. headers.forEach(function(header) {
  187. var component = self.get('components').findProperty('component_name', header.get('name'));
  188. hosts.forEach(function(host) {
  189. if (host.get('checkboxes').findProperty('title', component.display_name).checked) {
  190. masterComponentHosts .push({
  191. display_name: component.display_name,
  192. component: component.component_name,
  193. hostName: host.get('hostName'),
  194. serviceId: component.service_name,
  195. isInstalled: false
  196. });
  197. }
  198. });
  199. });
  200. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  201. App.db.setMasterComponentHosts(masterComponentHosts);
  202. this.set('content.masterComponentHosts', masterComponentHosts);
  203. },
  204. /**
  205. * Save slaveHostComponents to main controller
  206. * @param stepController
  207. */
  208. saveSlaveComponentHosts: function (stepController) {
  209. var hosts = stepController.get('hosts');
  210. var headers = stepController.get('headers');
  211. var formattedHosts = Ember.Object.create();
  212. headers.forEach(function(header) {
  213. formattedHosts.set(header.get('name'), []);
  214. });
  215. hosts.forEach(function (host) {
  216. var checkboxes = host.get('checkboxes');
  217. headers.forEach(function(header) {
  218. var cb = checkboxes.findProperty('title', header.get('label'));
  219. if (cb.get('checked')) {
  220. formattedHosts.get(header.get('name')).push({
  221. hostName: host.hostName,
  222. group: 'Default',
  223. isInstalled: cb.get('installed')
  224. });
  225. }
  226. });
  227. });
  228. var slaveComponentHosts = [];
  229. headers.forEach(function(header) {
  230. slaveComponentHosts.push({
  231. componentName: header.get('name'),
  232. displayName: header.get('label').replace(/\s/g, ''),
  233. hosts: formattedHosts.get(header.get('name'))
  234. });
  235. });
  236. App.db.setSlaveComponentHosts(slaveComponentHosts);
  237. console.log('addHostController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  238. this.set('content.slaveComponentHosts', slaveComponentHosts);
  239. },
  240. /**
  241. * return slaveComponents bound to hosts
  242. * @return {Array}
  243. */
  244. getSlaveComponentHosts: function () {
  245. var components = [
  246. {
  247. name: 'DATANODE',
  248. service: 'HDFS'
  249. },
  250. {
  251. name: 'TASKTRACKER',
  252. service: 'MAPREDUCE'
  253. },
  254. {
  255. name: 'HBASE_REGIONSERVER',
  256. service: 'HBASE'
  257. }
  258. ];
  259. var result = [];
  260. var services = App.Service.find();
  261. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  262. for (var index = 0; index < components.length; index++) {
  263. var comp = components[index];
  264. if (!selectedServices.contains(comp.service)) {
  265. continue;
  266. }
  267. var service = services.findProperty('id', comp.service);
  268. var hosts = [];
  269. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  270. hosts.push({
  271. group: "Default",
  272. hostName: host_component.get('host.id'),
  273. isInstalled: true
  274. });
  275. }, this);
  276. result.push({
  277. componentName: comp.name,
  278. displayName: App.format.role(comp.name),
  279. hosts: hosts,
  280. isInstalled: true
  281. })
  282. }
  283. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  284. var hosts = [];
  285. clientsHosts.forEach(function (host_component) {
  286. hosts.push({
  287. group: "Default",
  288. hostName: host_component.get('host.id'),
  289. isInstalled: true
  290. });
  291. }, this);
  292. result.push({
  293. componentName: 'CLIENT',
  294. displayName: 'client',
  295. hosts: hosts,
  296. isInstalled: true
  297. })
  298. return result;
  299. },
  300. /**
  301. * Load master component hosts data for using in required step controllers
  302. */
  303. loadSlaveComponentHosts: function () {
  304. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  305. if (!slaveComponentHosts) {
  306. slaveComponentHosts = this.getSlaveComponentHosts();
  307. }
  308. this.set("content.slaveComponentHosts", slaveComponentHosts);
  309. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  310. },
  311. /**
  312. * Save config properties
  313. * @param stepController Step7WizardController
  314. */
  315. saveServiceConfigProperties: function (stepController) {
  316. var serviceConfigProperties = [];
  317. stepController.get('stepConfigs').forEach(function (_content) {
  318. _content.get('configs').forEach(function (_configProperties) {
  319. var displayType = _configProperties.get('displayType');
  320. if (displayType === 'directories' || displayType === 'directory') {
  321. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  322. _configProperties.set('value', value);
  323. }
  324. var configProperty = {
  325. id: _configProperties.get('id'),
  326. name: _configProperties.get('name'),
  327. value: _configProperties.get('value'),
  328. defaultValue: _configProperties.get('defaultValue'),
  329. service: _configProperties.get('serviceName'),
  330. domain: _configProperties.get('domain'),
  331. filename: _configProperties.get('filename')
  332. };
  333. serviceConfigProperties.push(configProperty);
  334. }, this);
  335. }, this);
  336. App.db.setServiceConfigProperties(serviceConfigProperties);
  337. this.set('content.serviceConfigProperties', serviceConfigProperties);
  338. //TODO: Uncomment below code to enable slave Configuration
  339. /*var slaveConfigProperties = [];
  340. stepController.get('stepConfigs').forEach(function (_content) {
  341. if (_content.get('configCategories').someProperty('isForSlaveComponent', true)) {
  342. var slaveCategory = _content.get('configCategories').findProperty('isForSlaveComponent', true);
  343. slaveCategory.get('slaveConfigs.groups').forEach(function (_group) {
  344. _group.get('properties').forEach(function (_property) {
  345. var displayType = _property.get('displayType');
  346. if (displayType === 'directories' || displayType === 'directory') {
  347. var value = _property.get('value').trim().split(/\s+/g).join(',');
  348. _property.set('value', value);
  349. }
  350. _property.set('storeValue', _property.get('value'));
  351. }, this);
  352. }, this);
  353. slaveConfigProperties.pushObject(slaveCategory.get('slaveConfigs'));
  354. }
  355. }, this);
  356. App.db.setSlaveProperties(slaveConfigProperties);
  357. this.set('content.slaveGroupProperties', slaveConfigProperties);*/
  358. },
  359. /**
  360. * Load serviceConfigProperties to model
  361. */
  362. loadServiceConfigProperties: function () {
  363. var serviceConfigProperties = App.db.getServiceConfigProperties();
  364. this.set('content.serviceConfigProperties', serviceConfigProperties);
  365. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  366. },
  367. /**
  368. * Load information about hosts with clients components
  369. */
  370. loadClients: function () {
  371. var clients = App.db.getClientsForSelectedServices();
  372. this.set('content.clients', clients);
  373. console.log("AddHostController.loadClients: loaded list ", clients);
  374. },
  375. /**
  376. * return true if cluster data is loaded and false otherwise
  377. */
  378. dataLoading: function () {
  379. var dfd = $.Deferred();
  380. this.connectOutlet('loading');
  381. var interval = setInterval(function () {
  382. if (App.router.get('clusterController.isLoaded')) {
  383. dfd.resolve();
  384. clearInterval(interval);
  385. }
  386. }, 50);
  387. return dfd.promise();
  388. },
  389. /**
  390. * Generate clients list for selected services and save it to model
  391. * @param stepController step4WizardController
  392. */
  393. saveClients: function () {
  394. var clients = [];
  395. var serviceComponents = require('data/service_components');
  396. var hostComponents = App.HostComponent.find();
  397. this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) {
  398. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  399. if (client) {
  400. clients.pushObject({
  401. component_name: client.component_name,
  402. display_name: client.display_name,
  403. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  404. });
  405. }
  406. }, this);
  407. App.db.setClientsForSelectedServices(clients);
  408. this.set('content.clients', clients);
  409. console.log("AddHostController.saveClients: saved list ", clients);
  410. },
  411. /**
  412. * Load data for all steps until <code>current step</code>
  413. */
  414. loadAllPriorSteps: function () {
  415. var step = this.get('currentStep');
  416. switch (step) {
  417. case '9':
  418. case '8':
  419. case '7':
  420. case '6':
  421. case '5':
  422. this.loadServiceConfigProperties();
  423. case '4':
  424. case '3':
  425. this.loadClients();
  426. this.loadServices();
  427. this.loadMasterComponentHosts();
  428. this.loadSlaveComponentHosts();
  429. this.load('hosts');
  430. case '2':
  431. this.loadServices();
  432. case '1':
  433. this.load('hosts');
  434. this.load('installOptions');
  435. this.load('cluster');
  436. }
  437. },
  438. /**
  439. * load advanced configs for all selected services
  440. */
  441. loadAdvancedConfigs: function () {
  442. this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName').forEach(function (_serviceName) {
  443. this.loadAdvancedConfig(_serviceName);
  444. }, this);
  445. },
  446. /**
  447. * load advanced config for one service
  448. * @param serviceName
  449. */
  450. loadAdvancedConfig: function (serviceName) {
  451. var self = this;
  452. var url = (App.testMode) ? '/data/wizard/stack/hdp/version01/' + serviceName + '.json' : App.apiPrefix + '/stacks/HDP/version/1.2.0/services/' + serviceName; // TODO: get this url from the stack selected by the user in Install Options page
  453. var method = 'GET';
  454. $.ajax({
  455. type: method,
  456. url: url,
  457. async: false,
  458. dataType: 'text',
  459. timeout: App.timeout,
  460. success: function (data) {
  461. var jsonData = jQuery.parseJSON(data);
  462. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  463. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  464. var serviceComponents = jsonData.properties;
  465. serviceComponents.setEach('serviceName', serviceName);
  466. var configs;
  467. if (App.db.getAdvancedServiceConfig()) {
  468. configs = App.db.getAdvancedServiceConfig();
  469. } else {
  470. configs = [];
  471. }
  472. configs = configs.concat(serviceComponents);
  473. self.set('content.advancedServiceConfig', configs);
  474. App.db.setAdvancedServiceConfig(configs);
  475. console.log('TRACE: servicename: ' + serviceName);
  476. },
  477. error: function (request, ajaxOptions, error) {
  478. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  479. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  480. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  481. console.log('Step6 submit: Error message is: ' + request.responseText);
  482. },
  483. statusCode: require('data/statusCodes')
  484. });
  485. },
  486. /**
  487. * Remove all loaded data.
  488. * Created as copy for App.router.clearAllSteps
  489. */
  490. clearAllSteps: function () {
  491. this.clearInstallOptions();
  492. // clear temporary information stored during the install
  493. this.set('content.cluster', this.getCluster());
  494. },
  495. /**
  496. * Clear all temporary data
  497. */
  498. finish: function () {
  499. this.setCurrentStep('1');
  500. this.clearAllSteps();
  501. this.clearStorageData();
  502. App.router.get('updateController').updateAll();
  503. }
  504. });