add_controller.js 18 KB

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