浏览代码

Merge pull request #5487 from GordonSmith/HPCC-10724

HPCC-10724 Implement disk space usage for a scope/owner

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

+ 111 - 0
esp/files/scripts/DiskUsageWidget.js

@@ -0,0 +1,111 @@
+/*##############################################################################
+#    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+############################################################################## */
+define([
+    "dojo/_base/declare",
+    "dojo/_base/lang",
+    "dojo/i18n",
+    "dojo/i18n!./nls/hpcc",
+    "dojo/on",
+
+    "dgrid/OnDemandGrid",
+    "dgrid/Keyboard",
+    "dgrid/Selection",
+    "dgrid/selector",
+    "dgrid/extensions/ColumnResizer",
+    "dgrid/extensions/DijitRegistry",
+
+    "hpcc/WsDfu",
+    "hpcc/ESPUtil",
+    "hpcc/FilterDropDownWidget",
+
+    "dojo/text!../templates/DiskUsageWidget.html"
+], function (declare, lang, i18n, nlsHPCC, on,
+                OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
+                WsDfu, ESPUtil, FilterDropDownWidget,
+                template) {
+    return declare("DiskUsageWidget", [_Widget, ESPUtil.FormHelper], {
+        templateString: template,
+        baseClass: "DiskUsageWidget",
+        i18n: nlsHPCC,
+
+        resize: function (args) {
+            this.inherited(arguments);
+            this.widget.BorderContainer.resize();
+        },
+
+        getTitle: function () {
+            return this.i18n.title_DiskUsage;
+        },
+
+        //  Hitched actions  ---
+        _onRefresh: function (event) {
+            this.refreshGrid();
+        },
+
+        //  Implementation  ---
+        init: function (params) {
+            if (this.inherited(arguments))
+                return;
+
+            this.initDiskUsageGrid();
+
+            this.widget.Filter.refreshState();
+            var context = this;
+            this.widget.Filter.on("clear", function (evt) {
+                context.refreshGrid();
+            });
+            this.widget.Filter.on("apply", function (evt) {
+                context.refreshGrid();
+            });
+        },
+
+        initDiskUsageGrid: function () {
+            var store = new WsDfu.CreateDiskUsageStore();
+            this.diskUsageGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
+                allowSelectAll: true,
+                deselectOnRefresh: false,
+                store: store,
+                query: this.getFilter(),
+                columns: {
+                    Name: { label: this.i18n.Grouping, width: 90, sortable: true },
+                    NumOfFiles: { label: this.i18n.FileCounts, width: 90, sortable: true },
+                    TotalSize: { label: this.i18n.TotalSize, width: 90, sortable: true },
+                    LargestFile: { label: this.i18n.LargestFile, sortable: true },
+                    LargestSize: { label: this.i18n.LargestSize, width: 90, sortable: true },
+                    SmallestFile: { label: this.i18n.SmallestFile, sortable: true },
+                    SmallestSize: { label: this.i18n.SmallestSize, width: 90, sortable: true },
+                    NumOfFilesUnknown: { label: this.i18n.FilesWithUnknownSize, width: 90, sortable: true }
+                }
+            }, this.id + "DiskUsageGrid");
+        },
+
+        getFilter: function () {
+            var retVal = this.widget.Filter.toObject();
+            lang.mixin(retVal, {
+                StartDate: this.getISOString("FromDate", "FromTime"),
+                EndDate: this.getISOString("ToDate", "ToTime")
+            });
+            return retVal;
+        },
+
+        refreshGrid: function (clearSelection) {
+            this.diskUsageGrid.set("query", this.getFilter());
+            if (clearSelection) {
+                this.diskUsageGrid.clearSelection();
+            }
+        }
+    });
+});

+ 2 - 1
esp/files/scripts/HPCCPlatformOpsWidget.js

@@ -22,6 +22,7 @@ define([
     "dijit/registry",
     "dijit/registry",
 
 
     "hpcc/_TabContainerWidget",
     "hpcc/_TabContainerWidget",
+    "hpcc/DiskUsageWidget",
     "hpcc/ESPRequest",
     "hpcc/ESPRequest",
 
 
     "dojo/text!../templates/HPCCPlatformOpsWidget.html",
     "dojo/text!../templates/HPCCPlatformOpsWidget.html",
@@ -33,7 +34,7 @@ define([
 
 
 ], function (declare, lang, i18n, nlsHPCC,
 ], function (declare, lang, i18n, nlsHPCC,
                 registry,
                 registry,
-                _TabContainerWidget, ESPRequest,
+                _TabContainerWidget, DiskUsageWidget, ESPRequest,
                 template) {
                 template) {
     return declare("HPCCPlatformOpsWidget", [_TabContainerWidget], {
     return declare("HPCCPlatformOpsWidget", [_TabContainerWidget], {
         templateString: template,
         templateString: template,

+ 39 - 5
esp/files/scripts/HPCCPlatformWidget.js

@@ -31,6 +31,7 @@ define([
     "hpcc/ESPActivity",
     "hpcc/ESPActivity",
     "hpcc/ws_account",
     "hpcc/ws_account",
     "hpcc/ws_access",
     "hpcc/ws_access",
+    "hpcc/WsDfu",
     "hpcc/WsSMC",
     "hpcc/WsSMC",
     "hpcc/GraphWidget",
     "hpcc/GraphWidget",
 
 
@@ -58,7 +59,7 @@ define([
 ], function (declare, lang, i18n, nlsHPCC, arrayUtil, dom, domStyle,
 ], function (declare, lang, i18n, nlsHPCC, arrayUtil, dom, domStyle,
                 registry, Tooltip,
                 registry, Tooltip,
                 UpgradeBar,
                 UpgradeBar,
-                _TabContainerWidget, ESPActivity, WsAccount, WsAccess, WsSMC, GraphWidget,
+                _TabContainerWidget, ESPActivity, WsAccount, WsAccess, WsDfu, WsSMC, GraphWidget,
                 template) {
                 template) {
     return declare("HPCCPlatformWidget", [_TabContainerWidget], {
     return declare("HPCCPlatformWidget", [_TabContainerWidget], {
         templateString: template,
         templateString: template,
@@ -122,17 +123,50 @@ define([
             }
             }
         },
         },
 
 
+        refreshUserName: function () {
+            var userDisplay = this.userName ? this.userName : "";
+
+            var total = 0;
+            var myTotal = 0;
+            arrayUtil.forEach(this.spaceUsage, function (item, idx) {
+                var itemTotal = item.TotalSize.split(",").join("");
+                total += parseInt(itemTotal);
+                if (item.Name === this.userName) {
+                    myTotal = parseInt(itemTotal);
+                }
+            }, this);
+            this.userUsage = (myTotal / total) * 100;
+
+            if (this.userUsage) {
+                userDisplay += " (" + (Math.round(this.userUsage * 100) / 100) + "%)"
+            }
+            dom.byId(this.id + "UserID").innerHTML = userDisplay;
+        },
+
         init: function (params) {
         init: function (params) {
             if (this.inherited(arguments))
             if (this.inherited(arguments))
                 return;
                 return;
-            var context = this;
-            registry.byId(context.id + "SetBanner").set("disabled", true);
 
 
+            registry.byId(this.id + "SetBanner").set("disabled", true);
+
+            var context = this;
             WsAccount.MyAccount({
             WsAccount.MyAccount({
             }).then(function (response) {
             }).then(function (response) {
                 if (lang.exists("MyAccountResponse.username", response)) {
                 if (lang.exists("MyAccountResponse.username", response)) {
-                    dom.byId(context.id + "UserID").innerHTML = response.MyAccountResponse.username;
-                    context.checkIfAdmin(response.MyAccountResponse.username);
+                    context.userName = response.MyAccountResponse.username;
+                    context.checkIfAdmin(context.username);
+                    context.refreshUserName();
+                }
+            });
+
+            WsDfu.DFUSpace({
+                request: {
+                    CountBy: "Owner"
+                }
+            }).then(function (response) {
+                if (lang.exists("DFUSpaceResponse.DFUSpaceItems.DFUSpaceItem", response)) {
+                    context.spaceUsage = response.DFUSpaceResponse.DFUSpaceItems.DFUSpaceItem;
+                    context.refreshUserName();
                 }
                 }
             });
             });
 
 

+ 71 - 2
esp/files/scripts/WsDfu.js

@@ -19,17 +19,80 @@ define([
     "dojo/_base/lang",
     "dojo/_base/lang",
     "dojo/_base/Deferred",
     "dojo/_base/Deferred",
     "dojo/_base/array",
     "dojo/_base/array",
+    "dojo/store/Memory",
+    "dojo/store/Observable",
     "dojo/store/util/QueryResults",
     "dojo/store/util/QueryResults",
 
 
     "dojox/xml/parser",
     "dojox/xml/parser",
 
 
     "hpcc/ESPBase",
     "hpcc/ESPBase",
     "hpcc/ESPRequest"
     "hpcc/ESPRequest"
-], function (declare, lang, Deferred, arrayUtil, QueryResults,
+], function (declare, lang, Deferred, arrayUtil, Memory, Observable, QueryResults,
     parser,
     parser,
     ESPBase, ESPRequest) {
     ESPBase, ESPRequest) {
 
 
-    return {
+    var DiskUsageStore = declare([Memory], {
+
+        constructor: function () {
+            this.idProperty = "__hpcc_id";
+        },
+
+        query: function (query, options) {
+            switch (query.CountBy) {
+                case "Year":
+                case "Quarter":
+                case "Month":
+                case "Day":
+                    query.Interval = query.CountBy;
+                    query.CountBy = "Date";
+                    break;
+            }
+            var results = self.DFUSpace({
+                request: query
+            }).then(lang.hitch(this, function (response) {
+                var data = [];
+                if (lang.exists("DFUSpaceResponse.DFUSpaceItems.DFUSpaceItem", response)) {
+                    arrayUtil.forEach(response.DFUSpaceResponse.DFUSpaceItems.DFUSpaceItem, function (item, idx) {
+                        data.push(lang.mixin(item, {
+                            __hpcc_id: item.Name
+                        }));
+                    }, this);
+                }
+                if (options.sort && options.sort.length) {
+                    data.sort(function (_l, _r) {
+                        var l = _l[options.sort[0].attribute];
+                        var r = _r[options.sort[0].attribute];
+                        if (l === r) {
+                            return 0;
+                        }
+                        switch (options.sort[0].attribute) {
+                            case "TotalSize":
+                            case "LargestSize":
+                            case "SmallestSize":
+                            case "NumOfFiles":
+                            case "NumOfFilesUnknown":
+                                l = parseInt(l.split(",").join(""));
+                                r = parseInt(r.split(",").join(""));
+                        }
+                        if (options.sort[0].descending) {
+                            return r < l ? -1 : 1;
+                        }
+                        return l < r ? -1 : 1;
+                    })
+                }
+                this.setData(data);
+                return this.data;
+            }));
+            return QueryResults(results);
+        }
+    });
+
+    var self = {
+        CreateDiskUsageStore: function() {
+            var store = new DiskUsageStore();
+            return Observable(store);
+        },
+
         DFUArrayAction: function (logicalFiles, actionType, callback) {
         DFUArrayAction: function (logicalFiles, actionType, callback) {
             arrayUtil.forEach(logicalFiles, function (item, idx) {
             arrayUtil.forEach(logicalFiles, function (item, idx) {
                 item.qualifiedName = item.Name + "@" + item.ClusterName;
                 item.qualifiedName = item.Name + "@" + item.ClusterName;
@@ -130,6 +193,10 @@ define([
             return ESPRequest.send("WsDfu", "DFUQuery", params);
             return ESPRequest.send("WsDfu", "DFUQuery", params);
         },
         },
 
 
+        DFUSpace: function (params) {
+            return ESPRequest.send("WsDfu", "DFUSpace", params);
+        },
+
         DFUInfo: function (params) {
         DFUInfo: function (params) {
             return ESPRequest.send("WsDfu", "DFUInfo", params);
             return ESPRequest.send("WsDfu", "DFUInfo", params);
         },
         },
@@ -152,5 +219,7 @@ define([
             });
             });
         }
         }
     };
     };
+
+    return self;
 });
 });
 
 

+ 15 - 0
esp/files/scripts/nls/hpcc.js

@@ -54,6 +54,7 @@ define({root:
     Dali: "Dali",
     Dali: "Dali",
     dataset: ":=dataset*",
     dataset: ":=dataset*",
     Date: "Date",
     Date: "Date",
+    Day: "Day",
     Deactivate: "Deactivate",
     Deactivate: "Deactivate",
     DEF: "DEF",
     DEF: "DEF",
     Delete: "Delete",
     Delete: "Delete",
@@ -76,6 +77,7 @@ define({root:
     Despray: "Despray",
     Despray: "Despray",
     DFUServerName: "DFU Server Name",
     DFUServerName: "DFU Server Name",
     Directory: "Directory",
     Directory: "Directory",
+    DiskUsage: "Disk Usage",
     Distance: "Distance",
     Distance: "Distance",
     Dll: "Dll",
     Dll: "Dll",
     DOT: "DOT",
     DOT: "DOT",
@@ -109,12 +111,14 @@ define({root:
     FetchingData: "Fetching Data...",
     FetchingData: "Fetching Data...",
     fetchingresults: "fetching results",
     fetchingresults: "fetching results",
     File: "File",
     File: "File",
+    FileCounts: "File Counts",
     FileName: "File Name",
     FileName: "File Name",
     FileParts: "File Parts",
     FileParts: "File Parts",
     FilePath: "File Path",
     FilePath: "File Path",
     Files: "Files",
     Files: "Files",
     FileSize: "File Size",
     FileSize: "File Size",
     FilesNoPackage: "Files without matching package definitions",
     FilesNoPackage: "Files without matching package definitions",
+    FilesWithUnknownSize: "Files With Unknown Size",
     FileType: "File Type",
     FileType: "File Type",
     FileUploader: "File Uploader",
     FileUploader: "File Uploader",
     Filter: "Filter",
     Filter: "Filter",
@@ -130,6 +134,8 @@ define({root:
     Graphs: "Graphs",
     Graphs: "Graphs",
     GraphView: "Graph View",
     GraphView: "Graph View",
     Group: "Group",
     Group: "Group",
+    GroupBy: "Group By",
+    Grouping: "Grouping",
     GroupDetails: "Group Details",
     GroupDetails: "Group Details",
     GroupName: "Group Name",
     GroupName: "Group Name",
     GroupPermissions: "Group Permissions",
     GroupPermissions: "Group Permissions",
@@ -158,6 +164,8 @@ define({root:
     LandingZone: "Landing Zone",
     LandingZone: "Landing Zone",
     LandingZones: "Landing Zones",
     LandingZones: "Landing Zones",
     Largest: "Largest",
     Largest: "Largest",
+    LargestFile: "Largest File",
+    LargestSize: "Largest Size",
     LastName: "Last Name",
     LastName: "Last Name",
     LastNDays: "Last N Days",
     LastNDays: "Last N Days",
     LegacyForm: "Legacy Form",
     LegacyForm: "Legacy Form",
@@ -192,6 +200,7 @@ define({root:
     MonitorEventName: "Monitor Event Name",
     MonitorEventName: "Monitor Event Name",
     MonitorShotLimit: "Monitor Shot Limit",
     MonitorShotLimit: "Monitor Shot Limit",
     MonitorSub: "Monitor Sub",
     MonitorSub: "Monitor Sub",
+    Month: "Month",
     MustContainUppercaseAndSymbol: "Must contain uppercase and symbol",
     MustContainUppercaseAndSymbol: "Must contain uppercase and symbol",
     NA: "N/A",
     NA: "N/A",
     Name: "Name",
     Name: "Name",
@@ -259,6 +268,7 @@ define({root:
     Publish: "Publish",
     Publish: "Publish",
     PublishedBy: "Published By",
     PublishedBy: "Published By",
     PublishedQueries: "Published Queries",
     PublishedQueries: "Published Queries",
+    Quarter: "Quarter",
     Queries: "Queries",
     Queries: "Queries",
     QueriesNoPackage: "Queries without matching package",
     QueriesNoPackage: "Queries without matching package",
     QueryDetailsfor: "Query Details for",
     QueryDetailsfor: "Query Details for",
@@ -311,6 +321,8 @@ define({root:
     Skew: "Skew",
     Skew: "Skew",
     Slaves: "Slaves",
     Slaves: "Slaves",
     Smallest: "Smallest",
     Smallest: "Smallest",
+    SmallestFile: "Smallest File",
+    SmallestSize: "Smallest Size",
     SOAP: "SOAP",
     SOAP: "SOAP",
     SomeDescription: "Some*Description",
     SomeDescription: "Some*Description",
     somefile: "*::somefile*",
     somefile: "*::somefile*",
@@ -354,6 +366,7 @@ define({root:
     title_Activity: "Activity",
     title_Activity: "Activity",
     title_DFUQuery: "Logical Files",
     title_DFUQuery: "Logical Files",
     title_DFUWUDetails: "DFU Workunit",
     title_DFUWUDetails: "DFU Workunit",
+    title_DiskUsage: "Disk Usage",
     title_ECLPlayground: "ECL Playground",
     title_ECLPlayground: "ECL Playground",
     title_EventScheduleWorkunit: "Event Scheduler",
     title_EventScheduleWorkunit: "Event Scheduler",
     title_GetDFUWorkunits: "DFU Workunits",
     title_GetDFUWorkunits: "DFU Workunits",
@@ -388,6 +401,7 @@ define({root:
     ToDate: "To Date",
     ToDate: "To Date",
     Toenablegraphviews: "To enable graph views, please install the Graph View Control plugin",
     Toenablegraphviews: "To enable graph views, please install the Graph View Control plugin",
     ToSizes: "To Sizes",
     ToSizes: "To Sizes",
+    TotalSize: "Total Size",
     TotalThorTime: "Total Thor Time",
     TotalThorTime: "Total Thor Time",
     Type: "Type",
     Type: "Type",
     undefined: "undefined",
     undefined: "undefined",
@@ -433,6 +447,7 @@ define({root:
     XLS: "XLS",
     XLS: "XLS",
     XML: "XML",
     XML: "XML",
     XRef: "XRef",
     XRef: "XRef",
+    Year: "Year",
     ZAP: "Z.A.P",
     ZAP: "Z.A.P",
     ZeroLogicalFilesCheckFilter: "Zero Logical Files(check filter)",
     ZeroLogicalFilesCheckFilter: "Zero Logical Files(check filter)",
     Zip: "Zip",
     Zip: "Zip",

+ 30 - 0
esp/files/templates/DiskUsageWidget.html

@@ -0,0 +1,30 @@
+<div class="${baseClass}">
+    <div id="${id}BorderContainer" class="${baseClass}BorderContainer" style="width: 100%; height: 100%;" data-dojo-type="dijit.layout.BorderContainer">
+        <div id="${id}Toolbar" class="topPanel" data-dojo-props="region: 'top'" data-dojo-type="dijit.Toolbar">
+            <div id="${id}Refresh" data-dojo-attach-event="onClick:_onRefresh" data-dojo-props="iconClass:'iconRefresh'" data-dojo-type="dijit.form.Button">${i18n.Refresh}</div>
+            <span data-dojo-type="dijit.ToolbarSeparator"></span>
+            <div id="${id}Filter" data-dojo-type="FilterDropDownWidget">
+                <select id="${id}GroupBy" title="${i18n.GroupBy}:" name="CountBy" colspan="2" data-dojo-type="dijit/form/Select">
+                    <option selected="selected" value="Owner">${i18n.Owner}</option>
+                    <option value="Scope">${i18n.Scope}</option>
+                    <option value="Year">${i18n.Year}</option>
+                    <option value="Quarter">${i18n.Quarter}</option>
+                    <option value="Month">${i18n.Month}</option>
+                    <option value="Day">${i18n.Day}</option>
+                </select>
+                <input id="${id}ScopeUnder" title="${i18n.Scope}:" name="ScopeUnder" colspan="2" style="width:100%" data-dojo-type="dijit.form.TextBox" />
+                <input id="${id}OwnerUnder" title="${i18n.Owner}:" name="OwnerUnder" colspan="2" style="width:100%" data-dojo-type="dijit.form.TextBox" />
+                <input id="${id}FromDate" title="${i18n.FromDate}:" name="StartDate" data-dojo-props="trim: true, placeHolder:'7/28/2013'" data-dojo-type="dijit.form.DateTextBox" />
+                <input id="${id}FromTime" name="FromTime" data-dojo-props="trim: true, placeHolder:'7:30 AM'" data-dojo-type="dijit.form.TimeTextBox" />
+                <input id="${id}ToDate" title="${i18n.ToDate}:" name="EndDate" data-dojo-props="trim: true, placeHolder:'7/28/2013'" data-dojo-type="dijit.form.DateTextBox" />
+                <input id="${id}ToTime" name="ToTime" data-dojo-props="trim: true, placeHolder:'7:30 PM'" data-dojo-type="dijit.form.TimeTextBox" />
+            </div>
+            <span data-dojo-type="dijit.ToolbarSeparator"></span>
+            <div id="${id}NewPage" class="right" data-dojo-attach-event="onClick:_onNewPage" data-dojo-props="iconClass:'iconNewPage', showLabel:false" data-dojo-type="dijit.form.Button">${i18n.OpenInNewPage}</div>
+        </div>
+        <div id="${id}DiskUsageGridCP" style="border:0px; padding: 0px; border-color:none" data-dojo-props="region: 'center'" data-dojo-type="dijit.layout.ContentPane">
+            <div id="${id}DiskUsageGrid">
+            </div>
+        </div>
+    </div>
+</div>

+ 2 - 0
esp/files/templates/HPCCPlatformOpsWidget.html

@@ -4,6 +4,8 @@
             <div id="${id}StackController" style="width: 100%" data-dojo-props="containerId:'${id}TabContainer'" data-dojo-type="dijit.layout.StackController"></div>
             <div id="${id}StackController" style="width: 100%" data-dojo-props="containerId:'${id}TabContainer'" data-dojo-type="dijit.layout.StackController"></div>
         </div>
         </div>
         <div id="${id}TabContainer" data-dojo-props="region: 'center', tabPosition: 'top'" style="width: 100%; height: 100%" data-dojo-type="dijit.layout.StackContainer">
         <div id="${id}TabContainer" data-dojo-props="region: 'center', tabPosition: 'top'" style="width: 100%; height: 100%" data-dojo-type="dijit.layout.StackContainer">
+            <div id="${id}_DiskUsage" title="${i18n.DiskUsage}" style="padding: 0px; border:0px; border-color:none; overflow: hidden" data-dojo-type="DiskUsageWidget">
+            </div>
             <div id="${id}_TargetClusters" title="${i18n.TargetClusters}" style="padding: 0px; border:0px; border-color:none; overflow: hidden" data-dojo-type="dijit.layout.ContentPane">
             <div id="${id}_TargetClusters" title="${i18n.TargetClusters}" style="padding: 0px; border:0px; border-color:none; overflow: hidden" data-dojo-type="dijit.layout.ContentPane">
             </div>
             </div>
             <div id="${id}_ClusterProcesses" title="${i18n.ClusterProcesses}" style="padding: 0px; border:0px; border-color:none; overflow: hidden" data-dojo-type="dijit.layout.ContentPane">
             <div id="${id}_ClusterProcesses" title="${i18n.ClusterProcesses}" style="padding: 0px; border:0px; border-color:none; overflow: hidden" data-dojo-type="dijit.layout.ContentPane">