浏览代码

Merge pull request #4681 from GordonSmith/HPCC-9766

HPCC-9766 Defaulting to "hthor" is often wrong

Reviewed-By: Miguel Vazquez <miguel.vazquez@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 年之前
父节点
当前提交
3bddcd672d

+ 3 - 0
esp/files/scripts/ESPRequest.js

@@ -104,6 +104,9 @@ define([
         },
 
         send: function (service, action, params) {
+            if (!params)
+                params = {};
+
             dojo.publish("hpcc/standbyBackgroundShow");
             var handleAs = params.handleAs ? params.handleAs : "json";
             return this._send(service, action, params).then(function (response) {

+ 23 - 9
esp/files/scripts/ESPWorkunit.js

@@ -23,11 +23,12 @@ define([
     "dojo/store/Observable",
 
     "hpcc/WsWorkunits",
+    "hpcc/WsTopology",
     "hpcc/ESPUtil",
     "hpcc/ESPRequest",
     "hpcc/ESPResult"
 ], function (declare, arrayUtil, lang, Deferred, ObjectStore, QueryResults, Observable,
-    WsWorkunits, ESPUtil, ESPRequest, ESPResult) {
+    WsWorkunits, WsTopology, ESPUtil, ESPRequest, ESPResult) {
 
     var _workunits = {};
 
@@ -190,15 +191,28 @@ define([
         submit: function (target) {
             this._assertHasWuid();
             var context = this;
-            WsWorkunits.WUSubmit({
-                request: {
-                    Wuid: this.Wuid,
-                    Cluster: target
-                },
-                load: function (response) {
-                    context.onSubmit();
-                }
+            var deferred = new Deferred()
+            deferred.promise.then(function (target) {
+                WsWorkunits.WUSubmit({
+                    request: {
+                        Wuid: context.Wuid,
+                        Cluster: target
+                    },
+                    load: function (response) {
+                        context.onSubmit();
+                    }
+                });
             });
+
+            if (target) {
+                deferred.resolve(target);
+            } else {
+                WsTopology.TpLogicalClusterQuery().then(function (response) {
+                    if (lang.exists("TpLogicalClusterQueryResponse.default", response)) {
+                        deferred.resolve(response.TpLogicalClusterQueryResponse.default.Name);
+                    }
+                });
+            }
         },
         _resubmit: function (clone, resetWorkflow) {
             this._assertHasWuid();

+ 1 - 1
esp/files/scripts/HexViewWidget.js

@@ -109,7 +109,7 @@ define([
                         context.watchWU();
                     },
                     onUpdate: function () {
-                        context.wu.submit("hthor");
+                        context.wu.submit();
                     },
                     onSubmit: function () {
                     }

+ 2 - 6
esp/files/scripts/TargetSelectWidget.js

@@ -172,20 +172,16 @@ require([
             }).then(function (response) {
                 if (lang.exists("TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster", response)) {
                     var targetData = response.TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster;
-                    var has_hthor = false;
                     for (var i = 0; i < targetData.length; ++i) {
                         context.options.push({
                             label: targetData[i].Name,
                             value: targetData[i].Name
                         });
-                        if (targetData[i].Name == "hthor") {
-                            has_hthor = true;
-                        }
                     }
 
                     if (!context.includeBlank && context._value == "") {
-                        if (has_hthor) {
-                            context._value = "hthor";
+                        if (response.TpLogicalClusterQueryResponse.default) {
+                            context._value = response.TpLogicalClusterQueryResponse.default.Name;
                         } else {
                             context._value = context.options[0].value;
                         }

+ 28 - 6
esp/files/scripts/WsTopology.js

@@ -17,14 +17,12 @@
 define([
     "dojo/_base/declare",
     "dojo/_base/lang",
-    "dojo/_base/xhr",
+    "dojo/_base/array",
     "dojo/_base/Deferred",
-    "dojo/store/util/QueryResults",
 
-    "hpcc/ESPBase",
     "hpcc/ESPRequest"
-], function (declare, lang, xhr, Deferred, QueryResults,
-    ESPBase, ESPRequest) {
+], function (declare, lang, arrayUtil, Deferred,
+    ESPRequest) {
     return {
         TpServiceQuery: function (params) {
             lang.mixin(params.request, {
@@ -39,7 +37,31 @@ define([
             return ESPRequest.send("WsTopology", "TpGroupQuery", params);
         },
         TpLogicalClusterQuery: function (params) {
-            return ESPRequest.send("WsTopology", "TpLogicalClusterQuery", params);
+            return ESPRequest.send("WsTopology", "TpLogicalClusterQuery", params).then(function (response) {
+                var best = null;
+                var hthor = null;
+                if (lang.exists("TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster", response)) {
+                    arrayUtil.forEach(response.TpLogicalClusterQueryResponse.TpLogicalClusters.TpLogicalCluster, function (item, idx) {
+                        if (!best) {
+                            best = item;
+                        }
+                        if (item.Name.indexOf("hthor") !== -1) {
+                            hthor = item;
+                            return false;
+                        } else if (item.Name.indexOf("thor") !== -1) {
+                            best = item;
+                        }
+                    });
+                }
+                if (hthor) {
+                    response.TpLogicalClusterQueryResponse.default = hthor;
+                } else if (best) {
+                    response.TpLogicalClusterQueryResponse.default = best;
+                } else {
+                    response.TpLogicalClusterQueryResponse.default = null;
+                }
+                return response;
+            });
         }
     };
 });