ws_roxieconfig_deploytab.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. var dtDeploy, dsDeploy;
  18. var addEclPanel;
  19. var uploader;
  20. (function() {
  21. var btnDeploySelected = new YAHOO.widget.Button({
  22. label: "Deploy",
  23. id: "deploySelected",
  24. container: "btnDeployments",
  25. onclick: { fn: deployWorkunits }
  26. });
  27. })();
  28. function createDroplist(SelectedNameService, DroplistArray, oRecord, oColumn) {
  29. var d = "<select onChange=\"onEditDroplistChange('" + oColumn.getField() + "', '" + oRecord.getId() + "', this.value)\">";
  30. for (var i = 0; i < DroplistArray.length; i++) {
  31. d += '<option value="' + DroplistArray[i].value + '" ' + (DroplistArray[i].value == SelectedNameService ? 'selected = "1"' : '') + '>' + DroplistArray[i].label + '</option>';
  32. }
  33. d += '</select>';
  34. return d;
  35. }
  36. var formatInlinePassword = function(elCell, oRecord, oColumn, sData) {
  37. elCell.innerHTML = createEntry(sData, oRecord, oColumn, true);
  38. };
  39. function onEditDroplistChange(ColumnName, RecordId, Value) {
  40. var record = dtDeploy.getRecord(RecordId);
  41. record.setData(ColumnName, Value);
  42. dtDeploy.render();
  43. }
  44. var formatMaskedLabel = function(elCell, oRecord, oColumn, sData) {
  45. elCell.innerHTML = sData.replace(/./g, '*');
  46. };
  47. var formatProcessAction = function(elCell, oRecord, oColumn, sData) {
  48. if (sData == "1") {
  49. elCell.innerHTML = '<img src="/esp/files/yui/build/assets/skins/sam/loading.gif" />';
  50. }
  51. if (sData == "2") {
  52. elCell.innerHTML = '<img src="/esp/files/yui/build/assets/skins/sam/menuitem_checkbox.png" />';
  53. }
  54. };
  55. function checkNotifyRoxieCheck() {
  56. if (document.getElementById('deploySavePending') && !document.getElementById('checkNotifyRoxie5')) {
  57. var d = document.createElement("span");
  58. var notifyChecked = '';
  59. if (notifyRoxie) {
  60. notifyChecked = ' checked="true"';
  61. }
  62. d.innerHTML = '<input type="checkbox" name="checkNotifyRoxie5" id="checkNotifyRoxie5" ' + notifyChecked + ' onclick="setNotifyRoxie(this.checked);">Notify Roxie?</input>';
  63. document.getElementById('btnDeployments').appendChild(d);
  64. }
  65. }
  66. var WorkunitCellClickedHandler = function(oArgs) {
  67. var record = dtDeploy.getRecord(oArgs.target);
  68. var column = dtDeploy.getColumn(oArgs.target);
  69. if (column && column.field == 'Mark') {
  70. var isChecked = record.getData(column.field) == '1' ? true : false;
  71. record.setData(column.field, isChecked ? '0' : '1');
  72. record.setData('Activation', '1');
  73. dtDeploy.render();
  74. return;
  75. }
  76. dtDeploy.onEventShowCellEditor(oArgs);
  77. }
  78. var ar_Activate = new Array({ label: "Don't Activate", value: "0" }, { label: "Activate", value: "1" }, { label: "Suspend Previous", value: "2" }, { label: "Delete Previous", value: "3" });
  79. var formatActivate = function(elCell, oRecord, oColumn, sData) {
  80. var iActivate = 1;
  81. if (sData && sData.length > 0) { // not setting
  82. iActivate = parseInt(sData);
  83. }
  84. if (oRecord.getData('Mark') == '1') {
  85. elCell.innerHTML = createDroplist(iActivate, ar_Activate, oRecord, oColumn);
  86. } else {
  87. elCell.innerHTML = '';
  88. }
  89. };
  90. function onEditDroplistChange(ColumnName, RecordId, Value) {
  91. var record = dtDeploy.getRecord(RecordId);
  92. record.setData(ColumnName, Value);
  93. dtDeploy.render();
  94. }
  95. function createDroplist(SelectedNameService, DroplistArray, oRecord, oColumn) {
  96. var d = "<select onChange=\"onEditDroplistChange('" + oColumn.getField() + "', '" + oRecord.getId() + "', this.value)\">";
  97. for (var i = 0; i < DroplistArray.length; i++) {
  98. d += '<option value="' + DroplistArray[i].value + '" ' + (DroplistArray[i].value == SelectedNameService ? 'selected = "1"' : '') + '>' + DroplistArray[i].label + '</option>';
  99. }
  100. d += '</select>';
  101. return d;
  102. }
  103. function loadPendingDeployments(ElementId, Resize) {
  104. if (Resize) {
  105. createDeploymentDataTable(ElementId);
  106. return;
  107. }
  108. var connectionCallback = {
  109. success: function(o) {
  110. var xmlDoc = o.responseXML;
  111. dsDeploy = new YAHOO.util.DataSource(xmlDoc);
  112. dsDeploy.responseType = YAHOO.util.DataSource.TYPE_XML;
  113. dsDeploy.responseSchema = {
  114. resultNode: "RoxieECLWorkunitInfo",
  115. fields: ["Wuid", "Owner", "Cluster", "Jobname", "StateID", "State", "Protected", "IsPausing"]
  116. };
  117. createDeploymentDataTable(ElementId);
  118. checkNotifyRoxieCheck();
  119. },
  120. failure: function(o) {
  121. alert('Failure:' + o.statusText);
  122. }
  123. };
  124. clearDeploymentDataTable();
  125. createDeploymentDataTable(ElementId);
  126. dtDeploy.showTableMessage(dtDeploy.get("MSG_LOADING"), dtDeploy.CLASS_LOADING);
  127. var postBody = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns="http://webservices.seisint.com/ws_roxieconfig"><soap:Body><RoxieWUQueryRequest><Cluster></Cluster><TargetClusterType>roxie</TargetClusterType><Owner/><Jobname/></RoxieWUQueryRequest></soap:Body></soap:Envelope>';
  128. YAHOO.util.Connect.initHeader("SOAPAction", "/ws_roxieconfig/RoxieWUQuery?ver_=" + WS_ROXIECONFIG_VER);
  129. YAHOO.util.Connect.initHeader("Content-Type", "text/xml");
  130. YAHOO.util.Connect._use_default_post_header = false;
  131. var getXML = YAHOO.util.Connect.asyncRequest("POST",
  132. "/ws_roxieconfig/RoxieWUQuery",
  133. connectionCallback, postBody);
  134. return {
  135. };
  136. }
  137. function clearDeploymentDataTable() {
  138. if (dtDeploy) {
  139. dtDeploy.destroy();
  140. dtDeploy = null;
  141. dsDeploy = null;
  142. }
  143. dsDeploy = new YAHOO.util.DataSource();
  144. }
  145. function createDeploymentDataTable(ElementId) {
  146. var myColumnDefs = [{ key: "Mark", label: "", formatter: formatInlineEditCheckbox, width: 40 },
  147. { key: "Wuid", lable: "Workunit", sortable: true, resizeable: false, width: 300 },
  148. { key: "Owner", label: "Owner", sortable: true, resizeable: false, width: 180 },
  149. { key: "Jobname", label: "Jobname", editor: new YAHOO.widget.TextboxCellEditor({disableBtns:true}), sortable: true, resizeable: false, width: 120 },
  150. { key: "State", label: "State", sortable: true, resizeable: false, width: 150 },
  151. { key: "Activation", label: "Activation", formatter: formatActivate, sortable: true, resizeable: false, width: 150 },
  152. { key: "Action", label: "Action", formatter: formatProcessAction, sortable: true, resizeable: false, width: 150 },
  153. { key: "Protected", label: "Protected", formatter: formatCheckboxDisabled, sortable: true, resizeable: false, width: 100}];
  154. //dtDeploy = new YAHOO.widget.ScrollingDataTable(ElementId, myColumnDefs, dsDeploy, { width: "100%", height: "100%" });
  155. dtDeploy = new YAHOO.widget.ScrollingDataTable(ElementId, myColumnDefs, dsDeploy, { width: "100%" });
  156. var highlightEditableCell = function(oArgs) {
  157. var elCell = oArgs.target;
  158. if (YAHOO.util.Dom.hasClass(elCell, "yui-dt-editable")) {
  159. dtDeploy.highlightCell(elCell);
  160. }
  161. };
  162. dtDeploy.subscribe("cellMouseoverEvent", highlightEditableCell);
  163. dtDeploy.subscribe("cellMouseoutEvent", dtDeploy.onEventUnhighlightCell);
  164. dtDeploy.subscribe("cellClickEvent", WorkunitCellClickedHandler);
  165. }
  166. function deployWorkunits() {
  167. var records = dtDeploy.getRecordSet().getRecords();
  168. for (var i = 0; i < records.length; i++) {
  169. var mark = records[i].getData('Mark');
  170. var wuid = records[i].getData('Wuid');
  171. var jobName = records[i].getData('Jobname');
  172. var activate = records[i].getData('Activation');
  173. if (mark == '1') {
  174. // set ui to show 'deploying' and turn off when the ajax call completes.
  175. records[i].setData('Action', '1');
  176. deployWorkunit(wuid, jobName, activate);
  177. }
  178. }
  179. dtDeploy.render();
  180. }
  181. function deployWorkunit(Workunit, JobName, Activate) {
  182. var connectionCallback = {
  183. success: function(o) {
  184. var xmlDoc = o.responseXML;
  185. // find workunit in dtDeploy and set to deployed Action = '2'.
  186. var records = dtDeploy.getRecordSet().getRecords();
  187. for (var i = 0; i < records.length; i++) {
  188. var wuid = records[i].getData('Wuid');
  189. if (wuid == Workunit) {
  190. // set ui to show 'deploying' and turn off when the ajax call completes.
  191. records[i].setData('Mark', '');
  192. records[i].setData('Action', '2');
  193. }
  194. }
  195. dtDeploy.render();
  196. },
  197. failure: function(o) {
  198. alert('Failure:' + o.statusText);
  199. }
  200. };
  201. var postBody = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns="http://webservices.seisint.com/ws_roxieconfig"><soap:Body><RoxieDeployWorkunit><Wuid>' + Workunit + '</Wuid><QueryName>' + JobName + '</QueryName><Options><Activate>' + Activate + '</Activate><NotifyRoxie>' + notifyRoxie + '</NotifyRoxie></Options></RoxieDeployWorkunit></soap:Body></soap:Envelope>';
  202. YAHOO.util.Connect.initHeader("SOAPAction", "/ws_roxieconfig/DeployWorkunit?ver_=" + WS_ROXIECONFIG_VER);
  203. YAHOO.util.Connect.initHeader("Content-Type", "text/xml");
  204. YAHOO.util.Connect._use_default_post_header = false;
  205. var getXML = YAHOO.util.Connect.asyncRequest("POST",
  206. "/ws_roxieconfig/DeployWorkunit",
  207. connectionCallback, postBody);
  208. return {};
  209. }
  210. var statusPanel;
  211. function showDeployStatus(RecId) {
  212. var recordSet = dtDeploy.getRecordSet();
  213. var record = recordSet.getRecord(RecId);
  214. if (!record) {
  215. recordSet = dt_Action.getRecordSet();
  216. record = recordSet.getRecord(RecId);
  217. }
  218. var handleOk = function() {
  219. statusPanel.hide();
  220. statusPanel = null;
  221. };
  222. if (!statusPanel) {
  223. statusPanel = new YAHOO.widget.SimpleDialog("showDeploymentStatus",
  224. { width: "500px",
  225. fixedcenter: true,
  226. visible: true,
  227. close: true,
  228. effect: {
  229. effect: YAHOO.widget.ContainerEffect.FADE,
  230. duration: 0.25
  231. },
  232. icon: YAHOO.widget.SimpleDialog.ICON_INFO,
  233. constraintoviewport: true,
  234. buttons: [{ text: "Ok", handler: handleOk, isDefault: true}]
  235. });
  236. }
  237. statusPanel.setHeader(record.getData('OriginalName') + ' Status');
  238. statusPanel.setBody('<div style="text-align:left; height:200px; overflow:scroll;">' + record.getData('Status').replace(/\n/gi, '<br />') + '</div>');
  239. statusPanel.render("statusdiv");
  240. statusPanel.show()
  241. }