testConnectionResults_controller.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.TestConnectionResultsController = Ember.Controller.extend({
  19. name: 'testConnectionResultsController',
  20. connectStatuses: [
  21. Ember.Object.create({
  22. type: 'readonly',
  23. isConnectionSuccess: false
  24. }),
  25. Ember.Object.create({
  26. type: 'write',
  27. isConnectionSuccess: false
  28. }),
  29. Ember.Object.create({
  30. type: 'workflow',
  31. isConnectionSuccess: false
  32. })
  33. ],
  34. isNameNodeWebUIConnected: function () {
  35. var connectStatus = this.get('connectStatuses').findProperty('type', 'readonly');
  36. return connectStatus.get('isConnectionSuccess');
  37. }.property('connectStatuses.@each.isConnectionSuccess'),
  38. isNameNodeRpcConnected: function () {
  39. var connectStatus = this.get('connectStatuses').findProperty('type', 'write');
  40. return connectStatus.get('isConnectionSuccess');
  41. }.property('connectStatuses.@each.isConnectionSuccess'),
  42. isOozieServerConnected: function () {
  43. var connectStatus = this.get('connectStatuses').findProperty('type', 'workflow');
  44. return connectStatus.get('isConnectionSuccess');
  45. }.property('connectStatuses.@each.isConnectionSuccess'),
  46. isConnectionSuccessful: function () {
  47. return this.get('isNameNodeWebUIConnected') && this.get('isNameNodeRpcConnected') && this.get('isOozieServerConnected');
  48. }.property('isNameNodeWebUIConnected', 'isNameNodeRpcConnected', 'isOozieServerConnected'),
  49. shouldBeDisabled: function () {
  50. return !this.get('isConnectionSuccessful');
  51. }.property('isConnectionSuccessful'),
  52. mockDataPrefix: '/data/mirroring/poll/',
  53. tryConnecting: function () {
  54. var types = ["readonly", "write", "workflow"];
  55. var arrayOfPollData = ["testConnection_poll1", "testConnection_poll2", "testConnection_poll3", "testConnection_poll4"];
  56. var shouldContinuePolling = true;
  57. var poll_count = 0;
  58. var interval_id = 0;
  59. var self = this;
  60. var connect = function () {
  61. var method = 'GET';
  62. console.debug('poll_count : ' + poll_count);
  63. var url = self.get('mockDataPrefix') + arrayOfPollData[poll_count++] + ".json";
  64. $.ajax({
  65. type: method,
  66. url: url,
  67. async: true, // shd be chnaged to true
  68. data: null, // temporarily .this depends upon what the api is expecting.
  69. dataType: 'text',
  70. timeout: App.timeout,
  71. success: function (data) {
  72. var jsonData = jQuery.parseJSON(data);
  73. var connectStatuses = self.get('connectStatuses');
  74. jsonData.tasks.forEach(function (task) {
  75. var type = task.Tasks.type;
  76. var status = task.Tasks.status;
  77. var connectStatus = connectStatuses.findProperty("type", type);
  78. connectStatus.set('isConnectionSuccess', status === "SUCCESS");
  79. });
  80. var totalNum = connectStatuses.length;
  81. var succeededStatuses = connectStatuses.filterProperty("isConnectionSuccess", true);
  82. var succeededNum = succeededStatuses.length;
  83. if (totalNum == succeededNum) {
  84. clearInterval(interval_id);
  85. console.debug('Cleared function id ' + interval_id);
  86. }
  87. else {
  88. clearInterval(interval_id);
  89. console.debug('Cleared function id ' + interval_id + "totalNum : " + totalNum + ', succeededNum : ' + succeededNum);
  90. interval_id = setInterval(connect, 100);
  91. console.debug('Generated function id ' + interval_id);
  92. }
  93. }
  94. });
  95. };
  96. connect();
  97. },
  98. saveClusterName: function () {
  99. var targetCluster = this.get('content.targetCluster');
  100. var isEditing = this.get('content.isPopupForEdit');
  101. if (isEditing) {
  102. var targetClusterRecord = this.get('content.originalRecord');
  103. var targetClusterEdited = this.get('content.targetCluster');
  104. targetClusterRecord.set('id', targetClusterEdited.get('id'));
  105. targetClusterRecord.set('clusterName', targetClusterEdited.get('clusterName'));
  106. targetClusterRecord.set('nameNodeWebUrl', targetClusterEdited.get('nameNodeRpcUrl'));
  107. targetClusterRecord.set('nameNodeRpcUrl', targetClusterEdited.get('id'));
  108. targetClusterRecord.set('oozieServerUrl', targetClusterEdited.get('oozieServerUrl'));
  109. } else {
  110. var targetClusterRecord = App.TargetCluster.createRecord(targetCluster);
  111. // refresh main page model
  112. var mainMirroringController = App.router.get('mainMirroringController');
  113. mainMirroringController.notifyPropertyChange("targetClusters");
  114. // refresh add/edit dataset model
  115. var addDataSetController = App.router.get('mainMirroringDataSetController');
  116. var dataSet = addDataSetController.get('model.newDataSet');
  117. if (dataSet) // this may be undefined or null if we try to add cluster from main page. Hence the if check.
  118. dataSet.set('targetCluster', targetClusterRecord);
  119. }
  120. var popup = this.get('controllers.mainMirroringTargetClusterController.popup');
  121. popup.hide();
  122. }
  123. });