Skip to content

Commit

Permalink
add wait to create_coveragestore to fix issue GeoNode#20
Browse files Browse the repository at this point in the history
  • Loading branch information
seesteins committed Jun 22, 2024
1 parent d56461a commit e28cde3
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions src/geoserver/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#
#########################################################################

import base64
import base64
import logging
import os
import re
import os
import re
from datetime import datetime, timedelta
from time import sleep
from xml.etree.ElementTree import XML
Expand All @@ -24,13 +27,30 @@
from six import string_types
from urllib3 import Retry

from time import sleep
from xml.etree.ElementTree import XML
from xml.parsers.expat import ExpatError

import requests
from requests.adapters import HTTPAdapter
from requests.exceptions import HTTPError
from six import string_types
from urllib3 import Retry

from geoserver.layer import Layer
from geoserver.layergroup import LayerGroup, UnsavedLayerGroup
from geoserver.layergroup import LayerGroup, UnsavedLayerGroup
from geoserver.resource import FeatureType
from geoserver.security import user_from_index
from geoserver.service import service_from_index
from geoserver.settings import GlobalSettings
from geoserver.security import user_from_index
from geoserver.service import service_from_index
from geoserver.settings import GlobalSettings
from geoserver.store import (
UnsavedCoverageStore,
UnsavedDataStore,
UnsavedWmsStore,
UnsavedCoverageStore,
UnsavedDataStore,
UnsavedWmsStore,
Expand All @@ -41,6 +61,8 @@
from geoserver.style import Style
from geoserver.support import build_url, prepare_upload_bundle
from geoserver.workspace import Workspace, workspace_from_index
from geoserver.support import build_url, prepare_upload_bundle
from geoserver.workspace import Workspace, workspace_from_index

try:
from past.builtins import basestring
Expand All @@ -49,11 +71,14 @@

try:
from urllib.parse import parse_qsl, urlencode, urlparse
from urllib.parse import parse_qsl, urlencode, urlparse
except ImportError:
from urllib import urlencode

from urlparse import parse_qsl, urlparse

from urlparse import parse_qsl, urlparse

try:
from json.decoder import JSONDecodeError
except ImportError:
Expand Down Expand Up @@ -661,6 +686,9 @@ def create_coveragestore(
layer_name,
name,
resp.status_code,
layer_name,
name,
resp.status_code,
)
)
else:
Expand All @@ -687,18 +715,18 @@ def create_coveragestore(
if resp.status_code != 201:
raise FailedRequestError(
"Failed to create coverage/layer {} for : {}, {}".format(
layer_name, name, resp.status_code, resp.text
layer_name,
name,
resp.status_code,
)
)
self._cache.clear()
#servers not on localhost may not return a store throwing an error
time = 0
while name not in [
store.name for store in self.get_stores(workspaces=[workspace]) and time < 120
store.name for store in self.get_stores(workspaces=[workspace])
]:
sleep(.5)
time ++ .5
return self.get_stores(names=name, workspaces=[workspace])[0]
sleep(1)

return self.get_resources(names=layer_name, workspaces=[workspace])[0]

def add_granule(self, data, store, workspace=None):
"""Harvest/add a granule into an existing imagemosaic"""
Expand Down Expand Up @@ -1238,6 +1266,11 @@ def get_style(self, name, workspace=None, recursive=False):
Will raise an error if more than one style with the same name is found.
"""

url = (
f"{self.service_url}/workspaces/{workspace}/styles/{name}.json"
if workspace
else f"{self.service_url}/styles/{name}.json"
)
url = (
f"{self.service_url}/workspaces/{workspace}/styles/{name}.json"
if workspace
Expand All @@ -1253,11 +1286,19 @@ def get_style(self, name, workspace=None, recursive=False):
if payload.get("workspace")
else workspace
)
payload = resp.json()["style"]
extracted_workspace = (
payload["workspace"].get("name", workspace)
if payload.get("workspace")
else workspace
)
return Style(
self,
payload["name"],
payload["name"],
extracted_workspace,
payload["format"] + payload["languageVersion"]["version"],
payload["format"] + payload["languageVersion"]["version"],
)

except HTTPError as e:
Expand All @@ -1269,20 +1310,29 @@ def get_style(self, name, workspace=None, recursive=False):
logger.exception(e)
raise e


def delete_style(self, name, workspace=None, purge=True):
if workspace:
"""
"""
If workspace is passed, we call directly the wanted style
"""
url = (
f"{self.service_url}/workspaces/{workspace}/styles/{name}?purge={purge}"
)
"""
url = (
f"{self.service_url}/workspaces/{workspace}/styles/{name}?purge={purge}"
)
else:
"""
"""
If is not passed, we try to get the style without passing any workspace
"""
"""
url = f"{self.service_url}/styles/{name}?purge={purge}"


try:
resp = self.http_request(url, method="DELETE")
if resp.status_code != 404:
Expand Down Expand Up @@ -1501,6 +1551,7 @@ def get_services(self, ogc_type="wms"):
f"{self.service_url}/services/{ogc_type}/workspaces/{ws.name}/settings"
)
services.append(service_from_index(self, data))
except FailedRequestError:
except FailedRequestError:
logger.debug(f"Not found {ogc_type} service for workspace {ws.name}")
return services
Expand All @@ -1514,6 +1565,7 @@ def create_user(self, username, password):
)
try:
tmp_cat.get_version()
except FailedRequestError:
except FailedRequestError:
logger.error("And we probably have incorrect password")
raise FailedRequestError
Expand Down

0 comments on commit e28cde3

Please sign in to comment.