Commit b2d545d3 authored by Caughlin Bohn's avatar Caughlin Bohn
Browse files

Starts of HPC and HTC Script

parent 805b7b7d
import time
from random import randint
import socket
workers = {
"worker1": {"status":0,"time":0},
"worker2": {"status":0,"time":0},
"worker3": {"status":0,"time":0},
"worker4": {"status":0,"time":0},
"worker5": {"status":0,"time":0},
"worker6": {"status":0,"time":0},
"worker7": {"status":0,"time":0},
"worker8": {"status":0,"time":0}
}
### Format = from,To,Amount
def sendLights(command):
HOST = '192.168.1.6' # Symbolic name meaning all available interfaces
PORT = 50007
command += " %f" % time.time()
for i in range(1,9):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall(command)
s.close()
def writeWeb(data):
payload = "{\"worker1\":%s,\"worker2\":%s,\"worker3\":%s,\"worker4\":%s,\"worker5\":%s,\"worker6\":%s,\"worker7\":%s,\"worker8\":%s}" % (data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])
f =open("/var/www/html/control/index.html",'w')
f.write(payload)
f.close()
def workersToData(workers):
data = []
for k,v in workers.iteritems():
data.append(v["status"])
writeWeb(data)
start = time.time()
print("Starting")
sendLights("head worker1 5") ### Send data to master
time.sleep(5)
workers["worker1"]["status"] = 1 ### Turn on master
workersToData(workers)
time.sleep(1)
print("Master On")
for i in range(2,9): ### Send master to slave data
currentWorker = "worker"+str(i)
print(currentWorker)
sendLights("worker1 %s 2" % currentWorker)
time.sleep(1)
for i in range(2,9): ### Turn slave nodes on
currentWorker = "worker"+str(i)
print(currentWorker)
workers[currentWorker]["status"] = 1
workersToData(workers)
print("Slaves on and working")
for i in range(1,100):
currentWorker = "worker"+str(randint(1,8))
sendLights("%s %s 1" % ("worker"+str(randint(2,8)),"worker"+str(randint(2,8))))
for i in range(2,9): ### Send data back
currentWorker = "worker"+str(i)
print(currentWorker)
sendLights("%s worker1 2" % currentWorker)
for i in range(2,9): ### Turn slave nodes ooff
currentWorker = "worker"+str(i)
print(currentWorker)
workers[currentWorker]["status"] = 0
workersToData(workers)
print("Doning")
time.sleep(6)
sendLights("worker1 head 10") ### Send data to head
workers["worker1"]["status"] = 0 ### Turn off master
workersToData(workers)
workers = {
"worker1": {"status":0,"time":0},
"worker2": {"status":0,"time":0},
"worker3": {"status":0,"time":0},
"worker4": {"status":0,"time":0},
"worker5": {"status":0,"time":0},
"worker6": {"status":0,"time":0},
"worker7": {"status":0,"time":0},
"worker8": {"status":0,"time":0}
}
workersToData(workers)
import time
import socket
from random import randint
workers = {
"worker1": {"status":0,"time":0},
"worker2": {"status":0,"time":0},
"worker3": {"status":0,"time":0},
"worker4": {"status":0,"time":0},
"worker5": {"status":0,"time":0},
"worker6": {"status":0,"time":0},
"worker7": {"status":0,"time":0},
"worker8": {"status":0,"time":0}
}
### Format = from,To,Amount
def sendLights(command):
HOST = '192.168.1.6' # Symbolic name meaning all available interfaces
PORT = 50007
command += " %f" % time.time()
for i in range(1,9):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall(command)
s.close()
def writeWeb(data):
payload = "{\"worker1\":%s,\"worker2\":%s,\"worker3\":%s,\"worker4\":%s,\"worker5\":%s,\"worker6\":%s,\"worker7\":%s,\"worker8\":%s}" % (data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])
f =open("/var/www/html/control/index.html",'w')
f.write(payload)
f.close()
def workersToData(workers):
data = []
for k,v in workers.iteritems():
data.append(v["status"])
writeWeb(data)
start = time.time()
while (time.time() - start) < 45:
currentWorker = "worker"+str(randint(1,8))
if workers[currentWorker]["status"] == 0: ### If the worker is not active, turn it on and send data to it from head
sendLights("head %s 1" % currentWorker)
workers[currentWorker]["status"] = 1
workers[currentWorker]["time"] = int(time.time())
if workers[currentWorker]["status"] == 1:
if (time.time() - workers[currentWorker]["time"]) > 5:
sendLights("%s head 1" % currentWorker)
workers[currentWorker]["status"] = 0
workersToData(workers)
time.sleep(1)
print(workers)
workers = {
"worker1": {"status":0,"time":0},
"worker2": {"status":0,"time":0},
"worker3": {"status":0,"time":0},
"worker4": {"status":0,"time":0},
"worker5": {"status":0,"time":0},
"worker6": {"status":0,"time":0},
"worker7": {"status":0,"time":0},
"worker8": {"status":0,"time":0}
}
workersToData(workers)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment