add_controller.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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.AddHostController = App.WizardController.extend({
  20. name: 'addHostController',
  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. * hosts - hosts, ssh key, repo info, etc.
  31. * services - services list
  32. * hostsInfo - list of selected hosts
  33. * slaveComponentHosts, hostSlaveComponents - info about slave hosts
  34. * masterComponentHosts - info about master hosts
  35. * serviceConfigGroups - info about selected config group for service
  36. * configGroups - all config groups
  37. * config??? - to be described later
  38. */
  39. content: Em.Object.create({
  40. cluster: null,
  41. hosts: null,
  42. installOptions: null,
  43. services: null,
  44. slaveComponentHosts: null,
  45. masterComponentHosts: null,
  46. serviceConfigProperties: null,
  47. advancedServiceConfig: null,
  48. controllerName: 'addHostController',
  49. serviceConfigGroups: null,
  50. configGroups: null
  51. }),
  52. setCurrentStep: function (currentStep, completed) {
  53. this._super(currentStep, completed);
  54. App.clusterStatus.setClusterStatus({
  55. wizardControllerName: this.get('name'),
  56. localdb: App.db.data
  57. });
  58. },
  59. /**
  60. * return new object extended from clusterStatusTemplate
  61. * @return Object
  62. */
  63. getCluster: function(){
  64. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  65. },
  66. /**
  67. * return new object extended from installOptionsTemplate
  68. * @return Object
  69. */
  70. getInstallOptions: function(){
  71. return jQuery.extend({}, this.get('installOptionsTemplate'));
  72. },
  73. /**
  74. * return empty hosts array
  75. * @return Array
  76. */
  77. getHosts: function(){
  78. return [];
  79. },
  80. /**
  81. * Remove host from model. Used at <code>Confirm hosts</code> step
  82. * @param hosts Array of hosts, which we want to delete
  83. */
  84. removeHosts: function (hosts) {
  85. var dbHosts = this.getDBProperty('hosts');
  86. hosts.forEach(function (_hostInfo) {
  87. var host = _hostInfo.hostName;
  88. delete dbHosts[host];
  89. });
  90. this.setDBProperty('hosts', dbHosts);
  91. },
  92. /**
  93. * Load services data from server.
  94. */
  95. loadServicesFromServer: function() {
  96. var displayOrderConfig = require('data/services');
  97. var apiUrl = App.get('stack2VersionURL');
  98. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  99. //
  100. apiService.forEach(function(item, index){
  101. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  102. apiService[index].isDisabled = apiService[index].isSelected;
  103. apiService[index].isInstalled = apiService[index].isSelected;
  104. });
  105. this.set('content.services', apiService);
  106. this.setDBProperty('service', apiService);
  107. },
  108. /**
  109. * Load services data. Will be used at <code>Select services(step4)</code> step
  110. */
  111. loadServices: function () {
  112. var servicesInfo = this.getDBProperty('service');
  113. servicesInfo.forEach(function (item, index) {
  114. servicesInfo[index] = Em.Object.create(item);
  115. });
  116. this.set('content.services', servicesInfo);
  117. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  118. var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  119. console.log('selected services ', serviceNames);
  120. },
  121. /**
  122. * Load master component hosts data for using in required step controllers
  123. */
  124. loadMasterComponentHosts: function () {
  125. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  126. if (!masterComponentHosts) {
  127. masterComponentHosts = [];
  128. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  129. masterComponentHosts.push({
  130. component: item.get('componentName'),
  131. hostName: item.get('host.hostName'),
  132. isInstalled: true,
  133. serviceId: item.get('service.id'),
  134. display_name: item.get('displayName')
  135. })
  136. });
  137. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  138. }
  139. this.set("content.masterComponentHosts", masterComponentHosts);
  140. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  141. },
  142. /**
  143. * Save HBase and ZooKeeper to main controller
  144. * @param stepController
  145. */
  146. saveHbZk: function(stepController) {
  147. var self = this;
  148. var hosts = stepController.get('hosts');
  149. var headers = stepController.get('headers');
  150. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  151. headers.forEach(function(header) {
  152. var rm = masterComponentHosts.filterProperty('component', header.get('name'));
  153. if(rm) {
  154. masterComponentHosts.removeObjects(rm);
  155. }
  156. });
  157. headers.forEach(function(header) {
  158. var component = App.StackServiceComponent.find().findProperty('componentName', header.get('name'));
  159. hosts.forEach(function(host) {
  160. if (host.get('checkboxes').findProperty('title', component.display_name).checked) {
  161. masterComponentHosts .push({
  162. display_name: component.get('displayName'),
  163. component: component.get('componentName'),
  164. hostName: host.get('hostName'),
  165. serviceId: component.get('serviceName'),
  166. isInstalled: false
  167. });
  168. }
  169. });
  170. });
  171. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  172. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  173. this.set('content.masterComponentHosts', masterComponentHosts);
  174. },
  175. /**
  176. * return slaveComponents bound to hosts
  177. * @return {Array}
  178. */
  179. getSlaveComponentHosts: function () {
  180. return this._super().filter(function(component){
  181. return component.isInstalled;
  182. });
  183. },
  184. /**
  185. * Load master component hosts data for using in required step controllers
  186. */
  187. loadSlaveComponentHosts: function () {
  188. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts');
  189. if (!slaveComponentHosts) {
  190. slaveComponentHosts = this.getSlaveComponentHosts();
  191. }
  192. this.set("content.slaveComponentHosts", slaveComponentHosts);
  193. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  194. },
  195. /**
  196. * Load information about hosts with clients components
  197. */
  198. loadClients: function () {
  199. var clients = this.getDBProperty('clientInfo');
  200. this.set('content.clients', clients);
  201. console.log("AddHostController.loadClients: loaded list ", clients);
  202. },
  203. /**
  204. * Generate clients list for selected services and save it to model
  205. */
  206. saveClients: function () {
  207. var clients = [];
  208. var serviceComponents = App.StackServiceComponent.find();
  209. var hostComponents = App.HostComponent.find();
  210. this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) {
  211. var client = serviceComponents.filterProperty('serviceName', _service.serviceName).findProperty('isClient', true);
  212. if (client) {
  213. clients.pushObject({
  214. component_name: client.get('componentName'),
  215. display_name: client.get('displayName'),
  216. isInstalled: hostComponents.filterProperty('componentName', client.get('componentName')).length > 0
  217. });
  218. }
  219. }, this);
  220. this.setDBProperty('clientInfo', clients);
  221. this.set('content.clients', clients);
  222. console.log("AddHostController.saveClients: saved list ", clients);
  223. },
  224. /**
  225. * Apply config groups from step4 Configurations
  226. */
  227. applyConfigGroup: function () {
  228. var serviceConfigGroups = this.get('content.serviceConfigGroups');
  229. serviceConfigGroups.forEach(function (group){
  230. if (group.configGroups.someProperty('ConfigGroup.group_name', group.selectedConfigGroup)) {
  231. var configGroup = group.configGroups.findProperty('ConfigGroup.group_name', group.selectedConfigGroup);
  232. group.hosts.forEach(function(host){
  233. configGroup.ConfigGroup.hosts.push({
  234. host_name: host
  235. });
  236. },this);
  237. delete configGroup.href;
  238. App.ajax.send({
  239. name: 'config_groups.update_config_group',
  240. sender: this,
  241. data: {
  242. id: configGroup.ConfigGroup.id,
  243. configGroup: configGroup
  244. }
  245. });
  246. }
  247. },this);
  248. },
  249. /**
  250. * Load information about selected config groups
  251. */
  252. getServiceConfigGroups: function () {
  253. var serviceConfigGroups = this.getDBProperty('serviceConfigGroups');
  254. this.set('content.serviceConfigGroups', serviceConfigGroups);
  255. },
  256. /**
  257. * Save information about selected config groups
  258. */
  259. saveServiceConfigGroups: function () {
  260. this.setDBProperty('serviceConfigGroups', this.get('content.serviceConfigGroups'));
  261. this.set('content.serviceConfigGroups', this.get('content.serviceConfigGroups'));
  262. },
  263. /**
  264. * Set content.serviceConfigGroups for step4
  265. */
  266. loadServiceConfigGroups: function () {
  267. var slaveComponentHosts = this.get('content.slaveComponentHosts');
  268. var selectedServices = [];
  269. var selectedClientHosts = slaveComponentHosts.findProperty('componentName', 'CLIENT').hosts.mapProperty('hostName');
  270. var componentServiceMap = App.QuickDataMapper.componentServiceMap();
  271. slaveComponentHosts.forEach(function (slave) {
  272. if (slave.hosts.length > 0) {
  273. if (slave.componentName != "CLIENT") {
  274. var service = componentServiceMap[slave.componentName];
  275. var configGroups = this.get('content.configGroups').filterProperty('ConfigGroup.tag', service);
  276. var configGroupsNames = configGroups.mapProperty('ConfigGroup.group_name');
  277. var defaultGroupName = App.Service.DisplayNames[service] + ' Default';
  278. configGroupsNames.unshift(defaultGroupName);
  279. selectedServices.push({
  280. serviceId: service,
  281. displayName: App.Service.DisplayNames[service],
  282. hosts: slave.hosts.mapProperty('hostName'),
  283. configGroupsNames: configGroupsNames,
  284. configGroups: configGroups,
  285. selectedConfigGroup: defaultGroupName
  286. });
  287. }
  288. }
  289. }, this);
  290. if (selectedClientHosts.length > 0) {
  291. this.loadClients();
  292. var clients = this.get('content.clients');
  293. clients.forEach(function (client) {
  294. var service = componentServiceMap[client.component_name];
  295. var serviceMatch = selectedServices.findProperty('serviceId', service);
  296. if (serviceMatch) {
  297. serviceMatch.hosts = serviceMatch.hosts.concat(selectedClientHosts).uniq();
  298. } else {
  299. var configGroups = this.get('content.configGroups').filterProperty('ConfigGroup.tag', service);
  300. var configGroupsNames = configGroups.mapProperty('ConfigGroup.group_name').sort();
  301. var defaultGroupName = App.Service.DisplayNames[service] + ' Default';
  302. configGroupsNames.unshift(defaultGroupName);
  303. selectedServices.push({
  304. serviceId: service,
  305. displayName: App.Service.DisplayNames[service],
  306. hosts: selectedClientHosts,
  307. configGroupsNames: configGroupsNames,
  308. configGroups: configGroups,
  309. selectedConfigGroup: defaultGroupName
  310. });
  311. }
  312. }, this);
  313. }
  314. selectedServices.forEach(function(selectedService){
  315. selectedService.configGroups.sort(function(cfgA, cfgB){
  316. return cfgA.ConfigGroup.group_name >= cfgB.ConfigGroup.group_name;
  317. });
  318. });
  319. this.set('content.serviceConfigGroups', selectedServices);
  320. },
  321. loadServiceConfigProperties: function () {
  322. var serviceConfigProperties = App.db.get('AddService', 'serviceConfigProperties');
  323. if (!serviceConfigProperties || !serviceConfigProperties.length) {
  324. serviceConfigProperties = App.db.get('Installer', 'serviceConfigProperties');
  325. }
  326. this.set('content.serviceConfigProperties', serviceConfigProperties);
  327. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  328. },
  329. /**
  330. * Load data for all steps until <code>current step</code>
  331. */
  332. loadAllPriorSteps: function () {
  333. var step = this.get('currentStep');
  334. switch (step) {
  335. case '7':
  336. case '6':
  337. case '5':
  338. this.loadServiceConfigProperties();
  339. this.getServiceConfigGroups();
  340. case '4':
  341. case '3':
  342. this.loadClients();
  343. this.loadServices();
  344. this.loadMasterComponentHosts();
  345. this.loadSlaveComponentHosts();
  346. this.load('hosts');
  347. case '2':
  348. this.loadServices();
  349. case '1':
  350. this.load('hosts');
  351. this.load('installOptions');
  352. this.load('cluster');
  353. }
  354. },
  355. /**
  356. * Remove all loaded data.
  357. * Created as copy for App.router.clearAllSteps
  358. */
  359. clearAllSteps: function () {
  360. this.clearInstallOptions();
  361. // clear temporary information stored during the install
  362. this.set('content.cluster', this.getCluster());
  363. },
  364. /**
  365. * Clear all temporary data
  366. */
  367. finish: function () {
  368. this.setCurrentStep('1');
  369. this.clearAllSteps();
  370. this.clearStorageData();
  371. App.router.get('updateController').updateAll();
  372. App.updater.immediateRun('updateHost');
  373. },
  374. installServices: function (isRetry) {
  375. this.set('content.cluster.oldRequestsId', []);
  376. var clusterName = this.get('content.cluster.name');
  377. var data;
  378. var name;
  379. var hostnames = [];
  380. for (var hostname in this.getDBProperty('hosts')) {
  381. hostnames.push(hostname);
  382. }
  383. if (isRetry) {
  384. name = 'wizard.install_services.add_host_controller.is_retry';
  385. }
  386. else {
  387. name = 'wizard.install_services.add_host_controller.not_is_retry';
  388. }
  389. data = {
  390. "RequestInfo": {
  391. "context": Em.I18n.t('requestInfo.installComponents'),
  392. "query": "HostRoles/host_name.in(" + hostnames.join(',') + ")"
  393. },
  394. "Body": {
  395. "HostRoles": {"state": "INSTALLED"}
  396. }
  397. };
  398. data = JSON.stringify(data);
  399. App.ajax.send({
  400. name: name,
  401. sender: this,
  402. data: {
  403. data: data,
  404. cluster: clusterName
  405. },
  406. success: 'installServicesSuccessCallback',
  407. error: 'installServicesErrorCallback'
  408. });
  409. }
  410. });