add_controller.js 16 KB

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