step8_controller.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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.InstallerStep8Controller = Em.ArrayController.extend({
  20. name: 'installerStep8Controller',
  21. rawContent: require('data/review_configs'),
  22. content: [],
  23. services: [],
  24. clearStep: function () {
  25. this.clear();
  26. this.services.clear();
  27. },
  28. loadStep: function () {
  29. console.log("TRACE: Loading step8: Review Page");
  30. this.clearStep();
  31. var configObj = new Ember.Set();
  32. this.loadClusterName();
  33. this.loadHosts();
  34. this.loadServices();
  35. // this.doConfigsUneditable();
  36. },
  37. loadClusterName: function () {
  38. var obj = {};
  39. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  40. cluster.config_value = App.db.getClusterName();
  41. this.pushObject(Ember.Object.create(cluster));
  42. },
  43. loadHosts: function () {
  44. var masterHosts = App.db.getMasterComponentHosts().mapProperty('hostName').uniq();
  45. var slaveHosts = App.db.getSlaveComponentHosts();
  46. var hostObj = [];
  47. slaveHosts.forEach(function (_hosts) {
  48. hostObj = hostObj.concat(_hosts.hosts);
  49. }, this);
  50. slaveHosts = hostObj.mapProperty('hostname').uniq();
  51. console.log('The value of slaveHosts is: ' + slaveHosts);
  52. var totalHosts = masterHosts.concat(slaveHosts).uniq().length;
  53. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  54. totalHostsObj.config_value = totalHosts;
  55. this.pushObject(Ember.Object.create(totalHostsObj));
  56. },
  57. loadServices: function () {
  58. this.set('services', App.db.getSelectedServiceNames());
  59. },
  60. submit: function () {
  61. this.createCluster();
  62. this.createSelectedServices();
  63. this.createComponents();
  64. this.createHostComponents();
  65. App.router.send('next');
  66. },
  67. createCluster: function () {
  68. var self = this;
  69. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  70. var url = '/api/clusters/' + clusterName;
  71. $.ajax({
  72. type: 'PUT',
  73. url: url,
  74. async: false,
  75. //accepts: 'text',
  76. dataType: 'text',
  77. timeout: 5000,
  78. success: function (data) {
  79. var jsonData = jQuery.parseJSON(data);
  80. console.log("TRACE: STep8 -> In success function for createCluster call");
  81. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  82. },
  83. error: function (request, ajaxOptions, error) {
  84. console.log('Step8: In Error ');
  85. console.log('Step8: Error message is: ' + request.responseText);
  86. },
  87. statusCode: require('data/statusCodes')
  88. });
  89. },
  90. createSelectedServices: function () {
  91. var services = App.db.getSelectedServiceNames();
  92. services.forEach(function (_service) {
  93. this.createService(_service);
  94. }, this);
  95. },
  96. createService: function (service) {
  97. var self = this;
  98. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  99. var url = '/api/clusters/' + clusterName + '/services/' + service;
  100. $.ajax({
  101. type: 'PUT',
  102. url: url,
  103. async: false,
  104. dataType: 'text',
  105. timeout: 5000,
  106. success: function (data) {
  107. var jsonData = jQuery.parseJSON(data);
  108. console.log("TRACE: STep8 -> In success function for the createService call");
  109. console.log("TRACE: STep8 -> value of the url is: " + url);
  110. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  111. },
  112. error: function (request, ajaxOptions, error) {
  113. console.log('Step8: In Error ');
  114. console.log('Step8: Error message is: ' + request.responseText);
  115. },
  116. statusCode: require('data/statusCodes')
  117. });
  118. },
  119. createComponents: function () {
  120. var serviceComponents = require('data/service_components');
  121. var services = App.db.getSelectedServiceNames();
  122. services.forEach(function (_service) {
  123. var components = serviceComponents.filterProperty('service_name', _service);
  124. components.forEach(function (_component) {
  125. console.log("value of component is: " + _component.component_name);
  126. this.createComponent(_service, _component.component_name);
  127. }, this);
  128. }, this);
  129. },
  130. createComponent: function (service, component) {
  131. var self = this;
  132. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  133. var url = '/api/clusters/' + clusterName + '/services/' + service + '/components/' + component;
  134. $.ajax({
  135. type: 'PUT',
  136. url: url,
  137. async: false,
  138. dataType: 'text',
  139. timeout: 5000,
  140. success: function (data) {
  141. var jsonData = jQuery.parseJSON(data);
  142. console.log("TRACE: STep8 -> value of the url is: " + url);
  143. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  144. },
  145. error: function (request, ajaxOptions, error) {
  146. console.log('Step8: In Error ');
  147. console.log('Step8: Error message is: ' + request.responseText);
  148. },
  149. statusCode: require('data/statusCodes')
  150. });
  151. },
  152. createHostComponents: function () {
  153. var masterHosts = App.db.getMasterComponentHosts();
  154. var slaveHosts = App.db.getSlaveComponentHosts();
  155. masterHosts.forEach(function (_masterHost) {
  156. this.createHostComponent(_masterHost);
  157. }, this);
  158. slaveHosts.forEach(function (_slaveHosts) {
  159. var slaveObj = {};
  160. slaveObj.component = _slaveHosts.componentName;
  161. _slaveHosts.hosts.forEach(function (_slaveHost) {
  162. slaveObj.hostName = _slaveHost.hostname;
  163. this.createHostComponent(slaveObj);
  164. }, this);
  165. }, this);
  166. },
  167. createHostComponent: function (hostComponent) {
  168. var self = this;
  169. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  170. var url = '/api/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  171. $.ajax({
  172. type: 'PUT',
  173. url: url,
  174. async: false,
  175. dataType: 'text',
  176. timeout: 5000,
  177. success: function (data) {
  178. var jsonData = jQuery.parseJSON(data);
  179. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  180. console.log("TRACE: STep8 -> value of the url is: " + url);
  181. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  182. },
  183. error: function (request, ajaxOptions, error) {
  184. console.log('Step8: In Error ');
  185. console.log('Step8: Error message is: ' + request.responseText);
  186. },
  187. statusCode: require('data/statusCodes')
  188. });
  189. }
  190. })
  191. /*
  192. doConfigsUneditable: function () {
  193. this.content.forEach(function (_service) {
  194. _service.get('configs').forEach(function (_serviceConfig) {
  195. console.log('value of isEditable before for: ' + _serviceConfig.name);
  196. console.log('value of isEditable before: ' + _serviceConfig.isEditable);
  197. console.log('value of displayType before: ' + _serviceConfig.displayType);
  198. _serviceConfig.set('isEditable', false);
  199. _serviceConfig.set('displayType', 'string');
  200. console.log('value of isEditable after for: ' + _serviceConfig.name);
  201. console.log('value of isEditable after: ' + _serviceConfig.isEditable);
  202. console.log('value of displayType after: ' + _serviceConfig.displayType);
  203. }, this);
  204. }, this);
  205. }
  206. +
  207. */