Example #1
0
    def handle(self):
        lock_socket_list.acquire()
        socket_list[self.client_address] = self.request
        lock_socket_list.release()

        HP.logger.debug('Got connection from %s' % self.client_address[0])
        while True:
            msg = HP.recv_hm_message(socket_list[self.client_address])
            if not msg:
                continue
            if msg.message != HM.ACK:
                if msg.message == HM.DISCONNECT:
                    HP.logger.debug('Disconnecting from %s' %
                                    self.client_address[0])

                    lock_host.acquire()
                    del hosts[self.client_address]
                    del hosts_state[self.client_address]
                    lock_host.release()

                    socket_list[self.client_address].close()

                    lock_socket_list.acquire()
                    del socket_list[self.client_address]
                    lock_socket_list.release()
                    return
                else:
                    lock_host.acquire()
                    hosts[self.client_address] = msg
                    hosts_state[self.client_address] = NOTHING_RUN
                    lock_host.release()

                    if msg.message == HM.MODULE and msg.action == HM.COMPLETED:
                        if msg.module == HM.CPU:
                            cpu_completed(self.client_address, msg)
Example #2
0
    def handle(self):
        lock_socket_list.acquire()
        socket_list[self.client_address] = self.request
        lock_socket_list.release()

        HP.logger.debug('Got connection from %s' % self.client_address[0])
        while True:
            msg = HP.recv_hm_message(socket_list[self.client_address])
            if not msg:
                continue
            if msg.message != HM.ACK:
                if msg.message == HM.DISCONNECT:
                    HP.logger.debug('Disconnecting from %s' %
                                    self.client_address[0])

                    lock_host.acquire()
                    del hosts[self.client_address]
                    del hosts_state[self.client_address]
                    lock_host.release()

                    socket_list[self.client_address].close()

                    lock_socket_list.acquire()
                    del socket_list[self.client_address]
                    lock_socket_list.release()
                    return
                else:
                    lock_host.acquire()
                    hosts[self.client_address] = msg
                    hosts_state[self.client_address] = NOTHING_RUN
                    lock_host.release()

                    if msg.message == HM.MODULE and msg.action == HM.COMPLETED:
                        if msg.module == HM.CPU:
                            cpu_completed(self.client_address, msg)
Example #3
0
def connect_to_server(hostname):
    global s
    global connected
    try:
        s.connect((hostname, 20000))
    except:
        HP.logger.error("Server %s is not available, exiting" % hostname)
        sys.exit(1)

    connected = True

    msg = HM(HM.CONNECT)

    hrdw_json = json.loads(open(sys.argv[1]).read(-1))
    encode_hardware(hrdw_json, msg)

    HP.send_hm_message(s, msg, True)
    while True:
        try:
            msg = HP.recv_hm_message(s)
        except:
            HP.logger.error("Broken socket, exiting !")
            break

        if not msg:
            continue

        if msg.message == HM.INVALID:
            HP.logger.error("Ignoring invalid message")
            continue

        if msg.message == HM.DISCONNECTED:
            connected = False
            HP.logger.error("Got disconnected from server, exiting")
            return True
            break

        hrdw_json = json.loads(open(sys.argv[1]).read(-1))
        encode_hardware(hrdw_json, msg)

        handlers = {
            HM.NONE: none,
            HM.CONNECT: connect,
            HM.DISCONNECT: disconnect,
            HM.ACK: ack,
            HM.NACK: nack,
            HM.MODULE: module,
        }

        HP.logger.info("Received %d" % msg.message)
        HP.logger.info(handlers)
        handlers[msg.message](s, msg)
Example #4
0
    def handle(self):
        lock_socket_list.acquire()
        socket_list[self.client_address] = self.request
        lock_socket_list.release()

        HP.logger.debug('Got connection from %s' % self.client_address[0])
        while True:
            msg = HP.recv_hm_message(socket_list[self.client_address])
            if not msg:
                continue
            if msg.message != HM.ACK:

                # If we do receive a STARTING message, let's record the starting time
                # No need to continue processing the packet, we can wait the next one
                if msg.action == HM.STARTING:
                    start_time(self.client_address)
                    continue

                if msg.message == HM.DISCONNECT:
                    HP.logger.debug('Disconnecting from %s' %
                                    self.client_address[0])

                    lock_host.acquire()
                    del hosts[self.client_address]
                    del hosts_state[self.client_address]
                    lock_host.release()

                    socket_list[self.client_address].close()

                    lock_socket_list.acquire()
                    del socket_list[self.client_address]
                    lock_socket_list.release()
                    return
                else:
                    lock_host.acquire()
                    hosts[self.client_address] = msg
                    hosts_state[self.client_address] = NOTHING_RUN
                    lock_host.release()

                    if msg.message == HM.MODULE and msg.action == HM.COMPLETED:
                        if running_jitter is True:
                            stop_time(self.client_address)

                        if msg.module == HM.CPU:
                            cpu_completed(self.client_address, msg)
                        elif msg.module == HM.MEMORY:
                            memory_completed(self.client_address, msg)
                        elif msg.module == HM.NETWORK:
                            network_completed(self.client_address, msg)
                        elif msg.module == HM.STORAGE:
                            storage_completed(self.client_address, msg)
Example #5
0
    def handle(self):
        lock_socket_list.acquire()
        socket_list[self.client_address] = self.request
        lock_socket_list.release()

        HP.logger.debug('Got connection from %s' % self.client_address[0])
        while True:
            msg = HP.recv_hm_message(socket_list[self.client_address])
            if not msg:
                continue
            if msg.message != HM.ACK:

                # If we do receive a STARTING message, let's record the starting time
                # No need to continue processing the packet, we can wait the next one
                if msg.action == HM.STARTING:
                    start_time(self.client_address)
                    continue

                if msg.message == HM.DISCONNECT:
                    HP.logger.debug('Disconnecting from %s' %
                                    self.client_address[0])

                    lock_host.acquire()
                    del hosts[self.client_address]
                    del hosts_state[self.client_address]
                    lock_host.release()

                    socket_list[self.client_address].close()

                    lock_socket_list.acquire()
                    del socket_list[self.client_address]
                    lock_socket_list.release()
                    return
                else:
                    lock_host.acquire()
                    hosts[self.client_address] = msg
                    hosts_state[self.client_address] = NOTHING_RUN
                    lock_host.release()

                    if msg.message == HM.MODULE and msg.action == HM.COMPLETED:
                        if running_jitter is True:
                            stop_time(self.client_address)

                        if msg.module == HM.CPU:
                            cpu_completed(self.client_address, msg)
                        elif msg.module == HM.MEMORY:
                            memory_completed(self.client_address, msg)
                        elif msg.module == HM.NETWORK:
                            network_completed(self.client_address, msg)
                        elif msg.module == HM.STORAGE:
                            storage_completed(self.client_address, msg)
Example #6
0
def connect_to_server(hostname):
    global s
    global connected
    try:
        s.connect((hostname, 20000))
    except:
        HP.logger.error("Server %s is not available, exiting" % hostname)
        sys.exit(1)

    connected = True

    msg = HM(HM.CONNECT)

    hrdw_json = json.loads(open(sys.argv[1]).read(-1))
    encode_hardware(hrdw_json, msg)

    HP.send_hm_message(s, msg, True)
    while True:
        try:
            msg = HP.recv_hm_message(s)
        except:
            HP.logger.error("Broken socket, exiting !")
            break

        if not msg:
            continue

        if msg.message == HM.INVALID:
            HP.logger.error("Ignoring invalid message")
            continue

        if msg.message == HM.DISCONNECTED:
            connected = False
            HP.logger.error("Got disconnected from server, exiting")
            return True
            break

        hrdw_json = json.loads(open(sys.argv[1]).read(-1))
        encode_hardware(hrdw_json, msg)

        handlers = {HM.NONE: none,
                    HM.CONNECT: connect,
                    HM.DISCONNECT: disconnect,
                    HM.ACK: ack,
                    HM.NACK: nack,
                    HM.MODULE: module,
                    }

        HP.logger.info("Received %d" % msg.message)
        HP.logger.info(handlers)
        handlers[msg.message](s, msg)