step4_controller.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. setClientsForSelectedServices: function () {
  82. var clients = [];
  83. var serviceComponents = require('data/service_components');
  84. db.getService().filterProperty('isSelected',true).forEach(function (_service) {
  85. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  86. if (client) {
  87. clients.pushObject({
  88. component_name: client.component_name,
  89. display_name: client.display_name
  90. });
  91. }
  92. }, this);
  93. db.setClientsForSelectedServices(clients);
  94. },
  95. gangliaOrNagiosNotSelected: function () {
  96. return (this.findProperty('serviceName', 'GANGLIA').get('isSelected') === false || this.findProperty('serviceName', 'NAGIOS').get('isSelected') === false);
  97. },
  98. submit: function () {
  99. var self = this;
  100. if (this.needToAddMapReduce()) {
  101. App.ModalPopup.show({
  102. header: Em.I18n.t('installer.step4.mapreduceCheck.popup.header'),
  103. body: Em.I18n.t('installer.step4.mapreduceCheck.popup.body'),
  104. onPrimary: function () {
  105. self.findProperty('serviceName', 'MAPREDUCE').set('isSelected', true);
  106. this.hide();
  107. self.validateMonitoring();
  108. },
  109. onSecondary: function () {
  110. this.hide();
  111. }
  112. });
  113. } else {
  114. self.validateMonitoring();
  115. }
  116. },
  117. validateMonitoring: function () {
  118. var self = this;
  119. if (this.gangliaOrNagiosNotSelected()) {
  120. App.ModalPopup.show({
  121. header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),
  122. body: Em.I18n.t('installer.step4.monitoringCheck.popup.body'),
  123. onPrimary: function () {
  124. this.hide();
  125. self.proceed();
  126. },
  127. onSecondary: function () {
  128. this.hide();
  129. }
  130. });
  131. } else {
  132. self.proceed();
  133. }
  134. },
  135. proceed: function () {
  136. this.saveSelectedServiceNamesToDB();
  137. this.setClientsForSelectedServices();
  138. App.router.send('next');
  139. }
  140. })