Skip to content
Snippets Groups Projects
Commit 617eaf25 authored by David Trattnig's avatar David Trattnig
Browse files

refactor: use SimpleApi instead of urllib

parent 5deb8146
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
......@@ -32,12 +32,12 @@ import logging
import os
import platform
import threading
import urllib
from enum import Enum
from socket import AF_INET, SO_BROADCAST, SOCK_DGRAM, SOL_SOCKET, socket
import requests
from aura_engine.base.api import SimpleRestApi
from aura_engine.base.config import AuraConfig
from aura_engine.base.utils import SimpleUtil as SU
......@@ -70,7 +70,9 @@ class AuraMonitor:
"""
api: SimpleRestApi
logger = None
config = None
engine = None
status = None
already_invalid = None
......@@ -86,6 +88,7 @@ class AuraMonitor:
"""
Initialize Monitoring.
"""
self.api = SimpleRestApi()
self.logger = logging.getLogger("engine")
self.config = AuraConfig.config()
self.engine = engine
......@@ -315,14 +318,13 @@ class AuraMonitor:
def validate_url_connection(self, url):
"""
Check if connection to passed URL is successful.
# FIXME This should be refactored to a simple ping
"""
try:
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
response.read()
except Exception:
requests.get(url, timeout=5)
except requests.ConnectionError:
return False
return True
def validate_directory(self, dir_path):
......@@ -355,14 +357,11 @@ class AuraMonitor:
(dict[]): A Python object representing the JSON structure
"""
data = None
try:
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
data = response.read()
return json.loads(data, strict=False)
except (urllib.error.URLError, IOError, ValueError) as e:
result = self.api.get(url)
if 200 == result.response.status_code:
return result.json
except requests.ConnectionError as e:
self.logger.error("Error while connecting to URL '%s' - %s" % (url, e))
return MonitorResponseCode.INVALID_STATE.value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment