You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2008/10/11 00:18:43 UTC
svn commit: r703588 - in /incubator/qpid/trunk/qpid: cpp/src/qpid/agent/
cpp/src/qpid/management/ cpp/src/tests/ python/qpid/
Author: tross
Date: Fri Oct 10 15:18:42 2008
New Revision: 703588
URL: http://svn.apache.org/viewvc?rev=703588&view=rev
Log:
QPID-1350 - Object reference following in the QMF console API
Modified:
incubator/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementBroker.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h
incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp
incubator/qpid/trunk/qpid/python/qpid/qmfconsole.py
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp?rev=703588&r1=703587&r2=703588&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp Fri Oct 10 15:18:42 2008
@@ -403,9 +403,26 @@
ft.decode(inBuffer);
value = ft.get("_class");
- if (value.get() == 0 || !value->convertsTo<string>())
- {
- // TODO: Send completion with an error code
+ if (value.get() == 0 || !value->convertsTo<string>()) {
+ value = ft.get("_objectid");
+ if (value.get() == 0 || !value->convertsTo<string>())
+ return;
+
+ ObjectId selector(value->get<string>());
+ ManagementObjectMap::iterator iter = managementObjects.find(selector);
+ if (iter != managementObjects.end()) {
+ ManagementObject* object = iter->second;
+ Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
+ uint32_t outLen;
+
+ encodeHeader(outBuffer, 'g', sequence);
+ object->writeProperties(outBuffer);
+ object->writeStatistics(outBuffer, true);
+ outLen = MA_BUFFER_SIZE - outBuffer.available ();
+ outBuffer.reset ();
+ connThreadBody.sendBuffer(outBuffer, outLen, "amq.direct", replyTo);
+ }
+ sendCommandComplete(replyTo, sequence);
return;
}
@@ -413,11 +430,9 @@
for (ManagementObjectMap::iterator iter = managementObjects.begin();
iter != managementObjects.end();
- iter++)
- {
+ iter++) {
ManagementObject* object = iter->second;
- if (object->getClassName() == className)
- {
+ if (object->getClassName() == className) {
Buffer outBuffer(outputBuffer, MA_BUFFER_SIZE);
uint32_t outLen;
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementBroker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementBroker.cpp?rev=703588&r1=703587&r2=703588&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementBroker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementBroker.cpp Fri Oct 10 15:18:42 2008
@@ -828,34 +828,49 @@
ft.decode(inBuffer);
value = ft.get("_class");
- if (value.get() == 0 || !value->convertsTo<string>())
- {
- // TODO: Send completion with an error code
+ if (value.get() == 0 || !value->convertsTo<string>()) {
+ value = ft.get("_objectid");
+ if (value.get() == 0 || !value->convertsTo<string>())
+ return;
+
+ ObjectId selector(value->get<string>());
+ ManagementObjectMap::iterator iter = managementObjects.find(selector);
+ if (iter != managementObjects.end()) {
+ ManagementObject* object = iter->second;
+ Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
+ uint32_t outLen;
+
+ encodeHeader(outBuffer, 'g', sequence);
+ object->writeProperties(outBuffer);
+ object->writeStatistics(outBuffer, true);
+ outLen = MA_BUFFER_SIZE - outBuffer.available ();
+ outBuffer.reset ();
+ sendBuffer(outBuffer, outLen, dExchange, replyToKey);
+ }
+ sendCommandComplete(replyToKey, sequence);
return;
}
string className (value->get<string>());
- for (ManagementObjectMap::iterator iter = managementObjects.begin ();
- iter != managementObjects.end ();
- iter++)
- {
+ for (ManagementObjectMap::iterator iter = managementObjects.begin();
+ iter != managementObjects.end();
+ iter++) {
ManagementObject* object = iter->second;
- if (object->getClassName () == className)
- {
+ if (object->getClassName () == className) {
Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
uint32_t outLen;
- encodeHeader (outBuffer, 'g', sequence);
+ encodeHeader(outBuffer, 'g', sequence);
object->writeProperties(outBuffer);
object->writeStatistics(outBuffer, true);
outLen = MA_BUFFER_SIZE - outBuffer.available ();
outBuffer.reset ();
- sendBuffer (outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, outLen, dExchange, replyToKey);
}
}
- sendCommandComplete (replyToKey, sequence);
+ sendCommandComplete(replyToKey, sequence);
}
bool ManagementBroker::authorizeAgentMessageLH(Message& msg)
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp?rev=703588&r1=703587&r2=703588&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp Fri Oct 10 15:18:42 2008
@@ -57,15 +57,26 @@
ObjectId::ObjectId(std::istream& in) : agent(0)
{
-#define FIELDS 5
string text;
+ in >> text;
+ fromString(text);
+}
+
+ObjectId::ObjectId(const string& text) : agent(0)
+{
+ fromString(text);
+}
+
+void ObjectId::fromString(const string& text)
+{
+#define FIELDS 5
+ string copy(text.c_str());
char* cText;
char* field[FIELDS];
bool atFieldStart = true;
int idx = 0;
- in >> text;
- cText = const_cast<char*>(text.c_str());
+ cText = const_cast<char*>(copy.c_str());
for (char* cursor = cText; *cursor; cursor++) {
if (atFieldStart) {
if (idx >= FIELDS)
@@ -90,6 +101,7 @@
second = atoll(field[4]);
}
+
bool ObjectId::operator==(const ObjectId &other) const
{
uint64_t otherFirst = agent == 0 ? other.first : other.first & 0xffff000000000000LL;
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h?rev=703588&r1=703587&r2=703588&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h Fri Oct 10 15:18:42 2008
@@ -51,12 +51,14 @@
const AgentAttachment* agent;
uint64_t first;
uint64_t second;
+ void fromString(const std::string&);
public:
ObjectId() : agent(0), first(0), second(0) {}
ObjectId(framing::Buffer& buf) : agent(0) { decode(buf); }
ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint32_t bank, uint64_t object);
ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq, uint64_t object);
ObjectId(std::istream&);
+ ObjectId(const std::string&);
bool operator==(const ObjectId &other) const;
bool operator<(const ObjectId &other) const;
void encode(framing::Buffer& buffer);
Modified: incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp?rev=703588&r1=703587&r2=703588&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp Fri Oct 10 15:18:42 2008
@@ -28,7 +28,7 @@
using namespace qpid::framing;
using namespace qpid::management;
-QPID_AUTO_TEST_CASE(testObjectIdSerialize) {
+QPID_AUTO_TEST_CASE(testObjectIdSerializeStream) {
std::string text("0-10-4-2500-80000000000");
std::stringstream input(text);
@@ -40,6 +40,17 @@
BOOST_CHECK_EQUAL(text, output.str());
}
+QPID_AUTO_TEST_CASE(testObjectIdSerializeString) {
+ std::string text("0-10-4-2500-80000000000");
+
+ ObjectId oid(text);
+
+ std::stringstream output;
+ output << oid;
+
+ BOOST_CHECK_EQUAL(text, output.str());
+}
+
QPID_AUTO_TEST_CASE(testObjectIdEncode) {
char buffer[100];
Buffer msgBuf(buffer, 100);
Modified: incubator/qpid/trunk/qpid/python/qpid/qmfconsole.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/qmfconsole.py?rev=703588&r1=703587&r2=703588&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/qmfconsole.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/qmfconsole.py Fri Oct 10 15:18:42 2008
@@ -227,6 +227,7 @@
_key = <key> - supply a classKey from the list returned by getClasses.
_class = <name> - supply a class name as a string. If the class name exists
in multiple packages, a _package argument may also be supplied.
+ _objectId = <id> - get the object referenced by the object-id
If objects should be obtained from only one agent, use the following argument.
Otherwise, the query will go to all agents.
@@ -268,17 +269,20 @@
pname, cname, hash = None, kwargs["_class"], None
if "_package" in kwargs:
pname = kwargs["_package"]
- if cname == None:
- raise Exception("No class supplied, use '_schema', '_key', or '_class' argument")
- map = {}
- map["_class"] = cname
- if pname != None: map["_package"] = pname
- if hash != None: map["_hash"] = hash
+ if cname == None and "_objectId" not in kwargs:
+ raise Exception("No class supplied, use '_schema', '_key', '_class', or '_objectId' argument")
+ map = {}
self.getSelect = []
- for item in kwargs:
- if item[0] != '_':
- self.getSelect.append((item, kwargs[item]))
+ if "_objectId" in kwargs:
+ map["_objectid"] = kwargs["_objectId"].__repr__()
+ else:
+ map["_class"] = cname
+ if pname != None: map["_package"] = pname
+ if hash != None: map["_hash"] = hash
+ for item in kwargs:
+ if item[0] != '_':
+ self.getSelect.append((item, kwargs[item]))
self.getResult = []
for agent in agentList:
@@ -765,7 +769,7 @@
return 0
def __repr__(self):
- return "%d-%d-%d-%d-%x" % (self.getFlags(), self.getSequence(),
+ return "%d-%d-%d-%d-%d" % (self.getFlags(), self.getSequence(),
self.getBroker(), self.getBank(), self.getObject())
def index(self):
@@ -863,6 +867,12 @@
return lambda *args, **kwargs : self._invoke(name, args, kwargs)
for property, value in self._properties:
if name == property.name:
+ if property.type == 10: # Dereference references
+ deref = self._session.getObjects(_objectId=value)
+ if len(deref) != 1:
+ return None
+ else:
+ return deref[0]
return value
for statistic, value in self._statistics:
if name == statistic.name: