def serverOption(): option = request.args.get('option', default=1, type=int) workerAmount = request.args.get('N', default=1, type=int) processAlt = [ "creating network", "deploying new workers", "removing worker(s)" ] state = processAlt[option - 1] currState, Nmax, IP, tokens = getState() updateState(state, workerChange=0) if (option == 1): deployInstances([worker_image, master_image], 1) elif (option == 2): deployInstances([worker_image], workerAmount) elif (option == 3): #start time time_start = timeit.default_timer() removeNodes(workerAmount) time_end = timeit.default_timer() #wait for deleting nodes to be synced print("About to sleep for ", 5 * workerAmount - (time_end - time_start)) time.sleep(5 * workerAmount - (time_end - time_start)) workerAmount = int(workerAmount) * -1 state = "Finished " + processAlt[option - 1] updateState(state, workerChange=workerAmount) updateHostFiles() if (Nmax + workerAmount > 0): print("Sleeping 10s, then deploying anisble playbook") time.sleep(10) print(runAns("spark_deployment.yml")) else: state = "Too few workers!" return state
def deployInstances(nameList, N): flavor, private_net, nova, conn = genInitData() _, workerCount, IP, tokens = getState() for image_name in nameList: print("current name = ", image_name) n_times = 1 node_name = "ACC4_master" if "worker" in image_name.lower(): n_times = int(N) node_name = "ACC4_worker_" # Set this to range(1,2) to max deploy 1 worker for i in range(1 + workerCount, n_times + 1 + workerCount): print("about to worker node") createInstance(image_name, node_name + str(i), flavor, private_net, nova, conn) else: createInstance(image_name, node_name + "1", flavor, private_net, nova, conn)
def removeNodes(N): stringReturn = None state, amountWorkers, IP, tokens = getState() Nmax = amountWorkers if(N >= -1 and N <= Nmax): if(N == -1): N = Nmax item = sh.nova("delete","ACC4_master1") stringReturn = "You deleted the entire network" state = "shutdown" N = Nmax else: stringReturn = "You deleted "+ str(N) + "workers" for i in range(Nmax, Nmax-N, -1): item = sh.nova("delete","ACC4_worker_"+str(i)) amountWorkers -= N return stringReturn, amountWorkers
def shutdown(): removeNodes(-1) state, n, IP, tokens = getState() updateState("YOU BURNED IT TO THE GROUND!", workerChange=-n) return "It's all gone! \_( T _ T )_/"
def state(): state, count, IP, tokens = getState(path="") output = "State = " + state + "\n" + "Woker count = " + str( count) + "\n" + IP + "Tokens = " + tokens + "\n" return output