def __init__(self, domain: int, module_directory: str):
        self.domain = domain
        self.requests = {}
        self.config = Config().get_config()
        self.field_sets = {}
        self.logger = log().get_logger()

        if not module_directory:
            if 'AGNTProcessor' in self.config:
                if 'ModuleDir' in self.config['AGNTProcessor']:
                    module_directory = self.config['AGNTProcessor'][
                        'ModuleDir']
                else:
                    ValueError(
                        'Configuration file does not have {0} entry within {1}'
                        .format('ModuleDir', 'AGNTProcessor'))
            else:
                ValueError(
                    'Configuration file does not have {0} entry,please include it'
                    .format('AGNTProcessor'))

        if 'AGNTProcessor' in self.config:
            if 'Modules' in self.config['AGNTProcessor']:
                modules = self.config['AGNTProcessor']['Modules']
                self.module_loader = ModuleLoader(module_directory,
                                                  'AGNTProcessor', modules)
            else:
                ValueError(
                    'Configuration file does not have {0} entry within {1}'.
                    format('Modules', 'AGNTProcessor'))
        else:
            ValueError(
                'Configuration file does not have {0} entry,please include it'.
                format('AGNTProcessor'))
Beispiel #2
0
    def __init__(self, domain: int, module_directory: str=None):
        super(AuctionProcessor, self).__init__(domain)
        self.auctions = {}
        self.config = Config().get_config()
        self.field_sets = {}
        self.logger = log().get_logger()
        self.field_def_manager = FieldDefManager()

        if not module_directory:
            if 'AUMProcessor' in self.config:
                if 'ModuleDir' in self.config['AUMProcessor']:
                    module_directory = self.config['AUMProcessor']['ModuleDir']
                else:
                    ValueError(
                        'Configuration file does not have {0} entry within {1}'.format('ModuleDir', 'AumProcessor'))
            else:
                ValueError('Configuration file does not have {0} entry,please include it'.format('AumProcessor'))

        if 'AUMProcessor' in self.config:
            if 'Modules' in self.config['AUMProcessor']:
                modules = self.config['AUMProcessor']['Modules']
                self.module_loader = ModuleLoader(module_directory, 'AUMProcessor', modules)
            else:
                ValueError(
                    'Configuration file does not have {0} entry within {1}'.format('Modules', 'AumProcessor'))
        else:
            ValueError('Configuration file does not have {0} entry,please include it'.format('AumProcessor'))

        self.build_field_sets()
Beispiel #3
0
    def __init__(self, config_file_name: str):
        self._pending_tasks_by_auction = {}

        self.config = Config(config_file_name).get_config()

        # Start Listening the web server application
        loop = asyncio.get_event_loop()
        self.app = Application(loop=loop)

        # Gets the log file
        log_file_name = self.config['DefaultLogFile']
        self.logger = log(log_file_name).get_logger()

        self.domain = ParseFormats.parse_int(Config().get_config_param(
            'Main', 'Domain'))
        self.immediate_start = ParseFormats.parse_bool(
            Config().get_config_param('Main', 'ImmediateStart'))

        self._load_main_data()
        self._load_control_data()
Beispiel #4
0
 def _initilize_processors(self):
     """
     Initialize processors used
     :return:
     """
     self.logger.debug("Starting _initilize_processors")
     module_directory = Config().get_config_param('AGNTProcessor',
                                                  'ModuleDir')
     self.agent_processor = AgentProcessor(self.domain, module_directory)
     self.message_processor = ClientMessageProcessor(self.app)
     self.logger.debug("Ending _initilize_processors")
Beispiel #5
0
 def _initilize_processors(self):
     """
     Initialize processors used
     :return:
     """
     self.logger.debug("Starting _initilize_processors")
     module_directory = Config().get_config_param('AUMProcessor',
                                                  'ModuleDir')
     self.auction_processor = AuctionProcessor(self.domain,
                                               module_directory)
     self.message_processor = ServerMessageProcessor()
     self.logger.debug("Ending _initilize_processors")
Beispiel #6
0
    def _load_control_data(self):
        """
        Sets the control data defined in the configuration file
        """
        self.logger.debug("Stating _load_control_data")

        try:
            self.use_ssl = ParseFormats.parse_bool(Config().get_config_param(
                'Control', 'UseSSL'))
            self.control_port = ParseFormats.parse_uint16(
                Config().get_config_param('Control', 'ControlPort'))
            self.log_on_connect = ParseFormats.parse_bool(
                Config().get_config_param('Control', 'LogOnConnect'))
            self.log_command = ParseFormats.parse_bool(
                Config().get_config_param('Control', 'LogCommand'))
            self.control_hosts = self.config['Control']['Access']['Host']
            self.control_user, self.control_passwd = \
                self.config['Control']['Access']['User'].split(':')

            self.logger.debug("Ending _load_control_data")

        except ValueError as verr:
            self.logger.error(
                "The value for control port{0} is not a valid number".format(
                    Config().get_config_param('Control', 'ControlPort')))

            raise ValueError(
                "The value for control port{0} is not a valid number".format(
                    Config().get_config_param('Control', 'ControlPort')))
    def __init__(self):
        self.domain = Config().get_config_param('Main','Domain')
        use_ipv6 = Config().get_config_param('Main','UseIPv6')
        self.use_ipv6 = ParseFormats.parse_bool(use_ipv6)
        if self.use_ipv6:
            self.ip_address6 = ParseFormats.parse_ipaddress(Config().get_config_param('Main','LocalAddr-V6'))
        else:
            self.ip_address4 = ParseFormats.parse_ipaddress(Config().get_config_param('Main','LocalAddr-V4'))

        # Gets default ports (origin, destination)
        self.local_port = ParseFormats.parse_uint16(Config().get_config_param('Main','LocalPort'))
        self.protocol = ParseFormats.parse_uint8( Config().get_config_param('Main','DefaultProtocol'))
        self.life_time = ParseFormats.parse_uint8( Config().get_config_param('Main','LifeTime'))
        self.inmediate_start = ParseFormats.parse_bool( Config().get_config_param('Main','ImmediateStart'))
Beispiel #8
0
 def _load_auctions(self):
     """
     Loads auctions from file
     :return:
     """
     self.logger.debug("Starting _load_auctions")
     auction_file = Config().get_config_param('Main', 'AuctionFile')
     base_dir = pathlib.Path(__file__).parent.parent
     auction_file = base_dir / 'xmls' / auction_file
     auction_file = str(auction_file)
     handle = HandleLoadAuction(auction_file, 0)
     handle.start()
     self.logger.debug("Ending _load_auctions")
Beispiel #9
0
    def __init__(self, domain: int):

        super(BiddingObjectManager, self).__init__(domain)
        self.index_by_session: DefaultDict[str, list] = defaultdict(list)
        self.index_by_parent: DefaultDict[str, list] = defaultdict(list)
        self.logger = log().get_logger()
        try:
            self.store_objects = Config().get_config_param(
                'Main', 'StoreObjects')
        except ValueError:
            self.store_objects = False  # by default does not store objects.

        pass
    def __init__(self):

        self.domain = Config().get_config_param('Main', 'Domain')
        use_ipv6 = Config().get_config_param('Main', 'UseIPv6')
        self.use_ipv6 = ParseFormats.parse_bool(use_ipv6)
        self.ip_address6 = ParseFormats.parse_ipaddress(
            Config().get_config_param('Main', 'LocalAddr-V6'))
        self.destination_address6 = ParseFormats.parse_ipaddress(
            Config().get_config_param('Main', 'DefaultDestinationAddr-V6'))
        self.ip_address4 = ParseFormats.parse_ipaddress(
            Config().get_config_param('Main', 'LocalAddr-V4'))
        self.destination_address4 = ParseFormats.parse_ipaddress(
            Config().get_config_param('Main', 'DefaultDestinationAddr-V4'))

        # Gets default ports (origin, destination)
        self.source_port = ParseFormats.parse_uint16(Config().get_config_param(
            'Main', 'DefaultSourcePort'))
        self.destination_port = ParseFormats.parse_uint16(
            Config().get_config_param('Main', 'DefaultDestinationPort'))
        self.protocol = ParseFormats.parse_uint8(Config().get_config_param(
            'Main', 'DefaultProtocol'))
        self.life_time = ParseFormats.parse_uint8(Config().get_config_param(
            'Main', 'LifeTime'))
Beispiel #11
0
    async def test_parse(self):
        self.bidding_xml_file_parser = BiddingObjectXmlFileParser(10)
        self.config = Config('auction_agent.yaml')
        self.data_base = DataBaseManager(
            self.config.get_config_param('DataBase', 'Type'),
            self.config.get_config_param('DataBase', 'Host'),
            self.config.get_config_param('DataBase', 'User'),
            self.config.get_config_param('DataBase', 'Password'),
            self.config.get_config_param('DataBase', 'Port'),
            self.config.get_config_param('DataBase', 'DbName'),
            self.config.get_config_param('DataBase', 'Minsize'),
            self.config.get_config_param('DataBase', 'Maxsize'))

        lst_bids = self.bidding_xml_file_parser.parse(
            "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_bids1.xml"
        )

        self.assertEqual(len(lst_bids), 1)
        bidding_object = lst_bids[0]
        bidding_object.set_session("session_1")
        self.assertEqual(bidding_object.get_parent_key(), "1.1")
        self.assertEqual(bidding_object.get_key(), "1.bid1")
        self.assertEqual(len(bidding_object.elements), 2)
        self.assertEqual(len(bidding_object.options), 2)

        # Verifies the first element
        element = bidding_object.elements['element1']
        self.assertEqual(element['quantity'].value, "1")

        # Verifies the first option
        option = bidding_object.options['option1']
        self.assertEqual(option['biddingduration'].value, "600")

        connect = await self.data_base.acquire()

        await bidding_object.store(connect)
Beispiel #12
0
    def _load_resources(self):
        """
        Loads resources from file
        :return:
        """
        self.logger.debug("Starting _load_resources")

        try:
            resource_file = Config().get_config_param('Main', 'ResourceFile')
            base_dir = pathlib.Path(__file__).parent.parent
            resource_file = base_dir / 'config' / resource_file
            handle = HandleLoadResourcesFromFile(resource_file, 0)
            handle.start()
        except Exception as e:
            self.logger.error("An error occours during load resource", str(e))
        self.logger.debug("Ending _load_resources")
Beispiel #13
0
    def parse(self, file_name: str) -> list:
        """
        parse resource request within the file given as parameter
        :param file_name file name including the absolute path of te file to parse.

        :return: list of resource request in the file
        """
        config = Config().get_config()

        if 'Main' not in config:
            raise ValueError("The main section was not defined in configuration option file")

        if 'ResourceRequestFileDtd' in config['Main']:
            the_dtd = config['Main']['ResourceRequestFileDtd']
        else:
            raise ValueError("The DTD ({}) configuration option does not exist!".format('ResourceRequestFileDtd'))

        base_dir = pathlib.Path(__file__).parent.parent
        the_dtd = base_dir / 'xmls' / the_dtd

        if not os.path.exists(the_dtd):
            raise ValueError("The DTD ({}) does not exist!".format(the_dtd))

        if 'TimeFormat' in config['Main']:
            time_format = config['Main']['TimeFormat']
        else:
            raise ValueError("The time format configuration option fos not exist")

        with open(the_dtd) as dtd_file:
            dtd = etree.DTD(dtd_file)
            tree = etree.parse(file_name)
            valid = dtd.validate(tree)

            if not valid:
                raise ValueError("XML given is invalid!")

            root = tree.getroot()
            g_set = root.get('ID').lower()

            resource_requests = []
            for item in root.iterchildren():
                if isinstance(item.tag, str):  # Only it takes xml nodes (remove comments).
                    if item.tag.lower() == "resource_request":
                        resource_request = self._parse_resource_request(item, g_set, time_format)
                        resource_requests.append(resource_request)

            return resource_requests
Beispiel #14
0
    def parse(self, file_name: str) -> list:
        """
        parse the auction with the file given as parameter
        :param file_name file name including the absolute path of te file to parse.

        :return: list of auctions in the file
        """

        the_dtd = Config().get_config_param('Main', 'AuctionFileDtd')
        base_dir = pathlib.Path(__file__).parent.parent
        the_dtd = base_dir / 'xmls' / the_dtd

        if not os.path.exists(the_dtd):
            raise ValueError("The DTD ({}) does not exist!".format(the_dtd))

        with open(the_dtd) as dtd_file:
            dtd = etree.DTD(dtd_file)
            tree = etree.parse(file_name)
            valid = dtd.validate(tree)

            if not valid:
                raise ValueError("XML given is invalid!")

            root = tree.getroot()
            g_set = root.get('ID').lower()

            ipap_template_container = IpapTemplateContainerSingleton()

            auctions = []
            for item in root.iterchildren():
                if isinstance(
                        item.tag,
                        str):  # Only it takes xml nodes (remove comments).
                    if item.tag.lower() == "global":
                        (global_misc_config,
                         global_actions) = self._parse_global_options(item)
                    elif item.tag.lower() == "auction":
                        auction, templates = self._parse_auction(
                            item, g_set, global_misc_config, global_actions,
                            self.field_container)
                        auctions.append(auction)
                        for template in templates:
                            ipap_template_container.add_template(template)

            return auctions
Beispiel #15
0
 def _initialize_managers(self):
     """
     Initializes managers used.
     :return:
     """
     self.logger.debug("Starting _initialize_managers")
     self.auction_manager = AuctionManager(self.domain)
     self.database_manager = DataBaseManager(
         Config().get_config_param('DataBase', 'Type'),
         Config().get_config_param('DataBase', 'Host'),
         Config().get_config_param('DataBase', 'User'),
         Config().get_config_param('DataBase', 'Password'),
         Config().get_config_param('DataBase', 'Port'),
         Config().get_config_param('DataBase', 'DbName'),
         Config().get_config_param('DataBase', 'MinSize'),
         Config().get_config_param('DataBase', 'MaxSize'))
     self.bidding_object_manager = BiddingObjectManager(self.domain)
     self.resource_request_manager = ResourceRequestManager(self.domain)
     self.auction_session_manager = AuctionSessionManager()
     self.logger.debug("Ending _initialize_managers")
Beispiel #16
0
    def _load_resources_request(self):
        """
        Loads resource request registered in file
        :return:
        """
        self.logger.debug("Starting _load_resources_request")
        resource_request_file = Config().get_config_param(
            'Main', 'ResourceRequestFile')
        base_dir = pathlib.Path(__file__).parent.parent
        resource_request_file = base_dir / 'xmls' / resource_request_file
        resource_request_file = str(resource_request_file)
        resource_requests = self.resource_request_manager.parse_resource_request_from_file(
            resource_request_file)

        self.logger.debug("Nbr resource requests to read:{0}".format(
            len(resource_requests)))

        # schedule the new events.
        for request in resource_requests:
            try:
                ret_start, ret_stop = self.resource_request_manager.add_resource_request(
                    request)
                for start in ret_start:
                    when = DateUtils().calculate_when(start)
                    handle_activate = HandleActivateResourceRequestInterval(
                        start, ret_start[start], when)
                    request.add_task(handle_activate)
                    handle_activate.start()

                for stop in ret_stop:
                    when = DateUtils().calculate_when(stop)
                    handle_remove = HandleRemoveResourceRequestInterval(
                        stop, ret_stop[stop], when)
                    request.add_task(handle_remove)
                    handle_remove.start()
            except ValueError as e:
                self.logger.error(str(e))
        self.logger.debug("Ending _load_resources_request")
Beispiel #17
0
    def setUp(self):
        try:
            print('starting setup')
            self.bids = {}

            # Load the module
            module_name = "progressive_second_price"
            module_directory = Config('auction_server.yaml').get_config_param(
                'AUMProcessor', 'ModuleDir')
            self.loader = ModuleLoader(module_directory, "AUMProcessor",
                                       module_name)

            domain = 1
            manager = BiddingObjectManager(domain)

            # Parse the bidding objects in file example_bids1.xml, it allocates the memory.
            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids1.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid = new_bids[0]
            self.bids[bid.get_key()] = bid

            # Parse the bidding objects in file example_bids2.xml, it allocates the memory.
            domain = 2
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids2.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid2 = new_bids[0]
            self.bids[bid2.get_key()] = bid2

            # Parse the bidding objects in file example_bids3.xml, it allocates the memory.
            domain = 3
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids3.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid3 = new_bids[0]
            self.bids[bid3.get_key()] = bid3

            # Parse the bidding objects in file example_bids4.xml, it allocates the memory.
            domain = 4
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids4.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid4 = new_bids[0]
            self.bids[bid4.get_key()] = bid4

            # Parse the bidding objects in file example_bids5.xml, it allocates the memory.
            domain = 5
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids5.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid5 = new_bids[0]
            self.bids[bid5.get_key()] = bid5

            # Parse the bidding objects in file example_bids6.xml, it allocates the memory.
            domain = 6
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids6.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid6 = new_bids[0]
            self.bids[bid6.get_key()] = bid6

            # Parse the bidding objects in file example_bids7.xml, it allocates the memory.
            domain = 7
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids7.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid7 = new_bids[0]
            self.bids[bid7.get_key()] = bid7

            # Parse the bidding objects in file example_bids8.xml, it allocates the memory.
            domain = 8
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids8.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid8 = new_bids[0]
            self.bids[bid8.get_key()] = bid8

            # Parse the bidding objects in file example_bids9.xml, it allocates the memory.
            domain = 9
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids9.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid9 = new_bids[0]
            self.bids[bid9.get_key()] = bid9

            # Parse the bidding objects in file example_bids10.xml, it allocates the memory.
            domain = 10
            manager = BiddingObjectManager(domain)

            filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids10.xml"
            new_bids = manager.parse_bidding_objects(filename)
            self.assertEqual(len(new_bids), 1)
            bid10 = new_bids[0]
            self.bids[bid10.get_key()] = bid10

            self.assertEqual(len(self.bids), 10)

            print('ending setup')
        except Exception as e:
            print(str(e))
 def __init__(self, file_name: str, seconds_to_start: float):
     super(HandleAddResourceRequest, self).__init__(seconds_to_start)
     self.config = Config().get_config()
     self.file_name = file_name
     self.client_data = ClientMainData()
     self.resource_request_manager = ResourceRequestManager(self.client_data.domain)
Beispiel #19
0
    async def test_handle_client_tear_down(self):

        domain = 11
        self.conf = Config('auction_server.yaml').get_config()
        module_directory = '/home/ns3/py_charm_workspace/paper_subastas/auction/proc_modules'
        self.auction_processor = AuctionProcessor(domain, module_directory)
        self.auction_xml_file_parser = AuctionXmlFileParser(domain)

        lst_auctions = self.auction_xml_file_parser.parse(
            "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_auctions3.xml")

        self.auction = lst_auctions[0]
        self.auction_processor.add_auction_process(self.auction)

        self.server_main_data = ServerMainData()

        session_key = '1010'
        ip_address = '127.0.0.1'

        session = Session(session_key, ip_address, self.server_main_data.local_port,
                          '127.0.0.1', 1010, self.server_main_data.protocol)

        self.client_connection = ClientConnection(session_key)
        self.client_connection.set_session(session)

        self.bidding_manager = BiddingObjectManager(domain)

        # Parse the bidding objects in file example_bids1.xml, it allocates the memory.
        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids1.xml"
        new_bids = self.bidding_manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid = new_bids[0]
        bid.set_session(session_key)

        handle_remove_bid_1 = HandleRemoveBiddingObject(self.client_connection, bid, 10)
        handle_remove_bid_1.start()
        bid.add_task(handle_remove_bid_1)

        await self.bidding_manager.add_bidding_object(bid)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid)

        # Parse the bidding objects in file example_bids2.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids2.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid2 = new_bids[0]
        bid2.set_session(session_key)

        handle_remove_bid_2 = HandleRemoveBiddingObject(self.client_connection, bid2, 11)
        handle_remove_bid_2.start()
        bid2.add_task(handle_remove_bid_2)

        await self.bidding_manager.add_bidding_object(bid2)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid2)

        # Parse the bidding objects in file example_bids3.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids3.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid3 = new_bids[0]
        bid3.set_session(session_key)

        handle_remove_bid_3 = HandleRemoveBiddingObject(self.client_connection, bid3, 11)
        handle_remove_bid_3.start()
        bid3.add_task(handle_remove_bid_3)

        await self.bidding_manager.add_bidding_object(bid3)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid3)

        # Parse the bidding objects in file example_bids4.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids4.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid4 = new_bids[0]
        bid4.set_session(session_key)

        handle_remove_bid_4 = HandleRemoveBiddingObject(self.client_connection, bid4, 11)
        handle_remove_bid_4.start()
        bid4.add_task(handle_remove_bid_4)

        await self.bidding_manager.add_bidding_object(bid4)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid4)

        # Parse the bidding objects in file example_bids5.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids5.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid5 = new_bids[0]
        bid5.set_session(session_key)

        handle_remove_bid_5 = HandleRemoveBiddingObject(self.client_connection, bid5, 11)
        handle_remove_bid_5.start()
        bid5.add_task(handle_remove_bid_5)

        await self.bidding_manager.add_bidding_object(bid5)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid5)

        # Parse the bidding objects in file example_bids6.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids6.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid6 = new_bids[0]
        bid6.set_session("1012")
        await self.bidding_manager.add_bidding_object(bid6)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid6)

        # Parse the bidding objects in file example_bids7.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids7.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid7 = new_bids[0]
        bid7.set_session("1012")
        await self.bidding_manager.add_bidding_object(bid7)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid7)

        # Parse the bidding objects in file example_bids8.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids8.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid8 = new_bids[0]
        bid8.set_session("1012")
        await self.bidding_manager.add_bidding_object(bid8)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid8)

        # Parse the bidding objects in file example_bids9.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids9.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid9 = new_bids[0]
        bid9.set_session("1012")
        await self.bidding_manager.add_bidding_object(bid9)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid9)

        # Parse the bidding objects in file example_bids10.xml, it allocates the memory.
        manager = BiddingObjectManager(domain)

        filename = "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_generalized_bids10.xml"
        new_bids = manager.parse_bidding_objects(filename)
        self.assertEqual(len(new_bids), 1)
        bid10 = new_bids[0]
        bid10.set_session("1012")
        await self.bidding_manager.add_bidding_object(bid10)
        self.auction_processor.add_bidding_object_to_auction_process(self.auction.get_key(), bid10)

        auction_process = self.auction_processor.get_auction_process(self.auction.get_key())
        bids = auction_process.get_bids()
        self.assertEqual(len(bids), 10)

        allocations = self.auction_processor.execute_auction(self.auction.get_key(), datetime.now(),
                                                             datetime.now() + timedelta(seconds=10))

        print('in test_handle_client_teardown')
        handle_client_teardown = HandleClientTearDown(self.client_connection)
        self.assertEqual(handle_client_teardown.bidding_manager.get_num_auctioning_objects(), 10)
        self.assertEqual(handle_client_teardown.auction_processor.get_number_auction_processes(), 1)
        await handle_client_teardown.start()

        self.assertEqual(handle_client_teardown.bidding_manager.get_num_auctioning_objects(), 5)
        self.assertEqual(handle_client_teardown.auction_processor.get_number_auction_processes(), 1)

        self.assertEqual(len(handle_client_teardown.auction_processor.get_auction_process(
            self.auction.get_key()).get_bids()), 5)
Beispiel #20
0
 def setUp(self):
     domain = 10
     self.conf = Config('auction_server.yaml').get_config()
     module_directory = '/home/ns3/py_charm_workspace/paper_subastas/auction/proc_modules'
     self.auction_processor = AuctionProcessor(domain, module_directory)
     self.auction_xml_file_parser = AuctionXmlFileParser(domain)
Beispiel #21
0
 def setUp(self):
     config = Config('auction_agent.yaml')
     self.resource_request_file_parser = ResourceRequestFileParser(10)