How to use the spade.AMS.AmsAgentDescription function in spade

To help you get started, we’ve selected a few spade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github javipalanca / spade / examples / unittests / amsTestCase.py View on Github external
def _process(self):

            aad = spade.AMS.AmsAgentDescription()
            #aad.setAID(spade.AID.aid(self.s+"@"+host,["xmpp://"+self.s+"@"+host]))
            aad.ownership = "UNITTEST" 
            self.myAgent.result = self.myAgent.modifyAgent(aad)

            aad = spade.AMS.AmsAgentDescription()
            aad.setAID(spade.AID.aid(self.s+"@"+host,["xmpp://"+self.s+"@"+host]))
            self.myAgent.search = self.myAgent.searchAgent(aad)
github javipalanca / spade / examples / unittests / amsTestCase.py View on Github external
def _process(self):

            aad = spade.AMS.AmsAgentDescription()
            aad.setAID(spade.AID.aid(self.s+"@"+host,["xmpp://"+self.s+"@"+host]))
            aad.ownership = "NOT_ALLOWED" 
            self.myAgent.result = self.myAgent.modifyAgent(aad)

            aad = spade.AMS.AmsAgentDescription()
            aad.setAID(spade.AID.aid(self.s+"@"+host,["xmpp://"+self.s+"@"+host]))
            self.myAgent.search = self.myAgent.searchAgent(aad)
github javipalanca / spade / examples / unittests / amsTestCase.py View on Github external
def _process(self):

            aad = spade.AMS.AmsAgentDescription()
            #aad.setAID(spade.AID.aid(self.s+"@"+host,["xmpp://"+self.s+"@"+host]))
            aad.ownership = "UNITTEST" 
            self.myAgent.result = self.myAgent.modifyAgent(aad)

            aad = spade.AMS.AmsAgentDescription()
            aad.setAID(spade.AID.aid(self.s+"@"+host,["xmpp://"+self.s+"@"+host]))
            self.myAgent.search = self.myAgent.searchAgent(aad)
github javipalanca / spade / spade / AMS.py View on Github external
def _process(self):
            #The AMS agrees and then informs dummy of the successful execution of the action
            error = False
            aad = None

            if "rdf" in self.msg.getLanguage().lower():
                rdf = True
            else:
                # Old ugly SL0
                rdf = False

            if not rdf:

                try:
                    aad = AmsAgentDescription(self.content.action.modify['ams-agent-description'])
                except Exception, err:
                    error = "(missing-argument ams-agent-description)"
                    self.myAgent.DEBUG("Modify: Missing argument in ams-agent-description", 'error', "ams")
                #print "aad: " + str(aad.getAID().getName())
                #print "aid: " + str(self.msg.getSender())

                # If there is no AID in the AAD, fill it with the sender of the message
                if aad.getAID() and aad.getAID().getName() is None:
                    aad.setAID(self.msg.getSender())
                    self.myAgent.DEBUG("Modify: Overwriting missing AID with sender AID " + str(self.msg.getSender()), 'warn', "ams")

                if aad and (not aad.getAID() == self.msg.getSender()):
                    error = "(unauthorised)"
                    self.myAgent.DEBUG("Modify: Unauthorised. AID does not match with sender", 'error', "ams")

                if error:
github javipalanca / spade / spade / AMS.py View on Github external
def _setup(self):

        self.agentdb = dict()

        AAD = AmsAgentDescription()
        AAD.name = self.getAID()
        AAD.ownership = "SPADE"
        AAD.state = "active"

        self.agentdb[self.getAID().getName()] = AAD

        if self.getDF():
            AAD = AmsAgentDescription()
            AAD.name = self.getDF()
            AAD.ownership = "SPADE"
            AAD.state = "active"
            self.agentdb[self.getDF().getName()] = AAD

        db = self.DefaultBehaviour()
        #db.setPeriod(0.25)
        #self.setDefaultBehaviour(db)
        mt = Behaviour.ACLTemplate()
        mt.setOntology("FIPA-Agent-Management")
        mt.setPerformative("request")
        mt.setProtocol('fipa-request')
        self.addBehaviour(db, Behaviour.MessageTemplate(mt))

        self.wui.start()
github javipalanca / spade / spade / AMS.py View on Github external
if "max-results" in self.content.action.search["search-constraints"]:
                        try:
                            max = int(self.content.action.search["search-constraints"]["max-results"])
                        except Exception, err:
                            error = '(internal-error "max-results is not an integer")'
                if error:
                    reply = self.msg.createReply()
                    reply.setSender(self.myAgent.getAID())
                    reply.setPerformative("failure")
                    reply.setContent("( " + self.msg.getContent() + error + ")")
                    self.myAgent.send(reply)
                    return -1

                result = []
                if "ams-agent-description" in self.content.action.search:
                    aad = AmsAgentDescription(self.content.action.search['ams-agent-description'])
                    for a in self.myAgent.agentdb.values():
                        if max >= 0:
                            if a.match(aad):
                                result.append(a)
                                max -= 1
                        else:
                            break

                else:
                    result = self.myAgent.agentdb.values()

                content = "((result "  # TODO: + self.msg.getContent()
                if len(result) > 0:
                    content += " (set "
                    for i in result:
                        content += str(i) + " "
github javipalanca / spade / spade / AMS.py View on Github external
max = int(co["fipa:action"]["constraints"])
                    except:
                        error = 'constraints-error'
                if error:
                    reply = self.msg.createReply()
                    reply.setSender(self.myAgent.getAID())
                    reply.setPerformative("failure")
                    co["fipa:error"] = error
                    reply.setContentObject(co)
                    self.myAgent.send(reply)
                    return -1

                # Search for the results
                result = []
                if "fipa:argument" in co["fipa:action"].keys() and co["fipa:action"]["fipa:argument"]:
                    aad = AmsAgentDescription(co=co["fipa:action"]["fipa:argument"])
                    for a in self.myAgent.agentdb.values():
                        if max >= 0:
                            if a.match(aad):
                                result.append(a)
                                max -= 1
                        else:
                            break
                else:
                    result = self.myAgent.agentdb.values()

                co2 = ContentObject(namespaces={"http://www.fipa.org/schemas/fipa-rdf0#": "fipa:"})
                co2["fipa:result"] = []
                for i in result:
                    co2["fipa:result"].append(i.asContentObject())
                reply.setContentObject(co2)
github javipalanca / spade / spade / AMS.py View on Github external
return 1

                else:
                    reply.setPerformative("failure")
                    reply.setContent("(" + self.msg.getContent() + "(not-registered))")
                    self.myAgent.send(reply)
                    #print aad.getAID().getName()
                    #print self.myAgent.agentdb
                    return -1

            else:
                #Language is RDF
                co = self.msg.getContentObject()
                if "fipa:argument" in co["fipa:action"].keys() and co["fipa:action"]["fipa:argument"]:
                    aad = AmsAgentDescription(co=co["fipa:action"]["fipa:argument"])
                else:
                    error = "missing-argument ams-agent-description"
                    self.myAgent.DEBUG("Modify: Missing argument in ams-agent-description", 'error', "ams")
                #print "aad: " + str(aad.getAID().getName())
                #print "aid: " + str(self.msg.getSender())

                # If there is no AID in the AAD, fill it with the sender of the message
                if aad.getAID() and aad.getAID().getName() is None:
                    self.myAgent.DEBUG("Modify: Overwriting missing AID with sender AID " + str(self.msg.getSender()), 'warn', "ams")
                    aad.setAID(self.msg.getSender())

                #An agent is only allowed to modify itself
                if aad and (not aad.getAID() == self.msg.getSender()):
                    error = "unauthorised"
                    self.myAgent.DEBUG("Modify: Unauthorised. AID does not match with sender", 'error', "ams")
github javipalanca / spade / spade / wui.py View on Github external
def notifyAMS(self):
        """Notify AMS of current AWUI URL"""
        #return
        from spade.AMS import AmsAgentDescription
        aad = AmsAgentDescription()
        aid = self.owner.getAID()
        try:
            ip = socket.gethostbyname_ex(socket.gethostname())[2][0]
        except:
            ip = "127.0.0.1"
        aid.addAddress("awui://" + str(ip) + ":" + str(self.port))
        aad.setAID(aid)
        self.owner.modifyAgent(aad)