Skip to content

Commit

Permalink
[Fixes #4855] Download links always return whole world bbox
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Sep 10, 2019
1 parent fc8c26f commit 7b4b3fb
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 164 deletions.
22 changes: 8 additions & 14 deletions geonode/geoserver/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,6 @@ def geoserver_post_save(instance, sender, created, **kwargs):
if getattr(settings, 'DELAYED_SECURITY_SIGNALS', False):
instance.set_dirty_state()

if instance.storeType != 'remoteStore' and created:
logger.info("... Creating Default Resource Links for Layer [%s]" % (instance.alternate))
try:
set_resource_default_links(instance, sender, prune=True)
except BaseException:
from django.db import connection
connection._rollback()
logger.warn("Failure Creating Default Resource Links for Layer [%s]" % (instance.alternate))
logger.info("... Creating Thumbnail for Layer [%s]" % (instance.alternate))
try:
create_gs_thumbnail(instance, overwrite=True, check_bbox=True)
except BaseException:
logger.warn("Failure Creating Thumbnail for Layer [%s]" % (instance.alternate))


@on_ogc_backend(BACKEND_PACKAGE)
def geoserver_post_save_local(instance, *args, **kwargs):
Expand Down Expand Up @@ -376,6 +362,14 @@ def geoserver_post_save_local(instance, *args, **kwargs):
# some thumbnail generators will update thumbnail_url. If so, don't
# immediately re-generate the thumbnail here. use layer#save(update_fields=['thumbnail_url'])
if gs_resource:
logger.info("... Creating Default Resource Links for Layer [%s]" % (instance.alternate))
try:
set_resource_default_links(instance, instance, prune=True)
except BaseException:
from django.db import connection
connection._rollback()
logger.warn("Failure Creating Default Resource Links for Layer [%s]" % (instance.alternate))

if 'update_fields' in kwargs and kwargs['update_fields'] is not None and \
'thumbnail_url' in kwargs['update_fields']:
logger.info("... Creating Thumbnail for Layer [%s]" % (instance.alternate))
Expand Down
3 changes: 1 addition & 2 deletions geonode/monitoring/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,7 @@ def process_requests_batch(self, service, requests, valid_from, valid_to):
"""
Processes requests information into metric values
"""
log.info("Processing batch of %s requests from %s to %s",
requests.count(), valid_from, valid_to)
log.debug("Processing batch of %s requests from %s to %s", requests.count(), valid_from, valid_to)
if not requests.count():
return
event_all = EventType.objects.get(name=EventType.EVENT_ALL)
Expand Down
7 changes: 4 additions & 3 deletions geonode/monitoring/management/commands/collect_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ def run_check(self, service, collector, since=None, until=None, force_check=None
until = local_tz.localize(until).astimezone(utc).replace(tzinfo=utc)

last_check = local_tz.localize(since).astimezone(utc).replace(tzinfo=utc) if since else service.last_check
if not last_check or last_check > until or (until - last_check) > settings.MONITORING_DATA_TTL:
last_check = (until - settings.MONITORING_DATA_TTL)
_monitoring_ttl_max = 365 if force_check else settings.MONITORING_DATA_TTL
if not last_check or last_check > until or (until - last_check) > _monitoring_ttl_max:
last_check = (until - _monitoring_ttl_max)
service.last_check = last_check

print('[',now ,'] checking', service.name, 'since', last_check, 'until', until)
# print('[',now ,'] checking', service.name, 'since', last_check, 'until', until)
data_in = None
h = Handler(service, force_check=force_check)
data_in = h.collect(since=last_check, until=until, format=format)
Expand Down
70 changes: 41 additions & 29 deletions geonode/monitoring/tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
import logging
import os.path
import xmljson
import dj_database_url

from decimal import Decimal # noqa
from importlib import import_module
from defusedxml import lxml as dlxml

from django.core import mail
from django.conf import settings
from django.db import connections
from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from django.core.management import call_command
Expand All @@ -57,6 +60,7 @@
from geonode.layers.models import Layer
from geonode.people.models import Profile
from geonode.documents.models import Document
from geonode.monitoring.models import * # noqa

from geonode.tests.utils import Client
from geonode.geoserver.helpers import ogc_server_settings
Expand All @@ -73,6 +77,20 @@
GEOSERVER_URL = ogc_server_settings.LOCATION
GEOSERVER_USER, GEOSERVER_PASSWD = ogc_server_settings.credentials

DB_HOST = settings.DATABASES['default']['HOST']
DB_PORT = settings.DATABASES['default']['PORT']
DB_NAME = settings.DATABASES['default']['NAME']
DB_USER = settings.DATABASES['default']['USER']
DB_PASSWORD = settings.DATABASES['default']['PASSWORD']
DATASTORE_URL = 'postgis://{}:{}@{}:{}/{}'.format(
DB_USER,
DB_PASSWORD,
DB_HOST,
DB_PORT,
DB_NAME
)
postgis_db = dj_database_url.parse(DATASTORE_URL, conn_max_age=5)

logging.getLogger('south').setLevel(logging.WARNING)
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -165,8 +183,6 @@ def tearDownClass(cls):
os.unlink('integration_settings.py')

def setUp(self):
# super(MonitoringTestBase, self).setUp()

# await startup
cl = Client(
GEONODE_URL, GEONODE_USER, GEONODE_PASSWD
Expand All @@ -185,30 +201,18 @@ def setUp(self):

self.client = TestClient(REMOTE_ADDR='127.0.0.1')

settings.DATABASES['default']['NAME'] = DB_NAME

connections['default'].settings_dict['ATOMIC_REQUESTS'] = False
connections['default'].connect()

self._tempfiles = []
# createlayer must use postgis as a datastore
# set temporary settings to use a postgis datastore
# DB_HOST = DATABASES['default']['HOST']
# DB_PORT = DATABASES['default']['PORT']
# DB_NAME = DATABASES['default']['NAME']
# DB_USER = DATABASES['default']['USER']
# DB_PASSWORD = DATABASES['default']['PASSWORD']
# settings.DATASTORE_URL = 'postgis://{}:{}@{}:{}/{}'.format(
# DB_USER,
# DB_PASSWORD,
# DB_HOST,
# DB_PORT,
# DB_NAME
# )
# postgis_db = dj_database_url.parse(
# settings.DATASTORE_URL, conn_max_age=600)
# settings.DATABASES['datastore'] = postgis_db
# settings.OGC_SERVER['default']['DATASTORE'] = 'datastore'

# upload(gisdata.DATA_DIR, console=None)

def _post_teardown(self):
pass

def tearDown(self):
# super(MonitoringTestBase, self).setUp()
connections.databases['default']['ATOMIC_REQUESTS'] = False

map(os.unlink, self._tempfiles)

Expand All @@ -217,6 +221,14 @@ def tearDown(self):
Map.objects.all().delete()
Document.objects.all().delete()

MetricValue.objects.all().delete()
ExceptionEvent.objects.all().delete()
RequestEvent.objects.all().delete()
MonitoredResource.objects.all().delete()
NotificationCheck.objects.all().delete()
Service.objects.all().delete()
Host.objects.all().delete()

from django.conf import settings
if settings.OGC_SERVER['default'].get(
"GEOFENCE_SECURITY_ENABLED", False):
Expand Down Expand Up @@ -2146,8 +2158,8 @@ def test_hostgeoserver_cpu_endpoints(self):
self.assertEqual(data["axis_label"], "%")
self.assertEqual(data["type"], "rate")
d = data["data"][0]["data"]
self.assertEqual(d[0]["samples_count"], 3)
self.assertEqual(d[0]["val"], "20.3421000000000000")
self.assertEqual(d[0]["samples_count"], 2)
self.assertEqual(d[0]["val"], "17.6955000000000000")
self.assertEqual(d[0]["min"], "14.3935")
self.assertEqual(d[0]["max"], "25.6353")
self.assertEqual(d[0]["sum"], "61.0263")
Expand Down Expand Up @@ -2183,8 +2195,8 @@ def test_hostgeonode_mem_endpoints(self):
self.assertEqual(data["axis_label"], "%")
self.assertEqual(data["type"], "rate")
d = data["data"][0]["data"]
self.assertEqual(d[0]["samples_count"], 3)
self.assertEqual(d[0]["val"], "83.3176000000000000")
self.assertEqual(d[0]["samples_count"], 2)
self.assertEqual(d[0]["val"], "87.4178000000000000")
self.assertEqual(d[0]["min"], "75.1172")
self.assertEqual(d[0]["max"], "88.7119")
self.assertEqual(d[0]["sum"], "249.9528")
Expand Down Expand Up @@ -2218,8 +2230,8 @@ def test_hostgeoserver_mem_endpoints(self):
self.assertEqual(data["axis_label"], "%")
self.assertEqual(data["type"], "rate")
d = data["data"][0]["data"]
self.assertEqual(d[0]["samples_count"], 3)
self.assertEqual(d[0]["val"], "89.8485666666666667")
self.assertEqual(d[0]["samples_count"], 2)
self.assertEqual(d[0]["val"], "94.2085500000000000")
self.assertEqual(d[0]["min"], "81.1286")
self.assertEqual(d[0]["max"], "95.5952")
self.assertEqual(d[0]["sum"], "269.5457")
Expand Down
2 changes: 1 addition & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@
MONITORING_SERVICE_NAME = os.getenv("MONITORING_SERVICE_NAME", 'local-geonode')

# how long monitoring data should be stored
MONITORING_DATA_TTL = timedelta(days=int(os.getenv("MONITORING_DATA_TTL", 365)))
MONITORING_DATA_TTL = timedelta(days=int(os.getenv("MONITORING_DATA_TTL", 7)))

# this will disable csrf check for notification config views,
# use with caution - for dev purpose only
Expand Down
Loading

0 comments on commit 7b4b3fb

Please sign in to comment.