Пример #1
0
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)))
Пример #2
0
def removeInactiveComponents():
	removeInactiveBackup()
	if config.is_backup: return
	for component in components.active():
		# Wait twice the timeout, as nodes are sending state each timeout seconds
		# Don't check CSs, as their state is updated only for the parent in backups list
		if not component.isAlive(2 * config.timeout * 1000) and component.type != "CommunicationServer":
			# Release all problems or tasks assigned to that component
			problems.release(component.id)
			print("Removing inactive component: #{:d} ({:s})".format(component.id, type(component).__name__))

			# Backup message: remove component
			backup_msg = copy.deepcopy(component.registerMessage)
			backup_msg.Id = component.id
			backup_msg.Deregister = True
			backup_servers.registerQueueAppend(backup_msg)