from Resources import Resources
from Queries import Queries
from BaseNode import BaseNode
from DES import DES

print 'Reading Resources'
r = Resources()
print r.get_attribs()
print r.get_attribs()
print r.get_attribs()
print 'Reading Resources --- OK'

print 'Reading queries'
q = Queries()
print q.get_query()
print q.get_query()
print q.get_query()
print 'Reading queries --- OK'

print 'Testing Discrete Event Engine'
event_engine = DES()
event_engine.add_event(2.0, 1, 23, [], False)
event_engine.add_event(5.0, 1, 23, [], False)
event_engine.add_event(3.0, 1, 23, [], False)
event_engine.add_event(4.0, 1, 23, [], False)
event_engine.add_event(7.0, 1, 23, [], False)
event_engine.add_event(1.0, 1, 23, [], False)
print event_engine.get_next_event()
print event_engine.get_next_event()

event_engine.remove_event(7.0, 1, 23)
print event_engine.get_next_event()
print 'Testing Discrete Event Engine --- OK'

print 'Creating 5 nodes'
n1 = BaseNode(0, ['12323455'], 0)
n2 = BaseNode(1, ['123453455'], 0)
n3 = BaseNode(2, ['123445454555'], 0)
n4 = BaseNode(2, ['1234234324432455'], 0)
n5 = BaseNode(2, ['12342342342342343243455'], 0)
print 'Creating 5 nodes --- OK'

print 'Advertising'
print 'Adding for 1st time'
print n1.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]], True, False)
print n2.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']], True, False)
print n3.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]], True, False )
print n4.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]], True, False)
print 'Adding for 2nd time'
print n1.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], ['DiskSize', 221.347198], ['BWLimit', 1000]], True, False)
print n1.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], ['DiskSize', 221.347199], ['BWLimit', 1000]], True, False)
print n4.advertise([['Location', 1], ['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]], True, False)
print n4.advertise([['Location', 1], ['Latitude', 52.21], ['Longitude', 4.23], ['NodeType', 2], ['KernVer', 2], ['FCNamex', 4], ['CPUSpeed', 3.20011], ['NumCores', 8], ['CoresPerCPU', 4], ['MemSize', 1.9682111], ['DiskFree', 21.347199], ['5minLoad', 14.2]], True, False)
print 'Asking for all attribs'
print n4.advertise([['Location', 1], ['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]], True, True)
print 'Advertising --- OK'
print n2.query([['Location', 2, 2], ['Latitude', 52.21, 59.01], ['Longitude', 4.23, 5.234], ['NodeType', 2, 2], ['KernVer', 1, 1], ['CPUSpeed', 3.20011, 5.2311], ['NumCores', 2, 4], ['CoresPerCPU', 2, 2], ['MemSize', 1.9682111, 2.5]])
print n1.query([['NodeType', 2, 2], ['KernVer', 1, 1]])
print n4.query([['Location', 2, 2], ['Latitude', 52.21, 59.01], ['MemSize', 1.9682111, 2.5]])

print n1.get_stat()
print n2.get_stat()
print n3.get_stat()
print n4.get_stat()
