add_controller.js 19 KB

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