from Resources import Resources
from Queries import Queries
from Node import Node
from DES import DES
from Overlay import Overlay
import Config

#r = Resources(Config.RESOURCE_FILE)
#print r.get_attribs()
#print r.get_attribs()
#print r.get_attribs()

#q = Queries(Config.QUERY_FILE)
#print q.get_query()
#print q.get_query()
#print q.get_query()

#n = Node(1, [])

#event_engine = DES()
#event_engine.add_event(2.0, 1, 23)
#event_engine.add_event(5.0, 1, 23)
#event_engine.add_event(3.0, 1, 23)
#event_engine.add_event(4.0, 1, 23)
#event_engine.add_event(7.0, 1, 23)
#event_engine.add_event(1.0, 1, 23)
#print event_engine.get_next_event()
#print event_engine.get_next_event()

#event_engine.remove_event(3.0, 1, 23)
#event_engine.remove_event(8.0, 1, 23)
#event_engine.remove_event(5.0, 1, 23)
#event_engine.remove_event(7.0, 1, 23)
#event_engine.remove_event(1.0, 1, 23)
#event_engine.remove_event(2.0, 1, 23)
#event_engine.remove_event(4.0, 1, 23)
#event_engine.remove_event(3.0, 1, 23)
#print event_engine.get_next_event()

node1 = Node(0, ['123455'])
node2 = Node(1, ['123455'])
node3 = Node(2, ['123455'])
print node1.advertise([['Location', 3], ['Latitude', 52.22], ['Longitude', 4.53], ['NodeType', 1], ['KernVer', 2], ['FCNamex', 1], ['CPUSpeed', 3.2001], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 1.9682], ['DiskSize', 221.347], ['BWLimit', 100000]])
print node2.advertise([['Location', 1], ['Latitude', 42.27], ['Longitude', -71.8], ['NodeType', 1], ['KernVer', 2], ['FCNamex', 1], ['CPUSpeed', 2.99488], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 0.985874], ['DiskSize', 175.483], ['BWLimit', 'none']])
print node3.advertise([['Location', 1], ['Latitude', 42.27], ['Longitude', -71.8], ['NodeType', 1], ['KernVer', 2], ['FCNamex', 1], ['CPUSpeed', 2.49374], ['NumCores', 8], ['CoresPerCPU', 4], ['MemSize', 3.21139], ['DiskSize', 662.04], ['BWLimit', 10000]])
#print node1.advertise([['Location', 3], ['Latitude', 52.22], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 1.9682111], ['DiskSize', 221.347198], ['BWLimit', 1000]])
#print node1.advertise([['Location', 2], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 1.9682111], ['DiskSize', 221.347199], ['BWLimit', 1000]])
#print node2.advertise([['Location', 1], ['Latitude', 42.27], ['Longitude', -71.8], ['NodeType', 1], ['KernVer', 2], ['FCNamex', 1], ['CPUSpeed', 2.99488], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 0.985874], ['DiskSize', 175.483], ['BWLimit', 'none']])
print node1.advertise([['Location', 3], ['Latitude', 52.22], ['Longitude', 4.53], ['NodeType', 1], ['KernVer', 2], ['FCNamex', 1], ['CPUSpeed', 3.2001], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 1.9682], ['DiskSize', 221.347], ['BWLimit', 100000]])
print node2.advertise([['Location', 1], ['Latitude', 42.27], ['Longitude', -71.8], ['NodeType', 1], ['KernVer', 2], ['FCNamex', 1], ['CPUSpeed', 2.99488], ['NumCores', 2], ['CoresPerCPU', 1], ['MemSize', 0.985874], ['DiskSize', 175.483], ['BWLimit', 'none']])
'''
node4 = Node(4, ['123455'])
print node4.advertise([['Location', 2], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 3], ['CoresPerCPU', 2], ['MemSize', 1.9682111], ['DiskFree', 21.347199], ['5minLoad', 12.1]])
print node4.advertise([['Location', 2], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 3], ['CoresPerCPU', 2], ['MemSize', 1.9682111], ['DiskFree', 21.347199], ['5minLoad', 14.2]])
print node4.advertise([['Location', 2], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 3], ['CoresPerCPU', 2], ['MemSize', 1.9682111], ['DiskFree', 21.347199], ['5minLoad', 11.0]])

print node2.query([['Location', 2], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 3], ['CoresPerCPU', 2], ['MemSize', 1.9682111]])
print node4.query([['Location', 2], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 1], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 3], ['CoresPerCPU', 2], ['MemSize', 1.9682111], ['DiskFree', 21.347199], ['5minLoad', 11.0]])
'''

#print node1.get_stat()
#print node2.get_stat()
#print node3.get_stat()
#print node4.get_stat()

#Test code for Overlay
key_list = [[123, 77, 97], [255, 12, 95], [64, 82, 80], [0, 189, 78], [199, 50, 171]]
ov = Overlay()
#ov = Overlay(key_list)
'''
print ov.ULS_hash(['RespTime', 0.0])
print ov.ULS_hash(['1minLoad', 100.0])
print ov.ULS_hash(['FreeCPU', 25.0])
print ov.ULS_hash(['RespTime', 50.0])

print ov.get_distance(1, 3)
print ov.get_distance(2, 3)
print ov.get_distance(3, 3)
print ov.get_distance(2, 0)

print ov.get_neighbor(0,1)
print ov.get_neighbor(2,2)
print ov.get_neighbor(2,1)
print ov.get_neighbor(3,0)
'''
'''
nodes = [Node(0, key_list[0]), Node(1, key_list[1]), Node(2, key_list[2]), Node(3, key_list[3]), Node(4, key_list[4])]
print ov.route_new_ads(0, [['CPUSpeed', 2.512], ['KernVer', 2]], nodes) 
print ov.route_new_ads(2, [['Latitude', -100.0], ['KernVer', 1]], nodes) 
print ov.route_new_ads(0, [['CPUSpeed', 2.12], ['KernVer', 2]], nodes) 
print ov.route_old_ads(0, [['CPUSpeed', 2.512]], nodes) 
print ov.route_new_ads(3, [['CPUSpeed', 2.12]], nodes) 
print ov.route_new_ads(2, [['Latitude', -100.0], ['KernVer', 1]], nodes) 
print ov.route_new_ads(4, [['Latitude', 0.0], ['KernVer', 2]], nodes) 
print '-----'
print ov.route_query(2, [['CPUSpeed', 2.0, 3.0], ['KernVer', 1, 1]], 1, nodes) 
print '-----'
print ov.route_query(3, [['CPUSpeed', 2.0, 3.0], ['KernVer', 2, 2]], 2, nodes) 
'''
