Skip to content

Commit

Permalink
Simplify modules config:
Browse files Browse the repository at this point in the history
* Resolve rabbimq_address automatically.
* Remove rabbitmq_address from JSON configs.
* Remove obsolete variable rabbitmq_vhost in pub and sub config
  • Loading branch information
marionleborgne committed Sep 13, 2017
1 parent ae9fc5b commit 3417f56
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 63 deletions.
7 changes: 0 additions & 7 deletions examples/chained_modules/ecg.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down Expand Up @@ -42,7 +41,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand All @@ -61,7 +59,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down Expand Up @@ -89,7 +86,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand All @@ -107,7 +103,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down Expand Up @@ -143,7 +138,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand All @@ -161,7 +155,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
2 changes: 0 additions & 2 deletions examples/filter.band.pass.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand All @@ -32,7 +31,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
2 changes: 0 additions & 2 deletions examples/filter.band.stop.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand All @@ -32,7 +31,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/sink.csv.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/sink.csvout.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/sink.plotly.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/sink.pyplot.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/sink.stdout.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/source.mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
51 changes: 51 additions & 0 deletions examples/source.mock.marion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"modules": [
{
"name": "MockSource",
"package": "cloudbrain.modules.sources.mock",
"options": {
"sampling_frequency": 250.0,
"alpha_amplitude": 10.0,
"alpha_freq": 10.0,
"beta_amplitude": 5.0,
"beta_freq": 25.0,
"notch_amplitude": 0.0,
"notch_freq": 60.0,
"noise_amplitude": 10.0,
"number_points": 249
},
"publishers": [
{
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_user": "[email protected]",
"rabbitmq_pwd": "test"
},
"base_routing_key": "mock",
"metrics": [
{
"metric_name": "eeg",
"num_channels": 8,
"buffer_size": 10
}
]
},
{
"name": "PipePublisher",
"package": "cloudbrain.publishers.pipe",
"options": {},
"base_routing_key": "some_unique_key",
"metrics": [
{
"metric_name": "eeg",
"num_channels": 8,
"buffer_size": 100
}
]
}
],
"subscribers": []
}
]
}
1 change: 0 additions & 1 deletion examples/source.muse.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/source.neurosky.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
1 change: 0 additions & 1 deletion examples/source.openci.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
2 changes: 0 additions & 2 deletions examples/transform.fft.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"name": "PikaPublisher",
"package": "cloudbrain.publishers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand All @@ -46,7 +45,6 @@
"name": "PikaSubscriber",
"package": "cloudbrain.subscribers.rabbitmq",
"options": {
"rabbitmq_address": "localhost",
"rabbitmq_user": "YOUR_EMAIL",
"rabbitmq_pwd": "YOUR_PASSWORD"
},
Expand Down
2 changes: 0 additions & 2 deletions src/cloudbrain/core/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
import simplejson as json

from pkg_resources import resource_filename

from cloudbrain import core



def get_config():
if os.environ.get("DEV"):
config_file = resource_filename(core.__name__, 'config.dev.json')
Expand Down
28 changes: 8 additions & 20 deletions src/cloudbrain/publishers/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,32 @@ class PikaPublisher(PublisherInterface):

def __init__(self,
base_routing_key,
rabbitmq_address,
rabbitmq_user,
rabbitmq_pwd,
rabbitmq_vhost=None):
rabbitmq_pwd):

super(PikaPublisher, self).__init__(base_routing_key)
_LOGGER.debug("Base routing key: %s" % self.base_routing_key)
_LOGGER.debug("Routing keys: %s" % self.routing_keys)
_LOGGER.debug("Metric buffers: %s" % self.metric_buffers)

self.config = get_config()
self.rabbitmq_address = rabbitmq_address
self.rabbitmq_user = rabbitmq_user
self.rabbitmq_pwd = rabbitmq_pwd

self.connection = None
self.channels = {}

# Keep rabbitmq_vhost as an input param for backwards compatibility but
# log warning saying that it's going to be overridden.
if rabbitmq_vhost is not None:
_LOGGER.warn('The parameter "rabbitmq_vhost" is no longer '
'supported and will be overridden. Please remove it '
'from the module JSON config file. (rabbitmq_vhost=%s)'
% rabbitmq_vhost)

# Resolve vhost
auth = CloudbrainAuth(self.config['authUrl'])
self.rabbitmq_vhost = auth.get_vhost(rabbitmq_user, rabbitmq_pwd)
self.config = get_config()
self.rabbitmq_address = self.config['rabbitHost']
self.auth = CloudbrainAuth(self.config['authUrl'])
self.rabbitmq_vhost = self.auth.get_vhost(rabbitmq_user, rabbitmq_pwd)

def connect(self):
credentials = pika.PlainCredentials(self.rabbitmq_user,
self.rabbitmq_pwd)

self.connection = pika.BlockingConnection(pika.ConnectionParameters(
params = pika.ConnectionParameters(
host=self.rabbitmq_address,
virtual_host=self.rabbitmq_vhost,
credentials=credentials))
credentials=credentials)
self.connection = pika.BlockingConnection(parameters=params)

def disconnect(self):
for channel in self.channels.values():
Expand Down
2 changes: 1 addition & 1 deletion src/cloudbrain/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def run(file_conf, json_conf, log_level):
if file_conf:
with open(file_conf, 'rb') as f:
module_configs = json.load(f)
elif json_conf:
else:
module_configs = json.loads(json_conf)

runner = ModuleRunner(module_configs)
Expand Down
23 changes: 5 additions & 18 deletions src/cloudbrain/subscribers/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,23 @@
class PikaSubscriber(SubscriberInterface):
def __init__(self,
base_routing_key,
rabbitmq_address,
rabbitmq_user,
rabbitmq_pwd,
rabbitmq_vhost=None):
rabbitmq_pwd):

super(PikaSubscriber, self).__init__(base_routing_key)

_LOGGER.debug("Base routing key: %s" % self.base_routing_key)
_LOGGER.debug("Routing keys: %s" % self.routing_keys)
_LOGGER.debug("Metric buffers: %s" % self.metric_buffers)

self.config = get_config()
self.rabbitmq_address = rabbitmq_address
self.rabbitmq_user = rabbitmq_user
self.rabbitmq_pwd = rabbitmq_pwd

self.connection = None
self.channels = {}

# Keep rabbitmq_vhost as an input param for backwards compatibility but
# log warning saying that it's going to be overridden.
if rabbitmq_vhost is not None:
_LOGGER.warn('The parameter "rabbitmq_vhost" is no longer '
'supported and will be overridden. Please remove it '
'from the module JSON config file. (rabbitmq_vhost=%s)'
% rabbitmq_vhost)

# Resolve vhost
auth = CloudbrainAuth(self.config['authUrl'])
self.rabbitmq_vhost = auth.get_vhost(rabbitmq_user, rabbitmq_pwd)
self.config = get_config()
self.rabbitmq_address = self.config['rabbitHost']
self.auth = CloudbrainAuth(self.config['authUrl'])
self.rabbitmq_vhost = self.auth.get_vhost(rabbitmq_user, rabbitmq_pwd)

def connect(self):
credentials = pika.PlainCredentials(self.rabbitmq_user,
Expand Down

0 comments on commit 3417f56

Please sign in to comment.