def init_connector(data_node): trusted_node1 = { 'user': RABBIT_USER, 'password': RABBIT_PW, 'url': RABBIT_URL, 'priority': 1 } trusted_node2 = { 'user': RABBIT_USER, 'password': RABBIT_PW, 'url': RABBIT_URL, 'priority': 2 } open_node = {'user': RABBIT_USER_OPEN, 'url': RABBIT_URL_OPEN} connector = esgfpid.Connector( handle_prefix=PREFIX, messaging_service_credentials=[ trusted_node1, trusted_node2, open_node ], messaging_service_exchange_name=RABBIT_EXCHANGE, data_node=data_node, thredds_service_path=THREDDS_PATH, test_publication=IS_TEST) connector.start_messaging_thread() return connector
def establish_pid_connection(pid_prefix, test_publication, project_config_section, config, handler, publish=True): """Establish a connection to the PID service pid_prefix PID prefix to be used for given project test_publication Boolean to flag PIDs as test project_config_section The name of the project config section in esg.ini config Loaded config file(s) handler Project handler to be used for given project publish Flag to trigger publication and unpublication """ try: import esgfpid except ImportError: raise "PID module not found. Please install the package 'esgfpid' (e.g. with 'pip install')." pid_messaging_service_exchange_name, pid_messaging_service_credentials = handler.get_pid_config( project_config_section, config) pid_data_node = urlparse.urlparse(config.get('DEFAULT', 'thredds_url')).netloc thredds_service_path = None if publish: thredds_file_specs = getThreddsServiceSpecs(config, 'DEFAULT', 'thredds_file_services') for serviceType, base, name, compoundName in thredds_file_specs: if serviceType == 'HTTPServer': thredds_service_path = base break pid_connector = esgfpid.Connector( handle_prefix=pid_prefix, messaging_service_exchange_name=pid_messaging_service_exchange_name, messaging_service_credentials=pid_messaging_service_credentials, data_node=pid_data_node, thredds_service_path=thredds_service_path, test_publication=test_publication) # Check connection check_pid_connection(pid_connector, send_message=True) return pid_connector
def init_connector(list_of_nodes, exch=RABBIT_EXCHANGE): print('Init connector (%s)' % list_of_nodes) connector = esgfpid.Connector( handle_prefix=PREFIX, messaging_service_credentials=list_of_nodes, messaging_service_exchange_name=exch, data_node='data.dkrz.foo.de', test_publication=True ) connector.start_messaging_thread() return connector
def datacart_pid(request, site_id, user_id): # check User object user = get_object_or_404(User, pk=user_id) # security check if not request.user.id != user_id: raise Exception("User not authorized to modify datacart") pid_messaging_service_credentials = [] priority = 1 for cred in settings.PID_CREDENTIALS: parts = cred.split('|') if len(parts) == 6: ssl_enabled = False if parts[5].strip().upper() == 'TRUE': ssl_enabled = True pid_messaging_service_credentials.append({ 'url': parts[0].strip(), 'port': parts[1].strip(), 'vhost': parts[2].strip(), 'user': parts[3].strip(), 'password': parts[4].strip(), 'ssl_enabled': ssl_enabled, 'priority': priority }) priority += 1 # get list of dataset_pids and dataset_ids try: datacart = DataCart.objects.get(user=user) except DataCart.DoesNotExist: datacart = None queryDict = getQueryDict(request) ids = queryDict.getlist('id') dataset_ids = {} if datacart: for item in datacart.items.all(): # filter selected datasets only if item.identifier in ids: dataset_ids[item.identifier.split('|')[0]] = item.getValue( 'pid') # call PID library to generate collection PID connector = esgfpid.Connector( handle_prefix=settings.PID_PREFIX, messaging_service_exchange_name=settings. PID_MESSAGING_SERVICE_EXCHANGE, messaging_service_credentials=pid_messaging_service_credentials, ) connector.start_messaging_thread() pid = connector.create_data_cart_pid(dataset_ids) connector.finish_messaging_thread() print 'Generated data cart PID for %d datasets: %s' % (len(ids), pid) return HttpResponse(json.dumps(pid), content_type="application/json")
# Create credentials # (This does not connect) creds = dict(url=HOST, user=USER, password=PW, vhost=VHOST, port=AMQP_PORT, ssl_enabled=SSL) # Create a connector # (This does not connect) pid_connector = esgfpid.Connector( handle_prefix=pid_prefix, messaging_service_exchange_name=EXCH, messaging_service_credentials=[creds], # list of dicts data_node=pid_data_node, thredds_service_path=thredds_service_path, test_publication=test_publication) # Send a message with res = pid_connector.check_pid_queue_availability(send_message=True) print(res) if res is None: print('Unexpected behaviour, message should not be confirmed!') else: print('Message not sent - expected error') input( 'Please restore the binding between exchange %s and routing key "PREFIX.HASH.fresh.preflightcheck".'
# RabbitMQ connection config: # Please fill in: HOST = 'my-rabbit.ra' USER = '******' PW = 'bazfoo' SSL = False VHOST = 'foobar' EXCH = 'foobar' AMQP_PORT = 5672 HTTP_PORT = 15672 # Default RabbitMQ http port, if configured PREFIX = '21.14100' TEST = True # only change if you know what you're doing!!! # Create connector import esgfpid creds = dict(url=HOST, user=USER, password=PW, vhost=VHOST, port=AMQP_PORT, ssl_enabled=SSL) args = dict(messaging_service_credentials=[creds], messaging_service_exchange_name=EXCH, handle_prefix=PREFIX, test_publication=TEST) con = esgfpid.Connector(**args) # Check queue availability: x = con.check_pid_queue_availability() print(x) # Send con.start_messaging_thread() errata_args = dict(errata_ids=["aaa", "bbb"], drs_id="fooz", version_number=11110531) con.add_errata_ids(**errata_args) con.finish_messaging_thread()
(exch, exch_production)) exch = exch_production message = newmessage send_message = True # Make connector print('\nTesting connection to RabbitMQ at %s (user %s, password ****)' % (host, user)) cred = dict(user=user, password=password, url=host) if vhost is not None: cred['vhost'] = vhost if port is not None: cred['port'] = port connector = esgfpid.Connector(handle_prefix=prefix, messaging_service_exchange_name=exch, messaging_service_credentials=[cred], message_service_synchronous=synchronous_mode) # # Test Part 1 # test1_passed = False # Connect failed = False coupler = connector._Connector__coupler if synchronous_mode: try: print('Connecting...') coupler.start_rabbit_business() test1_passed = True
def get_connector(**kwargs): connector_args = get_connector_args(**kwargs) return esgfpid.Connector(**connector_args)