installer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 headers = stepController.get('headers');
  160. var formattedHosts = Ember.Object.create();
  161. headers.forEach(function(header) {
  162. formattedHosts.set(header.get('name'), []);
  163. });
  164. hosts.forEach(function (host) {
  165. var checkboxes = host.get('checkboxes');
  166. headers.forEach(function(header) {
  167. var cb = checkboxes.findProperty('title', header.get('label'));
  168. if (cb.get('checked')) {
  169. formattedHosts.get(header.get('name')).push({
  170. hostName: host.hostName,
  171. group: 'Default',
  172. isInstalled: cb.get('installed')
  173. });
  174. }
  175. });
  176. });
  177. var slaveComponentHosts = [];
  178. headers.forEach(function(header) {
  179. slaveComponentHosts.push({
  180. componentName: header.get('name'),
  181. displayName: header.get('label').replace(/\s/g, ''),
  182. hosts: formattedHosts.get(header.get('name'))
  183. });
  184. });
  185. App.db.setSlaveComponentHosts(slaveComponentHosts);
  186. console.log('InstallerController.saveSlaveComponentHosts: saved hosts ', slaveComponentHosts);
  187. this.set('content.slaveComponentHosts', slaveComponentHosts);
  188. },
  189. /**
  190. * Load master component hosts data for using in required step controllers
  191. */
  192. loadSlaveComponentHosts: function () {
  193. var slaveComponentHosts = App.db.getSlaveComponentHosts() || null;
  194. this.set("content.slaveComponentHosts", slaveComponentHosts);
  195. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  196. },
  197. /**
  198. * Save config properties
  199. * @param stepController Step7WizardController
  200. */
  201. saveServiceConfigProperties: function (stepController) {
  202. var serviceConfigProperties = [];
  203. stepController.get('stepConfigs').forEach(function (_content) {
  204. _content.get('configs').forEach(function (_configProperties) {
  205. var displayType = _configProperties.get('displayType');
  206. if (displayType === 'directories' || displayType === 'directory') {
  207. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  208. _configProperties.set('value', value);
  209. }
  210. var overrides = _configProperties.get('overrides');
  211. var overridesArray = [];
  212. if(overrides!=null){
  213. overrides.forEach(function(override){
  214. var overrideEntry = {
  215. value: override.get('value'),
  216. hosts: []
  217. };
  218. override.get('selectedHostOptions').forEach(function(host){
  219. overrideEntry.hosts.push(host);
  220. });
  221. overridesArray.push(overrideEntry);
  222. });
  223. }
  224. var configProperty = {
  225. id: _configProperties.get('id'),
  226. name: _configProperties.get('name'),
  227. value: _configProperties.get('value'),
  228. defaultValue: _configProperties.get('defaultValue'),
  229. service: _configProperties.get('serviceName'),
  230. domain: _configProperties.get('domain'),
  231. filename: _configProperties.get('filename'),
  232. overrides: overridesArray
  233. };
  234. serviceConfigProperties.push(configProperty);
  235. }, this);
  236. }, this);
  237. App.db.setServiceConfigProperties(serviceConfigProperties);
  238. this.set('content.serviceConfigProperties', serviceConfigProperties);
  239. //TODO: Uncomment below code to enable slave Configuration
  240. /*
  241. var slaveConfigProperties = [];
  242. stepController.get('stepConfigs').forEach(function (_content) {
  243. if (_content.get('configCategories').someProperty('isForSlaveComponent', true)) {
  244. var slaveCategory = _content.get('configCategories').findProperty('isForSlaveComponent', true);
  245. slaveCategory.get('slaveConfigs.groups').forEach(function (_group) {
  246. _group.get('properties').forEach(function (_property) {
  247. var displayType = _property.get('displayType');
  248. if (displayType === 'directories' || displayType === 'directory') {
  249. var value = _property.get('value').trim().split(/\s+/g).join(',');
  250. _property.set('value', value);
  251. }
  252. _property.set('storeValue', _property.get('value'));
  253. }, this);
  254. }, this);
  255. slaveConfigProperties.pushObject(slaveCategory.get('slaveConfigs'));
  256. }
  257. }, this);
  258. App.db.setSlaveProperties(slaveConfigProperties);
  259. this.set('content.slaveGroupProperties', slaveConfigProperties);
  260. */
  261. },
  262. /**
  263. * Load serviceConfigProperties to model
  264. */
  265. loadServiceConfigProperties: function () {
  266. var serviceConfigProperties = App.db.getServiceConfigProperties();
  267. this.set('content.serviceConfigProperties', serviceConfigProperties);
  268. console.log("InstallerController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  269. this.set('content.advancedServiceConfig', App.db.getAdvancedServiceConfig());
  270. },
  271. /**
  272. * Load information about hosts with clients components
  273. */
  274. loadClients: function () {
  275. var clients = App.db.getClientsForSelectedServices();
  276. this.set('content.clients', clients);
  277. console.log("InstallerController.loadClients: loaded list ", clients);
  278. },
  279. /**
  280. * Generate clients list for selected services and save it to model
  281. * @param stepController step4WizardController
  282. */
  283. saveClients: function (stepController) {
  284. var clients = [];
  285. var serviceComponents = require('data/service_components');
  286. stepController.get('content').filterProperty('isSelected', true).forEach(function (_service) {
  287. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  288. if (client) {
  289. clients.pushObject({
  290. component_name: client.component_name,
  291. display_name: client.display_name,
  292. isInstalled: false
  293. });
  294. }
  295. }, this);
  296. App.db.setClientsForSelectedServices(clients);
  297. this.set('content.clients', clients);
  298. console.log("InstallerController.saveClients: saved list ", clients);
  299. },
  300. /**
  301. * Load data for all steps until <code>current step</code>
  302. */
  303. loadAllPriorSteps: function () {
  304. var step = this.get('currentStep');
  305. switch (step) {
  306. case '10':
  307. case '9':
  308. case '8':
  309. case '7':
  310. this.loadServiceConfigProperties();
  311. // loadSlaveGroupProperties depends on loadSlaveComponentHosts; call loadSlaveComponentHosts first
  312. // this.loadSlaveComponentHosts();
  313. // this.loadSlaveGroupProperties();
  314. case '6':
  315. this.loadSlaveComponentHosts();
  316. this.loadClients();
  317. case '5':
  318. this.loadMasterComponentHosts();
  319. this.loadConfirmedHosts();
  320. case '4':
  321. this.loadServices();
  322. case '3':
  323. this.loadConfirmedHosts();
  324. case '2':
  325. this.load('installOptions');
  326. case '1':
  327. this.load('cluster');
  328. }
  329. },
  330. loadAdvancedConfigs: function () {
  331. var configs = [];
  332. App.db.getSelectedServiceNames().forEach(function (_serviceName) {
  333. var serviceComponents = this.loadAdvancedConfig(_serviceName);
  334. configs = configs.concat(serviceComponents);
  335. }, this);
  336. this.set('content.advancedServiceConfig', configs);
  337. App.db.setAdvancedServiceConfig(configs);
  338. },
  339. /**
  340. * Generate serviceProperties save it to localdata
  341. * called form stepController step6WizardController
  342. */
  343. loadAdvancedConfig: function (serviceName) {
  344. var self = this;
  345. var url = (App.testMode) ? '/data/wizard/stack/hdp/version01/' + serviceName + '.json' : App.apiPrefix + App.get('stackVersionURL') + '/services/' + serviceName; // TODO: get this url from the stack selected by the user in Install Options page
  346. var method = 'GET';
  347. var serviceComponents;
  348. $.ajax({
  349. type: method,
  350. url: url,
  351. async: false,
  352. dataType: 'text',
  353. timeout: App.timeout,
  354. success: function (data) {
  355. var jsonData = jQuery.parseJSON(data);
  356. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  357. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  358. serviceComponents = jsonData.properties;
  359. serviceComponents.setEach('serviceName', serviceName);
  360. console.log('TRACE: servicename: ' + serviceName);
  361. },
  362. error: function (request, ajaxOptions, error) {
  363. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  364. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  365. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  366. console.log('Step6 submit: Error message is: ' + request.responseText);
  367. },
  368. statusCode: require('data/statusCodes')
  369. });
  370. return serviceComponents;
  371. },
  372. /**
  373. * Clear all temporary data
  374. */
  375. finish: function () {
  376. this.setCurrentStep('1');
  377. this.clearStorageData();
  378. }
  379. });