add_controller.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. * hosts - hosts, ssh key, repo info, etc.
  31. * services - services list
  32. * hostsInfo - 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. services: null,
  41. hostsInfo: 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. bootStatus: "DONE",
  68. isInstalled: true
  69. };
  70. });
  71. App.db.setHosts(hosts);
  72. }
  73. this.set('content.hostsInfo', hosts);
  74. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  75. },
  76. /**
  77. * Save data after installation to main controller
  78. * @param stepController App.WizardStep9Controller
  79. */
  80. saveInstalledHosts: function (stepController) {
  81. var hosts = stepController.get('hosts');
  82. var hostInfo = App.db.getHosts();
  83. for (var index in hostInfo) {
  84. hostInfo[index].status = "pending";
  85. var host = hosts.findProperty('name', hostInfo[index].name);
  86. if (host) {
  87. hostInfo[index].status = host.status;
  88. hostInfo[index].message = host.message;
  89. hostInfo[index].progress = host.progress;
  90. }
  91. }
  92. App.db.setHosts(hostInfo);
  93. this.set('content.hostsInfo', hostInfo);
  94. console.log('AddServiceController:saveInstalledHosts: save hosts ', hostInfo);
  95. },
  96. /**
  97. * Load services data. Will be used at <code>Select services(step4)</code> step
  98. */
  99. loadServices: function () {
  100. var servicesInfo = App.db.getService();
  101. if(!servicesInfo || !servicesInfo.length){
  102. servicesInfo = require('data/services').slice(0);
  103. servicesInfo.forEach(function(item, index){
  104. servicesInfo[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  105. servicesInfo[index].isDisabled = servicesInfo[index].isSelected;
  106. servicesInfo[index].isInstalled = servicesInfo[index].isSelected;
  107. });
  108. }
  109. servicesInfo.forEach(function (item, index) {
  110. servicesInfo[index] = Em.Object.create(item);
  111. });
  112. this.set('content.services', servicesInfo);
  113. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  114. var serviceNames = servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  115. console.log('selected services ', serviceNames);
  116. this.set('content.missSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  117. },
  118. /**
  119. * Save data to model
  120. * @param stepController App.WizardStep4Controller
  121. */
  122. saveServices: function (stepController) {
  123. var serviceNames = [];
  124. App.db.setService(stepController.get('content'));
  125. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  126. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  127. serviceNames.push(item.serviceName);
  128. });
  129. this.set('content.selectedServiceNames', serviceNames);
  130. App.db.setSelectedServiceNames(serviceNames);
  131. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  132. this.set('content.missSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  133. },
  134. /**
  135. * Save Master Component Hosts data to Main Controller
  136. * @param stepController App.WizardStep5Controller
  137. */
  138. saveMasterComponentHosts: function (stepController) {
  139. var obj = stepController.get('selectedServicesMasters');
  140. var masterComponentHosts = [];
  141. var installedComponents = App.Component.find();
  142. obj.forEach(function (_component) {
  143. masterComponentHosts.push({
  144. display_name: _component.display_name,
  145. component: _component.component_name,
  146. hostName: _component.selectedHost,
  147. serviceId: _component.serviceId,
  148. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  149. });
  150. });
  151. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  152. App.db.setMasterComponentHosts(masterComponentHosts);
  153. this.set('content.masterComponentHosts', masterComponentHosts);
  154. this.set('content.missMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  155. },
  156. /**
  157. * Load master component hosts data for using in required step controllers
  158. */
  159. loadMasterComponentHosts: function () {
  160. var masterComponentHosts = App.db.getMasterComponentHosts();
  161. if(!masterComponentHosts){
  162. masterComponentHosts = [];
  163. App.Component.find().filterProperty('isMaster', true).forEach(function(item){
  164. masterComponentHosts.push({
  165. component: item.get('componentName'),
  166. hostName: item.get('host.hostName'),
  167. isInstalled: true
  168. })
  169. });
  170. }
  171. this.set("content.masterComponentHosts", masterComponentHosts);
  172. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  173. this.set('content.missMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  174. },
  175. /**
  176. * Save slaveHostComponents to main controller
  177. * @param stepController
  178. */
  179. saveSlaveComponentHosts: function (stepController) {
  180. var hosts = stepController.get('hosts');
  181. var isMrSelected = stepController.get('isMrSelected');
  182. var isHbSelected = stepController.get('isHbSelected');
  183. var dataNodeHosts = [];
  184. var taskTrackerHosts = [];
  185. var regionServerHosts = [];
  186. var clientHosts = [];
  187. hosts.forEach(function (host) {
  188. if (host.get('isDataNode')) {
  189. dataNodeHosts.push({
  190. hostName: host.hostName,
  191. group: 'Default',
  192. isInstalled: host.get('isDataNodeInstalled')
  193. });
  194. }
  195. if (isMrSelected && host.get('isTaskTracker')) {
  196. taskTrackerHosts.push({
  197. hostName: host.hostName,
  198. group: 'Default',
  199. isInstalled: host.get('isTaskTrackerInstalled')
  200. });
  201. }
  202. if (isHbSelected && host.get('isRegionServer')) {
  203. regionServerHosts.push({
  204. hostName: host.hostName,
  205. group: 'Default',
  206. isInstalled: host.get('isRegionServerInstalled')
  207. });
  208. }
  209. if (host.get('isClient')) {
  210. clientHosts.pushObject({
  211. hostName: host.hostName,
  212. group: 'Default',
  213. isInstalled: host.get('isClientInstalled')
  214. });
  215. }
  216. }, this);
  217. var slaveComponentHosts = [];
  218. slaveComponentHosts.push({
  219. componentName: 'DATANODE',
  220. displayName: 'DataNode',
  221. hosts: dataNodeHosts
  222. });
  223. if (isMrSelected) {
  224. slaveComponentHosts.push({
  225. componentName: 'TASKTRACKER',
  226. displayName: 'TaskTracker',
  227. hosts: taskTrackerHosts
  228. });
  229. }
  230. if (isHbSelected) {
  231. slaveComponentHosts.push({
  232. componentName: 'HBASE_REGIONSERVER',
  233. displayName: 'RegionServer',
  234. hosts: regionServerHosts
  235. });
  236. }
  237. slaveComponentHosts.pushObject({
  238. componentName: 'CLIENT',
  239. displayName: 'client',
  240. hosts: clientHosts
  241. });
  242. App.db.setSlaveComponentHosts(slaveComponentHosts);
  243. console.log('addServiceController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  244. this.set('content.slaveComponentHosts', slaveComponentHosts);
  245. },
  246. /**
  247. * return slaveComponents bound to hosts
  248. * @return {Array}
  249. */
  250. getSlaveComponentHosts: function () {
  251. var components = [{
  252. name : 'DATANODE',
  253. service : 'HDFS'
  254. },
  255. {
  256. name: 'TASKTRACKER',
  257. service: 'MAPREDUCE'
  258. },{
  259. name: 'HBASE_REGIONSERVER',
  260. service: 'HBASE'
  261. }];
  262. var result = [];
  263. var services = App.Service.find();
  264. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  265. for(var index=0; index < components.length; index++){
  266. var comp = components[index];
  267. if(!selectedServices.contains(comp.service)){
  268. continue;
  269. }
  270. var service = services.findProperty('id', comp.service);
  271. var hosts = [];
  272. if(!service){
  273. service = services.findProperty('id', 'HDFS');
  274. service.get('hostComponents').filterProperty('componentName', 'DATANODE').forEach(function (host_component) {
  275. hosts.push({
  276. group: "Default",
  277. hostName: host_component.get('host.id'),
  278. isInstalled: false
  279. });
  280. }, this);
  281. } else {
  282. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  283. hosts.push({
  284. group: "Default",
  285. hostName: host_component.get('host.id'),
  286. isInstalled: true
  287. });
  288. }, this);
  289. }
  290. result.push({
  291. componentName: comp.name,
  292. displayName: App.format.role(comp.name),
  293. hosts: hosts
  294. })
  295. }
  296. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  297. var hosts = [];
  298. clientsHosts.forEach(function (host_component) {
  299. hosts.push({
  300. group: "Default",
  301. hostName: host_component.get('host.id'),
  302. isInstalled: true
  303. });
  304. }, this);
  305. result.push({
  306. componentName: 'CLIENT',
  307. displayName: 'client',
  308. hosts: hosts
  309. })
  310. return result;
  311. },
  312. /**
  313. * Load master component hosts data for using in required step controllers
  314. */
  315. loadSlaveComponentHosts: function () {
  316. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  317. if(!slaveComponentHosts){
  318. slaveComponentHosts = this.getSlaveComponentHosts();
  319. }
  320. this.set("content.slaveComponentHosts", slaveComponentHosts);
  321. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  322. },
  323. /**
  324. * Save config properties
  325. * @param stepController Step7WizardController
  326. */
  327. saveServiceConfigProperties: function (stepController) {
  328. var serviceConfigProperties = [];
  329. stepController.get('stepConfigs').forEach(function (_content) {
  330. _content.get('configs').forEach(function (_configProperties) {
  331. var configProperty = {
  332. name: _configProperties.get('name'),
  333. value: _configProperties.get('value'),
  334. service: _configProperties.get('serviceName')
  335. };
  336. serviceConfigProperties.push(configProperty);
  337. }, this);
  338. }, this);
  339. App.db.setServiceConfigProperties(serviceConfigProperties);
  340. this.set('content.serviceConfigProperties', serviceConfigProperties);
  341. },
  342. /**
  343. * Load serviceConfigProperties to model
  344. */
  345. loadServiceConfigProperties: function () {
  346. var serviceConfigProperties = App.db.getServiceConfigProperties();
  347. this.set('content.serviceConfigProperties', serviceConfigProperties);
  348. console.log("AddServiceController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  349. },
  350. /**
  351. * Load information about hosts with clients components
  352. */
  353. loadClients: function(){
  354. var clients = App.db.getClientsForSelectedServices();
  355. this.set('content.clients', clients);
  356. console.log("AddServiceController.loadClients: loaded list ", clients);
  357. },
  358. dataLoading: function(){
  359. var dfd = $.Deferred();
  360. this.connectOutlet('loading');
  361. if (App.router.get('clusterController.isLoaded')){
  362. dfd.resolve();
  363. } else{
  364. var interval = setInterval(function(){
  365. if (App.router.get('clusterController.isLoaded')){
  366. dfd.resolve();
  367. clearInterval(interval);
  368. }
  369. },50);
  370. }
  371. return dfd.promise();
  372. },
  373. /**
  374. * Generate clients list for selected services and save it to model
  375. * @param stepController step4WizardController
  376. */
  377. saveClients: function(stepController){
  378. var clients = [];
  379. var serviceComponents = require('data/service_components');
  380. var hostComponents = App.HostComponent.find();
  381. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  382. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  383. if (client) {
  384. clients.pushObject({
  385. component_name: client.component_name,
  386. display_name: client.display_name,
  387. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  388. });
  389. }
  390. }, this);
  391. App.db.setClientsForSelectedServices(clients);
  392. this.set('content.clients', clients);
  393. console.log("AddServiceController.saveClients: saved list ", clients);
  394. },
  395. /**
  396. * Load data for all steps until <code>current step</code>
  397. */
  398. loadAllPriorSteps: function () {
  399. var step = this.get('currentStep');
  400. switch (step) {
  401. case '7':
  402. case '6':
  403. case '5':
  404. this.load('cluster');
  405. case '4':
  406. this.loadServiceConfigProperties();
  407. case '3':
  408. this.loadServices();
  409. this.loadClients();
  410. this.loadSlaveComponentHosts();//depends on loadServices
  411. case '2':
  412. this.loadMasterComponentHosts();
  413. this.loadConfirmedHosts();
  414. case '1':
  415. this.loadServices();
  416. }
  417. },
  418. loadAdvancedConfigs: function () {
  419. App.db.getSelectedServiceNames().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.clearHosts();
  469. //todo it)
  470. },
  471. /**
  472. * Clear all temporary data
  473. */
  474. finish: function(){
  475. this.setCurrentStep('1');
  476. App.db.setService(undefined); //not to use this data at AddService page
  477. App.db.setHosts(undefined);
  478. App.db.setMasterComponentHosts(undefined);
  479. App.db.setSlaveComponentHosts(undefined);
  480. App.db.setCluster(undefined);
  481. App.db.setAllHostNames(undefined);
  482. }
  483. });