add_controller.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. serviceConfigs:require('data/service_configs'),
  22. totalSteps: 7,
  23. /**
  24. * Used for hiding back button in wizard
  25. */
  26. hideBackButton: true,
  27. /**
  28. * All wizards data will be stored in this variable
  29. *
  30. * cluster - cluster name
  31. * installOptions - ssh key, repo info, etc.
  32. * services - services list
  33. * hosts - list of selected hosts
  34. * slaveComponentHosts, - info about slave hosts
  35. * masterComponentHosts - info about master hosts
  36. * config??? - to be described later
  37. */
  38. content: Em.Object.create({
  39. cluster: null,
  40. hosts: null,
  41. installOptions: null,
  42. services: null,
  43. slaveComponentHosts: null,
  44. masterComponentHosts: null,
  45. serviceConfigProperties: null,
  46. advancedServiceConfig: null,
  47. controllerName: 'addServiceController'
  48. }),
  49. setCurrentStep: function (currentStep, completed) {
  50. this._super(currentStep, completed);
  51. App.clusterStatus.setClusterStatus({
  52. wizardControllerName: this.get('name'),
  53. localdb: App.db.data
  54. });
  55. },
  56. /**
  57. * return new object extended from clusterStatusTemplate
  58. * @return Object
  59. */
  60. getCluster: function(){
  61. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  62. },
  63. /**
  64. * Load confirmed hosts.
  65. * Will be used at <code>Assign Masters(step5)</code> step
  66. */
  67. loadConfirmedHosts: function(){
  68. var hosts = this.getDBProperty('hosts');
  69. if(!hosts){
  70. var hosts = {};
  71. App.Host.find().forEach(function(item){
  72. hosts[item.get('id')] = {
  73. name: item.get('id'),
  74. cpu: item.get('cpu'),
  75. memory: item.get('memory'),
  76. disk_info: item.get('diskInfo'),
  77. bootStatus: "REGISTERED",
  78. isInstalled: true
  79. };
  80. });
  81. this.setDBProperty('hosts', hosts);
  82. }
  83. this.set('content.hosts', hosts);
  84. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  85. },
  86. /**
  87. * Load services data from server.
  88. */
  89. loadServicesFromServer: function() {
  90. if(this.getDBProperty('service')){
  91. return;
  92. }
  93. var displayOrderConfig = require('data/services');
  94. var apiUrl = App.get('stack2VersionURL');
  95. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  96. //
  97. apiService.forEach(function(item, index){
  98. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  99. apiService[index].isDisabled = apiService[index].isSelected;
  100. apiService[index].isInstalled = apiService[index].isSelected;
  101. });
  102. this.set('content.services', apiService);
  103. this.setDBProperty('service', apiService);
  104. },
  105. /**
  106. * Load services data. Will be used at <code>Select services(step4)</code> step
  107. */
  108. loadServices: function () {
  109. var servicesInfo = this.getDBProperty('service');
  110. servicesInfo.forEach(function (item, index) {
  111. servicesInfo[index] = Em.Object.create(item);
  112. });
  113. this.set('content.services', servicesInfo);
  114. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  115. var serviceNames = servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  116. console.log('selected services ', serviceNames);
  117. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  118. if (this.get('content.skipSlavesStep')) {
  119. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  120. }
  121. },
  122. /**
  123. * Save data to model
  124. * @param stepController App.WizardStep4Controller
  125. */
  126. saveServices: function (stepController) {var serviceNames = [];
  127. this.setDBProperty('service', stepController.get('content'));
  128. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  129. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  130. serviceNames.push(item.serviceName);
  131. });
  132. this.set('content.selectedServiceNames', serviceNames);
  133. this.setDBProperty('selectedServiceNames',serviceNames);
  134. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  135. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  136. if (this.get('content.skipSlavesStep')) {
  137. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  138. }
  139. },
  140. /**
  141. * Save Master Component Hosts data to Main Controller
  142. * @param stepController App.WizardStep5Controller
  143. */
  144. saveMasterComponentHosts: function (stepController) {
  145. var obj = stepController.get('selectedServicesMasters');
  146. var masterComponentHosts = [];
  147. var installedComponents = App.HostComponent.find();
  148. obj.forEach(function (_component) {
  149. masterComponentHosts.push({
  150. display_name: _component.display_name,
  151. component: _component.component_name,
  152. hostName: _component.selectedHost,
  153. serviceId: _component.serviceId,
  154. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  155. });
  156. });
  157. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  158. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  159. this.set('content.masterComponentHosts', masterComponentHosts);
  160. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  161. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  162. },
  163. /**
  164. * Load master component hosts data for using in required step controllers
  165. */
  166. loadMasterComponentHosts: function () {
  167. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  168. if(!masterComponentHosts){
  169. masterComponentHosts = [];
  170. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  171. masterComponentHosts.push({
  172. component: item.get('componentName'),
  173. hostName: item.get('host.hostName'),
  174. isInstalled: true
  175. })
  176. });
  177. }
  178. this.set("content.masterComponentHosts", masterComponentHosts);
  179. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  180. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  181. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  182. },
  183. /**
  184. * Does service have any configs
  185. * @param {string} serviceName
  186. * @returns {boolean}
  187. */
  188. isServiceConfigurable: function(serviceName) {
  189. return this.get('serviceConfigs').mapProperty('serviceName').contains(serviceName);
  190. },
  191. /**
  192. * Should Config Step be skipped (based on selected services list)
  193. * @returns {boolean}
  194. */
  195. skipConfigStep: function() {
  196. var skipConfigStep = true;
  197. var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  198. selectedServices.map(function(serviceName) {
  199. skipConfigStep = skipConfigStep && !this.isServiceConfigurable(serviceName);
  200. }, this);
  201. return skipConfigStep;
  202. },
  203. loadServiceConfigProperties: function() {
  204. this._super();
  205. if (!this.get('content.services')) {
  206. this.loadServices();
  207. }
  208. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  209. this.set('content.skipConfigStep', this.skipConfigStep());
  210. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  211. }
  212. },
  213. saveServiceConfigProperties: function(stepController) {
  214. this._super(stepController);
  215. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  216. this.set('content.skipConfigStep', this.skipConfigStep());
  217. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  218. }
  219. },
  220. /**
  221. * return slaveComponents bound to hosts
  222. * @return {Array}
  223. */
  224. getSlaveComponentHosts: function () {
  225. var components = [{
  226. name : 'DATANODE',
  227. service : 'HDFS'
  228. },
  229. {
  230. name: 'TASKTRACKER',
  231. service: 'MAPREDUCE'
  232. },
  233. {
  234. name: 'HBASE_REGIONSERVER',
  235. service: 'HBASE'
  236. }];
  237. if (App.get('isHadoop2Stack')) {
  238. components.push({
  239. name: 'NODEMANAGER',
  240. service: 'YARN'
  241. });
  242. }
  243. var result = [];
  244. var services = App.Service.find();
  245. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  246. for(var index=0; index < components.length; index++){
  247. var comp = components[index];
  248. if(!selectedServices.contains(comp.service)){
  249. continue;
  250. }
  251. var service = services.findProperty('id', comp.service);
  252. var hosts = [];
  253. if(!service){
  254. service = services.findProperty('id', 'HDFS');
  255. service.get('hostComponents').filterProperty('componentName', 'DATANODE').forEach(function (host_component) {
  256. hosts.push({
  257. group: "Default",
  258. hostName: host_component.get('host.id'),
  259. isInstalled: false
  260. });
  261. }, this);
  262. } else {
  263. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  264. hosts.push({
  265. group: "Default",
  266. hostName: host_component.get('host.id'),
  267. isInstalled: true
  268. });
  269. }, this);
  270. }
  271. result.push({
  272. componentName: comp.name,
  273. displayName: App.format.role(comp.name),
  274. hosts: hosts
  275. })
  276. }
  277. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  278. var hosts = [];
  279. clientsHosts.forEach(function (host_component) {
  280. hosts.push({
  281. group: "Default",
  282. hostName: host_component.get('host.id'),
  283. isInstalled: true
  284. });
  285. }, this);
  286. result.push({
  287. componentName: 'CLIENT',
  288. displayName: 'client',
  289. hosts: hosts
  290. });
  291. return result;
  292. },
  293. /**
  294. * Load master component hosts data for using in required step controllers
  295. */
  296. loadSlaveComponentHosts: function () {
  297. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts');
  298. if(!slaveComponentHosts){
  299. slaveComponentHosts = this.getSlaveComponentHosts();
  300. }
  301. this.set("content.slaveComponentHosts", slaveComponentHosts);
  302. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  303. },
  304. /**
  305. * Load information about hosts with clients components
  306. */
  307. loadClients: function(){
  308. var clients = this.getDBProperty('clientInfo');
  309. this.set('content.clients', clients);
  310. console.log("AddServiceController.loadClients: loaded list ", clients);
  311. },
  312. /**
  313. * Generate clients list for selected services and save it to model
  314. * @param stepController step4WizardController
  315. */
  316. saveClients: function(stepController){
  317. var clients = [];
  318. var serviceComponents = require('data/service_components');
  319. var hostComponents = App.HostComponent.find();
  320. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  321. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  322. if (client) {
  323. clients.pushObject({
  324. component_name: client.component_name,
  325. display_name: client.display_name,
  326. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  327. });
  328. }
  329. }, this);
  330. this.setDBProperty('clientInfo', clients);
  331. this.set('content.clients', clients);
  332. console.log("AddServiceController.saveClients: saved list ", clients);
  333. },
  334. /**
  335. * Load data for all steps until <code>current step</code>
  336. */
  337. loadAllPriorSteps: function () {
  338. var step = this.get('currentStep');
  339. switch (step) {
  340. case '7':
  341. case '6':
  342. case '5':
  343. this.load('cluster');
  344. case '4':
  345. this.loadServiceConfigProperties();
  346. case '3':
  347. this.loadServices();
  348. this.loadClients();
  349. this.loadSlaveComponentHosts();//depends on loadServices
  350. case '2':
  351. this.loadMasterComponentHosts();
  352. this.loadConfirmedHosts();
  353. case '1':
  354. this.loadServices();
  355. }
  356. },
  357. /**
  358. * Remove all loaded data.
  359. * Created as copy for App.router.clearAllSteps
  360. */
  361. clearAllSteps: function () {
  362. this.clearInstallOptions();
  363. // clear temporary information stored during the install
  364. this.set('content.cluster', this.getCluster());
  365. },
  366. /**
  367. * Clear all temporary data
  368. */
  369. finish: function () {
  370. this.setCurrentStep('1');
  371. this.clearAllSteps();
  372. this.clearStorageData();
  373. App.router.get('updateController').updateAll();
  374. },
  375. installServices: function (isRetry) {
  376. this.set('content.cluster.oldRequestsId', []);
  377. var clusterName = this.get('content.cluster.name');
  378. var data;
  379. var name;
  380. if (isRetry) {
  381. this.getFailedHostComponents();
  382. console.log('failedHostComponents', this.get('failedHostComponents'));
  383. name = 'wizard.install_services.installer_controller.is_retry';
  384. data = {
  385. "RequestInfo": {
  386. "context" : Em.I18n.t('requestInfo.installComponents'),
  387. "query": "HostRoles/component_name.in(" + this.get('failedHostComponents').join(',') + ")"
  388. },
  389. "Body": {
  390. "HostRoles": {
  391. "state": "INSTALLED"
  392. }
  393. }
  394. };
  395. data = JSON.stringify(data);
  396. }
  397. else {
  398. name = 'wizard.install_services.installer_controller.not_is_retry';
  399. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  400. }
  401. App.ajax.send({
  402. name: name,
  403. sender: this,
  404. data: {
  405. data: data,
  406. cluster: clusterName
  407. },
  408. success: 'installServicesSuccessCallback',
  409. error: 'installServicesErrorCallback'
  410. });
  411. },
  412. /**
  413. * List of failed to install HostComponents while adding Service
  414. */
  415. failedHostComponents: [],
  416. getFailedHostComponents: function() {
  417. App.ajax.send({
  418. name: 'wizard.install_services.add_service_controller.get_failed_host_components',
  419. sender: this,
  420. success: 'getFailedHostComponentsSuccessCallback',
  421. error: 'getFailedHostComponentsErrorCallback'
  422. });
  423. },
  424. /**
  425. * Parse all failed components and filter out installed earlier components (based on selected to install services)
  426. * @param {Object} json
  427. */
  428. getFailedHostComponentsSuccessCallback: function(json) {
  429. var allFailed = json.items.filterProperty('HostRoles.state', 'INSTALL_FAILED');
  430. var currentFailed = [];
  431. var selectedServices = this.getDBProperty('service').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  432. allFailed.forEach(function(failed) {
  433. if (selectedServices.contains(failed.component[0].ServiceComponentInfo.service_name)) {
  434. currentFailed.push(failed.HostRoles.component_name);
  435. }
  436. });
  437. this.set('failedHostComponents', currentFailed);
  438. },
  439. getFailedHostComponentsErrorCallback: function(request, ajaxOptions, error) {
  440. console.warn(error);
  441. }
  442. });