add_controller.js 15 KB

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