installer.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.InstallerController = App.WizardController.extend({
  20. name: 'installerController',
  21. totalSteps: 10,
  22. content: Em.Object.create({
  23. cluster: null,
  24. installOptions: null,
  25. hosts: null,
  26. services: null,
  27. slaveComponentHosts: null,
  28. masterComponentHosts: null,
  29. serviceConfigProperties: null,
  30. advancedServiceConfig: null,
  31. slaveGroupProperties: null,
  32. controllerName: 'installerController'
  33. }),
  34. getCluster: function(){
  35. return jQuery.extend({}, this.get('clusterStatusTemplate'));
  36. },
  37. getInstallOptions: function(){
  38. return jQuery.extend({}, this.get('installOptionsTemplate'));
  39. },
  40. getHosts: function(){
  41. return [];
  42. },
  43. /**
  44. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  45. * @param hosts Array of hosts, which we want to delete
  46. */
  47. removeHosts: function (hosts) {
  48. //todo Replace this code with real logic
  49. App.db.removeHosts(hosts);
  50. },
  51. /**
  52. * Load confirmed hosts.
  53. * Will be used at <code>Assign Masters(step5)</code> step
  54. */
  55. loadConfirmedHosts: function () {
  56. this.set('content.hosts', App.db.getHosts() || []);
  57. },
  58. /**
  59. * Load services data. Will be used at <code>Select services(step4)</code> step
  60. */
  61. loadServices: function () {
  62. var servicesInfo = App.db.getService();
  63. servicesInfo.forEach(function (item, index) {
  64. servicesInfo[index] = Em.Object.create(item);
  65. servicesInfo[index].isInstalled = false;
  66. });
  67. this.set('content.services', servicesInfo);
  68. console.log('installerController.loadServices: loaded data ', JSON.stringify(servicesInfo));
  69. console.log("The type odf serviceInfo: " + typeof servicesInfo);
  70. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  71. },
  72. /**
  73. * Save data to model
  74. * @param stepController App.WizardStep4Controller
  75. */
  76. saveServices: function (stepController) {
  77. var serviceNames = [];
  78. App.db.setService(stepController.get('content'));
  79. stepController.filterProperty('isSelected', true).forEach(function (item) {
  80. serviceNames.push(item.serviceName);
  81. });
  82. this.set('content.selectedServiceNames', serviceNames);
  83. App.db.setSelectedServiceNames(serviceNames);
  84. console.log('installerController.saveServices: saved data ', serviceNames);
  85. },
  86. /**
  87. * Save Master Component Hosts data to Main Controller
  88. * @param stepController App.WizardStep5Controller
  89. */
  90. saveMasterComponentHosts: function (stepController) {
  91. var obj = stepController.get('selectedServicesMasters');
  92. var masterComponentHosts = [];
  93. obj.forEach(function (_component) {
  94. masterComponentHosts.push({
  95. display_name: _component.get('display_name'),
  96. component: _component.get('component_name'),
  97. hostName: _component.get('selectedHost'),
  98. serviceId: _component.get('serviceId'),
  99. isInstalled: false
  100. });
  101. });
  102. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  103. App.db.setMasterComponentHosts(masterComponentHosts);
  104. this.set('content.masterComponentHosts', masterComponentHosts);
  105. },
  106. /**
  107. * Load master component hosts data for using in required step controllers
  108. */
  109. loadMasterComponentHosts: function () {
  110. var masterComponentHosts = App.db.getMasterComponentHosts() || [];
  111. this.set("content.masterComponentHosts", masterComponentHosts);
  112. console.log("InstallerController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  113. },
  114. /**
  115. * Load master component hosts data for using in required step controllers
  116. */
  117. loadSlaveComponentHosts: function () {
  118. var slaveComponentHosts = App.db.getSlaveComponentHosts() || null;
  119. this.set("content.slaveComponentHosts", slaveComponentHosts);
  120. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  121. },
  122. /**
  123. * Load serviceConfigProperties to model
  124. */
  125. loadServiceConfigProperties: function () {
  126. var serviceConfigProperties = App.db.getServiceConfigProperties();
  127. this.set('content.serviceConfigProperties', serviceConfigProperties);
  128. console.log("InstallerController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  129. this.set('content.advancedServiceConfig', App.db.getAdvancedServiceConfig());
  130. },
  131. /**
  132. * Load information about hosts with clients components
  133. */
  134. loadClients: function () {
  135. var clients = App.db.getClientsForSelectedServices();
  136. this.set('content.clients', clients);
  137. console.log("InstallerController.loadClients: loaded list ", clients);
  138. },
  139. /**
  140. * Generate clients list for selected services and save it to model
  141. * @param stepController step4WizardController
  142. */
  143. saveClients: function (stepController) {
  144. var clients = [];
  145. var serviceComponents = require('data/service_components');
  146. stepController.get('content').filterProperty('isSelected', true).forEach(function (_service) {
  147. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  148. if (client) {
  149. clients.pushObject({
  150. component_name: client.component_name,
  151. display_name: client.display_name,
  152. isInstalled: false
  153. });
  154. }
  155. }, this);
  156. App.db.setClientsForSelectedServices(clients);
  157. this.set('content.clients', clients);
  158. console.log("InstallerController.saveClients: saved list ", clients);
  159. },
  160. /**
  161. * Load data for all steps until <code>current step</code>
  162. */
  163. loadAllPriorSteps: function () {
  164. var step = this.get('currentStep');
  165. switch (step) {
  166. case '10':
  167. case '9':
  168. case '8':
  169. case '7':
  170. this.loadServiceConfigProperties();
  171. case '6':
  172. this.loadSlaveComponentHosts();
  173. this.loadClients();
  174. case '5':
  175. this.loadMasterComponentHosts();
  176. this.loadConfirmedHosts();
  177. case '4':
  178. this.loadServices();
  179. case '3':
  180. this.loadConfirmedHosts();
  181. case '2':
  182. this.load('installOptions');
  183. case '1':
  184. this.load('cluster');
  185. }
  186. },
  187. /**
  188. * Clear all temporary data
  189. */
  190. finish: function () {
  191. this.setCurrentStep('1');
  192. this.clearStorageData();
  193. }
  194. });