step4_controller.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. renderStep: function (serviceInfo) {
  53. serviceInfo.forEach(function (item) {
  54. this.pushObject(Ember.Object.create(item));
  55. }, this);
  56. },
  57. selectAll: function () {
  58. this.setEach('isSelected', true);
  59. },
  60. selectMinimum: function () {
  61. this.filterProperty('isDisabled', false).setEach('isSelected', false);
  62. },
  63. saveSelectedServiceNamesToDB: function () {
  64. var serviceNames = [];
  65. db.setService(this.get('content'));
  66. this.filterProperty('isSelected', true).forEach(function (item) {
  67. serviceNames.push(item.serviceName);
  68. });
  69. db.setSelectedServiceNames(serviceNames);
  70. },
  71. needToAddMapReduce: function () {
  72. if (this.findProperty('serviceName', 'MAPREDUCE').get('isSelected') === false) {
  73. var mapreduceDependentServices = this.filter(function (item) {
  74. return ['PIG', 'OOZIE', 'HIVE'].contains(item.get('serviceName')) && item.get('isSelected', true);
  75. });
  76. return (mapreduceDependentServices.get('length') > 0);
  77. } else {
  78. return false;
  79. }
  80. },
  81. gangliaOrNagiosNotSelected: function () {
  82. return (this.findProperty('serviceName', 'GANGLIA').get('isSelected') === false || this.findProperty('serviceName', 'NAGIOS').get('isSelected') === false);
  83. },
  84. submit: function () {
  85. var self = this;
  86. if (this.needToAddMapReduce()) {
  87. App.ModalPopup.show({
  88. header: Em.I18n.t('installer.step4.mapreduceCheck.popup.header'),
  89. body: Em.I18n.t('installer.step4.mapreduceCheck.popup.body'),
  90. onPrimary: function () {
  91. self.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  92. this.hide();
  93. self.validateMonitoring();
  94. },
  95. onSecondary: function () {
  96. this.hide();
  97. }
  98. });
  99. } else {
  100. self.validateMonitoring();
  101. }
  102. },
  103. validateMonitoring: function () {
  104. var self = this;
  105. if (this.gangliaOrNagiosNotSelected()) {
  106. App.ModalPopup.show({
  107. header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),
  108. body: Em.I18n.t('installer.step4.monitoringCheck.popup.body'),
  109. onPrimary: function () {
  110. this.hide();
  111. self.proceed();
  112. },
  113. onSecondary: function () {
  114. this.hide();
  115. }
  116. });
  117. } else {
  118. self.proceed();
  119. }
  120. },
  121. proceed: function () {
  122. this.saveSelectedServiceNamesToDB();
  123. App.router.send('next');
  124. }
  125. })