add_controller.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. configGroups: [],
  48. clients: [],
  49. additionalClients: []
  50. }),
  51. setCurrentStep: function (currentStep, completed) {
  52. this._super(currentStep, completed);
  53. App.clusterStatus.setClusterStatus({
  54. wizardControllerName: this.get('name'),
  55. localdb: App.db.data
  56. });
  57. },
  58. /**
  59. * Load services data. Will be used at <code>Select services(step4)</code> step
  60. */
  61. loadServices: function () {
  62. var services = this.getDBProperty('services');
  63. if (!services) {
  64. services = {
  65. selectedServices: [],
  66. installedServices: []
  67. };
  68. App.StackService.find().forEach(function (item) {
  69. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  70. item.set('isSelected', isInstalled);
  71. item.set('isInstalled', isInstalled);
  72. if (isInstalled) {
  73. services.selectedServices.push(item.get('serviceName'));
  74. services.installedServices.push(item.get('serviceName'));
  75. }
  76. }, this);
  77. this.setDBProperty('services', services);
  78. } else {
  79. App.StackService.find().forEach(function (item) {
  80. var isSelected = services.selectedServices.contains(item.get('serviceName'));
  81. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  82. item.set('isSelected', isSelected);
  83. item.set('isInstalled', isInstalled);
  84. }, this);
  85. var isServiceWithSlave = App.StackService.find().filterProperty('isSelected').filterProperty('hasSlave').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  86. var isServiceWithClient = App.StackService.find().filterProperty('isSelected').filterProperty('hasClient').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  87. this.set('content.skipSlavesStep', !isServiceWithSlave && !isServiceWithClient);
  88. if (this.get('content.skipSlavesStep')) {
  89. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  90. }
  91. }
  92. this.set('content.services', App.StackService.find());
  93. },
  94. /**
  95. * Save data to model
  96. * @param stepController App.WizardStep4Controller
  97. */
  98. saveServices: function (stepController) {
  99. var services = {
  100. selectedServices: [],
  101. installedServices: []
  102. };
  103. var selectedServices = stepController.get('content').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  104. services.selectedServices.pushObjects(selectedServices);
  105. services.installedServices.pushObjects(stepController.get('content').filterProperty('isInstalled', true).mapProperty('serviceName'));
  106. this.setDBProperty('services', services);
  107. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  108. this.set('content.selectedServiceNames', selectedServices);
  109. this.setDBProperty('selectedServiceNames', selectedServices);
  110. var isServiceWithSlave = stepController.get('content').filterProperty('isSelected').filterProperty('hasSlave').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  111. var isServiceWithClient = App.StackService.find().filterProperty('isSelected').filterProperty('hasClient').filterProperty('isInstalled', false).mapProperty('serviceName').length;
  112. this.set('content.skipSlavesStep', !isServiceWithSlave && !isServiceWithClient);
  113. if (this.get('content.skipSlavesStep')) {
  114. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  115. }
  116. },
  117. /**
  118. * Save Master Component Hosts data to Main Controller
  119. * @param stepController App.WizardStep5Controller
  120. */
  121. saveMasterComponentHosts: function (stepController) {
  122. var obj = stepController.get('selectedServicesMasters');
  123. var masterComponentHosts = [];
  124. var installedComponents = App.HostComponent.find();
  125. obj.forEach(function (_component) {
  126. masterComponentHosts.push({
  127. display_name: _component.display_name,
  128. component: _component.component_name,
  129. hostName: _component.selectedHost,
  130. serviceId: _component.serviceId,
  131. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  132. });
  133. });
  134. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  135. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  136. this.set('content.masterComponentHosts', masterComponentHosts);
  137. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  138. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  139. },
  140. /**
  141. * Load master component hosts data for using in required step controllers
  142. */
  143. loadMasterComponentHosts: function () {
  144. this._super();
  145. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  146. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  147. },
  148. /**
  149. * Does service have any configs
  150. * @param {string} serviceName
  151. * @returns {boolean}
  152. */
  153. isServiceNotConfigurable: function (serviceName) {
  154. return App.get('services.noConfigTypes').contains(serviceName);
  155. },
  156. /**
  157. * Should Config Step be skipped (based on selected services list)
  158. * @returns {boolean}
  159. */
  160. skipConfigStep: function () {
  161. var skipConfigStep = true;
  162. var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  163. selectedServices.map(function (serviceName) {
  164. skipConfigStep = skipConfigStep && this.isServiceNotConfigurable(serviceName);
  165. }, this);
  166. return skipConfigStep;
  167. },
  168. loadServiceConfigProperties: function () {
  169. this._super();
  170. if (!this.get('content.services')) {
  171. this.loadServices();
  172. }
  173. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  174. this.set('content.skipConfigStep', this.skipConfigStep());
  175. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  176. }
  177. },
  178. saveServiceConfigProperties: function (stepController) {
  179. this._super(stepController);
  180. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  181. this.set('content.skipConfigStep', this.skipConfigStep());
  182. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  183. }
  184. },
  185. /**
  186. * Load master component hosts data for using in required step controllers
  187. */
  188. loadSlaveComponentHosts: function () {
  189. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts'),
  190. hosts = this.getDBProperty('hosts'),
  191. host_names = Em.keys(hosts);
  192. if (!Em.isNone(slaveComponentHosts)) {
  193. slaveComponentHosts.forEach(function (component) {
  194. component.hosts.forEach(function (host) {
  195. //Em.set(host, 'hostName', hosts[host.host_id].name);
  196. for (var i = 0; i < host_names.length; i++) {
  197. if (hosts[host_names[i]].id === host.host_id) {
  198. host.hostName = host_names[i];
  199. break;
  200. }
  201. }
  202. });
  203. });
  204. }
  205. if (!slaveComponentHosts) {
  206. slaveComponentHosts = this.getSlaveComponentHosts();
  207. }
  208. this.set("content.slaveComponentHosts", slaveComponentHosts);
  209. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  210. },
  211. /**
  212. * return slaveComponents bound to hosts
  213. * @return {Array}
  214. */
  215. getSlaveComponentHosts: function () {
  216. var components = this.get('slaveComponents');
  217. var result = [];
  218. var installedServices = App.Service.find().mapProperty('serviceName');
  219. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  220. var installedComponentsMap = {};
  221. var uninstalledComponents = [];
  222. var hosts = this.get('content.hosts');
  223. components.forEach(function (component) {
  224. if (installedServices.contains(component.get('serviceName'))) {
  225. installedComponentsMap[component.get('componentName')] = [];
  226. } else if (selectedServices.contains(component.get('serviceName'))) {
  227. uninstalledComponents.push(component);
  228. }
  229. }, this);
  230. for (var hostName in hosts) {
  231. if (hosts[hostName].isInstalled) {
  232. hosts[hostName].hostComponents.forEach(function (component) {
  233. if (installedComponentsMap[component.HostRoles.component_name]) {
  234. installedComponentsMap[component.HostRoles.component_name].push(hostName);
  235. }
  236. }, this);
  237. }
  238. }
  239. for (var componentName in installedComponentsMap) {
  240. var component = {
  241. componentName: componentName,
  242. displayName: App.format.role(componentName),
  243. hosts: [],
  244. isInstalled: true
  245. };
  246. installedComponentsMap[componentName].forEach(function (hostName) {
  247. component.hosts.push({
  248. group: "Default",
  249. hostName: hostName,
  250. isInstalled: true
  251. });
  252. }, this);
  253. result.push(component);
  254. }
  255. uninstalledComponents.forEach(function (component) {
  256. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  257. hosts.setEach('isInstalled', false);
  258. result.push({
  259. componentName: component.get('componentName'),
  260. displayName: App.format.role(component.get('componentName')),
  261. hosts: hosts,
  262. isInstalled: false
  263. })
  264. });
  265. return result;
  266. },
  267. /**
  268. * Generate clients list for selected services and save it to model
  269. * @param stepController step4WizardController
  270. */
  271. saveClients: function (stepController) {
  272. var clients = [];
  273. var serviceComponents = App.StackServiceComponent.find();
  274. this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled',false).forEach(function (_service) {
  275. var serviceClients = serviceComponents.filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
  276. serviceClients.forEach(function (client) {
  277. clients.push({
  278. component_name: client.get('componentName'),
  279. display_name: client.get('displayName'),
  280. isInstalled: false
  281. });
  282. }, this);
  283. }, this);
  284. this.setDBProperty('clientInfo', clients);
  285. this.set('content.clients', clients);
  286. console.log("AddServiceController.saveClients: saved list ", clients);
  287. },
  288. /**
  289. * Load data for all steps until <code>current step</code>
  290. */
  291. loadAllPriorSteps: function () {
  292. var step = this.get('currentStep');
  293. switch (step) {
  294. case '7':
  295. case '6':
  296. case '5':
  297. this.load('cluster');
  298. this.set('content.additionalClients', []);
  299. case '4':
  300. this.loadServiceConfigGroups();
  301. this.loadServiceConfigProperties();
  302. case '3':
  303. this.loadServices();
  304. this.loadClients();
  305. this.loadSlaveComponentHosts();//depends on loadServices
  306. case '2':
  307. this.loadMasterComponentHosts();
  308. this.load('hosts');
  309. case '1':
  310. this.loadServices();
  311. }
  312. },
  313. /**
  314. * Remove all loaded data.
  315. * Created as copy for App.router.clearAllSteps
  316. */
  317. clearAllSteps: function () {
  318. this.clearInstallOptions();
  319. // clear temporary information stored during the install
  320. this.set('content.cluster', this.getCluster());
  321. },
  322. /**
  323. * Clear all temporary data
  324. */
  325. finish: function () {
  326. this.clearAllSteps();
  327. this.clearStorageData();
  328. this.resetDbNamespace();
  329. App.router.get('updateController').updateAll();
  330. },
  331. installServices: function (callback) {
  332. this.set('content.cluster.oldRequestsId', []);
  333. this.installAdditionalClients();
  334. var selectedServices = this.get('content.services').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  335. var name = 'common.services.update';
  336. var data = {
  337. "context": Em.I18n.t('requestInfo.installServices'),
  338. "ServiceInfo": {"state": "INSTALLED"},
  339. "urlParams": "ServiceInfo/service_name.in(" + selectedServices.join(',') + ")"
  340. };
  341. this.installServicesRequest(name, data, callback);
  342. },
  343. installServicesRequest: function (name, data, callback) {
  344. callback = callback || Em.K;
  345. App.ajax.send({
  346. name: name,
  347. sender: this,
  348. data: data,
  349. success: 'installServicesSuccessCallback',
  350. error: 'installServicesErrorCallback'
  351. }).then(callback, callback);
  352. },
  353. /**
  354. * installs clients before install new services
  355. * on host where some components require this
  356. * @method installAdditionalClients
  357. */
  358. installAdditionalClients: function () {
  359. this.get('content.additionalClients').forEach(function (c) {
  360. var queryStr = 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')';
  361. App.ajax.send({
  362. name: 'common.host_component.update',
  363. sender: this,
  364. data: {
  365. query: queryStr,
  366. context: 'Install ' + App.format.role(c.componentName),
  367. HostRoles: {
  368. state: 'INSTALLED'
  369. }
  370. }
  371. });
  372. }, this);
  373. }
  374. });