Пример #1
0
    def update_backup(self, cmd='', msg=''):
        bk_tp_service = TupleSpaceClient(self.parsed_args.backup_sap[0],
                                         self.parsed_args.backup_sap[1])
        if self.isPrimary:
            if self.initial_backup_update:
                update = self.app.search_tuple(".*", ".*")
                res = bk_tp_service.put(str(update))
                self.initial_backup_update = False
            else:
                update = msg
                method = getattr(bk_tp_service, cmd.lower())
                res = method(msg)

            if res.data['status'] == 'ok':
                logger.info('backup updated')
                logger.debug('backup updated with {}'.format(update))
Пример #2
0
def server():
    HOST = "localhost"
    mock_server_port = get_free_port()
    start_tcp_main_server(HOST, mock_server_port)
    req = TupleSpaceClient(HOST, mock_server_port)
    return req
Пример #3
0
def server1():
    mock_server_port = get_free_port()
    start_tcp_mock_server(HOST, mock_server_port)
    req = TupleSpaceClient(HOST, mock_server_port)
    return req
Пример #4
0
def server():
    HOST = "localhost"
    port = 9999
    start_tcp_main_server(HOST, port)
    req = TupleSpaceClient(HOST, port)
    return req
Пример #5
0
def main():
    random.seed()
    try:
        # set up to acquire arguments from command line
        parser = argparse.ArgumentParser()
        # parser.add_argument('-host', '--server-host', type=hostname_parser, dest='server_host', default=None, )
        # parser.add_argument('-ip', '--server-IP', type=IPv4_addr_parser, dest='server_IP', default=conf.PROXY_2_CLIENT_IP, )
        # parser.add_argument('-port', '--server-port', type=port_parser, dest='server_port', default=conf.PROXY_2_CLIENT_PORT, )

        parser.add_argument(
            '-ip',
            '--server-IP',
            dest='server_IP',
            default=conf.PROXY_2_CLIENT_IP,
        )
        parser.add_argument(
            '-port',
            '--server-port',
            type=port_parser,
            dest='server_port',
            default=conf.PROXY_2_CLIENT_PORT,
        )

        parsed_args = parser.parse_args()

        # # postprocess host, IP arguments to set default / validate consistency, depending on what's there
        # if parsed_args.server_IP is None:
        #     try:
        #         parsed_args.server_IP = socket.gethostbyname(conf.PROXY_2_CLIENT_IP) if parsed_args.server_host is None else \
        #             parsed_args.server_host[1]
        #     except OSError as err:
        #         raise OSError('invalid hostname (%s): %s' % (parsed_args.server_host[0], logger.debug(err)))
        # else:
        #     specified_IP, specified_host, actual_IP = parsed_args.server_host[1], parsed_args.server_host[
        #         0], parsed_args.server_IP
        #     syndrome = "specified IP address {} for server host {} differs from actual IP address {}".format(
        #         specified_IP, specified_host, actual_IP)
        #     assert parsed_args.server_host[1] == parsed_args.server_IP, syndrome

        # --------------------------------------------------
        #  instantiate and run the client
        # --------------------------------------------------
        tp_service = TupleSpaceClient(parsed_args.server_IP,
                                      parsed_args.server_port)
        for i in range(10):
            try:
                keyExpr = "^f"
                valExpr = ".*"
                res = tp_service.get(keyExpr, valExpr)
                print(res.data['payload'])
                print(res.data['status'])

                res = tp_service.post(
                    '[("kdkdkd","niyilomo"),("osayamen","heyeeeeeees"), ("boss","heyes")]'
                )
                print(res.data['payload'])
                print(res.data['status'])
                #
                # res = tp_service.put('[("fal","niyi"),("gal","heyes"),("zal","heyes"),("galoolll","heyes")]')
                # print(res.data['payload'])

            except ConnectionAbortedError as err:
                #@TODO: implement a wait and retry here
                pass
                # raise
    #
    except Exception as err:
        logger.info('aborting {}'.format(err))
        if conf.DEBUG_MODE: raise