Beispiel #1
0
def example2():

    nodes_h = {}

    tcpconf = ('tcp', ('127.0.0.1', 1234))
    host = init_host(tcpconf)

    t1  = time()
    # Create and initialize nodes
    for i in range(100):
        nodes_h[i] = host.spawn_id(str(id()), 'chord_protocol', 'Node', [])
        nodes_h[i].init_node()

    for i in range(len(nodes_h)):
        j = 0 if i is 0 else i-1
        try:
            nodes_h[i].join(nodes_h[j])
        except:
            print 'Node %s fails' % str(i)
        else:
            interval_host(host, 0.5, update, nodes_h[i])

    t2 = time()
    print 'Time to create 100 nodes'
    print t2 - t1

    # Wait to give time to chord to fix its tables.
    # Note that if we use the class chord_improved we will need less time to fix the node tables.
    sleep(30)

    key = hash('pedro')
    print key
    found = nodes_h[0].find_predecessor(key)
    print found.get_id()
Beispiel #2
0
def example1():
    nodes = [1,8,14,21,32,38,42,48,51,56]
    nodes_h = {}

    tcpconf = ('tcp', ('127.0.0.1', 1234))
    host = init_host(tcpconf)

    # Create and initialize nodes
    for i in range(len(nodes)):
        nodes_h[i] = host.spawn_id(str(nodes[i]), 'chord_protocol', 'Node', [])
        nodes_h[i].init_node()

    for i in range(len(nodes)):
        j = 0 if i is 0 else i-1
        try:
            nodes_h[i].join(nodes_h[j])
        except:
            print 'Node %s fails' % str(i)
        else:
            interval_host(host, 0.5, update, nodes_h[i])

    # Wait to give time to chord to fix its tables.
    sleep(5)

    found = nodes_h[0].find_successor(40)
    print 'found', found.get_id()
Beispiel #3
0
def test():
    host = init_host()
    e1 = host.spawn_id('1', 'actor5c', 'Echo', [])
    bot = host.spawn_id('1', 'actor5c', 'Bot', [])
    bot.set_channel()
    bot.insult()
    sleep(4)
Beispiel #4
0
def testN():
    net_conf = ('tcp',('127.0.0.1',6664))
    host = init_host(net_conf)

    print 'TEST ',NUM_NODES,' nodes and', NUM_MSGS, "messages."

    nf  = host.spawn_id('init', 'ring3','Node',['nf'])

    ni = nf;
    for i in range (NUM_NODES-2):
        ni = host.spawn_id(str(i), 'ring3','Node',[('n',i),ni])

    n1 = host.spawn_id('end','ring3','Node',['n1',ni])

    nf.set_next(n1)
    print 'start time!!'
    init = time()

    nf.init_token()

    while(not n1.is_finished()):
        sleep(0.01)

    end = time()

    print ((end - init)*1000),' ms.'
Beispiel #5
0
def test_log():
    host = init_host()
    log = host.spawn_id('log', 'log', 'Log', [])
    host.set_tracer(log)
    ref = host.spawn_id('1', 'log', 'Server', [])
    ref.substract(6, 5)
    print ref.add(5, 5)
    sleep(1)
def serve_forever(func, params=[]):
    threads[current_thread()] = 'atom://localhost/'+func.__module__+'/'+func.__name__
    func(*params)

    signal.signal(signal.SIGINT, signal_handler)
    print 'Press Ctrl+C to kill the execution'
    while True:
        controller.sleep(1)
def launch(func, params=[]):
    t1 = Thread(target=func, args=params)
    threads[t1] = 'atom://localhost/'+func.__module__+'/'+func.__name__
    t1.start()
    t1.join()
    controller.sleep(2)
    host =  controller.get_host()
    host._shutdown()
Beispiel #8
0
def test_log():
    host = init_host()
    log = host.spawn_id('log', 'log','Log',[])
    host.set_tracer(log)
    ref = host.spawn_id('1','log','Server',[])
    ref.substract(6,5)
    print ref.add(5,5)
    sleep(1)
Beispiel #9
0
def test1(test):
    n2 = test.host.spawn_id('0', 'ring', 'Node', ['n2'])
    n1 = test.host.spawn_id('1', 'ring', 'Node', ['n1', n2])
    n3 = test.host.spawn_id('2', 'ring', 'Node', ['n3', n2])
    n1.start()
    n3.start()
    sleep(0.5)
    cnt = n2.get_cnt()
    test.assertEqual(cnt, 200, "testing load oneway")
def test1():
    host = init_host()
    n2 = host.spawn_id('2','test_sync_parallel','Server',[])
    n1 = host.spawn_id('3','test_sync_parallel','Server',[n2]) 
    n3 = host.spawn_id('4','test_sync_parallel','Server',[n2]) 
    n1.start()
    sleep(1)
    n3.start2()
    sleep(15)   
Beispiel #11
0
def test1(test):
    n2  = test.host.spawn_id('0','ring','Node',['n2'])
    n1 = test.host.spawn_id('1','ring','Node',['n1',n2]) 
    n3 = test.host.spawn_id('2','ring','Node',['n3',n2]) 
    n1.start()     
    n3.start()
    sleep(0.5)
    cnt = n2.get_cnt()
    test.assertEqual(cnt, 200, "testing load oneway") 
Beispiel #12
0
def test1():
    host = init_host()
    n2 = host.spawn_id('2','parallel1','Node',['n2'])
    n1 = host.spawn_id('1','parallel1','Node',['n1',n2]) 
    n3 = host.spawn_id('3','parallel1','Node',['n3',n1]) 
    n1.start()
    sleep(2)
    n3.start_n3()
    sleep(15)   
Beispiel #13
0
def test():
    host = init_host()

    e1 = host.spawn_id('1', 'actor4', 'Echo', [])
    bot = host.spawn_id('1', 'actor4', 'Bot', [e1])

    bot.insult()

    sleep(4)
Beispiel #14
0
def client_test():

    tcpconf = ('tcp',('127.0.0.1',4324))
    host = init_host(tcpconf)
    e1 = host.lookup('tcp://127.0.0.1:1237/actor2/Echo/1')


    e1.echo('hola amigo')

    e1.echo('adeu')

    sleep(1)
Beispiel #15
0
def test1(test):
    n3 = test.host.spawn_id('0', 'ring2', 'Node', ['n3'])
    n2 = test.host.spawn_id('1', 'ring2', 'Node', ['n2', n3])
    n1 = test.host.spawn_id('2', 'ring2', 'Node', ['n1', n2])

    n3.set_next(n1)

    n1.init_token()
    sleep(0.5)
    cnt = n3.get_cnt()

    test.assertEqual(cnt, 1, "testing message loop")
Beispiel #16
0
def test1(test):
    n3  = test.host.spawn_id('0','ring2','Node',['n3'])
    n2 = test.host.spawn_id('1','ring2','Node',['n2',n3]) 
    n1 = test.host.spawn_id('2','ring2','Node',['n1',n2]) 
    
    
    n3.set_next(n1)  
      
    n1.init_token()
    sleep(0.5)
    cnt = n3.get_cnt()
    
    test.assertEqual(cnt, 1, "testing message loop") 
Beispiel #17
0
	def push_data(self,inf,index,on,cont,lamport,index_server):
		
		
		if(self.id==1):			# delay de 1 segon al server 1
			sleep(1)
			
			
		print 'Informacio streetlight ' + str(index+1) +': ' + str(inf) # feedback
		self.opcio=3
		
		self.inf[index]=inf
		self.cont[index]=cont
		
		if (int(self.inf[index])==1):	# si tenim un "1" posa contador a 0
			self.cont[index]=0
			
			
			if (on==False):				# si teniem Streetlight tancat, obre
				self.opcio=1
				
		else:
			self.cont[index]=self.cont[index]+1		# si tenim un "0" augmenta contador
			
			if (self.cont[index]==4):	# si tenim 4 "0"
				if(on==True):			# si el Streetlight esta obert, tanca
					self.opcio=0
					self.cont[index]=0
		
		
		
		
		for i in self.database:	
			if(i.vote(lamport,index)==True):		# contem quantes databases estan a favor del commit
				self.cont_commit+=1
		
			
				
		if (self.cont_commit==len(self.database)):	# mirem si totes les database estan a favor
			self.cont_commit=0
			#print "commit"
			for i in self.database:
				i.commit(lamport,index)				# indiquem a les databases que el commit es realitzara i que actualitzin el seu lamport clock
			print "Lamport "+str(lamport)+" de Streetlight "+str(index+1)+" commited"
			self.queue.switch(self.opcio,index,self.cont[index])				# canviem estat segons opcio
			
		else:
			print "Lamport "+str(lamport)+ " Streetlight "+str(index+1)+ " aborted"
			for i in self.database:
				i.abort(lamport)					# indica a les databases que el commit no es realitzara
			sleep(1)	
			self.queue.send(self.inf[index],index,on,cont,lamport)	# reenvia dada a la cua
Beispiel #18
0
def test_2pc_bad():
    host = init_host()
    coord = host.spawn_id('5','2pc_multi','Coordinator',[])

    cohort1 = host.spawn_id('1','2pc_multi','GoodCohort',[coord])
    cohort2 = host.spawn_id('2','2pc_multi','BadCohort',[coord])
    cohort3 = host.spawn_id('3','2pc_multi','GoodCohort',[coord])
    cohort4 = host.spawn_id('4','2pc_multi','BadCohort',[coord])

    coord.set_cohorts([cohort1, cohort2, cohort3, cohort4])

    coord.commit()

    sleep(1)
Beispiel #19
0
def test():
    host = init_host()

    f1 = host.spawn_id('1', 'actor9', 'File', [])
    web = host.spawn_id('1', 'actor9', 'Web', [])
    web.remote_server(f1)
    load = host.spawn_id('1', 'actor9', 'Workload', [])
    load.remote_server(web)
    load2 = host.spawn_id('2', 'actor9', 'Workload', [])
    load2.remote_server(web)
    load.launch()
    load2.download()


    sleep(10)
Beispiel #20
0
def test():
    host = init_host()

    # parameters 1 = 'id', 'test_sync' = module name, 'Server' = class name
    f1 = host.spawn_id('1', 'actor8', 'File', [])
    web = host.spawn_id('1', 'actor8', 'Web', [])
    web.remote_server(f1)
    load = host.spawn_id('1', 'actor8', 'Workload', [])
    load.remote_server(web)
    load2 = host.spawn_id('2', 'actor8', 'Workload', [])
    load2.remote_server(web)
    load.launch()
    load2.download()


    sleep(10)
Beispiel #21
0
def test_2pc():
    host = init_host()
    #log = host.spawn('loguml','LogUML',[])
    #host.set_tracer(log)
    coord = host.spawn_id('5', '2pc_multi','Coordinator',[])

    cohort1 = host.spawn_id('1', '2pc_multi','GoodCohort',[coord])
    cohort2 = host.spawn_id('2', '2pc_multi','GoodCohort',[coord])
    cohort3 = host.spawn_id('3', '2pc_multi','GoodCohort',[coord])
    cohort4 = host.spawn_id('4', '2pc_multi','GoodCohort',[coord])

    coord.set_cohorts([cohort1, cohort2, cohort3, cohort4])

    coord.commit()
    print 'hola que tal!'
    sleep(1)
Beispiel #22
0
def test3():
    host = init_host(('tcp', ('127.0.0.1', 4346)))
    aref = 'tcp://127.0.0.1:1234/s1/Server/0'
    ref = host.lookup(aref)
    ref.substract(34, 2)
    ref.add(6, 8)
    for i in range(3):
        s = ref.add(56, 4)
        print s, 'ok'
    sleep(1)
    try:
        ref.wait_a_lot()
    except TimeoutError:
        print 'correct timeout'

    sleep(3)
    host.shutdown()
Beispiel #23
0
def testN(test):
    
    nf  = test.host.spawn_id('3','ring2','Node',['nf'])
    
    ni = nf;
    for i in range (10):    
        ni = test.host.spawn_id(str(i + 4),'ring2','Node',[('n',i+4),ni]) 
    
    n1 = test.host.spawn_id('16','ring2','Node',['n1',ni]) 
        
    nf.set_next(n1)  
      
    n1.init_token()
    sleep(0.5)
    cnt = nf.get_cnt()
    
    test.assertEqual(cnt, 1, "testing message loop")     
Beispiel #24
0
def testN(test):

    nf = test.host.spawn_id('3', 'ring2', 'Node', ['nf'])

    ni = nf
    for i in range(10):
        ni = test.host.spawn_id(str(i + 4), 'ring2', 'Node',
                                [('n', i + 4), ni])

    n1 = test.host.spawn_id('16', 'ring2', 'Node', ['n1', ni])

    nf.set_next(n1)

    n1.init_token()
    sleep(0.5)
    cnt = nf.get_cnt()

    test.assertEqual(cnt, 1, "testing message loop")
Beispiel #25
0
def test3():
    host = init_host(('tcp',('127.0.0.1',4346)))
    aref = 'tcp://127.0.0.1:1234/s1/Server/0'
    ref = host.lookup(aref)
    ref.substract(34,2)
    ref.add(6,8)
    for i in range(3):
        s = ref.add(56,4)
        print s,'ok'
    sleep(1)
    try:
        ref.wait_a_lot()
    except TimeoutError:
        print 'correct timeout'
    
    
    sleep(3)
    host.shutdown()
Beispiel #26
0
def test():
    lP = []
    lA = []
    lL = []
    host = init_host()
    log = host.spawn_id('log', 'mpaxos_main', 'LogUML', [])
    host.set_tracer(log)
    interval(1, save_log, log)
    for i in range(0, N_SERVERS):
        l = host.spawn_id(str(i), 'multi_paxos', 'Server',[N_SERVERS])
        lL.append(l)
    for i in range(0, N_SERVERS):
        if i == 0:
            lL[i].set_multi(lL[1:])
        else:
            lL[i].set_multi(lL[:i] + lL[i+1:])
        
        interval(2, update, lL[i])       

    lL[N_SERVERS - 1].set_leader()         
    for i in range(0,N_SERVERS):        
        num = int(random.random() * 100)
        print i, num
        lL[i].set_proposal(num)
    
    print lL[N_SERVERS - 1].set_proposal(int(random.random() * 100))
    print lL[N_SERVERS - 1].set_proposal(int(random.random() * 100))
    print lL[N_SERVERS - 1].set_proposal(int(random.random() * 100))
    print lL[N_SERVERS - 1].set_proposal(int(random.random() * 100))    
#    lP[0].set_multi([lA[0], lA[1],lA[2]])
#    lP[1].set_multi([lA[2], lA[3],lA[4]])
#    lP[2].set_multi([lA[0], lA[1],lA[2]])
#    lP[3].set_multi([lA[2], lA[3],lA[4]])
#     p = AMulti(lP)
#     p.prepare()
    
    print lL[0].prepare()
    print lL[1].prepare()
    print lL[2].prepare()
    print lL[N_SERVERS - 1].prepare()
    sleep(5)
    lL[N_SERVERS - 1].set_proposal(num) 
    print lL[N_SERVERS - 1].prepare()
Beispiel #27
0
def test_2pc_bad():
    host = init_host()
    coord = host.spawn('2pc_multi','Coordinator',[])
    
    cohort1 = host.spawn('2pc_multi','GoodCohort',[coord,'1'])
    cohort2 = host.spawn('2pc_multi','BadCohort',[coord,'2'])
    cohort3 = host.spawn('2pc_multi','GoodCohort',[coord,'3'])
    cohort4 = host.spawn('2pc_multi','BadCohort',[coord,'4'])
    group  = host.spawn_id('2pc_bad','atom.multi','Multi',[])
    #print group.aref,group.members()
    group.join(cohort1)
    group.join(cohort2)
    group.join(cohort3)
   
    
    coord.set_cohort(group.join(cohort4))
     
    coord.commit()
    
    sleep(0.5)
Beispiel #28
0
def test_2pc():
    host = init_host()
    #log = host.spawn('loguml','LogUML',[])
    #host.set_tracer(log)
    coord = host.spawn_id('5', '2pc_multi','Coordinator',[])
     
    cohort1 = host.spawn_id('1', '2pc_multi','GoodCohort',[coord,'1'])
    cohort2 = host.spawn_id('2', '2pc_multi','GoodCohort',[coord,'2'])
    cohort3 = host.spawn_id('3', '2pc_multi','GoodCohort',[coord,'3'])
    cohort4 = host.spawn_id('4', '2pc_multi','GoodCohort',[coord,'4'])
#    group  = host.new_group('6')
    #es queda pillat al join! mirar el enviament de missatges
#    group.join(cohort1)
#    group.join(cohort2)
#    group.join(cohort3)
#    pepito = group.join(cohort4)
#    print 'pepitooooo', pepito
    coord.set_cohort(cohort4)
    
    coord.commit()
    sleep(0.5)
Beispiel #29
0
def start_node():            
    nodes_h = {}
    num_nodes = 5
    cont = 1
    retry = 0
    index=0
#    tcpconf = ('tcp', ('127.0.0.1', 1234))
#    host = init_host(tcpconf)
    momconf = ('mom',{'name':'s1','ip':'127.0.0.1','port':61613,'namespace':'/topic/test'})
    host = init_host(momconf)

    log = host.spawn_id('log','chord_log','LogUML',[])
    host.set_tracer(log)
#    print log
    for i in range(num_nodes):
        nodes_h[i] = host.spawn_id(str(cont), 'chord_protocol', 'Node', [])
        cont += 1
    for i in range(num_nodes):    
        nodes_h[i].init_node()
    
    while index < num_nodes:
        try:
            if(nodes_h[index].join(nodes_h[0])):
                print "True"
            interval(5, update, nodes_h[index])
            index += 1
            retry = 0
            sleep(0.2)
        except TimeoutError:
            retry += 1
            if retry > 3:
                index += 1
    interval(200, show, nodes_h[0])
    interval(200, show, nodes_h[num_nodes/2])
    interval(200, show, nodes_h[num_nodes - 1])
    interval(15, save_log, log)
Beispiel #30
0
def test1():
    host = init_host()
    n2 = host.spawn_id('2','lock_test','Node',['n2'])
    sleep(2)
    n1 = host.spawn_id('1','lock_test','Node',['n1']) 
    n1.registry_object(n2)
    n3 = host.spawn_id('3','lock_test','Node',['n3']) 
    n3.registry_object(n1)

    n1.start()
    n3.start_n3()
    sleep(15)
    result =  n1.start2() 
    print 'response_start2', result
    sleep(20)
Beispiel #31
0
 def throw_timeout(self):
     sleep(3)
     return 'timeout test'
Beispiel #32
0
 def wait_a_lot(self):
     sleep(2)
     return 'ok'
Beispiel #33
0
 def tearDownModule(self):
     sleep(0.2)
Beispiel #34
0
 def wait_a_lot(self):
     sleep(2)
     return 'ok'
Beispiel #35
0
 def tearDownModule(self):
     sleep(0.2)
Beispiel #36
0
 def return_msg(self):
     sleep(10)
     return 'Hello World'
Beispiel #37
0
def test():
	
	
	
	
	
	host=init_host()
	sensor=host.spawn_id('1','SD_Task2_A','Sensor',[])
	sl1=host.spawn_id('1','SD_Task2_A','Streetlight',[])
	sl2=host.spawn_id('2','SD_Task2_A','Streetlight',[])
	sl3=host.spawn_id('3','SD_Task2_A','Streetlight',[])
	q= host.spawn_id('1','SD_Task2_A','Queue',[])

	
	l=host.spawn_id('1','SD_Task2_A','Write_file',[])


	sensor.subscribe(sl1)	# connectem clients al sensor
	sensor.subscribe(sl2)
	sensor.subscribe(sl3)
	
	sl1.set_log(l)		# connectem clients amb classe per escriure a arxiu
	sl2.set_log(l)		# connectem clients amb classe per escriure a arxiu
	sl3.set_log(l)		# connectem clients amb classe per escriure a arxiu
	
	
	sl1.set_queue(q,0)		# connectem clients amb cua
	sl2.set_queue(q,1)
	sl3.set_queue(q,2)
	
	q.connect_queue(sl1)	# connectem cua amb clients
	q.connect_queue(sl2)
	q.connect_queue(sl3)
	
	
	s1=host.spawn_id('1','SD_Task2_A','Server',[])
	s2=host.spawn_id('2','SD_Task2_A','Server',[])
	
	
	db1=host.spawn_id('1','SD_Task2_A','Database',[])
	db2=host.spawn_id('2','SD_Task2_A','Database',[])
	db3=host.spawn_id('3','SD_Task2_A','Database',[])
	s1.connect_database(db1)		# connectem servidors amb database
	s1.connect_database(db2)
	s1.connect_database(db3)
	
	s1.set_queue_server(q)			# connectem servidors amb cua
	q.add_server(s1)				# connectem cua amb servidors
	

	
	sensor.start('arxiu.txt')

	sensor.start_interval()

	sleep(27)			# esperar a tenir tots els valors
	sl1.log()
	sleep(1)
	sl2.log()
	sleep(1)
	sl3.log()
	sleep(1)

	l.write()