Example #1
0
def verifyDataMovement(entranceNode, dest, data, sock, msgQ, dataId=None):
    
    if dataId == None:
        dataId = MsgFactory.generateMessageId(data)
        moveData(entranceNode, dest, data, dataId, sock, MsgType.DATA_MSG)
    elif dataId != None:
        moveData(entranceNode, dest, data, dataId, sock, MsgType.DATA_MOVE_MSG)
    
    while True:
        try:
            while msgQ.empty() == False:
                msg = msgQ.get(False)
                assert len(msg) == 2
                msgIn = cPickle.loads(msg[1])
                if msgIn[MsgType.TYPE] == MsgType.DATA_ACK and \
                    msg[0] == dest and msgIn[MsgType.DATA_ID] == dataId:
                    msgQ.task_done()
                    print "Message with id", dataId, " arrived to dest", dest
                    return
                if msgIn[MsgType.TYPE] == MsgType.DATA_NACK \
                     and msgIn[MsgType.DATA_ID] == dataId:
                    msgQ.task_done()
                    print "Message with id", dataId, " was not in the dest", msg[0]
                    return 
        except Empty:
            continue
Example #2
0
def playScenario(scenarioFile, peerSock, inQueue, outQueue, sinkServer):           
    
    hungryNodes = []
    counter = 1
    scenario = buildScenario(scenarioFile)
    logging.basicConfig(level=logging.INFO, filename=LOGFILE)
    initiateGraph(scenario)
    
    drawGraph(graphNetXLast, "graphProgress/graph_stepL_000.png", "step000")
    
    for cmd in scenario:
    
        try:
            updateAck = inQueue.get(True, timeout=1)
            inQueue.task_done()
            node, statusAck = verifyOperation(updateAck, hungryNodes, counter)
            counter+=1
            
            print 'Sending ACK back to the ', node            
            outQueue.put([node, statusAck])
                  
        except Empty:
            pass
        
        if cmd['ACTION'] == 'sleep':
            print 'Waiting for ', cmd['ARG']
            sleep(int(cmd['ARG']))
            
        elif cmd['ACTION'] == 'set':
            dataItem = str(choice(xrange(1000)))
            dataId = MsgFactory.generateMessageId(dataItem)
            txMsg = MsgFactory.create(MsgType.PR_SETUP, 
                                      dst=cmd['ARG'], 
                                      data=dataItem,
                                       dataId=dataId)
            print 'Setting object', dataItem, 'to node:', cmd['ARG']
            peerSock.send_multipart(['Set', txMsg])
            
        elif cmd['ACTION'] == 'reset':
            print 'Reseting nodes'
            peerSock.send_string('Reset')
            
        elif cmd['ACTION'] == 'hungry':
            hungryNodes.append(cmd['ARG'])
            print 'Set Hungry node ', cmd['ARG']
            txMsg = MsgFactory.create(MsgType.PR_GET_HUNGRY, dst=cmd['ARG'])
            peerSock.send_multipart([cmd['ARG'], txMsg])
        
        elif cmd['ACTION'] == 'exit':
            print 'Exiting'
            print 'Creating videos'
            #createVideo()
            peerSock.send_string('Exit')
            
            inQueue.join()
            outQueue.join()
            sinkServer.join()
            for n in NodeProcesses:
                print n, n.is_alive()
                n.join()
                n.terminate()
            system("killall -9 python")