WsTopology.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/_base/array",
  21. "dojo/_base/Deferred",
  22. "hpcc/ESPRequest"
  23. ], function (declare, lang, arrayUtil, Deferred,
  24. ESPRequest) {
  25. return {
  26. TpServiceQuery: function (params) {
  27. lang.mixin(params.request, {
  28. Type: "ALLSERVICES"
  29. });
  30. return ESPRequest.send("WsTopology", "TpServiceQuery", params);
  31. },
  32. GetESPServiceBaseURL: function (type) {
  33. var deferred = new Deferred();
  34. var context = this;
  35. this.TpServiceQuery({}).then(function (response) {
  36. var retVal = "";
  37. if (lang.exists("TpServiceQueryResponse.ServiceList.TpEspServers.TpEspServer", response)) {
  38. arrayUtil.forEach(response.TpServiceQueryResponse.ServiceList.TpEspServers.TpEspServer, function (item, idx) {
  39. if (lang.exists("TpBindings.TpBinding", item)) {
  40. arrayUtil.forEach(item.TpBindings.TpBinding, function (binding, idx) {
  41. if (binding.Name === type) {
  42. retVal = ESPRequest.getURL({
  43. port: binding.Port,
  44. pathname: ""
  45. });
  46. return true;
  47. }
  48. });
  49. }
  50. if (retVal !== "")
  51. return true;
  52. });
  53. }
  54. deferred.resolve(retVal);
  55. });
  56. return deferred.promise;
  57. },
  58. WsEclURL: "",
  59. GetWsEclURL: function (type) {
  60. var deferred = new Deferred();
  61. if (this.WsEclURL === "") {
  62. var context = this;
  63. this.GetESPServiceBaseURL("ws_ecl").then(function (response) {
  64. context.WsEclURL = response + "/WsEcl/";
  65. deferred.resolve(context.WsEclURL + type + "/query/");
  66. });
  67. } else {
  68. deferred.resolve(this.WsEclURL + type + "/query/");
  69. }
  70. return deferred.promise;
  71. },
  72. WsEclIFrameURL: "",
  73. GetWsEclIFrameURL: function (type) {
  74. var deferred = new Deferred();
  75. if (this.WsEclIFrameURL === "") {
  76. var context = this;
  77. this.GetESPServiceBaseURL("ws_ecl").then(function (response) {
  78. context.WsEclIFrameURL = response + "/esp/files/stub.htm?Widget=IFrameWidget&src=" + encodeURIComponent("/WsEcl/");
  79. deferred.resolve(context.WsEclIFrameURL + encodeURIComponent(type + "/query/"));
  80. });
  81. } else {
  82. deferred.resolve(this.WsEclIFrameURL + encodeURIComponent(type + "/query/"));
  83. }
  84. return deferred.promise;
  85. },
  86. TpTargetClusterQuery: function (params) {
  87. return ESPRequest.send("WsTopology", "TpTargetClusterQuery", params);
  88. },
  89. TpGroupQuery: function (params) {
  90. return ESPRequest.send("WsTopology", "TpGroupQuery", params);
  91. },
  92. TpLogicalClusterQuery: function (params) {
  93. return ESPRequest.send("WsTopology", "TpLogicalClusterQuery", params).then(function (response) {
  94. var best = null;
  95. var hthor = null;
  96. if (lang.exists("TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster", response)) {
  97. arrayUtil.forEach(response.TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster, function (item, idx) {
  98. if (!best) {
  99. best = item;
  100. }
  101. if (item.Name.indexOf("hthor") !== -1) {
  102. hthor = item;
  103. return false;
  104. } else if (item.Name.indexOf("thor") !== -1) {
  105. best = item;
  106. }
  107. });
  108. }
  109. if (hthor) {
  110. response.TpLogicalClusterQueryResponse["default"] = hthor;
  111. } else if (best) {
  112. response.TpLogicalClusterQueryResponse["default"] = best;
  113. } else {
  114. response.TpLogicalClusterQueryResponse["default"] = null;
  115. }
  116. return response;
  117. });
  118. }
  119. };
  120. });