installer.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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.InstallerController = App.WizardController.extend({
  20. name: 'installerController',
  21. totalSteps: 10,
  22. content: Em.Object.create({
  23. cluster: null,
  24. installOptions: null,
  25. hosts: null,
  26. services: null,
  27. slaveComponentHosts: null,
  28. masterComponentHosts: null,
  29. serviceConfigProperties: null,
  30. advancedServiceConfig: null,
  31. slaveGroupProperties: null,
  32. controllerName: 'installerController'
  33. }),
  34. getCluster: function(){
  35. return jQuery.extend({}, this.get('clusterStatusTemplate'));
  36. },
  37. getInstallOptions: function(){
  38. return jQuery.extend({}, this.get('installOptionsTemplate'));
  39. },
  40. getHosts: function(){
  41. return [];
  42. },
  43. /**
  44. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  45. * @param hosts Array of hosts, which we want to delete
  46. */
  47. removeHosts: function (hosts) {
  48. //todo Replace this code with real logic
  49. App.db.removeHosts(hosts);
  50. },
  51. /**
  52. * Save data, which user filled, to main controller
  53. * @param stepController App.WizardStep3Controller
  54. */
  55. saveConfirmedHosts: function (stepController) {
  56. var hostInfo = {};
  57. stepController.get('content.hosts').forEach(function (_host) {
  58. hostInfo[_host.name] = {
  59. name: _host.name,
  60. cpu: _host.cpu,
  61. memory: _host.memory,
  62. disk_info: _host.disk_info,
  63. bootStatus: _host.bootStatus,
  64. isInstalled: false
  65. };
  66. });
  67. this.set('content.hosts', hostInfo);
  68. this.save('hosts');
  69. },
  70. /**
  71. * Load confirmed hosts.
  72. * Will be used at <code>Assign Masters(step5)</code> step
  73. */
  74. loadConfirmedHosts: function () {
  75. this.set('content.hosts', App.db.getHosts() || []);
  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. var host = hosts.findProperty('name', hostInfo[index].name);
  86. if (host) {
  87. hostInfo[index].status = host.status;
  88. //tasks should be empty because they loads from the server
  89. //hostInfo[index].tasks = host.tasks;
  90. hostInfo[index].message = host.message;
  91. hostInfo[index].progress = host.progress;
  92. }
  93. }
  94. this.set('content.hosts', hostInfo);
  95. this.save('hosts');
  96. },
  97. /**
  98. * Load services data. Will be used at <code>Select services(step4)</code> step
  99. */
  100. loadServices: function () {
  101. var servicesInfo = App.db.getService();
  102. servicesInfo.forEach(function (item, index) {
  103. servicesInfo[index] = Em.Object.create(item);
  104. servicesInfo[index].isInstalled = false;
  105. });
  106. this.set('content.services', servicesInfo);
  107. console.log('installerController.loadServices: loaded data ', JSON.stringify(servicesInfo));
  108. console.log("The type odf serviceInfo: " + typeof servicesInfo);
  109. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  110. },
  111. /**
  112. * Save data to model
  113. * @param stepController App.WizardStep4Controller
  114. */
  115. saveServices: function (stepController) {
  116. var serviceNames = [];
  117. App.db.setService(stepController.get('content'));
  118. stepController.filterProperty('isSelected', true).forEach(function (item) {
  119. serviceNames.push(item.serviceName);
  120. });
  121. this.set('content.selectedServiceNames', serviceNames);
  122. App.db.setSelectedServiceNames(serviceNames);
  123. console.log('installerController.saveServices: saved data ', serviceNames);
  124. },
  125. /**
  126. * Save Master Component Hosts data to Main Controller
  127. * @param stepController App.WizardStep5Controller
  128. */
  129. saveMasterComponentHosts: function (stepController) {
  130. var obj = stepController.get('selectedServicesMasters');
  131. var masterComponentHosts = [];
  132. obj.forEach(function (_component) {
  133. masterComponentHosts.push({
  134. display_name: _component.get('display_name'),
  135. component: _component.get('component_name'),
  136. hostName: _component.get('selectedHost'),
  137. serviceId: _component.get('serviceId'),
  138. isInstalled: false
  139. });
  140. });
  141. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  142. App.db.setMasterComponentHosts(masterComponentHosts);
  143. this.set('content.masterComponentHosts', masterComponentHosts);
  144. },
  145. /**
  146. * Load master component hosts data for using in required step controllers
  147. */
  148. loadMasterComponentHosts: function () {
  149. var masterComponentHosts = App.db.getMasterComponentHosts() || [];
  150. this.set("content.masterComponentHosts", masterComponentHosts);
  151. console.log("InstallerController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  152. },
  153. /**
  154. * Save slaveHostComponents to main controller
  155. * @param stepController called at the submission of step6
  156. */
  157. saveSlaveComponentHosts: function (stepController) {
  158. var hosts = stepController.get('hosts');
  159. var isMrSelected = stepController.get('isMrSelected');
  160. var isHbSelected = stepController.get('isHbSelected');
  161. var dataNodeHosts = [];
  162. var taskTrackerHosts = [];
  163. var regionServerHosts = [];
  164. var clientHosts = [];
  165. hosts.forEach(function (host) {
  166. if (host.get('isDataNode')) {
  167. dataNodeHosts.push({
  168. hostName: host.hostName,
  169. group: 'Default',
  170. isInstalled: false
  171. });
  172. }
  173. if (isMrSelected && host.get('isTaskTracker')) {
  174. taskTrackerHosts.push({
  175. hostName: host.hostName,
  176. group: 'Default',
  177. isInstalled: false
  178. });
  179. }
  180. if (isHbSelected && host.get('isRegionServer')) {
  181. regionServerHosts.push({
  182. hostName: host.hostName,
  183. group: 'Default',
  184. isInstalled: false
  185. });
  186. }
  187. if (host.get('isClient')) {
  188. clientHosts.pushObject({
  189. hostName: host.hostName,
  190. group: 'Default',
  191. isInstalled: false
  192. });
  193. }
  194. }, this);
  195. var slaveComponentHosts = [];
  196. slaveComponentHosts.push({
  197. componentName: 'DATANODE',
  198. displayName: 'DataNode',
  199. hosts: dataNodeHosts
  200. });
  201. if (isMrSelected) {
  202. slaveComponentHosts.push({
  203. componentName: 'TASKTRACKER',
  204. displayName: 'TaskTracker',
  205. hosts: taskTrackerHosts
  206. });
  207. }
  208. if (isHbSelected) {
  209. slaveComponentHosts.push({
  210. componentName: 'HBASE_REGIONSERVER',
  211. displayName: 'RegionServer',
  212. hosts: regionServerHosts
  213. });
  214. }
  215. slaveComponentHosts.pushObject({
  216. componentName: 'CLIENT',
  217. displayName: 'client',
  218. hosts: clientHosts
  219. });
  220. App.db.setSlaveComponentHosts(slaveComponentHosts);
  221. this.set('content.slaveComponentHosts', slaveComponentHosts);
  222. console.log("InstallerController.saveSlaveComponentHosts: saved hosts ", slaveComponentHosts);
  223. },
  224. /**
  225. * Load master component hosts data for using in required step controllers
  226. */
  227. loadSlaveComponentHosts: function () {
  228. var slaveComponentHosts = App.db.getSlaveComponentHosts() || null;
  229. this.set("content.slaveComponentHosts", slaveComponentHosts);
  230. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  231. },
  232. /**
  233. * Save config properties
  234. * @param stepController Step7WizardController
  235. */
  236. saveServiceConfigProperties: function (stepController) {
  237. var serviceConfigProperties = [];
  238. stepController.get('stepConfigs').forEach(function (_content) {
  239. _content.get('configs').forEach(function (_configProperties) {
  240. var displayType = _configProperties.get('displayType');
  241. if (displayType === 'directories' || displayType === 'directory') {
  242. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  243. _configProperties.set('value', value);
  244. }
  245. var configProperty = {
  246. id: _configProperties.get('id'),
  247. name: _configProperties.get('name'),
  248. value: _configProperties.get('value'),
  249. defaultValue: _configProperties.get('defaultValue'),
  250. service: _configProperties.get('serviceName'),
  251. domain: _configProperties.get('domain'),
  252. filename: _configProperties.get('filename')
  253. };
  254. serviceConfigProperties.push(configProperty);
  255. }, this);
  256. }, this);
  257. App.db.setServiceConfigProperties(serviceConfigProperties);
  258. this.set('content.serviceConfigProperties', serviceConfigProperties);
  259. //TODO: Uncomment below code to enable slave Configuration
  260. /*
  261. var slaveConfigProperties = [];
  262. stepController.get('stepConfigs').forEach(function (_content) {
  263. if (_content.get('configCategories').someProperty('isForSlaveComponent', true)) {
  264. var slaveCategory = _content.get('configCategories').findProperty('isForSlaveComponent', true);
  265. slaveCategory.get('slaveConfigs.groups').forEach(function (_group) {
  266. _group.get('properties').forEach(function (_property) {
  267. var displayType = _property.get('displayType');
  268. if (displayType === 'directories' || displayType === 'directory') {
  269. var value = _property.get('value').trim().split(/\s+/g).join(',');
  270. _property.set('value', value);
  271. }
  272. _property.set('storeValue', _property.get('value'));
  273. }, this);
  274. }, this);
  275. slaveConfigProperties.pushObject(slaveCategory.get('slaveConfigs'));
  276. }
  277. }, this);
  278. App.db.setSlaveProperties(slaveConfigProperties);
  279. this.set('content.slaveGroupProperties', slaveConfigProperties);
  280. */
  281. },
  282. /**
  283. * Load serviceConfigProperties to model
  284. */
  285. loadServiceConfigProperties: function () {
  286. var serviceConfigProperties = App.db.getServiceConfigProperties();
  287. this.set('content.serviceConfigProperties', serviceConfigProperties);
  288. console.log("InstallerController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  289. this.set('content.advancedServiceConfig', App.db.getAdvancedServiceConfig());
  290. },
  291. /**
  292. * Load information about hosts with clients components
  293. */
  294. loadClients: function () {
  295. var clients = App.db.getClientsForSelectedServices();
  296. this.set('content.clients', clients);
  297. console.log("InstallerController.loadClients: loaded list ", clients);
  298. },
  299. /**
  300. * Generate clients list for selected services and save it to model
  301. * @param stepController step4WizardController
  302. */
  303. saveClients: function (stepController) {
  304. var clients = [];
  305. var serviceComponents = require('data/service_components');
  306. stepController.get('content').filterProperty('isSelected', true).forEach(function (_service) {
  307. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  308. if (client) {
  309. clients.pushObject({
  310. component_name: client.component_name,
  311. display_name: client.display_name,
  312. isInstalled: false
  313. });
  314. }
  315. }, this);
  316. App.db.setClientsForSelectedServices(clients);
  317. this.set('content.clients', clients);
  318. console.log("InstallerController.saveClients: saved list ", clients);
  319. },
  320. /**
  321. * Load data for all steps until <code>current step</code>
  322. */
  323. loadAllPriorSteps: function () {
  324. var step = this.get('currentStep');
  325. switch (step) {
  326. case '10':
  327. case '9':
  328. case '8':
  329. case '7':
  330. this.loadServiceConfigProperties();
  331. // loadSlaveGroupProperties depends on loadSlaveComponentHosts; call loadSlaveComponentHosts first
  332. // this.loadSlaveComponentHosts();
  333. // this.loadSlaveGroupProperties();
  334. case '6':
  335. this.loadSlaveComponentHosts();
  336. this.loadClients();
  337. case '5':
  338. this.loadMasterComponentHosts();
  339. this.loadConfirmedHosts();
  340. case '4':
  341. this.loadServices();
  342. case '3':
  343. this.loadConfirmedHosts();
  344. case '2':
  345. this.load('installOptions');
  346. case '1':
  347. this.load('cluster');
  348. }
  349. },
  350. loadAdvancedConfigs: function () {
  351. var configs = [];
  352. App.db.getSelectedServiceNames().forEach(function (_serviceName) {
  353. var serviceComponents = this.loadAdvancedConfig(_serviceName);
  354. configs = configs.concat(serviceComponents);
  355. }, this);
  356. this.set('content.advancedServiceConfig', configs);
  357. App.db.setAdvancedServiceConfig(configs);
  358. },
  359. /**
  360. * Generate serviceProperties save it to localdata
  361. * called form stepController step6WizardController
  362. */
  363. loadAdvancedConfig: function (serviceName) {
  364. var self = this;
  365. 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
  366. var method = 'GET';
  367. var serviceComponents;
  368. $.ajax({
  369. type: method,
  370. url: url,
  371. async: false,
  372. dataType: 'text',
  373. timeout: App.timeout,
  374. success: function (data) {
  375. var jsonData = jQuery.parseJSON(data);
  376. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  377. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  378. serviceComponents = jsonData.properties;
  379. serviceComponents.setEach('serviceName', serviceName);
  380. console.log('TRACE: servicename: ' + serviceName);
  381. },
  382. error: function (request, ajaxOptions, error) {
  383. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  384. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  385. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  386. console.log('Step6 submit: Error message is: ' + request.responseText);
  387. },
  388. statusCode: require('data/statusCodes')
  389. });
  390. return serviceComponents;
  391. },
  392. /**
  393. * Clear all temporary data
  394. */
  395. finish: function () {
  396. this.setCurrentStep('1');
  397. this.clearStorageData();
  398. }
  399. });