add_controller.js 19 KB

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