Author: justi9
Date: 2007-11-26 17:43:50 -0500 (Mon, 26 Nov 2007)
New Revision: 1362
Added:
mgmt/mint/Makefile
Removed:
mgmt/mint/python/mint/config.xml
Modified:
mgmt/mint/python/mint/schema.sql
mgmt/mint/python/mint/schemaparser.py
Log:
Changes schemaparser.py and SchemaParser to to take arguments.
Adds a Makefile to generate schema.py and schema.sql. Run "make schema"
inside the mint dir to regenerate everything.
Regenerates schema.sql, as I think I messed it up earlier.
Added: mgmt/mint/Makefile
===================================================================
--- mgmt/mint/Makefile (rev 0)
+++ mgmt/mint/Makefile 2007-11-26 22:43:50 UTC (rev 1362)
@@ -0,0 +1,14 @@
+.phony: message schema schema-sql schema-python
+
+dsn := "postgresql://localhost/"
+
+message:
+ @echo "Run \"make schema\" to regenerate the schema from
xml/MgmtSchema.xml"
+
+schema: schema-python schema-sql
+
+schema-python:
+ python python/mint/schemaparser.py xml/MgmtSchema.xml python/mint/schema.py ${dsn}
+
+schema-sql:
+ sqlobject-admin sql -m mint.schema -c ${dsn} | sed -e '1,2d' >
python/mint/schema.sql
Deleted: mgmt/mint/python/mint/config.xml
===================================================================
--- mgmt/mint/python/mint/config.xml 2007-11-26 21:50:03 UTC (rev 1361)
+++ mgmt/mint/python/mint/config.xml 2007-11-26 22:43:50 UTC (rev 1362)
@@ -1,5 +0,0 @@
-<config>
- <configOption name="dsn" value="postgresql://localhost/" />
- <configOption name="pythonOutput" value="schema.py" />
- <configOption name="schemaXML" value="xml/MgmtSchema.xml" />
-</config>
Modified: mgmt/mint/python/mint/schema.sql
===================================================================
--- mgmt/mint/python/mint/schema.sql 2007-11-26 21:50:03 UTC (rev 1361)
+++ mgmt/mint/python/mint/schema.sql 2007-11-26 22:43:50 UTC (rev 1362)
@@ -1,24 +1,433 @@
-These classes do not have connections set:
- * Binding
- * BindingStats
- * Broker
- * BrokerStats
- * Client
- * ClientStats
- * Consumer
- * ConsumerStats
- * Destination
- * DestinationStats
- * Exchange
- * ExchangeStats
- * Producer
- * ProducerStats
- * Queue
- * QueueStats
- * Session
- * SessionStats
- * System
- * SystemStats
- * Vhost
- * VhostStats
-You must indicate --connection=URI
+CREATE TABLE binding (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ queue_id INT,
+ exchange_id INT,
+ binding_key VARCHAR(1000)
+);
+
+CREATE TABLE binding_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ binding_id INT,
+ msg_matched BIGINT
+);
+
+CREATE TABLE broker (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ system_id INT,
+ port SMALLINT,
+ worker_threads SMALLINT,
+ max_conns SMALLINT,
+ conn_backlog SMALLINT,
+ staging_threshold INT,
+ store_lib VARCHAR(1000),
+ async_store BOOL,
+ mgmt_pub_interval SMALLINT,
+ initial_disk_page_size INT,
+ initial_pages_per_queue INT,
+ cluster_name VARCHAR(1000),
+ version VARCHAR(1000)
+);
+
+CREATE TABLE broker_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ broker_id INT
+);
+
+CREATE TABLE client (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ vhost_id INT,
+ ip_addr INT,
+ port SMALLINT
+);
+
+CREATE TABLE client_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ client_id INT,
+ auth_identity VARCHAR(1000),
+ msgs_produced BIGINT,
+ msgs_consumed BIGINT,
+ bytes_produced BIGINT,
+ bytes_consumed BIGINT
+);
+
+CREATE TABLE consumer (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ destination_id INT,
+ queue_id INT
+);
+
+CREATE TABLE consumer_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ consumer_id INT,
+ msgs_consumed BIGINT,
+ bytes_consumed BIGINT,
+ unacked_messages INT,
+ unacked_messages_low INT,
+ unacked_messages_high INT
+);
+
+CREATE TABLE destination (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ session_id INT,
+ name VARCHAR(1000)
+);
+
+CREATE TABLE destination_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ destination_id INT,
+ flow_mode SMALLINT,
+ max_msg_credits INT,
+ max_byte_credits INT,
+ msg_credits INT,
+ byte_credits INT
+);
+
+CREATE TABLE exchange (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ vhost_id INT,
+ name VARCHAR(1000),
+ type VARCHAR(1000)
+);
+
+CREATE TABLE exchange_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ exchange_id INT,
+ producers INT,
+ producers_low INT,
+ producers_high INT,
+ bindings INT,
+ bindings_low INT,
+ bindings_high INT,
+ msg_receives BIGINT,
+ msg_drops BIGINT,
+ msg_routes BIGINT,
+ byte_receives BIGINT,
+ byte_drops BIGINT,
+ byte_routes BIGINT
+);
+
+CREATE TABLE producer (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ destination_id INT,
+ exchange_id INT
+);
+
+CREATE TABLE producer_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ producer_id INT,
+ msgs_produced BIGINT,
+ bytes_produced BIGINT
+);
+
+CREATE TABLE queue (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ vhost_id INT,
+ name VARCHAR(1000),
+ durable BOOL,
+ auto_delete BOOL,
+ exclusive BOOL,
+ page_memory_limit INT
+);
+
+CREATE TABLE queue_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ queue_id INT,
+ journal_location VARCHAR(1000),
+ journal_base_file_name VARCHAR(1000),
+ journal_initial_file_count INT,
+ journal_current_file_count INT,
+ journal_data_file_size INT,
+ journal_free_file_count INT,
+ journal_free_file_count_low INT,
+ journal_free_file_count_high INT,
+ journal_available_file_count INT,
+ journal_available_file_count_low INT,
+ journal_available_file_count_high INT,
+ journal_record_depth INT,
+ journal_record_depth_low INT,
+ journal_record_depth_high INT,
+ journal_record_enqueues BIGINT,
+ journal_record_dequeues BIGINT,
+ journal_write_wait_failures BIGINT,
+ journal_write_busy_failures BIGINT,
+ journal_read_record_count BIGINT,
+ journal_read_busy_failures BIGINT,
+ journal_write_page_cache_depth INT,
+ journal_write_page_cache_depth_low INT,
+ journal_write_page_cache_depth_high INT,
+ journal_write_page_size INT,
+ journal_read_page_cache_depth INT,
+ journal_read_page_cache_depth_low INT,
+ journal_read_page_cache_depth_high INT,
+ journal_read_page_size INT,
+ msg_total_enqueues BIGINT,
+ msg_total_dequeues BIGINT,
+ msg_txn_enqueues BIGINT,
+ msg_txn_dequeues BIGINT,
+ msg_persist_enqueues BIGINT,
+ msg_persist_dequeues BIGINT,
+ msg_depth INT,
+ msg_depth_low INT,
+ msg_depth_high INT,
+ byte_total_enqueues BIGINT,
+ byte_total_dequeues BIGINT,
+ byte_txn_enqueues BIGINT,
+ byte_txn_dequeues BIGINT,
+ byte_persist_enqueues BIGINT,
+ byte_persist_dequeues BIGINT,
+ byte_depth INT,
+ byte_depth_low INT,
+ byte_depth_high INT,
+ enqueue_txn_starts BIGINT,
+ enqueue_txn_commits BIGINT,
+ enqueue_txn_rejects BIGINT,
+ enqueue_txn_count INT,
+ enqueue_txn_count_low INT,
+ enqueue_txn_count_high INT,
+ dequeue_txn_starts BIGINT,
+ dequeue_txn_commits BIGINT,
+ dequeue_txn_rejects BIGINT,
+ dequeue_txn_count INT,
+ dequeue_txn_count_low INT,
+ dequeue_txn_count_high INT,
+ consumers INT,
+ consumers_low INT,
+ consumers_high INT,
+ bindings INT,
+ bindings_low INT,
+ bindings_high INT,
+ unacked_messages INT,
+ unacked_messages_low INT,
+ unacked_messages_high INT
+);
+
+CREATE TABLE session (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ vhost_id INT,
+ name VARCHAR(1000),
+ client_id INT,
+ detached_lifespan INT
+);
+
+CREATE TABLE session_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ session_id INT,
+ attached BOOL,
+ remaining_lifespan INT,
+ frames_outstanding INT
+);
+
+CREATE TABLE system (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ sys_id VARCHAR(1000)
+);
+
+CREATE TABLE system_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ system_id INT
+);
+
+CREATE TABLE vhost (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ creation_time TIMESTAMP,
+ deletion_time TIMESTAMP,
+ managed_broker VARCHAR(1000),
+ stats_id INT,
+ stats_prev_id INT,
+ broker_id INT,
+ name VARCHAR(1000)
+);
+
+CREATE TABLE vhost_stats (
+ id SERIAL PRIMARY KEY,
+ id_original BIGINT,
+ rec_time TIMESTAMP,
+ vhost_id INT
+);
+
+ALTER TABLE binding ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
binding_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE binding ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES binding_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE binding ADD CONSTRAINT queue_id_exists FOREIGN KEY (queue_id) REFERENCES
queue (id) ON DELETE SET NULL;
+
+ALTER TABLE binding ADD CONSTRAINT exchange_id_exists FOREIGN KEY (exchange_id)
REFERENCES exchange (id) ON DELETE SET NULL;
+
+ALTER TABLE binding_stats ADD CONSTRAINT binding_id_exists FOREIGN KEY (binding_id)
REFERENCES binding (id) ON DELETE SET NULL;
+
+ALTER TABLE broker ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
broker_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE broker ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES broker_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE broker ADD CONSTRAINT system_id_exists FOREIGN KEY (system_id) REFERENCES
system (id) ON DELETE SET NULL;
+
+ALTER TABLE broker_stats ADD CONSTRAINT broker_id_exists FOREIGN KEY (broker_id)
REFERENCES broker (id) ON DELETE SET NULL;
+
+ALTER TABLE client ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
client_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE client ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES client_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE client ADD CONSTRAINT vhost_id_exists FOREIGN KEY (vhost_id) REFERENCES vhost
(id) ON DELETE SET NULL;
+
+ALTER TABLE client_stats ADD CONSTRAINT client_id_exists FOREIGN KEY (client_id)
REFERENCES client (id) ON DELETE SET NULL;
+
+ALTER TABLE consumer ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
consumer_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE consumer ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES consumer_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE consumer ADD CONSTRAINT destination_id_exists FOREIGN KEY (destination_id)
REFERENCES destination (id) ON DELETE SET NULL;
+
+ALTER TABLE consumer ADD CONSTRAINT queue_id_exists FOREIGN KEY (queue_id) REFERENCES
queue (id) ON DELETE SET NULL;
+
+ALTER TABLE consumer_stats ADD CONSTRAINT consumer_id_exists FOREIGN KEY (consumer_id)
REFERENCES consumer (id) ON DELETE SET NULL;
+
+ALTER TABLE destination ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
destination_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE destination ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES destination_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE destination ADD CONSTRAINT session_id_exists FOREIGN KEY (session_id)
REFERENCES session (id) ON DELETE SET NULL;
+
+ALTER TABLE destination_stats ADD CONSTRAINT destination_id_exists FOREIGN KEY
(destination_id) REFERENCES destination (id) ON DELETE SET NULL;
+
+ALTER TABLE exchange ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
exchange_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE exchange ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES exchange_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE exchange ADD CONSTRAINT vhost_id_exists FOREIGN KEY (vhost_id) REFERENCES
vhost (id) ON DELETE SET NULL;
+
+ALTER TABLE exchange_stats ADD CONSTRAINT exchange_id_exists FOREIGN KEY (exchange_id)
REFERENCES exchange (id) ON DELETE SET NULL;
+
+ALTER TABLE producer ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
producer_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE producer ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES producer_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE producer ADD CONSTRAINT destination_id_exists FOREIGN KEY (destination_id)
REFERENCES destination (id) ON DELETE SET NULL;
+
+ALTER TABLE producer ADD CONSTRAINT exchange_id_exists FOREIGN KEY (exchange_id)
REFERENCES exchange (id) ON DELETE SET NULL;
+
+ALTER TABLE producer_stats ADD CONSTRAINT producer_id_exists FOREIGN KEY (producer_id)
REFERENCES producer (id) ON DELETE SET NULL;
+
+ALTER TABLE queue ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
queue_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE queue ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES queue_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE queue ADD CONSTRAINT vhost_id_exists FOREIGN KEY (vhost_id) REFERENCES vhost
(id) ON DELETE SET NULL;
+
+ALTER TABLE queue_stats ADD CONSTRAINT queue_id_exists FOREIGN KEY (queue_id) REFERENCES
queue (id) ON DELETE SET NULL;
+
+ALTER TABLE session ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
session_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE session ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES session_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE session ADD CONSTRAINT vhost_id_exists FOREIGN KEY (vhost_id) REFERENCES
vhost (id) ON DELETE SET NULL;
+
+ALTER TABLE session ADD CONSTRAINT client_id_exists FOREIGN KEY (client_id) REFERENCES
client (id) ON DELETE SET NULL;
+
+ALTER TABLE session_stats ADD CONSTRAINT session_id_exists FOREIGN KEY (session_id)
REFERENCES session (id) ON DELETE SET NULL;
+
+ALTER TABLE system ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
system_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE system ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES system_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE system_stats ADD CONSTRAINT system_id_exists FOREIGN KEY (system_id)
REFERENCES system (id) ON DELETE SET NULL;
+
+ALTER TABLE vhost ADD CONSTRAINT stats_id_exists FOREIGN KEY (stats_id) REFERENCES
vhost_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE vhost ADD CONSTRAINT stats_prev_id_exists FOREIGN KEY (stats_prev_id)
REFERENCES vhost_stats (id) ON DELETE SET NULL;
+
+ALTER TABLE vhost ADD CONSTRAINT broker_id_exists FOREIGN KEY (broker_id) REFERENCES
broker (id) ON DELETE SET NULL;
+
+ALTER TABLE vhost_stats ADD CONSTRAINT vhost_id_exists FOREIGN KEY (vhost_id) REFERENCES
vhost (id) ON DELETE SET NULL;
+
Modified: mgmt/mint/python/mint/schemaparser.py
===================================================================
--- mgmt/mint/python/mint/schemaparser.py 2007-11-26 21:50:03 UTC (rev 1361)
+++ mgmt/mint/python/mint/schemaparser.py 2007-11-26 22:43:50 UTC (rev 1362)
@@ -4,9 +4,10 @@
class SchemaParser:
"""parses broker XML schema"""
- def __init__(self):
- self.options = dict()
- self.parseConfigFile()
+ def __init__(self, xmlSchemaPath, pythonFilePath, dsn):
+ self.xmlSchemaPath = xmlSchemaPath
+ self.pythonFilePath = pythonFilePath
+ self.dsn = dsn
self.style = MixedCaseUnderscoreStyle()
self.pythonOutput = "from sqlobject import *\n"
self.pythonOutput += "from datetime import datetime\n"
@@ -14,8 +15,8 @@
self.currentClass = ""
self.finalPythonOutput = "\nclassToSchemaNameMap = dict()\n"
self.finalPythonOutput += "schemaNameToClassMap = dict()\n"
- self.pythonOutput += "conn = connectionForURI(\"%s\")\n" %
(self.options["dsn"])
- self.pythonOutput += "sqlhub.processConnection = conn\n\n"
+ #self.pythonOutput += "conn = connectionForURI(\"%s\")\n" %
(self.dsn)
+ #self.pythonOutput += "sqlhub.processConnection = conn\n\n"
# mapping between xml schema types and database column types
# see xml/MintTypes.xml
self.dataTypesMap = dict()
@@ -124,15 +125,9 @@
self.pythonOutput += " pass\n"
self.currentClass = ""
- def parseConfigFile(self):
- config = mllib.xml_parse("config.xml")
- configOptions = config.query["config/configOption"]
- for opt in configOptions:
- self.options[opt["@name"]] = opt["@value"]
-
def generateCode(self):
- outputFile = open(self.options["pythonOutput"], "w")
- schema = mllib.xml_parse(self.options["schemaXML"])
+ outputFile = open(self.pythonFilePath, "w")
+ schema = mllib.xml_parse(self.xmlSchemaPath)
classes = schema.query["schema/class"]
for cls in classes:
self.startClass(cls["@name"])
@@ -146,6 +141,12 @@
outputFile.write(self.pythonOutput + self.finalPythonOutput)
outputFile.close()
+if __name__ == "__main__":
+ import sys
-parser = SchemaParser()
-parser.generateCode()
+ if len(sys.argv) != 4:
+ print "Usage: schemaparser.py INPUT-XML-SCHEMA OUTPUT-PYTHON-FILE DSN"
+ sys.exit(1)
+ else:
+ parser = SchemaParser(*sys.argv[1:])
+ parser.generateCode()