def parseMessageBCS(msg): # Forward messages if type(msg) == messages.Register: backup_servers.backupQueueAppend(copy.deepcopy(msg)) else: backup_servers.registerQueueAppend(copy.deepcopy(msg)) # Parse if type(msg) == messages.Register: if not msg.Deregister: print("% -> Register component #{:d} - {:s}".format(msg.Id, msg.Type)) components.add(msg) else: print("% -> Deregister component #{:d} - {:s}".format(msg.Id, msg.Type)) component = components.get(msg.Id) component.dead = True problems.release(component.id) elif type(msg) == messages.SolveRequest: print("% -> SolveRequest") problems.add(msg) elif type(msg) == messages.SolvePartialProblems: print("% -> SolvePartialProblems") problem = problems.list[msg.Id] problem.updateWithDivide(msg) elif type(msg) == messages.Solutions: print("% -> Solutions") problem = problems.list[msg.Id] problem.updateWithSolutions(msg) elif type(msg) == messages.NoOperation: print("% -> NoOperation") # update backup server list else: print("% ? {:s}".format(str(msg)))
def messageSolvePartialProblems(conn, msg): assert msg.Id < len(problems.list), "problem id not registered" print("-> SolvePartialProblems :: #{id:d} Type: {type:s} PartialProblems: {count:d}".format(type=msg.ProblemType, id=msg.Id, count=len(msg.PartialProblems))) problem = problems.list[msg.Id] problem.updateWithDivide(msg) backup_msg = copy.deepcopy(msg) backup_servers.backupQueueAppend(backup_msg)
def messageSolveRequest(conn, msg): id = problems.add(msg) print("-> AddProblem :: #{id:d} Type: {type:s} Timeout: {timeout:d}".format(type=msg.ProblemType, timeout=msg.SolvingTimeout, id=id)) problemStartTime[id] = current_time_ms() response = messages.SolveRequestResponse(id) conn.send(response) backup_msg = copy.deepcopy(msg) backup_msg.Id = id backup_servers.backupQueueAppend(backup_msg)
def messageSolutions(conn, msg): problem = problems.list[msg.Id] # Received partial solution from CN if problem.status == Problem.Divided: print("-> Solutions :: #{id:d} Type: {type:s}".format(type=msg.ProblemType, id=msg.Id)) for solution in msg.Solutions: print("--- Solution :: #{id:d} Type: {type:s} Time: {time:d} Timeout: {timeout:}".format(type=solution.Type, time=solution.ComputationsTime, id=solution.TaskId, timeout=solution.TimeoutOccured)) # Received final merged solution from TM elif problem.status == Problem.Computed: print("-> Merged Solutions :: #{id:d} Type: {type:s}".format(type=msg.ProblemType, id=msg.Id)) time = current_time_ms() - problemStartTime[msg.Id] print("-> Solve time: {time:d}".format(time=time)) with open("Output {}.txt".format(msg.Id), "w") as text_file: print("{}\n{}\n".format(time, msg.Solutions[0].Data), file=text_file) problem.updateWithSolutions(msg) backup_msg = copy.deepcopy(msg) backup_servers.backupQueueAppend(backup_msg)