Skip to content

Commit

Permalink
Remove brew-view and bartender references (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
catattack05 authored Aug 15, 2022
1 parent 6022612 commit 0ed1ca0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
40 changes: 20 additions & 20 deletions brewtils/request_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,25 +383,25 @@ def __init__(self, ez_client, shutdown_event, **kwargs):
self.max_timeout = kwargs.get("max_timeout", 30)
self.starting_timeout = kwargs.get("starting_timeout", 5)

# Tightly manage when we're in an 'error' state, aka Brew-view is down
self.brew_view_error_condition = threading.Condition()
self.brew_view_down = False
# Tightly manage when we're in an 'error' state, aka beergarden is down
self.beergarden_error_condition = threading.Condition()
self.beergarden_down = False

self.logger.debug("Creating and starting connection poll thread")
self.connection_poll_thread = self._create_connection_poll_thread()
self.connection_poll_thread.start()

def shutdown(self):
self.logger.debug("Shutting down, about to wake any sleeping updater threads")
with self.brew_view_error_condition:
self.brew_view_error_condition.notify_all()
with self.beergarden_error_condition:
self.beergarden_error_condition.notify_all()

def update_request(self, request, headers):
"""Sends a Request update to beer-garden
Ephemeral requests do not get updated, so we simply skip them.
If brew-view appears to be down, it will wait for brew-view to come back
If beergarden appears to be down, it will wait for beergarden to come back
up before updating.
If this is the final attempt to update, we will attempt a known, good
Expand All @@ -422,9 +422,9 @@ def update_request(self, request, headers):
sys.stdout.flush()
return

with self.brew_view_error_condition:
with self.beergarden_error_condition:

self._wait_for_brew_view_if_down(request)
self._wait_for_beergarden_if_down(request)

try:
if not self._should_be_final_attempt(headers):
Expand Down Expand Up @@ -460,10 +460,10 @@ def _wait_if_not_first_attempt(self, headers):

def _handle_request_update_failure(self, request, headers, exc):

# If brew-view is down, we always want to try again
# If beergarden is down, we always want to try again
# Yes, even if it is the 'final_attempt'
if isinstance(exc, (RequestsConnectionError, RestConnectionError)):
self.brew_view_down = True
self.beergarden_down = True
self.logger.error(
"Error updating request status: {0} exception: {1}".format(
request.id, exc
Expand Down Expand Up @@ -528,14 +528,14 @@ def _should_be_final_attempt(self, headers):

return self.max_attempts <= headers.get("retry_attempt", 0)

def _wait_for_brew_view_if_down(self, request):
if self.brew_view_down and not self._shutdown_event.is_set():
def _wait_for_beergarden_if_down(self, request):
if self.beergarden_down and not self._shutdown_event.is_set():
self.logger.warning(
"Currently unable to communicate with Brew-view, about to wait "
"Currently unable to communicate with beergarden, about to wait "
"until connection is reestablished to update request %s",
request.id,
)
self.brew_view_error_condition.wait()
self.beergarden_error_condition.wait()

def _create_connection_poll_thread(self):
connection_poll_thread = threading.Thread(target=self._connection_poll)
Expand All @@ -547,18 +547,18 @@ def _connection_poll(self):

while not self._shutdown_event.wait(5):
try:
with self.brew_view_error_condition:
if self.brew_view_down:
with self.beergarden_error_condition:
if self.beergarden_down:
try:
self._ez_client.get_version()
except Exception:
self.logger.debug("Brew-view reconnection attempt failure")
self.logger.debug("Beergarden reconnection attempt failure")
else:
self.logger.info(
"Brew-view connection reestablished, about to "
"Beergarden connection reestablished, about to "
"notify any waiting requests"
)
self.brew_view_down = False
self.brew_view_error_condition.notify_all()
self.beergarden_down = False
self.beergarden_error_condition.notify_all()
except Exception as ex:
self.logger.exception("Exception in connection poll thread: %s", ex)
22 changes: 11 additions & 11 deletions test/request_handling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ def test_errors(self, updater, client, bg_request, ex, raised, bv_down):
with pytest.raises(raised):
updater.update_request(bg_request, {})
assert client.update_request.called is True
assert updater.brew_view_down is bv_down
assert updater.beergarden_down is bv_down

def test_wait_during_error(self, updater, client, bg_request):
error_condition_mock = MagicMock()
updater.brew_view_error_condition = error_condition_mock
updater.brew_view_down = True
updater.beergarden_error_condition = error_condition_mock
updater.beergarden_down = True

updater.update_request(bg_request, {})
assert error_condition_mock.wait.called is True
Expand Down Expand Up @@ -455,31 +455,31 @@ def test_shut_down(self, updater, client, shutdown_event):
updater._connection_poll()
assert client.get_version.called is False

def test_brew_view_normal(self, updater, client, shutdown_event):
def test_beergarden_normal(self, updater, client, shutdown_event):
shutdown_event.wait.side_effect = [False, True]

updater._connection_poll()
assert client.get_version.called is False

def test_brew_view_down(self, updater, client, shutdown_event):
def test_beergarden_down(self, updater, client, shutdown_event):
shutdown_event.wait.side_effect = [False, True]
updater.brew_view_down = True
updater.beergarden_down = True
client.get_version.side_effect = ValueError

updater._connection_poll()
assert client.get_version.called is True
assert updater.brew_view_down is True
assert updater.beergarden_down is True

def test_brew_view_back(self, updater, client, shutdown_event):
def test_beergarden_back(self, updater, client, shutdown_event):
shutdown_event.wait.side_effect = [False, True]
updater.brew_view_down = True
updater.beergarden_down = True

updater._connection_poll()
assert client.get_version.called is True
assert updater.brew_view_down is False
assert updater.beergarden_down is False

def test_never_die(self, monkeypatch, updater, client, shutdown_event):
monkeypatch.setattr(updater, "brew_view_error_condition", None)
monkeypatch.setattr(updater, "beergarden_error_condition", None)
shutdown_event.wait.side_effect = [False, True]

# Test passes if this doesn't raise
Expand Down

0 comments on commit 0ed1ca0

Please sign in to comment.