FileSpray.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/_base/array",
  20. "dojo/_base/Deferred",
  21. "dojo/store/util/QueryResults",
  22. "dojo/store/JsonRest",
  23. "dojo/store/Memory",
  24. "dojo/store/Cache",
  25. "dojo/store/Observable",
  26. "dojox/xml/parser",
  27. "hpcc/ESPBase",
  28. "hpcc/ESPRequest"
  29. ], function (declare, lang, arrayUtil, Deferred, QueryResults, JsonRest, Memory, Cache, Observable,
  30. parser,
  31. ESPBase, ESPRequest) {
  32. var FileListStore = declare([ESPRequest.Store], {
  33. service: "FileSpray",
  34. action: "FileList",
  35. responseQualifier: "FileListResponse.files.PhysicalFileStruct",
  36. idProperty: "calculatedID",
  37. create: function (id) {
  38. var retVal = {
  39. lfEncode: function(path) {
  40. var retVal = "";
  41. for (var i = 0; i < path.length; ++i) {
  42. switch (path[i]) {
  43. case "/":
  44. case "\\":
  45. retVal += "::";
  46. break;
  47. case "A":
  48. case "B":
  49. case "C":
  50. case "D":
  51. case "E":
  52. case "F":
  53. case "G":
  54. case "H":
  55. case "I":
  56. case "J":
  57. case "K":
  58. case "L":
  59. case "M":
  60. case "N":
  61. case "O":
  62. case "P":
  63. case "Q":
  64. case "R":
  65. case "S":
  66. case "T":
  67. case "U":
  68. case "V":
  69. case "W":
  70. case "X":
  71. case "Y":
  72. case "Z":
  73. retVal += "^" + path[i];
  74. break;
  75. default:
  76. retVal += path[i];
  77. }
  78. }
  79. return retVal;
  80. },
  81. getLogicalFile: function () {
  82. //var filePath = this.DropZone.Path + "/" +
  83. return "~file::" + this.DropZone.NetAddress + this.lfEncode(this.fullPath);
  84. }
  85. };
  86. retVal[this.idProperty] = id;
  87. return retVal;
  88. },
  89. preProcessRow: function (row) {
  90. var partialPath = this.parent.partialPath + row.name + (row.isDir ? "/" : "");
  91. var fullPath = this.parent.fullPath + row.name + (row.isDir ? "/" : "");
  92. lang.mixin(row, {
  93. calculatedID: this.parent.DropZone.NetAddress + fullPath,
  94. partialPath: partialPath,
  95. fullPath: fullPath,
  96. DropZone: this.parent.DropZone,
  97. displayName: row.name,
  98. type: row.isDir ? "folder" : "file"
  99. });
  100. },
  101. postProcessResults: function (items) {
  102. items.sort(function (l, r) {
  103. if (l.isDir === r.isDir) {
  104. if (l.displayName === r.displayName)
  105. return 0;
  106. else if (l.displayName < r.displayName)
  107. return -1;
  108. return 1;
  109. } else if (l.isDir) {
  110. return -1;
  111. }
  112. return 1;
  113. });
  114. }
  115. });
  116. var LandingZonesStore = declare([ESPRequest.Store], {
  117. service: "FileSpray",
  118. action: "DropZoneFiles",
  119. responseQualifier: "DropZoneFilesResponse.DropZones.DropZone",
  120. idProperty: "calculatedID",
  121. constructor: function (options) {
  122. if (options) {
  123. declare.safeMixin(this, options);
  124. }
  125. },
  126. preProcessRow: function (row) {
  127. lang.mixin(row, {
  128. OS: row.Linux === "true" ? 2 : 0
  129. });
  130. lang.mixin(row, {
  131. calculatedID: row.NetAddress,
  132. displayName: row.Name,
  133. type: "dropzone",
  134. partialPath: "",
  135. fullPath: row.Path + "/",
  136. DropZone: row
  137. });
  138. },
  139. mayHaveChildren: function (item) {
  140. switch (item.type) {
  141. case "dropzone":
  142. case "folder":
  143. return true;
  144. }
  145. return false;
  146. },
  147. getChildren: function (parent, options) {
  148. var store = Observable(new FileListStore({
  149. parent: parent
  150. }));
  151. return store.query({
  152. Netaddr: parent.DropZone.NetAddress,
  153. Path: parent.fullPath,
  154. Mask: "",
  155. OS: parent.DropZone.OS
  156. });
  157. }
  158. });
  159. return {
  160. States: {
  161. 0: "unknown",
  162. 1: "scheduled",
  163. 2: "queued",
  164. 3: "started",
  165. 4: "aborted",
  166. 5: "failed",
  167. 6: "finished",
  168. 7: "monitoring",
  169. 8: "aborting",
  170. 999: "deleted"
  171. },
  172. isComplete: function (state) {
  173. switch (state) {
  174. case 4:
  175. case 5:
  176. case 6:
  177. case 999:
  178. return true;
  179. }
  180. return false;
  181. },
  182. OS_TYPE:
  183. {
  184. OS_WINDOWS: 0,
  185. OS_SOLARIS: 1,
  186. OS_LINUX: 2
  187. },
  188. CommandMessages: {
  189. 1: "Copy",
  190. 2: "Remove",
  191. 3: "Move",
  192. 4: "Rename",
  193. 5: "Replicate",
  194. 6: "Spray (Import)",
  195. 7: "Despray (Export)",
  196. 8: "Add",
  197. 9: "Transfer",
  198. 10: "Save Map",
  199. 11: "Add Group",
  200. 12: "Server",
  201. 13: "Monitor",
  202. 14: "Copy Merge",
  203. 15: "Super Copy"
  204. },
  205. FormatMessages: {
  206. 0: "fixed",
  207. 1: "csv",
  208. 2: "utf8",
  209. 3: "utf8n",
  210. 4: "utf16",
  211. 5: "utf16le",
  212. 6: "utf16be",
  213. 7: "utf32",
  214. 8: "utf32le",
  215. 9: "utf32be",
  216. 10: "variable",
  217. 11: "recfmvb",
  218. 12: "recfmv",
  219. 13: "variablebigendian"
  220. },
  221. CreateLandingZonesStore: function (options) {
  222. var store = new LandingZonesStore(options);
  223. return Observable(store);
  224. },
  225. CreateFileListStore: function (options) {
  226. var store = new FileListStore(options);
  227. return Observable(store);
  228. },
  229. GetDFUWorkunits: function (params) {
  230. return ESPRequest.send("FileSpray", "GetDFUWorkunits", params);
  231. },
  232. DFUWorkunitsAction: function (workunits, actionType, callback) {
  233. var request = {
  234. wuids: workunits,
  235. Type: actionType
  236. };
  237. ESPRequest.flattenArray(request, "wuids", "ID");
  238. return ESPRequest.send("FileSpray", "DFUWorkunitsAction", {
  239. request: request,
  240. load: function (response) {
  241. arrayUtil.forEach(workunits, function (item, index) {
  242. item.refresh();
  243. });
  244. /* TODO: Revisit after HPCC-9241 is fixed
  245. if (lang.exists("DFUWorkunitsActionResponse.ActionResults.WUActionResult", response)) {
  246. arrayUtil.forEach(response.WUActionResponse.ActionResults.WUActionResult, function (item, index) {
  247. if (item.Result.indexOf("Failed:") === 0) {
  248. dojo.publish("hpcc/brToaster", {
  249. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  250. type: "error",
  251. duration: -1
  252. });
  253. } else {
  254. dojo.publish("hpcc/brToaster", {
  255. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  256. type: "message"
  257. });
  258. }
  259. });
  260. }
  261. */
  262. if (callback && callback.load) {
  263. callback.load(response);
  264. }
  265. },
  266. error: function (err) {
  267. if (callback && callback.error) {
  268. callback.error(err);
  269. }
  270. }
  271. });
  272. },
  273. SprayFixed: function (params) {
  274. return ESPRequest.send("FileSpray", "SprayFixed", params);
  275. },
  276. SprayVariable: function (params) {
  277. return ESPRequest.send("FileSpray", "SprayVariable", params);
  278. },
  279. Despray: function (params) {
  280. return ESPRequest.send("FileSpray", "Despray", params);
  281. },
  282. Copy: function (params) {
  283. return ESPRequest.send("FileSpray", "Copy", params);
  284. },
  285. Rename: function (params) {
  286. return ESPRequest.send("FileSpray", "Rename", params);
  287. },
  288. GetDFUWorkunit: function (params) {
  289. return ESPRequest.send("FileSpray", "GetDFUWorkunit", params).then(function(response) {
  290. if (lang.exists("Exceptions.Exception", response)) {
  291. arrayUtil.forEach(response.Exceptions.Exception, function (item, idx) {
  292. if (item.Code === 20080) {
  293. lang.mixin(response, {
  294. GetDFUWorkunitResponse: {
  295. result: {
  296. Wuid: params.request.Wuid,
  297. State: 999,
  298. StateMessage: "deleted"
  299. }
  300. }
  301. });
  302. }
  303. });
  304. }
  305. return response;
  306. });
  307. },
  308. UpdateDFUWorkunit: function (params) {
  309. return ESPRequest.send("FileSpray", "UpdateDFUWorkunit", params);
  310. },
  311. AbortDFUWorkunit: function(params) {
  312. return ESPRequest.send("FileSpray", "AbortDFUWorkunit", params);
  313. },
  314. DFUWUFile: function (params) {
  315. lang.mixin(params, {
  316. handleAs: "text"
  317. });
  318. return ESPRequest.send("FileSpray", "DFUWUFile", params);
  319. },
  320. FileList: function (params) {
  321. return ESPRequest.send("FileSpray", "FileList", params);
  322. },
  323. DropZoneFiles: function (params) {
  324. return ESPRequest.send("FileSpray", "DropZoneFiles", params);
  325. },
  326. DeleteDropZoneFile: function (params) {
  327. // Single File Only
  328. return ESPRequest.send("FileSpray", "DeleteDropZoneFiles", params).then(function (response) {
  329. if (lang.exists("DFUWorkunitsActionResponse.DFUActionResults.DFUActionResult", response)) {
  330. var resultID = response.DFUWorkunitsActionResponse.DFUActionResults.DFUActionResult[0].ID;
  331. var resultMessage = response.DFUWorkunitsActionResponse.DFUActionResults.DFUActionResult[0].Result;
  332. if (resultMessage.indexOf("Success") === 0) {
  333. dojo.publish("hpcc/brToaster", {
  334. Severity: "Message",
  335. Source: "FileSpray.DeleteDropZoneFiles",
  336. Exceptions: [{ Source: "Delete " + resultID, Message: resultMessage }]
  337. });
  338. } else {
  339. dojo.publish("hpcc/brToaster", {
  340. Severity: "Error",
  341. Source: "FileSpray.DeleteDropZoneFiles",
  342. Exceptions: [{ Source: "Delete " + resultID, Message: resultMessage }]
  343. });
  344. }
  345. }
  346. return response;
  347. });
  348. }
  349. };
  350. });