def process_rmq_inputs(args, instance_name=None): if not is_rabbitmq_available(): raise RuntimeError( "Rabbitmq Dependencies not installed please run python bootstrap.py --rabbitmq" ) confirm_volttron_home() if len(args) == 2: vhome = get_home() if args[0] == 'single': vhome_config = os.path.join(vhome, 'rabbitmq_config.yml') elif args[0] == 'federation': vhome_config = os.path.join(vhome, 'rabbitmq_federation_config.yml') elif args[0] == 'shovel': vhome_config = os.path.join(vhome, 'rabbitmq_shovel_config.yml') else: print( "Invalid argument. \nUsage: vcf --rabbitmq single|federation|shovel " "[optional path to rabbitmq config yml]") exit(1) if args[1] != vhome_config: if not os.path.exists(vhome): os.makedirs(vhome, 0o755) copy(args[1], vhome_config) setup_rabbitmq_volttron(args[0], verbose, instance_name=instance_name) else: setup_rabbitmq_volttron(args[0], verbose, prompt=True, instance_name=instance_name)
def process_rmq_inputs(args_dict, instance_name=None): #print(f"args_dict:{args_dict}, args") if not is_rabbitmq_available(): raise RuntimeError( "Rabbitmq Dependencies not installed please run python bootstrap.py --rabbitmq" ) confirm_volttron_home() vhome = get_home() if args_dict['config'] is not None: if not os.path.exists(vhome): os.makedirs(vhome, 0o755) if args_dict['installation-type'] == 'single': vhome_config = os.path.join(vhome, 'rabbitmq_config.yml') if args_dict['config'] != vhome_config: copy(args_dict['config'], vhome_config) elif args_dict['installation-type'] == 'federation': vhome_config = os.path.join(vhome, 'rabbitmq_federation_config.yml') if os.path.exists(vhome_config): prompt = f"rabbitmq_federation_config.yml already exists in VOLTTRON_HOME: {vhome}.\n" \ "Do you wish to use this config file? If no, rabbitmq_federation_config.yml \n" \ "will be replaced with new config file" prompt = prompt_response(prompt, valid_answers=y_or_n, default='N') if prompt in n: copy(args_dict['config'], vhome_config) else: r = copy(args_dict['config'], vhome_config) elif args_dict['installation-type'] == 'shovel': vhome_config = os.path.join(vhome, 'rabbitmq_shovel_config.yml') if os.path.exists(vhome_config): prompt = f"rabbitmq_shovel_config.yml already exists in VOLTTRON_HOME: {vhome}.\n" \ "Do you wish to use this config file? If no, rabbitmq_shovel_config.yml \n" \ "will be replaced with new config file" prompt = prompt_response(prompt, valid_answers=y_or_n, default='N') if prompt in n: copy(args_dict['config'], vhome_config) else: r = copy(args_dict['config'], vhome_config) else: print( "Invalid installation type. Acceptable values single|federation|shovel" ) sys.exit(1) setup_rabbitmq_volttron(args_dict['installation-type'], verbose, instance_name=instance_name, max_retries=args_dict['max_retries']) else: setup_rabbitmq_volttron(args_dict['installation-type'], verbose, prompt=True, instance_name=instance_name, max_retries=args_dict['max_retries'])
def do_message_bus(): global config_opts bus_type = None valid_bus = False while not valid_bus: prompt = 'What type of message bus (rmq/zmq)?' new_bus = prompt_response(prompt, default='zmq') valid_bus = is_valid_bus(new_bus) if valid_bus: bus_type = new_bus else: print("Message type is not valid. Valid entries are zmq or rmq.") if bus_type == 'rmq': if not is_rabbitmq_available(): print("RabbitMQ has not been set up!") print( "Please run scripts/rabbit_dependencies.sh and bootstrap --rabbitmq before running vcfg." ) sys.exit() # print("Setting up now...") # set_dependencies_rmq() # print("Done!") # if not _check_dependencies_met('rabbitmq'): # print("Rabbitmq dependencies not installed. Installing now...") # set_dependencies("rabbitmq") # print("Done!") try: check_rmq_setup() except AssertionError: print( "RabbitMQ setup is incomplete. RabbitMQ server directory is missing." ) print("Please run bootstrap --rabbitmq before running vcfg") sys.exit() config_opts['message-bus'] = bus_type
# operated by BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY # under Contract DE-AC05-76RL01830 # }}} import errno import json import logging import os from volttron.platform import is_rabbitmq_available from volttron.platform.agent.utils import get_fq_identity from volttron.platform.vip import BaseConnection from volttron.platform.vip.agent.errors import Unreachable from volttron.platform.vip.socket import Message if is_rabbitmq_available(): import pika _log = logging.getLogger(__name__) # reduce pika log level logging.getLogger("pika").setLevel(logging.WARNING) RMQ_RESOURCE_LOCKED = 405 CONNECTION_FORCED = 320 class RMQConnection(BaseConnection): """ Connection class for RabbitMQ message bus. 1. It maintains connection with RabbitMQ broker using Pika library APIs 2. Translates from VIP message format to RabbitMQ message format and visa-versa 3. Sends and receives messages using Pika library APIs
import os import pytest from random import randint import socket import uuid from volttrontesting.utils.platformwrapper import PlatformWrapper from volttrontesting.utils.utils import get_hostname_and_random_port, get_rand_vip, get_rand_ip_and_port from volttron.platform import is_rabbitmq_available PRINT_LOG_ON_SHUTDOWN = False HAS_RMQ = is_rabbitmq_available() rmq_skipif = pytest.mark.skipif(not HAS_RMQ, reason='RabbitMQ is not setup') def print_log(volttron_home): if PRINT_LOG_ON_SHUTDOWN: if os.environ.get('PRINT_LOGS', PRINT_LOG_ON_SHUTDOWN): log_path = volttron_home + "/volttron.log" if os.path.exists(log_path): with open(volttron_home + "/volttron.log") as fin: print(fin.read()) else: print('NO LOG FILE AVAILABLE.') def build_wrapper(vip_address, should_start=True, messagebus='zmq', remote_platform_ca=None, instance_name=None,