Ejemplo n.º 1
0
 def __init__(self, session: AuctionSession):
     super(HandleClientTearDown, self).__init__()
     self.session = session
     self.template_container = IpapTemplateContainerSingleton()
     self.server_main_data = ServerMainData()
     self.bidding_manager = BiddingObjectManager(
         self.server_main_data.domain)
     self.auction_processor = AuctionProcessor(self.server_main_data.domain)
     self.server_message_processor = ServerMessageProcessor()
Ejemplo n.º 2
0
 def __init__(self, session: AuctionSession, bidding_object: BiddingObject,
              periods_to_maintain: int, seconds_to_start: float):
     super(HandleRemoveBiddingObject, self).__init__(seconds_to_start)
     self.session = session
     self.bidding_object = bidding_object
     self.periods_to_maintain = periods_to_maintain
     self.server_main_data = ServerMainData()
     self.bidding_manager = BiddingObjectManager(
         self.server_main_data.domain)
     self.auction_manager = AuctionManager(self.server_main_data.domain)
     self.auction_processor = AuctionProcessor(self.server_main_data.domain)
Ejemplo n.º 3
0
 def __init__(self, session: AuctionSession, ipap_message: IpapMessage,
              seconds_to_start: float):
     super(HandleAddBiddingObjects, self).__init__(seconds_to_start)
     self.session = session
     self.ipap_message = ipap_message
     self.server_main_data = ServerMainData()
     self.server_message_processor = ServerMessageProcessor()
     self.bididing_manager = BiddingObjectManager(
         self.server_main_data.domain)
     self.auction_manager = AuctionManager(self.server_main_data.domain)
     self.template_container = IpapTemplateContainerSingleton()
     self.logger = log().get_logger()
Ejemplo n.º 4
0
class HandleRemoveBiddingObject(ScheduledTask):
    """
    Handles the removal of a bidding object. This removes the bidding object from the auction for bidding.
    """
    def __init__(self, session: AuctionSession, bidding_object: BiddingObject,
                 periods_to_maintain: int, seconds_to_start: float):
        super(HandleRemoveBiddingObject, self).__init__(seconds_to_start)
        self.session = session
        self.bidding_object = bidding_object
        self.periods_to_maintain = periods_to_maintain
        self.server_main_data = ServerMainData()
        self.bidding_manager = BiddingObjectManager(
            self.server_main_data.domain)
        self.auction_manager = AuctionManager(self.server_main_data.domain)
        self.auction_processor = AuctionProcessor(self.server_main_data.domain)

    async def _run_specific(self):
        try:
            self.logger.info("bidding object remove key: {0}".format(
                self.bidding_object.get_key()))

            # Wait for the bid to complete execution.
            if self.bidding_object.get_type() == AuctioningObjectType.BID:
                while self.bidding_object.get_execution_periods(
                ) <= self.periods_to_maintain:
                    self.logger.info(
                        "inactivate bidding object number of periods:{0}".
                        format(str(
                            self.bidding_object.get_execution_periods())))
                    # we have to wait for the process request to execute
                    await asyncio.sleep(1)

            auction = self.auction_manager.get_auction(
                self.bidding_object.get_parent_key())
            if auction.get_state() == AuctioningObjectState.ACTIVE:
                self.auction_processor.delete_bidding_object_from_auction_process(
                    auction.get_key(), self.bidding_object)
                self.bidding_manager.del_actioning_object(
                    self.bidding_object.get_key())
            else:
                raise ValueError("Auction {0} is not active".format(
                    auction.get_key()))

        except Exception as e:
            self.logger.error(str(e))
    def __init__(self, request_process_key: str, bidding_objects: List[BiddingObject], seconds_to_start: float):
        """
        Handles the generation of new bidding objects

        :param request_process_key: process key where the bidding objects have been generated
        :param bidding_objects: bidding object list to include
        :param seconds_to_start: seconds to wait for running the task.
        """
        super(HandledAddGenerateBiddingObject, self).__init__(seconds_to_start)
        self.request_process_key = request_process_key
        self.bidding_objects = bidding_objects
        self.client_data = ClientMainData()
        self.agent_processor = AgentProcessor(self.client_data.domain, '')
        self.auction_session_manager = AuctionSessionManager()
        self.auction_manager = AuctionManager(self.client_data.domain)
        self.agent_template_container = AgentTemplateContainerManager()
        self.bidding_manager = BiddingObjectManager(self.client_data.domain)
        self.message_processor = ClientMessageProcessor()
Ejemplo n.º 6
0
class HandleClientTearDown(ImmediateTask):
    """
    This class handles the message to teardown the client's session that arrives from an agent.
    """
    def __init__(self, session: AuctionSession):
        super(HandleClientTearDown, self).__init__()
        self.session = session
        self.template_container = IpapTemplateContainerSingleton()
        self.server_main_data = ServerMainData()
        self.bidding_manager = BiddingObjectManager(
            self.server_main_data.domain)
        self.auction_processor = AuctionProcessor(self.server_main_data.domain)
        self.server_message_processor = ServerMessageProcessor()

    def remove_bidding_object_from_processes(self,
                                             bidding_object: BiddingObject):
        """
        # remove a bidding object from all auction_processes

        :param bidding_object: bidding object to disassociate
        :return:
        """
        keys = bidding_object.get_participating_auction_processes().copy()
        for key in keys:
            self.auction_processor.delete_bidding_object_from_auction_process(
                key, bidding_object)

    async def _run_specific(self, **kwargs):
        try:

            bidding_object_keys = copy.deepcopy(
                self.bidding_manager.get_bidding_objects_by_session(
                    self.session.get_key()))

            for bidding_object_key in bidding_object_keys:
                bidding_object = self.bidding_manager.get_bidding_object(
                    bidding_object_key)
                self.remove_bidding_object_from_processes(bidding_object)
                await bidding_object.stop_tasks()
                self.bidding_manager.delete_bidding_object(bidding_object_key)

        except ValueError:
            # This means that the session does not have bidding objects associated
            pass
    def __init__(self, auction: Auction):
        """
        Handles the removal of an auction

        :param auction: auction to remove.
        :param seconds_to_start: seconds to wait for running the task.
        """
        super(HandleAuctionRemove, self).__init__()
        self.client_data = ClientMainData()
        self.auction_manager = AuctionManager(self.client_data.domain)
        self.bidding_object_manager = BiddingObjectManager(self.client_data.domain)
        self.agent_processor = AgentProcessor(self.client_data.domain, '')
        self.auction = auction
class HandleRemoveBiddingObjectByAuction(ImmediateTask):
    """
    This class remove all bidding objects that was created for an auction.
    """

    def __init__(self, auction: Auction):
        super(HandleRemoveBiddingObjectByAuction, self).__init__()
        self.client_data = ClientMainData()
        self.bidding_object_manager = BiddingObjectManager(self.client_data.domain)
        self.auction = auction

    async def _run_specific(self):
        """
        delete all binding objects related with the auction

        :return:
        """
        bidding_object_keys = deepcopy(
            self.bidding_object_manager.get_bidding_objects_by_parent(self.auction.get_key()))
        for bidding_object_key in bidding_object_keys:
            self.logger.info("removing bidding object: {0}".format(bidding_object_key))
            bidding_object = self.bidding_object_manager.get_bidding_object(bidding_object_key)
            await bidding_object.stop_tasks()
            self.bidding_object_manager.delete_bidding_object(bidding_object_key)
class HandleRemoveBiddingObject(ScheduledTask):
    """
    Handles the removal of a bidding object. This removes the bidding object from the auction for bidding.
    """

    def __init__(self, bidding_object: BiddingObject, seconds_to_start: float):
        super(HandleRemoveBiddingObject, self).__init__(seconds_to_start)
        self.bidding_object = bidding_object
        self.server_main_data = ClientMainData()
        self.bidding_manager = BiddingObjectManager(self.server_main_data.domain)
        self.auction_manager = AuctionManager(self.server_main_data.domain)

    async def _run_specific(self):
        try:
            self.logger.info("starting HandleRemoveBiddingObject key {0}".format(self.bidding_object.get_key()))
            auction = self.auction_manager.get_auction(self.bidding_object.get_parent_key())
            if auction.get_state() == AuctioningObjectState.ACTIVE:
                await self.bidding_object.stop_tasks([self])
                self.bidding_manager.delete_bidding_object(self.bidding_object.get_key())
            else:
                raise ValueError("Auction {0} is not active".format(auction.get_key()))

        except Exception as e:
            self.logger.error(str(e))
Ejemplo n.º 10
0
    def __init__(self, auction: Auction, start: datetime,
                 seconds_to_start: float):
        """
        Creates the task

        :param auction:  auction to activate
        :param start:
        :param seconds_to_start: seconds when the auction should be activate
        """
        super(HandleAuctionExecution, self).__init__(seconds_to_start)
        self.auction = auction
        self.start_datetime = start
        self.server_main_data = ServerMainData()
        self.auction_processor = AuctionProcessor(self.server_main_data.domain)
        self.bidding_object_manager = BiddingObjectManager(
            self.server_main_data.domain)
Ejemplo n.º 11
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")
Ejemplo n.º 12
0
    def test_execute_auction(self):
        lst_auctions = self.auction_xml_file_parser.parse(
            "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_auctions3.xml")
        auction = lst_auctions[0]
        self.auction_processor.add_auction_process(auction)

        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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.get_key(), bid10)

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

        allocations = self.auction_processor.execute_auction(auction.get_key(), datetime.now(),
                                                             datetime.now() + timedelta(seconds=10))
        self.assertEqual(len(allocations), 10)
Ejemplo n.º 13
0
class HandleAddBiddingObjects(ScheduledTask):
    """
    This class handles adding a new bidding object sent from an agent to the server.
    """
    def __init__(self, session: AuctionSession, ipap_message: IpapMessage,
                 seconds_to_start: float):
        super(HandleAddBiddingObjects, self).__init__(seconds_to_start)
        self.session = session
        self.ipap_message = ipap_message
        self.server_main_data = ServerMainData()
        self.server_message_processor = ServerMessageProcessor()
        self.bididing_manager = BiddingObjectManager(
            self.server_main_data.domain)
        self.auction_manager = AuctionManager(self.server_main_data.domain)
        self.template_container = IpapTemplateContainerSingleton()
        self.logger = log().get_logger()

    async def _run_specific(self):
        """
        Adds bidding objects sent from an agent.
        """
        try:
            self.logger.debug("starting HandleAddBiddingObjects")
            # parse the message
            bidding_objects = self.bididing_manager.parse_ipap_message(
                self.ipap_message, self.template_container)

            # insert bidding objects to bidding object manager
            for bidding_object in bidding_objects:
                self.logger.info(
                    "receiving bidding object with key: {0}".format(
                        bidding_object.get_key()))
                bidding_object.set_session(self.session.get_key())
                self.bididing_manager.add_auctioning_object(bidding_object)
                i = 0
                num_options = len(bidding_object.options)
                for option_name in sorted(bidding_object.options.keys()):
                    interval = bidding_object.calculate_interval(option_name)
                    when = (interval.start - datetime.now()).total_seconds()
                    handle_activate = HandleActivateBiddingObject(
                        self.session, bidding_object, when)
                    handle_activate.start()
                    bidding_object.add_task(handle_activate)

                    auction = self.auction_manager.get_auction(
                        bidding_object.get_parent_key())

                    when = (interval.stop - datetime.now()).total_seconds()
                    # calculates the number of periods that should be active given the auction frequency
                    periods = math.ceil(when / auction.interval.duration)

                    if i < num_options - 1:
                        self.logger.info(
                            "scheduling bidding object inactivate when: {0}".
                            format(str(when)))
                        handle_inactivate = HandleInactivateBiddingObject(
                            self.session, bidding_object, periods, when)
                        handle_inactivate.start()
                        bidding_object.add_task(handle_inactivate)
                    else:
                        self.logger.info(
                            "scheduling bidding object remove when: {0}".
                            format(str(when)))
                        handle_inactivate = HandleRemoveBiddingObject(
                            self.session, bidding_object, periods, when)
                        handle_inactivate.start()
                        bidding_object.add_task(handle_inactivate)

                    i = i + 1

            # confirm the message
            confim_message = self.server_message_processor.build_ack_message(
                self.session.get_next_message_id(),
                self.ipap_message.get_seqno())
            await self.server_message_processor.send_message(
                self.session.get_connection(), confim_message.get_message())
            self.logger.debug("ending HandleAddBiddingObjects")
        except Exception as e:
            self.logger.error(str(e))
class HandledAddGenerateBiddingObject(ScheduledTask):

    def __init__(self, request_process_key: str, bidding_objects: List[BiddingObject], seconds_to_start: float):
        """
        Handles the generation of new bidding objects

        :param request_process_key: process key where the bidding objects have been generated
        :param bidding_objects: bidding object list to include
        :param seconds_to_start: seconds to wait for running the task.
        """
        super(HandledAddGenerateBiddingObject, self).__init__(seconds_to_start)
        self.request_process_key = request_process_key
        self.bidding_objects = bidding_objects
        self.client_data = ClientMainData()
        self.agent_processor = AgentProcessor(self.client_data.domain, '')
        self.auction_session_manager = AuctionSessionManager()
        self.auction_manager = AuctionManager(self.client_data.domain)
        self.agent_template_container = AgentTemplateContainerManager()
        self.bidding_manager = BiddingObjectManager(self.client_data.domain)
        self.message_processor = ClientMessageProcessor()

    async def _run_specific(self, **kwargs):
        try:
            # Gets the session
            session_key = self.agent_processor.get_session_for_request(self.request_process_key)
            session: AuctionSession = self.auction_session_manager.get_session(session_key)

            # Inserts the objects in the bidding object container
            for bidding_object in self.bidding_objects:
                self.logger.info("it is going to send bidding object: {0}".format(bidding_object.get_key()))
                bidding_object.set_process_request_key(self.request_process_key)
                interval: ResourceRequestInterval = session.get_resource_request_interval()
                bidding_object.set_resource_request_key(interval.get_resource_request_key())

                await self.bidding_manager.add_bidding_object(bidding_object)
                i = 0
                num_options = len(bidding_object.options)
                for option_name in sorted(bidding_object.options.keys()):
                    interval = bidding_object.calculate_interval(option_name)
                    when = (interval.start - datetime.now()).total_seconds()
                    handle_activate = HandleActivateBiddingObject(bidding_object, when)
                    handle_activate.start()
                    bidding_object.add_task(handle_activate)

                    if i < num_options - 1:
                        when = (interval.stop - datetime.now()).total_seconds()
                        handle_inactivate = HandleInactivateBiddingObject(bidding_object, when)
                        bidding_object.add_task(handle_inactivate)
                        handle_inactivate.start()
                    else:
                        when = (interval.stop - datetime.now()).total_seconds()
                        handle_remove = HandleRemoveBiddingObject(bidding_object, when)
                        bidding_object.add_task(handle_remove)
                        handle_remove.start()

                    i = i + 1

            # Gets the server domain from the request process
            server_domain = self.agent_processor.get_server_domain(self.request_process_key)

            # Builds and sends the message
            template_container = self.agent_template_container.get_template_container(server_domain)
            ipap_message = self.bidding_manager.get_ipap_message(self.bidding_objects, template_container)
            ipap_message.set_seqno(session.get_next_message_id())
            ipap_message.set_ack_seq_no(0)
            session.add_pending_message(ipap_message)
            await self.message_processor.send_message(session.get_server_connnection(), ipap_message.get_message())

            for bidding_object in self.bidding_objects:
                self.logger.info("after sending bidding object: {0}".format(bidding_object.get_key()))

        except Exception as e:
            self.logger.error(str(e))
 def __init__(self, auction: Auction):
     super(HandleRemoveBiddingObjectByAuction, self).__init__()
     self.client_data = ClientMainData()
     self.bidding_object_manager = BiddingObjectManager(self.client_data.domain)
     self.auction = auction
 def __init__(self, bidding_object: BiddingObject, seconds_to_start: float):
     super(HandleRemoveBiddingObject, self).__init__(seconds_to_start)
     self.bidding_object = bidding_object
     self.server_main_data = ClientMainData()
     self.bidding_manager = BiddingObjectManager(self.server_main_data.domain)
     self.auction_manager = AuctionManager(self.server_main_data.domain)
Ejemplo n.º 17
0
    def test_add_bidding_object_to_auction_process(self):
        lst_auctions = self.auction_xml_file_parser.parse(
            "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_auctions3.xml")
        auction = lst_auctions[0]
        self.auction_processor.add_auction_process(auction)

        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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.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.auction_processor.add_bidding_object_to_auction_process(auction.get_key(), bid10)

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

        # test wrong bidding object- auction is not as an auction process.
        lst_auctions = self.auction_xml_file_parser.parse(
            "/home/ns3/py_charm_workspace/paper_subastas/auction/xmls/example_auctions1.xml")
        auction2 = lst_auctions[0]
        bidding_object_2 = BiddingObject(auction2, 'bidding_obj_2', {}, {})
        with self.assertRaises(ValueError):
            self.auction_processor.add_bidding_object_to_auction_process(auction.get_key(), bidding_object_2)

        with self.assertRaises(ValueError):
            self.auction_processor.add_bidding_object_to_auction_process(auction2.get_key(), bidding_object_2)
Ejemplo n.º 18
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))
Ejemplo n.º 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)