def getServices(self):
     logger.debug('Starting get services Id:%s', self._list_vars['Id'])
     messageAsk = Message('')
     messageAsk.setMethod(Message.GET_SERVICES)
     messageResult = self.sendMessageClock(messageAsk)
     if messageResult.isMessageStatusOk():
         return self.handleGetServices(messageResult.getBody())
     else:
         raise FoundationException('Services not received! Communication failed')
     logger.debug('Ending get services Id:%s', self._list_vars['Id'])
Пример #2
0
 def getMessage(self, string_key):
     foundIdx =  (self._strings_received[string_key]).find("Method")
     if (foundIdx == 0):
         foundIdx2 =  (self._strings_received[string_key]).find("Method", foundIdx + 1)
         if (foundIdx2 != -1):
             message = Message( (self._strings_received[string_key])[foundIdx : foundIdx2 - 1])
             # Even that the message could have errors is complete
             self._strings_received[string_key] = (self._strings_received[string_key])[foundIdx2 : ]
         else:
             message = Message((self._strings_received[string_key]))
             try:
                 isComplete = message.isComplete( len(self._strings_received[string_key]) )
                 if (isComplete):
                     (self._strings_received[string_key]) = ''
                 else:
                     message = None
             except FoundationException as e:
                 message = None
     else:
         if (len(self._strings_received[string_key]) == 0):
             message = None
         else:
             # The message is not well formed, so we create a message with method not specified
             message = Message('')
             message.setMethod(Message.UNDEFINED)
             (self._strings_received[string_key])[foundIdx : ]
     return message
Пример #3
0
 def getServices(self):
     logger.debug('Starting get services Id:%s', self._list_vars['Id'])
     messageAsk = Message('')
     messageAsk.setMethod(Message.GET_SERVICES)
     messageResult = self.sendMessageClock(messageAsk)
     if messageResult.isMessageStatusOk():
         return self.handleGetServices(messageResult.getBody())
     else:
         raise FoundationException(
             'Services not received! Communication failed')
     logger.debug('Ending get services Id:%s', self._list_vars['Id'])
 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__())
 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 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
Пример #7
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 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 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")
Пример #10
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__())
 def create_connect_message(self, strID):
     connect = Message("")
     connect.setMethod(Message.CONNECT)
     connect.setParameter("Agent",strID)
     return connect
Пример #12
0
 def sendMessageClock(self, message):
     response = Message('')
     if self._channelClockServer != None:
         response = (self._channelClockServer).sendMessage(message)
     return response
Пример #13
0
 def sendMessageMarketBuy(self, message):
     response = Message('')
     if self._channelMarketPlaceBuy != None:
         response = (self._channelMarketPlaceBuy).sendMessage(message)
     return response
    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')
Пример #15
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')
 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 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')
Пример #18
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')
Пример #19
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()
Пример #20
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
Пример #21
0
 def create_connect_message(self, strID):
     connect = Message("")
     connect.setMethod(Message.CONNECT)
     connect.setParameter("Agent", strID)
     return connect
Пример #22
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
    
	'''