diff --git a/data/model/legacy.py b/data/model/legacy.py index f2c1b9e61..11c603ede 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -1098,13 +1098,32 @@ def set_image_metadata(docker_image_id, namespace_name, repository_name, def get_repository_images(namespace_name, repository_name): - return (Image - .select(Image, ImageStorage) - .join(Repository) - .switch(Image) + location_list = list((ImageStoragePlacement + .select(ImageStoragePlacement, Image, ImageStorage, ImageStorageLocation) + .join(ImageStorageLocation) + .switch(ImageStoragePlacement) .join(ImageStorage, JOIN_LEFT_OUTER) + .join(Image) + .join(Repository) .where(Repository.name == repository_name, - Repository.namespace == namespace_name)) + Repository.namespace == namespace_name))) + + images = {} + for location in location_list: + # Make sure we're always retrieving the same image object. + image = location.storage.image + image_id = image.docker_image_id + + if not image_id in images: + images[image_id] = image + image.storage.locations = set() + else: + image = images[image_id] + + # Add the location to the image's locations set. + image.storage.locations.add(location) + + return images.values() def list_repository_tags(namespace_name, repository_name): diff --git a/endpoints/api/image.py b/endpoints/api/image.py index 48b471c38..6eab4837d 100644 --- a/endpoints/api/image.py +++ b/endpoints/api/image.py @@ -23,6 +23,7 @@ def image_view(image): 'ancestors': image.ancestors, 'dbid': image.id, 'size': extended_props.image_size, + 'locations': [l.location.name for l in image.storage.locations] } diff --git a/endpoints/api/repository.py b/endpoints/api/repository.py index 13d32a3fc..215caa1b5 100644 --- a/endpoints/api/repository.py +++ b/endpoints/api/repository.py @@ -151,7 +151,7 @@ def image_view(image): 'command': json.loads(command) if command else None, 'ancestors': image.ancestors, 'dbid': image.id, - 'size': extended_props.image_size, + 'size': extended_props.image_size } @resource('/v1/repository/') diff --git a/static/css/quay.css b/static/css/quay.css index 68e317c70..cc33d877b 100644 --- a/static/css/quay.css +++ b/static/css/quay.css @@ -3790,4 +3790,64 @@ pre.command:before { .form-change input { margin-top: 12px; margin-bottom: 12px; -} \ No newline at end of file +} + +.location-view { + display: inline-block; + margin-rigth: 6px; +} + +.location-view .flag { + position: relative; + transition: opacity 0.5s ease; +} + +.location-view .ping-tower { + display: inline-block; + vertical-align: middle; +} + +.location-view .ping-sliver { + margin: 1px; + width: 14px; + height: 3px; + border: 1px solid #D5D5D5; + transition: 0.5s ease; +} + +.location-view .ping-tower.good .ping-sliver { + background: green; + border: 1px solid green; +} + +.location-view .ping-tower.fair .ping-sliver { + background: orange; + border: 1px solid orange; +} + +.location-view .ping-tower.fair .ping-sliver:first-child { + border: 1px solid #D5D5D5; + background: transparent; +} + +.location-view .ping-tower.barely .ping-sliver { + background: rgb(255, 61, 0); + border: 1px solid rgb(255, 61, 0); +} + +.location-view .ping-tower.barely .ping-sliver:first-child { + border: 1px solid #D5D5D5; + background: transparent; +} + +.location-view .ping-tower.barely .ping-sliver:nth-child(2) { + border: 1px solid #D5D5D5; + background: transparent; +} + +.location-view .ping-tower.poor .ping-sliver:last-child { + border: 1px solid red; + background: red; +} + + diff --git a/static/directives/location-view.html b/static/directives/location-view.html new file mode 100644 index 000000000..ace3dad53 --- /dev/null +++ b/static/directives/location-view.html @@ -0,0 +1,12 @@ + + + + + + +
+
+
+
+
+
diff --git a/static/img/flags/AU.png b/static/img/flags/AU.png new file mode 100644 index 000000000..5135f7c29 Binary files /dev/null and b/static/img/flags/AU.png differ diff --git a/static/img/flags/BR.png b/static/img/flags/BR.png new file mode 100644 index 000000000..79ecfcb2a Binary files /dev/null and b/static/img/flags/BR.png differ diff --git a/static/img/flags/EU.png b/static/img/flags/EU.png new file mode 100644 index 000000000..f2936a0cc Binary files /dev/null and b/static/img/flags/EU.png differ diff --git a/static/img/flags/IE.png b/static/img/flags/IE.png new file mode 100644 index 000000000..197bc80e1 Binary files /dev/null and b/static/img/flags/IE.png differ diff --git a/static/img/flags/JP.png b/static/img/flags/JP.png new file mode 100644 index 000000000..69cca05ee Binary files /dev/null and b/static/img/flags/JP.png differ diff --git a/static/img/flags/LICENSE.txt b/static/img/flags/LICENSE.txt new file mode 100644 index 000000000..21f84a5bb --- /dev/null +++ b/static/img/flags/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (c) 2013 Go Squared Ltd. http://www.gosquared.com/ + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/static/img/flags/SG.png b/static/img/flags/SG.png new file mode 100644 index 000000000..9f6779748 Binary files /dev/null and b/static/img/flags/SG.png differ diff --git a/static/img/flags/US.png b/static/img/flags/US.png new file mode 100644 index 000000000..44b3c28f4 Binary files /dev/null and b/static/img/flags/US.png differ diff --git a/static/img/flags/unknown.png b/static/img/flags/unknown.png new file mode 100644 index 000000000..e2ef37c29 Binary files /dev/null and b/static/img/flags/unknown.png differ diff --git a/static/js/app.js b/static/js/app.js index 397729c3b..f27d31ff4 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -4604,6 +4604,140 @@ quayApp.directive('dockerfileBuildForm', function () { }); +quayApp.directive('locationView', function () { + var directiveDefinitionObject = { + priority: 0, + templateUrl: '/static/directives/location-view.html', + replace: false, + transclude: true, + restrict: 'C', + scope: { + 'location': '=location' + }, + controller: function($rootScope, $scope, $element, $http) { + var LOCATIONS = { + 'local_us': { 'country': 'US', 'data': 'quay-registry.s3.amazonaws.com', 'title': 'United States' }, + 'local_eu': { 'country': 'EU', 'data': 'quay-registry-eu.s3-eu-west-1.amazonaws.com', 'title': 'Europe' }, + + 's3_us_east_1': { 'country': 'US', 'data': 'quay-registry.s3.amazonaws.com', 'title': 'United States' }, + 's3_eu_west_1': { 'country': 'EU', 'data': 'quay-registry-eu.s3-eu-west-1.amazonaws.com', 'title': 'Europe' }, + + 's3_ap_southeast_1': { 'country': 'SG', 'data': 'quay-registry-singapore.s3-ap-southeast-1.amazonaws.com', 'title': 'Singapore' }, + 's3_ap_southeast_2': { 'country': 'AU', 'data': 'quay-registry-sydney.s3-ap-southeast-2.amazonaws.com', 'title': 'Australia' }, + +// 's3_ap_northeast-1': { 'country': 'JP', 'data': 's3-ap-northeast-1.amazonaws.com', 'title': 'Japan' }, +// 's3_sa_east1': { 'country': 'BR', 'data': 's3-east-1.amazonaws.com', 'title': 'Sao Paulo' } + }; + + $scope.locationPing = null; + $scope.locationPingClass = null; + + $scope.getLocationTooltip = function(location, ping) { + var tip = $scope.getLocationTitle(location) + '
'; + if (ping < 0) { + tip += '
Note: Could not contact server'; + } else { + tip += 'Estimated Ping: ' + (ping ? ping + 'ms' : '(Loading)'); + } + return tip; + }; + + $scope.getLocationTitle = function(location) { + if (!LOCATIONS[location]) { + return '(Unknown)'; + } + return 'Image data is located in ' + LOCATIONS[location]['title']; + }; + + $scope.getLocationImage = function(location) { + if (!LOCATIONS[location]) { + return 'unknown.png'; + } + return LOCATIONS[location]['country'] + '.png'; + }; + + $scope.getLocationPing = function(location) { + if (!$rootScope.__CACHED_LOCATION_PINGS) { + $rootScope.__CACHED_LOCATION_PINGS = {}; + } + + if ($rootScope.__CACHED_LOCATION_PINGS[location]) { + $scope.locationPing = $rootScope.__CACHED_LOCATION_PINGS[location]; + return; + } + + var conductPing = function() { + var path = 'http://' + LOCATIONS[location]['data'] + '/okay.txt?cb=' + (Math.random() * 100); + var start = new Date(); + var xhr = new XMLHttpRequest(); + xhr.onerror = function() { + $scope.$apply(function() { + $scope.locationPing = -1; + }); + }; + xhr.onreadystatechange = function () { + if (xhr.readyState === xhr.HEADERS_RECEIVED) { + if (xhr.status != 200) { + $scope.$apply(function() { + $scope.locationPing = -1; + }); + return; + } + + var ping = (new Date() - start); + $scope.$apply(function() { + $rootScope.__CACHED_LOCATION_PINGS[location] = $scope.locationPing = ping; + }); + } + }; + + xhr.open("GET", path); + xhr.send(null); + return; + }; + + setTimeout(conductPing, 1000); + }; + + $scope.$watch('location', function(location) { + if (!location) { return; } + $scope.getLocationPing(location); + }); + + $scope.$watch('locationPing', function(locationPing) { + if (locationPing == null) { + $scope.locationPingClass = null; + return; + } + + if (locationPing < 0) { + $scope.locationPingClass = 'error'; + return; + } + + if (locationPing < 100) { + $scope.locationPingClass = 'good'; + return; + } + + if (locationPing < 250) { + $scope.locationPingClass = 'fair'; + return; + } + + if (locationPing < 500) { + $scope.locationPingClass = 'barely'; + return; + } + + $scope.locationPingClass = 'poor'; + }); + } + }; + return directiveDefinitionObject; +}); + + quayApp.directive('tagSpecificImagesView', function () { var directiveDefinitionObject = { priority: 0, diff --git a/static/partials/view-repo.html b/static/partials/view-repo.html index eedeece40..915bc52ec 100644 --- a/static/partials/view-repo.html +++ b/static/partials/view-repo.html @@ -261,6 +261,14 @@ {{ currentImage.size | bytes }} + + +
+ +