add_controller.js 17 KB

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