add_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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: 6,
  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. * 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: 'addHostController'
  47. }),
  48. components:require('data/service_components'),
  49. /**
  50. * return new object extended from clusterStatusTemplate
  51. * @return Object
  52. */
  53. getCluster: function(){
  54. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  55. },
  56. /**
  57. * return new object extended from installOptionsTemplate
  58. * @return Object
  59. */
  60. getInstallOptions: function(){
  61. return jQuery.extend({}, this.get('installOptionsTemplate'));
  62. },
  63. /**
  64. * return empty hosts array
  65. * @return Array
  66. */
  67. getHosts: function(){
  68. return [];
  69. },
  70. /**
  71. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  72. * @param hosts Array of hosts, which we want to delete
  73. */
  74. removeHosts: function (hosts) {
  75. //todo Replace this code with real logic
  76. App.db.removeHosts(hosts);
  77. },
  78. /**
  79. * Load services data from server.
  80. */
  81. loadServicesFromServer: function() {
  82. var displayOrderConfig = require('data/services');
  83. var apiUrl = App.get('stack2VersionURL');
  84. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  85. //
  86. apiService.forEach(function(item, index){
  87. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  88. apiService[index].isDisabled = apiService[index].isSelected;
  89. apiService[index].isInstalled = apiService[index].isSelected;
  90. });
  91. this.set('content.services', apiService);
  92. App.db.setService(apiService);
  93. },
  94. /**
  95. * Load services data. Will be used at <code>Select services(step4)</code> step
  96. */
  97. loadServices: function () {
  98. var servicesInfo = App.db.getService();
  99. servicesInfo.forEach(function (item, index) {
  100. servicesInfo[index] = Em.Object.create(item);
  101. });
  102. this.set('content.services', servicesInfo);
  103. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  104. var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  105. console.log('selected services ', serviceNames);
  106. },
  107. /**
  108. * Load master component hosts data for using in required step controllers
  109. */
  110. loadMasterComponentHosts: function () {
  111. var masterComponentHosts = App.db.getMasterComponentHosts();
  112. if (!masterComponentHosts) {
  113. masterComponentHosts = [];
  114. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  115. masterComponentHosts.push({
  116. component: item.get('componentName'),
  117. hostName: item.get('host.hostName'),
  118. isInstalled: true,
  119. serviceId: item.get('service.id'),
  120. display_name: item.get('displayName')
  121. })
  122. });
  123. App.db.setMasterComponentHosts(masterComponentHosts);
  124. }
  125. this.set("content.masterComponentHosts", masterComponentHosts);
  126. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  127. },
  128. /**
  129. * Save HBase and ZooKeeper to main controller
  130. * @param stepController
  131. */
  132. saveHbZk: function(stepController) {
  133. var self = this;
  134. var hosts = stepController.get('hosts');
  135. var headers = stepController.get('headers');
  136. var masterComponentHosts = App.db.getMasterComponentHosts();
  137. headers.forEach(function(header) {
  138. var rm = masterComponentHosts.filterProperty('component', header.get('name'));
  139. if(rm) {
  140. masterComponentHosts.removeObjects(rm);
  141. }
  142. });
  143. headers.forEach(function(header) {
  144. var component = self.get('components').findProperty('component_name', header.get('name'));
  145. hosts.forEach(function(host) {
  146. if (host.get('checkboxes').findProperty('title', component.display_name).checked) {
  147. masterComponentHosts .push({
  148. display_name: component.display_name,
  149. component: component.component_name,
  150. hostName: host.get('hostName'),
  151. serviceId: component.service_name,
  152. isInstalled: false
  153. });
  154. }
  155. });
  156. });
  157. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  158. App.db.setMasterComponentHosts(masterComponentHosts);
  159. this.set('content.masterComponentHosts', masterComponentHosts);
  160. },
  161. /**
  162. * return slaveComponents bound to hosts
  163. * @return {Array}
  164. */
  165. getSlaveComponentHosts: function () {
  166. var components = [
  167. {
  168. name: 'DATANODE',
  169. service: 'HDFS'
  170. },
  171. {
  172. name: 'TASKTRACKER',
  173. service: 'MAPREDUCE'
  174. },
  175. {
  176. name: 'HBASE_REGIONSERVER',
  177. service: 'HBASE'
  178. }
  179. ];
  180. var result = [];
  181. var services = App.Service.find();
  182. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  183. for (var index = 0; index < components.length; index++) {
  184. var comp = components[index];
  185. if (!selectedServices.contains(comp.service)) {
  186. continue;
  187. }
  188. var service = services.findProperty('id', comp.service);
  189. var hosts = [];
  190. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  191. hosts.push({
  192. group: "Default",
  193. hostName: host_component.get('host.id'),
  194. isInstalled: true
  195. });
  196. }, this);
  197. result.push({
  198. componentName: comp.name,
  199. displayName: App.format.role(comp.name),
  200. hosts: hosts,
  201. isInstalled: true
  202. })
  203. }
  204. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  205. var hosts = [];
  206. clientsHosts.forEach(function (host_component) {
  207. hosts.push({
  208. group: "Default",
  209. hostName: host_component.get('host.id'),
  210. isInstalled: true
  211. });
  212. }, this);
  213. result.push({
  214. componentName: 'CLIENT',
  215. displayName: 'client',
  216. hosts: hosts,
  217. isInstalled: true
  218. })
  219. return result;
  220. },
  221. /**
  222. * Load master component hosts data for using in required step controllers
  223. */
  224. loadSlaveComponentHosts: function () {
  225. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  226. if (!slaveComponentHosts) {
  227. slaveComponentHosts = this.getSlaveComponentHosts();
  228. }
  229. this.set("content.slaveComponentHosts", slaveComponentHosts);
  230. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  231. },
  232. /**
  233. * Load information about hosts with clients components
  234. */
  235. loadClients: function () {
  236. var clients = App.db.getClientsForSelectedServices();
  237. this.set('content.clients', clients);
  238. console.log("AddHostController.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 () {
  245. var clients = [];
  246. var serviceComponents = require('data/service_components');
  247. var hostComponents = App.HostComponent.find();
  248. this.get('content.services').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. App.db.setClientsForSelectedServices(clients);
  259. this.set('content.clients', clients);
  260. console.log("AddHostController.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 '6':
  269. case '5':
  270. case '4':
  271. this.loadServiceConfigProperties();
  272. case '3':
  273. this.loadClients();
  274. this.loadServices();
  275. this.loadMasterComponentHosts();
  276. this.loadSlaveComponentHosts();
  277. this.load('hosts');
  278. case '2':
  279. this.loadServices();
  280. case '1':
  281. this.load('hosts');
  282. this.load('installOptions');
  283. this.load('cluster');
  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. App.updater.immediateRun('updateHost');
  304. },
  305. installServices: function (isRetry) {
  306. this.set('content.cluster.oldRequestsId', []);
  307. var clusterName = this.get('content.cluster.name');
  308. var data;
  309. var name;
  310. var hostnames = [];
  311. for (var hostname in App.db.getHosts()) {
  312. hostnames.push(hostname);
  313. }
  314. if (isRetry) {
  315. name = 'wizard.install_services.add_host_controller.is_retry';
  316. }
  317. else {
  318. name = 'wizard.install_services.add_host_controller.not_is_retry';
  319. }
  320. data = {
  321. "RequestInfo": {
  322. "context": Em.I18n.t('requestInfo.installComponents'),
  323. "query": "HostRoles/host_name.in(" + hostnames.join(',') + ")"
  324. },
  325. "Body": {
  326. "HostRoles": {"state": "INSTALLED"}
  327. }
  328. };
  329. data = JSON.stringify(data);
  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. });