Added health check feature to find faulty components

This commit is contained in:
Martin Schett
2020-12-06 18:53:29 +01:00
parent ddf0cbf2d7
commit 08b30bb9cd
7 changed files with 67 additions and 3 deletions
@@ -5,6 +5,19 @@ import dropbox
class DropboxService:
@staticmethod
def check() -> bool:
try:
dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN)
result = dbx.check_user(query=u'Hello')
if not result.result == 'Hello':
print("String does not match")
return False
except:
return False
return True
@staticmethod
def create_file(filename: str, file: bytes) -> bool:
"""Create / save (or overwrite) an file on the dropbox storage.
@@ -5,6 +5,18 @@ from django.conf import settings
class MinioService:
@staticmethod
def check() -> bool:
print("Checking MinIO availability")
try:
url= settings.AWS_HOST
r = requests.put(url)
if not (r.status_code >= 200 and r.status_code < 500):
return False
except:
return False
return True
@staticmethod
def create_file(filename: str, file: bytes) -> bool:
"""Create / save (or overwrite) an file on the minio storage.
@@ -5,6 +5,15 @@ from app_be.services.hashservice import create_sha512
class MongoDBService:
@staticmethod
def check() -> bool:
try:
instance = MongoManager.getInstance()
instance.AIC
except:
return False
return True
@staticmethod
def getAll():
instance = MongoManager.getInstance()
+3 -2
View File
@@ -18,7 +18,7 @@ from django.contrib import admin
from django.urls import path, re_path
from rest_framework.routers import DefaultRouter
from app_be.views.rest_api import TestApiClass, ImageEndpoint
from app_be.views.rest_api import TestApiClass, ImageEndpoint, HealthEndpoint
urlpatterns = [
path('admin/', admin.site.urls),
@@ -27,7 +27,8 @@ urlpatterns = [
url(r'^image/get/(?P<identifier>[\w-]+)$', ImageEndpoint.image_api_get_single),
url(r'^image/delete/all$', ImageEndpoint.image_api_delete_all),
url(r'^image/delete/(?P<identifier>[\w-]+)$', ImageEndpoint.image_api_delete),
url(r'^image/post$', ImageEndpoint.image_api_post)
url(r'^image/post$', ImageEndpoint.image_api_post),
url(r'^check', HealthEndpoint.check_systems)
]
router = DefaultRouter()
+1 -1
View File
@@ -14,7 +14,7 @@ class MongoManager:
if MongoManager.__instance != None:
raise Exception("This class is a singleton!")
else:
MongoManager.__instance = pymongo.MongoClient('127.0.0.1', 27017)
MongoManager.__instance = pymongo.MongoClient('127.0.0.1', port=27017, serverSelectionTimeoutMS=1000)
db = MongoManager.__instance.AIC
coll = db.metadata
db.coll["identifier"]
+11
View File
@@ -141,3 +141,14 @@ class ImageEndpoint:
result_bool = False
return JsonResponse({'Result': result_bool}, safe=False)
class HealthEndpoint:
@staticmethod
@api_view(['GET'])
def check_systems(request):
logger.debug('Check health of all sub-systems')
mongo = MongoDBService.check()
dbx = DropboxService.check()
minio = MinioService.check()
return JsonResponse({'MongoDB': mongo, 'Dropbox': dbx, 'MinIO': minio}, safe=False)