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

Initial Adding of the Basics

parents
## DisplayNode Scripts and Magic
ALL SCRIPTS USING THE NEOPIXEL LIBRARY NEED ROOT PERMISSIONS TO RUN
WorkerNode.py args - > [startNode, endNode, numberOfIterations]
Neopixel/WS2811x Repo:
https://github.com/jgarff/rpi_ws281x
python-dev, scons, and swig will be needed from apt. Run scons from the root of the repo.
import time
import sys
from neopixel import *
import argparse
from random import randint
# LED strip configuration:
LED_COUNT = 100 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
#LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10 # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()
NetPath ={
'A': ['C'],
'B': ['B'],
'C': ['A','B','D'],
'D': ['E','G','C'],
'E': ['D','M','N','F'],
'F': ['E','O','P'],
'G': ['D','L','K','H'],
'H': ['G','I','J'],
'I': ['H'],
'J': ['H'],
'K': ['G'],
'L': ['G'],
'M': ['E'],
'N': ['E'],
'O': ['F'],
'P': ['F']
}
NodePath = {"head": 'A',
"file": 'B',
"worker1": 'O',
"worker2": 'P',
"worker3": 'M',
"worker4": 'N',
"worker5": 'L',
"worker6": 'K',
"worker7": 'I',
"worker8": 'J'
}
NetLights ={
'AC' :[0,1,2,3,4,5,6,7,8,9,10,11,12],
'BC' : [19,18,17,16,15,14,13,12],
'CA' : [12,11,10,9,8,7,6,5,4,3,2,1,0],
'CB' : [12,13,14,15,16,17,18,19],
'CD' : [22,23,24,25,26,27,28,29,30],
'DC' : [30,29,28,2,7,26,25,24,23,22],
'DE' : [31,50,51],
'ED' : [51,50,31],
'DG' : [31,32,33],
'GD' :[33,32,31],
'EM' :[52,53,54],
'ME' :[54,53,52],
'EN' :[52,55,56],
'NE' :[56,55,52],
'EF' : [57,58,59,60],
'FE' : [60,59,58,57],
'FO' :[61,62,63],
'OF' :[63,62,61],
'PF' :[65,64,61],
'FP' :[61,64,65],
'GH' : [39,40,41,42],
'HG' :[42,41,40,39],
'LG' :[36,35,24],
'GL' :[24,35,36],
'GK' :[34,37,38],
'KG' :[38,37,34],
'HI' :[43,44,45],
'IH' :[45,44,43],
'HJ' :[43,46,47],
'JH' :[47,46,43]
}
def find_path(graph, start, end, path=[]):
if '81' in start or '81' in end:
print("TEMPEST DETECTED")
return None
path = path + [start]
if end == "192.168.1.1":
end = "HeadRev"
if end == "192.168.1.5":
end = "FileRev"
if start == end:
return path
if not graph.has_key(start):
return None
for node in graph[start]:
if node not in path:
newpath = find_path(graph, node, end, path)
if newpath: return newpath
return None
print("starting")
import random
iter = 0
while iter < int(sys.argv[3]):
start = NodePath[sys.argv[1]]
end = NodePath[sys.argv[2]]
### To do random
start_path = find_path(NetPath,start,end)
path = []
try:
for i in range(0,len(start_path)-1):
path.append(start_path[i]+start_path[i+1])
except:
print("empty path")
try:
for a in path:
data = 128
for i in NetLights.get(a):
strip.setPixelColor(i,Color(255,128,255))
strip.show()
time.sleep(0.01)
for i in range(0,100):
strip.setPixelColor(i, Color(0,0,0))
strip.show()
time.sleep(0.05)
iter += 1
except Exception as e:
print(str(e))
x=0
print("ERROR")
## Head Node Specific Items
In order to provide a pretty user interface for the project, `Web` has the scripts for controlling and submitting items to the workers. It is used in conjunction with scripts in the Workers folder.
\ No newline at end of file
<html>
<?php
$lightType = $_POST["category"];
$command = $_POST["command"];
$rVal = (int)$_POST["redValue"];
$gVal = (int)$_POST["greenValue"];
$bVal = (int)$_POST["blueValue"];
$rgbVal = dechex($rVal)."-".dechex($gVal)."-".dechex($bVal);
//echo $lightType.$command.$rgbVal;
$cookie_name = "lights";
$cookie_value = $lightType."-".$command."-".$rgbVal;
setcookie($cookie_name, $cookie_value, time() + (86400 * 1), "/");
?>
<body>
LightType: "<?php echo $lightType; ?>"<br>
Command: "<?php echo $command; ?>"<br>
HexRGB: "<?php echo $rgbVal; ?>"<br>
Cookie Value: "<?php echo $lightType."-".$command."-".$rgbVal;?>"
</body>
<script type"text/javascript">
window.location.replace("setLED.php");
</script>
</html>
* {
margin: 0;
padding: 0;
}
#header {
min-height: 64px;
background: #CC0000;
font-family: 'Tungsten A','Tungsten B', Arial, sans-serif;
font-size: 22px;
}
#logo {
margin-left: 6px;
width: 73px;
height: 64px;
display: inline;
float: left;
background: url("Nebraska_N_rev.png") no-repeat;
background-size: 73px 64px;
}
#title {
margin-right: 30px;
height: 64px;
display: inline;
float: right;
line-height: 64px;
font-family: "Tungsten A","Tungsten B",HelveticaNeueCondensed,HelveticaNeue-Condensed,"Helvetica Neue Condensed",HelveticaNeueRomanCondensed,HelveticaNeue-Roman-Condensed,"Helvetica Neue Roman Condensed","Arial Narrow",HelveticaNeue,"Helvetica Neue",HelveticaNeueRoman,HelveticaNeue-Roman,"Helvetica Neue Roman",Helvetica,Tahoma,Geneva,Arial,sans-serif;
font-style: normal;
font-weight: 400;
font-size: 1.4375rem;
text-transform: uppercase;
color: #FFFFFF;
}
#main {
width: 960px;
min-height: 200px;
padding-bottom: 50px;
margin-left: auto;
margin-right: auto;
}
#sep {
width: 100%;
height: 32px;
display: block;
box-shadow: 0 41px 0 rgba(93, 78, 34, 0.04) inset;
}
#topic {
margin-top: 30px;
margin-bottom: 50px;
margin-left: auto;
margin-right: auto;
border-bottom: 1px solid #CCC;
width: 780px;
position: relative;
}
#message {
width: 500px;
position: relative;
margin-left: auto;
margin-right: auto;
margin-bottom: 40px;
}
#loginbox {
border: thin #CCCCCC solid;
border-radius: 5px;
padding: 5px;
font-size: 18px;
}
#username_input, #password_input{
font-size: 18px;
}
footer {
text-align: center;
}
body {
font-family: "Mercury SSm A","Mercury SSm B",Georgia,Baskerville,"Baskerville Old Face","Hoefler Text",Garamond,"Times New Roman",serif;
font-size: 16px;
color: #545350;
background: #F8F5EC;
}
h1 {
display: inline;
font-family: "Tungsten A","Tungsten B",Impact,Haettenschweiler,"Arial Narrow Bold","Franklin Gothic Bold",Charcoal,"Helvetica Inserat","Bitstream Vera Sans Bold","Arial Black",sans-serif;
font-weight: 600;
font-size: 3.1875rem;
color: #444341;
}
table {
margin: auto;
}
th {
padding: 5px;
font-weight: bold;
text-align: left;
}
td {
padding: 5px;
}
input[type="submit"] {
background: #137CBD;
color: white;
text-shadow: 1px 1px 1px #666;
gradient(top, #709FD8 0%, #649EE2 58%, #5F8DC6 100%);
background-image: linear-gradient(top, #709FD8 0%, #649EE2 58%, #5F8DC6 100%);
border: 1px solid #4C80C0;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
font-family: Arial, Helvetica, Verdana, sans-serif;
font-size: 1.0em;
font-weight: normal;
margin: 0 5px 0 0;
padding: 4px 10px 5px;
vertical-align: middle;
}
a {
color: #CC0000;
text-decoration: none;
border-bottom-style: dotted;
border-bottom-width: 1px;
}
a:hover {
color: #990000;
}
iframe {
width: 100%;
display: block;
}
#logout, #home {
font-family: 'Tungsten A','Tungsten B', Arial, sans-serif;
font-size: 22px;
}
#start, #stop {
font-family: 'Tungsten A','Tungsten B', Arial, sans-serif;
font-size: 20px;
}
#spawnhelp {
margin-top: 30px;
}
#spawnhelp li {
margin: 10px 0;
}
<html>
<title>RED LED Controller</title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="led.css">
</head>
<body>
<h1 style="text-align: center;">Controls:</h1>
<table>
<td>
<div class="row">
<div class="center">
<!-- cookie format:
netBright<0-100>-workBright<0-100>-worker1<1/0>
-->
<div class="column"><h2>Pre-Defined Actions:</h2>
<button onclick="setCookie('lights','100-100',365)">All On</button>
<button onclick="setCookie('lights','00-00',365)">All Off</button>
</div>
</div>
<div class="column"><br/>
<div class="center">
<h2>Custom Actions:</h2>
<form method="POST" action="/action.php">
Worker Brightness: <input type="range" min="0" max="100" value="0" class="slider" id="workBright" name="workBright" oninput="this.form.wB.value=this.value"><input type="number" name="wB" min="0" max="100" value="0" oninput="this.form.workBright.value=this.value" /><br>
Network Brightness: <input type="range" min="0" max="100" value="0" class="slider" id="netBright" name="netBright" oninput="this.form.nB.value=this.value"><input type="number" name="nB" min="0" max="100" value="0" oninput="this.form.netBright.value=this.value" /><br>
<br><br>
</form>
<button onclick="magicSubmit()">Submit</button>
</div>
</div>
</div>
</td>
<td>
<div class="row">
<div class="column">
<h2>Jobs:</h2>
<button onclick="setCookie('job','HTC',365)">HTC Job Submit</button>
<button onclick="setCookie('job','HPC',365)">HPC Job Submit</button>
</br></br></br></br></br></br></br></br></br></br>
</div>
</div>
</td>
</table>
</body>
<script>
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
window.location.replace("setLEDs.php");
}
function magicSubmit(){
console.log(parseInt(document.getElementById("workBright").value).toString(16) + '-'+ parseInt(document.getElementById("netBright").value).toString(16));
setCookie('lights',parseInt(document.getElementById("workBright").value).toString(10) + '-'+ parseInt(document.getElementById("netBright").value).toString(10),365)
//setCookie('redlight','S-' + document.getElementById("command").value + '-' + (document.getElementById("redValue").value).toString(16)+ '-' + (document.getElementById("greenValue").value).toString(16) +'-' + (document.getElementById("blueValue").value).toString(16),365);
}
</script>
</html>
/* CSS Document */
html,
html * {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: Gotham, Helvetica Neue, Helvetica, Arial," sans-serif";
background-color: darkgray;
}
\ No newline at end of file
<html>
<?php
//echo exec('whoami');
$job_name = "job";
$lights_name = "lights";
$filename = "/work/LED.txt";
exec("rm /work/LED.txt");
$file = fopen($filename, "a");
fwrite($file, $_COOKIE[$cookie_name]);
fclose($file);
if ($_COOKIE[$job_name] == "HPC"){
$random = (string)rand(5,30);
exec("cd /work/; sudo -H -u pi bash -c \"sbatch /work/master.sh\"");
}
if ($_COOKIE[$job_name] == "HTC"){
for ($x = 0; $x < 20; $x++){
exec("cd /work/; sudo -H -u pi bash -c \"sbatch --export=A=".(string)rand(5,30)." /work/slurmMock.sh\"" );
}
}
?>
<body style="background-color:#FFFFFF">
<table style="width: 100%" border="1">
<tbody>
<tr>
<tr><b>Sending Data...</b></tr>
Cookie Value: "<?php echo $_COOKIE[$cookie_name];?>"
<br><tr>
</tr>
</tr>
</tbody>
</table>
<p><br>
</p>
</body>
</html>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
window.location.replace("index.php");
});
</script>
## Worker Specific Items
workDir contains items to be stored in /work
\ No newline at end of file
import time
import subprocess
from random import randint
import socket
def sendCommand(command):
p = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
###Get Master Number
host = socket.gethostname()[-1:]
workers = ["1","2","3","4","5","6","7","8"]
###Send job from head to master, M - > F - > M
sendCommand("bash net.sh head worker"+host+" 5")
sendCommand("bash net.sh worker"+host+" file 5")
sendCommand("bash net.sh file worker"+host+" 5")
for i in workers:
if i != host:
#sendCommand("bash net.sh worker"+host+" worker"+i+" 1")
time.sleep(0.75)
print("sbatch slave"+i+".sh")
sendCommand("sbatch slave"+i+".sh")
sendCommand("bash net.sh worker"+host+" worker"+i+" 1")
#sendCommand("ssh -i /work/LegionKey pi@192.168.1.1"+i+" \"screen -md python /work/usage.py\"")
print("ssh -i /work/LegionKey pi@192.168.1.1"+i+" \"screen -md python /work/usage.py\"")
#sendCommand("bash slaveSubmit.sh")
end = time.time() + 40
while time.time() < end:
sendCommand("bash net.sh worker"+str(randint(1,8))+" worker"+str(randint(1,8))+" 1")
x = 0
sendCommand("bash net.sh worker"+host+" file 5")
sendCommand("bash net.sh worker"+host+" head 5")
#!/bin/sh
#SBATCH --time=00:02:00 # Run time in hh:mm:ss
#SBATCH --mem-per-cpu=100 # Memory required in MB
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=4
#SBATCH --job-name=Master
#SBATCH --error=/work/slurm/userJob%J.err
#SBATCH --output=/work/slurm/userJob.%J.out
#SBATCH --partition=Part1
python /work/HPCMagic.py
#!/bin/sh
#SBATCH --time=00:02:00 # Run time in hh:mm:ss
#SBATCH --mem-per-cpu=100 # Memory required in MB
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=4
#SBATCH --job-name=SlurmMock
#SBATCH --error=/work/slurm/userJob%J.err
#SBATCH --output=/work/slurm/userJob.%J.out
#SBATCH --partition=Part1
python /work/HTC.py $A
from piglow import PiGlow
from time import sleep
import psutil
from random import randint
p = PiGlow()
val = 100
colour = 1
def cpu_temp():
with open('/sys/class/thermal/thermal_zone0/temp', 'r') as f:
temp = float(f.read()) / 1000.0
return temp
arm1 = [6,5,4,3,2,1]
arm2 = [12,11,10,9,8,7]
arm3 = [18,17,16,15,14,13]
arms = [arm1,arm2,arm3]
x = 0
while True:
try:
cpuLoad = psutil.cpu_percent(percpu=True)
except:
print("Math dun goofed")
if cpu_temp() > 65:
p.red(255)
p.orange(255)
p.yellow(255)
sleep(0.005)
p.all(0)
else:
LEDList = []
for i in range(0,3):
lights = randint(0,100)/17#cpuLoad[i]/17
# print(cpuLoad)
LEDload = int(round(lights))
# print("Core: " + str(i))
for j in arms[i]:
if x <= LEDload:
# print("IF: " + str(x-int(lights)), x, int(lights))
if (x-int(lights)) <=0:
p.led(j,128)
else:
# print("ELSE",j,int(round((j-int(lights)*255))))
p.led(j,int(round((j-int(lights)*64))))
LEDList.append(j)
# print(j)
x = x + 1
x = 0
for k in range(1,18):
if k not in LEDList:
p.led(k,0)
sleep(0.08)