コード例 #1
0
ファイル: multi_response.py プロジェクト: ncdc/qpid
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.schema_count = _SCHEMAS_PER_AGENT
        self.obj_count = _OBJS_PER_AGENT
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_msg_size=_MAX_OBJS_PER_MSG)

        # Dynamically construct a management database
        for i in range(self.schema_count):
            _schema = SchemaObjectClass( _classId=SchemaClassId("MyPackage",
                                                                "MyClass-" + str(i)),
                                         _desc="A test data schema",
                                         _object_id_names=["index1", "index2"] )
            # add properties
            _schema.add_property( "index1", SchemaProperty(qmfTypes.TYPE_UINT8))
            _schema.add_property( "index2", SchemaProperty(qmfTypes.TYPE_LSTR))

            # these two properties are statistics
            _schema.add_property( "query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
            _schema.add_property( "method_call_count", SchemaProperty(qmfTypes.TYPE_UINT32))

            # These two properties can be set via the method call
            _schema.add_property( "set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_property( "set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

            # add method
            _meth = SchemaMethod( _desc="Method to set string and int in object." )
            _meth.add_argument( "arg_int", SchemaProperty(qmfTypes.TYPE_UINT32) )
            _meth.add_argument( "arg_str", SchemaProperty(qmfTypes.TYPE_LSTR) )
            _schema.add_method( "set_meth", _meth )

            # Add schema to Agent

            self.agent.register_object_class(_schema)

            # instantiate managed data objects matching the schema

            for j in range(self.obj_count):

                self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                                     _values={"index1":j,
                                                              "index2": "name-" + str(j),
                                                              "set_string": "UNSET",
                                                              "set_int": 0,
                                                              "query_count": 0,
                                                              "method_call_count": 0} ))

        self.running = False
        self.ready = Event()
コード例 #2
0
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.timeout = 3
        self.broker_url = broker_url
        self.notifier = _testNotifier()
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaEventClass(_classId=SchemaClassId(
            "MyPackage", "MyClass", stype=SchemaClassId.TYPE_EVENT),
                                   _desc="A test event schema")
        # add properties
        _schema.add_property("prop-1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("prop-2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # Add schema to Agent
        self.schema = _schema
        self.agent.register_object_class(_schema)

        self.running = False
        self.ready = Event()
コード例 #3
0
ファイル: events.py プロジェクト: ncdc/qpid
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.timeout = 3
        self.broker_url = broker_url
        self.notifier = _testNotifier()
        self.agent = Agent(name, _notifier=self.notifier, heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaEventClass(
            _classId=SchemaClassId("MyPackage", "MyClass", stype=SchemaClassId.TYPE_EVENT), _desc="A test event schema"
        )
        # add properties
        _schema.add_property("prop-1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("prop-2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # Add schema to Agent
        self.schema = _schema
        self.agent.register_object_class(_schema)

        self.running = False
        self.ready = Event()
コード例 #4
0
ファイル: subscriptions.py プロジェクト: binarycod3r/qpid
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_duration=10,
                           default_duration=7,
                           min_duration=5,
                           min_interval=1,
                           default_interval=2)

        # Management Database
        # - two different schema packages,
        # - two classes within one schema package
        # - multiple objects per schema package+class
        # - two "undescribed" objects

        # "package1/class1"

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "package1", "class1"),
                                    _desc="A test data schema - one",
                                    _object_id_names=["key"])

        _schema.add_property("key", SchemaProperty(qmfTypes.TYPE_LSTR))

        # note: count1 is continuous, count2 is not
        count1_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=True)
        _schema.add_property("count1", count1_prop)
        count2_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=False)
        _schema.add_property("count2", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p1c1_key1"},
                            _schema=_schema)
        _obj.set_value("count1", 0)
        _obj.set_value("count2", 0)
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p1c1_key2"},
                            _schema=_schema)
        _obj.set_value("count1", 9)
        _obj.set_value("count2", 10)
        self.agent.add_object(_obj)

        # "package1/class2"

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "package1", "class2"),
                                    _desc="A test data schema - two",
                                    _object_id_names=["name"])
        # add properties
        _schema.add_property("name", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("string1", SchemaProperty(qmfTypes.TYPE_LSTR))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"name": "p1c2_name1"},
                            _schema=_schema)
        _obj.set_value("string1", "a data string")
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"name": "p1c2_name2"},
                            _schema=_schema)
        _obj.set_value("string1", "another data string")
        self.agent.add_object(_obj)

        # "package2/class1"

        _schema = SchemaObjectClass(
            _classId=SchemaClassId("package2", "class1"),
            _desc="A test data schema - second package",
            _object_id_names=["key"])

        _schema.add_property("key", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("counter", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p2c1_key1"},
                            _schema=_schema)
        _obj.set_value("counter", 0)
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p2c1_key2"},
                            _schema=_schema)
        _obj.set_value("counter", 2112)
        self.agent.add_object(_obj)

        # add two "unstructured" objects to the Agent

        _obj = QmfAgentData(self.agent, _object_id="undesc-1")
        _obj.set_value("field1", "a value")
        _obj.set_value("field2", 2)
        _obj.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj.set_value("field4", ["a", "list", "value"])
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent, _object_id="undesc-2")
        _obj.set_value("key-1", "a value")
        _obj.set_value("key-2", 2)
        self.agent.add_object(_obj)

        self.running = False
        self.ready = Event()
コード例 #5
0
ファイル: subscriptions.py プロジェクト: binarycod3r/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_duration=10,
                           default_duration=7,
                           min_duration=5,
                           min_interval=1,
                           default_interval=2)

        # Management Database
        # - two different schema packages,
        # - two classes within one schema package
        # - multiple objects per schema package+class
        # - two "undescribed" objects

        # "package1/class1"

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "package1", "class1"),
                                    _desc="A test data schema - one",
                                    _object_id_names=["key"])

        _schema.add_property("key", SchemaProperty(qmfTypes.TYPE_LSTR))

        # note: count1 is continuous, count2 is not
        count1_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=True)
        _schema.add_property("count1", count1_prop)
        count2_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=False)
        _schema.add_property("count2", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p1c1_key1"},
                            _schema=_schema)
        _obj.set_value("count1", 0)
        _obj.set_value("count2", 0)
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p1c1_key2"},
                            _schema=_schema)
        _obj.set_value("count1", 9)
        _obj.set_value("count2", 10)
        self.agent.add_object(_obj)

        # "package1/class2"

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "package1", "class2"),
                                    _desc="A test data schema - two",
                                    _object_id_names=["name"])
        # add properties
        _schema.add_property("name", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("string1", SchemaProperty(qmfTypes.TYPE_LSTR))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"name": "p1c2_name1"},
                            _schema=_schema)
        _obj.set_value("string1", "a data string")
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"name": "p1c2_name2"},
                            _schema=_schema)
        _obj.set_value("string1", "another data string")
        self.agent.add_object(_obj)

        # "package2/class1"

        _schema = SchemaObjectClass(
            _classId=SchemaClassId("package2", "class1"),
            _desc="A test data schema - second package",
            _object_id_names=["key"])

        _schema.add_property("key", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("counter", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p2c1_key1"},
                            _schema=_schema)
        _obj.set_value("counter", 0)
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p2c1_key2"},
                            _schema=_schema)
        _obj.set_value("counter", 2112)
        self.agent.add_object(_obj)

        # add two "unstructured" objects to the Agent

        _obj = QmfAgentData(self.agent, _object_id="undesc-1")
        _obj.set_value("field1", "a value")
        _obj.set_value("field2", 2)
        _obj.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj.set_value("field4", ["a", "list", "value"])
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent, _object_id="undesc-2")
        _obj.set_value("key-1", "a value")
        _obj.set_value("key-2", 2)
        self.agent.add_object(_obj)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        self.notifier.indication()  # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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()

        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" %
                              wi.get_type())
                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)
コード例 #6
0
ファイル: events.py プロジェクト: ncdc/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.timeout = 3
        self.broker_url = broker_url
        self.notifier = _testNotifier()
        self.agent = Agent(name, _notifier=self.notifier, heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaEventClass(
            _classId=SchemaClassId("MyPackage", "MyClass", stype=SchemaClassId.TYPE_EVENT), _desc="A test event schema"
        )
        # add properties
        _schema.add_property("prop-1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("prop-2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # Add schema to Agent
        self.schema = _schema
        self.agent.register_object_class(_schema)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")
        # time.sleep(1)

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication()  # hmmm... collide with daemon???
        self.join(self.timeout)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    def run(self):
        # broker_url = "user/passwd@hostname:port"
        conn = qpid.messaging.Connection(self.broker_url)
        try:
            conn.open()
        except qpid.messaging.ConnectError, e:
            raise Skipped(e)

        self.agent.set_connection(conn)
        self.ready.set()

        counter = 1
        while self.running:
            # post an event every second
            event = QmfEvent.create(
                long(time.time() * 1000),
                QmfEvent.SEV_WARNING,
                {"prop-1": counter, "prop-2": str(datetime.datetime.utcnow())},
                _schema_id=self.schema.get_class_id(),
            )
            counter += 1
            self.agent.raise_event(event)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" % wi.get_type())
                self.agent.release_workitem(wi)
                wi = self.agent.get_next_workitem(timeout=0)
            self.notifier.wait_for_work(1)

        self.agent.remove_connection(self.timeout)
        self.agent.destroy(self.timeout)
コード例 #7
0
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "MyPackage", "MyClass"),
                                    _desc="A test data schema",
                                    _object_id_names=["index1", "index2"])
        # add properties
        _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property("query_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property("method_call_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property("set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod(_desc="Method to set string and int in object.")
        _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
        _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_method("set_meth", _meth)

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData(self.agent,
                             _schema=_schema,
                             _values={
                                 "index1": 100,
                                 "index2": "a name"
                             })
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object(_obj1)

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 99,
                             "index2": "another name",
                             "set_string": "UNSET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.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"])
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication()  # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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)
コード例 #8
0
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.schema_count = _SCHEMAS_PER_AGENT
        self.obj_count = _OBJS_PER_AGENT
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_msg_size=_MAX_OBJS_PER_MSG)

        # Dynamically construct a management database
        for i in range(self.schema_count):
            _schema = SchemaObjectClass(_classId=SchemaClassId(
                "MyPackage", "MyClass-" + str(i)),
                                        _desc="A test data schema",
                                        _object_id_names=["index1", "index2"])
            # add properties
            _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
            _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

            # these two properties are statistics
            _schema.add_property("query_count",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))
            _schema.add_property("method_call_count",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))

            # These two properties can be set via the method call
            _schema.add_property("set_string",
                                 SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_property("set_int",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))

            # add method
            _meth = SchemaMethod(
                _desc="Method to set string and int in object.")
            _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
            _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_method("set_meth", _meth)

            # Add schema to Agent

            self.agent.register_object_class(_schema)

            # instantiate managed data objects matching the schema

            for j in range(self.obj_count):

                self.agent.add_object(
                    QmfAgentData(self.agent,
                                 _schema=_schema,
                                 _values={
                                     "index1": j,
                                     "index2": "name-" + str(j),
                                     "set_string": "UNSET",
                                     "set_int": 0,
                                     "query_count": 0,
                                     "method_call_count": 0
                                 }))

        self.running = False
        self.ready = Event()
コード例 #9
0
ファイル: async_query.py プロジェクト: ncdc/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass( _classId=SchemaClassId("MyPackage", "MyClass"),
                                     _desc="A test data schema",
                                     _object_id_names=["index1", "index2"] )
        # add properties
        _schema.add_property( "index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property( "index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property( "query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property( "method_call_count", SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property( "set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod( _desc="Method to set string and int in object." )
        _meth.add_argument( "arg_int", SchemaProperty(qmfTypes.TYPE_UINT32) )
        _meth.add_argument( "arg_str", SchemaProperty(qmfTypes.TYPE_LSTR) )
        _schema.add_method( "set_meth", _meth )

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData( self.agent, _schema=_schema,
                              _values={"index1":100, "index2":"a name"})
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object( _obj1 )

        self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                             _values={"index1":99,
                                                      "index2": "another name",
                                                      "set_string": "UNSET",
                                                      "set_int": 0,
                                                      "query_count": 0,
                                                      "method_call_count": 0} ))

        self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                             _values={"index1":50,
                                                      "index2": "my name",
                                                      "set_string": "SET",
                                                      "set_int": 0,
                                                      "query_count": 0,
                                                      "method_call_count": 0} ))


        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.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"])
        _obj2.set_value("index1", 50)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01546")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 3)
        _obj2.set_value("field3", {"a":1, "map":2, "value":3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 51)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01544")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a":1, "map":2, "value":3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 49)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01543")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a":1, "map":2, "value":3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 48)
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication() # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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()

        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" % wi.get_type())
                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)
コード例 #10
0
ファイル: async_method.py プロジェクト: ncdc/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass( _classId=SchemaClassId("MyPackage", "MyClass"),
                                     _desc="A test data schema",
                                     _object_id_names=["index1", "index2"] )
        # add properties
        _schema.add_property( "index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property( "index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property( "query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property( "method_call_count", SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property( "set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod( _desc="Method to set string and int in object." )
        _meth.add_argument( "arg_int", SchemaProperty(qmfTypes.TYPE_UINT32) )
        _meth.add_argument( "arg_str", SchemaProperty(qmfTypes.TYPE_LSTR) )
        # the input value of cookie is returned in the response
        _meth.add_argument( "cookie", SchemaProperty(qmfTypes.TYPE_LSTR,
                                                     kwargs={"dir":"IO"}))
        _schema.add_method( "set_meth", _meth )

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData( self.agent, _schema=_schema,
                              _values={"index1":100, "index2":"a name"})
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object( _obj1 )

        self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                             _values={"index1":99, 
                                                      "index2": "another name",
                                                      "set_string": "UNSET",
                                                      "set_int": 0,
                                                      "query_count": 0,
                                                      "method_call_count": 0} ))

        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.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"])
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication() # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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)
コード例 #11
0
ファイル: multi_response.py プロジェクト: ncdc/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.schema_count = _SCHEMAS_PER_AGENT
        self.obj_count = _OBJS_PER_AGENT
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_msg_size=_MAX_OBJS_PER_MSG)

        # Dynamically construct a management database
        for i in range(self.schema_count):
            _schema = SchemaObjectClass( _classId=SchemaClassId("MyPackage",
                                                                "MyClass-" + str(i)),
                                         _desc="A test data schema",
                                         _object_id_names=["index1", "index2"] )
            # add properties
            _schema.add_property( "index1", SchemaProperty(qmfTypes.TYPE_UINT8))
            _schema.add_property( "index2", SchemaProperty(qmfTypes.TYPE_LSTR))

            # these two properties are statistics
            _schema.add_property( "query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
            _schema.add_property( "method_call_count", SchemaProperty(qmfTypes.TYPE_UINT32))

            # These two properties can be set via the method call
            _schema.add_property( "set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_property( "set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

            # add method
            _meth = SchemaMethod( _desc="Method to set string and int in object." )
            _meth.add_argument( "arg_int", SchemaProperty(qmfTypes.TYPE_UINT32) )
            _meth.add_argument( "arg_str", SchemaProperty(qmfTypes.TYPE_LSTR) )
            _schema.add_method( "set_meth", _meth )

            # Add schema to Agent

            self.agent.register_object_class(_schema)

            # instantiate managed data objects matching the schema

            for j in range(self.obj_count):

                self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                                     _values={"index1":j,
                                                              "index2": "name-" + str(j),
                                                              "set_string": "UNSET",
                                                              "set_int": 0,
                                                              "query_count": 0,
                                                              "method_call_count": 0} ))

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication() # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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()

        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" % wi.get_type())
                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)
コード例 #12
0
ファイル: agent_test.py プロジェクト: ncdc/qpid
class QmfTest(unittest.TestCase):
    def test_begin(self):
        print("!!! being test")

    def test_end(self):
        print("!!! end test")


#
# An example agent application
#


if __name__ == '__main__':
    _notifier = ExampleNotifier()
    _agent = Agent( "qmf.testAgent", _notifier=_notifier )

    # Dynamically construct a class schema

    _schema = SchemaObjectClass( _classId=SchemaClassId("MyPackage", "MyClass"),
                                 _desc="A test data schema",
                                 _object_id_names=["index1", "index2"] )
    # add properties
    _schema.add_property( "index1", SchemaProperty(qmfTypes.TYPE_UINT8))
    _schema.add_property( "index2", SchemaProperty(qmfTypes.TYPE_LSTR))

    # these two properties are statistics
    _schema.add_property( "query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
    _schema.add_property( "method_call_count", SchemaProperty(qmfTypes.TYPE_UINT32))

    # These two properties can be set via the method call
コード例 #13
0
ファイル: subscriptions.py プロジェクト: ncdc/qpid
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_duration=10,
                           default_duration=7,
                           min_duration=5,
                           min_interval=1,
                           default_interval=2)

        # Management Database
        # - two different schema packages,
        # - two classes within one schema package
        # - multiple objects per schema package+class
        # - two "undescribed" objects

        # "package1/class1"

        _schema = SchemaObjectClass( _classId=SchemaClassId("package1", "class1"),
                                     _desc="A test data schema - one",
                                     _object_id_names=["key"] )

        _schema.add_property( "key", SchemaProperty(qmfTypes.TYPE_LSTR))

        # note: count1 is continuous, count2 is not
        count1_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=True)
        _schema.add_property( "count1", count1_prop)
        count2_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=False)
        _schema.add_property( "count2", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData( self.agent,
                             _values={"key":"p1c1_key1"},
                             _schema=_schema)
        _obj.set_value("count1", 0)
        _obj.set_value("count2", 0)
        self.agent.add_object( _obj )

        _obj = QmfAgentData( self.agent, 
                             _values={"key":"p1c1_key2"},
                             _schema=_schema )
        _obj.set_value("count1", 9)
        _obj.set_value("count2", 10)
        self.agent.add_object( _obj )

        # "package1/class2"

        _schema = SchemaObjectClass( _classId=SchemaClassId("package1", "class2"),
                                     _desc="A test data schema - two",
                                     _object_id_names=["name"] )
        # add properties
        _schema.add_property( "name", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "string1", SchemaProperty(qmfTypes.TYPE_LSTR))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData( self.agent, 
                             _values={"name":"p1c2_name1"},
                             _schema=_schema )
        _obj.set_value("string1", "a data string")
        self.agent.add_object( _obj )

        _obj = QmfAgentData( self.agent, 
                             _values={"name":"p1c2_name2"},
                             _schema=_schema )
        _obj.set_value("string1", "another data string")
        self.agent.add_object( _obj )


        # "package2/class1"

        _schema = SchemaObjectClass( _classId=SchemaClassId("package2", "class1"),
                                     _desc="A test data schema - second package",
                                     _object_id_names=["key"] )

        _schema.add_property( "key", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "counter", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData( self.agent, 
                             _values={"key":"p2c1_key1"},
                             _schema=_schema )
        _obj.set_value("counter", 0)
        self.agent.add_object( _obj )

        _obj = QmfAgentData( self.agent, 
                             _values={"key":"p2c1_key2"},
                             _schema=_schema )
        _obj.set_value("counter", 2112)
        self.agent.add_object( _obj )


        # add two "unstructured" objects to the Agent

        _obj = QmfAgentData(self.agent, _object_id="undesc-1")
        _obj.set_value("field1", "a value")
        _obj.set_value("field2", 2)
        _obj.set_value("field3", {"a":1, "map":2, "value":3})
        _obj.set_value("field4", ["a", "list", "value"])
        self.agent.add_object(_obj)


        _obj = QmfAgentData(self.agent, _object_id="undesc-2")
        _obj.set_value("key-1", "a value")
        _obj.set_value("key-2", 2)
        self.agent.add_object(_obj)

        self.running = False
        self.ready = Event()
コード例 #14
0
ファイル: subscriptions.py プロジェクト: ncdc/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_duration=10,
                           default_duration=7,
                           min_duration=5,
                           min_interval=1,
                           default_interval=2)

        # Management Database
        # - two different schema packages,
        # - two classes within one schema package
        # - multiple objects per schema package+class
        # - two "undescribed" objects

        # "package1/class1"

        _schema = SchemaObjectClass( _classId=SchemaClassId("package1", "class1"),
                                     _desc="A test data schema - one",
                                     _object_id_names=["key"] )

        _schema.add_property( "key", SchemaProperty(qmfTypes.TYPE_LSTR))

        # note: count1 is continuous, count2 is not
        count1_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=True)
        _schema.add_property( "count1", count1_prop)
        count2_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=False)
        _schema.add_property( "count2", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData( self.agent,
                             _values={"key":"p1c1_key1"},
                             _schema=_schema)
        _obj.set_value("count1", 0)
        _obj.set_value("count2", 0)
        self.agent.add_object( _obj )

        _obj = QmfAgentData( self.agent, 
                             _values={"key":"p1c1_key2"},
                             _schema=_schema )
        _obj.set_value("count1", 9)
        _obj.set_value("count2", 10)
        self.agent.add_object( _obj )

        # "package1/class2"

        _schema = SchemaObjectClass( _classId=SchemaClassId("package1", "class2"),
                                     _desc="A test data schema - two",
                                     _object_id_names=["name"] )
        # add properties
        _schema.add_property( "name", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "string1", SchemaProperty(qmfTypes.TYPE_LSTR))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData( self.agent, 
                             _values={"name":"p1c2_name1"},
                             _schema=_schema )
        _obj.set_value("string1", "a data string")
        self.agent.add_object( _obj )

        _obj = QmfAgentData( self.agent, 
                             _values={"name":"p1c2_name2"},
                             _schema=_schema )
        _obj.set_value("string1", "another data string")
        self.agent.add_object( _obj )


        # "package2/class1"

        _schema = SchemaObjectClass( _classId=SchemaClassId("package2", "class1"),
                                     _desc="A test data schema - second package",
                                     _object_id_names=["key"] )

        _schema.add_property( "key", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "counter", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData( self.agent, 
                             _values={"key":"p2c1_key1"},
                             _schema=_schema )
        _obj.set_value("counter", 0)
        self.agent.add_object( _obj )

        _obj = QmfAgentData( self.agent, 
                             _values={"key":"p2c1_key2"},
                             _schema=_schema )
        _obj.set_value("counter", 2112)
        self.agent.add_object( _obj )


        # add two "unstructured" objects to the Agent

        _obj = QmfAgentData(self.agent, _object_id="undesc-1")
        _obj.set_value("field1", "a value")
        _obj.set_value("field2", 2)
        _obj.set_value("field3", {"a":1, "map":2, "value":3})
        _obj.set_value("field4", ["a", "list", "value"])
        self.agent.add_object(_obj)


        _obj = QmfAgentData(self.agent, _object_id="undesc-2")
        _obj.set_value("key-1", "a value")
        _obj.set_value("key-2", 2)
        self.agent.add_object(_obj)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        self.notifier.indication() # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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()

        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" % wi.get_type())
                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)
コード例 #15
0
class QmfTest(unittest.TestCase):
    def test_begin(self):
        print("!!! being test")

    def test_end(self):
        print("!!! end test")


#
# An example agent application
#

if __name__ == '__main__':
    _notifier = ExampleNotifier()
    _agent = Agent("qmf.testAgent", _notifier=_notifier)

    # Dynamically construct a class schema

    _schema = SchemaObjectClass(_classId=SchemaClassId("MyPackage", "MyClass"),
                                _desc="A test data schema",
                                _object_id_names=["index1", "index2"])
    # add properties
    _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
    _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

    # these two properties are statistics
    _schema.add_property("query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
    _schema.add_property("method_call_count",
                         SchemaProperty(qmfTypes.TYPE_UINT32))
コード例 #16
0
ファイル: async_query.py プロジェクト: binarycod3r/qpid
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "MyPackage", "MyClass"),
                                    _desc="A test data schema",
                                    _object_id_names=["index1", "index2"])
        # add properties
        _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property("query_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property("method_call_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property("set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod(_desc="Method to set string and int in object.")
        _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
        _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_method("set_meth", _meth)

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData(self.agent,
                             _schema=_schema,
                             _values={
                                 "index1": 100,
                                 "index2": "a name"
                             })
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object(_obj1)

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 99,
                             "index2": "another name",
                             "set_string": "UNSET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 50,
                             "index2": "my name",
                             "set_string": "SET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.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"])
        _obj2.set_value("index1", 50)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01546")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 3)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 51)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01544")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 49)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01543")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 48)
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication()  # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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()

        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" %
                              wi.get_type())
                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)
コード例 #17
0
ファイル: async_query.py プロジェクト: binarycod3r/qpid
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "MyPackage", "MyClass"),
                                    _desc="A test data schema",
                                    _object_id_names=["index1", "index2"])
        # add properties
        _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property("query_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property("method_call_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property("set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod(_desc="Method to set string and int in object.")
        _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
        _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_method("set_meth", _meth)

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData(self.agent,
                             _schema=_schema,
                             _values={
                                 "index1": 100,
                                 "index2": "a name"
                             })
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object(_obj1)

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 99,
                             "index2": "another name",
                             "set_string": "UNSET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 50,
                             "index2": "my name",
                             "set_string": "SET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.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"])
        _obj2.set_value("index1", 50)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01546")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 3)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 51)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01544")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 49)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01543")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 48)
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()
コード例 #18
0
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.timeout = 3
        self.broker_url = broker_url
        self.notifier = _testNotifier()
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaEventClass(_classId=SchemaClassId(
            "MyPackage", "MyClass", stype=SchemaClassId.TYPE_EVENT),
                                   _desc="A test event schema")
        # add properties
        _schema.add_property("prop-1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("prop-2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # Add schema to Agent
        self.schema = _schema
        self.agent.register_object_class(_schema)

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")
        # time.sleep(1)

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication()  # hmmm... collide with daemon???
        self.join(self.timeout)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    def run(self):
        # broker_url = "user/passwd@hostname:port"
        conn = qpid.messaging.Connection(self.broker_url)
        try:
            conn.open()
        except qpid.messaging.ConnectError, e:
            raise Skipped(e)

        self.agent.set_connection(conn)
        self.ready.set()

        counter = 1
        while self.running:
            # post an event every second
            event = QmfEvent.create(
                long(time.time() * 1000),
                QmfEvent.SEV_WARNING, {
                    "prop-1": counter,
                    "prop-2": str(datetime.datetime.utcnow())
                },
                _schema_id=self.schema.get_class_id())
            counter += 1
            self.agent.raise_event(event)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" %
                              wi.get_type())
                self.agent.release_workitem(wi)
                wi = self.agent.get_next_workitem(timeout=0)
            self.notifier.wait_for_work(1)

        self.agent.remove_connection(self.timeout)
        self.agent.destroy(self.timeout)
コード例 #19
0
ファイル: async_query.py プロジェクト: ncdc/qpid
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass( _classId=SchemaClassId("MyPackage", "MyClass"),
                                     _desc="A test data schema",
                                     _object_id_names=["index1", "index2"] )
        # add properties
        _schema.add_property( "index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property( "index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property( "query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property( "method_call_count", SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property( "set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property( "set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod( _desc="Method to set string and int in object." )
        _meth.add_argument( "arg_int", SchemaProperty(qmfTypes.TYPE_UINT32) )
        _meth.add_argument( "arg_str", SchemaProperty(qmfTypes.TYPE_LSTR) )
        _schema.add_method( "set_meth", _meth )

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData( self.agent, _schema=_schema,
                              _values={"index1":100, "index2":"a name"})
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object( _obj1 )

        self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                             _values={"index1":99,
                                                      "index2": "another name",
                                                      "set_string": "UNSET",
                                                      "set_int": 0,
                                                      "query_count": 0,
                                                      "method_call_count": 0} ))

        self.agent.add_object( QmfAgentData( self.agent, _schema=_schema,
                                             _values={"index1":50,
                                                      "index2": "my name",
                                                      "set_string": "SET",
                                                      "set_int": 0,
                                                      "query_count": 0,
                                                      "method_call_count": 0} ))


        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.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"])
        _obj2.set_value("index1", 50)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01546")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 3)
        _obj2.set_value("field3", {"a":1, "map":2, "value":3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 51)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01544")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a":1, "map":2, "value":3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 49)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01543")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a":1, "map":2, "value":3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 48)
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()
コード例 #20
0
class _agentApp(Thread):
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.schema_count = _SCHEMAS_PER_AGENT
        self.obj_count = _OBJS_PER_AGENT
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_msg_size=_MAX_OBJS_PER_MSG)

        # Dynamically construct a management database
        for i in range(self.schema_count):
            _schema = SchemaObjectClass(_classId=SchemaClassId(
                "MyPackage", "MyClass-" + str(i)),
                                        _desc="A test data schema",
                                        _object_id_names=["index1", "index2"])
            # add properties
            _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
            _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

            # these two properties are statistics
            _schema.add_property("query_count",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))
            _schema.add_property("method_call_count",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))

            # These two properties can be set via the method call
            _schema.add_property("set_string",
                                 SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_property("set_int",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))

            # add method
            _meth = SchemaMethod(
                _desc="Method to set string and int in object.")
            _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
            _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_method("set_meth", _meth)

            # Add schema to Agent

            self.agent.register_object_class(_schema)

            # instantiate managed data objects matching the schema

            for j in range(self.obj_count):

                self.agent.add_object(
                    QmfAgentData(self.agent,
                                 _schema=_schema,
                                 _values={
                                     "index1": j,
                                     "index2": "name-" + str(j),
                                     "set_string": "UNSET",
                                     "set_int": 0,
                                     "query_count": 0,
                                     "method_call_count": 0
                                 }))

        self.running = False
        self.ready = Event()

    def start_app(self):
        self.running = True
        self.start()
        self.ready.wait(10)
        if not self.ready.is_set():
            raise Exception("Agent failed to connect to broker.")

    def stop_app(self):
        self.running = False
        # wake main thread
        self.notifier.indication()  # hmmm... collide with daemon???
        self.join(10)
        if self.isAlive():
            raise Exception("AGENT DID NOT TERMINATE AS EXPECTED!!!")

    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()

        while self.running:
            self.notifier.wait_for_work(None)
            wi = self.agent.get_next_workitem(timeout=0)
            while wi is not None:
                logging.error("UNEXPECTED AGENT WORKITEM RECEIVED=%s" %
                              wi.get_type())
                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)