add_controller.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. }),
  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. * Load confirmed hosts.
  58. * Will be used at <code>Assign Masters(step5)</code> step
  59. */
  60. loadConfirmedHosts: function(){
  61. var hosts = App.db.getHosts();
  62. if(!hosts){
  63. var hosts = {};
  64. App.Host.find().forEach(function(item){
  65. hosts[item.get('id')] = {
  66. name: item.get('id'),
  67. cpu: item.get('cpu'),
  68. memory: item.get('memory'),
  69. disk_info: item.get('diskInfo'),
  70. bootStatus: "REGISTERED",
  71. isInstalled: true
  72. };
  73. });
  74. App.db.setHosts(hosts);
  75. }
  76. this.set('content.hosts', hosts);
  77. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  78. },
  79. /**
  80. * Load services data from server.
  81. */
  82. loadServicesFromServer: function() {
  83. if(App.db.getService()){
  84. return;
  85. }
  86. var displayOrderConfig = require('data/services');
  87. var apiUrl = App.get('stack2VersionURL');
  88. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  89. //
  90. apiService.forEach(function(item, index){
  91. apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  92. apiService[index].isDisabled = apiService[index].isSelected;
  93. apiService[index].isInstalled = apiService[index].isSelected;
  94. });
  95. this.set('content.services', apiService);
  96. App.db.setService(apiService);
  97. },
  98. /**
  99. * Load services data. Will be used at <code>Select services(step4)</code> step
  100. */
  101. loadServices: function () {
  102. var servicesInfo = App.db.getService();
  103. servicesInfo.forEach(function (item, index) {
  104. servicesInfo[index] = Em.Object.create(item);
  105. });
  106. this.set('content.services', servicesInfo);
  107. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  108. var serviceNames = servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  109. console.log('selected services ', serviceNames);
  110. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  111. if (this.get('content.skipSlavesStep')) {
  112. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  113. }
  114. },
  115. /**
  116. * Save data to model
  117. * @param stepController App.WizardStep4Controller
  118. */
  119. saveServices: function (stepController) {var serviceNames = [];
  120. App.db.setService(stepController.get('content'));
  121. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  122. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  123. serviceNames.push(item.serviceName);
  124. });
  125. this.set('content.selectedServiceNames', serviceNames);
  126. App.db.setSelectedServiceNames(serviceNames);
  127. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  128. this.set('content.skipSlavesStep', !serviceNames.contains('MAPREDUCE') && !serviceNames.contains('HBASE'));
  129. if (this.get('content.skipSlavesStep')) {
  130. this.get('isStepDisabled').findProperty('step', 3).set('value', this.get('content.skipSlavesStep'));
  131. }
  132. },
  133. /**
  134. * Save Master Component Hosts data to Main Controller
  135. * @param stepController App.WizardStep5Controller
  136. */
  137. saveMasterComponentHosts: function (stepController) {
  138. var obj = stepController.get('selectedServicesMasters');
  139. var masterComponentHosts = [];
  140. var installedComponents = App.HostComponent.find();
  141. obj.forEach(function (_component) {
  142. masterComponentHosts.push({
  143. display_name: _component.display_name,
  144. component: _component.component_name,
  145. hostName: _component.selectedHost,
  146. serviceId: _component.serviceId,
  147. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  148. });
  149. });
  150. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  151. App.db.setMasterComponentHosts(masterComponentHosts);
  152. this.set('content.masterComponentHosts', masterComponentHosts);
  153. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  154. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  155. },
  156. /**
  157. * Load master component hosts data for using in required step controllers
  158. */
  159. loadMasterComponentHosts: function () {
  160. var masterComponentHosts = App.db.getMasterComponentHosts();
  161. if(!masterComponentHosts){
  162. masterComponentHosts = [];
  163. App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){
  164. masterComponentHosts.push({
  165. component: item.get('componentName'),
  166. hostName: item.get('host.hostName'),
  167. isInstalled: true
  168. })
  169. });
  170. }
  171. this.set("content.masterComponentHosts", masterComponentHosts);
  172. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  173. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  174. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  175. },
  176. /**
  177. * Does service have any configs
  178. * @param {string} serviceName
  179. * @returns {boolean}
  180. */
  181. isServiceConfigurable: function(serviceName) {
  182. return this.get('serviceConfigs').mapProperty('serviceName').contains(serviceName);
  183. },
  184. /**
  185. * Should Config Step be skipped (based on selected services list)
  186. * @returns {boolean}
  187. */
  188. skipConfigStep: function() {
  189. var skipConfigStep = true;
  190. var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  191. selectedServices.map(function(serviceName) {
  192. skipConfigStep = skipConfigStep && !this.isServiceConfigurable(serviceName);
  193. }, this);
  194. return skipConfigStep;
  195. },
  196. loadServiceConfigProperties: function() {
  197. this._super();
  198. if (this.get('currentStep') > 1) {
  199. this.set('content.skipConfigStep', this.skipConfigStep());
  200. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  201. }
  202. },
  203. saveServiceConfigProperties: function(stepController) {
  204. this._super(stepController);
  205. if (this.get('currentStep') > 1) {
  206. this.set('content.skipConfigStep', this.skipConfigStep());
  207. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  208. }
  209. },
  210. /**
  211. * return slaveComponents bound to hosts
  212. * @return {Array}
  213. */
  214. getSlaveComponentHosts: function () {
  215. var components = [{
  216. name : 'DATANODE',
  217. service : 'HDFS'
  218. },
  219. {
  220. name: 'TASKTRACKER',
  221. service: 'MAPREDUCE'
  222. },
  223. {
  224. name: 'HBASE_REGIONSERVER',
  225. service: 'HBASE'
  226. }];
  227. if (App.get('isHadoop2Stack')) {
  228. components.push({
  229. name: 'NODEMANAGER',
  230. service: 'YARN'
  231. });
  232. }
  233. var result = [];
  234. var services = App.Service.find();
  235. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  236. for(var index=0; index < components.length; index++){
  237. var comp = components[index];
  238. if(!selectedServices.contains(comp.service)){
  239. continue;
  240. }
  241. var service = services.findProperty('id', comp.service);
  242. var hosts = [];
  243. if(!service){
  244. service = services.findProperty('id', 'HDFS');
  245. service.get('hostComponents').filterProperty('componentName', 'DATANODE').forEach(function (host_component) {
  246. hosts.push({
  247. group: "Default",
  248. hostName: host_component.get('host.id'),
  249. isInstalled: false
  250. });
  251. }, this);
  252. } else {
  253. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  254. hosts.push({
  255. group: "Default",
  256. hostName: host_component.get('host.id'),
  257. isInstalled: true
  258. });
  259. }, this);
  260. }
  261. result.push({
  262. componentName: comp.name,
  263. displayName: App.format.role(comp.name),
  264. hosts: hosts
  265. })
  266. }
  267. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  268. var hosts = [];
  269. clientsHosts.forEach(function (host_component) {
  270. hosts.push({
  271. group: "Default",
  272. hostName: host_component.get('host.id'),
  273. isInstalled: true
  274. });
  275. }, this);
  276. result.push({
  277. componentName: 'CLIENT',
  278. displayName: 'client',
  279. hosts: hosts
  280. });
  281. return result;
  282. },
  283. /**
  284. * Load master component hosts data for using in required step controllers
  285. */
  286. loadSlaveComponentHosts: function () {
  287. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  288. if(!slaveComponentHosts){
  289. slaveComponentHosts = this.getSlaveComponentHosts();
  290. }
  291. this.set("content.slaveComponentHosts", slaveComponentHosts);
  292. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  293. },
  294. /**
  295. * Load information about hosts with clients components
  296. */
  297. loadClients: function(){
  298. var clients = App.db.getClientsForSelectedServices();
  299. this.set('content.clients', clients);
  300. console.log("AddServiceController.loadClients: loaded list ", clients);
  301. },
  302. /**
  303. * Generate clients list for selected services and save it to model
  304. * @param stepController step4WizardController
  305. */
  306. saveClients: function(stepController){
  307. var clients = [];
  308. var serviceComponents = require('data/service_components');
  309. var hostComponents = App.HostComponent.find();
  310. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  311. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  312. if (client) {
  313. clients.pushObject({
  314. component_name: client.component_name,
  315. display_name: client.display_name,
  316. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  317. });
  318. }
  319. }, this);
  320. App.db.setClientsForSelectedServices(clients);
  321. this.set('content.clients', clients);
  322. console.log("AddServiceController.saveClients: saved list ", clients);
  323. },
  324. /**
  325. * Load data for all steps until <code>current step</code>
  326. */
  327. loadAllPriorSteps: function () {
  328. var step = this.get('currentStep');
  329. switch (step) {
  330. case '7':
  331. case '6':
  332. case '5':
  333. this.load('cluster');
  334. case '4':
  335. this.loadServiceConfigProperties();
  336. case '3':
  337. this.loadServices();
  338. this.loadClients();
  339. this.loadSlaveComponentHosts();//depends on loadServices
  340. case '2':
  341. this.loadMasterComponentHosts();
  342. this.loadConfirmedHosts();
  343. case '1':
  344. this.loadServices();
  345. }
  346. },
  347. /**
  348. * Remove all loaded data.
  349. * Created as copy for App.router.clearAllSteps
  350. */
  351. clearAllSteps: function () {
  352. this.clearInstallOptions();
  353. // clear temporary information stored during the install
  354. this.set('content.cluster', this.getCluster());
  355. },
  356. /**
  357. * Clear all temporary data
  358. */
  359. finish: function () {
  360. this.setCurrentStep('1');
  361. this.clearAllSteps();
  362. this.clearStorageData();
  363. App.router.get('updateController').updateAll();
  364. }
  365. });