step4_controller.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. var db = require('utils/db');
  20. App.InstallerStep4Controller = Em.ArrayController.extend({
  21. name: 'installerStep4Controller',
  22. rawContent: require('data/mock/services'),
  23. content: [],
  24. isAll: function () {
  25. return this.everyProperty('isSelected', true);
  26. }.property('@each.isSelected'),
  27. isMinimum: function () {
  28. return this.filterProperty('isDisabled', false).everyProperty('isSelected', false);
  29. }.property('@each.isSelected'),
  30. checkDependencies: function () {
  31. var hbase = this.findProperty('serviceName', 'HBASE');
  32. var zookeeper = this.findProperty('serviceName', 'ZOOKEEPER');
  33. if (hbase && zookeeper) {
  34. zookeeper.set('isSelected', hbase.get('isSelected'));
  35. }
  36. var hive = this.findProperty('serviceName', 'HIVE');
  37. var hcatalog = this.findProperty('serviceName', 'HCATALOG');
  38. if (hive && hcatalog) {
  39. hcatalog.set('isSelected', hive.get('isSelected'));
  40. }
  41. }.observes('@each.isSelected'),
  42. clearStep: function () {
  43. this.clear();
  44. },
  45. loadStep: function() {
  46. this.clearStep();
  47. this.renderStep(this.loadServices());
  48. },
  49. loadServices: function() {
  50. return db.getService();
  51. },
  52. /*
  53. loadStepFromContent: function () {
  54. console.log("TRACE: Loading from rawContent/API step4: Choose Services");
  55. this.clear();
  56. var rawContent = this.rawContent;
  57. rawContent.setEach('isSelected', true);
  58. this.renderStep(rawContent);
  59. },
  60. */
  61. /*
  62. loadStepFromDb: function () {
  63. console.log("TRACE: Loading form localStorage step4: Choose Services");
  64. this.clear();
  65. var rawContent = this.rawContent;
  66. rawContent.setEach('isSelected', false);
  67. var services = App.db.getSelectedServiceNames();
  68. if (services !== undefined && services !== null) {
  69. rawContent.forEach(function (_content) {
  70. var serviceFound = services.contains(_content.serviceName);
  71. if (serviceFound) {
  72. _content.isSelected = true;
  73. } else {
  74. _content.isSelected = false;
  75. }
  76. console.log('TRACE: value of service is: ' + _content.serviceName);
  77. });
  78. this.renderStep(rawContent);
  79. }
  80. },
  81. */
  82. renderStep: function (serviceInfo) {
  83. serviceInfo.forEach(function (item) {
  84. this.pushObject(Ember.Object.create(item));
  85. }, this);
  86. },
  87. selectAll: function () {
  88. this.setEach('isSelected', true);
  89. },
  90. selectMinimum: function () {
  91. this.filterProperty('isDisabled', false).setEach('isSelected', false);
  92. },
  93. saveSelectedServiceNamesToDB: function () {
  94. var serviceNames = [];
  95. db.setService(this.get('content'));
  96. this.filterProperty('isSelected', true).forEach(function (item) {
  97. serviceNames.push(item.serviceName);
  98. });
  99. db.setSelectedServiceNames(serviceNames);
  100. },
  101. needToAddMapReduce: function () {
  102. if (this.findProperty('serviceName', 'MAPREDUCE').get('isSelected') === false) {
  103. var mapreduceDependentServices = this.filter(function (item) {
  104. return ['PIG', 'OOZIE', 'HIVE'].contains(item.get('serviceName')) && item.get('isSelected', true);
  105. });
  106. return (mapreduceDependentServices.get('length') > 0);
  107. } else {
  108. return false;
  109. }
  110. },
  111. gangliaOrNagiosNotSelected: function () {
  112. return (this.findProperty('serviceName', 'GANGLIA').get('isSelected') === false || this.findProperty('serviceName', 'NAGIOS').get('isSelected') === false);
  113. },
  114. submit: function () {
  115. var self = this;
  116. if (this.needToAddMapReduce()) {
  117. App.ModalPopup.show({
  118. header: Em.I18n.t('installer.step4.mapreduceCheck.popup.header'),
  119. body: Em.I18n.t('installer.step4.mapreduceCheck.popup.body'),
  120. onPrimary: function () {
  121. self.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  122. this.hide();
  123. self.validateMonitoring();
  124. },
  125. onSecondary: function () {
  126. this.hide();
  127. }
  128. });
  129. } else {
  130. self.validateMonitoring();
  131. }
  132. },
  133. validateMonitoring: function () {
  134. var self = this;
  135. if (this.gangliaOrNagiosNotSelected()) {
  136. App.ModalPopup.show({
  137. header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),
  138. body: Em.I18n.t('installer.step4.monitoringCheck.popup.body'),
  139. onPrimary: function () {
  140. this.hide();
  141. self.proceed();
  142. },
  143. onSecondary: function () {
  144. this.hide();
  145. }
  146. });
  147. } else {
  148. self.proceed();
  149. }
  150. },
  151. proceed: function () {
  152. this.saveSelectedServiceNamesToDB();
  153. App.router.send('next');
  154. }
  155. })