add_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. setCurrentStep: function (currentStep, completed) {
  50. this._super(currentStep, completed);
  51. App.clusterStatus.setClusterStatus({
  52. wizardControllerName: this.get('name'),
  53. localdb: App.db.data
  54. });
  55. },
  56. /**
  57. * return new object extended from clusterStatusTemplate
  58. * @return Object
  59. */
  60. getCluster: function(){
  61. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  62. },
  63. /**
  64. * return new object extended from installOptionsTemplate
  65. * @return Object
  66. */
  67. getInstallOptions: function(){
  68. return jQuery.extend({}, this.get('installOptionsTemplate'));
  69. },
  70. /**
  71. * return empty hosts array
  72. * @return Array
  73. */
  74. getHosts: function(){
  75. return [];
  76. },
  77. /**
  78. * Load services data from server.
  79. */
  80. loadServicesFromServer: function() {
  81. var displayOrderConfig = require('data/services');
  82. var apiUrl = App.get('stack2VersionURL');
  83. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  84. //
  85. apiService.forEach(function(item, index){
  86. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  87. apiService[index].isDisabled = apiService[index].isSelected;
  88. apiService[index].isInstalled = apiService[index].isSelected;
  89. });
  90. this.set('content.services', apiService);
  91. this.setDBProperty('service', apiService);
  92. },
  93. /**
  94. * Load services data. Will be used at <code>Select services(step4)</code> step
  95. */
  96. loadServices: function () {
  97. var servicesInfo = this.getDBProperty('service');
  98. servicesInfo.forEach(function (item, index) {
  99. servicesInfo[index] = Em.Object.create(item);
  100. });
  101. this.set('content.services', servicesInfo);
  102. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  103. var serviceNames = servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  104. console.log('selected services ', serviceNames);
  105. },
  106. /**
  107. * Load master component hosts data for using in required step controllers
  108. */
  109. loadMasterComponentHosts: function () {
  110. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  111. if (!masterComponentHosts) {
  112. masterComponentHosts = [];
  113. App.HostComponent.find().filterProperty('isMaster', true).forEach(function (item) {
  114. masterComponentHosts.push({
  115. component: item.get('componentName'),
  116. hostName: item.get('host.hostName'),
  117. isInstalled: true,
  118. serviceId: item.get('service.id'),
  119. display_name: item.get('displayName')
  120. })
  121. });
  122. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  123. }
  124. this.set("content.masterComponentHosts", masterComponentHosts);
  125. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  126. },
  127. /**
  128. * Save HBase and ZooKeeper to main controller
  129. * @param stepController
  130. */
  131. saveHbZk: function(stepController) {
  132. var self = this;
  133. var hosts = stepController.get('hosts');
  134. var headers = stepController.get('headers');
  135. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  136. headers.forEach(function(header) {
  137. var rm = masterComponentHosts.filterProperty('component', header.get('name'));
  138. if(rm) {
  139. masterComponentHosts.removeObjects(rm);
  140. }
  141. });
  142. headers.forEach(function(header) {
  143. var component = self.get('components').findProperty('component_name', header.get('name'));
  144. hosts.forEach(function(host) {
  145. if (host.get('checkboxes').findProperty('title', component.display_name).checked) {
  146. masterComponentHosts .push({
  147. display_name: component.display_name,
  148. component: component.component_name,
  149. hostName: host.get('hostName'),
  150. serviceId: component.service_name,
  151. isInstalled: false
  152. });
  153. }
  154. });
  155. });
  156. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  157. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  158. this.set('content.masterComponentHosts', masterComponentHosts);
  159. },
  160. /**
  161. * return slaveComponents bound to hosts
  162. * @return {Array}
  163. */
  164. getSlaveComponentHosts: function () {
  165. var components = [
  166. {
  167. name: 'DATANODE',
  168. service: 'HDFS'
  169. },
  170. {
  171. name: 'TASKTRACKER',
  172. service: 'MAPREDUCE'
  173. },
  174. {
  175. name: 'HBASE_REGIONSERVER',
  176. service: 'HBASE'
  177. }
  178. ];
  179. var result = [];
  180. var services = App.Service.find();
  181. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  182. for (var index = 0; index < components.length; index++) {
  183. var comp = components[index];
  184. if (!selectedServices.contains(comp.service)) {
  185. continue;
  186. }
  187. var service = services.findProperty('id', comp.service);
  188. var hosts = [];
  189. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  190. hosts.push({
  191. group: "Default",
  192. hostName: host_component.get('host.id'),
  193. isInstalled: true
  194. });
  195. }, this);
  196. result.push({
  197. componentName: comp.name,
  198. displayName: App.format.role(comp.name),
  199. hosts: hosts,
  200. isInstalled: true
  201. })
  202. }
  203. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  204. var hosts = [];
  205. clientsHosts.forEach(function (host_component) {
  206. hosts.push({
  207. group: "Default",
  208. hostName: host_component.get('host.id'),
  209. isInstalled: true
  210. });
  211. }, this);
  212. result.push({
  213. componentName: 'CLIENT',
  214. displayName: 'client',
  215. hosts: hosts,
  216. isInstalled: true
  217. });
  218. return result;
  219. },
  220. /**
  221. * Load master component hosts data for using in required step controllers
  222. */
  223. loadSlaveComponentHosts: function () {
  224. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts');
  225. if (!slaveComponentHosts) {
  226. slaveComponentHosts = this.getSlaveComponentHosts();
  227. }
  228. this.set("content.slaveComponentHosts", slaveComponentHosts);
  229. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  230. },
  231. /**
  232. * Load information about hosts with clients components
  233. */
  234. loadClients: function () {
  235. var clients = this.getDBProperty('clientInfo');
  236. this.set('content.clients', clients);
  237. console.log("AddHostController.loadClients: loaded list ", clients);
  238. },
  239. /**
  240. * Generate clients list for selected services and save it to model
  241. * @param stepController step4WizardController
  242. */
  243. saveClients: function () {
  244. var clients = [];
  245. var serviceComponents = require('data/service_components');
  246. var hostComponents = App.HostComponent.find();
  247. this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) {
  248. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  249. if (client) {
  250. clients.pushObject({
  251. component_name: client.component_name,
  252. display_name: client.display_name,
  253. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  254. });
  255. }
  256. }, this);
  257. this.setDBProperty('clientInfo', clients);
  258. this.set('content.clients', clients);
  259. console.log("AddHostController.saveClients: saved list ", clients);
  260. },
  261. /**
  262. * Load data for all steps until <code>current step</code>
  263. */
  264. loadAllPriorSteps: function () {
  265. var step = this.get('currentStep');
  266. switch (step) {
  267. case '6':
  268. case '5':
  269. case '4':
  270. this.loadServiceConfigProperties();
  271. case '3':
  272. this.loadClients();
  273. this.loadServices();
  274. this.loadMasterComponentHosts();
  275. this.loadSlaveComponentHosts();
  276. this.load('hosts');
  277. case '2':
  278. this.loadServices();
  279. case '1':
  280. this.load('hosts');
  281. this.load('installOptions');
  282. this.load('cluster');
  283. }
  284. },
  285. /**
  286. * Remove all loaded data.
  287. * Created as copy for App.router.clearAllSteps
  288. */
  289. clearAllSteps: function () {
  290. this.clearInstallOptions();
  291. // clear temporary information stored during the install
  292. this.set('content.cluster', this.getCluster());
  293. },
  294. /**
  295. * Clear all temporary data
  296. */
  297. finish: function () {
  298. this.setCurrentStep('1');
  299. this.clearAllSteps();
  300. this.clearStorageData();
  301. App.router.get('updateController').updateAll();
  302. App.updater.immediateRun('updateHost');
  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. var hostnames = [];
  310. for (var hostname in this.getDBProperty('hosts')) {
  311. hostnames.push(hostname);
  312. }
  313. if (isRetry) {
  314. name = 'wizard.install_services.add_host_controller.is_retry';
  315. }
  316. else {
  317. name = 'wizard.install_services.add_host_controller.not_is_retry';
  318. }
  319. data = {
  320. "RequestInfo": {
  321. "context": Em.I18n.t('requestInfo.installComponents'),
  322. "query": "HostRoles/host_name.in(" + hostnames.join(',') + ")"
  323. },
  324. "Body": {
  325. "HostRoles": {"state": "INSTALLED"}
  326. }
  327. };
  328. data = JSON.stringify(data);
  329. App.ajax.send({
  330. name: name,
  331. sender: this,
  332. data: {
  333. data: data,
  334. cluster: clusterName
  335. },
  336. success: 'installServicesSuccessCallback',
  337. error: 'installServicesErrorCallback'
  338. });
  339. }
  340. });