Beispiel #1
0
    def run(self):
        # broker_url = "user/passwd@hostname:port"
        self.conn = qpid.messaging.Connection(self.broker_url)
        self.conn.open()
        self.agent.set_connection(self.conn)
        self.ready.set()

        # Agent application main processing loop
        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                if wi.get_type() == WorkItem.METHOD_CALL:
                    mc = wi.get_params()
                    if not isinstance(mc, MethodCallParams):
                        raise Exception("Unexpected method call parameters")

                    if mc.get_name() == "set_meth":
                        obj = self.agent.get_object(mc.get_object_id(),
                                                    mc.get_schema_id())
                        if obj is None:
                            error_info = QmfData.create(
                                {
                                    "code": -2,
                                    "description": "Bad Object Id."
                                },
                                _object_id="_error")
                            self.agent.method_response(wi.get_handle(),
                                                       _error=error_info)
                        else:
                            obj.inc_value("method_call_count")
                            if "arg_int" in mc.get_args():
                                obj.set_value("set_int",
                                              mc.get_args()["arg_int"])
                            if "arg_str" in mc.get_args():
                                obj.set_value("set_string",
                                              mc.get_args()["arg_str"])
                            self.agent.method_response(wi.get_handle(),
                                                       {"code": 0})
                    elif mc.get_name() == "a_method":
                        obj = self.agent.get_object(mc.get_object_id(),
                                                    mc.get_schema_id())
                        if obj is None:
                            error_info = QmfData.create(
                                {
                                    "code": -3,
                                    "description": "Unknown object id."
                                },
                                _object_id="_error")
                            self.agent.method_response(wi.get_handle(),
                                                       _error=error_info)
                        elif obj.get_object_id() != "01545":
                            error_info = QmfData.create(
                                {
                                    "code": -4,
                                    "description": "Unexpected id."
                                },
                                _object_id="_error")
                            self.agent.method_response(wi.get_handle(),
                                                       _error=error_info)
                        else:
                            args = mc.get_args()
                            if ("arg1" in args and args["arg1"] == 1
                                    and "arg2" in args
                                    and args["arg2"] == "Now set!"
                                    and "arg3" in args
                                    and args["arg3"] == 1966):
                                self.agent.method_response(
                                    wi.get_handle(), {"code": 0})
                            else:
                                error_info = QmfData.create(
                                    {
                                        "code": -5,
                                        "description": "Bad Args."
                                    },
                                    _object_id="_error")
                                self.agent.method_response(wi.get_handle(),
                                                           _error=error_info)
                    else:
                        error_info = QmfData.create(
                            {
                                "code": -1,
                                "description": "Unknown method call."
                            },
                            _object_id="_error")
                        self.agent.method_response(wi.get_handle(),
                                                   _error=error_info)

                self.agent.release_workitem(wi)
                wi = self.agent.get_next_workitem(timeout=0)

        if self.conn:
            self.agent.remove_connection(10)
        self.agent.destroy(10)
Beispiel #2
0
    # add an "unstructured" object to the Agent
    _obj2 = QmfAgentData(_agent, _object_id="01545")
    _obj2.set_value("field1", "a value")
    _obj2.set_value("field2", 2)
    _obj2.set_value("field3", {"a":1, "map":2, "value":3})
    _obj2.set_value("field4", ["a", "list", "value"])
    _agent.add_object(_obj2)


    ## Now connect to the broker

    _c = Connection("localhost")
    _c.connect()
    _agent.setConnection(_c)

    _error_data = QmfData.create({"code": -1, "description": "You made a boo-boo."})

    _done = False
    while not _done:
        # try:
        _notifier.waitForWork()

        _wi = _agent.get_next_workitem(timeout=0)
        while _wi:

            if _wi.get_type() == WorkItem.METHOD_CALL:
                mc = _wi.get_params()
            
                if mc.get_name() == "set_meth":
                    print("!!! Calling 'set_meth' on Object_id = %s" % mc.get_object_id())
                    print("!!! args='%s'" % str(mc.get_args()))
Beispiel #3
0
    def run(self):
        # broker_url = "user/passwd@hostname:port"
        self.conn = qpid.messaging.Connection(self.broker_url)
        self.conn.open()
        self.agent.set_connection(self.conn)
        self.ready.set()

        # Agent application main processing loop
        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                if wi.get_type() == WorkItem.METHOD_CALL:
                    mc = wi.get_params()
                    if not isinstance(mc, MethodCallParams):
                        raise Exception("Unexpected method call parameters")

                    if mc.get_name() == "set_meth":
                        obj = self.agent.get_object(mc.get_object_id(),
                                                    mc.get_schema_id())
                        if obj is None:
                            error_info = QmfData.create({"code": -2, 
                                                         "description":
                                                             "Bad Object Id."},
                                                        _object_id="_error")
                            self.agent.method_response(wi.get_handle(),
                                                       _error=error_info)
                        else:
                            obj.inc_value("method_call_count")
                            out_args = {"code" : 0}
                            if "cookie" in mc.get_args():
                                out_args["cookie"] = mc.get_args()["cookie"]
                            if "arg_int" in mc.get_args():
                                obj.set_value("set_int", mc.get_args()["arg_int"])
                            if "arg_str" in mc.get_args():
                                obj.set_value("set_string", mc.get_args()["arg_str"])
                            self.agent.method_response(wi.get_handle(),
                                                       out_args)
                    elif mc.get_name() == "a_method":
                        obj = self.agent.get_object(mc.get_object_id(),
                                                    mc.get_schema_id())
                        if obj is None:
                            error_info = QmfData.create({"code": -3, 
                                                         "description":
                                                             "Unknown object id."},
                                                        _object_id="_error")
                            self.agent.method_response(wi.get_handle(),
                                                       _error=error_info)
                        elif obj.get_object_id() != "01545":
                            error_info = QmfData.create( {"code": -4, 
                                                          "description":
                                                              "Unexpected id."},
                                                         _object_id="_error")
                            self.agent.method_response(wi.get_handle(),
                                                       _error=error_info)
                        else:
                            args = mc.get_args()
                            if ("arg1" in args and args["arg1"] == 1 and
                                "arg2" in args and args["arg2"] == "Now set!"
                                and "arg3" in args and args["arg3"] == 1966): 
                                out_args = {"code" : 0}
                                if "cookie" in mc.get_args():
                                    out_args["cookie"] = mc.get_args()["cookie"]
                                self.agent.method_response(wi.get_handle(),
                                                           out_args)
                            else:
                                error_info = QmfData.create(
                                    {"code": -5, 
                                     "description":
                                         "Bad Args."},
                                    _object_id="_error")
                                self.agent.method_response(wi.get_handle(),
                                                           _error=error_info)
                    else:
                        error_info = QmfData.create( {"code": -1, 
                                                     "description":
                                                         "Unknown method call."},
                                                     _object_id="_error")
                        self.agent.method_response(wi.get_handle(), _error=error_info)

                self.agent.release_workitem(wi)
                wi = self.agent.get_next_workitem(timeout=0)

        if self.conn:
            self.agent.remove_connection(10)
        self.agent.destroy(10)
Beispiel #4
0
    # add an "unstructured" object to the Agent
    _obj2 = QmfAgentData(_agent, _object_id="01545")
    _obj2.set_value("field1", "a value")
    _obj2.set_value("field2", 2)
    _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
    _obj2.set_value("field4", ["a", "list", "value"])
    _agent.add_object(_obj2)

    ## Now connect to the broker

    _c = Connection("localhost")
    _c.connect()
    _agent.setConnection(_c)

    _error_data = QmfData.create({
        "code": -1,
        "description": "You made a boo-boo."
    })

    _done = False
    while not _done:
        # try:
        _notifier.waitForWork()

        _wi = _agent.get_next_workitem(timeout=0)
        while _wi:

            if _wi.get_type() == WorkItem.METHOD_CALL:
                mc = _wi.get_params()

                if mc.get_name() == "set_meth":
                    print("!!! Calling 'set_meth' on Object_id = %s" %