Skip to content
Permalink
Browse files

[Hardening] Reduce db connection idle timeout / Assert the GeoServer …

…resource actually exists and throw an exception accordingly
  • Loading branch information...
afabiani committed Sep 5, 2019
1 parent 1ec49d4 commit 2e0e6e1fa02b3054c1d33b0c9bc1fa3df9d4420a
Showing with 42 additions and 10 deletions.
  1. +10 −6 geonode/geoserver/upload.py
  2. +10 −2 geonode/local_settings.py.geoserver.sample
  3. +22 −2 geonode/settings.py
@@ -169,15 +169,16 @@ def geoserver_upload(
workspace=workspace)
if not gs_resource:
gs_resource = gs_catalog.get_resource(name=name)
if gs_resource is not None:
assert gs_resource.name == name
else:

if not gs_resource:
msg = ('GeoNode encountered problems when creating layer %s.'
'It cannot find the Layer that matches this Workspace.'
'try renaming your files.' % name)
logger.warn(msg)
raise GeoNodeException(msg)

assert gs_resource.name == name

# Step 6. Make sure our data always has a valid projection
# FIXME: Put this in gsconfig.py
logger.info('>>> Step 6. Making sure [%s] has a valid projection' % name)
@@ -201,9 +202,12 @@ def geoserver_upload(
_native_bbox = [-180, -90, 180, 90, "EPSG:4326"]
gs_resource.latlon_bbox = _native_bbox
gs_resource.projection = "EPSG:4326"
cat.save(gs_resource)
logger.debug('BBOX coordinates forced to [-180, -90, 180, 90] for layer '
'[%s].', name)
try:
cat.save(gs_resource)
logger.debug('BBOX coordinates forced to [-180, -90, 180, 90] for layer '
'[%s].', name)
except BaseException as e:
logger.exception('Error occurred while trying to force BBOX on resource', e)

# Step 7. Create the style and assign it to the created resource
# FIXME: Put this in gsconfig.py
@@ -48,7 +48,11 @@ DATABASES = {
'PASSWORD': 'geonode',
'HOST': 'localhost',
'PORT': '5432',
'CONN_TOUT': 900,
'CONN_MAX_AGE': 5,
'CONN_TOUT': 5,
'OPTIONS': {
'connect_timeout': 5,
}
},
# vector datastore for uploads
'datastore': {
@@ -59,7 +63,11 @@ DATABASES = {
'PASSWORD': 'geonode',
'HOST': 'localhost',
'PORT': '5432',
'CONN_TOUT': 900,
'CONN_MAX_AGE': 5,
'CONN_TOUT': 5,
'OPTIONS': {
'connect_timeout': 5,
}
}
}

@@ -99,20 +99,40 @@
# 'ENGINE': 'django.contrib.gis.db.backends.postgis'
# see https://docs.djangoproject.com/en/1.8/ref/contrib/gis/db-api/#module-django.contrib.gis.db.backends for
# detailed list of supported backends and notes.
_db_conf = dj_database_url.parse(DATABASE_URL, conn_max_age=600)
_db_conf = dj_database_url.parse(DATABASE_URL, conn_max_age=5)
if 'spatialite' in DATABASE_URL:
SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so'
DATABASES = {
'default': _db_conf
}
if 'CONN_MAX_AGE' in DATABASES['default']:
DATABASES['default']['CONN_MAX_AGE'] = 5
if 'CONN_TOUT' in DATABASES['default']:
DATABASES['default']['CONN_TOUT'] = 5
if 'OPTIONS' not in DATABASES['default']:
DATABASES['default']['OPTIONS'] = {}
DATABASES['default']['OPTIONS'].update({
'connect_timeout': 5,
})

if os.getenv('DEFAULT_BACKEND_DATASTORE'):
GEODATABASE_URL = os.getenv('GEODATABASE_URL',
'postgis://\
geonode_data:geonode_data@localhost:5432/geonode_data')
DATABASES[os.getenv('DEFAULT_BACKEND_DATASTORE')] = dj_database_url.parse(
GEODATABASE_URL, conn_max_age=600
GEODATABASE_URL, conn_max_age=5
)
_geo_db = DATABASES[os.getenv('DEFAULT_BACKEND_DATASTORE')]
if 'CONN_MAX_AGE' in _geo_db:
_geo_db['CONN_MAX_AGE'] = 5
if 'CONN_TOUT' in DATABASES['default']:
_geo_db['CONN_TOUT'] = 5
if 'OPTIONS' not in DATABASES['default']:
_geo_db['OPTIONS'] = {}
_geo_db['OPTIONS'].update({
'connect_timeout': 5,
})
DATABASES[os.getenv('DEFAULT_BACKEND_DATASTORE')] = _geo_db

# If set to 'True' it will refresh/regenrate all resource links everytime a 'migrate' will be performed
UPDATE_RESOURCE_LINKS_AT_MIGRATE = ast.literal_eval(os.getenv('UPDATE_RESOURCE_LINKS_AT_MIGRATE', 'False'))

0 comments on commit 2e0e6e1

Please sign in to comment.
You can’t perform that action at this time.