add_controller.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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 = Em.Controller.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, hostSlaveComponents - 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. hostSlaveComponents: null,
  39. masterComponentHosts: null,
  40. serviceConfigProperties: null,
  41. controllerName: 'addServiceController'
  42. }),
  43. /**
  44. * Used for hiding back button in wizard
  45. */
  46. hideBackButton: true,
  47. isStepDisabled: [],
  48. totalSteps: 9,
  49. init: function () {
  50. this.isStepDisabled.pushObject(Ember.Object.create({
  51. step: 1,
  52. value: false
  53. }));
  54. for (var i = 2; i <= this.totalSteps; i++) {
  55. this.isStepDisabled.pushObject(Ember.Object.create({
  56. step: i,
  57. value: true
  58. }));
  59. }
  60. },
  61. setStepsEnable: function () {
  62. for (var i = 2; i <= this.totalSteps; i++) {
  63. var step = this.get('isStepDisabled').findProperty('step', i);
  64. if (i <= this.get('currentStep')) {
  65. step.set('value', false);
  66. } else {
  67. step.set('value', true);
  68. }
  69. }
  70. }.observes('currentStep'),
  71. /**
  72. * Return current step of Add Host Wizard
  73. */
  74. currentStep: function () {
  75. return App.get('router').getWizardCurrentStep('addService');
  76. }.property(),
  77. clusters: null,
  78. /**
  79. * Set current step to new value.
  80. * Method moved from App.router.setInstallerCurrentStep
  81. * @param currentStep
  82. * @param completed
  83. */
  84. setCurrentStep: function (currentStep, completed) {
  85. App.db.setWizardCurrentStep('addService', currentStep, completed);
  86. this.set('currentStep', currentStep);
  87. },
  88. isStep1: function () {
  89. return this.get('currentStep') == 1;
  90. }.property('currentStep'),
  91. isStep2: function () {
  92. return this.get('currentStep') == 2;
  93. }.property('currentStep'),
  94. isStep3: function () {
  95. return this.get('currentStep') == 3;
  96. }.property('currentStep'),
  97. isStep4: function () {
  98. return this.get('currentStep') == 4;
  99. }.property('currentStep'),
  100. isStep5: function () {
  101. return this.get('currentStep') == 5;
  102. }.property('currentStep'),
  103. isStep6: function () {
  104. return this.get('currentStep') == 6;
  105. }.property('currentStep'),
  106. isStep7: function () {
  107. return this.get('currentStep') == 7;
  108. }.property('currentStep'),
  109. gotoStep: function (step) {
  110. if (this.get('isStepDisabled').findProperty('step', step).get('value') === false) {
  111. App.router.send('gotoStep' + step);
  112. }
  113. },
  114. gotoStep1: function () {
  115. this.gotoStep(1);
  116. },
  117. gotoStep2: function () {
  118. this.gotoStep(2);
  119. },
  120. gotoStep3: function () {
  121. this.gotoStep(3);
  122. },
  123. gotoStep4: function () {
  124. this.gotoStep(4);
  125. },
  126. gotoStep5: function () {
  127. this.gotoStep(5);
  128. },
  129. gotoStep6: function () {
  130. this.gotoStep(6);
  131. },
  132. gotoStep7: function () {
  133. this.gotoStep(7);
  134. },
  135. /**
  136. * Load clusterInfo(step1) to model
  137. */
  138. loadClusterInfo: function(){
  139. var cStatus = App.db.getClusterStatus() || {status: "", isCompleted: false};
  140. var cluster = {
  141. name: App.db.getClusterName() || "",
  142. status: cStatus.status,
  143. isCompleted: cStatus.isCompleted
  144. };
  145. this.set('content.cluster', cluster);
  146. console.log("AddServiceController:loadClusterInfo: loaded data ", cluster);
  147. },
  148. /**
  149. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  150. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  151. */
  152. saveClusterStatus: function (clusterStatus) {
  153. this.set('content.cluster', clusterStatus);
  154. App.db.setClusterStatus(clusterStatus);
  155. },
  156. /**
  157. * Temporary function for wizardStep9, before back-end integration
  158. */
  159. setInfoForStep9: function () {
  160. var hostInfo = App.db.getHosts();
  161. for (var index in hostInfo) {
  162. hostInfo[index].status = "pending";
  163. hostInfo[index].message = 'Information';
  164. hostInfo[index].progress = '0';
  165. }
  166. App.db.setHosts(hostInfo);
  167. },
  168. /**
  169. * Load confirmed hosts.
  170. * Will be used at <code>Assign Masters(step5)</code> step
  171. */
  172. loadConfirmedHosts: function(){
  173. var hosts = {};
  174. App.Host.find().forEach(function(item){
  175. hosts[item.get('id')] = {
  176. name: item.get('id'),
  177. cpu: item.get('cpu'),
  178. memory: item.get('memory'),
  179. bootStatus: "success",
  180. isInstalled: true
  181. };
  182. });
  183. this.set('content.hostsInfo', hosts);
  184. },
  185. /**
  186. * Save data after installation to main controller
  187. * @param stepController App.WizardStep9Controller
  188. */
  189. saveInstalledHosts: function (stepController) {
  190. var hosts = stepController.get('hosts');
  191. var hostInfo = App.db.getHosts();
  192. for (var index in hostInfo) {
  193. hostInfo[index].status = "pending";
  194. var host = hosts.findProperty('name', hostInfo[index].name);
  195. if (host) {
  196. hostInfo[index].status = host.status;
  197. hostInfo[index].message = host.message;
  198. hostInfo[index].progress = host.progress;
  199. }
  200. }
  201. App.db.setHosts(hostInfo);
  202. this.set('content.hostsInfo', hostInfo);
  203. console.log('AddServiceController:saveInstalledHosts: save hosts ', hostInfo);
  204. },
  205. /**
  206. * Remove all data for hosts
  207. */
  208. clearHosts: function () {
  209. var hosts = this.get('content').get('hosts');
  210. if (hosts) {
  211. hosts.hostNames = '';
  212. hosts.manualInstall = false;
  213. hosts.localRepo = '';
  214. hosts.localRepopath = '';
  215. hosts.sshKey = '';
  216. hosts.passphrase = '';
  217. hosts.confirmPassphrase = '';
  218. }
  219. App.db.setHosts(null);
  220. App.db.setAllHostNames(null);
  221. },
  222. /**
  223. * Load services data. Will be used at <code>Select services(step4)</code> step
  224. */
  225. loadServices: function () {
  226. var servicesInfo = App.db.getService();
  227. if(!servicesInfo){
  228. servicesInfo = require('data/mock/services').slice(0);
  229. servicesInfo.forEach(function(item, index){
  230. servicesInfo[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  231. servicesInfo[index].isDisabled = servicesInfo[index].isSelected;
  232. });
  233. }
  234. servicesInfo.forEach(function (item, index) {
  235. servicesInfo[index] = Em.Object.create(item);
  236. });
  237. this.set('content.services', servicesInfo);
  238. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  239. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  240. },
  241. /**
  242. * Save data to model
  243. * @param stepController App.WizardStep4Controller
  244. */
  245. saveServices: function (stepController) {
  246. var serviceNames = [];
  247. // we can also do it without stepController since all data,
  248. // changed at page, automatically changes in model(this.content.services)
  249. App.db.setService(stepController.get('content'));
  250. stepController.filterProperty('isSelected', true).filterProperty('isDisabled', false).forEach(function (item) {
  251. serviceNames.push(item.serviceName);
  252. });
  253. this.set('content.selectedServiceNames', serviceNames);
  254. App.db.setSelectedServiceNames(serviceNames);
  255. console.log('AddServiceController.saveServices: saved data ', serviceNames);
  256. },
  257. /**
  258. * Save Master Component Hosts data to Main Controller
  259. * @param stepController App.WizardStep5Controller
  260. */
  261. saveMasterComponentHosts: function (stepController) {
  262. var obj = stepController.get('selectedServicesMasters');
  263. var masterComponentHosts = [];
  264. var installedComponents = App.Component.find();
  265. obj.forEach(function (_component) {
  266. if(!installedComponents.someProperty('componentName', _component.component_name)){
  267. masterComponentHosts.push({
  268. display_name: _component.display_name,
  269. component: _component.component_name,
  270. hostName: _component.selectedHost,
  271. isInstalled: false
  272. });
  273. }
  274. });
  275. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  276. App.db.setMasterComponentHosts(masterComponentHosts);
  277. this.set('content.masterComponentHosts', masterComponentHosts);
  278. },
  279. /**
  280. * Load master component hosts data for using in required step controllers
  281. */
  282. loadMasterComponentHosts: function () {
  283. var masterComponentHosts = App.db.getMasterComponentHosts() || [];
  284. App.Component.find().filterProperty('isMaster', true).forEach(function(item){
  285. masterComponentHosts.push({
  286. component: item.get('componentName'),
  287. display_name: item.get('displayName'),
  288. hostName: item.get('host.hostName'),
  289. isInstalled: true
  290. })
  291. });
  292. this.set("content.masterComponentHosts", masterComponentHosts);
  293. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  294. },
  295. /**
  296. * Save slaveHostComponents to main controller
  297. * @param stepController
  298. */
  299. saveSlaveComponentHosts: function (stepController) {
  300. var hosts = stepController.get('hosts');
  301. var isMrSelected = stepController.get('isMrSelected');
  302. var isHbSelected = stepController.get('isHbSelected');
  303. App.db.setHostSlaveComponents(hosts);
  304. this.set('content.hostSlaveComponents', hosts);
  305. var dataNodeHosts = [];
  306. var taskTrackerHosts = [];
  307. var regionServerHosts = [];
  308. var clientHosts = [];
  309. var installedComponents = App.Component.find();
  310. hosts.forEach(function (host) {
  311. if (host.get('isDataNode')) {
  312. dataNodeHosts.push({
  313. hostName: host.hostName,
  314. group: 'Default',
  315. isInstalled: installedComponents.someProperty('componentName', 'DATANODE')
  316. });
  317. }
  318. if (isMrSelected && host.get('isTaskTracker')) {
  319. taskTrackerHosts.push({
  320. hostName: host.hostName,
  321. group: 'Default',
  322. isInstalled: installedComponents.someProperty('componentName', 'TASKTRACKER')
  323. });
  324. }
  325. if (isHbSelected && host.get('isRegionServer')) {
  326. regionServerHosts.push({
  327. hostName: host.hostName,
  328. group: 'Default',
  329. isInstalled: installedComponents.someProperty('componentName', 'HBASE_REGIONSERVER')
  330. });
  331. }
  332. if (host.get('isClient')) {
  333. clientHosts.pushObject({
  334. hostName: host.hostName,
  335. group: 'Default',
  336. isInstalled: installedComponents.someProperty('componentName', 'CLIENT')
  337. });
  338. }
  339. }, this);
  340. var slaveComponentHosts = [];
  341. slaveComponentHosts.push({
  342. componentName: 'DATANODE',
  343. displayName: 'DataNode',
  344. hosts: dataNodeHosts
  345. });
  346. if (isMrSelected) {
  347. slaveComponentHosts.push({
  348. componentName: 'TASKTRACKER',
  349. displayName: 'TaskTracker',
  350. hosts: taskTrackerHosts
  351. });
  352. }
  353. if (isHbSelected) {
  354. slaveComponentHosts.push({
  355. componentName: 'HBASE_REGIONSERVER',
  356. displayName: 'RegionServer',
  357. hosts: regionServerHosts
  358. });
  359. }
  360. slaveComponentHosts.pushObject({
  361. componentName: 'CLIENT',
  362. displayName: 'client',
  363. hosts: clientHosts
  364. });
  365. App.db.setSlaveComponentHosts(slaveComponentHosts);
  366. this.set('content.slaveComponentHosts', slaveComponentHosts);
  367. },
  368. /**
  369. * Load master component hosts data for using in required step controllers
  370. */
  371. loadSlaveComponentHosts: function () {
  372. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  373. this.set("content.slaveComponentHosts", slaveComponentHosts);
  374. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  375. var hostSlaveComponents = App.db.getHostSlaveComponents();
  376. this.set('content.hostSlaveComponents', hostSlaveComponents);
  377. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", hostSlaveComponents);
  378. },
  379. /**
  380. * Save config properties
  381. * @param stepController Step7WizardController
  382. */
  383. saveServiceConfigProperties: function (stepController) {
  384. var serviceConfigProperties = [];
  385. stepController.get('stepConfigs').forEach(function (_content) {
  386. _content.get('configs').forEach(function (_configProperties) {
  387. var configProperty = {
  388. name: _configProperties.get('name'),
  389. value: _configProperties.get('value'),
  390. service: _configProperties.get('serviceName')
  391. };
  392. serviceConfigProperties.push(configProperty);
  393. }, this);
  394. }, this);
  395. App.db.setServiceConfigProperties(serviceConfigProperties);
  396. this.set('content.serviceConfigProperties', serviceConfigProperties);
  397. },
  398. /**
  399. * Load serviceConfigProperties to model
  400. */
  401. loadServiceConfigProperties: function () {
  402. var serviceConfigProperties = App.db.getServiceConfigProperties();
  403. this.set('content.serviceConfigProperties', serviceConfigProperties);
  404. console.log("AddServiceController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  405. },
  406. /**
  407. * Load information about hosts with clients components
  408. */
  409. loadClients: function(){
  410. var clients = App.db.getClientsForSelectedServices();
  411. this.set('content.clients', clients);
  412. console.log("AddServiceController.loadClients: loaded list ", clients);
  413. },
  414. /**
  415. * Generate clients list for selected services and save it to model
  416. * @param stepController step4WizardController
  417. */
  418. saveClients: function(stepController){
  419. var clients = [];
  420. var serviceComponents = require('data/service_components');
  421. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  422. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  423. if (client) {
  424. clients.pushObject({
  425. component_name: client.component_name,
  426. display_name: client.display_name
  427. });
  428. }
  429. }, this);
  430. App.db.setClientsForSelectedServices(clients);
  431. this.set('content.clients', clients);
  432. console.log("AddServiceController.saveClients: saved list ", clients);
  433. },
  434. /**
  435. * Load data for all steps until <code>current step</code>
  436. */
  437. loadAllPriorSteps: function () {
  438. var step = this.get('currentStep');
  439. switch (step) {
  440. case '6':
  441. case '5':
  442. this.loadClusterInfo();
  443. case '4':
  444. this.loadServiceConfigProperties();
  445. case '3':
  446. this.loadClients();
  447. this.loadSlaveComponentHosts();
  448. case '2':
  449. this.loadMasterComponentHosts();
  450. this.loadConfirmedHosts();
  451. case '1':
  452. this.loadServices();
  453. }
  454. },
  455. /**
  456. * Generate clients list for selected services and save it to model
  457. * @param stepController step8WizardController or step9WizardController
  458. */
  459. installServices: function () {
  460. var self = this;
  461. var clusterName = this.get('content.cluster.name');
  462. var url = (App.testMode) ? '/data/wizard/deploy/poll_1.json' : '/api/clusters/' + clusterName + '/services?state=INIT';
  463. var method = (App.testMode) ? 'GET' : 'PUT';
  464. var data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  465. $.ajax({
  466. type: method,
  467. url: url,
  468. data: data,
  469. async: false,
  470. dataType: 'text',
  471. timeout: 5000,
  472. success: function (data) {
  473. var jsonData = jQuery.parseJSON(data);
  474. var installSartTime = new Date().getTime();
  475. console.log("TRACE: STep8 -> In success function for the installService call");
  476. console.log("TRACE: STep8 -> value of the url is: " + url);
  477. if (jsonData) {
  478. var requestId = jsonData.href.match(/.*\/(.*)$/)[1];
  479. console.log('requestId is: ' + requestId);
  480. var clusterStatus = {
  481. status: 'PENDING',
  482. requestId: requestId,
  483. isInstallError: false,
  484. isCompleted: false,
  485. installStartTime: installSartTime
  486. };
  487. self.saveClusterStatus(clusterStatus);
  488. } else {
  489. console.log('ERROR: Error occurred in parsing JSON data');
  490. }
  491. },
  492. error: function (request, ajaxOptions, error) {
  493. console.log("TRACE: STep8 -> In error function for the installService call");
  494. console.log("TRACE: STep8 -> value of the url is: " + url);
  495. console.log("TRACE: STep8 -> error code status is: " + request.status);
  496. console.log('Step8: Error message is: ' + request.responseText);
  497. var clusterStatus = {
  498. status: 'PENDING',
  499. isInstallError: true,
  500. isCompleted: false
  501. };
  502. self.saveClusterStatus(clusterStatus);
  503. },
  504. statusCode: require('data/statusCodes')
  505. });
  506. },
  507. /**
  508. * Remove all loaded data.
  509. * Created as copy for App.router.clearAllSteps
  510. */
  511. clearAllSteps: function () {
  512. this.clearHosts();
  513. //todo it)
  514. }
  515. });