def createConfigFiles(nodeName, topoGraph, externalAgentsCommPort=28809, isDBEnabled=True):
	
	config.setNodeDir("/tmp/%s" %(nodeName))
	
	expdl = dict()
	expdl['topoGraph'] = json_graph.node_link_data(topoGraph)
	
	dbdl = dict()
	dbdl['isDBEnabled'] = isDBEnabled
		
	expConf = dict()
	expConf['expdl'] = expdl
	expConf['dbdl'] = dbdl
	
	expConf = config.loadExperimentConfig(experimentConfig=expConf, 
										  distributionPath='/tmp/magi',
										  transportClass=helpers.TRANSPORT_TCP)
	
	localInfo = dict()
	localInfo['nodename'] = nodeName
	localInfo['processAgentsCommPort'] = externalAgentsCommPort
	
	nodeConf = dict()
	nodeConf['localInfo'] = localInfo
	
	nodeConf = config.loadNodeConfig(nodeConf, expConf)
	
	helpers.makeDir(config.getConfigDir())
	helpers.writeYaml(expConf, config.getExperimentConfFile())
	helpers.writeYaml(nodeConf, config.getNodeConfFile())
	
	return (config.getNodeConfFile(), config.getExperimentConfFile())
def createConfigFiles(nodeName,
                      topoGraph,
                      externalAgentsCommPort=28809,
                      isDBEnabled=True):

    config.setNodeDir("/tmp/%s" % (nodeName))

    expdl = dict()
    expdl['topoGraph'] = json_graph.node_link_data(topoGraph)

    dbdl = dict()
    dbdl['isDBEnabled'] = isDBEnabled

    expConf = dict()
    expConf['expdl'] = expdl
    expConf['dbdl'] = dbdl

    expConf = config.loadExperimentConfig(experimentConfig=expConf,
                                          distributionPath='/tmp/magi',
                                          transportClass=helpers.TRANSPORT_TCP)

    localInfo = dict()
    localInfo['nodename'] = nodeName
    localInfo['processAgentsCommPort'] = externalAgentsCommPort

    nodeConf = dict()
    nodeConf['localInfo'] = localInfo

    nodeConf = config.loadNodeConfig(nodeConf, expConf)

    helpers.makeDir(config.getConfigDir())
    helpers.writeYaml(expConf, config.getExperimentConfFile())
    helpers.writeYaml(nodeConf, config.getNodeConfFile())

    return (config.getNodeConfFile(), config.getExperimentConfFile())
Exemple #3
0
def initializeProcessAgent(agent, argv):
    '''argv is assumed to have the following format. (This is usually set by the
    Magi daemon):

        agent_name agent_dock execute=[pipe|socket] (logfile=path)

    Where agent_name and agent_dock are strings and the key in the key=value
    pairs is literally the key given. The value may be restricted.
    '''
    if len(argv) < 3:
        log.critical('command line must start with name and dock')
        sys.exit(2)

    agent.name, dock, nodeConfigFile, experimentConfigFile = argv[1:5]
    args = argv_to_dict(argv[5:])

    config.loadNodeConfig(nodeConfigFile, experimentConfigFile)

    setAttributes(
        agent, {
            'hostname':
            config.getNodeName(),
            'execute':
            'socket',
            'logfile':
            os.path.join(config.getLogDir(), agent.name + '.log'),
            'loglevel':
            'DEBUG',
            'commHost':
            'localhost',
            'commPort':
            config.getConfig()['localInfo'].get('processAgentsCommPort',
                                                18809),
            'commGroup':
            None
        }, args)

    agent.docklist.add(dock)

    helpers.makeDir(os.path.dirname(agent.logfile))

    handler = logging.FileHandler(agent.logfile, 'w')
    handler.setFormatter(
        logging.Formatter(helpers.LOG_FORMAT_MSECS, helpers.LOG_DATEFMT))
    root = logging.getLogger()
    root.setLevel(helpers.logLevels.get(agent.loglevel.lower(), logging.INFO))
    root.handlers = []
    root.addHandler(handler)

    log.info('argv: %s', argv)
    log.info('agent attributes: %s', agent.__dict__)

    log.info("Setting up agent messaging interface")
    inTransport, outTransport = _getIOHandles(agent)
    agent.messenger = AgentMessenger(inTransport, outTransport, agent)
    agent.messenger.start()
    log.info("Agent messaging interface initialized and running")

    # Tell the daemon we want to listen on the dock.
    # GTL - why doesn't the Daemon just associate the dock
    # with this process?
    agent.messenger.listenDock(dock)

    if agent.commGroup:
        agent.messenger.joinGroup(agent.commGroup)
        #TODO: In ideal condition wait from the node to join group before proceeding further

    # now that we're connected, send an AgentLoaded message.
    agent.messenger.trigger(event='AgentLoadDone',
                            agent=agent.name,
                            nodes=[agent.hostname])

    return args
Exemple #4
0
                )
                log.info("Testing to see if one is present")

                createNodeConfig = False
                # Create a MAGI node configuration file if one is not present or needs to be recreated
                if options.force == True:
                    log.info(
                        "force flag set. Need to (re)create node configuration file."
                    )
                    createNodeConfig = True
                elif os.path.exists(config.getNodeConfFile()):
                    log.info(
                        "Found a node configuration file at %s. Using it.",
                        config.getNodeConfFile())
                    nodeConfig = config.loadNodeConfig(
                        nodeConfig=config.getNodeConfFile(),
                        experimentConfig=experimentConfig)
                else:
                    # Node configuration file does not exist
                    log.info(
                        "No valid node configuration file found at %s. Need to create one.",
                        config.getNodeConfFile())
                    createNodeConfig = True

                if createNodeConfig:
                    log.info("Creating a new node configuration file")
                    # Use the experiment configuration to create node specific configuration
                    nodeConfig = config.createNodeConfig(
                        experimentConfig=experimentConfig)

            else:
Exemple #5
0
    optparser.add_option("-f", "--logfile", dest="logfile", action='store', 
                         help="Log to specified file, ex: -f file.log")
    optparser.add_option("-l", "--loglevel", dest="loglevel", default="INFO", 
                         help="set logger to level ALL, DEBUG, INFO, " + 
                         "WARNING, ERROR. Default: %default, ex: -l DEBUG")
    optparser.add_option("-e", "--expconf", dest="expconf", 
                         help="Specify location of the experiment " +
                         "configuration file, ex: -c experiment.conf ")
    optparser.add_option("-c", "--nodeconf", dest="nodeconf", 
                         help="Specify location of the node " +
                         "configuration file, ex: -c localnode.conf ")

    (options, args) = optparser.parse_args()
    
    expConfig = config.loadExperimentConfig(options.expconf)
    nodeConfig = config.loadNodeConfig(options.nodeconf)
    
    #import once the system is cofigured
    from magi.daemon.daemon import Daemon

    if not options.logfile:
        options.logfile = os.path.join(config.getLogDir(), "daemon.log")
    
    helpers.makeDir(os.path.dirname(options.logfile))
    helpers.makeDir(config.getTempDir())
            
    # Roll over the old log and create a new one
    # Note here that we will have at most 5 logs 
    # Need to check existence of file before creating the handler instance
    # This is because handler creation creates the file if not existent 
    if os.path.isfile(options.logfile):
Exemple #6
0
                        log.info("Using experiment configuration file at %s", options.expconf)
                        experimentConfig = config.loadExperimentConfig(options.expconf, distributionPath=rpath, isDBEnabled=not options.nodataman)
                                                
                # create a MAGI node configuration file only if one is not explicitly specified 
                if not options.nodeconf:
                        log.info("MAGI node configuration file has not been provided as an input argument")
                        log.info("Testing to see if one is present")
                        
                        createNodeConfig = False 
                        # Create a MAGI node configuration file if one is not present or needs to be recreated 
                        if options.force == True:
                                log.info("force flag set. Need to (re)create node configuration file.")  
                                createNodeConfig  = True
                        elif os.path.exists(config.getNodeConfFile()):
                                log.info("Found a node configuration file at %s. Using it.", config.getNodeConfFile()) 
                                nodeConfig = config.loadNodeConfig(nodeConfig=config.getNodeConfFile(), experimentConfig=experimentConfig) 
                        else:
                                # Node configuration file does not exist
                                log.info("No valid node configuration file found at %s. Need to create one.", config.getNodeConfFile())
                                createNodeConfig = True 

                        if createNodeConfig: 
                                log.info("Creating a new node configuration file")
                                # Use the experiment configuration to create node specific configuration
                                nodeConfig = config.createNodeConfig(experimentConfig=experimentConfig) 
                
                else:
                        log.info("Using node configuration file at %s", options.nodeconf)
                        nodeConfig = config.loadNodeConfig(nodeConfig=options.nodeconf, experimentConfig=experimentConfig) 
                        
                helpers.makeDir(os.path.dirname(config.getNodeConfFile()))
Exemple #7
0
                         "WARNING, ERROR. Default: %default, ex: -l DEBUG")
    optparser.add_option("-e",
                         "--expconf",
                         dest="expconf",
                         help="Specify location of the experiment " +
                         "configuration file, ex: -c experiment.conf ")
    optparser.add_option("-c",
                         "--nodeconf",
                         dest="nodeconf",
                         help="Specify location of the node " +
                         "configuration file, ex: -c localnode.conf ")

    (options, args) = optparser.parse_args()

    expConfig = config.loadExperimentConfig(options.expconf)
    nodeConfig = config.loadNodeConfig(options.nodeconf)

    #import once the system is cofigured
    from magi.daemon.daemon import Daemon

    if not options.logfile:
        options.logfile = os.path.join(config.getLogDir(), "daemon.log")

    helpers.makeDir(os.path.dirname(options.logfile))
    helpers.makeDir(config.getTempDir())

    # Roll over the old log and create a new one
    # Note here that we will have at most 5 logs
    # Need to check existence of file before creating the handler instance
    # This is because handler creation creates the file if not existent
    if os.path.isfile(options.logfile):