svn commit: r1676190 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/jetapp/ webapp/WEB-INF/ webapp/jetapp/charts/ webapp/jetapp/scripts/

[email protected]
Newsgroups gmane.comp.jakarta.jetspeed.devel
Message-ID <[email protected]>
Author: taylor
Date: Mon Apr 27 03:12:15 2015
New Revision: 1676190

URL: http://svn.apache.org/r1676190
Log:
JS2-1320: hooking in backend data to chart portlets

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java Mon Apr 27 03:12:15 2015
@@ -24,12 +24,12 @@ public class JetAppChartPortlet extends
             { "/jetapp/scripts/directives.js", "j2admin_directives"},
             { "/jetapp/scripts/filters.js", "j2admin_filters"},
             { "/jetapp/charts/scripts/d3.min.js", "chart_d3"},
-            { "/jetapp/charts/scripts/nv.d3.min.js", "chart_nvd3js"},
-            { "/jetapp/charts/scripts/data.js", "chart_data"},
+            { "/jetapp/charts/scripts/nv.d3.min.js", "chart_nvd3js"}
+//            { "/jetapp/charts/scripts/data.js", "chart_data"},
 //            { "/jetapp/charts/scripts/app-memory.js", "chart_memory"},
-            { "/jetapp/charts/scripts/app-caches.js", "chart_caches"},
-            { "/jetapp/charts/scripts/app-pages.js", "chart_pages"},
-            { "/jetapp/charts/scripts/app-users.js", "chart_users"}
+//            { "/jetapp/charts/scripts/app-caches.js", "chart_caches"},
+//            { "/jetapp/charts/scripts/app-pages.js", "chart_pages"},
+//            { "/jetapp/charts/scripts/app-users.js", "chart_users"}
     };
 
     @Override
@@ -53,3 +53,4 @@ public class JetAppChartPortlet extends
     }
 
 }
+

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java Mon Apr 27 03:12:15 2015
@@ -70,8 +70,9 @@ public class JetAppPortletFilter impleme
 
     protected boolean alreadyContributedAngular(RenderRequest renderRequest) {
         HttpServletRequest request = JetAppPortlet.getServletRequest(renderRequest);
-        if (request == null)
-        return false;
+        if (request == null) {
+            return false;
+        }
         Boolean contributed = (Boolean) request.getAttribute(JET_DASHBOARD_ANGULAR_FLAG);
         if (contributed == null || contributed == false) {
             request.setAttribute(JET_DASHBOARD_ANGULAR_FLAG, Boolean.TRUE);

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml Mon Apr 27 03:12:15 2015
@@ -2765,7 +2765,7 @@
     <portlet-name>MemoryUsageChart</portlet-name>
     <display-name>JVM Memory Usage</display-name>
     <portlet-class>org.apache.jetspeed.jetapp.JetAppChartPortlet</portlet-class>
-    <expiration-cache>-1</expiration-cache>
+    <expiration-cache>0</expiration-cache>
     <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>
@@ -2794,7 +2794,7 @@
     <portlet-name>PageUsageChart</portlet-name>
     <display-name>Page Usage Chart</display-name>
     <portlet-class>org.apache.jetspeed.jetapp.JetAppChartPortlet</portlet-class>
-    <expiration-cache>-1</expiration-cache>
+    <expiration-cache>0</expiration-cache>
     <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>
@@ -2823,7 +2823,7 @@
     <portlet-name>UserLoginsChart</portlet-name>
     <display-name>User Logins Chart</display-name>
     <portlet-class>org.apache.jetspeed.jetapp.JetAppChartPortlet</portlet-class>
-    <expiration-cache>-1</expiration-cache>
+    <expiration-cache>0</expiration-cache>
     <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>
@@ -2852,7 +2852,7 @@
     <portlet-name>CacheUsageChart</portlet-name>
     <display-name>Cache Usage Chart</display-name>
     <portlet-class>org.apache.jetspeed.jetapp.JetAppChartPortlet</portlet-class>
-    <expiration-cache>-1</expiration-cache>
+    <expiration-cache>0</expiration-cache>
     <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html Mon Apr 27 03:12:15 2015
@@ -1 +1,4 @@
+<div ng-controller="CachesController" ng-init="init()">
     <svg class="caches-container" height="225"></svg>
+</div>
+

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html Mon Apr 27 03:12:15 2015
@@ -1,15 +1,3 @@
 <div ng-controller="MemoryController" ng-init="init()">
-    <!-- <div class="legend">
-        <select id="root-list" ng-options="root.name for root in roots track by root.id" ng-model="currentRoot_" ng-disabled="!roots.length">
-        </select>
-        <br /><br />
-        <a href="#" id="add-cg-root" class="add-root pull-right" ng-click="addRoot('CUSTOM_GROUP')">CG+</a>
-        <br /><br /><br />
-        <a href="#" id="add-hg-root" class="add-root pull-right" ng-click="addRoot('HOSTGROUP')">HG+</a>
-        <br /><br /><br />
-        <a href="#" id="add-sg-root" class="add-root pull-right" ng-click="addRoot('SERVICE_GROUP')">SG+</a>
-    </div>
-
-    <div id="canvas-container"></div> -->
     <svg class="memory-container" height="225"></svg>
 </div>
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html Mon Apr 27 03:12:15 2015
@@ -1,3 +1,3 @@
-
+<div ng-controller="PagesController" ng-init="init()">
     <svg class="pages-container" height="225"></svg>
-
+</div>

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html Mon Apr 27 03:12:15 2015
@@ -1 +1,3 @@
-    <svg class="users-container" height="225"></svg>
+<div ng-controller="UsersController" ng-init="init()">
+  <svg class="users-container" height="225"></svg>
+</div>
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js Mon Apr 27 03:12:15 2015
@@ -13,7 +13,7 @@ var StatisticsRestService = function ($h
         statistics: [],
 
         /**
-         * Get JVM runtime info via query. The query is specified as an object with the
+         * Get JVM runtime memory info via query. The query is specified as an object with the
          * following fields;
          *
          * 'id' : matches profile id
@@ -24,7 +24,103 @@ var StatisticsRestService = function ($h
         memoryUsage: function () {
             var deferred = $q.defer();
             var self = this;
-            var url = ServerService.api('/statistics/runtime');
+            var url = ServerService.api('/statistics/memory');
+            var config = ServerService.apiConfig();
+            config.params = {
+                "type": "json"
+            };
+            $http.get(url, config)
+                .success(function success(data, status, headers, config) {
+                    deferred.resolve(data, status);
+                })
+                .error(function error(data, status) {
+                    if (status == 404) {
+                        deferred.resolve(data, status);
+                    }
+                    else {
+                        deferred.reject(data, status);
+                    }
+                });
+            return deferred.promise;
+        },
+
+        /**
+         * Get JVM runtime top pages usage info via query. The query is specified as an object with the
+         * following fields;
+         *
+         * 'id' : matches profile id
+         * 'title' : contains within title
+         * 'concreteClass' : contains within class name
+         *
+         */
+        pageHits: function () {
+            var deferred = $q.defer();
+            var self = this;
+            var url = ServerService.api('/statistics/pages');
+            var config = ServerService.apiConfig();
+            config.params = {
+                "type": "json"
+            };
+            $http.get(url, config)
+                .success(function success(data, status, headers, config) {
+                    deferred.resolve(data, status);
+                })
+                .error(function error(data, status) {
+                    if (status == 404) {
+                        deferred.resolve(data, status);
+                    }
+                    else {
+                        deferred.reject(data, status);
+                    }
+                });
+            return deferred.promise;
+        },
+
+        /**
+         * Get JVM runtime top user sessions usage info via query. The query is specified as an object with the
+         * following fields;
+         *
+         * 'id' : matches profile id
+         * 'title' : contains within title
+         * 'concreteClass' : contains within class name
+         *
+         */
+        sessions: function () {
+            var deferred = $q.defer();
+            var self = this;
+            var url = ServerService.api('/statistics/users');
+            var config = ServerService.apiConfig();
+            config.params = {
+                "type": "json"
+            };
+            $http.get(url, config)
+                .success(function success(data, status, headers, config) {
+                    deferred.resolve(data, status);
+                })
+                .error(function error(data, status) {
+                    if (status == 404) {
+                        deferred.resolve(data, status);
+                    }
+                    else {
+                        deferred.reject(data, status);
+                    }
+                });
+            return deferred.promise;
+        },
+
+        /**
+         * Get JVM runtime top caches usage info via query. The query is specified as an object with the
+         * following fields;
+         *
+         * 'id' : matches profile id
+         * 'title' : contains within title
+         * 'concreteClass' : contains within class name
+         *
+         */
+        cacheStats: function () {
+            var deferred = $q.defer();
+            var self = this;
+            var url = ServerService.api('/statistics/caches');
             var config = ServerService.apiConfig();
             config.params = {
                 "type": "json"
@@ -44,5 +140,7 @@ var StatisticsRestService = function ($h
             return deferred.promise;
         }
     }
+
     return service;
+
 }
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js?rev=1676190&r1=1676189&r2=1676190&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js Mon Apr 27 03:12:15 2015
@@ -3,6 +3,7 @@
  */
 'use strict';
 
+/* Utility functions */
 function bytesToSize(bytes)
 {
     var precision = 1,
@@ -43,13 +44,16 @@ function bytesToSize(bytes)
 
 /* Controllers: */
 angular.module('j2admin.chartControllers', [])
+
+    // -- Memory Usage Controller
     .controller('MemoryController', function ($scope, $q, StatisticsService, PortletService) {
         $scope.memoryUsage = [];
 
-        // ---- init function
+        // -- init function
         $scope.init = function () {
 
- /*           $scope.readResourceURL = readResourceURL;
+            /* -- Possible future add of preferences handling. Should be included for each .controller
+            $scope.readResourceURL = readResourceURL;
             PortletService.lookupPreferences(readResourceURL).then(
                 function success(prefs, status) {
                     $scope.prefs = prefs;
@@ -109,14 +113,180 @@ angular.module('j2admin.chartControllers
                             .attr("text-anchor", "middle");
 
                         return chart;
-                    });
+                    })
+                },
+                function error(msg, status) {
+                    console.log(msg);
+                    $scope.addFailureAlert(msg, status);
+                }
+            )
+        }
+    }
+)
+
+    //-- Page Usage Controller
+    .controller('PagesController', function ($scope, $q, StatisticsService, PortletService) {
+        $scope.pageHits = [];
+
+        // ---- init function
+        $scope.init = function () {
+
+            // -- retrieve runtime page usage
+            StatisticsService.pageHits().then(
+                function success(pages, status) {
+                    $scope.pageHits = pages;
+
+                    // Process page data:
+                    var datum = [{key: "Page Hits", values: []}];
+
+//                    console.log('>>>>>>> pageHits: ' +JSON.stringify($scope.pageHits));
+
+                    for (var label in $scope.pageHits.pages) {
+                        datum[0].values.push({label: label, value: $scope.pageHits.pages[label]})
+                        }
+
+                    nv.addGraph(function () {
+                        var chart = nv.models.discreteBarChart()
+                            .x(function (d) {
+                                return d.label
+                            })    //Specify the data accessors.
+                            .y(function (d) {
+                                return d.value
+                            })
+                            .tooltips(false)        //Don't show tooltips
+                            .showValues(true)       //...instead, show the bar value right on top of each bar.
+                            .duration(500);
+
+                        chart.yAxis.tickFormat(function (d) {
+                            return d3.format('g')(d);
+                        });
+                        chart.xAxis.tickPadding(10);
+                        chart.valueFormat(d3.format('g'));
+
+                        d3.select(".pages-container")
+                            .datum(datum)
+                            .call(chart);
+
+                        nv.utils.windowResize(chart.update);
+
+                        return chart;
+                    })
+                },
+                function error(msg, status) {
+                    console.log(msg);
+                    $scope.addFailureAlert(msg, status);
+                }
+            )
+        }
+    }
+)
+
+    //-- User Sessions Usage Controller
+    .controller('UsersController', function ($scope, $q, StatisticsService, PortletService) {
+        $scope.sessions = [];
+
+        // -- init function
+        $scope.init = function () {
+
+            // -- retrieve top user logins
+            StatisticsService.sessions().then(
+                function success(users, status) {
+                    $scope.sessions = users;
+
+                    // Process user data:
+                    var datum = [{key: "User Sessions", values: []}];
+
+//                    console.log('>>>>>>> sessions: ' +JSON.stringify($scope.sessions));
 
+                    for(var label in $scope.sessions.users) {
+                        datum[0].values.push({label: label, value: $scope.sessions.users[label]});
+                    }
+
+                    nv.addGraph(function() {
+                        var chart = nv.models.discreteBarChart()
+                            .x(function(d) { return d.label })    //Specify the data accessors.
+                            .y(function(d) { return d.value })
+                            .tooltips(false)        //Don't show tooltips
+                            .showValues(true)       //...instead, show the bar value right on top of each bar.
+                            .duration(500);
+
+                        chart.yAxis.tickFormat(function(d) { return d3.format('g')(d); });
+                        chart.xAxis.tickPadding(10);
+                        chart.valueFormat(d3.format('g'));
+
+                        d3.select(".users-container")
+                            .datum(datum)
+                            .call(chart);
+
+                        nv.utils.windowResize(chart.update);
+
+                        return chart;
+                    })
+                },
+                function error(msg, status) {
+                    console.log(msg);
+                    $scope.addFailureAlert(msg, status);
+                }
+            )
+        }
+    }
+)
+
+    //-- Top Caches Usage Controller
+    .controller('CachesController', function ($scope, $q, StatisticsService, PortletService) {
+        $scope.cacheStats = [];
+
+        // -- init function
+        $scope.init = function () {
+
+            // -- retrieve runtime page usage
+            StatisticsService.cacheStats().then(
+                function success(caches, status) {
+                    $scope.cacheStats = caches;
+
+                    // Process cache data:
+                    var datum = [{key: "Hits", values: []}, {key: "Misses", values: []}, {key: "Evictions", values: []}];
+
+//                    console.log('>>>>>>> cacheStats: ' +JSON.stringify($scope.cacheStats));
+
+                    for (var cache in $scope.cacheStats.caches) {
+                        datum[0].values.push({x: cache, y: $scope.cacheStats.caches[cache].hits});
+                        datum[1].values.push({x: cache, y: $scope.cacheStats.caches[cache].misses});
+                        datum[2].values.push({x: cache, y: $scope.cacheStats.caches[cache].evictions});
+                    }
+
+                    nv.addGraph(function () {
+                        var chart = nv.models.multiBarChart()
+                            .x(function (d) {
+                                return d.x
+                            })    //Specify the data accessors.
+                            .y(function (d) {
+                                return d.y
+                            })
+                            .tooltips(true)        //Don't show tooltips
+//                            .showValues(true)      // ...instead, show the bar value right on top of each bar.
+                            .duration(500);
+
+                        chart.yAxis.tickFormat(function (d) {
+                            return d3.format('g')(d);
+                        });
+                        chart.xAxis.tickPadding(10);
+//                        chart.valueFormat(d3.format('g'));
+
+                        d3.select(".caches-container")
+                            .datum(datum)
+                            .call(chart);
+
+                        nv.utils.windowResize(chart.update);
+
+                        return chart;
+                    })
                 },
                 function error(msg, status) {
                     console.log(msg);
                     $scope.addFailureAlert(msg, status);
                 }
-            );
+            )
         }
     }
-);
+)
\ No newline at end of file
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.