add_controller.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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. /**
  22. * All wizards data will be stored in this variable
  23. *
  24. * cluster - cluster name
  25. * hosts - hosts, ssh key, repo info, etc.
  26. * services - services list
  27. * hostsInfo - list of selected hosts
  28. * slaveComponentHosts, - info about slave hosts
  29. * masterComponentHosts - info about master hosts
  30. * config??? - to be described later
  31. */
  32. content: Em.Object.create({
  33. cluster: null,
  34. hosts: null,
  35. services: null,
  36. hostsInfo: null,
  37. slaveComponentHosts: null,
  38. masterComponentHosts: null,
  39. serviceConfigProperties: null,
  40. advancedServiceConfig: null,
  41. controllerName: 'addServiceController',
  42. isWizard: true
  43. }),
  44. /**
  45. * Used for hiding back button in wizard
  46. */
  47. hideBackButton: true,
  48. totalSteps: 7,
  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. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  67. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  68. */
  69. saveClusterStatus: function (clusterStatus) {
  70. clusterStatus.name = this.get('content.cluster.name');
  71. this.set('content.cluster', clusterStatus);
  72. console.log('called saveClusterStatus ' + JSON.stringify(clusterStatus));
  73. App.db.setClusterStatus(clusterStatus);
  74. },
  75. /**
  76. * Temporary function for wizardStep9, before back-end integration
  77. */
  78. setInfoForStep9: function () {
  79. var hostInfo = App.db.getHosts();
  80. for (var index in hostInfo) {
  81. hostInfo[index].status = "pending";
  82. hostInfo[index].message = 'Information';
  83. hostInfo[index].progress = '0';
  84. }
  85. App.db.setHosts(hostInfo);
  86. },
  87. /**
  88. * Load confirmed hosts.
  89. * Will be used at <code>Assign Masters(step5)</code> step
  90. */
  91. loadConfirmedHosts: function(){
  92. var hosts = App.db.getHosts();
  93. if(!hosts){
  94. var hosts = {};
  95. App.Host.find().forEach(function(item){
  96. hosts[item.get('id')] = {
  97. name: item.get('id'),
  98. cpu: item.get('cpu'),
  99. memory: item.get('memory'),
  100. bootStatus: "DONE",
  101. isInstalled: true
  102. };
  103. });
  104. App.db.setHosts(hosts);
  105. }
  106. this.set('content.hostsInfo', hosts);
  107. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  108. },
  109. /**
  110. * Save data after installation to main controller
  111. * @param stepController App.WizardStep9Controller
  112. */
  113. saveInstalledHosts: function (stepController) {
  114. var hosts = stepController.get('hosts');
  115. var hostInfo = App.db.getHosts();
  116. for (var index in hostInfo) {
  117. hostInfo[index].status = "pending";
  118. var host = hosts.findProperty('name', hostInfo[index].name);
  119. if (host) {
  120. hostInfo[index].status = host.status;
  121. hostInfo[index].message = host.message;
  122. hostInfo[index].progress = host.progress;
  123. }
  124. }
  125. App.db.setHosts(hostInfo);
  126. this.set('content.hostsInfo', hostInfo);
  127. console.log('AddServiceController:saveInstalledHosts: save hosts ', hostInfo);
  128. },
  129. /**
  130. * Remove all data for hosts
  131. */
  132. clearHosts: function () {
  133. var hosts = this.get('content').get('hosts');
  134. if (hosts) {
  135. hosts.hostNames = '';
  136. hosts.manualInstall = false;
  137. hosts.localRepo = '';
  138. hosts.localRepopath = '';
  139. hosts.sshKey = '';
  140. hosts.passphrase = '';
  141. hosts.confirmPassphrase = '';
  142. }
  143. App.db.setHosts(null);
  144. App.db.setAllHostNames(null);
  145. },
  146. /**
  147. * Load services data. Will be used at <code>Select services(step4)</code> step
  148. */
  149. loadServices: function () {
  150. var servicesInfo = App.db.getService();
  151. if(!servicesInfo || !servicesInfo.length){
  152. servicesInfo = require('data/services').slice(0);
  153. servicesInfo.forEach(function(item, index){
  154. servicesInfo[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  155. servicesInfo[index].isDisabled = servicesInfo[index].isSelected;
  156. servicesInfo[index].isInstalled = servicesInfo[index].isSelected;
  157. });
  158. }
  159. servicesInfo.forEach(function (item, index) {
  160. servicesInfo[index] = Em.Object.create(item);
  161. });
  162. this.set('content.services', servicesInfo);
  163. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  164. var serviceNames = servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  165. console.log('selected services ', serviceNames);
  166. this.set('content.missSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  167. },
  168. /**
  169. * Save data to model
  170. * @param stepController App.WizardStep4Controller
  171. */
  172. saveServices: function (stepController) {
  173. var serviceNames = [];
  174. App.db.setService(stepController.get('content'));
  175. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  176. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  177. serviceNames.push(item.serviceName);
  178. });
  179. this.set('content.selectedServiceNames', serviceNames);
  180. App.db.setSelectedServiceNames(serviceNames);
  181. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  182. this.set('content.missSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  183. },
  184. /**
  185. * Save Master Component Hosts data to Main Controller
  186. * @param stepController App.WizardStep5Controller
  187. */
  188. saveMasterComponentHosts: function (stepController) {
  189. var obj = stepController.get('selectedServicesMasters');
  190. var masterComponentHosts = [];
  191. var installedComponents = App.Component.find();
  192. obj.forEach(function (_component) {
  193. masterComponentHosts.push({
  194. display_name: _component.display_name,
  195. component: _component.component_name,
  196. hostName: _component.selectedHost,
  197. serviceId: _component.serviceId,
  198. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  199. });
  200. });
  201. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  202. App.db.setMasterComponentHosts(masterComponentHosts);
  203. this.set('content.masterComponentHosts', masterComponentHosts);
  204. this.set('content.missMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  205. },
  206. /**
  207. * Load master component hosts data for using in required step controllers
  208. */
  209. loadMasterComponentHosts: function () {
  210. var masterComponentHosts = App.db.getMasterComponentHosts();
  211. if(!masterComponentHosts){
  212. masterComponentHosts = [];
  213. App.Component.find().filterProperty('isMaster', true).forEach(function(item){
  214. masterComponentHosts.push({
  215. component: item.get('componentName'),
  216. hostName: item.get('host.hostName'),
  217. isInstalled: true
  218. })
  219. });
  220. }
  221. this.set("content.masterComponentHosts", masterComponentHosts);
  222. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  223. this.set('content.missMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  224. },
  225. /**
  226. * Save slaveHostComponents to main controller
  227. * @param stepController
  228. */
  229. saveSlaveComponentHosts: function (stepController) {
  230. var hosts = stepController.get('hosts');
  231. var isMrSelected = stepController.get('isMrSelected');
  232. var isHbSelected = stepController.get('isHbSelected');
  233. var dataNodeHosts = [];
  234. var taskTrackerHosts = [];
  235. var regionServerHosts = [];
  236. var clientHosts = [];
  237. hosts.forEach(function (host) {
  238. if (host.get('isDataNode')) {
  239. dataNodeHosts.push({
  240. hostName: host.hostName,
  241. group: 'Default',
  242. isInstalled: host.get('isDataNodeInstalled')
  243. });
  244. }
  245. if (isMrSelected && host.get('isTaskTracker')) {
  246. taskTrackerHosts.push({
  247. hostName: host.hostName,
  248. group: 'Default',
  249. isInstalled: host.get('isTaskTrackerInstalled')
  250. });
  251. }
  252. if (isHbSelected && host.get('isRegionServer')) {
  253. regionServerHosts.push({
  254. hostName: host.hostName,
  255. group: 'Default',
  256. isInstalled: host.get('isRegionServerInstalled')
  257. });
  258. }
  259. if (host.get('isClient')) {
  260. clientHosts.pushObject({
  261. hostName: host.hostName,
  262. group: 'Default',
  263. isInstalled: host.get('isClientInstalled')
  264. });
  265. }
  266. }, this);
  267. var slaveComponentHosts = [];
  268. slaveComponentHosts.push({
  269. componentName: 'DATANODE',
  270. displayName: 'DataNode',
  271. hosts: dataNodeHosts
  272. });
  273. if (isMrSelected) {
  274. slaveComponentHosts.push({
  275. componentName: 'TASKTRACKER',
  276. displayName: 'TaskTracker',
  277. hosts: taskTrackerHosts
  278. });
  279. }
  280. if (isHbSelected) {
  281. slaveComponentHosts.push({
  282. componentName: 'HBASE_REGIONSERVER',
  283. displayName: 'RegionServer',
  284. hosts: regionServerHosts
  285. });
  286. }
  287. slaveComponentHosts.pushObject({
  288. componentName: 'CLIENT',
  289. displayName: 'client',
  290. hosts: clientHosts
  291. });
  292. App.db.setSlaveComponentHosts(slaveComponentHosts);
  293. console.log('addServiceController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  294. this.set('content.slaveComponentHosts', slaveComponentHosts);
  295. },
  296. /**
  297. * return slaveComponents bound to hosts
  298. * @return {Array}
  299. */
  300. getSlaveComponentHosts: function () {
  301. var components = [{
  302. name : 'DATANODE',
  303. service : 'HDFS'
  304. },
  305. {
  306. name: 'TASKTRACKER',
  307. service: 'MAPREDUCE'
  308. },{
  309. name: 'HBASE_REGIONSERVER',
  310. service: 'HBASE'
  311. }];
  312. var result = [];
  313. var services = App.Service.find();
  314. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  315. for(var index=0; index < components.length; index++){
  316. var comp = components[index];
  317. if(!selectedServices.contains(comp.service)){
  318. continue;
  319. }
  320. var service = services.findProperty('id', comp.service);
  321. var hosts = [];
  322. if(!service){
  323. service = services.findProperty('id', 'HDFS');
  324. service.get('hostComponents').filterProperty('componentName', 'DATANODE').forEach(function (host_component) {
  325. hosts.push({
  326. group: "Default",
  327. hostName: host_component.get('host.id'),
  328. isInstalled: false
  329. });
  330. }, this);
  331. } else {
  332. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  333. hosts.push({
  334. group: "Default",
  335. hostName: host_component.get('host.id'),
  336. isInstalled: true
  337. });
  338. }, this);
  339. }
  340. result.push({
  341. componentName: comp.name,
  342. displayName: App.format.role(comp.name),
  343. hosts: hosts
  344. })
  345. }
  346. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  347. var hosts = [];
  348. clientsHosts.forEach(function (host_component) {
  349. hosts.push({
  350. group: "Default",
  351. hostName: host_component.get('host.id'),
  352. isInstalled: true
  353. });
  354. }, this);
  355. result.push({
  356. componentName: 'CLIENT',
  357. displayName: 'client',
  358. hosts: hosts
  359. })
  360. return result;
  361. },
  362. /**
  363. * Load master component hosts data for using in required step controllers
  364. */
  365. loadSlaveComponentHosts: function () {
  366. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  367. if(!slaveComponentHosts){
  368. slaveComponentHosts = this.getSlaveComponentHosts();
  369. }
  370. this.set("content.slaveComponentHosts", slaveComponentHosts);
  371. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  372. },
  373. /**
  374. * Save config properties
  375. * @param stepController Step7WizardController
  376. */
  377. saveServiceConfigProperties: function (stepController) {
  378. var serviceConfigProperties = [];
  379. stepController.get('stepConfigs').forEach(function (_content) {
  380. _content.get('configs').forEach(function (_configProperties) {
  381. var configProperty = {
  382. name: _configProperties.get('name'),
  383. value: _configProperties.get('value'),
  384. service: _configProperties.get('serviceName')
  385. };
  386. serviceConfigProperties.push(configProperty);
  387. }, this);
  388. }, this);
  389. App.db.setServiceConfigProperties(serviceConfigProperties);
  390. this.set('content.serviceConfigProperties', serviceConfigProperties);
  391. },
  392. /**
  393. * Load serviceConfigProperties to model
  394. */
  395. loadServiceConfigProperties: function () {
  396. var serviceConfigProperties = App.db.getServiceConfigProperties();
  397. this.set('content.serviceConfigProperties', serviceConfigProperties);
  398. console.log("AddServiceController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  399. },
  400. /**
  401. * Load information about hosts with clients components
  402. */
  403. loadClients: function(){
  404. var clients = App.db.getClientsForSelectedServices();
  405. this.set('content.clients', clients);
  406. console.log("AddServiceController.loadClients: loaded list ", clients);
  407. },
  408. dataLoading: function(){
  409. var dfd = $.Deferred();
  410. this.connectOutlet('loading');
  411. if (App.router.get('clusterController.isLoaded')){
  412. dfd.resolve();
  413. } else{
  414. var interval = setInterval(function(){
  415. if (App.router.get('clusterController.isLoaded')){
  416. dfd.resolve();
  417. clearInterval(interval);
  418. }
  419. },50);
  420. }
  421. return dfd.promise();
  422. },
  423. /**
  424. * Generate clients list for selected services and save it to model
  425. * @param stepController step4WizardController
  426. */
  427. saveClients: function(stepController){
  428. var clients = [];
  429. var serviceComponents = require('data/service_components');
  430. var hostComponents = App.HostComponent.find();
  431. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  432. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  433. if (client) {
  434. clients.pushObject({
  435. component_name: client.component_name,
  436. display_name: client.display_name,
  437. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  438. });
  439. }
  440. }, this);
  441. App.db.setClientsForSelectedServices(clients);
  442. this.set('content.clients', clients);
  443. console.log("AddServiceController.saveClients: saved list ", clients);
  444. },
  445. /**
  446. * Load data for all steps until <code>current step</code>
  447. */
  448. loadAllPriorSteps: function () {
  449. var step = this.get('currentStep');
  450. switch (step) {
  451. case '7':
  452. case '6':
  453. case '5':
  454. this.loadClusterInfo();
  455. case '4':
  456. this.loadServiceConfigProperties();
  457. case '3':
  458. this.loadServices();
  459. this.loadClients();
  460. this.loadSlaveComponentHosts();//depends on loadServices
  461. case '2':
  462. this.loadMasterComponentHosts();
  463. this.loadConfirmedHosts();
  464. case '1':
  465. this.loadServices();
  466. }
  467. },
  468. loadAdvancedConfigs: function () {
  469. App.db.getSelectedServiceNames().forEach(function (_serviceName) {
  470. this.loadAdvancedConfig(_serviceName);
  471. }, this);
  472. },
  473. /**
  474. * Generate serviceProperties save it to localdata
  475. * called form stepController step6WizardController
  476. */
  477. loadAdvancedConfig: function (serviceName) {
  478. var self = this;
  479. 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
  480. var method = 'GET';
  481. $.ajax({
  482. type: method,
  483. url: url,
  484. async: false,
  485. dataType: 'text',
  486. timeout: App.timeout,
  487. success: function (data) {
  488. var jsonData = jQuery.parseJSON(data);
  489. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  490. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  491. var serviceComponents = jsonData.properties;
  492. serviceComponents.setEach('serviceName', serviceName);
  493. var configs;
  494. if (App.db.getAdvancedServiceConfig()) {
  495. configs = App.db.getAdvancedServiceConfig();
  496. } else {
  497. configs = [];
  498. }
  499. configs = configs.concat(serviceComponents);
  500. self.set('content.advancedServiceConfig', configs);
  501. App.db.setAdvancedServiceConfig(configs);
  502. console.log('TRACE: servicename: ' + serviceName);
  503. },
  504. error: function (request, ajaxOptions, error) {
  505. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  506. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  507. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  508. console.log('Step6 submit: Error message is: ' + request.responseText);
  509. },
  510. statusCode: require('data/statusCodes')
  511. });
  512. },
  513. /**
  514. * Invoke installation of selected services to the server and saves the request id returned by the server.
  515. * @param isRetry
  516. */
  517. installServices: function (isRetry) {
  518. if(!isRetry && this.get('content.cluster.requestId')){
  519. return;
  520. }
  521. var self = this;
  522. var clusterName = this.get('content.cluster.name');
  523. var url = (App.testMode) ? '/data/wizard/deploy/poll_1.json' : App.apiPrefix + '/clusters/' + clusterName + '/services?ServiceInfo/state=INIT';
  524. var method = (App.testMode) ? 'GET' : 'PUT';
  525. var data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  526. $.ajax({
  527. type: method,
  528. url: url,
  529. data: data,
  530. async: false,
  531. dataType: 'text',
  532. timeout: App.timeout,
  533. success: function (data) {
  534. var jsonData = jQuery.parseJSON(data);
  535. var installSartTime = new Date().getTime();
  536. console.log("TRACE: STep8 -> In success function for the installService call");
  537. console.log("TRACE: STep8 -> value of the url is: " + url);
  538. if (jsonData) {
  539. var requestId = jsonData.href.match(/.*\/(.*)$/)[1];
  540. console.log('requestId is: ' + requestId);
  541. var clusterStatus = {
  542. status: 'PENDING',
  543. requestId: requestId,
  544. isInstallError: false,
  545. isCompleted: false,
  546. installStartTime: installSartTime
  547. };
  548. self.saveClusterStatus(clusterStatus);
  549. } else {
  550. console.log('ERROR: Error occurred in parsing JSON data');
  551. }
  552. },
  553. error: function (request, ajaxOptions, error) {
  554. console.log("TRACE: STep8 -> In error function for the installService call");
  555. console.log("TRACE: STep8 -> value of the url is: " + url);
  556. console.log("TRACE: STep8 -> error code status is: " + request.status);
  557. console.log('Step8: Error message is: ' + request.responseText);
  558. var clusterStatus = {
  559. status: 'PENDING',
  560. isInstallError: true,
  561. isCompleted: false
  562. };
  563. self.saveClusterStatus(clusterStatus);
  564. },
  565. statusCode: require('data/statusCodes')
  566. });
  567. },
  568. /**
  569. * Remove all loaded data.
  570. * Created as copy for App.router.clearAllSteps
  571. */
  572. clearAllSteps: function () {
  573. this.clearHosts();
  574. //todo it)
  575. },
  576. /**
  577. * Clear all temporary data
  578. */
  579. finish: function(){
  580. this.setCurrentStep('1', false);
  581. App.db.setService(undefined); //not to use this data at AddService page
  582. App.db.setHosts(undefined);
  583. App.db.setMasterComponentHosts(undefined);
  584. App.db.setSlaveComponentHosts(undefined);
  585. App.db.setClusterStatus(undefined);
  586. App.db.setAllHostNames(undefined);
  587. }
  588. });