Example #1
0
    def do_GET(self):
        # The URL path is the key
        key = self.path

        # Defer to NodeCore
        result = node.do_get(key)

        # Take action depending on NodeCore decision
        if isinstance(result, ValueFound):
            self.respond(200, "application/octet-stream", result.value)

        elif isinstance(result, ValueNotFound):
            self.respond(404, "text/html", "Key not found")

        elif isinstance(result, ForwardRequest):
            # Forward request to specified node
            (status_code, content_type, data) = node_request.sendGET(
                    result.destination, node_httpserver_port, key)

            # Relay response to requesting node
            self.respond(status_code, content_type, data)

        else:
            raise Exception("Unknown result command: " + pformat(result))
	def sendGET(self, key):
		node = random.choice(storageBackendNodes)
		(status_code, content_type, data) = node_request.sendGET(
				node, node_httpserver_port, key)
		return data