def ret_fail(self, message):
     LOG.error("%s" % str(message))
     message = NetworkUtil.encoding({
         Protocol.KEY_COMMAND: Protocol.MESSAGE_COMMAND_FAILED,
         Protocol.KEY_FAILED_REASON: message
     })
     message_size = struct.pack("!I", len(message))
     self.request.send(message_size)
     self.wfile.write(message)
 def ret_fail(self, message):
     LOG.error("%s" % str(message))
     message = NetworkUtil.encoding({
         Protocol.KEY_COMMAND : Protocol.MESSAGE_COMMAND_FAIELD,
         Protocol.KEY_FAILED_REASON : message
         })
     message_size = struct.pack("!I", len(message))
     self.request.send(message_size)
     self.wfile.write(message)
 def send_synthesis_done(self):
     message = NetworkUtil.encoding({
         Protocol.KEY_COMMAND : Protocol.MESSAGE_COMMAND_SYNTHESIS_DONE,
         })
     LOG.info("SUCCESS to launch VM")
     try:
         message_size = struct.pack("!I", len(message))
         self.request.send(message_size)
         self.wfile.write(message)
     except socket.error as e:
         pass
 def send_synthesis_done(self):
     message = NetworkUtil.encoding({
         Protocol.KEY_COMMAND: Protocol.MESSAGE_COMMAND_SYNTHESIS_DONE,
         })
     LOG.info("SUCCESS to launch VM")
     try:
         message_size = struct.pack("!I", len(message))
         self.request.send(message_size)
         self.wfile.write(message)
     except socket.error as e:
         pass
 def ret_success(self, req_command, payload=None):
     send_message = {
         Protocol.KEY_COMMAND: Protocol.MESSAGE_COMMAND_SUCCESS,
         Protocol.KEY_REQUESTED_COMMAND: req_command,
     }
     if payload:
         send_message.update(payload)
     message = NetworkUtil.encoding(send_message)
     message_size = struct.pack("!I", len(message))
     self.request.send(message_size)
     self.wfile.write(message)
     self.wfile.flush()
 def ret_success(self, req_command, payload=None):
     send_message = {
         Protocol.KEY_COMMAND : Protocol.MESSAGE_COMMAND_SUCCESS,
         Protocol.KEY_REQUESTED_COMMAND : req_command,
         }
     if payload:
         send_message.update(payload)
     message = NetworkUtil.encoding(send_message)
     message_size = struct.pack("!I", len(message))
     self.request.send(message_size)
     self.wfile.write(message)
     self.wfile.flush()
    def transfer(self):
        # connect
        address = (self.remote_addr, self.remote_port)
        sock = None
        for index in range(5):
            LOG.info("Connecting to (%s).." % str(address))
            try:
                sock = socket.create_connection(address, 10)
                break
            except Exception as e:
                time.sleep(1)
                pass
        if sock == None:
            msg = "failed to connect to %s" % str(address)
            raise StreamSynthesisClientError(msg)
        sock.setblocking(True)
        self.blob_sent_time_dict = dict()
        self.receive_thread = NetworkMeasurementThread(sock,
                                                       self.blob_sent_time_dict,
                                                       self.monitor_network_bw,
                                                       self.vm_resume_time_at_dest)
        self.receive_thread.start()

        # send header
        header_dict = {
            Protocol.KEY_SYNTHESIS_OPTION: None,
            }
        header_dict.update(self.metadata)
        header = NetworkUtil.encoding(header_dict)
        sock.sendall(struct.pack("!I", len(header)))
        sock.sendall(header)

        # stream blob
        blob_counter = 0
        while True:
            comp_task = self.compdata_queue.get()
            if self.is_first_recv == False:
                self.is_first_recv = True
                self.time_first_recv = time.time()
                LOG.debug("[time] Transfer first input at : %f" % (self.time_first_recv))
            transfer_size = 0
            if comp_task == Const.QUEUE_SUCCESS_MESSAGE:
                break
            if comp_task == Const.QUEUE_FAILED_MESSAGE:
                sys.stderr.write("Failed to get compressed data\n")
                break
            (blob_comp_type, compdata, disk_chunks, memory_chunks) = comp_task
            blob_header_dict = {
                Const.META_OVERLAY_FILE_COMPRESSION: blob_comp_type,
                Const.META_OVERLAY_FILE_SIZE:len(compdata),
                Const.META_OVERLAY_FILE_DISK_CHUNKS: disk_chunks,
                Const.META_OVERLAY_FILE_MEMORY_CHUNKS: memory_chunks
                }
            # send
            header = NetworkUtil.encoding(blob_header_dict)
            sock.sendall(struct.pack("!I", len(header)))
            sock.sendall(header)
            self.blob_sent_time_dict[blob_counter] = (time.time(), len(compdata))
            sock.sendall(compdata)
            transfer_size += (4+len(header)+len(compdata))
            blob_counter += 1

        # end message
        end_header = {
            "blob_type": "blob",
            Const.META_OVERLAY_FILE_SIZE:0
        }
        header = NetworkUtil.encoding(end_header)
        sock.sendall(struct.pack("!I", len(header)))
        sock.sendall(header)

        self.is_processing_alive.value = False
        self.time_finish_transmission.value = time.time()
        sys.stdout.write("Finish transmission. Waiting for finishing migration\n")
        self.receive_thread.join()
        sock.close()
Esempio n. 8
0
    def transfer(self):
        # connect
        address = (self.remote_addr, self.remote_port)
        sock = None
        for _ in range(5):
            LOG.info("Attempting connection to (%s)..", str(address))
            try:
                sock = socket.create_connection(address, 10)
                break
            except Exception as ex:
                time.sleep(1)
                LOG.error(ex)
        if sock is None:
            msg = "Failed to connect to %s" % str(address)
            LOG.error(msg)
            raise StreamSynthesisClientError(msg)
        else:
            sock.setblocking(True)
            self.blob_sent_time_dict = dict()
            self.receive_thread = NetworkMeasurementThread(
                sock, self.blob_sent_time_dict, self.monitor_network_bw,
                self.vm_resume_time_at_dest)
            self.receive_thread.start()

            # send header
            header_dict = {
                Protocol.KEY_SYNTHESIS_OPTION: None,
            }
            header_dict.update(self.metadata)
            header = NetworkUtil.encoding(header_dict)
            sock.sendall(struct.pack("!I", len(header)))
            sock.sendall(header)

            # stream blob
            blob_counter = 0
            while True:
                comp_task = self.compdata_queue.get()
                if self.is_first_recv == False:
                    self.is_first_recv = True
                    self.time_first_recv = time.time()
                    LOG.debug("[time] Transfer first input at : %f",
                              (self.time_first_recv))
                transfer_size = 0
                if comp_task == Const.QUEUE_SUCCESS_MESSAGE:
                    LOG.debug(
                        "Received SUCCESS message from compression task. Breaking..."
                    )
                    break
                if comp_task == Const.QUEUE_FAILED_MESSAGE:
                    LOG.error(
                        "Failed to get compressed data from compression thread!"
                    )
                    break
                (blob_comp_type, compdata, disk_chunks,
                 memory_chunks) = comp_task
                blob_header_dict = {
                    Const.META_OVERLAY_FILE_COMPRESSION: blob_comp_type,
                    Const.META_OVERLAY_FILE_SIZE: len(compdata),
                    Const.META_OVERLAY_FILE_DISK_CHUNKS: disk_chunks,
                    Const.META_OVERLAY_FILE_MEMORY_CHUNKS: memory_chunks
                }
                # send
                header = NetworkUtil.encoding(blob_header_dict)
                sock.sendall(struct.pack("!I", len(header)))
                sock.sendall(header)
                self.blob_sent_time_dict[blob_counter] = (time.time(),
                                                          len(compdata))
                sock.sendall(compdata)
                transfer_size += (4 + len(header) + len(compdata))
                blob_counter += 1
                #send the current iteration number for use at the destination
                sock.sendall(
                    struct.pack(
                        "!I",
                        self.process_controller.get_migration_iteration_count(
                        )))

            # end message
            end_header = {"blob_type": "blob", Const.META_OVERLAY_FILE_SIZE: 0}
            header = NetworkUtil.encoding(end_header)
            sock.sendall(struct.pack("!I", len(header)))
            sock.sendall(header)

            self.is_processing_alive.value = False
            self.time_finish_transmission.value = time.time()
            LOG.info(
                "Finished data transmission. Waiting for response that deltas have been applied..."
            )
            self.receive_thread.join()
            sock.close()
Esempio n. 9
0
    def transfer(self):
        # connect
        address = (self.remote_addr, self.remote_port)
        sock = None
        for index in range(5):
            LOG.info("Connecting to (%s).." % str(address))
            try:
                sock = socket.create_connection(address, 10)
                break
            except Exception as e:
                time.sleep(1)
                pass
        if sock == None:
            msg = "failed to connect to %s" % str(address)
            raise StreamSynthesisClientError(msg)
        sock.setblocking(True)
        self.blob_sent_time_dict = dict()
        self.receive_thread = NetworkMeasurementThread(sock,
                                                       self.blob_sent_time_dict,
                                                       self.monitor_network_bw,
                                                       self.vm_resume_time_at_dest)
        self.receive_thread.start()

        # send header
        header_dict = {
            Protocol.KEY_SYNTHESIS_OPTION: None,
            }
        header_dict.update(self.metadata)
        header = NetworkUtil.encoding(header_dict)
        sock.sendall(struct.pack("!I", len(header)))
        sock.sendall(header)

        # stream blob
        blob_counter = 0
        while True:
            comp_task = self.compdata_queue.get()
            if self.is_first_recv == False:
                self.is_first_recv = True
                self.time_first_recv = time.time()
                LOG.debug("[time] Transfer first input at : %f" % (self.time_first_recv))
            transfer_size = 0
            if comp_task == Const.QUEUE_SUCCESS_MESSAGE:
                break
            if comp_task == Const.QUEUE_FAILED_MESSAGE:
                sys.stderr.write("Failed to get compressed data\n")
                break
            (blob_comp_type, compdata, disk_chunks, memory_chunks) = comp_task
            blob_header_dict = {
                Const.META_OVERLAY_FILE_COMPRESSION: blob_comp_type,
                Const.META_OVERLAY_FILE_SIZE:len(compdata),
                Const.META_OVERLAY_FILE_DISK_CHUNKS: disk_chunks,
                Const.META_OVERLAY_FILE_MEMORY_CHUNKS: memory_chunks
                }
            # send
            header = NetworkUtil.encoding(blob_header_dict)
            sock.sendall(struct.pack("!I", len(header)))
            sock.sendall(header)
            self.blob_sent_time_dict[blob_counter] = (time.time(), len(compdata))
            sock.sendall(compdata)
            transfer_size += (4+len(header)+len(compdata))
            blob_counter += 1

        # end message
        end_header = {
            "blob_type": "blob",
            Const.META_OVERLAY_FILE_SIZE:0
        }
        header = NetworkUtil.encoding(end_header)
        sock.sendall(struct.pack("!I", len(header)))
        sock.sendall(header)

        self.is_processing_alive.value = False
        self.time_finish_transmission.value = time.time()
        sys.stdout.write("Finish transmission. Waiting for finishing migration\n")
        self.receive_thread.join()
        sock.close()