123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- /*##############################################################################
- # Copyright (C) 2011 HPCC Systems.
- #
- # All rights reserved. This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/_base/xhr",
- "hpcc/ESPResult",
- "hpcc/ESPBase"
- ], function (declare, lang, xhr, ESPResult, ESPBase) {
- return declare(ESPBase, {
- wuid: "",
- stateID: 0,
- state: "",
- text: "",
- resultCount: 0,
- results: [],
- graphs: [],
- exceptions: [],
- timers: [],
- onCreate: function () {
- },
- onUpdate: function () {
- },
- onSubmit: function () {
- },
- constructor: function (args) {
- declare.safeMixin(this, args);
- if (!this.wuid) {
- this.create();
- }
- },
- isComplete: function () {
- switch (this.stateID) {
- case 3: //WUStateCompleted:
- case 4: //WUStateFailed:
- case 5: //WUStateArchived:
- case 7: //WUStateAborted:
- return true;
- }
- return false;
- },
- monitor: function (callback, monitorDuration) {
- if (!monitorDuration)
- monitorDuration = 0;
- var request = {};
- request['Wuid'] = this.wuid;
- request['rawxml_'] = "1";
- var context = this;
- xhr.post({
- url: this.getBaseURL() + "/WUQuery.json",
- handleAs: "json",
- content: request,
- load: function (response) {
- var workunit = response.WUQueryResponse.Workunits.ECLWorkunit[0];
- context.stateID = workunit.StateID;
- context.state = workunit.State;
- if (callback) {
- callback(context);
- }
- if (!context.isComplete()) {
- var timeout = 30; // Seconds
- if (monitorDuration < 5) {
- timeout = 1;
- } else if (monitorDuration < 10) {
- timeout = 2;
- } else if (monitorDuration < 30) {
- timeout = 5;
- } else if (monitorDuration < 60) {
- timeout = 10;
- } else if (monitorDuration < 120) {
- timeout = 20;
- }
- setTimeout(function () {
- context.monitor(callback, monitorDuration + timeout);
- }, timeout * 1000);
- }
- },
- error: function () {
- done = true;
- }
- });
- },
- create: function (ecl) {
- var request = {};
- request['rawxml_'] = "1";
- var context = this;
- xhr.post({
- url: this.getBaseURL() + "/WUCreate.json",
- handleAs: "json",
- content: request,
- load: function (response) {
- context.wuid = response.WUCreateResponse.Workunit.Wuid;
- context.onCreate();
- },
- error: function () {
- }
- });
- },
- update: function (ecl, graphName, svg) {
- var request = {};
- request['Wuid'] = this.wuid;
- if (ecl) {
- request['QueryText'] = ecl;
- }
- if (graphName && svg) {
- /*
- request['ApplicationValues'] = {
- ApplicationValue: {
- itemcount: 1,
- Application: "ESPWorkunit.js",
- Name: graphName + "_SVG",
- Value: svg
- }
- }
- */
- request['ApplicationValues.ApplicationValue.itemcount'] = 1;
- request['ApplicationValues.ApplicationValue.0.Application'] = "ESPWorkunit.js";
- request['ApplicationValues.ApplicationValue.0.Name'] = graphName + "_SVG";
- request['ApplicationValues.ApplicationValue.0.Value'] = svg;
- }
- request['rawxml_'] = "1";
- var context = this;
- xhr.post({
- url: this.getBaseURL() + "/WUUpdate.json",
- handleAs: "json",
- content: request,
- load: function (response) {
- context.onUpdate();
- },
- error: function (error) {
- }
- });
- },
- submit: function (target) {
- var request = {
- Wuid: this.wuid,
- Cluster: target
- };
- request['rawxml_'] = "1";
- var context = this;
- xhr.post({
- url: this.getBaseURL() + "/WUSubmit.json",
- handleAs: "json",
- content: request,
- load: function (response) {
- context.onSubmit();
- },
- error: function (error) {
- }
- });
- },
- getInfo: function (args) {
- var request = {
- Wuid: this.wuid,
- TruncateEclTo64k: args.onGetText ? false : true,
- IncludeExceptions: args.onGetExceptions ? true : false,
- IncludeGraphs: args.onGetGraphs ? true : false,
- IncludeSourceFiles: false,
- IncludeResults: args.onGetResults ? true : false,
- IncludeResultsViewNames: false,
- IncludeVariables: false,
- IncludeTimers: args.onGetTimers ? true : false,
- IncludeDebugValues: false,
- IncludeApplicationValues: args.onGetApplicationValues ? true : false,
- IncludeWorkflows: false,
- SuppressResultSchemas: args.onGetResults ? false : true,
- };
- request['rawxml_'] = "1";
- var context = this;
- xhr.post({
- url: this.getBaseURL() + "/WUInfo.json",
- handleAs: "json",
- content: request,
- load: function (response) {
- //var workunit = context.getValue(xmlDom, "Workunit", ["ECLException", "ECLResult", "ECLGraph", "ECLTimer", "ECLSchemaItem", "ApplicationValue"]);
- var workunit = response.WUInfoResponse.Workunit;
- if (args.onGetText && workunit.Query.Text) {
- context.text = workunit.Query.Text;
- args.onGetText(context.text);
- }
- if (args.onGetExceptions && workunit.Exceptions && workunit.Exceptions.ECLException) {
- context.exceptions = [];
- for (var i = 0; i < workunit.Exceptions.ECLException.length; ++i) {
- if (workunit.Exceptions.ECLException[i].Severity == "Error" ||
- workunit.Exceptions.ECLException[i].Severity == "Warning")
- context.exceptions.push(workunit.Exceptions.ECLException[i]);
- }
- args.onGetExceptions(context.exceptions);
- }
- if (args.onGetApplicationValues && workunit.ApplicationValues && workunit.ApplicationValues.ApplicationValue) {
- context.applicationValues = workunit.ApplicationValues.ApplicationValue;
- args.onGetApplicationValues(context.applicationValues)
- }
- if (args.onGetResults && workunit.Results && workunit.Results.ECLResult) {
- context.results = [];
- var results = workunit.Results.ECLResult;
- for (var i = 0; i < results.length; ++i) {
- context.results.push(new ESPResult(lang.mixin({ wuid: context.wuid }, results[i])));
- }
- args.onGetResults(context.results);
- }
- if (args.onGetTimers && workunit.Timers && workunit.Timers.ECLTimer) {
- context.timers = workunit.Timers.ECLTimer;
- args.onGetTimers(context.timers);
- }
- if (args.onGetGraphs && workunit.Graphs && workunit.Graphs.ECLGraph) {
- context.graphs = workunit.Graphs.ECLGraph;
- if (context.timers || context.applicationValues) {
- for (var i = 0; i < context.graphs.length; ++i) {
- if (context.timers) {
- context.graphs[i].Time = 0;
- for (var j = 0; j < context.timers.length; ++j) {
- if (context.timers[j].GraphName == context.graphs[i].Name) {
- context.graphs[i].Time += parseFloat(context.timers[j].Value);
- }
- context.graphs[i].Time = Math.round(context.graphs[i].Time * 1000) / 1000;
- }
- }
- if (context.applicationValues) {
- var idx = context.getApplicationValueIndex("ESPWorkunit.js", context.graphs[i].Name + "_SVG");
- if (idx >= 0) {
- context.graphs[i].svg = context.applicationValues[idx].Value;
- }
- }
- }
- }
- args.onGetGraphs(context.graphs)
- }
- if (args.onGetAll) {
- args.onGetAll(workunit);
- }
- },
- error: function (e) {
- }
- });
- },
- getGraphIndex: function (name) {
- for (var i = 0; i < this.graphs.length; ++i) {
- if (this.graphs[i].Name == name) {
- return i;
- }
- }
- return -1;
- },
- getApplicationValueIndex: function (application, name) {
- for (var i = 0; i < this.applicationValues.length; ++i) {
- if (this.applicationValues[i].Application == application && this.applicationValues[i].Name == name) {
- return i;
- }
- }
- return -1;
- },
- fetchText: function (onFetchText) {
- if (this.text) {
- onFetchText(this.text);
- return;
- }
- this.getInfo({
- onGetText: onFetchText
- });
- },
- fetchResults: function (onFetchResults) {
- if (this.results && this.results.length) {
- onFetchResults(this.results);
- return;
- }
- this.getInfo({
- onGetResults: onFetchResults
- });
- },
- fetchGraphs: function (onFetchGraphs) {
- if (this.graphs && this.graphs.length) {
- onFetchGraphs(this.graphs);
- return;
- }
- this.getInfo({
- onGetGraphs: onFetchGraphs
- });
- },
- fetchGraphXgmmlByName: function (name, onFetchGraphXgmml) {
- var idx = this.getGraphIndex(name);
- if (idx >= 0) {
- this.fetchGraphXgmml(idx, onFetchGraphXgmml);
- }
- },
- fetchGraphXgmml: function (idx, onFetchGraphXgmml) {
- var request = {};
- request['Wuid'] = this.wuid;
- request['GraphName'] = this.graphs[idx].Name;
- request['rawxml_'] = "1";
- var context = this;
- xhr.post({
- url: this.getBaseURL() + "/WUGetGraph.json",
- handleAs: "json",
- content: request,
- load: function (response) {
- context.graphs[idx].xgmml = response.WUGetGraphResponse.Graphs.ECLGraphEx[0].Graph;
- onFetchGraphXgmml(context.graphs[idx].xgmml, context.graphs[idx].svg);
- },
- error: function () {
- }
- });
- },
- setGraphSvg: function (graphName, svg) {
- var idx = this.getGraphIndex(graphName);
- if (idx >= 0) {
- this.graphs[idx].svg = svg;
- this.update(null, graphName, svg);
- }
- }
- });
- });
|