def __init__(self): """Instantiate CommandMessageManager based on setting values""" # Set up the backend message passing... right now its just RabbitMQ or SQS broker_type = BrokerDetails.from_broker_url(settings.BROKER_URL).get_type() self._backend = get_message_backend(broker_type)
def test_valid_rabbitmq_broker_url(self): """Tests instantiating broker from URL for RabbitMQ.""" broker_url = 'amqp://*****:*****@localhost:5672//' broker = BrokerDetails.from_broker_url(broker_url) self.assertEqual(broker.get_type(), 'amqp') self.assertEqual(broker.get_user_name(), 'guest') self.assertEqual(broker.get_password(), 'pass') self.assertEqual(broker.get_address(), 'localhost:5672')
def test_valid_sqs_broker_url_no_credentials(self): """Tests instantiating broker from URL for SQS without keys.""" broker_url = 'sqs://us-east-1//' broker = BrokerDetails.from_broker_url(broker_url) self.assertEqual(broker.get_type(), 'sqs') self.assertIsNone(broker.get_user_name()) self.assertIsNone(broker.get_password()) self.assertEqual(broker.get_address(), 'us-east-1')
def test_valid_sqs_broker_url(self): """Tests instantiating broker from URL for SQS with Access and Secret Key.""" broker_url = 'sqs://*****:*****@us-east-1//' broker = BrokerDetails.from_broker_url(broker_url) self.assertEqual(broker.get_type(), 'sqs') self.assertEqual(broker.get_user_name(), 'access') self.assertEqual(broker.get_password(), 'secret') self.assertEqual(broker.get_address(), 'us-east-1')
def _generate_msg_queue_status(self): """Generates the Message Queue status message AMQP (rabbitmq) """ status_dict = {'OK': False, 'detail': {}, 'errors': [], 'warnings': []} status_dict['detail']['msg'] = 'Message Queue is healthy' status_dict['detail']['queue_name'] = scale_settings.QUEUE_NAME status_dict['detail']['num_message_handlers'] = scheduler_mgr.config.num_message_handlers status_dict['detail']['queue_depth'] = 0 status_dict['detail']['region_name'] = '' status_dict['detail']['type'] = '' try: broker_details = BrokerDetails.from_broker_url(scale_settings.BROKER_URL) except InvalidBrokerUrl: msg = 'Error parsing broker url' status_dict['errors'] = [{'INVALID_BROKER_URL': msg}] status_dict['detail']['msg'] = msg return status_dict status_dict['detail']['type'] = broker_details.get_type() if broker_details.get_type() == 'amqp': try: CommandMessageManager().get_queue_size() status_dict['OK'] = True except Exception as ex: logger.error('Error connecting to RabbitMQ: %s' % unicode(ex)) status_dict['OK'] = False msg = 'Error connecting to RabbitMQ: Check Logs for details' status_dict['errors'] = [{'RABBITMQ_ERROR': msg}] status_dict['detail']['msg'] = 'Unable to get message queue size.' elif broker_details.get_type() == 'sqs': status_dict['detail']['region_name'] = broker_details.get_address() try: CommandMessageManager().get_queue_size() status_dict['OK'] = True except Exception as ex: logger.error('Unable to get queue size from sqs: %s' % unicode(ex)) msg = 'Error connecting to SQS: Check Logs for details' status_dict['OK'] = False status_dict['errors'] = [{'SQS_ERROR': msg}] status_dict['detail']['msg'] = 'Unable to get message queue size.' else: status_dict['OK'] = False status_dict['detail']['msg'] = 'Broker is an unsupported type: %s' % broker_details.get_type() if status_dict['OK']: status_dict['detail']['queue_depth'] = CommandMessageManager().get_queue_size() if scale_settings.MESSSAGE_QUEUE_DEPTH_WARN > 0 and status_dict['detail']['queue_depth'] > scale_settings.MESSSAGE_QUEUE_DEPTH_WARN: status_dict['warnings'].append({'LARGE_QUEUE': 'Message queue is very large'}) status_dict['detail']['msg'] = 'Message queue is large. Scale may be unresponsive.' return status_dict
def __init__(self, backend_type): """Instantiates backend specific settings """ # Unique type of MessagingBackend, each type must be registered in apps.py self.type = backend_type # Connection string pulled from configuration self._broker_url = settings.BROKER_URL self._broker = BrokerDetails.from_broker_url(settings.BROKER_URL) # TODO: Transition to more advanced message routing per command message type self._queue_name = settings.QUEUE_NAME
def test_missing_solidus_credentials_broker_url(self): """Tests instantiating broker from invalid URL missing double solidus delimiter.""" broker_url = 'sqs:/us-east-1' with self.assertRaises(InvalidBrokerUrl): BrokerDetails.from_broker_url(broker_url)
def test_bad_credentials_broker_url(self): """Tests instantiating broker from invalid URL with credential delimiter.""" broker_url = 'sqs://@us-east-1' with self.assertRaises(InvalidBrokerUrl): BrokerDetails.from_broker_url(broker_url)