def executeInfrastructureTasks(self): print("") print("Executing Infrastructure tasks") print(" ...Executing site tasks") # ESTO ES UNA CHAPUZA # para saber si hay que hacer un profiling completo o no, miro la infraestructura # si no tiene hosts es que toca. # entonces, lo miro antes de crear las tarea,s ya que al crear las tareas # se rcean loss hosts... waitingTime = self.myInfrastructure.getSiteWaitingtime() siteTasks = self.myInfrastructure.createInfrastructureTasks(self.infrastructureTasks) for task in siteTasks: ExecutionManager.submit(task) # =================================================================== # print ("desactivado el envio de tareas de profiling: ID: PERROLOCO") # =================================================================== self.infrastructureTasks.append(task) if waitingTime > 0: print("Waiting for profiling tasks to execute") print("this will take " + str(waitingTime) + " seconds to execute") ExecutionManager.waitForTermination(siteTasks, waitingTime=waitingTime) print("profiling tasks executed") for task in siteTasks: self.myInfrastructure.updateInfoAfterProfiling(task) task.status = "CLEAR" base.Session.add(task)
def profileApplication(self): goodHosts = self.myInfrastructure.getGoodHosts() appProfilingTasks = [ ExecutionManager.createProfilingTask(host, self.myApplication) for host in goodHosts for i in range(2) ] # appProfilingTasks = [self.myApplication.profile.createProfilingTask(host) for host in goodHosts] # DEBIG # ======================================================================= # profilingTask = appProfilingTasks[0] # profilingTask.gwID = "2217" # self.myApplication.updateInfoAfterProfiling(profilingTask) # ======================================================================= # submit the tasks to the Grid for profilingTask in appProfilingTasks: ExecutionManager.submit(profilingTask) base.Session.add(profilingTask) try: base.Session.commit() except: base.Session.rollback() print("Lost connection with database, not storing anything!") profilingTime = 10 * self.myApplication.maxProfilingTime print("Waiting for the app profiles to finish, waiting for " + str(profilingTime) + " seconds") ExecutionManager.waitForTermination(appProfilingTasks, waitingTime=profilingTime) for profilingTask in appProfilingTasks: self.myApplication.updateInfoAfterProfiling(profilingTask) try: base.Session.commit() except: print("Lost connection with database, trying to recover it") try: base.Session = scoped_session(sessionmaker(bind=base.engine)) for profilingTask in appProfilingTasks: base.Session.add(profilingTask) base.Session.commit() print("Worked, yeah") except: print("didn't work, not storing anything! Will probably crash soon LOL") base.Session.rollback() print("Lost connection with database, not storing anything!")
def execute(self): while True: # update status of tasks being executed print("---") print("date:" + str(datetime.now())) print("") print("CHECKING FOR GRID CERTIFICATE") if not InformationManager.checkForValidCertificates(): print("Could not find a valid certificate") print("Finishing execution now :(") break # =================================================================== # print ("PRINCICIPIO DE EXECUTE") # for task in self.infrastructureTasks: # print ("Task " + task.gwID + "has hosttype " + str(task.host.__class__)) # # # =================================================================== print("") print("UPDATING INFRASTRUCTURE STATUS") for gridTask in self.infrastructureTasks: ExecutionManager.updateGridTaskStatus(gridTask) finishedTasks = [gridTask for gridTask in self.infrastructureTasks if gridTask.status == "DONE"] for gridTask in finishedTasks: if gridTask.type == "hostProfiling": self.myInfrastructure.updateInfoAfterProfiling(gridTask) # and update gridTask status ExecutionManager.removeTaskFromGW(gridTask) self.infrastructureTasks.remove(gridTask) self.myInfrastructure.updateStatus(self.infrastructureTasks) print("") print("CREATING INFRASTRUCTURE TASKS") self.executeInfrastructureTasks() # =================================================================== # print ("FILNAL DE EXECUTE") # for task in self.infrastructureTasks: # print ("Task " + task.gwID + "has hosttype " + str(task.host.__class__)) # =================================================================== print("UPDATE APPLICATION STATUS") for gridTask in self.applicationTasks: ExecutionManager.updateGridTaskStatus(gridTask) # estoe s una chapuza totalTasks = self.infrastructureTasks + self.applicationTasks self.myInfrastructure.updateStatus(totalTasks) # process recently finishedTasks finishedTasks = [gridTask for gridTask in self.applicationTasks if gridTask.status == "DONE"] for gridTask in finishedTasks: if gridTask.type == "applicationProfiling": self.myApplication.updateInfoAfterProfiling(gridTask) elif gridTask.type == "applicationExecution": self.myApplication.updateInfoAfterExecution(gridTask) # and update gridTask status ExecutionManager.removeTaskFromGW(gridTask) self.applicationTasks.remove(gridTask) # check for execution finish if self.myApplication.remainingSamples <= 0: print("Starting the exit of execution loop") # TODO: poner en los hosts que el máximo de host total es el maximo del total y del maximoThisTime self.myApplication.finished = 1 base.Session.add(self.myApplication) print("Application marked as finished") print("") print("Storing information about available hosts on remote sites") for host in self.myInfrastructure.hosts: host.maxSlotCount = max(host.maxSlotCount, host.maxSlotCountThisTime) base.Session.add(host) print("") print("Removing finished tasks from gridWay") # esto es discutible, # ahora, si una tarea de profiling ha llegado hasta el final de la ejecución sin ser completada, la marco como fallida # esto perjudica a los sitios que tienen un tiempo enorme de respuesta # lo contrario hace que si un sitio no contesta se siga considerando pendiente de profiling hasta el infinito for gridTask in self.applicationTasks: ExecutionManager.removeTaskFromGW(gridTask) if gridTask.type == "hostProfiling": self.myInfrastructure.updateInfoAfterProfiling(gridTask) try: base.Session.commit() except: base.Session.rollback() print("Lost connection with database, not storing anything!") print("Exiting execution loop") break print("") print("CREATING NEW EXECUTION TASKS") # =================================================================== # self.myInfrastructure.showHosts() # =================================================================== applicationExecutionTasks = self.mySchedulingAlgorithm.createApplicationTasks( self.myInfrastructure, self.myApplication, self.applicationTasks ) for gridTask in applicationExecutionTasks: ExecutionManager.submit(gridTask) self.applicationTasks.append(gridTask) base.Session.add(gridTask) try: base.Session.commit() except: base.Session.rollback() print("Lost connection with database, not storing anything!") print("...") sleep(15)