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

View File

@ -104,6 +104,20 @@ def get_all():
return True
def check_system():
print("Checking system health")
baseurl = "http://127.0.0.1:8000"
get_url = "/check"
try:
response = requests.get(baseurl + get_url)
print_response(response)
except os.error:
print("Error checking system health")
return True
metadata = None
index = 0
metadata_folder = "." + os.path.sep
@ -160,6 +174,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("List of commands:")
print("exit - exits the program")
print("help - lists all commands")
print("check - control health of all associated systems")
print("dir - list current selected image folder")
print("len - length of current metadata set")
print("index - display index of current lined up image")
@ -179,6 +194,9 @@ while (command.lower() not in ["exit", "quit", "end"]):
print()
print()
if command.lower() == "check":
check_system()
if command.lower() == "dir":
print("Current image folder is " + image_folder)

View File

@ -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.

View File

@ -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.

View File

@ -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()

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()

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"]

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)