This repository has been archived by the owner on Aug 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added robust message publisher and subscriber
AMQP message broadcasting did not reconnect when, for some reason, the server disconnected (ex: restart). This change builds on the ConnectionService class to make it a generic, self-healing connection manager that may be extended. The publisher and subscriber logic was then built on top of ConnectionService to take advantage of connection management. - New self-healing, lazy initializing connection service. - Publisher extends connection service. - Subscriber extends connection service. - ResourceHook was moved into notifications as the NotificationHook. - Configuration options for explicit exchange and queue naming added. Change-Id: Ib57c56a38574a0c70db9066625aef75ff8891c93
- Loading branch information
1 parent
8d86f7e
commit 6df6a60
Showing
9 changed files
with
416 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import json | ||
import re | ||
|
||
from pecan import hooks | ||
|
||
from storyboard.notifications.publisher import publish | ||
|
||
|
||
class NotificationHook(hooks.PecanHook): | ||
def __init__(self): | ||
super(NotificationHook, self).__init__() | ||
|
||
def after(self, state): | ||
# Ignore get methods, we only care about changes. | ||
if state.request.method == 'GET': | ||
return | ||
|
||
request = state.request | ||
req_method = request.method | ||
req_user_id = request.current_user_id | ||
req_path = request.path | ||
req_resource_grp = self._parse(req_path) | ||
|
||
if not req_resource_grp: | ||
return | ||
|
||
resource = req_resource_grp[0] | ||
|
||
if req_resource_grp[1]: | ||
resource_id = req_resource_grp[1] | ||
else: | ||
# When a resource is created.. | ||
response_str = state.response.body | ||
response = json.loads(response_str) | ||
if response: | ||
resource_id = response.get('id') | ||
else: | ||
resource_id = None | ||
|
||
# when adding/removing projects to project_groups.. | ||
if req_resource_grp[3]: | ||
sub_resource_id = req_resource_grp[3] | ||
payload = { | ||
"user_id": req_user_id, | ||
"method": req_method, | ||
"resource": resource, | ||
"resource_id": resource_id, | ||
"sub_resource_id": sub_resource_id | ||
} | ||
|
||
else: | ||
payload = { | ||
"user_id": req_user_id, | ||
"method": req_method, | ||
"resource": resource, | ||
"resource_id": resource_id | ||
} | ||
|
||
publish(resource, payload) | ||
|
||
def _parse(self, s): | ||
url_pattern = re.match("^\/v1\/([a-z_]+)\/?([0-9]+)?" | ||
"\/?([a-z]+)?\/?([0-9]+)?$", s) | ||
if url_pattern and url_pattern.groups()[0] != "openid": | ||
return url_pattern.groups() | ||
else: | ||
return |
Oops, something went wrong.