From 526588c59479fcac0e7746a46b6998781de5955e Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Mon, 11 Jun 2018 01:36:42 -0400 Subject: [PATCH] Prepare to get a Results() for each machine-test combination. Need to add back the dictionary() dump for the Client --- Client/OpenBench.py | 21 +----------------- OpenBench/utils.py | 53 ++++++++++++++++++++++++--------------------- OpenBench/views.py | 40 +++++++++++++++++++--------------- 3 files changed, 52 insertions(+), 62 deletions(-) diff --git a/Client/OpenBench.py b/Client/OpenBench.py index b0fbd55..ebcce37 100644 --- a/Client/OpenBench.py +++ b/Client/OpenBench.py @@ -401,23 +401,4 @@ if __name__ == "__main__": print (response) - sys.exit(0) - - - #while True: - # try: - # request = requests.get("{0}/getWorkload/{1}".format(server, cores)) - # asstring = request.content.decode("utf-8") - # - # if asstring == "No Workloads": - # time.sleep(60) - # - # else: - # asdictionary = ast.literal_eval(asstring) - # completeWorkload(server, cores, asdictionary) - # time.sleep(1) - # - # except: - # print (" : ", sys.exc_info()[0]) - # time.sleep(10) - + sys.exit(0) \ No newline at end of file diff --git a/OpenBench/utils.py b/OpenBench/utils.py index 4e1fbaf..3575c5d 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -15,27 +15,6 @@ def getSourceLocation(branch, repo): except: raise Exception('Unable to find branch ({0})'.format(branch)) -def verifyMachine(machineid, username, osname, threads): - - # Machine does not exist, make a new one - if machineid == 'None': - machine = Machine() - machine.owner = username - machine.osname = osname - machine.threads = threads - machine.mnps = 0.00 - machine.save() - return machine - - # Verify the selected machine is the user's - machine = Machine.objects.get(id=machineid) - assert machine.owner == username - assert machine.osname == osname - machine.threads = threads - machine.mnps = 0.00 - machine.save() - return machine - def newEngine(name, source, protocol, sha, bench): # Engine may already exist, which is okay @@ -101,7 +80,28 @@ def newTest(request): test.save() return test -def getWorkload(threads): +def getMachine(machineid, username, osname, threads): + + # Machine does not exist, make a new one + if machineid == 'None': + machine = Machine() + machine.owner = username + machine.osname = osname + machine.threads = threads + machine.mnps = 0.00 + machine.save() + return machine + + # Verify the selected machine is the user's + machine = Machine.objects.get(id=machineid) + assert machine.owner == username + assert machine.osname == osname + machine.threads = threads + machine.mnps = 0.00 + machine.save() + return machine + +def getWorkload(machine): # Get a list of all active tests tests = Test.objects.filter(finished=False) @@ -128,12 +128,12 @@ def getWorkload(threads): threadcnt = max(devthreads, basethreads) # Empty list or higher priority found for workable test - if (options == [] or test.priority > highest) and threadcnt <= threads: + if (options == [] or test.priority > highest) and threadcnt <= machine.threads: highest = test.priority options = [test] # New workable test with the same priority - elif options != [] and test.priority == highest and threadcnt <= threads: + elif options != [] and test.priority == highest and threadcnt <= machine.threads: options.append(test) # Sum of throughputs, for weighted randomness @@ -149,4 +149,7 @@ def getWorkload(threads): # Drop the test from selection target -= options[0].throughput - options = options[1:] \ No newline at end of file + options = options[1:] + +def getResults(machine, test): + pass \ No newline at end of file diff --git a/OpenBench/views.py b/OpenBench/views.py index 190078c..976a791 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -355,31 +355,37 @@ def getFiles(request): @csrf_exempt def getWorkload(request): - try: # Attempt to login in user - user = authenticate( + # Attempt to login in user + try: loginUser(request, authenticate( username=request.POST['username'], - password=request.POST['password']) - loginUser(request, user) - except: - return HttpResponse('Bad Credentials') + password=request.POST['password'])) + except: return HttpResponse('Bad Credentials') - try: # Create or fetch the Machine - machine = OpenBench.utils.verifyMachine( + # Create or fetch the Machine + try: machine = OpenBench.utils.getMachine( request.POST['machineid'], request.POST['username'], request.POST['osname'], request.POST['threads']) - except: - return HttpResponse('Bad Machine') + except: return HttpResponse('Bad Machine') - try: # Find an active Test to work on - test = OpenBench.utils.getWorkload(machine.threads) - except: - return HttpResponse('None') + # Find an active Test to work on + try: test = OpenBench.utils.getWorkload(machine) + except: return HttpResponse('None') - print(user) - print(machine) - print(test) + # Create or fetch the Results + try: results = OpenBench.utils.getResults(machine, test) + except: return HttpResponse('None') + + # Convert everything for the Client + data = { + "machine" : machine.dictionary(), + "test" : test.dictionary(), + "result" : results.dictionary() + } + + # Send context as a string0 + return HttpResponse(str(data)) @csrf_exempt def submitResults(request):