コード例 #1
0
ファイル: kepler_utilities.py プロジェクト: camm/code
def send_amq_results_ready():
    """
        Entry point for console script to send a results-ready message to AMQ
    """
    # Create a configuration object
    conf = Configuration()

    # Parse command arguments
    parser = argparse.ArgumentParser(description="Kepler workflow communication")
    parser.add_argument(
        conf.kepler_result_queue_flag,
        metavar="return_queue",
        required=True,
        help="AMQ queue to send results to",
        dest="return_queue",
    )
    parser.add_argument(
        conf.kepler_output_file_flag,
        metavar="output_file",
        default="results.out",
        help="Kepler output file",
        dest="output_file",
    )
    namespace = parser.parse_args()

    # Setup the AMQ client
    c = Client(conf.brokers, conf.amq_user, conf.amq_pwd)

    # Send a simple message to the return queue
    message = {"output_file": namespace.output_file}
    c.send(destination="/queue/" + namespace.return_queue, message=json.dumps(message))
    c._disconnect()

    send_status_info(str(os.getpid()), "stop_iteration")
コード例 #2
0
ファイル: camm_monitor.py プロジェクト: camm/code
def send_status_info(instance_number, status, code=0):
    """
        Send a status message to ActiveMQ
        @param instrance_numer: unique number of the CAMM job this process belongs to
        @param status: status string
        @param code: status code
    """
    try:
        int(instance_number)
    except:
        logging.error("Instance_number must be an integer. Found: %s" % str(instance_number))
        
    if status not in ['dakota_start', 'start_iteration', 'stop_iteration', 'dakota_stop']:
        logging.error("Invalid status string. Found: %s" % str(status))
        
    # Create a configuration object
    conf = Configuration()
    # Setup the AMQ client
    c = Client(conf.brokers, conf.amq_user, conf.amq_pwd)

    # Send a simple message to the return queue
    message = {'instance_number': instance_number,
               'user': str(getpass.getuser()),
               'timestamp': time.time(),
               'status': status,
               'code': code}
    
    c.send(destination='/topic/SNS.CAMM.STATUS.JOBS', message=json.dumps(message))
    c._disconnect()       
コード例 #3
0
ファイル: camm_monitor.py プロジェクト: camm/code
 def run(self):
     """
         Run the CAMM listener daemon
     """
     # Create a configuration object
     conf = Configuration()
     # Setup the AMQ client
     c = Client(conf.brokers, conf.amq_user, conf.amq_pwd, 
                queues=['/topic/SNS.CAMM.STATUS.JOBS'])
     listener = CammListener(conf)
     c.set_listener(listener)
     c.listen_and_wait(0.1)
コード例 #4
0
ファイル: send_amq.py プロジェクト: camm/code
#!/usr/bin/env python
"""
    Dummy AMQ producer to test the Kepler service
"""
import json
import argparse
import os
from sns_utilities.amq_connector.amq_consumer import Client
from camm_amq.configuration import Configuration
import time

# Setup the AMQ client
conf = Configuration('/etc/kepler_consumer.conf')
c = Client(conf.brokers, conf.amq_user, conf.amq_pwd)

# Parse command arguments
parser = argparse.ArgumentParser(description='Dummy Kepler workflow')
parser.add_argument(conf.kepler_result_queue_flag, metavar='return_queue',
                    default='DAKOTA.RESULTS.TEST',
                    help='AMQ queue to send results to',
                    dest='return_queue')
parser.add_argument(conf.kepler_output_file_flag, metavar='output_file',
                    default='results.out',
                    help='Kepler output file',
                    dest='output_file')
namespace = parser.parse_args()

output_file = namespace.output_file
value = output_file.split(".")[-1]

# Send a simple message to the return queue