[rhq] Branch 'content' - modules/core
by Pradeep Kilambi
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 466 +++++++++-
1 file changed, 465 insertions(+), 1 deletion(-)
New commits:
commit 035991df58b69564d9fc3b20c342c0d8d31fca63
Author: Pradeep Kilambi <pkilambi(a)redhat.com>
Date: Mon Nov 23 16:51:14 2009 -0500
db upgrade supporting the Advisory schema changes
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 3e12bad..5a580ae 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2173,7 +2173,471 @@
</statement>
</schema-directSQL>
</schemaSpec>
+
+ <!-- RHQ Advisory Representation -->
+ <schemaSpec version="2.71">
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_TYPE ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_TYPE" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_TYPE" column="NAME" precision="200" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY_TYPE" column="NAME" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_TYPE" column="DESCRIPTION" precision="500" columnType="VARCHAR2" />
+ <schema-directSQL>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, NAME, DESCRIPTION )
+ VALUES ( 101, 'Bug Fix Advisory', 'Bug fix(RHBA) Advisory' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, NAME, DESCRIPTION )
+ VALUES ( 102, 'Product Enhancement Advisory', 'Product Enhancement(RHEA) Advisory' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, NAME, DESCRIPTION )
+ VALUES ( 103, 'Security Advisory', 'Security Advisory(RHSA) Advisory' )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_SEVERITY ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_SEVERITY" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_SEVERITY" column="RANK" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_SEVERITY" column="RANK" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_SEVERITY" column="LABEL" precision="40" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY_SEVERITY" column="LABEL" nullable="false" />
+ <schema-directSQL>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, RANK, LABEL)
+ VALUES ( 101, 0, 'errata.sev.label.critical' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, RANK, LABEL)
+ VALUES ( 102, 1, 'errata.sev.label.important' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, RANK, LABEL)
+ VALUES ( 103, 2, 'errata.sev.label.moderate' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_TYPE ( ID, RANK, LABEL)
+ VALUES ( 104, 3, 'errata.sev.label.low' )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_FILE_TYPE ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_FILE_TYPE" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE_TYPE" column="LABEL" precision="40" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE_TYPE" column="LABEL" nullable="false" />
+ <schema-directSQL>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_FILE_TYPE ( ID, LABEL)
+ VALUES ( 101, 'RPM' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_FILE_TYPE ( ID, LABEL)
+ VALUES ( 102, 'SRPM' )
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_FILE_TYPE ( ID, LABEL)
+ VALUES ( 103, 'IMG')
+ </statement>
+ <statement>
+ INSERT INTO
+ RHQ_ADVISORY_FILE_TYPE ( ID, LABEL)
+ VALUES ( 104, 'OVAL')
+ </statement>
+ </schema-directSQL>
+ <schema-createSequence name="RHQ_ADVISORY_SEQ" initial="10001" />
+ <schema-directSQL>
+
+ <statement desc="Creating table RHQ_ADVISORY">
+ CREATE TABLE RHQ_ADVISORY ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY" column="ID" nullable="false" columnType="INTEGER"/>
+ <schema-addColumn table="RHQ_ADVISORY" column="ADVISORY" precision="64" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="ADVISORY" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="ADVISORY_TYPE_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="ADVISORY_TYPE_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="ADVISORY_NAME" precision="64" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="ADVISORY_NAME" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="ADVISORY_REL" precision="64" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="ADVISORY_REL" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="DESCRIPTION" precision="4000" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="DESCRIPTION" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="SYNOPSIS" precision="4000" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="SYNOPSIS" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="TOPIC" precision="4000" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="TOPIC" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="SOLUTION" precision="4000" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="SOLUTION" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="SEVERITY_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="SEVERITY_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="ISSUE_DATE" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="ISSUE_DATE" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="UPDATE_DATE" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="UPDATE_DATE" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="CTIME" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="CTIME" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY" column="LAST_MODIFIED" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY" column="LAST_MODIFIED" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="postgresql">
+ CREATE UNIQUE INDEX RHQ_ADVISORY_NAME_UQ
+ ON RHQ_ADVISORY ( ADVISORY_NAME )
+ </statement>
+ <statement targetDBVendor="oracle">
+ CREATE UNIQUE INDEX RHQ_ADVISORY_NAME_UQ
+ ON RHQ_ADVISORY ( ADVISORY_NAME )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="postgresql">
+ CREATE UNIQUE INDEX RHQ_ADVISORY_UQ
+ ON RHQ_ADVISORY ( ADVISORY )
+ </statement>
+ <statement targetDBVendor="oracle">
+ CREATE UNIQUE INDEX RHQ_ADVISORY_UQ
+ ON RHQ_ADVISORY ( ADVISORY )
+ </statement>
+ </schema-directSQL>
- </dbupgrade>
+ <schema-directSQL>
+ <statement targetDBVendor="postgresql">
+ CREATE INDEX RHQ_ADVISORY_UDATE_IDX
+ ON RHQ_ADVISORY (UPDATE_DATE )
+ </statement>
+ <statement targetDBVendor="oracle">
+ CREATE INDEX RHQ_ADVISORY_UDATE_IDX
+ ON RHQ_ADVISORY (UPDATE_DATE )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="postgresql">
+ CREATE INDEX RHQ_ADVISORY_SYN_IDX
+ ON RHQ_ADVISORY ( SYNOPSIS )
+ </statement>
+ <statement targetDBVendor="oracle">
+ CREATE INDEX RHQ_ADVISORY_SYN_IDX
+ ON RHQ_ADVISORY ( SYNOPSIS )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY
+ ADD CONSTRAINT RHQ_ADV_TYPE_FKEY
+ FOREIGN KEY ( ADVISORY_TYPE_ID )
+ REFERENCES RHQ_ADVISORY_TYPE ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY
+ ADD CONSTRAINT RHQ_ADV_TYPE_FKEY
+ FOREIGN KEY ( ADVISORY_TYPE_ID )
+ REFERENCES RHQ_ADVISORY_TYPE ( ID )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY
+ ADD CONSTRAINT RHQ_ADV_SEV_FKEY
+ FOREIGN KEY ( SEVERITY_ID )
+ REFERENCES RHQ_ADVISORY_SEVERITY ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY
+ ADD CONSTRAINT RHQ_ADV_SEV_FKEY
+ FOREIGN KEY ( SEVERITY_ID )
+ REFERENCES RHQ_ADVISORY_SEVERITY ( ID )
+ </statement>
+ </schema-directSQL>
+ <schema-createSequence name="RHQ_ADVISORY_FILE_SEQ" initial="10001" />
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_FILE ( ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_FILE" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE" column="ADVISORY_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE" column="ADVISORY_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE" column="FILE_TYPE_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE" column="FILE_TYPE_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE" column="RELATIVE_FILENAME" precision="256" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE" column="RELATIVE_FILENAME" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE" column="MD5SUM" precision="64" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE" column="MD5SUM" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE" column="LAST_MODIFIED" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE" column="LAST_MODIFIED" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="postgresql">
+ CREATE UNIQUE INDEX RHQ_ADVISORY_ID_FILE_UQ
+ ON RHQ_ADVISORY_FILE ( ADVISORY_ID, RELATIVE_FILENAME )
+ </statement>
+ <statement targetDBVendor="oracle">
+ CREATE UNIQUE INDEX RHQ_ADVISORY_ID_FILE_UQ
+ ON RHQ_ADVISORY_FILE ( ADVISORY_ID, RELATIVE_FILENAME )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_FILE
+ ADD CONSTRAINT RHQ_ADV_FILE_FKEY
+ FOREIGN KEY ( ADVISORY_ID)
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_FILE
+ ADD CONSTRAINT RHQ_ADV_FILE_FKEY
+ FOREIGN KEY ( ADVISORY_ID)
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_FILE
+ ADD CONSTRAINT RHQ_ADV_FILE_TYPE_FKEY
+ FOREIGN KEY ( FILE_TYPE_ID )
+ REFERENCES RHQ_ADVISORY_FILE_TYPE ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_FILE
+ ADD CONSTRAINT RHQ_ADV_FILE_TYPE_FKEY
+ FOREIGN KEY ( FILE_TYPE_TYPE )
+ REFERENCES RHQ_ADVISORY_FILE_TYPE ( ID )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_PACKAGE_MAP ( ADVISORY_ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_PACKAGE_MAP" column="ADVISORY_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_PACKAGE_MAP" column="PACKAGE_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_PACKAGE_MAP" column="PACKAGE_ID" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_PACKAGE_MAP
+ ADD CONSTRAINT RHQ_ADV_PKG_MAP_KEY
+ PRIMARY KEY ( ADVISORY_ID, PACKAGE_ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_PACKAGE_MAP
+ ADD CONSTRAINT RHQ_ADV_PKG_MAP_KEY
+ PRIMARY KEY ( ADVISORY_ID, PACKAGE_ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_PACKAGE_MAP
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_PACKAGE_MAP
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_PACKAGE_MAP
+ ADD FOREIGN KEY ( PACKAGE_ID )
+ REFERENCES RHQ_PACKAGE ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_PACKAGE_MAP
+ ADD FOREIGN KEY ( PACKAGE_ID )
+ REFERENCES RHQ_PACKAGE ( ID )
+ </statement>
+ </schema-directSQL>
+
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_FILE_PKG_MAP ( ADVISORY_ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_FILE_PKG_MAP" column="ADVISORY_FILE_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_FILE_PKG_MAP" column="PACKAGE_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_FILE_PKG_MAP" column="PACKAGE_ID" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_FILE_PKG_MAP
+ ADD CONSTRAINT RHQ_ADV_FILE_PKG_MAP_KEY
+ PRIMARY KEY ( ADVISORY_FILE_ID, PACKAGE_ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_FILE_PKG_MAP
+ ADD CONSTRAINT RHQ_ADV_FILE_PKG_MAP_KEY
+ PRIMARY KEY ( ADVISORY_FILE_ID, PACKAGE_ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_FILE_PKG_MAP
+ ADD FOREIGN KEY ( ADVISORY_FILE_ID )
+ REFERENCES RHQ_ADVISORY_FILE ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_FILE_PKG_MAP
+ ADD FOREIGN KEY ( ADVISORY_FILE_ID )
+ REFERENCES RHQ_ADVISORY_FILE ( ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_FILE_PKG_MAP
+ ADD FOREIGN KEY ( PACKAGE_ID )
+ REFERENCES RHQ_PACKAGE ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_FILE_PKG_MAP
+ ADD FOREIGN KEY ( PACKAGE_ID )
+ REFERENCES RHQ_PACKAGE ( ID )
+ </statement>
+ </schema-directSQL>
+ <schema-createSequence name="RHQ_CVE_SEQ" initial="101" />
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_CVE ( ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_CVE" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_CVE" column="NAME" precision="64" columnType="VARCHAR2"/>
+ <schema-alterColumn table="RHQ_CVE" column="NAME" nullable="false" />
+
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_CVE ( ADVISORY_ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_ADVISORY_CVE" column="ADVISORY_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_CVE" column="CVE_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_CVE" column="CVE_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_CVE" column="CTIME" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY_CVE" column="CTIME" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_CVE" column="LAST_MODIFIED" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY_CVE" column="LAST_MODIFIED" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_CVE
+ ADD CONSTRAINT RHQ_ADV_CVE_MAP_KEY
+ PRIMARY KEY ( ADVISORY_ID, CVE_ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_CVE
+ ADD CONSTRAINT RHQ_ADV_CVE_MAP_KEY
+ PRIMARY KEY ( ADVISORY_ID, CVE_ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_CVE
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_CVE
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_CVE
+ ADD FOREIGN KEY ( CVE_ID )
+ REFERENCES RHQ_CVE ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_CVE
+ ADD FOREIGN KEY ( CVE_ID )
+ REFERENCES RHQ_CVE ( ID )
+ </statement>
+ </schema-directSQL>
+
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_ADVISORY_BUGLIST ( ADVISORY_ID INTEGER )
+ </statement>
+ </schema-directSQL>
+
+ <schema-alterColumn table="RHQ_ADVISORY_BUGLIST" column="ADVISORY_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_BUGLIST" column="BUG_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_ADVISORY_BUGLIST" column="BUG_ID" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_BUGLIST" column="CTIME" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY_BUGLIST" column="CTIME" nullable="false" />
+ <schema-addColumn table="RHQ_ADVISORY_BUGLIST" column="LAST_MODIFIED" columnType="LONG" />
+ <schema-alterColumn table="RHQ_ADVISORY_BUGLIST" column="LAST_MODIFIED" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_BUGLIST
+ ADD CONSTRAINT RHQ_ADV_BUG_LIST_KEY
+ PRIMARY KEY ( ADVISORY_ID, BUG_ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_BUGLIST
+ ADD CONSTRAINT RHQ_ADV_BUG_LIST_KEY
+ PRIMARY KEY ( ADVISORY_ID, BUG_ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_ADVISORY_BUGLIST
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_ADVISORY_BUGLIST
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_REPO_ADVISORY ( REPO_ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_REPO_ADVISORY" column="REPO_ID" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_ADVISORY" column="ADVISORY_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_REPO_ADVISORY" column="ADVISORY_ID" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_ADVISORY" column="CTIME" columnType="LONG" />
+ <schema-alterColumn table="RHQ_REPO_ADVISORY" column="CTIME" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_ADVISORY" column="LAST_MODIFIED" columnType="LONG" />
+ <schema-alterColumn table="RHQ_REPO_ADVISORY" column="LAST_MODIFIED" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_REPO_ADVISORY
+ ADD CONSTRAINT RHQ_REPO_ADV_MAP_KEY
+ PRIMARY KEY ( REPO_ID, ADVISORY_ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_REPO_ADVISORY
+ ADD CONSTRAINT RHQ_REPO_ADV_MAP_KEY
+ PRIMARY KEY ( REPO_ID, ADVISORY_ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_REPO_ADVISORY
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_REPO_ADVISORY
+ ADD FOREIGN KEY ( ADVISORY_ID )
+ REFERENCES RHQ_ADVISORY ( ID )
+ </statement>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_REPO_ADVISORY
+ ADD FOREIGN KEY ( REPO_ID )
+ REFERENCES RHQ_REPO ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_REPO_ADVISORY
+ ADD FOREIGN KEY ( REPO_ID )
+ REFERENCES RHQ_REPO ( ID )
+ </statement>
+ </schema-directSQL>
+ </schemaSpec>
+ </dbupgrade>
</target>
</project>
14 years, 6 months
[rhq] Branch 'content' - modules/core
by Pradeep Kilambi
modules/core/dbutils/pom.xml | 2
modules/core/dbutils/src/main/scripts/dbsetup/content-data.xml | 22 +
modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml | 150 ++++++++++
3 files changed, 172 insertions(+), 2 deletions(-)
New commits:
commit 74cf31fd294d625cb0447ac7f17c68d8c03af9b2
Author: Pradeep Kilambi <pkilambi(a)redhat.com>
Date: Mon Nov 23 16:49:16 2009 -0500
Initial schema changes to support
- RHQ Advisory model
- Represent Types of Advisories (RHBA,RHEA,RHSA)
- Represent different filetypes associated with an errata (RPM,SRPM,IMG,OVAL and may be more)
- Represent types of severity for security errata critical, important, moderate, low
- Advisory <-> Packages mapping
- Associate CVE(Common Vulnerabilities and Exposures to relevant errata
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 6f6f12b..f352799 100644
--- a/modules/core/dbutils/pom.xml
+++ b/modules/core/dbutils/pom.xml
@@ -22,7 +22,7 @@
<properties>
<scm.module.path>modules/core/dbutils/</scm.module.path>
- <db.schema.version>2.69</db.schema.version>
+ <db.schema.version>2.71</db.schema.version>
</properties>
<dependencies>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/content-data.xml b/modules/core/dbutils/src/main/scripts/dbsetup/content-data.xml
index 210eb69..ddb04c4 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/content-data.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/content-data.xml
@@ -55,5 +55,25 @@
<data id="1" name="kickstart" description="Linux kickstart distribution"/>
<data id="2" name="jumpstart" description="solaris jumpstart distribution"/>
</table>
-
+
+ <table name="RHQ_ADVISORY_TYPE">
+ <data id="101" name="Bug Fix Advisory" description="Bug fix(RHBA) Advisory"/>
+ <data id="102" name="Product Enhancement Advisory" description="Product Enhancement(RHEA) Advisory"/>
+ <data id="103" name="Security Advisory" description="Security Advisory(RHSA) Advisory"/>
+ </table>
+
+ <table name="RHQ_ADVISORY_FILE_TYPE">
+ <data id="101" label="RPM" />
+ <data id="102" label="SRPM"/>
+ <data id="103" label="IMG"/>
+ <data id="104" label="OVAL"/>
+ </table>
+
+ <table name="RHQ_ADVISORY_SEVERITY">
+ <data id="101" rank="0" label="errata.sev.label.critical" />
+ <data id="102" rank="1" label="errata.sev.label.important"/>
+ <data id="103" rank="2" label="errata.sev.label.moderate"/>
+ <data id="104" rank="3" label="errata.sev.label.low"/>
+ </table>
+
</dbsetup>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
index 61eaeff..d5f6566 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/content-schema.xml
@@ -382,6 +382,156 @@
</primaryKey>
</constraint>
</table>
+
+ <table name="RHQ_ADVISORY_TYPE">
+ <column name="ID" default="sequence-only" initial="101" primarykey="true" required="true" type="INTEGER"/>
+ <column name="NAME" size="200" type="VARCHAR2" required="true"/>
+ <column name="DESCRIPTION" size="500" type="VARCHAR2" required="false"/>
+
+ </table>
+
+ <table name="RHQ_ADVISORY_SEVERITY">
+ <column name="ID" default="sequence-only" initial="101" primarykey="true" required="true" type="INTEGER"/>
+ <column name="RANK" type="INTEGER" required="true"/>
+ <column name="LABEL" size="40" type="VARCHAR2" required="true"/>
+ </table>
+
+ <table name="RHQ_ADVISORY">
+ <column name="ID" default="sequence-only" initial="10001" primarykey="true" required="true" type="INTEGER"/>
+ <column name="ADVISORY" size="64" type="VARCHAR2" required="true"/>
+ <column name="ADVISORY_TYPE_ID" type="INTEGER" required="true" references="RHQ_ADVISORY_TYPE"/>
+ <column name="ADVISORY_REL" size="64" type="VARCHAR2" required="true"/>
+ <column name="ADVISORY_NAME" size="64" type="VARCHAR2" required="true"/>
+ <column name="DESCRIPTION" size="4000" type="VARCHAR2" required="true"/>
+ <column name="SYNOPSIS" size="4000" type="VARCHAR2" required="true"/>
+ <column name="TOPIC" size="4000" type="VARCHAR2" required="false"/>
+ <column name="SOLUTION" size="4000" type="VARCHAR2" required="true"/>
+ <column name="SEVERITY_ID" type="INTEGER" required="true" references="RHQ_ADVISORY_SEVERITY"/>
+ <column name="ISSUE_DATE" type="LONG" required="true"/>
+ <column name="UPDATE_DATE" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+
+ <index name="RHQ_ADVISORY_NAME_UQ" unique="true">
+ <field ref="ADVISORY_NAME"/>
+ </index>
+
+ <index name="RHQ_ADVISORY_UQ" unique="true">
+ <field ref="ADVISORY"/>
+ </index>
+
+ <index name="RHQ_ADVISORY_UDATE_IDX" unique="false">
+ <field ref="UPDATE_DATE"/>
+ </index>
+
+ <index name="RHQ_ADVISORY_SYN_IDX" unique="false">
+ <field ref="SYNOPSIS"/>
+ </index>
+
+ </table>
+
+ <table name="RHQ_ADVISORY_FILE_TYPE">
+ <column name="ID" default="sequence-only" initial="101" primarykey="true" required="true" type="INTEGER"/>
+ <column name="LABEL" size="40" type="VARCHAR2" required="true"/>
+
+ <index name="RHQ_ADVISORY_FILE_TYPE_UQ" unique="true">
+ <field ref="LABEL"/>
+ </index>
+
+ </table>
+
+ <table name="RHQ_ADVISORY_FILE">
+ <column name="ID" default="sequence-only" initial="10001" primarykey="true" required="true" type="INTEGER"/>
+ <column name="ADVISORY_ID" type="INTEGER" required="true" references="RHQ_DISTRIBUTION"/>
+ <column name="FILE_TYPE_ID" type="INTEGER" required="true" references="RHQ_ADVISORY_FILE_TYPE"/>
+ <column name="RELATIVE_FILENAME" size="256" type="VARCHAR2" required="true"/>
+ <column name="MD5SUM" size="64" type="VARCHAR2" required="true"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+
+ <index name="RHQ_ADVISORY_ID_FILE_UQ" unique="true">
+ <field ref="ADVISORY_ID"/>
+ <field ref="RELATIVE_FILENAME"/>
+ </index>
+ </table>
+
+ <table name="RHQ_ADVISORY_PACKAGE_MAP">
+ <column name="ADVISORY_ID" type="INTEGER" required="true" references="RHQ_ADVISORY"/>
+ <column name="PACKAGE_ID" type="INTEGER" required="true" references="RHQ_PACKAGE"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+
+ <constraint name="RHQ_ADV_PKG_MAP_KEY" unique="true">
+ <primaryKey>
+ <field ref="ADVISORY_ID"/>
+ <field ref="PACKAGE_ID"/>
+ </primaryKey>
+ </constraint>
+ </table>
+
+ <table name="RHQ_ADVISORY_FILE_PKG_MAP">
+ <column name="ADVISORY_FILE_ID" type="INTEGER" required="true" references="RHQ_ADVISORY_FILE"/>
+ <column name="PACKAGE_ID" type="INTEGER" required="true" references="RHQ_PACKAGE"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+
+ <constraint name="RHQ_ADV_FILE_PKG_MAP_KEY" unique="true">
+ <primaryKey>
+ <field ref="ADVISORY_FILE_ID"/>
+ <field ref="PACKAGE_ID"/>
+ </primaryKey>
+ </constraint>
+ </table>
+
+ <table name="RHQ_CVE">
+ <column name="ID" default="sequence-only" initial="101" primarykey="true" required="true" type="INTEGER"/>
+ <column name="NAME" size="64" type="VARCHAR2" required="true"/>
+ </table>
+
+ <table name="RHQ_ADVISORY_CVE">
+ <column name="ADVISORY_ID" type="INTEGER" required="true" references="RHQ_ADVISORY"/>
+ <column name="CVE_ID" type="INTEGER" required="true" references="RHQ_CVE"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+
+ <constraint name="RHQ_ADV_CVE_MAP_KEY" unique="true">
+ <primaryKey>
+ <field ref="ADVISORY_ID"/>
+ <field ref="CVE_ID"/>
+ </primaryKey>
+ </constraint>
+
+ </table>
+
+ <table name="RHQ_ADVISORY_BUGLIST">
+ <column name="ADVISORY_ID" type="INTEGER" required="true" references="RHQ_ADVISORY"/>
+ <column name="BUG_ID" type="INTEGER" required="true"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+
+ <constraint name="RHQ_ADV_BUG_LIST_KEY" unique="true">
+ <primaryKey>
+ <field ref="ADVISORY_ID"/>
+ <field ref="BUG_ID"/>
+ </primaryKey>
+ </constraint>
+ </table>
+
+
+ <table name="RHQ_REPO_ADVISORY">
+ <column name="REPO_ID" type="INTEGER" required="true" references="RHQ_REPO"/>
+ <column name="ADVISORY_ID" type="INTEGER" required="true" references="RHQ_DISTRIBUTION"/>
+ <column name="LAST_MODIFIED" type="LONG" required="true"/>
+ <column name="CTIME" type="LONG" required="true"/>
+
+ <constraint name="RHQ_REPO_ADV_MAP_KEY">
+ <primaryKey>
+ <field ref="REPO_ID"/>
+ <field ref="ADVISORY_ID"/>
+ </primaryKey>
+ </constraint>
+ </table>
+
</dbsetup>
14 years, 6 months
[rhq] Branch 'content' - modules/enterprise
by jdob
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java | 299 +++++-----
1 file changed, 171 insertions(+), 128 deletions(-)
New commits:
commit 7cf18efe9efb9f6b54e55ef47ae688ad9f6a1aab
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 23 16:14:16 2009 -0500
Reformatted so I can have it side by side with other code when refactoring the giant synchronizeContentSource method
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
index f84309b..e5e42ba 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
@@ -40,20 +40,19 @@ import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
import org.rhq.core.domain.content.ContentSourceSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
+import org.rhq.core.domain.content.Distribution;
+import org.rhq.core.domain.content.DistributionFile;
import org.rhq.core.domain.content.Package;
import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.content.PackageVersionContentSource;
import org.rhq.core.domain.content.Repo;
-import org.rhq.core.domain.content.Distribution;
-import org.rhq.core.domain.content.DistributionFile;
+import org.rhq.core.domain.criteria.RepoCriteria;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageControl;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.core.domain.criteria.RepoCriteria;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
-import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.DistributionManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.metadata.ContentSourceMetadataManagerLocal;
import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.content.metadata.ContentSourcePluginMetadataManager;
@@ -67,7 +66,7 @@ import org.rhq.enterprise.server.util.LookupUtil;
*/
public class ContentProviderManager {
private static final Log log = LogFactory.getLog(ContentProviderManager.class);
-
+
private ContentServerPluginManager pluginManager;
private Map<ContentSource, ContentProvider> adapters;
@@ -76,14 +75,12 @@ public class ContentProviderManager {
private final Object synchronizeContentSourceLock = new Object();
/**
- * Asks that the adapter responsible for the given content source return a stream to the package bits for the
- * package at the given location.
- *
- * @param contentSourceId the adapter for this content source will be used to stream the bits
- * @param location where the adapter can find the package bits on the content source
+ * Asks that the adapter responsible for the given content source return a stream to the package
+ * bits for the package at the given location.
*
+ * @param contentSourceId the adapter for this content source will be used to stream the bits
+ * @param location where the adapter can find the package bits on the content source
* @return the stream to the package bits
- *
* @throws Exception if the adapter failed to load the bits
*/
public InputStream loadPackageBits(int contentSourceId, String location) throws Exception {
@@ -102,17 +99,16 @@ public class ContentProviderManager {
/**
- * Asks that the adapter responsible for the given content source return a stream to the DistributionFile
- * bits for the DistributionFile at the given location.
- *
- * @param contentSourceId the adapter for this content source will be used to stream the bits
- * @param location where the adapter can find the DistributionFile bits on the content source
+ * Asks that the adapter responsible for the given content source return a stream to the
+ * DistributionFile bits for the DistributionFile at the given location.
*
+ * @param contentSourceId the adapter for this content source will be used to stream the bits
+ * @param location where the adapter can find the DistributionFile bits on the source
* @return the stream to the DistributionFile bits
- *
* @throws Exception if the adapter failed to load the bits
*/
- public InputStream loadDistributionFileBits(int contentSourceId, String location) throws Exception {
+ public InputStream loadDistributionFileBits(int contentSourceId, String location)
+ throws Exception {
ContentProvider adapter = getIsolatedContentProvider(contentSourceId);
DistributionSource distSource = (DistributionSource) adapter;
@@ -120,24 +116,24 @@ public class ContentProviderManager {
if (inputStream == null) {
throw new Exception("Adapter for content source [" + contentSourceId
- + "] failed to give us a stream to the distribution file at location [" + location + "]");
+ + "] failed to give us a stream to the distribution file at location [" + location +
+ "]");
}
return inputStream;
}
/**
- * Asks the provider responsible for the given content source to synchronize with its remote repository. This will
- * not attempt to load any package bits - it only synchronizes the repos and package version information. Note
- * that if a synchronization is already currently underway, this method will not do anything and will return
- * <code>false</code> (in effect, will let the currently running synchronization continue; we try not to step on
- * it). If this method does actually do a sync, <code>true</code> will be returned.
- *
- * @param contentSourceId identifies the database entry of the provider
- *
- * @return <code>true</code> if the synchronization completed; <code>false</code> if there was already a
- * synchronization happening and this method aborted
+ * Asks the provider responsible for the given content source to synchronize with its remote
+ * repository. This will not attempt to load any package bits - it only synchronizes the repos
+ * and package version information. Note that if a synchronization is already currently underway,
+ * this method will not do anything and will return <code>false</code> (in effect, will let the
+ * currently running synchronization continue; we try not to step on it). If this method does
+ * actually do a sync, <code>true</code> will be returned.
*
+ * @param contentSourceId identifies the database entry of the provider
+ * @return <code>true</code> if the synchronization completed; <code>false</code> if there was
+ * already a synchronization happening and this method aborted
* @throws Exception
*/
public boolean synchronizeContentSource(int contentSourceId) throws Exception {
@@ -149,23 +145,28 @@ public class ContentProviderManager {
ContentSourceSyncResults results = null;
SubjectManagerLocal subjMgr = LookupUtil.getSubjectManager();
Subject overlord = subjMgr.getOverlord();
- StringBuilder progress = new StringBuilder(); // append to this as we go along, building a status report
+
+ // append to this as we go along, building a status report
+ StringBuilder progress = new StringBuilder();
long start = System.currentTimeMillis();
try {
- ContentSource contentSource = contentSourceManager.getContentSource(overlord, contentSourceId);
+ ContentSource contentSource = contentSourceManager
+ .getContentSource(overlord, contentSourceId);
if (contentSource == null) {
- throw new Exception("Cannot sync a non-existing content source [" + contentSourceId + "]");
+ throw new Exception(
+ "Cannot sync a non-existing content source [" + contentSourceId + "]");
}
// This should not take very long so it should be OK to block other callers.
- // We are avoiding the problem that would occur if we try to synchronize the same content source
- // at the same time. We could do it more cleverly by synchronizing on
- // a per content source basis, but I don't see a need right now to make this more complicated.
+ // We are avoiding the problem that would occur if we try to synchronize the same source
+ // at the same time. We could do it more cleverly by synchronizing on a per content source
+ // basis, but I don't see a need right now to make this more complicated.
// We can come back and revisit if we need more fine-grained locking.
synchronized (synchronizeContentSourceLock) {
progress.append(new Date()).append(": ");
- progress.append("Start synchronization of content provider [").append(contentSource.getName()).append(
+ progress.append("Start synchronization of content provider [")
+ .append(contentSource.getName()).append(
"]");
progress.append('\n');
progress.append(new Date()).append(": ");
@@ -176,10 +177,11 @@ public class ContentProviderManager {
}
if (results == null) {
- // note that it technically is still possible to have concurrent syncs - if two threads running
- // in two different servers (i.e. different VMs) both try to sync the same content source and
- // both enter the persistContentSourceSyncResults method at the same time, you'll get two
- // inprogress rows - this is so rare as to not care. Even if it does happen, it may still work, or
+ // note that it technically is still possible to have concurrent syncs - if two
+ // threads running in two different servers (i.e. different VMs) both try to sync the
+ // same content source and both enter the persistContentSourceSyncResults method at
+ // the same time, you'll get two inprogress rows - this is so rare as to not care.
+ // Even if it does happen, it may still work, or
// one sync will get an error and rollback its tx and no harm will be done.
log.info("Content provider [" + contentSource.getName()
+ "] is already currently being synchronized, this sync request will be ignored");
@@ -205,11 +207,12 @@ public class ContentProviderManager {
}
// ------------------
- // NOTE: Ultimately, this will be moved out as repos get their own schedules. For now, simply
- // synchronize *all* repos for this provider.
+ // NOTE: Ultimately, this will be moved out as repos get their own schedules. For now,
+ // simply synchronize *all* repos for this provider.
// ------------------
- // If the provider is capable of handling packages, perform the package synchronization portion of the sync
+ // If the provider is capable of handling packages, perform the package synchronization
+ // portion of the sync
if (provider instanceof PackageSource) {
PackageSource packageSource = (PackageSource) provider;
@@ -223,22 +226,25 @@ public class ContentProviderManager {
for (Repo repo : repos) {
// Convert the existing package list for this repo into DTOs for the API
// --------------------------------------------
- List<PackageVersionContentSource> existingPVCS; // what we already know about this content source
- Set<ContentProviderPackageDetails> allDetails; // what we tell the plugin about what we know
+ List<PackageVersionContentSource> existingPVCS; // already know about this source
+ Set<ContentProviderPackageDetails> allDetails; // send to plugin
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> keyPVCSMap;
start = System.currentTimeMillis();
- existingPVCS = contentSourceManager.getPackageVersionsFromContentSourceForRepo(subjMgr.getOverlord(),
- contentSource.getId(), repo.getId());
+ existingPVCS = contentSourceManager
+ .getPackageVersionsFromContentSourceForRepo(subjMgr.getOverlord(),
+ contentSource.getId(), repo.getId());
int existingCount = existingPVCS.size();
- keyPVCSMap = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>(existingCount);
+ keyPVCSMap = new HashMap<ContentProviderPackageDetailsKey,
+ PackageVersionContentSource>(existingCount);
allDetails = new HashSet<ContentProviderPackageDetails>(existingCount);
translateDomainToDto(existingPVCS, allDetails, keyPVCSMap);
- log.info("synchronizePackages: [" + contentSource.getName() + "]: loaded existing list of size=["
+ log.info("synchronizePackages: [" + contentSource.getName() +
+ "]: loaded existing list of size=["
+ existingCount + "] (" + (System.currentTimeMillis() - start) + ")ms");
progress.append(existingCount).append('\n');
@@ -253,12 +259,14 @@ public class ContentProviderManager {
packageSource.synchronizePackages(repo.getName(), report, allDetails);
- log.info("synchronizePackages: [" + contentSource.getName() + "]: got sync report from adapter=["
+ log.info("synchronizePackages: [" + contentSource.getName() +
+ "]: got sync report from adapter=["
+ report + "] (" + (System.currentTimeMillis() - start) + ")ms");
progress.append("new=").append(report.getNewPackages().size());
progress.append(", updated=").append(report.getUpdatedPackages().size());
- progress.append(", deleted=").append(report.getDeletedPackages().size()).append('\n');
+ progress.append(", deleted=").append(report.getDeletedPackages().size())
+ .append('\n');
progress.append(new Date()).append(": ");
progress.append("FULL SUMMARY FOLLOWS:").append('\n');
progress.append(report.getSummary()).append('\n');
@@ -268,26 +276,29 @@ public class ContentProviderManager {
results = contentSourceManager.mergeContentSourceSyncResults(results);
start = System.currentTimeMillis();
- results = contentSourceManager.mergeContentSourceSyncReport(contentSource, report, keyPVCSMap, results);
+ results = contentSourceManager
+ .mergeContentSourceSyncReport(contentSource, report, keyPVCSMap, results);
}
- // let's reset our progress string to the full results including the text added by the merge
+ // Reset our progress string to the full results including the text added by the merge
progress.setLength(0);
progress.append(results.getResults());
- log.info("synchronizePackages: [" + contentSource.getName() + "]: report has been merged ("
- + (System.currentTimeMillis() - start) + ")ms");
+ log.info(
+ "synchronizePackages: [" + contentSource.getName() + "]: report has been merged ("
+ + (System.currentTimeMillis() - start) + ")ms");
progress.append(new Date()).append(": ").append("DONE.");
results.setResults(progress.toString());
results.setStatus(ContentSourceSyncStatus.SUCCESS);
results = contentSourceManager.mergeContentSourceSyncResults(results);
}
-
+
log.info("Checking if provider: " + provider + " is a DistributionSource");
if (provider instanceof DistributionSource) {
- log.info("synchronizeContentSource(" + contentSourceId + "): this source is a DistributionSource");
+ log.info("synchronizeContentSource(" + contentSourceId +
+ "): this source is a DistributionSource");
log.info("We will skip the sync for now until PackageSource is working.");
DistributionSource distSource = (DistributionSource) provider;
@@ -298,14 +309,16 @@ public class ContentProviderManager {
// Temporary functionality: loop for all repos that use this content source
for (Repo repo : repos) {
- log.info("ContentProviderManager::synchronizeContentSource DistributionSource would be syncing repo: " + repo.getName());
-
+ log.info(
+ "ContentProviderManager::synchronizeContentSource DistributionSource would " +
+ "be syncing repo: " + repo.getName());
start = System.currentTimeMillis();
PageControl pc = PageControl.getUnlimitedInstance();
log.debug("Looking up existing distributions for repoId: " + repo.getId());
- List<Distribution> dists = repoManager.findAssociatedDistributions(overlord, repo.getId(), pc);
+ List<Distribution> dists = repoManager
+ .findAssociatedDistributions(overlord, repo.getId(), pc);
log.debug("Found " + dists.size() + " Distributions for repoId " + repo.getId());
progress.append(dists.size()).append('\n');
@@ -313,12 +326,14 @@ public class ContentProviderManager {
progress.append("Asking content source to update the list of packages...");
DistributionSyncReport distReport = new DistributionSyncReport(repo.getId());
- List<DistributionDetails> distDetails = new ArrayList<DistributionDetails>(dists.size());
+ List<DistributionDetails> distDetails = new ArrayList<DistributionDetails>(
+ dists.size());
translateDomainToDto(dists, distDetails);
-
+
distSource.synchronizeDistribution(repo.getName(), distReport, distDetails);
- log.info("synchronizeDistributions: [" + contentSource.getName() + "]: loaded existing list of size=["
+ log.info("synchronizeDistributions: [" + contentSource.getName() +
+ "]: loaded existing list of size=["
+ dists.size() + "] (" + (System.currentTimeMillis() - start) + ")ms");
results.setResults(progress.toString());
@@ -327,22 +342,26 @@ public class ContentProviderManager {
distSource.synchronizeDistribution(repo.getName(), distReport, distDetails);
- log.info("synchronizeDistributions: [" + contentSource.getName() + "]: got sync report from adapter=["
+ log.info("synchronizeDistributions: [" + contentSource.getName() +
+ "]: got sync report from adapter=["
+ distReport + "] (" + (System.currentTimeMillis() - start) + ")ms");
progress.append("new=").append(distReport.getDistributions().size());
- progress.append(", deleted=").append(distReport.getDeletedDistributions().size()).append('\n');
+ progress.append(", deleted=").append(distReport.getDeletedDistributions().size())
+ .append('\n');
results.setResults(progress.toString());
results = contentSourceManager.mergeContentSourceSyncResults(results);
start = System.currentTimeMillis();
- results = contentSourceManager.mergeContentSourceSyncReport(contentSource, distReport, results);
+ results = contentSourceManager
+ .mergeContentSourceSyncReport(contentSource, distReport, results);
}
- // let's reset our progress string to the full results including the text added by the merge
+ // Reset our progress string to the full results including the text added by the merge
progress.setLength(0);
progress.append(results.getResults());
- log.info("synchronizeDistributions: [" + contentSource.getName() + "]: report has been merged ("
+ log.info("synchronizeDistributions: [" + contentSource.getName() +
+ "]: report has been merged ("
+ (System.currentTimeMillis() - start) + ")ms");
progress.append(new Date()).append(": ").append("DONE.");
@@ -351,10 +370,13 @@ public class ContentProviderManager {
results = contentSourceManager.mergeContentSourceSyncResults(results);
}
- } catch (Throwable t) {
+ }
+ catch (Throwable t) {
if (results != null) {
- // try to reload the results in case it was updated by the SLSB before the exception happened
- ContentSourceSyncResults reloadedResults = contentSourceManager.getContentSourceSyncResults(results.getId());
+ // try to reload the results in case it was updated by the SLSB before the
+ // exception happened
+ ContentSourceSyncResults reloadedResults = contentSourceManager
+ .getContentSourceSyncResults(results.getId());
if (reloadedResults != null) {
results = reloadedResults;
if (results.getResults() != null) {
@@ -386,11 +408,9 @@ public class ContentProviderManager {
/**
* Tests the connection to the content source that has the given ID.
*
- * @param contentSourceId
- *
- * @return <code>true</code> if there is an adapter that can successfully connect to the given content source <code>
- * false</code> if there is an adapter but it cannot successfully connect
- *
+ * @param contentSourceId
+ * @return <code>true</code> if there is an adapter that can successfully connect to the given
+ * content source <code>false</code> if there is an adapter but it cannot connect
* @throws Exception if failed to get an adapter to attempt the connection
*/
public boolean testConnection(int contentSourceId) throws Exception {
@@ -398,7 +418,8 @@ public class ContentProviderManager {
try {
adapter.testConnection();
- } catch (Throwable t) {
+ }
+ catch (Throwable t) {
return false;
}
@@ -417,10 +438,12 @@ public class ContentProviderManager {
}
/**
- * Call this method when a new content source is added to the system during runtime. This can also be used to
- * restart an adapter that was previously {@link #shutdownAdapter(ContentSource) shutdown}.
+ * Call this method when a new content source is added to the system during runtime. This can
+ * also be used to restart an adapter that was previously {@link #shutdownAdapter(ContentSource)
+ * shutdown}.
*
- * <p>If there is already an adapter currently started for the given content source, this returns silently.</p>
+ * <p>If there is already an adapter currently started for the given content source, this
+ * returns silently.</p>
*
* @param contentSource the new content source that was added
* @throws InitializationException if the provider throws an error on its startup
@@ -440,8 +463,11 @@ public class ContentProviderManager {
ContentProvider adapter = getIsolatedContentSourceAdapter(contentSource);
adapter.initialize(contentSource.getConfiguration());
- } catch (Exception e) {
- log.warn("Failed to initialize adapter for content source [" + contentSource.getName() + "]", e);
+ }
+ catch (Exception e) {
+ log.warn(
+ "Failed to initialize adapter for content source [" + contentSource.getName() + "]",
+ e);
throw new InitializationException(e);
}
@@ -449,10 +475,12 @@ public class ContentProviderManager {
}
/**
- * Call this method when a content source is removed from the system during runtime or if you just want to shutdown
- * the adapter for whatever reason. You can restart the adapter by calling {@link #startAdapter(ContentSource)}.
+ * Call this method when a content source is removed from the system during runtime or if you
+ * just want to shutdown the adapter for whatever reason. You can restart the adapter by calling
+ * {@link #startAdapter(ContentSource)}.
*
- * <p>If there are no adapters currently started for the given content source, this returns silently.</p>
+ * <p>If there are no adapters currently started for the given content source, this returns
+ * silently.</p>
*
* @param contentSource the content source being deleted
*/
@@ -469,17 +497,19 @@ public class ContentProviderManager {
ContentProvider adapter = getIsolatedContentSourceAdapter(contentSource);
adapter.shutdown();
- } catch (Throwable t) {
- log.warn("Failed to shutdown adapter for content source [" + contentSource.getName() + "]", t);
+ }
+ catch (Throwable t) {
+ log.warn(
+ "Failed to shutdown adapter for content source [" + contentSource.getName() + "]", t);
} finally {
this.adapters.remove(contentSource);
}
}
/**
- * Convienence method that simply {@link #shutdownAdapter(ContentSource) shuts down the adapter} and then
- * {@link #startAdapter(ContentSource) restarts it}. Call this when, for example, a content source's
- * {@link ContentSource#getConfiguration() configuration} has changed.
+ * Convienence method that simply {@link #shutdownAdapter(ContentSource) shuts down the adapter}
+ * and then {@link #startAdapter(ContentSource) restarts it}. Call this when, for example, a
+ * content source's {@link ContentSource#getConfiguration() configuration} has changed.
*
* @param contentSource the content source whose adapter is to be restarted
* @throws Exception if there is an error asking the provider to shutdown or start
@@ -494,18 +524,21 @@ public class ContentProviderManager {
*
* <p>This is protected so only the plugin container and subclasses can use it.</p>
*
- * @param pluginManager the plugin manager this object can use to obtain information from (like classloaders)
+ * @param pluginManager the plugin manager this object can use to obtain information from (like
+ * classloaders)
* @throws InitializationException if any of the providers throw an error on startup
*/
protected void initialize(ContentServerPluginManager pluginManager) {
this.pluginManager = pluginManager;
- ContentSourceMetadataManagerLocal metadataManager = LookupUtil.getContentSourceMetadataManager();
+ ContentSourceMetadataManagerLocal metadataManager = LookupUtil
+ .getContentSourceMetadataManager();
ContentSourceManagerLocal contentSourceManager = LookupUtil.getContentSourceManager();
// Our plugin manager should have parsed all descriptors and have our types for us.
// Let's register the types to make sure they are merged with the old existing types.
- ContentSourcePluginMetadataManager pluginMetadataManager = this.pluginManager.getMetadataManager();
+ ContentSourcePluginMetadataManager pluginMetadataManager = this.pluginManager
+ .getMetadataManager();
Set<ContentSourceType> allTypes = pluginMetadataManager.getAllContentSourceTypes();
metadataManager.registerTypes(allTypes);
@@ -521,7 +554,8 @@ public class ContentProviderManager {
for (ContentSource contentSource : contentSources) {
try {
startAdapter(contentSource);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.warn("Failed to start adapator for content source [" + contentSource + "]");
}
}
@@ -560,13 +594,12 @@ public class ContentProviderManager {
}
/**
- * Given a ID to a content source, this returns the adapter that is responsible for communicating with that content
- * source where that adapter object will ensure invocations on it are isolated to its plugin classloader.
- *
- * @param contentProviderId an ID to a {@link ContentSource}
+ * Given a ID to a content source, this returns the adapter that is responsible for communicating
+ * with that content source where that adapter object will ensure invocations on it are isolated
+ * to its plugin classloader.
*
+ * @param contentProviderId an ID to a {@link ContentSource}
* @return the adapter that is communicating with the content source, isolated to its classloader
- *
* @throws RuntimeException if there is no content source with the given ID
*/
public ContentProvider getIsolatedContentProvider(int contentProviderId) throws RuntimeException {
@@ -578,20 +611,20 @@ public class ContentProviderManager {
}
}
- throw new RuntimeException("Content source ID [" + contentProviderId + "] doesn't exist; can't get adapter");
+ throw new RuntimeException(
+ "Content source ID [" + contentProviderId + "] doesn't exist; can't get adapter");
}
/**
- * This returns the adapter that is responsible for communicating with the given content source where that adaptor
- * object will ensure invocations on it are isolated to its plugin classloader.
- *
- * @param contentSource the returned adapter communicates with this content source
+ * This returns the adapter that is responsible for communicating with the given content source
+ * where that adaptor object will ensure invocations on it are isolated to its plugin classloader.
*
+ * @param contentSource the returned adapter communicates with this content source
* @return the adapter that is communicating with the content source, isolated to its classloader
- *
* @throws RuntimeException if there is no content source adapter available
*/
- protected ContentProvider getIsolatedContentSourceAdapter(ContentSource contentSource) throws RuntimeException {
+ protected ContentProvider getIsolatedContentSourceAdapter(ContentSource contentSource)
+ throws RuntimeException {
ContentProvider adapter;
synchronized (this.adapters) {
@@ -602,9 +635,11 @@ public class ContentProviderManager {
throw new RuntimeException("There is no adapter for content source [" + adapter + "]");
}
- ServerPluginEnvironment env = this.pluginManager.getPluginEnvironment(contentSource.getContentSourceType());
+ ServerPluginEnvironment env = this.pluginManager
+ .getPluginEnvironment(contentSource.getContentSourceType());
if (env == null) {
- throw new RuntimeException("There is no plugin env. for content source [" + contentSource + "]");
+ throw new RuntimeException(
+ "There is no plugin env. for content source [" + contentSource + "]");
}
ClassLoader classLoader = env.getPluginClassLoader();
@@ -631,8 +666,7 @@ public class ContentProviderManager {
/**
* Creates a provider instance that will service the give {@link ContentSource}.
*
- * @param contentSource the source that the adapter will connect to
- *
+ * @param contentSource the source that the adapter will connect to
* @return an adapter instance; will be <code>null</code> if failed to create adapter
*/
private ContentProvider instantiateAdapter(ContentSource contentSource) {
@@ -643,7 +677,8 @@ public class ContentProviderManager {
try {
ContentSourceType type = contentSource.getContentSourceType();
apiClassName = type.getContentSourceApiClass();
- pluginName = this.pluginManager.getMetadataManager().getPluginNameFromContentSourceType(type);
+ pluginName = this.pluginManager.getMetadataManager()
+ .getPluginNameFromContentSourceType(type);
ServerPluginEnvironment pluginEnv = this.pluginManager.getPluginEnvironment(pluginName);
ClassLoader pluginClassloader = pluginEnv.getPluginClassLoader();
@@ -663,8 +698,11 @@ public class ContentProviderManager {
} finally {
Thread.currentThread().setContextClassLoader(startingClassLoader);
}
- } catch (Throwable t) {
- log.warn("Failed to create the API class [" + apiClassName + "] for plugin [" + pluginName + "]", t);
+ }
+ catch (Throwable t) {
+ log.warn(
+ "Failed to create the API class [" + apiClassName + "] for plugin [" + pluginName +
+ "]", t);
}
if (adapter != null) {
@@ -677,13 +715,14 @@ public class ContentProviderManager {
}
/**
- * Translates the domain representation of a list of packages into DTOs used in the plugin APIs. During the
- * translation the two collections (allDetails and keyPVCSMap) will be populated with different
- * views into the data.
+ * Translates the domain representation of a list of packages into DTOs used in the plugin APIs.
+ * During the translation the two collections (allDetails and keyPVCSMap) will be populated with
+ * different views into the data.
*
- * @param existingPVCS list of packages in the form of the wrapper object linking them to the content source
+ * @param existingPVCS list of packages in the form of the wrapper object linking them to
+ * the content source
* @param allDetails set of all translated package DTOs
- * @param keyPVCSMap mapping of package version key to package domain object
+ * @param keyPVCSMap mapping of package version key to package domain object
*/
private void translateDomainToDto(List<PackageVersionContentSource> existingPVCS,
Set<ContentProviderPackageDetails> allDetails,
@@ -695,8 +734,9 @@ public class ContentProviderManager {
ResourceType rt = p.getPackageType().getResourceType();
ContentProviderPackageDetailsKey key;
- key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(), p.getPackageType()
- .getName(), pv.getArchitecture().getName(), rt.getName(), rt.getPlugin());
+ key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(),
+ p.getPackageType()
+ .getName(), pv.getArchitecture().getName(), rt.getName(), rt.getPlugin());
ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
details.setClassification(pv.getGeneralPackage().getClassification());
@@ -720,18 +760,21 @@ public class ContentProviderManager {
}
}
- private void translateDomainToDto(List<Distribution>dists, List<DistributionDetails> distDetails) {
+ private void translateDomainToDto(List<Distribution> dists,
+ List<DistributionDetails> distDetails) {
DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal();
- for (Distribution d: dists) {
- DistributionDetails detail = new DistributionDetails(d.getLabel(), d.getDistributionType().getName());
+ for (Distribution d : dists) {
+ DistributionDetails detail = new DistributionDetails(d.getLabel(),
+ d.getDistributionType().getName());
detail.setLabel(d.getLabel());
detail.setDistributionPath(d.getBasePath());
detail.setDescription(d.getDistributionType().getDescription());
List<DistributionFile> files = distManager.getDistributionFilesByDistId(d.getId());
- for (DistributionFile f: files) {
+ for (DistributionFile f : files) {
DistributionFileDetails dfd =
- new DistributionFileDetails(f.getRelativeFilename(), f.getLastModified(), f.getMd5sum());
+ new DistributionFileDetails(f.getRelativeFilename(), f.getLastModified(),
+ f.getMd5sum());
detail.addFile(dfd);
}
distDetails.add(detail);
@@ -739,8 +782,8 @@ public class ContentProviderManager {
}
/**
- * This will handle invocations to an object ensuring that the call is isolated to within the appropriate
- * classloader.
+ * This will handle invocations to an object ensuring that the call is isolated to within the
+ * appropriate classloader.
*/
private class IsolatedInvocationHandler implements InvocationHandler {
private final Object instance;
14 years, 6 months
[rhq] Branch 'content' - modules/enterprise
by jdob
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJob.java | 208 ++++++++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJobTest.java | 117 +++++
2 files changed, 325 insertions(+)
New commits:
commit dbd258e71a3348e5820dbbdd66a48a768b00efac
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 23 14:44:51 2009 -0500
635 - Initial implementation of RepoSyncJob. It's not actually being called yet and the RepoManager synchronizeRepos method needs to be flushed out with all of the pieces to be done in the sync.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJob.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJob.java
new file mode 100644
index 0000000..6c7891d
--- /dev/null
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJob.java
@@ -0,0 +1,208 @@
+/*
+* RHQ Management Platform
+* Copyright (C) 2009 Red Hat, Inc.
+* All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License, version 2, as
+* published by the Free Software Foundation, and/or the GNU Lesser
+* General Public License, version 2.1, also as published by the Free
+* Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License and the GNU Lesser General Public License
+* for more details.
+*
+* You should have received a copy of the GNU General Public License
+* and the GNU Lesser General Public License along with this program;
+* if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+package org.rhq.enterprise.server.scheduler.jobs;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.StatefulJob;
+
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.content.Repo;
+import org.rhq.enterprise.server.auth.SubjectManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * Quartz schedule job that handles synchronizing contents of a repo, including:
+ * <ul>
+ * <li>Package Metadata</li>
+ * <li>Package Bits</li>
+ * <li>Distribution Trees</li>
+ * </ul>
+ * <p/>
+ * Many of the calls out to the plugin are ultimately made from the
+ * {@link org.rhq.enterprise.server.plugin.pc.content.ContentProviderManager}. The methods in
+ * this job do not call that directly, but rather go through EJB methods to get there.
+ * <p/>
+ * This implements {@link StatefulJob} (as opposed to {@link org.quartz.Job}) because we do not need
+ * nor want this job triggered concurrently. That is, we don't need multiple instances of this job
+ * running at the same time.
+ * <p/>
+ * Much of the functionality in this class was migrated from {@link ContentSourceSyncJob}.
+ *
+ * @author Jason Dobies
+ */
+public class RepoSyncJob implements StatefulJob {
+
+ public static final String KEY_REPO_NAME = "repoName";
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute(JobExecutionContext context) throws JobExecutionException {
+ try {
+ JobDetail jobDetail = context.getJobDetail();
+ if (jobDetail == null) {
+ throw new IllegalStateException("The job does not have any details");
+ }
+
+ JobDataMap dataMap = jobDetail.getJobDataMap();
+ if (dataMap == null) {
+ throw new IllegalStateException("The job does not have any data in its details");
+ }
+
+ String repoName = dataMap.getString(KEY_REPO_NAME);
+
+ if (repoName == null) {
+ throw new IllegalStateException("Missing repo name in details context");
+ }
+
+ sync(repoName);
+ }
+ catch (Exception e) {
+ String errorMsg = "Failed to sync repo in job [" + context.getJobDetail() + "]";
+
+ log.error(errorMsg, e);
+ JobExecutionException jobExecutionException = new JobExecutionException(errorMsg, e,
+ false);
+
+ // Do not retrigger if we threw IllegalStateException because it'll never work anyway
+ if (!(e instanceof IllegalStateException)) {
+ jobExecutionException.setUnscheduleAllTriggers(false);
+ }
+
+ throw jobExecutionException;
+ }
+ }
+
+ /**
+ * Creates (if necessary) and populates a job details map to contain the necessary data to
+ * perform a repo sync. If there is an existing details map in the provided details object,
+ * it will be reused, leaving existing data intact.
+ *
+ * @param details may not be <code>null</code>
+ * @param repo may not be <code>null</code>
+ * @return populated map used to drive a repo sync job; this will be the same map as what
+ * exists in the {@link JobDetail#getJobDataMap()} call of the details object if
+ * that call does not return <code>null</code>
+ */
+ public static JobDataMap createJobDataMap(JobDetail details, Repo repo) {
+ JobDataMap dataMap;
+
+ if (details != null) {
+ dataMap = details.getJobDataMap();
+ } else {
+ dataMap = new JobDataMap();
+ }
+
+ dataMap.put(KEY_REPO_NAME, repo.getName());
+
+ return dataMap;
+ }
+
+ /**
+ * Creates a name to use when scheduling a repo sync job. Calling this method multiple times
+ * on the same parameters will always produce the <em>same</em> name.
+ *
+ * @param repo may not be <code>null</code>
+ * @return name to use to schedule the job; will not be <code>null</code>
+ */
+ public static String createJobName(Repo repo) {
+ // The quartz table has a limited column width of 80 - but we need to use the names to make
+ // jobs unique so encode the names' hashcodes to ensure we fit into the quartz job name.
+ String jobName = Integer.toHexString(repo.getName().hashCode());
+
+ if (jobName.length() > 80) {
+ throw new IllegalArgumentException("Job names max size is 80 chars due to DB column " +
+ "size restrictions: " + jobName);
+ }
+
+ return jobName;
+ }
+
+ /**
+ * Performs similar to {#createJobName} except adds uniqueness to the name regardless of the
+ * parameters. In other words, calling this method multiple times on the same parameters
+ * will always (almost, it's based on system time) produce a <em>unique</em> name.
+ *
+ * @param repo may not be <code>null</code>
+ * @return name to use to schedule the job; will not be <code>null</code>
+ */
+ public static String createUniqueJobName(Repo repo) {
+ // Append current time to add uniqueness to exising job name algorithm
+ String jobName = createJobName(repo);
+
+ String uniquifier = Long.toHexString(System.currentTimeMillis());
+ jobName = jobName + "-" + uniquifier;
+
+ if (jobName.length() > 80) {
+ throw new IllegalArgumentException("Job names max size is 80 chars due to DB column " +
+ "size restrictions: " + jobName);
+ }
+
+ return jobName;
+ }
+
+
+ /**
+ * Performs the repo synchronization.
+ * <p/>
+ * Note that this method executes outside of any transaction. This is very important since this
+ * job is potentially very long running (on the order of hours potentially). We do our processing
+ * in here with this in mind. We make sure we never do any one thing that potentially could
+ * timeout a transaction.
+ *
+ * @param repoName may not be <code>null</code>
+ * @throws Exception if there is an error in the sync
+ */
+ private void sync(String repoName) throws Exception {
+
+ SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
+ RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
+
+ // Note that we will keep calling getOverlord on this subject manager - the overlord
+ // has a very short session lifespan so we need to keep asking for a new one, due to
+ // the possibility that some of the methods we call here take longer than its lifespan
+ Subject overlord;
+
+ overlord = subjectManager.getOverlord();
+ List<Repo> repoList = repoManager.getRepoByName(repoName);
+
+ if (repoList.size() != 1) {
+ throw new Exception("Unexpected number of repos found for name [" + repoName + "]. " +
+ "Found [" + repoList.size() + "] repos");
+ }
+ Repo repoToSync = repoList.get(0);
+
+ // This call executes all of the logic associated with synchronizing the given repo
+ repoManager.synchronizeRepos(overlord, new Integer[]{repoToSync.getId()});
+ }
+}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJobTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJobTest.java
new file mode 100644
index 0000000..1927932
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/scheduler/jobs/RepoSyncJobTest.java
@@ -0,0 +1,117 @@
+/*
+* RHQ Management Platform
+* Copyright (C) 2009 Red Hat, Inc.
+* All rights reserved.
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License, version 2, as
+* published by the Free Software Foundation, and/or the GNU Lesser
+* General Public License, version 2.1, also as published by the Free
+* Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License and the GNU Lesser General Public License
+* for more details.
+*
+* You should have received a copy of the GNU General Public License
+* and the GNU Lesser General Public License along with this program;
+* if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+package org.rhq.enterprise.server.scheduler.jobs;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.content.Repo;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
+
+/**
+ * @author Jason Dobies
+ */
+public class RepoSyncJobTest extends AbstractEJB3Test {
+
+ private static final boolean ENABLED = true;
+
+ @BeforeMethod
+ public void beforeMethod() throws Exception {
+ prepareScheduler();
+ prepareForTestAgents();
+ }
+
+ @AfterMethod
+ public void afterMethod() throws Exception {
+ unprepareForTestAgents();
+ unprepareScheduler();
+ }
+
+ @Test(enabled = ENABLED)
+ public void createJobDataMap() throws Exception {
+ // Setup
+ String repoName = "testRepo";
+ Repo repo = new Repo(repoName);
+
+ JobDataMap existingMap = new JobDataMap();
+ JobDetail detail = new JobDetail();
+ detail.setJobDataMap(existingMap);
+
+ // Test
+ JobDataMap nullDetailsMap = RepoSyncJob.createJobDataMap(null, repo);
+ JobDataMap existingDetailsMap = RepoSyncJob.createJobDataMap(detail, repo);
+
+ // Verify
+ assert nullDetailsMap.getString(RepoSyncJob.KEY_REPO_NAME).equals(repoName);
+
+ assert existingDetailsMap.getString(RepoSyncJob.KEY_REPO_NAME).equals(repoName);
+ assert existingDetailsMap == existingMap;
+ }
+
+ @Test(enabled = ENABLED)
+ public void createJobName() throws Exception {
+ // Setup
+ Repo repo = new Repo("testRepo");
+
+ // Test
+ Set<String> jobNames = new HashSet<String>(1);
+
+ jobNames.add(RepoSyncJob.createJobName(repo));
+ jobNames.add(RepoSyncJob.createJobName(repo));
+ jobNames.add(RepoSyncJob.createJobName(repo));
+ jobNames.add(RepoSyncJob.createJobName(repo));
+ jobNames.add(RepoSyncJob.createJobName(repo));
+
+ // Verify
+ assert jobNames.size() == 1 : "Number of jobs found: " + jobNames.size();
+ }
+
+ @Test(enabled = ENABLED)
+ public void createUniqueJobName() throws Exception {
+ // Setup
+ Repo repo = new Repo("testRepo");
+
+ // Test
+ Set<String> jobNames = new HashSet<String>(1);
+
+ jobNames.add(RepoSyncJob.createUniqueJobName(repo));
+ Thread.sleep(100); // Need a quick pause to allow for uniqueness
+ jobNames.add(RepoSyncJob.createUniqueJobName(repo));
+ Thread.sleep(100);
+ jobNames.add(RepoSyncJob.createUniqueJobName(repo));
+ Thread.sleep(100);
+ jobNames.add(RepoSyncJob.createUniqueJobName(repo));
+ Thread.sleep(100);
+ jobNames.add(RepoSyncJob.createUniqueJobName(repo));
+
+ // Verify
+ assert jobNames.size() == 5 : "Number of jobs found: " + jobNames.size();
+ }
+
+}
14 years, 6 months
[rhq] Branch 'content' - modules/enterprise
by Jeff Ortel
modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/repoAssociations.xhtml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
New commits:
commit d8811ca4d11e919fb3e00c3e091912dcf1983c16
Author: Jeff Ortel <jortel(a)redhat.com>
Date: Mon Nov 23 13:27:08 2009 -0600
537207 - updated 'Content Sources' to 'Content Providers' in table titles.
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/repoAssociations.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/repoAssociations.xhtml
index 1d06075..39d1cce 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/repoAssociations.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/repoAssociations.xhtml
@@ -31,7 +31,7 @@
</h:outputLink>
>
<h:outputLink value="repoAssociations.xhtml">
- Associate With Content Sources
+ Associate With Content Providers
<f:param name="id" value="#{item.id}" />
</h:outputLink>
</ui:define>
@@ -55,7 +55,7 @@
<rich:panel>
<f:facet name="header">
- <h:outputText value="Content Sources Associated With This Repository"/>
+ <h:outputText value="Content Providers Associated With This Repository"/>
</f:facet>
<h:panelGrid columns="1" width="100%">
@@ -177,7 +177,7 @@
<rich:panel>
<f:facet name="header">
- <h:outputText value="Available Content Sources"/>
+ <h:outputText value="Available Content Providers"/>
</f:facet>
<h:panelGrid columns="1" width="100%">
14 years, 6 months
[rhq] Branch 'content' - modules/enterprise
by Jeff Ortel
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentProviderDetailsUIBean.java | 8 ++---
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceReposUIBean.java | 7 ++---
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceSyncResultsUIBean.java | 6 ++--
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateContentSourceUIBean.java | 6 ++--
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java | 14 +++++-----
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListContentSourcesUIBean.java | 11 +++----
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java | 3 --
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoAssociationsUIBean.java | 9 +++---
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoContentSourcesUIBean.java | 5 +--
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDetailsUIBean.java | 4 +-
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDisassociationsUIBean.java | 12 +++-----
11 files changed, 41 insertions(+), 44 deletions(-)
New commits:
commit f4fb61b22dbe018c7dd1ece28d9d1fbfbd52ecf3
Author: Jeff Ortel <jortel(a)redhat.com>
Date: Mon Nov 23 13:13:22 2009 -0600
537207 - Fix confirmation messages to read content 'provider' and spell out 'repository'.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentProviderDetailsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentProviderDetailsUIBean.java
index 12e3800..2eb1707 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentProviderDetailsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentProviderDetailsUIBean.java
@@ -49,10 +49,10 @@ public class ContentProviderDetailsUIBean {
try {
manager.updateContentSource(subject, contentSource);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "The content source [" + contentSource.getName()
- + "] has been updated.");
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "The content provider ["
+ + contentSource.getName() + "] has been updated.");
} catch (Exception e) {
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_WARN, "Failed to update content source ["
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_WARN, "Failed to update content provider ["
+ contentSource.getName() + "]", e);
}
@@ -89,7 +89,7 @@ public class ContentProviderDetailsUIBean {
try {
manager.synchronizeAndLoadContentSource(subject, contentSource.getId());
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Synchronizing content source ["
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Synchronizing content provider ["
+ contentSource.getName() + "] now.");
} catch (Exception e) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_WARN,
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceReposUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceReposUIBean.java
index a056ee7..455be12 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceReposUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceReposUIBean.java
@@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.content;
import javax.faces.application.FacesMessage;
import javax.faces.model.DataModel;
+
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.util.PageControl;
@@ -29,8 +30,8 @@ import org.rhq.enterprise.gui.common.framework.PagedDataTableUIBean;
import org.rhq.enterprise.gui.common.paging.PageControlView;
import org.rhq.enterprise.gui.common.paging.PagedListDataModel;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
-import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
public class ContentSourceReposUIBean extends PagedDataTableUIBean {
@@ -53,10 +54,10 @@ public class ContentSourceReposUIBean extends PagedDataTableUIBean {
}
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Disassociated [" + repoIds.length
- + "] repositories from content source");
+ + "] repositories from content provider");
} catch (Exception e) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to disassociate one or more repositories from content source", e);
+ "Failed to disassociate one or more repositories from content provider", e);
}
}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceSyncResultsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceSyncResultsUIBean.java
index d400b8b..eddd8cc 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceSyncResultsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ContentSourceSyncResultsUIBean.java
@@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.content;
import javax.faces.application.FacesMessage;
import javax.faces.model.DataModel;
+
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.ContentSourceSyncResults;
import org.rhq.core.domain.util.PageControl;
@@ -49,10 +50,10 @@ public class ContentSourceSyncResultsUIBean extends PagedDataTableUIBean {
contentSourceManager.deleteContentSourceSyncResults(subject, ids);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Deleted [" + ids.length
- + "] content source sync results.");
+ + "] content provider sync results.");
} catch (Exception e) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to delete content source sync results.", e);
+ "Failed to delete content provider sync results.", e);
}
}
@@ -75,7 +76,6 @@ public class ContentSourceSyncResultsUIBean extends PagedDataTableUIBean {
}
@Override
- @SuppressWarnings("unchecked")
public PageList<ContentSourceSyncResults> fetchPage(PageControl pc) {
Subject subject = EnterpriseFacesContextUtility.getSubject();
int id = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateContentSourceUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateContentSourceUIBean.java
index 2625f61..eb4f814 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateContentSourceUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateContentSourceUIBean.java
@@ -84,11 +84,11 @@ public class CreateContentSourceUIBean extends PagedDataTableUIBean {
}
public String getNullConfigurationDefinitionMessage() {
- return "The selected content source type does not require a configuration.";
+ return "The selected content provider type does not require a configuration.";
}
public String getNullConfigurationMessage() {
- return "Content source has an empty configuration."; // is this ever really used?
+ return "Content provider has an empty configuration."; // is this ever really used?
}
public String save() {
@@ -138,7 +138,7 @@ public class CreateContentSourceUIBean extends PagedDataTableUIBean {
}
}
- // reset the content source's sync schedule and other settings to the new type's defaults
+ // reset the content provider's sync schedule and other settings to the new type's defaults
newContentSource.setSyncSchedule(cst.getDefaultSyncSchedule());
newContentSource.setLazyLoad(cst.isDefaultLazyLoad());
newContentSource.setDownloadMode(cst.getDefaultDownloadMode());
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
index 294bfe4..a520b21 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/CreateNewPackageUIBean.java
@@ -34,11 +34,11 @@ import org.richfaces.model.UploadItem;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.Architecture;
-import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.content.InstalledPackage;
import org.rhq.core.domain.content.Package;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.content.PackageVersion;
+import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.content.composite.RepoComposite;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCreationDataType;
@@ -46,10 +46,10 @@ import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
-import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.ContentException;
import org.rhq.enterprise.server.content.ContentManagerLocal;
import org.rhq.enterprise.server.content.ContentUIManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
/**
@@ -162,14 +162,14 @@ public class CreateNewPackageUIBean {
}
if (repoOption == null) {
- FacesContextUtility
- .addMessage(FacesMessage.SEVERITY_ERROR, "A repo deployment option must be specified");
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
+ "A repository deployment option must be specified");
return null;
}
if (repoOption.equals(REPO_OPTION_NEW) && (newRepoName == null || newRepoName.trim().equals(""))) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "When creating a new repo, the name of the repo to be created must be specified");
+ "When creating a new repo, the name of the repository to be created must be specified");
return null;
}
@@ -184,7 +184,7 @@ public class CreateNewPackageUIBean {
repoId = determineRepo(repoOption, subject, resource.getId());
} catch (ContentException ce) {
String errorMessages = ThrowableUtil.getAllMessages(ce);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to determine repo. Cause: "
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to determine repository. Cause: "
+ errorMessages);
return "failure";
}
@@ -234,7 +234,7 @@ public class CreateNewPackageUIBean {
} catch (Exception e) {
String errorMessages = ThrowableUtil.getAllMessages(e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to associate package ["
- + packageName + "] with repo ID [" + repoId + "]. Cause: " + errorMessages);
+ + packageName + "] with repository ID [" + repoId + "]. Cause: " + errorMessages);
return "failure";
}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListContentSourcesUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListContentSourcesUIBean.java
index a311f63..bd9f392 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListContentSourcesUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListContentSourcesUIBean.java
@@ -57,9 +57,9 @@ public class ListContentSourcesUIBean extends PagedDataTableUIBean {
}
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Deleted [" + ids.length
- + "] content sources.");
+ + "] content providers.");
} catch (Exception e) {
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to delete content sources.", e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to delete content providers.", e);
}
}
@@ -78,10 +78,10 @@ public class ListContentSourcesUIBean extends PagedDataTableUIBean {
}
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Synchronizing [" + ids.length
- + "] content sources.");
+ + "] content providers.");
} catch (Exception e) {
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to synchronized content sources.",
- e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
+ "Failed to synchronized content providers.", e);
}
}
@@ -103,7 +103,6 @@ public class ListContentSourcesUIBean extends PagedDataTableUIBean {
}
@Override
- @SuppressWarnings("unchecked")
public PageList<ContentSource> fetchPage(PageControl pc) {
Subject subject = EnterpriseFacesContextUtility.getSubject();
ContentSourceManagerLocal manager = LookupUtil.getContentSourceManager();
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java
index 3e8e315..e3ac9d1 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java
@@ -66,7 +66,7 @@ public class ListReposUIBean extends PagedDataTableUIBean {
int syncCount = repoManager.synchronizeRepos(subject, repoIds);
if (syncCount > 0) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Synchronizing [" + syncCount
- + "] content sources.");
+ + "] content providers.");
} else {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
"Selected Repositories have no content to sync.");
@@ -112,7 +112,6 @@ public class ListReposUIBean extends PagedDataTableUIBean {
}
@Override
- @SuppressWarnings("unchecked")
public PageList<Repo> fetchPage(PageControl pc) {
Subject subject = EnterpriseFacesContextUtility.getSubject();
RepoManagerLocal manager = LookupUtil.getRepoManagerLocal();
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoAssociationsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoAssociationsUIBean.java
index 1a07232..b562471 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoAssociationsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoAssociationsUIBean.java
@@ -20,8 +20,10 @@ package org.rhq.enterprise.gui.content;
import java.util.HashMap;
import java.util.Map;
+
import javax.faces.application.FacesMessage;
import javax.faces.model.DataModel;
+
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.util.PageControl;
@@ -35,7 +37,7 @@ import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
/**
- * This is the list of content sources that are currently associated with a repo.
+ * This is the list of content providers that are currently associated with a repo.
*/
public class RepoAssociationsUIBean extends PagedDataTableUIBean {
public static final String MANAGED_BEAN_NAME = "RepoAssociationsUIBean";
@@ -75,10 +77,10 @@ public class RepoAssociationsUIBean extends PagedDataTableUIBean {
manager.removeContentSourcesFromRepo(subject, repoId, contentSourceIds);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Disassociated [" + contentSourceIds.length
- + "] content sources from repo");
+ + "] content providers from repo");
} catch (Exception e) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to disassociate one or more content sources from repo", e);
+ "Failed to disassociate one or more content providers from repo", e);
}
}
@@ -100,7 +102,6 @@ public class RepoAssociationsUIBean extends PagedDataTableUIBean {
}
@Override
- @SuppressWarnings("unchecked")
public PageList<ContentSource> fetchPage(PageControl pc) {
Subject subject = EnterpriseFacesContextUtility.getSubject();
int id = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoContentSourcesUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoContentSourcesUIBean.java
index b465f19..b2821b2 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoContentSourcesUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoContentSourcesUIBean.java
@@ -55,10 +55,10 @@ public class RepoContentSourcesUIBean extends PagedDataTableUIBean {
manager.removeContentSourcesFromRepo(subject, repoId, contentSourceIds);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Disassociated [" + contentSourceIds.length
- + "] content sources from repo");
+ + "] content providers from repo");
} catch (Exception e) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to disassociate one or more content sources from repo", e);
+ "Failed to disassociate one or more content providers from repo", e);
}
}
@@ -80,7 +80,6 @@ public class RepoContentSourcesUIBean extends PagedDataTableUIBean {
}
@Override
- @SuppressWarnings("unchecked")
public PageList<ContentSource> fetchPage(PageControl pc) {
Subject subject = EnterpriseFacesContextUtility.getSubject();
int id = Integer.valueOf(FacesContextUtility.getRequiredRequestParameter("id"));
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDetailsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDetailsUIBean.java
index 4fe6cfd..f850d0f 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDetailsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDetailsUIBean.java
@@ -53,7 +53,7 @@ public class RepoDetailsUIBean {
if (syncCount > 0) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "The repository is syncing.");
} else {
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Nothing to sync for this Repository.");
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Nothing to sync for this repository.");
}
return "success";
}
@@ -64,7 +64,7 @@ public class RepoDetailsUIBean {
try {
manager.updateRepo(subject, repo);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "The repo has been updated.");
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "The repository has been updated.");
} catch (ContentException ce) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Error: " + ce.getMessage());
return "edit"; // stay in edit mode on failure
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDisassociationsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDisassociationsUIBean.java
index 3f2dbc6..4461ace 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDisassociationsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/RepoDisassociationsUIBean.java
@@ -30,12 +30,12 @@ import org.rhq.enterprise.gui.common.framework.PagedDataTableUIBean;
import org.rhq.enterprise.gui.common.paging.PageControlView;
import org.rhq.enterprise.gui.common.paging.PagedListDataModel;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
-import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
/**
- * This is the list of content sources that are currently disassociated from a repo.
+ * This is the list of content providers that are currently disassociated from a repo.
*/
public class RepoDisassociationsUIBean extends PagedDataTableUIBean {
public static final String MANAGED_BEAN_NAME = "RepoDisassociationsUIBean";
@@ -55,10 +55,10 @@ public class RepoDisassociationsUIBean extends PagedDataTableUIBean {
manager.addContentSourcesToRepo(subject, repoId, contentSourceIds);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Associated [" + contentSourceIds.length
- + "] content sources with repo");
+ + "] content providers with repo");
} catch (Exception e) {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "Failed to associate one or more content sources with repo", e);
+ "Failed to associate one or more content providers with repo", e);
}
}
@@ -68,8 +68,7 @@ public class RepoDisassociationsUIBean extends PagedDataTableUIBean {
@Override
public DataModel getDataModel() {
if (dataModel == null) {
- dataModel = new RepoDisassociationsDataModel(PageControlView.RepoDisassociationsList,
- MANAGED_BEAN_NAME);
+ dataModel = new RepoDisassociationsDataModel(PageControlView.RepoDisassociationsList, MANAGED_BEAN_NAME);
}
return dataModel;
@@ -81,7 +80,6 @@ public class RepoDisassociationsUIBean extends PagedDataTableUIBean {
}
@Override
- @SuppressWarnings("unchecked")
public PageList<ContentSource> fetchPage(PageControl pc) {
Subject subject = EnterpriseFacesContextUtility.getSubject();
ContentSourceManagerLocal manager = LookupUtil.getContentSourceManager();
14 years, 6 months
[rhq] Branch 'pc' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java | 53 ++++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java | 8 -
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java | 74 +++++++---
3 files changed, 92 insertions(+), 43 deletions(-)
New commits:
commit c8a8622dce3142a91725a0a152bee94be64a9259
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Mon Nov 23 14:05:06 2009 -0500
because we put the byte[] content directly in the plugin entity, we can't entityManager.find() because that would load the full plugin content.
instead, use getReference. when we need to load the relationships, we have to play games by
loading in the configs directly and doing a deep copy (mainly to workaround a hibernate bug)
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index 157911d..ce603da 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
@@ -94,11 +94,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public Plugin getServerPluginRelationships(Plugin plugin) {
- plugin = entityManager.find(Plugin.class, plugin.getId());
+ plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
- // force eager load
- plugin.getPluginConfiguration().getProperties().size();
- plugin.getScheduledJobsConfiguration().getProperties().size();
+ int pluginConfigId = plugin.getPluginConfiguration().getId();
+ int scheduledJobsId = plugin.getScheduledJobsConfiguration().getId();
+ Configuration pluginConfig = entityManager.find(Configuration.class, pluginConfigId);
+ Configuration scheduledJobs = entityManager.find(Configuration.class, scheduledJobsId);
+ plugin.setPluginConfiguration(pluginConfig.deepCopyWithoutProxies());
+ plugin.setScheduledJobsConfiguration(scheduledJobs.deepCopyWithoutProxies());
return plugin;
}
@@ -146,9 +149,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public List<Plugin> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ public List<String> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<Plugin>(); // nothing to do
+ return new ArrayList<String>(); // nothing to do
}
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
@@ -156,19 +159,24 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
- List<Plugin> doomedPlugins = new ArrayList<Plugin>();
+ List<String> doomedPlugins = new ArrayList<String>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = entityManager.find(Plugin.class, pluginId);
+ Plugin doomedPlugin = null;
+ try {
+ doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ } catch (Exception ignore) {
+ }
if (doomedPlugin != null) {
- doomedPlugins.add(doomedPlugin);
+ String pluginName = doomedPlugin.getName();
+ doomedPlugins.add(pluginName);
if (master != null) {
- AbstractTypeServerPluginContainer pc = master.getPluginContainer(doomedPlugin.getName());
+ AbstractTypeServerPluginContainer pc = master.getPluginContainer(pluginName);
if (pc != null) {
try {
- pc.unschedulePluginJobs(doomedPlugin.getName());
+ pc.unschedulePluginJobs(pluginName);
} catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" + doomedPlugin.getName() + "]", e);
+ log.warn("Failed to unschedule jobs for plugin [" + pluginName + "]", e);
}
}
}
@@ -184,9 +192,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public List<Plugin> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ public List<String> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<Plugin>(); // nothing to do
+ return new ArrayList<String>(); // nothing to do
}
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
@@ -194,19 +202,24 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
- List<Plugin> doomedPlugins = new ArrayList<Plugin>();
+ List<String> doomedPlugins = new ArrayList<String>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = entityManager.find(Plugin.class, pluginId);
+ Plugin doomedPlugin = null;
+ try {
+ doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ } catch (Exception ignore) {
+ }
if (doomedPlugin != null) {
- doomedPlugins.add(doomedPlugin);
+ String pluginName = doomedPlugin.getName();
+ doomedPlugins.add(pluginName);
if (master != null) {
- AbstractTypeServerPluginContainer pc = master.getPluginContainer(doomedPlugin.getName());
+ AbstractTypeServerPluginContainer pc = master.getPluginContainer(pluginName);
if (pc != null) {
try {
- pc.unschedulePluginJobs(doomedPlugin.getName());
+ pc.unschedulePluginJobs(pluginName);
} catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" + doomedPlugin.getName() + "]", e);
+ log.warn("Failed to unschedule jobs for plugin [" + pluginName + "]", e);
}
}
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
index 6f3600e..803f7cf 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
@@ -86,20 +86,20 @@ public interface ServerPluginsLocal {
*
* @param subject user making the request
* @param pluginIds the plugins to be disabled
- * @return the list of plugins that were disabled
+ * @return the list of names of the plugins that were disabled
* @throws Exception if failed to disable a plugin
*/
- List<Plugin> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
+ List<String> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
/**
* Removes the plugin from the system and restarts the server plugin container.
*
* @param subject user making the request
* @param pluginIds
- * @return the list of plugins that were undeployed
+ * @return the list of names of plugins that were undeployed
* @throws Exception if failed to undeploy a plugin
*/
- List<Plugin> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
+ List<String> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
/**
* Turns on or off the enabled flag in the database but does NOT restart the server plugin container.
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
index e1796bf..d1a6aba 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
@@ -135,6 +135,24 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assetLazyInitializationException(plugins.get(1));
}
+ public void testUpdatePlugins() throws Exception {
+ Plugin p1 = registerPlugin(1);
+ p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
+ p1 = this.serverPluginsBean.getServerPluginRelationships(p1);
+
+ Plugin p1update = this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
+ p1update = this.serverPluginsBean.getServerPluginRelationships(p1update);
+
+ assert p1update.getId() == p1.getId() : p1update;
+ assert p1update.getId() == p1.getId() : p1update;
+ assert p1update.getName().equals(p1.getName()) : p1update;
+ assert p1update.getName().equals(p1.getName()) : p1update;
+ assert p1update.getPluginConfiguration().equals(p1.getPluginConfiguration()) : p1update;
+ assert p1update.getScheduledJobsConfiguration().equals(p1.getScheduledJobsConfiguration()) : p1update;
+ p1update.getPluginConfiguration().equals(p1.getPluginConfiguration());
+ p1update.getScheduledJobsConfiguration().equals(p1.getScheduledJobsConfiguration());
+ }
+
public void testDisableEnablePlugins() throws Exception {
Plugin p1 = registerPlugin(1);
Plugin p2 = registerPlugin(2);
@@ -142,12 +160,13 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<Plugin> disabled = this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
+ List<String> disabled = this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
assert disabled.size() == 2 : disabled;
- assert disabled.contains(p1) : disabled;
- assert disabled.contains(p2) : disabled;
- assert disabled.get(0).getStatus() == PluginStatusType.INSTALLED; // still installed
- assert disabled.get(1).getStatus() == PluginStatusType.INSTALLED; // still installed
+ assert disabled.contains(p1.getName()) : disabled;
+ assert disabled.contains(p2.getName()) : disabled;
+ ;
+ assert this.serverPluginsBean.getServerPlugin(p1.getName()).getStatus() == PluginStatusType.INSTALLED; // still installed
+ assert this.serverPluginsBean.getServerPlugin(p2.getName()).getStatus() == PluginStatusType.INSTALLED; // still installed
List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
@@ -195,12 +214,14 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<Plugin> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
+ List<String> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
- assert undeployed.contains(p1) : undeployed;
- assert undeployed.contains(p2) : undeployed;
- assert undeployed.get(0).getStatus() == PluginStatusType.DELETED;
- assert undeployed.get(1).getStatus() == PluginStatusType.DELETED;
+ assert undeployed.contains(p1.getName()) : undeployed;
+ assert undeployed.contains(p2.getName()) : undeployed;
+ Plugin p1deleted = getDeletedPluginInTx(p1.getName());
+ Plugin p2deleted = getDeletedPluginInTx(p2.getName());
+ assert p1deleted.getStatus() == PluginStatusType.DELETED;
+ assert p2deleted.getStatus() == PluginStatusType.DELETED;
List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be returned even here" + pluginNames;
@@ -230,16 +251,18 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<Plugin> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
+ List<String> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
- assert undeployed.contains(p1) : undeployed;
- assert undeployed.contains(p2) : undeployed;
- assert undeployed.get(0).getStatus() == PluginStatusType.DELETED;
- assert undeployed.get(0).getPluginConfiguration() == null; // undeploy should have removed this
- assert undeployed.get(0).getScheduledJobsConfiguration() == null; // undeploy should have removed this
- assert undeployed.get(1).getStatus() == PluginStatusType.DELETED;
- assert undeployed.get(1).getPluginConfiguration() == null; // undeploy should have removed this
- assert undeployed.get(1).getScheduledJobsConfiguration() == null; // undeploy should have removed this
+ assert undeployed.contains(p1.getName()) : undeployed;
+ assert undeployed.contains(p2.getName()) : undeployed;
+ Plugin p1deleted = getDeletedPluginInTx(p1.getName());
+ assert p1deleted.getStatus() == PluginStatusType.DELETED;
+ assert p1deleted.getPluginConfiguration() == null; // undeploy should have removed this
+ assert p1deleted.getScheduledJobsConfiguration() == null; // undeploy should have removed this
+ Plugin p2deleted = getDeletedPluginInTx(p1.getName());
+ assert p2deleted.getStatus() == PluginStatusType.DELETED;
+ assert p2deleted.getPluginConfiguration() == null; // undeploy should have removed this
+ assert p2deleted.getScheduledJobsConfiguration() == null; // undeploy should have removed this
List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be returned even here" + pluginNames;
@@ -320,4 +343,17 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
private Subject getOverlord() {
return LookupUtil.getSubjectManager().getOverlord();
}
+
+ private Plugin getDeletedPluginInTx(String pluginName) throws Exception {
+ EntityManager em = getEntityManager();
+ getTransactionManager().begin();
+ try {
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q.setParameter("name", pluginName);
+ q.setParameter("type", PluginDeploymentType.SERVER);
+ return (Plugin) q.getSingleResult();
+ } finally {
+ getTransactionManager().rollback();
+ }
+ }
}
14 years, 6 months
[rhq] Branch 'raw-config' - 2 commits - modules/core modules/pom.xml modules/test-utils
by John Sanda
modules/core/plugin-container/pom.xml | 6
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementTest.java | 1
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java | 64 -------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java | 51 -----
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadResourceConfigurationFactoryImplTest.java | 1
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java | 39 ----
modules/pom.xml | 6
modules/test-utils/pom.xml | 32 +++
modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java | 50 +++++
modules/test-utils/src/main/java/org/rhq/test/JMockTest.java | 51 +++++
modules/test-utils/src/main/java/org/rhq/test/MatchResult.java | 44 +++++
modules/test-utils/src/main/java/org/rhq/test/PropertyMatchException.java | 43 ++++
modules/test-utils/src/main/java/org/rhq/test/PropertyMatcher.java | 88 ++++++++++
modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java | 56 ++++++
14 files changed, 382 insertions(+), 150 deletions(-)
New commits:
commit 91cf9cc20ab0058bb6fabe6dc60e0f729e5beb01
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 23 13:47:21 2009 -0500
[US 6] Adding Javadocs
diff --git a/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java b/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
index bde72ba..03581eb 100644
--- a/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
+++ b/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
@@ -27,6 +27,16 @@ import static org.testng.Assert.*;
public class AssertUtils {
+ /**
+ * Verifies that all public, accessible properties of the two objects are equal. This method might be used when you
+ * want to compare two objects without using their <code>equals()</code> methods or when do not implement <code>
+ * equals()</code>.
+ *
+ * @param expected The expected object to compare against
+ * @param actual The actual object to be compared
+ * @param msg An error message
+ * @param <T> The type of the objects to be compared
+ */
public static <T> void assertPropertiesMatch(T expected, T actual, String msg) {
PropertyMatcher<T> matcher = new PropertyMatcher<T>();
matcher.setExpected(expected);
diff --git a/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java b/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java
index 3be7e2d..4a46adc 100644
--- a/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java
+++ b/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java
@@ -27,6 +27,11 @@ import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.Description;
import org.rhq.test.MatchResult;
+/**
+ * A JMock custom matcher that matches based on the public, accessible properties of an object.
+ *
+ * @param <T> The type of the object to match.
+ */
public class PropertyMatcher<T> extends TypeSafeMatcher<T> {
private T expected;
commit a89ac8b47d650b67df4a1446018f107ddaa1b3b9
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 23 13:28:30 2009 -0500
[US 6] Refactoring common test classes into test-utils module.
Moving JMockTest into test-utils so that it can be resued across different modules.
Initial commit for AssertUtils which for now contains only a single method,
assertPropertyMatches(). This method compare all accessible properties of two
objects. Internally, that method is implemented by org.rhq.test.PropertyMathcher.
Initial commit for org.rhq.test.jmock.PropertyMatcher. This is a custom JMock
matcher that performs matching based on the accessible properties of an object.
diff --git a/modules/core/plugin-container/pom.xml b/modules/core/plugin-container/pom.xml
index 90b481b..6285a42 100644
--- a/modules/core/plugin-container/pom.xml
+++ b/modules/core/plugin-container/pom.xml
@@ -96,9 +96,9 @@
</dependency>
<dependency>
- <groupId>org.jmock</groupId>
- <artifactId>jmock</artifactId>
- <version>2.5.1</version>
+ <groupId>${groupId}</groupId>
+ <artifactId>test-utils</artifactId>
+ <version>${version}</version>
<scope>test</scope>
</dependency>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementTest.java
index afed6b6..cf6e9e9 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementTest.java
@@ -28,6 +28,7 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.RawConfiguration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.test.JMockTest;
import static org.testng.Assert.assertEquals;
import java.util.HashSet;
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java
deleted file mode 100644
index 74bca9b..0000000
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
-import org.rhq.core.clientapi.server.configuration.ConfigurationUpdateResponse;
-
-public class ConfigurationUpdateResponseMatcher extends TypeSafeMatcher<ConfigurationUpdateResponse> {
-
- public static Matcher<ConfigurationUpdateResponse> matchingResponse(ConfigurationUpdateResponse expected) {
- return new ConfigurationUpdateResponseMatcher(expected);
- }
-
- private ConfigurationUpdateResponse expected;
-
- public ConfigurationUpdateResponseMatcher(ConfigurationUpdateResponse response) {
- expected = response;
- }
-
- public boolean matchesSafely(ConfigurationUpdateResponse actual) {
- return propertyEquals(expected.getConfiguration(), actual.getConfiguration()) &&
- propertyEquals(expected.getConfigurationUpdateId(), actual.getConfigurationUpdateId()) &&
- propertyEquals(expected.getErrorMessage(), actual.getErrorMessage()) &&
- propertyEquals(expected.getStatus(), actual.getStatus());
- }
-
- private boolean propertyEquals(Object expected, Object actual) {
- if (expected == null && actual == null) {
- return true;
- }
-
- if (expected == null && actual != null) {
- return false;
- }
- return expected.equals(actual);
- }
-
- public void describeTo(Description description) {
- description.appendText(expected.toString());
- }
-}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java
deleted file mode 100644
index e6e9422..0000000
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import org.jmock.Mockery;
-import org.testng.IHookCallBack;
-import org.testng.IHookable;
-import org.testng.ITestResult;
-import org.testng.annotations.BeforeMethod;
-
-public class JMockTest implements IHookable {
-
- protected Mockery context;
-
- @BeforeMethod
- void initContext() {
- context = new Mockery();
- }
-
- public void run(IHookCallBack iHookCallBack, ITestResult iTestResult) {
- iHookCallBack.runTestMethod(iTestResult);
- try {
- context.assertIsSatisfied();
- }
- catch (Throwable t) {
- iTestResult.setStatus(ITestResult.FAILURE);
- iTestResult.setThrowable(t);
- }
- }
-}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadResourceConfigurationFactoryImplTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadResourceConfigurationFactoryImplTest.java
index 6913b87..ef028d2 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadResourceConfigurationFactoryImplTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadResourceConfigurationFactoryImplTest.java
@@ -31,6 +31,7 @@ import org.rhq.core.pc.util.ComponentService;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
+import org.rhq.test.JMockTest;
import org.jmock.Expectations;
public class LoadResourceConfigurationFactoryImplTest extends JMockTest {
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
index 10bc6d1..272d22e 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
@@ -23,9 +23,9 @@
package org.rhq.core.pc.configuration;
-import static org.rhq.core.pc.configuration.ConfigurationUpdateResponseMatcher.*;
import static org.rhq.core.domain.configuration.ConfigurationUpdateStatus.*;
-import static org.testng.Assert.*;
+import static org.rhq.test.AssertUtils.*;
+import org.rhq.test.jmock.PropertyMatcher;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
@@ -39,6 +39,7 @@ import org.jmock.Expectations;
import org.jmock.api.Action;
import org.jmock.api.Invocation;
import org.hamcrest.Description;
+import org.hamcrest.Matcher;
public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest {
@@ -239,35 +240,7 @@ public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest
void assertConfigurationUpdateResponseMatches(ConfigurationUpdateResponse expected,
ConfigurationUpdateResponse actual, String msg) {
- boolean matches = true;
- StringBuilder errors = new StringBuilder(msg + " -- " + ConfigurationUpdateResponse.class.getSimpleName() +
- " objects do not match:\n");
-
- if (!propertyEquals(expected.getConfigurationUpdateId(), actual.getConfigurationUpdateId())) {
- matches = false;
- errors.append("expected.configurationUpdateId = " + expected.getConfigurationUpdateId() + "\n");
- errors.append("actual.configurationUpdateId = " + actual.getConfigurationUpdateId() + "\n\n");
- }
-
- if (!propertyEquals(expected.getConfiguration(), actual.getConfiguration())) {
- matches = false;
- errors.append("expected.configuration = " + expected.getConfiguration() + "\n");
- errors.append("actual.configuration = " + actual.getConfiguration() + "\n\n");
- }
-
- if (!propertyEquals(expected.getErrorMessage(), actual.getErrorMessage())) {
- matches = false;
- errors.append("expected.errorMessage = " + expected.getErrorMessage() + "\n");
- errors.append("actual.errorMessage = " + actual.getErrorMessage() + "\n\n");
- }
-
- if (!propertyEquals(expected.getStatus(), actual.getStatus())) {
- matches = false;
- errors.append("expected.status = " + expected.getStatus() + "\n");
- errors.append("actual.status = " + actual.getStatus() + "\n\n");
- }
-
- assertTrue(matches, errors.toString());
+ assertPropertiesMatch(expected, actual, msg);
}
boolean propertyEquals(Object expected, Object actual) {
@@ -281,6 +254,10 @@ public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest
return expected.equals(actual);
}
+ public static Matcher<ConfigurationUpdateResponse> matchingResponse(ConfigurationUpdateResponse expected) {
+ return new PropertyMatcher<ConfigurationUpdateResponse>(expected);
+ }
+
public static Action updateReportTo(ConfigurationUpdateStatus status) {
return new UpdateResourceConfigurationAction(status);
}
diff --git a/modules/pom.xml b/modules/pom.xml
index b8edc96..9954974 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -81,4 +82,7 @@
</profiles>
-</project>
+ <modules>
+ <module>test-utils</module>
+ </modules>
+</project>
\ No newline at end of file
diff --git a/modules/test-utils/pom.xml b/modules/test-utils/pom.xml
new file mode 100644
index 0000000..50453bd
--- /dev/null
+++ b/modules/test-utils/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>rhq-modules-parent</artifactId>
+ <groupId>org.rhq</groupId>
+ <version>1.4.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>test-utils</artifactId>
+ <name>RHQ Test Utils</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.9</version>
+ <scope>compile</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>2.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.2</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java b/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
new file mode 100644
index 0000000..bde72ba
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
@@ -0,0 +1,40 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test;
+
+import static org.testng.Assert.*;
+
+public class AssertUtils {
+
+ public static <T> void assertPropertiesMatch(T expected, T actual, String msg) {
+ PropertyMatcher<T> matcher = new PropertyMatcher<T>();
+ matcher.setExpected(expected);
+ matcher.setActual(actual);
+
+ MatchResult result = matcher.execute();
+
+ assertTrue(result.isMatch(), msg + " -- " + result.getDetails());
+ }
+
+}
diff --git a/modules/test-utils/src/main/java/org/rhq/test/JMockTest.java b/modules/test-utils/src/main/java/org/rhq/test/JMockTest.java
new file mode 100644
index 0000000..f3add4e
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/JMockTest.java
@@ -0,0 +1,51 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test;
+
+import org.jmock.Mockery;
+import org.testng.IHookCallBack;
+import org.testng.IHookable;
+import org.testng.ITestResult;
+import org.testng.annotations.BeforeMethod;
+
+public class JMockTest implements IHookable {
+
+ protected Mockery context;
+
+ @BeforeMethod
+ public void initContext() {
+ context = new Mockery();
+ }
+
+ public void run(IHookCallBack iHookCallBack, ITestResult iTestResult) {
+ iHookCallBack.runTestMethod(iTestResult);
+ try {
+ context.assertIsSatisfied();
+ }
+ catch (Throwable t) {
+ iTestResult.setStatus(ITestResult.FAILURE);
+ iTestResult.setThrowable(t);
+ }
+ }
+}
diff --git a/modules/test-utils/src/main/java/org/rhq/test/MatchResult.java b/modules/test-utils/src/main/java/org/rhq/test/MatchResult.java
new file mode 100644
index 0000000..a68d956
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/MatchResult.java
@@ -0,0 +1,44 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test;
+
+public class MatchResult {
+
+ private boolean isMatch;
+
+ private String details;
+
+ public MatchResult(boolean isMatch, String details) {
+ this.isMatch = isMatch;
+ this.details = details;
+ }
+
+ public boolean isMatch() {
+ return isMatch;
+ }
+
+ public String getDetails() {
+ return details;
+ }
+}
diff --git a/modules/test-utils/src/main/java/org/rhq/test/PropertyMatchException.java b/modules/test-utils/src/main/java/org/rhq/test/PropertyMatchException.java
new file mode 100644
index 0000000..6acc3d9
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/PropertyMatchException.java
@@ -0,0 +1,43 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test;
+
+public class PropertyMatchException extends RuntimeException {
+
+ public PropertyMatchException() {
+ super();
+ }
+
+ public PropertyMatchException(String message) {
+ super(message);
+ }
+
+ public PropertyMatchException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public PropertyMatchException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/modules/test-utils/src/main/java/org/rhq/test/PropertyMatcher.java b/modules/test-utils/src/main/java/org/rhq/test/PropertyMatcher.java
new file mode 100644
index 0000000..6352be5
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/PropertyMatcher.java
@@ -0,0 +1,88 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test;
+
+import org.apache.commons.beanutils.PropertyUtils;
+
+import java.util.Map;
+import java.lang.reflect.InvocationTargetException;
+
+public class PropertyMatcher<T> {
+
+ private T expected;
+
+ private T actual;
+
+ public void setExpected(T expected) {
+ this.expected = expected;
+ }
+
+ public void setActual(T actual) {
+ this.actual = actual;
+ }
+
+ public MatchResult execute() {
+ try {
+ Map<String, ?> expectedProps = PropertyUtils.describe(expected);
+ Map<String, ?> actualProps = PropertyUtils.describe(actual);
+
+ boolean isMatch = true;
+ StringBuilder details = new StringBuilder(expected.getClass().getSimpleName() +
+ " objects do not match:\n");
+
+ for (String name : expectedProps.keySet()) {
+ Object expectedValue = expectedProps.get(name);
+ Object actualValue = actualProps.get(name);
+
+ if (!propertyEquals(expectedValue, actualValue)) {
+ isMatch = false;
+ details.append("expected." + name + " = " + expectedValue + "\n");
+ details.append("actual." + name + " = " + actualValue + "\n\n");
+ }
+ }
+
+ return new MatchResult(isMatch, details.toString());
+ }
+ catch (IllegalAccessException e) {
+ throw new PropertyMatchException(e);
+ }
+ catch (InvocationTargetException e) {
+ throw new PropertyMatchException(e);
+ }
+ catch (NoSuchMethodException e) {
+ throw new PropertyMatchException(e);
+ }
+ }
+
+ private boolean propertyEquals(Object expected, Object actual) {
+ if (expected == null && actual == null) {
+ return true;
+ }
+
+ if (expected == null && actual != null) {
+ return false;
+ }
+ return expected.equals(actual);
+ }
+}
diff --git a/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java b/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java
new file mode 100644
index 0000000..3be7e2d
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/jmock/PropertyMatcher.java
@@ -0,0 +1,51 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test.jmock;
+
+import org.hamcrest.TypeSafeMatcher;
+import org.hamcrest.Description;
+import org.rhq.test.MatchResult;
+
+public class PropertyMatcher<T> extends TypeSafeMatcher<T> {
+
+ private T expected;
+
+ public PropertyMatcher(T expected) {
+ this.expected = expected;
+ }
+
+ public boolean matchesSafely(T actual) {
+ org.rhq.test.PropertyMatcher<T> matcher = new org.rhq.test.PropertyMatcher<T>();
+ matcher.setExpected(expected);
+ matcher.setActual(actual);
+
+ MatchResult result = matcher.execute();
+
+ return result.isMatch();
+ }
+
+ public void describeTo(Description description) {
+ description.appendText(expected.toString());
+ }
+}
14 years, 6 months
[rhq] Branch 'pc' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 263227e335728de980194c0632ae04938396536e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Mon Nov 23 11:36:47 2009 -0500
put the proper values in the query params
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index 3697caa..157911d 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
@@ -405,8 +405,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
q.setParameter("version", plugin.getVersion());
q.setParameter("ampsVersion", plugin.getAmpsVersion());
q.setParameter("deployment", plugin.getDeployment());
- q.setParameter("pluginConfiguration", config);
- q.setParameter("scheduledJobsConfiguration", config);
+ q.setParameter("pluginConfiguration", plugin.getPluginConfiguration());
+ q.setParameter("scheduledJobsConfiguration", plugin.getScheduledJobsConfiguration());
q.setParameter("description", plugin.getDescription());
q.setParameter("help", plugin.getHelp());
q.setParameter("mtime", plugin.getMtime());
14 years, 6 months
[rhq] Branch 'raw-config' - 4 commits - modules/core
by John Sanda
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationUpdateService.java | 8
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateLegacyConfig.java | 8
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunner.java | 52 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java | 64 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java | 4
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java | 327 ++++++++++
6 files changed, 422 insertions(+), 41 deletions(-)
New commits:
commit 641c32987ac120c4f4e2a891c048c7528d5b466f
Merge: a89b22a... 89f7276...
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 23 11:22:56 2009 -0500
Merge branch 'raw-config' of ssh://git.fedorahosted.org/git/rhq/rhq into raw-config
commit a89b22aa59250277e59cc7fc0871f6d6f94b47db
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 23 11:19:57 2009 -0500
[US 6] Adding unit tests for embedded mode
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
index 392130b..10bc6d1 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
@@ -25,6 +25,7 @@ package org.rhq.core.pc.configuration;
import static org.rhq.core.pc.configuration.ConfigurationUpdateResponseMatcher.*;
import static org.rhq.core.domain.configuration.ConfigurationUpdateStatus.*;
+import static org.testng.Assert.*;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
@@ -76,6 +77,39 @@ public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest
}
@Test
+ public void successfulUpdateShouldReturnSuccessResponseInEmbeddedMode() throws Exception {
+ final Configuration config = createStructuredConfig();
+
+ final ConfigurationFacet facet = context.mock(ConfigurationFacet.class);
+
+ final ConfigurationUtilityService configUtilService = context.mock(ConfigurationUtilityService.class);
+
+ int configUpdateId = -1;
+
+ ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId);
+
+ UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(null, resourceType,
+ facet, updateRequest);
+ updateRunner.setConfigUtilService(configUtilService);
+
+ final ConfigurationUpdateResponse successResponse = new ConfigurationUpdateResponse(configUpdateId, null,
+ SUCCESS, null);
+
+ context.checking(new Expectations() {{
+ oneOf(facet).updateResourceConfiguration(with(any(ConfigurationUpdateReport.class)));
+ will(updateReportTo(SUCCESS));
+
+ oneOf(configUtilService).normalizeConfiguration(config, resourceType.getResourceConfigurationDefinition());
+ oneOf(configUtilService).validateConfiguration(config, resourceType.getResourceConfigurationDefinition());
+
+ }});
+
+ ConfigurationUpdateResponse actualResponse = updateRunner.call();
+
+ assertConfigurationUpdateResponseMatches(successResponse, actualResponse, "Expected a success response");
+ }
+
+ @Test
public void inProgressUpdateShouldSendFailureResponseToServer() throws Exception {
final Configuration config = createStructuredConfig();
@@ -112,6 +146,40 @@ public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest
}
@Test
+ public void failedUpdateShouldReturnFailureResponseInEmbeddedMode() throws Exception {
+ final Configuration config = createStructuredConfig();
+
+ final ConfigurationFacet facet = context.mock(ConfigurationFacet.class);
+
+ final ConfigurationUtilityService configUtilService = context.mock(ConfigurationUtilityService.class);
+
+ int configUpdateId = -1;
+
+ ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId);
+
+ UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(null, resourceType,
+ facet, updateRequest);
+ updateRunner.setConfigUtilService(configUtilService);
+
+ String errorMsg = "Configuration facet did not indicate success or failure - assuming failure.";
+
+ final ConfigurationUpdateResponse failureResponse = new ConfigurationUpdateResponse(configUpdateId, config,
+ FAILURE, errorMsg);
+
+ context.checking(new Expectations() {{
+ oneOf(facet).updateResourceConfiguration(with(any(ConfigurationUpdateReport.class)));
+ will(updateReportTo(INPROGRESS));
+
+ oneOf(configUtilService).normalizeConfiguration(config, resourceType.getResourceConfigurationDefinition());
+ oneOf(configUtilService).validateConfiguration(config, resourceType.getResourceConfigurationDefinition());
+ }});
+
+ ConfigurationUpdateResponse actualResponse = updateRunner.call();
+
+ assertConfigurationUpdateResponseMatches(failureResponse, actualResponse, "Expected a failure response");
+ }
+
+ @Test
public void failureResponseShouldBeSentToServerWhenFacetThrowsAnException() throws Exception {
final Configuration config = createStructuredConfig();
@@ -138,7 +206,79 @@ public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest
oneOf(configServerService).completeConfigurationUpdate(with(matchingResponse(failureResponse)));
}});
- updateRunner.call();
+ updateRunner.call();
+ }
+
+ @Test
+ public void failureResponseShouldBeReturnedWhenFacetThrowsAnExceptionInEmbeddedMode() throws Exception {
+ final Configuration config = createStructuredConfig();
+
+ final ConfigurationFacet facet = context.mock(ConfigurationFacet.class);
+
+ int configUpdateId = -1;
+
+ ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId);
+
+ UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(null, resourceType,
+ facet, updateRequest);
+
+ final NullPointerException exception = new NullPointerException("Unexpected error during update");
+
+ final ConfigurationUpdateResponse failureResponse = new ConfigurationUpdateResponse(configUpdateId, config,
+ exception);
+
+ context.checking(new Expectations() {{
+ oneOf(facet).updateResourceConfiguration(with(any(ConfigurationUpdateReport.class)));
+ will(throwExceptionFromFacet(exception));
+ }});
+
+ ConfigurationUpdateResponse actualResponse = updateRunner.call();
+
+ assertConfigurationUpdateResponseMatches(failureResponse, actualResponse, "Expected a failure response");
+ }
+
+ void assertConfigurationUpdateResponseMatches(ConfigurationUpdateResponse expected,
+ ConfigurationUpdateResponse actual, String msg) {
+ boolean matches = true;
+ StringBuilder errors = new StringBuilder(msg + " -- " + ConfigurationUpdateResponse.class.getSimpleName() +
+ " objects do not match:\n");
+
+ if (!propertyEquals(expected.getConfigurationUpdateId(), actual.getConfigurationUpdateId())) {
+ matches = false;
+ errors.append("expected.configurationUpdateId = " + expected.getConfigurationUpdateId() + "\n");
+ errors.append("actual.configurationUpdateId = " + actual.getConfigurationUpdateId() + "\n\n");
+ }
+
+ if (!propertyEquals(expected.getConfiguration(), actual.getConfiguration())) {
+ matches = false;
+ errors.append("expected.configuration = " + expected.getConfiguration() + "\n");
+ errors.append("actual.configuration = " + actual.getConfiguration() + "\n\n");
+ }
+
+ if (!propertyEquals(expected.getErrorMessage(), actual.getErrorMessage())) {
+ matches = false;
+ errors.append("expected.errorMessage = " + expected.getErrorMessage() + "\n");
+ errors.append("actual.errorMessage = " + actual.getErrorMessage() + "\n\n");
+ }
+
+ if (!propertyEquals(expected.getStatus(), actual.getStatus())) {
+ matches = false;
+ errors.append("expected.status = " + expected.getStatus() + "\n");
+ errors.append("actual.status = " + actual.getStatus() + "\n\n");
+ }
+
+ assertTrue(matches, errors.toString());
+ }
+
+ boolean propertyEquals(Object expected, Object actual) {
+ if (expected == null && actual == null) {
+ return true;
+ }
+
+ if (expected == null && actual != null) {
+ return false;
+ }
+ return expected.equals(actual);
}
public static Action updateReportTo(ConfigurationUpdateStatus status) {
commit 85e904f544bf0e1d4b4bdf818f51757c3a7fd363
Merge: 5d70557... 866e687...
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 23 09:44:38 2009 -0500
Merge branch 'raw-config' of ssh://git.fedorahosted.org/git/rhq/rhq into raw-config
commit 5d70557ee7d45a3caffb31e626e6318045336240
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 23 09:40:07 2009 -0500
[US 6] Adding unit tests for existing resource configuration update code
Initial commit for ConfigurationUpdateResponseMatcher. Getting UpdateResourceConfigurationRunner under test
has been a bit cumbersome because the collaborators that it calls (ConfigurationFacet and
ConfigurationServerService) produce side effects on the arguments that they receive instead of returning
values.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationUpdateService.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationUpdateService.java
deleted file mode 100644
index bdafc4b..0000000
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationUpdateService.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.rhq.core.pc.configuration;
-
-/**
- * Created by IntelliJ IDEA. User: john Date: Nov 12, 2009 Time: 4:37:07 PM To change this template use File | Settings
- * | File Templates.
- */
-public interface ConfigurationUpdateService {
-}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateLegacyConfig.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateLegacyConfig.java
deleted file mode 100644
index 4039310..0000000
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateLegacyConfig.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.rhq.core.pc.configuration;
-
-/**
- * Created by IntelliJ IDEA. User: john Date: Nov 12, 2009 Time: 4:33:27 PM To change this template use File | Settings
- * | File Templates.
- */
-public interface UpdateLegacyConfig {
-}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunner.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunner.java
index fbb84e3..c93485b 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunner.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunner.java
@@ -1,25 +1,25 @@
/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.rhq.core.pc.configuration;
import java.util.List;
@@ -67,6 +67,8 @@ public class UpdateResourceConfigurationRunner implements Runnable, Callable<Con
*/
private ConfigurationServerService configurationServerService;
+ private ConfigurationUtilityService configUtilService = new ConfigurationUtilityServiceImpl();
+
public UpdateResourceConfigurationRunner(ConfigurationServerService configurationServerService, ResourceType type,
ConfigurationFacet facet, ConfigurationUpdateRequest request) {
this.configurationServerService = configurationServerService; // may be null
@@ -75,6 +77,10 @@ public class UpdateResourceConfigurationRunner implements Runnable, Callable<Con
this.request = request;
}
+ void setConfigUtilService(ConfigurationUtilityService service) {
+ configUtilService = service;
+ }
+
public void run() {
try {
call();
@@ -100,8 +106,8 @@ public class UpdateResourceConfigurationRunner implements Runnable, Callable<Con
ConfigurationDefinition configurationDefinition = resourceType.getResourceConfigurationDefinition();
// Normalize and validate the config.
- ConfigurationUtility.normalizeConfiguration(response.getConfiguration(), configurationDefinition);
- List<String> errorMessages = ConfigurationUtility.validateConfiguration(response.getConfiguration(),
+ configUtilService.normalizeConfiguration(response.getConfiguration(), configurationDefinition);
+ List<String> errorMessages = configUtilService.validateConfiguration(response.getConfiguration(),
configurationDefinition);
for (String errorMessage : errorMessages) {
log.warn("Plugin Error: Invalid " + resourceType.getName() + " Resource configuration returned by "
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java
new file mode 100644
index 0000000..74bca9b
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigurationUpdateResponseMatcher.java
@@ -0,0 +1,64 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.rhq.core.clientapi.server.configuration.ConfigurationUpdateResponse;
+
+public class ConfigurationUpdateResponseMatcher extends TypeSafeMatcher<ConfigurationUpdateResponse> {
+
+ public static Matcher<ConfigurationUpdateResponse> matchingResponse(ConfigurationUpdateResponse expected) {
+ return new ConfigurationUpdateResponseMatcher(expected);
+ }
+
+ private ConfigurationUpdateResponse expected;
+
+ public ConfigurationUpdateResponseMatcher(ConfigurationUpdateResponse response) {
+ expected = response;
+ }
+
+ public boolean matchesSafely(ConfigurationUpdateResponse actual) {
+ return propertyEquals(expected.getConfiguration(), actual.getConfiguration()) &&
+ propertyEquals(expected.getConfigurationUpdateId(), actual.getConfigurationUpdateId()) &&
+ propertyEquals(expected.getErrorMessage(), actual.getErrorMessage()) &&
+ propertyEquals(expected.getStatus(), actual.getStatus());
+ }
+
+ private boolean propertyEquals(Object expected, Object actual) {
+ if (expected == null && actual == null) {
+ return true;
+ }
+
+ if (expected == null && actual != null) {
+ return false;
+ }
+ return expected.equals(actual);
+ }
+
+ public void describeTo(Description description) {
+ description.appendText(expected.toString());
+ }
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java
index 4f95f42..e6e9422 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/JMockTest.java
@@ -23,11 +23,11 @@
package org.rhq.core.pc.configuration;
-import org.testng.IHookable;
+import org.jmock.Mockery;
import org.testng.IHookCallBack;
+import org.testng.IHookable;
import org.testng.ITestResult;
import org.testng.annotations.BeforeMethod;
-import org.jmock.Mockery;
public class JMockTest implements IHookable {
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
new file mode 100644
index 0000000..392130b
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/UpdateResourceConfigurationRunnerTest.java
@@ -0,0 +1,187 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import static org.rhq.core.pc.configuration.ConfigurationUpdateResponseMatcher.*;
+import static org.rhq.core.domain.configuration.ConfigurationUpdateStatus.*;
+
+import org.testng.annotations.Test;
+import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
+import org.rhq.core.clientapi.server.configuration.ConfigurationUpdateResponse;
+import org.rhq.core.clientapi.agent.configuration.ConfigurationUpdateRequest;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.jmock.Expectations;
+import org.jmock.api.Action;
+import org.jmock.api.Invocation;
+import org.hamcrest.Description;
+
+public class UpdateResourceConfigurationRunnerTest extends ConfigManagementTest {
+
+ @Test
+ public void successfulUpdateShouldSendSuccessResponseToServer() throws Exception {
+ final Configuration config = createStructuredConfig();
+
+ final ConfigurationServerService configServerService = context.mock(ConfigurationServerService.class);
+
+ final ConfigurationFacet facet = context.mock(ConfigurationFacet.class);
+
+ final ConfigurationUtilityService configUtilService = context.mock(ConfigurationUtilityService.class);
+
+ int configUpdateId = -1;
+
+ ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId);
+
+ UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(configServerService,
+ resourceType, facet, updateRequest);
+ updateRunner.setConfigUtilService(configUtilService);
+
+ final ConfigurationUpdateResponse successResponse = new ConfigurationUpdateResponse(configUpdateId, null,
+ SUCCESS, null);
+
+ context.checking(new Expectations() {{
+ oneOf(facet).updateResourceConfiguration(with(any(ConfigurationUpdateReport.class)));
+ will(updateReportTo(SUCCESS));
+
+ oneOf(configUtilService).normalizeConfiguration(config, resourceType.getResourceConfigurationDefinition());
+ oneOf(configUtilService).validateConfiguration(config, resourceType.getResourceConfigurationDefinition());
+
+ oneOf(configServerService).completeConfigurationUpdate(with(matchingResponse(successResponse)));
+ }});
+
+ updateRunner.call();
+ }
+
+ @Test
+ public void inProgressUpdateShouldSendFailureResponseToServer() throws Exception {
+ final Configuration config = createStructuredConfig();
+
+ final ConfigurationServerService configServerService = context.mock(ConfigurationServerService.class);
+
+ final ConfigurationFacet facet = context.mock(ConfigurationFacet.class);
+
+ final ConfigurationUtilityService configUtilService = context.mock(ConfigurationUtilityService.class);
+
+ int configUpdateId = -1;
+
+ ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId);
+
+ UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(configServerService,
+ resourceType, facet, updateRequest);
+ updateRunner.setConfigUtilService(configUtilService);
+
+ String errorMsg = "Configuration facet did not indicate success or failure - assuming failure.";
+
+ final ConfigurationUpdateResponse failureResponse = new ConfigurationUpdateResponse(configUpdateId, config,
+ FAILURE, errorMsg);
+
+ context.checking(new Expectations() {{
+ oneOf(facet).updateResourceConfiguration(with(any(ConfigurationUpdateReport.class)));
+ will(updateReportTo(INPROGRESS));
+
+ oneOf(configUtilService).normalizeConfiguration(config, resourceType.getResourceConfigurationDefinition());
+ oneOf(configUtilService).validateConfiguration(config, resourceType.getResourceConfigurationDefinition());
+
+ oneOf(configServerService).completeConfigurationUpdate(with(matchingResponse(failureResponse)));
+ }});
+
+ updateRunner.call();
+ }
+
+ @Test
+ public void failureResponseShouldBeSentToServerWhenFacetThrowsAnException() throws Exception {
+ final Configuration config = createStructuredConfig();
+
+ final ConfigurationServerService configServerService = context.mock(ConfigurationServerService.class);
+
+ final ConfigurationFacet facet = context.mock(ConfigurationFacet.class);
+
+ int configUpdateId = -1;
+
+ ConfigurationUpdateRequest updateRequest = new ConfigurationUpdateRequest(configUpdateId, config, resourceId);
+
+ UpdateResourceConfigurationRunner updateRunner = new UpdateResourceConfigurationRunner(configServerService,
+ resourceType, facet, updateRequest);
+
+ final NullPointerException exception = new NullPointerException("Unexpected error during update");
+
+ final ConfigurationUpdateResponse failureResponse = new ConfigurationUpdateResponse(configUpdateId, config,
+ exception);
+
+ context.checking(new Expectations() {{
+ oneOf(facet).updateResourceConfiguration(with(any(ConfigurationUpdateReport.class)));
+ will(throwExceptionFromFacet(exception));
+
+ oneOf(configServerService).completeConfigurationUpdate(with(matchingResponse(failureResponse)));
+ }});
+
+ updateRunner.call();
+ }
+
+ public static Action updateReportTo(ConfigurationUpdateStatus status) {
+ return new UpdateResourceConfigurationAction(status);
+ }
+
+ public static Action throwExceptionFromFacet(Throwable t) {
+ return new ThrowFacetExceptionAction(t);
+ }
+
+ static class UpdateResourceConfigurationAction implements Action {
+ ConfigurationUpdateStatus status;
+
+ public UpdateResourceConfigurationAction(ConfigurationUpdateStatus status) {
+ this.status = status;
+ }
+
+ public void describeTo(Description description) {
+ description.appendText("Updating status of " + ConfigurationUpdateReport.class.getSimpleName() + " to " +
+ status);
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable {
+ ConfigurationUpdateReport report = (ConfigurationUpdateReport) invocation.getParameter(0);
+ report.setStatus(status);
+ return null;
+ }
+ }
+
+ static class ThrowFacetExceptionAction implements Action {
+ Throwable throwable;
+
+ public ThrowFacetExceptionAction(Throwable t) {
+ throwable = t;
+ }
+
+ public void describeTo(Description description) {
+ description.appendText("throws <" + throwable.getClass().getName() + ">: " + throwable.getMessage());
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable {
+ throw throwable;
+ }
+ }
+
+}
14 years, 6 months