def purchase(self, messagePurchase, bid, quantity):

        # Copy basic data from the purchase message given as parameter.
        message = Message('')
        message.setMethod(Message.RECEIVE_PURCHASE)
        message.setParameter('Id', messagePurchase.getParameter('Id'))
        message.setParameter('Service',
                             messagePurchase.getParameter('Service'))

        # Set the rest of the data from the bid and quantity given as parameters.
        message.setParameter('Bid', bid.getId())
        message.setParameter('Quantity', str(quantity))
        for decisionVariable in (self._service)._decision_variables:
            value = ((self._service)._decision_variables[decisionVariable]
                     ).getSample(DecisionVariable.PDST_VALUE)
            message.setParameter(decisionVariable, str(value))
        messageResult = self.sendMessageMarket(message)

        # Check if message was succesfully received by the marketplace
        if messageResult.isMessageStatusOk():
            quantity = float(messageResult.getParameter("Quantity_Purchased"))
            return quantity
        else:
            # logger.error('Agent: %s - Period: %s - Purchase not received! Communication failed - Message: %s', self._list_vars['strId'], str(self._list_vars['Current_Period']), messageResult.__str__())
            raise ProviderException(
                'Purchase not received! Communication failed')
 def purchaseBasedOnProvidersBids(self, currentPeriod, serviceId, bid, quantity, fileResult):        
     ''' 
     The Purchase method assigns all the parameters and access provider ID
     to the message to be send to the Marketplace.
 	
     In the end, the function sends the message to the marketplace
     and checks if it was succesfully received. 
     
     Test: implemented.
     '''
     self.registerLog(fileResult, 'PurchaseBasedOnProvidersBids - Period:' + str(self.getCurrentPeriod()) + ':bidId:' + bid.getId() + ':qty_to_purchase:' + str(quantity))
     messagePurchase = Message('')
     messagePurchase.setMethod(Message.RECEIVE_PURCHASE)
     uuidId = uuid.uuid1()	# make a UUID based on the host ID and current time
     idStr = str(uuidId)
     messagePurchase.setParameter('Id', idStr)
     messagePurchase.setParameter('Service', serviceId)
     messagePurchase.setParameter('Bid', bid.getId())        
     messagePurchase.setParameter('Quantity', str(quantity))
     service = self._services[serviceId]
     for decisionVariable in service._decision_variables:
         value = float(bid.getDecisionVariable(decisionVariable))
         messagePurchase.setParameter(decisionVariable, str(value))
     messageResult = self.sendMessageMarketBuy(messagePurchase)
     # Check if message was succesfully received by the marketplace
     if messageResult.isMessageStatusOk():
         quantity = float(messageResult.getParameter("Quantity_Purchased"))
         self.registerLog(fileResult,'PurchaseBasedOnProvidersBids - Period: %s ' + str(currentPeriod) + ' - Purchase BidId:' + bid.getId() + ' purchase qty:' + str(quantity) )
         return quantity
     else:
         self.registerLog(fileResult,' Period: %s ' + str(currentPeriod) + ' - Purchase not received! Communication failed' )
         raise ProviderException('Purchase not received! Communication failed')
    def purchase(self, messagePurchase, serviceId, bid, quantity, fileResult):
        self.registerLog(fileResult, 'Starting Purchase - Period:' + str(self.getCurrentPeriod()) + ' - bidId:' + bid.getId() + ' -qty to purchase:' + str(quantity) )

        # Copy basic data from the purchase message given as parameter.
        message = Message('')
        message.setMethod(Message.RECEIVE_PURCHASE)
        message.setParameter('Id', messagePurchase.getParameter('Id'))
        message.setParameter('Service', messagePurchase.getParameter('Service'))
        
        # set the rest of the data from the bid and quantity given as parameters.
        message.setParameter('Bid', bid.getId())        
        message.setParameter('Quantity', str(quantity))
        service = self._services[serviceId]
        for decisionVariable in service._decision_variables:
            value = float(bid.getDecisionVariable(decisionVariable))
            message.setParameter(decisionVariable, str(value))
        messageResult = self.sendMessageMarketBuy(message)
        
        # Check if message was succesfully received by the marketplace
        if messageResult.isMessageStatusOk():
            quantity = float(messageResult.getParameter("Quantity_Purchased"))
            self.registerLog(fileResult,'Ending Purchase - Period:' + str(self.getCurrentPeriod()) + '- bidId:' + bid.getId() + 'qty_purchased:' + str(quantity) )
            return quantity
        else:
            self.registerLog(fileResult, 'Period: ' + str(self.getCurrentPeriod()) + '- Purchase not received! Communication failed - Message:' + messageResult.__str__())
            raise ProviderException('Purchase not received! Communication failed')
 def createPurchaseMessage(self, serviceId):
     messagePurchase = Message('')
     messagePurchase.setMethod(Message.RECEIVE_PURCHASE)
     uuidId = uuid.uuid1()	# make a UUID based on the host ID and current time
     idStr = str(uuidId)
     messagePurchase.setParameter('Id', idStr)
     messagePurchase.setParameter('Service', serviceId)
     return messagePurchase
 def createPurchaseMessage(self):
     messagePurchase = Message('')
     messagePurchase.setMethod(Message.RECEIVE_PURCHASE)
     uuidId = uuid.uuid1(
     )  # make a UUID based on the host ID and current time
     idStr = str(uuidId)
     messagePurchase.setParameter('Id', idStr)
     messagePurchase.setParameter('Service', self._service.getId())
     return messagePurchase
 def getServiceFromServer(self, serviceId):
     logger.debug('Starting getServiceFromServer Id:%s', self._list_vars['Id'])
     try: 
         connect = Message("")
         connect.setMethod(Message.GET_SERVICES)
         connect.setParameter("Service",serviceId)
         response = self.sendMessageClock(connect)
         if (response.isMessageStatusOk() ):
             logger.debug('ending  getServiceFromServer')
             return self.handleGetService(response.getBody())
     except FoundationException as e:
         raise FoundationException(e.__str__())
예제 #7
0
 def getServiceFromServer(self, serviceId):
     logger.debug('Starting getServiceFromServer Id:%s',
                  self._list_vars['Id'])
     try:
         connect = Message("")
         connect.setMethod(Message.GET_SERVICES)
         connect.setParameter("Service", serviceId)
         response = self.sendMessageClock(connect)
         if (response.isMessageStatusOk()):
             logger.debug('ending  getServiceFromServer')
             return self.handleGetService(response.getBody())
     except FoundationException as e:
         raise FoundationException(e.__str__())
예제 #8
0
 def AskBackhaulBids(self, serviceId):
     messageAsk = Message('')
     messageAsk.setMethod(Message.GET_BEST_BIDS)
     messageAsk.setParameter('Provider', self._list_vars['strId'])
     messageAsk.setParameter('Service', serviceId)
     messageResult = self.sendMessageMarketBuy(messageAsk)
     if messageResult.isMessageStatusOk():
         document = self.removeIlegalCharacters(messageResult.getBody())
         try:
             dom = xml.dom.minidom.parseString(document)
             return self.handleBestBids(dom)
         except Exception as e:
             raise FoundationException(str(e))
     else:
         raise FoundationException("Best bids not received")
 def AskBackhaulBids(self, serviceId):
     messageAsk = Message('')
     messageAsk.setMethod(Message.GET_BEST_BIDS)
     messageAsk.setParameter('Provider', self._list_vars['strId'])
     messageAsk.setParameter('Service', serviceId)
     messageResult = self.sendMessageMarketBuy(messageAsk)
     if messageResult.isMessageStatusOk():
         document = self.removeIlegalCharacters(messageResult.getBody())
         try:
             dom = xml.dom.minidom.parseString(document)
             return self.handleBestBids(dom)
         except Exception as e: 
             raise FoundationException(str(e))
     else:
         raise FoundationException("Best bids not received")
 def purchaseBasedOnProvidersBids(self, currentPeriod, serviceId, bid,
                                  quantity, fileResult):
     ''' 
     The Purchase method assigns all the parameters and access provider ID
     to the message to be send to the Marketplace.
 	
     In the end, the function sends the message to the marketplace
     and checks if it was succesfully received. 
     
     Test: implemented.
     '''
     self.registerLog(
         fileResult, 'PurchaseBasedOnProvidersBids - Period:' +
         str(self.getCurrentPeriod()) + ':bidId:' + bid.getId() +
         ':qty_to_purchase:' + str(quantity))
     messagePurchase = Message('')
     messagePurchase.setMethod(Message.RECEIVE_PURCHASE)
     uuidId = uuid.uuid1(
     )  # make a UUID based on the host ID and current time
     idStr = str(uuidId)
     messagePurchase.setParameter('Id', idStr)
     messagePurchase.setParameter('Service', serviceId)
     messagePurchase.setParameter('Bid', bid.getId())
     messagePurchase.setParameter('Quantity', str(quantity))
     service = self._services[serviceId]
     for decisionVariable in service._decision_variables:
         value = float(bid.getDecisionVariable(decisionVariable))
         messagePurchase.setParameter(decisionVariable, str(value))
     messageResult = self.sendMessageMarketBuy(messagePurchase)
     # Check if message was succesfully received by the marketplace
     if messageResult.isMessageStatusOk():
         quantity = float(messageResult.getParameter("Quantity_Purchased"))
         self.registerLog(
             fileResult, 'PurchaseBasedOnProvidersBids - Period: %s ' +
             str(currentPeriod) + ' - Purchase BidId:' + bid.getId() +
             ' purchase qty:' + str(quantity))
         return quantity
     else:
         self.registerLog(
             fileResult, ' Period: %s ' + str(currentPeriod) +
             ' - Purchase not received! Communication failed')
         raise ProviderException(
             'Purchase not received! Communication failed')
예제 #11
0
 def process_getUnitaryCost(self, message):
     logger.debug('Initiating process GetUnitaryCost')
     self.lock.acquire()
     try:
         bid = None
         agent_type = self._list_args['Type']
         if (( agent_type.getType() == AgentType.PROVIDER_ISP) 
            or ( agent_type.getType() == AgentType.PROVIDER_BACKHAUL)):
             bidId = message.getParameter("BidId")
             if bidId in self._list_args['Bids']:
                 bid = (self._list_args['Bids']).get(bidId)
             if bidId in self._list_args['Inactive_Bids']:
                 bid = (self._list_args['Inactive_Bids']).get(bidId)
             if (bid is not None):
                 unitary_cost = bid.getUnitaryCost()
                 message = Message('')
                 message.setMethod(Message.GET_UNITARY_COST)
                 message.setMessageStatusOk()
                 message.setParameter("UnitaryCost", str(unitary_cost))
             else:
                 message = Message('')
                 message.setMethod(Message.GET_UNITARY_COST)
                 message.setParameter("Status_Code", "310")
                 messageResponse.setParameter("Status_Description", "Bid is not from the provider")
         else:
             message = Message('')
             message.setMethod(Message.GET_UNITARY_COST)
             message.setParameter("Status_Code", "330")
             messageResponse.setParameter("Status_Description", "The agent is not a provider")
         self.send(message.__str__())
         logger.debug('Ending process GetUnitaryCost')
     finally:
        if self.testThread == True:
            time.sleep(2)
        self.lock.release()
예제 #12
0
    def purchase(self, messagePurchase, bid, quantity):
        
        # Copy basic data from the purchase message given as parameter.        
        message = Message('')
        message.setMethod(Message.RECEIVE_PURCHASE)
        message.setParameter('Id', messagePurchase.getParameter('Id'))
        message.setParameter('Service', messagePurchase.getParameter('Service'))
        
        # Set the rest of the data from the bid and quantity given as parameters.        
        message.setParameter('Bid', bid.getId())        
        message.setParameter('Quantity', str(quantity))
        for decisionVariable in (self._service)._decision_variables:
            value = ((self._service)._decision_variables[decisionVariable]).getSample(DecisionVariable.PDST_VALUE)
            message.setParameter(decisionVariable, str(value))
        messageResult = self.sendMessageMarket(message)

        # Check if message was succesfully received by the marketplace
        if messageResult.isMessageStatusOk():
            quantity = float(messageResult.getParameter("Quantity_Purchased"))
            return quantity
        else:
            # logger.error('Agent: %s - Period: %s - Purchase not received! Communication failed - Message: %s', self._list_vars['strId'], str(self._list_vars['Current_Period']), messageResult.__str__())
            raise ProviderException('Purchase not received! Communication failed')
예제 #13
0
 def build_message(self, port):
     logger.debug('Build messsage Id: %s', self._list_vars['Id'])
     port_message = Message("")
     port_message.setMethod(Message.SEND_PORT)
     port_message.setParameter("Port", str(port))
     agent_type = self._list_vars['Type']
     port_message.setParameter("Type", agent_type.getInterfaceName())
     logger.debug('Announcing type %s to servers', agent_type.getType())
     if ((agent_type.getType() == AgentType.PROVIDER_ISP)
             or (agent_type.getType() == AgentType.PROVIDER_BACKHAUL)):
         capacityType = self._list_vars['capacityControl']
         if (capacityType == 'B'):
             port_message.setParameter("CapacityType", "bid")
         else:
             port_message.setParameter("CapacityType", "bulk")
     return port_message
 def sendCapacityEdgeProvider(self, fileResult):
     '''
     Sends the capacity to the market server.
     '''
     self.registerLog(fileResult,"Initializing send capacity")    
     for resourceId in self._used_variables['resources']:
         resourceNode = (self._used_variables['resources'])[resourceId]
         message = Message('')
         message.setMethod(Message.SEND_AVAILABILITY)
         message.setParameter("Provider", self._list_vars['strId'])
         message.setParameter("Resource", resourceId)
         availableQty = resourceNode['InitCapacity'] - resourceNode['Capacity']
         self.registerLog(fileResult,"Capacity being sent:" + str(availableQty), Provider.INFO)
         message.setParameter("Quantity",str(availableQty))
         messageResult = self.sendMessageMarket(message)
         if messageResult.isMessageStatusOk():
             logger.info("Capacity tranmitted sucessfully")
         else:
             raise ProviderException('Capacity not received')
     self.registerLog(fileResult,"Ends send capacity")
 def create_connect_message(self, strID):
     connect = Message("")
     connect.setMethod(Message.CONNECT)
     connect.setParameter("Agent",strID)
     return connect
예제 #16
0
 def create_connect_message(self, strID):
     connect = Message("")
     connect.setMethod(Message.CONNECT)
     connect.setParameter("Agent", strID)
     return connect
예제 #17
0
    def to_message(self):
        messageBid = Message('')
        messageBid.setMethod(Message.RECEIVE_BID)
        messageBid.setParameter('Id', self._bidId)
        messageBid.setParameter('Provider', self._provider)
        messageBid.setParameter('Service', self._service)
        messageBid.setParameter('Status', self.getStatusStr())
        messageBid.setParameter('UnitaryProfit', str(self.getUnitaryProfit() ))
        messageBid.setParameter('UnitaryCost', str(self.getUnitaryCost() ))
        messageBid.setParameter('Capacity', str(self.getCapacity() ))
        messageBid.setParameter('CreationPeriod', str(self.getCreationPeriod() ))
        if (self._parent != None):
            messageBid.setParameter('ParentBid', self._parent.getId())
        else:
            messageBid.setParameter('ParentBid', ' ')
        for decisionVariable in self._decision_variables:
            messageBid.setParameter(decisionVariable, str(self._decision_variables[decisionVariable]))
        return messageBid
    
	'''