Example #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)))
Example #2
0
def registerTMCN(conn, msg):
	id = components.add(msg)
	print("-> Register :: #{id:d} Type: {type:s}".format(type=msg.Type, id=id))
	response = messages.RegisterResponse(id, config.timeout, components.getBackupServersList())
	conn.send(response)

	backup_msg = copy.deepcopy(msg)
	backup_msg.Id = id
	backup_servers.registerQueueAppend(backup_msg)
Example #3
0
def registerBCS(conn, msg):
	peer = conn.socket.getpeername()
	# Current main CS decides component id, if msg.Id exists -> components.add preserves it
	id = components.add(msg, (peer[0], peer[1]))
	# Current server has no backups
	if config.child_address == None and config.child_port == None:
		print("-> Register BCS :: #{id:d}".format(id=id))
		config.child_address = peer[0]
		config.child_port = peer[1]
		config.child_id = id
		response = messages.RegisterResponse(id, config.timeout, [])
		conn.send(response)
		# Send accumulated register messages queue
		for registerMsg in backup_servers.getRegisterMessages():
			conn.send(registerMsg)
	# Forward BCS to first backup server
	else:
		print("-> Send register BCS downstream :: #{id:d}".format(id=msg.Id))
		backups = [{
			"address": config.child_address,
			"port": config.child_port
		}]
		response = messages.RegisterResponse(msg.Id, config.timeout, backups)
		conn.send(response)