Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1 | {% extends "admin/base.html" %} |
| 2 | {% load admin_static %} |
| 3 | |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 4 | {% block content %} |
| 5 | <h1>Welcome <a href="core/user/{{user.id}}">{{user.email}}</a> from Site: <a href="core/site/{{site.id}}">{{site}}</a></h1> |
| 6 | <table class="table table-striped table-bordered table-hover table-condensed"> |
| 7 | <thead><tr> |
| 8 | <th class="sortable">Slices</th><th class="sortable">Privilege</th> |
| 9 | <th class="sortable">Reservations</th> |
| 10 | </tr></thead> |
| 11 | {% for entry in userSliceInfo %} |
| 12 | <tr><td> <a href="core/slice/{{entry.slice.id}}">{{entry.slice.name}}</a><br> |
| 13 | </td><td>{{entry.role}}</td> |
| 14 | {% if entry.reservations %} |
| 15 | <td><a href="core/slice/{{entry.slice.id}}/#reservations"> |
| 16 | {% for resSlot in entry.reservations.1 %} |
| 17 | {{resSlot}} <br> |
| 18 | {% endfor %} |
| 19 | </a></td></tr> |
| 20 | {% else %} |
| 21 | <td></td></tr> |
| 22 | {% endif %} |
| 23 | {% endfor %} |
| 24 | </table> |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 25 | <script type="text/javascript" src="{% static 'log4javascript-1.4.6/log4javascript.js' %}"></script> |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 26 | <div id="HPCDashboard"> |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 27 | <h1>HPC Dashboard</h1> |
| 28 | <span id="hpcSummary"> |
| 29 | <span class="summary-attr"><b>Active Slivers:</b> 78 </span> |
| 30 | <span class="summary-attr"><b>Overall Throughput:</b> 58Gbps</span> |
| 31 | <span class="summary-attr-util"><b>CPU Utilization:</b> 45%</span> |
| 32 | |
| 33 | </span> |
| 34 | <div id="map-us" ></div> |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 35 | </div> |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 36 | <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" /> |
| 37 | <script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script> |
| 38 | |
| 39 | <script src="{% static 'js/Leaflet.MakiMarkers.js' %}" > </script> |
| 40 | |
| 41 | <script> |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 42 | |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 43 | var consoleAppender = new log4javascript.BrowserConsoleAppender(); |
| 44 | var patternLayout = new log4javascript.PatternLayout("%d{HH:mm:ss,SSS} %l{s:l} %-5p - %m{1}%n"); |
| 45 | consoleAppender.setLayout(patternLayout); |
| 46 | |
| 47 | var log = log4javascript.getRootLogger(); |
| 48 | log.addAppender(consoleAppender); |
| 49 | log.setLevel(log4javascript.Level.ALL); |
| 50 | |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 51 | L.Map = L.Map.extend({ |
| 52 | openPopup: function(popup) { |
| 53 | this._popup = popup; |
| 54 | |
| 55 | return this.addLayer(popup).fire('popupopen', { |
| 56 | popup: this._popup |
| 57 | }); |
| 58 | } |
| 59 | }); |
| 60 | |
| 61 | |
| 62 | //Iterate through data and find the max/min coordinates to include all of our points to start |
| 63 | var map = L.map('map-us'); //.setView([0, 0], 1); |
| 64 | |
| 65 | L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', { |
| 66 | maxZoom: 18, |
| 67 | attribution: 'Test' |
| 68 | }).addTo(map); |
| 69 | |
| 70 | var arrayOfLatLngs = []; |
| 71 | var data = {{ cdnData|safe }}; |
| 72 | log.info( data ); |
| 73 | |
| 74 | for ( var key in data ) { |
| 75 | arrayOfLatLngs.push([data[key]['lat'],data[key]['long']]); |
| 76 | log.info( arrayOfLatLngs ); |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 77 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 78 | data[key]['marker'] = L.marker([data[key]['lat'], data[key]['long']], {icon: getIcon(data[key]['numNodes'], data[key]['numHPCSlivers']) }); |
| 79 | data[key]['marker'].addTo(map).bindPopup(setPopupVals(key, data[key])); |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 80 | |
| 81 | } |
| 82 | var bounds = new L.LatLngBounds(arrayOfLatLngs); |
| 83 | map.fitBounds(bounds); |
| 84 | |
| 85 | var popup = L.popup(); |
| 86 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 87 | |
| 88 | function setPopupVals (site, siteData) { |
| 89 | var retVal = '<span class="SiteDetail"><b>' + site + '</b></span>' + |
| 90 | '</br><a href="' + siteData['siteUrl'] + '">' + siteData['siteUrl'] + '</a>' + |
| 91 | '</br><b>Available Nodes: </b>' + siteData['numNodes'] + |
| 92 | '</br><b>Active HPC Slivers: </b>' + siteData['numHPCSlivers'] + |
| 93 | '</br><span id="addSlivers">Add HPC Slivers</span>' + |
| 94 | '<span id="remSlivers">Remove HPC Slivers</span>' ; |
| 95 | |
| 96 | return retVal; |
| 97 | } |
| 98 | function getIcon(numNodes, numHPCSlivers, currentBW) { |
| 99 | var colorChoices = ["#007FFF", "#0000FF", "#7f00ff", "#FF00FF", "#FF007F", "#FF0000"]; |
| 100 | |
| 101 | var ratio = (numHPCSlivers/numNodes) * 100; |
| 102 | var numColors = colorChoices.length; |
| 103 | var colorBands = 100/numColors; |
| 104 | |
| 105 | //Algorithm for color tone should consider the number of available nodes |
| 106 | // on the site, and then how much the current dedicated nodes are impacted |
| 107 | //var iconColor = 0; |
| 108 | var iconColor = 5; |
| 109 | for (colorBand = 0; colorBand < numColors; colorBand ++) { |
| 110 | if (ratio < colorBands * colorBand+1) { |
| 111 | iconColor = colorBand |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | var icon = L.MakiMarkers.icon({icon: "star-stroked", color: colorChoices[iconColor] , size: "s"}); |
| 117 | return icon; |
| 118 | } |
| 119 | |
| 120 | function updateMaps() { |
| 121 | log.info("Attempting to update Maps"); |
| 122 | $.ajax({ |
| 123 | url : '/hpcdashboard', |
| 124 | dataType : 'json', |
| 125 | type : 'GET', |
| 126 | success: function(newData) |
| 127 | { |
| 128 | log.info("Successfully got data back..."); |
| 129 | log.info(newData); |
| 130 | log.info("Still have old data too"); |
| 131 | log.info(data); |
| 132 | updateMapData(newData); |
| 133 | } |
| 134 | }); |
| 135 | setTimeout(updateMaps, 45000) |
| 136 | |
| 137 | } |
| 138 | |
| 139 | function updateMapData(newData) { |
| 140 | for ( site in newData ) { |
| 141 | var isNewSite = false; |
| 142 | //check to see if the site is new or not |
| 143 | if (site in data) { |
| 144 | log.info("Site " + site + " already mapped"); |
| 145 | //take ownership of marker |
| 146 | newData[site]['marker'] = data[site]['marker']; |
| 147 | delete data[site]; |
| 148 | newData[site]['marker'].setIcon(getIcon(newData[site]['numNodes'], newData[site]['numHPCSlivers'])); |
| 149 | // workaround, markers currently don't have a setPopup Content method -- so have to grab object directly |
| 150 | newData[site]['marker']._popup.setContent(setPopupVals(site, newData[site])); |
| 151 | } |
| 152 | else { |
| 153 | isNewSite = true; |
| 154 | log.info("New Site detected: " + site); |
| 155 | newData[site]['marker'] = L.marker([newData[site]['lat'], newData[site]['long']], |
| 156 | {icon: getIcon(newData[site]['numNodes'], newData[site]['numHPCSlivers']) }); |
| 157 | newData[site]['marker'].addTo(map).bindPopup(setPopupVals(site, newData[site])); //.openPopup(); |
| 158 | log.info("Should have added the new site"); |
| 159 | |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // Anything still in data needs to be removed since it is no longer a valid site |
| 164 | for (remSite in data) { |
| 165 | log.warn("Site: " + remSite + " is no longer valid, removing from map"); |
| 166 | map.removeLayer(data[remSite]['marker']); |
| 167 | } |
| 168 | data = newData; |
| 169 | } |
| 170 | |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 171 | function onMapClick(e) { |
| 172 | popup |
| 173 | .setLatLng(e.latlng) |
| 174 | .setContent("You clicked the map at " + e.latlng.toString()) |
| 175 | .openOn(map); |
| 176 | } |
| 177 | |
Siobhan Tully | 06d2c03 | 2014-02-23 23:48:52 -0500 | [diff] [blame] | 178 | setTimeout(updateMaps, 5000) |
| 179 | |
Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 180 | </script> |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 181 | {% endblock %} |