add_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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.AddHostController = App.WizardController.extend({
  20. name: 'addHostController',
  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, hostSlaveComponents - 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. installOptions: null,
  41. services: null,
  42. slaveComponentHosts: null,
  43. masterComponentHosts: null,
  44. serviceConfigProperties: null,
  45. advancedServiceConfig: null,
  46. controllerName: 'addHostController'
  47. }),
  48. components:require('data/service_components'),
  49. /**
  50. * return new object extended from clusterStatusTemplate
  51. * @return Object
  52. */
  53. getCluster: function(){
  54. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  55. },
  56. /**
  57. * return new object extended from installOptionsTemplate
  58. * @return Object
  59. */
  60. getInstallOptions: function(){
  61. return jQuery.extend({}, this.get('installOptionsTemplate'));
  62. },
  63. /**
  64. * return empty hosts array
  65. * @return Array
  66. */
  67. getHosts: function(){
  68. return [];
  69. },
  70. /**
  71. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  72. * @param hosts Array of hosts, which we want to delete
  73. */
  74. removeHosts: function (hosts) {
  75. //todo Replace this code with real logic
  76. App.db.removeHosts(hosts);
  77. },
  78. /**
  79. * Load services data from server.
  80. */
  81. loadServicesFromServer: function() {
  82. var displayOrderConfig = require('data/services');
  83. var apiUrl = App.get('stackVersionURL');
  84. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  85. //
  86. apiService.forEach(function(item, index){
  87. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  88. apiService[index].isDisabled = apiService[index].isSelected;
  89. apiService[index].isInstalled = apiService[index].isSelected;
  90. });
  91. this.set('content.services', apiService);
  92. App.db.setService(apiService);
  93. },
  94. /**
  95. * Load services data. Will be used at <code>Select services(step4)</code> step
  96. */
  97. loadServices: function () {
  98. var servicesInfo = App.db.getService();
  99. servicesInfo.forEach(function (item, index) {
  100. servicesInfo[index] = Em.Object.create(item);
  101. });
  102. this.set('content.services', servicesInfo);
  103. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  104. var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  105. console.log('selected services ', serviceNames);
  106. this.set('content.skipMasterStep', !serviceNames.contains('HBASE') && !serviceNames.contains('ZOOKEEPER'));
  107. },
  108. /**
  109. * Load master component hosts data for using in required step controllers
  110. */
  111. loadMasterComponentHosts: function () {
  112. var masterComponentHosts = App.db.getMasterComponentHosts();
  113. if (!masterComponentHosts) {
  114. masterComponentHosts = [];
  115. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  116. masterComponentHosts.push({
  117. component: item.get('componentName'),
  118. hostName: item.get('host.hostName'),
  119. isInstalled: true,
  120. serviceId: item.get('service.id'),
  121. display_name: item.get('displayName')
  122. })
  123. });
  124. App.db.setMasterComponentHosts(masterComponentHosts);
  125. }
  126. this.set("content.masterComponentHosts", masterComponentHosts);
  127. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  128. },
  129. /**
  130. * Save HBase and ZooKeeper to main controller
  131. * @param stepController
  132. */
  133. saveHbZk: function(stepController) {
  134. var self = this;
  135. var hosts = stepController.get('hosts');
  136. var headers = stepController.get('headers');
  137. var masterComponentHosts = App.db.getMasterComponentHosts();
  138. headers.forEach(function(header) {
  139. var rm = masterComponentHosts.filterProperty('component', header.get('name'));
  140. if(rm) {
  141. masterComponentHosts.removeObjects(rm);
  142. }
  143. });
  144. headers.forEach(function(header) {
  145. var component = self.get('components').findProperty('component_name', header.get('name'));
  146. hosts.forEach(function(host) {
  147. if (host.get('checkboxes').findProperty('title', component.display_name).checked) {
  148. masterComponentHosts .push({
  149. display_name: component.display_name,
  150. component: component.component_name,
  151. hostName: host.get('hostName'),
  152. serviceId: component.service_name,
  153. isInstalled: false
  154. });
  155. }
  156. });
  157. });
  158. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  159. App.db.setMasterComponentHosts(masterComponentHosts);
  160. this.set('content.masterComponentHosts', masterComponentHosts);
  161. },
  162. /**
  163. * return slaveComponents bound to hosts
  164. * @return {Array}
  165. */
  166. getSlaveComponentHosts: function () {
  167. var components = [
  168. {
  169. name: 'DATANODE',
  170. service: 'HDFS'
  171. },
  172. {
  173. name: 'TASKTRACKER',
  174. service: 'MAPREDUCE'
  175. },
  176. {
  177. name: 'HBASE_REGIONSERVER',
  178. service: 'HBASE'
  179. }
  180. ];
  181. var result = [];
  182. var services = App.Service.find();
  183. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  184. for (var index = 0; index < components.length; index++) {
  185. var comp = components[index];
  186. if (!selectedServices.contains(comp.service)) {
  187. continue;
  188. }
  189. var service = services.findProperty('id', comp.service);
  190. var hosts = [];
  191. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  192. hosts.push({
  193. group: "Default",
  194. hostName: host_component.get('host.id'),
  195. isInstalled: true
  196. });
  197. }, this);
  198. result.push({
  199. componentName: comp.name,
  200. displayName: App.format.role(comp.name),
  201. hosts: hosts,
  202. isInstalled: true
  203. })
  204. }
  205. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  206. var hosts = [];
  207. clientsHosts.forEach(function (host_component) {
  208. hosts.push({
  209. group: "Default",
  210. hostName: host_component.get('host.id'),
  211. isInstalled: true
  212. });
  213. }, this);
  214. result.push({
  215. componentName: 'CLIENT',
  216. displayName: 'client',
  217. hosts: hosts,
  218. isInstalled: true
  219. })
  220. return result;
  221. },
  222. /**
  223. * Load master component hosts data for using in required step controllers
  224. */
  225. loadSlaveComponentHosts: function () {
  226. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  227. if (!slaveComponentHosts) {
  228. slaveComponentHosts = this.getSlaveComponentHosts();
  229. }
  230. this.set("content.slaveComponentHosts", slaveComponentHosts);
  231. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  232. },
  233. /**
  234. * Save config properties
  235. * @param stepController Step7WizardController
  236. */
  237. saveServiceConfigProperties: function (stepController) {
  238. var serviceConfigProperties = [];
  239. stepController.get('stepConfigs').forEach(function (_content) {
  240. _content.get('configs').forEach(function (_configProperties) {
  241. var displayType = _configProperties.get('displayType');
  242. if (displayType === 'directories' || displayType === 'directory') {
  243. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  244. _configProperties.set('value', value);
  245. }
  246. var configProperty = {
  247. id: _configProperties.get('id'),
  248. name: _configProperties.get('name'),
  249. value: _configProperties.get('value'),
  250. defaultValue: _configProperties.get('defaultValue'),
  251. service: _configProperties.get('serviceName'),
  252. domain: _configProperties.get('domain'),
  253. filename: _configProperties.get('filename')
  254. };
  255. serviceConfigProperties.push(configProperty);
  256. }, this);
  257. }, this);
  258. App.db.setServiceConfigProperties(serviceConfigProperties);
  259. this.set('content.serviceConfigProperties', serviceConfigProperties);
  260. },
  261. /**
  262. * Load serviceConfigProperties to model
  263. */
  264. loadServiceConfigProperties: function () {
  265. var serviceConfigProperties = App.db.getServiceConfigProperties();
  266. this.set('content.serviceConfigProperties', serviceConfigProperties);
  267. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  268. },
  269. /**
  270. * Load information about hosts with clients components
  271. */
  272. loadClients: function () {
  273. var clients = App.db.getClientsForSelectedServices();
  274. this.set('content.clients', clients);
  275. console.log("AddHostController.loadClients: loaded list ", clients);
  276. },
  277. /**
  278. * Generate clients list for selected services and save it to model
  279. * @param stepController step4WizardController
  280. */
  281. saveClients: function () {
  282. var clients = [];
  283. var serviceComponents = require('data/service_components');
  284. var hostComponents = App.HostComponent.find();
  285. this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) {
  286. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  287. if (client) {
  288. clients.pushObject({
  289. component_name: client.component_name,
  290. display_name: client.display_name,
  291. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  292. });
  293. }
  294. }, this);
  295. App.db.setClientsForSelectedServices(clients);
  296. this.set('content.clients', clients);
  297. console.log("AddHostController.saveClients: saved list ", clients);
  298. },
  299. /**
  300. * Load data for all steps until <code>current step</code>
  301. */
  302. loadAllPriorSteps: function () {
  303. var step = this.get('currentStep');
  304. switch (step) {
  305. case '9':
  306. case '8':
  307. case '7':
  308. case '6':
  309. case '5':
  310. this.loadServiceConfigProperties();
  311. case '4':
  312. case '3':
  313. this.loadClients();
  314. this.loadServices();
  315. this.loadMasterComponentHosts();
  316. this.loadSlaveComponentHosts();
  317. this.load('hosts');
  318. case '2':
  319. this.loadServices();
  320. case '1':
  321. this.load('hosts');
  322. this.load('installOptions');
  323. this.load('cluster');
  324. }
  325. },
  326. /**
  327. * load advanced configs for all selected services
  328. */
  329. loadAdvancedConfigs: function () {
  330. this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName').forEach(function (_serviceName) {
  331. this.loadAdvancedConfig(_serviceName);
  332. }, this);
  333. },
  334. /**
  335. * load advanced config for one service
  336. * @param serviceName
  337. */
  338. loadAdvancedConfig: function (serviceName) {
  339. var self = this;
  340. 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
  341. var method = 'GET';
  342. $.ajax({
  343. type: method,
  344. url: url,
  345. async: false,
  346. dataType: 'text',
  347. timeout: App.timeout,
  348. success: function (data) {
  349. var jsonData = jQuery.parseJSON(data);
  350. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  351. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  352. var serviceComponents = jsonData.properties;
  353. serviceComponents.setEach('serviceName', serviceName);
  354. var configs;
  355. if (App.db.getAdvancedServiceConfig()) {
  356. configs = App.db.getAdvancedServiceConfig();
  357. } else {
  358. configs = [];
  359. }
  360. configs = configs.concat(serviceComponents);
  361. self.set('content.advancedServiceConfig', configs);
  362. App.db.setAdvancedServiceConfig(configs);
  363. console.log('TRACE: servicename: ' + serviceName);
  364. },
  365. error: function (request, ajaxOptions, error) {
  366. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  367. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  368. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  369. console.log('Step6 submit: Error message is: ' + request.responseText);
  370. },
  371. statusCode: require('data/statusCodes')
  372. });
  373. },
  374. /**
  375. * Remove all loaded data.
  376. * Created as copy for App.router.clearAllSteps
  377. */
  378. clearAllSteps: function () {
  379. this.clearInstallOptions();
  380. // clear temporary information stored during the install
  381. this.set('content.cluster', this.getCluster());
  382. },
  383. /**
  384. * Clear all temporary data
  385. */
  386. finish: function () {
  387. this.setCurrentStep('1');
  388. this.clearAllSteps();
  389. this.clearStorageData();
  390. App.router.get('updateController').updateAll();
  391. }
  392. });