add_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. * Load master component hosts data for using in required step controllers
  223. */
  224. loadSlaveComponentHosts: function () {
  225. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts');
  226. if(!slaveComponentHosts){
  227. slaveComponentHosts = this.getSlaveComponentHosts();
  228. }
  229. this.set("content.slaveComponentHosts", slaveComponentHosts);
  230. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  231. },
  232. /**
  233. * Load information about hosts with clients components
  234. */
  235. loadClients: function(){
  236. var clients = this.getDBProperty('clientInfo');
  237. this.set('content.clients', clients);
  238. console.log("AddServiceController.loadClients: loaded list ", clients);
  239. },
  240. /**
  241. * Generate clients list for selected services and save it to model
  242. * @param stepController step4WizardController
  243. */
  244. saveClients: function(stepController){
  245. var clients = [];
  246. var serviceComponents = require('data/service_components');
  247. var hostComponents = App.HostComponent.find();
  248. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  249. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  250. if (client) {
  251. clients.pushObject({
  252. component_name: client.component_name,
  253. display_name: client.display_name,
  254. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  255. });
  256. }
  257. }, this);
  258. this.setDBProperty('clientInfo', clients);
  259. this.set('content.clients', clients);
  260. console.log("AddServiceController.saveClients: saved list ", clients);
  261. },
  262. /**
  263. * Load data for all steps until <code>current step</code>
  264. */
  265. loadAllPriorSteps: function () {
  266. var step = this.get('currentStep');
  267. switch (step) {
  268. case '7':
  269. case '6':
  270. case '5':
  271. this.load('cluster');
  272. case '4':
  273. this.loadServiceConfigGroups();
  274. this.loadServiceConfigProperties();
  275. case '3':
  276. this.loadServices();
  277. this.loadClients();
  278. this.loadSlaveComponentHosts();//depends on loadServices
  279. case '2':
  280. this.loadMasterComponentHosts();
  281. this.loadConfirmedHosts();
  282. case '1':
  283. this.loadServices();
  284. }
  285. },
  286. /**
  287. * Remove all loaded data.
  288. * Created as copy for App.router.clearAllSteps
  289. */
  290. clearAllSteps: function () {
  291. this.clearInstallOptions();
  292. // clear temporary information stored during the install
  293. this.set('content.cluster', this.getCluster());
  294. },
  295. /**
  296. * Clear all temporary data
  297. */
  298. finish: function () {
  299. this.setCurrentStep('1');
  300. this.clearAllSteps();
  301. this.clearStorageData();
  302. App.router.get('updateController').updateAll();
  303. },
  304. installServices: function (isRetry) {
  305. this.set('content.cluster.oldRequestsId', []);
  306. var clusterName = this.get('content.cluster.name');
  307. var data;
  308. var name;
  309. if (isRetry) {
  310. this.getFailedHostComponents();
  311. console.log('failedHostComponents', this.get('failedHostComponents'));
  312. name = 'wizard.install_services.installer_controller.is_retry';
  313. data = {
  314. "RequestInfo": {
  315. "context" : Em.I18n.t('requestInfo.installComponents'),
  316. "query": "HostRoles/component_name.in(" + this.get('failedHostComponents').join(',') + ")"
  317. },
  318. "Body": {
  319. "HostRoles": {
  320. "state": "INSTALLED"
  321. }
  322. }
  323. };
  324. data = JSON.stringify(data);
  325. }
  326. else {
  327. name = 'wizard.install_services.installer_controller.not_is_retry';
  328. data = '{"RequestInfo": {"context" :"' + Em.I18n.t('requestInfo.installServices') + '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
  329. }
  330. App.ajax.send({
  331. name: name,
  332. sender: this,
  333. data: {
  334. data: data,
  335. cluster: clusterName
  336. },
  337. success: 'installServicesSuccessCallback',
  338. error: 'installServicesErrorCallback'
  339. });
  340. },
  341. /**
  342. * List of failed to install HostComponents while adding Service
  343. */
  344. failedHostComponents: [],
  345. getFailedHostComponents: function() {
  346. App.ajax.send({
  347. name: 'wizard.install_services.add_service_controller.get_failed_host_components',
  348. sender: this,
  349. success: 'getFailedHostComponentsSuccessCallback',
  350. error: 'getFailedHostComponentsErrorCallback'
  351. });
  352. },
  353. /**
  354. * Parse all failed components and filter out installed earlier components (based on selected to install services)
  355. * @param {Object} json
  356. */
  357. getFailedHostComponentsSuccessCallback: function(json) {
  358. var allFailed = json.items.filterProperty('HostRoles.state', 'INSTALL_FAILED');
  359. var currentFailed = [];
  360. var selectedServices = this.getDBProperty('service').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  361. allFailed.forEach(function(failed) {
  362. if (selectedServices.contains(failed.component[0].ServiceComponentInfo.service_name)) {
  363. currentFailed.push(failed.HostRoles.component_name);
  364. }
  365. });
  366. this.set('failedHostComponents', currentFailed);
  367. },
  368. getFailedHostComponentsErrorCallback: function(request, ajaxOptions, error) {
  369. console.warn(error);
  370. }
  371. });