tests done
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
import logging
|
||||
import random
|
||||
import requests
|
||||
from consumerlocator import ConsumerLocator
|
||||
|
||||
"""
|
||||
Communicator module
|
||||
@@ -21,13 +19,13 @@ class Communicator:
|
||||
Class handling low level communication with consumers.
|
||||
"""
|
||||
|
||||
def __init__(self, consumerlocator: ConsumerLocator, uuid: str):
|
||||
def __init__(self, currentconsumer: str, uuid: str):
|
||||
"""
|
||||
Initialize object
|
||||
:param consumerlocator:
|
||||
:param uuid:
|
||||
"""
|
||||
self.consumerlocator=consumerlocator
|
||||
self.currenctconsumer=currentconsumer
|
||||
self.uuid = uuid
|
||||
|
||||
def sendmessage(self, message: str) -> None:
|
||||
@@ -36,7 +34,7 @@ class Communicator:
|
||||
:param message:
|
||||
:return: none
|
||||
"""
|
||||
currentconsumer=self.consumerlocator.getcurrentconsumer()
|
||||
currentconsumer=self.currenctconsumer
|
||||
LOGGER.debug(f"Sending message to {currentconsumer}")
|
||||
requests.post(f'http://{currentconsumer}/log', json={'uuid': self.uuid, 'message': message})
|
||||
|
||||
@@ -45,7 +43,7 @@ class Communicator:
|
||||
Get the list of available consumer from the current primary consumer.
|
||||
:return:
|
||||
"""
|
||||
currentconsumer = self.consumerlocator.getcurrentconsumer()
|
||||
currentconsumer = self.currenctconsumer
|
||||
response = requests.get(f'http://{currentconsumer}/consumer')
|
||||
json = response.json()
|
||||
LOGGER.debug(f"List of currently available consumers: {json}")
|
||||
@@ -56,9 +54,13 @@ class Communicator:
|
||||
Readiness probe primary consumer.
|
||||
:return:
|
||||
"""
|
||||
currentconsumer = self.consumerlocator.getcurrentconsumer()
|
||||
response = requests.get(f'http://{currentconsumer}/consumer')
|
||||
isavailable = response.status_code == 200
|
||||
currentconsumer = self.currenctconsumer
|
||||
try:
|
||||
response = requests.get(f'http://{currentconsumer}/consumer')
|
||||
isavailable = response.status_code == 200
|
||||
except Exception as e:
|
||||
LOGGER.exception(e)
|
||||
isavailable = False
|
||||
LOGGER.debug(f"Current consumer availability: {isavailable}")
|
||||
return isavailable
|
||||
|
||||
@@ -68,7 +70,19 @@ class Communicator:
|
||||
:param consumer:
|
||||
:return:
|
||||
"""
|
||||
response = requests.get(f'http://{consumer}/consumer')
|
||||
isavailable = response.status_code == 200
|
||||
try:
|
||||
response = requests.get(f'http://{consumer}/consumer')
|
||||
isavailable = response.status_code == 200
|
||||
except Exception as e:
|
||||
LOGGER.exception(e)
|
||||
isavailable = False
|
||||
LOGGER.debug(f"Consumer {consumer} availability: {isavailable}")
|
||||
return isavailable
|
||||
|
||||
def set_currentconsumer(self,currenctconsumer):
|
||||
"""
|
||||
Set current consumer
|
||||
:param currenctconsumer:
|
||||
:return:
|
||||
"""
|
||||
self.currenctconsumer=currenctconsumer
|
||||
|
||||
Reference in New Issue
Block a user