add_controller.js 17 KB

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