targetClusterController.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. App.MainMirroringTargetClusterController = Ember.Controller.extend({
  19. name: 'mainMirroringTargetClusterController',
  20. model: Ember.Object.create({
  21. targetCluster: null,
  22. originalRecord: null,
  23. isPopupForEdit: false, // set the default to add scenario
  24. isNameNodeWebUrlError: function (key, value) {
  25. if (value) {
  26. return value;
  27. }
  28. var controller = App.router.get('mainMirroringTargetClusterController');
  29. return controller.checkNameNodeWebUrlErrors();
  30. }.property('targetCluster.nameNodeWebUrl', 'model.targetCluster.nameNodeWebUrl'),
  31. isNameNodeRpcUrlError: function (key, value) {
  32. if (value) {
  33. return value;
  34. }
  35. var controller = App.router.get('mainMirroringTargetClusterController');
  36. return controller.checkNameNodeRpcUrlErrors();
  37. }.property('targetCluster.nameNodeRpcUrl', 'model.targetCluster.nameNodeRpcUrl'),
  38. isOozieServerUrlError: function (key, value) {
  39. if (value) {
  40. return value;
  41. }
  42. var controller = App.router.get('mainMirroringTargetClusterController');
  43. return controller.checkOozieServerUrlErrors();
  44. }.property('targetCluster.oozieServerUrl', 'model.targetCluster.oozieServerUrl'),
  45. isClusterNameError: function (key, value) {
  46. if (value) {
  47. return value;
  48. }
  49. var controller = App.router.get('mainMirroringTargetClusterController');
  50. return controller.checkClusterNameErrors();
  51. }.property('targetCluster.clusterName', 'model.targetCluster.clusterName'),
  52. nameNodeWebUrlErrorMessage: null,
  53. nameNodeRpcUrlErrorMessage: null,
  54. oozieServerUrlErrorMessage: null,
  55. clusterNameErrorMessage: null
  56. }),
  57. isSubmitted1: null,
  58. isSubmitted2: null,
  59. validate1: function () {
  60. var isNameNodeWebUrlError = this.checkNameNodeWebUrlErrors();
  61. var isNameNodeRpcUrlError = this.checkNameNodeRpcUrlErrors();
  62. var isOozieServerUrlError = this.checkOozieServerUrlErrors();
  63. return !(isNameNodeWebUrlError || isNameNodeRpcUrlError || isOozieServerUrlError);
  64. },
  65. validate2: function () {
  66. return !this.checkClusterNameErrors();
  67. },
  68. checkNameNodeWebUrlErrors: function () {
  69. if (!this.get('isSubmitted1')){
  70. this.set('model.nameNodeWebUrlErrorMessage', "");
  71. return false;
  72. }
  73. var nameNodeWebUrl = this.get('model.targetCluster.nameNodeWebUrl');
  74. if (!nameNodeWebUrl || nameNodeWebUrl.trim() === "") {
  75. this.set('model.isNameNodeWebUrlError', true);
  76. this.set('model.nameNodeWebUrlErrorMessage', Em.I18n.t('mirroring.required.error'));
  77. return true;
  78. }
  79. else {
  80. this.set('model.nameNodeWebUrlErrorMessage', "");
  81. return false;
  82. }
  83. },
  84. checkNameNodeRpcUrlErrors: function () {
  85. if (!this.get('isSubmitted1')){
  86. this.set('model.nameNodeRpcUrlErrorMessage', "");
  87. return false;
  88. }
  89. var nameNodeRpcUrl = this.get('model.targetCluster.nameNodeRpcUrl');
  90. if (!nameNodeRpcUrl || nameNodeRpcUrl.trim() === "") {
  91. this.set('model.isNameNodeRpcUrlError', true);
  92. this.set('model.nameNodeRpcUrlErrorMessage', Em.I18n.t('mirroring.required.error'));
  93. return true;
  94. }
  95. else {
  96. this.set('model.nameNodeRpcUrlErrorMessage', "");
  97. return false;
  98. }
  99. },
  100. checkOozieServerUrlErrors: function () {
  101. if (!this.get('isSubmitted1')){
  102. this.set('model.oozieServerUrlErrorMessage', "");
  103. return false;
  104. }
  105. var oozieServerUrl = this.get('model.targetCluster.oozieServerUrl');
  106. if (!oozieServerUrl || oozieServerUrl.trim() === "") {
  107. this.set('model.isOozieServerUrlError', true);
  108. this.set('model.oozieServerUrlErrorMessage', Em.I18n.t('mirroring.required.error'));
  109. return true;
  110. }
  111. else {
  112. this.set('model.oozieServerUrlErrorMessage', "");
  113. return false;
  114. }
  115. },
  116. checkClusterNameErrors: function () {
  117. if (!this.get('isSubmitted1')){
  118. this.set('model.clusterNameErrorMessage', "");
  119. return false;
  120. }
  121. var clusterName = this.get('model.targetCluster.clusterName');
  122. if (!clusterName || clusterName.trim() === "") {
  123. this.set('model.isClusterNameError', true);
  124. this.set('model.clusterNameErrorMessage', Em.I18n.t('mirroring.required.error'));
  125. return true;
  126. }
  127. else {
  128. this.set('model.clusterNameErrorMessage', "");
  129. return false;
  130. }
  131. },
  132. setOriginalRecord: function (targetClusterRecord) {
  133. this.set('model.originalRecord', targetClusterRecord);
  134. },
  135. setTargetCluster: function (targetClusterRecord) {
  136. var targetCluster = Ember.Object.create({
  137. id: targetClusterRecord.get('id'),
  138. clusterName: targetClusterRecord.get('clusterName'),
  139. nameNodeWebUrl: targetClusterRecord.get('nameNodeWebUrl'),
  140. nameNodeRpcUrl: targetClusterRecord.get('nameNodeRpcUrl'),
  141. oozieServerUrl: targetClusterRecord.get('oozieServerUrl')
  142. });
  143. this.set('model.targetCluster', targetCluster);
  144. },
  145. createTargetCluster: function () {
  146. var targetCluster = Ember.Object.create({
  147. clusterName: null,
  148. nameNodeWebUrl: null,
  149. nameNodeRpcUrl: null,
  150. oozieServerUrl: null
  151. });
  152. this.set('model.targetCluster', targetCluster);
  153. return targetCluster;
  154. /* For future (but on record objects , not on pojos):
  155. targetCluster.on('didUpdate', function() {
  156. console.log("------Updated!");
  157. });
  158. targetCluster.on('didDelete', function() {
  159. console.log("------Deleted!");
  160. });
  161. targetCluster.on('didCreate', function() {
  162. console.log("------Created!");
  163. });
  164. */
  165. },
  166. getTargetCluster: function () {
  167. return this.get('content.targetCluster');
  168. },
  169. popup: null,
  170. /**
  171. * "Delete" button handler.
  172. * A DataSet
  173. */
  174. deleteTargetCluster: function () {
  175. var self = this;
  176. App.showConfirmationPopup(function () {
  177. var originalRecord = self.get('model.originalRecord');
  178. originalRecord.deleteRecord();
  179. originalRecord.get("transaction").commit();
  180. self.get('popup').hide();
  181. App.router.transitionTo('main.mirroring.index');
  182. });
  183. }
  184. });