[rhq] Branch 'content' - modules/core modules/enterprise
by jdob
modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java | 14
modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersionContentSource.java | 23
modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoPackageVersion.java | 13
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java | 231 +++++-----
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerLocal.java | 20
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java | 4
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java | 59 +-
7 files changed, 204 insertions(+), 160 deletions(-)
New commits:
commit 1992722650053bcc1f5895b3bf1478f3298de6dd
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 30 15:37:59 2009 -0500
1137 - Refactored server-side methods for handling a package sync that's scoped to a particular repo.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java
index 7d9b0d9..4a221e9 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersion.java
@@ -130,9 +130,16 @@ import org.rhq.core.domain.resource.ProductVersion;
// deletes orphaned package versions - that is, if they have no associated content sources or repos and is not installed anywhere
@NamedQuery(name = PackageVersion.DELETE_IF_NO_CONTENT_SOURCES_OR_REPOS, query = "DELETE PackageVersion pv "
- + " WHERE pv.id NOT IN (SELECT pvcs.packageVersion.id "
- + " FROM PackageVersionContentSource pvcs) "
- + " AND pv.repoPackageVersions IS EMPTY " + " AND pv.installedPackages IS EMPTY "
+ + " WHERE pv.id NOT IN (SELECT pvcs.packageVersion.id " //
+ + " FROM PackageVersionContentSource pvcs) " //
+ + " AND pv.repoPackageVersions IS EMPTY " //
+ + " AND pv.installedPackages IS EMPTY " //
+ + " AND pv.installedPackageHistory IS EMPTY "),
+
+ @NamedQuery(name = PackageVersion.DELETE_SINGLE_IF_NO_CONTENT_SOURCES_OR_REPOS, query = "DELETE PackageVersion pv "
+ + " WHERE pv.id = :packageVersionId" //
+ + " AND pv.repoPackageVersions IS EMPTY " //
+ + " AND pv.installedPackages IS EMPTY " //
+ " AND pv.installedPackageHistory IS EMPTY "),
// the bulk delete that removes the PVPV mapping from orphaned package versions
@@ -240,6 +247,7 @@ public class PackageVersion implements Serializable {
public static final String QUERY_FIND_BY_ID_IF_NO_CONTENT_SOURCES_OR_REPOS = "PackageVersion.findByIdIfNoContentSourcesOrRepos";
public static final String QUERY_GET_PKG_BITS_LENGTH_BY_PKG_DETAILS_AND_RES_ID = "PackageVersion.getPkgBitsLengthByPkgDetailsAndResId";
public static final String DELETE_IF_NO_CONTENT_SOURCES_OR_REPOS = "PackageVersion.deleteIfNoContentSourcesOrRepos";
+ public static final String DELETE_SINGLE_IF_NO_CONTENT_SOURCES_OR_REPOS = "PackageVersion.deleteSingleIfNoContentSourcesOrRepos";
public static final String DELETE_PVPV_IF_NO_CONTENT_SOURCES_OR_REPOS = "PackageVersion.deletePVPVIfNoContentSourcesOrRepos";
public static final String FIND_EXTRA_PROPS_IF_NO_CONTENT_SOURCES_OR_REPOS = "PackageVersion.findOrphanedExtraProps";
public static final String FIND_FILES_IF_NO_CONTENT_SOURCES_OR_REPOS = "PackageVersion.findOrphanedFiles";
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersionContentSource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersionContentSource.java
index 6ae6c39..ffaaed7 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersionContentSource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/PackageVersionContentSource.java
@@ -76,17 +76,24 @@ import javax.persistence.Table;
// this is the same as FIND_BY_CONTENT_SOURCE_ID, but it only returns those PVs whose bits are not loaded yet
@NamedQuery(name = PackageVersionContentSource.QUERY_FIND_BY_CONTENT_SOURCE_ID_AND_NOT_LOADED, query = "SELECT pvcs "
- + " FROM PackageVersionContentSource pvcs "
- + " LEFT JOIN FETCH pvcs.packageVersion pv "
- + " LEFT JOIN FETCH pv.generalPackage gp "
- + " LEFT JOIN FETCH gp.packageType pt "
- + " LEFT JOIN FETCH pv.architecture arch "
- + " LEFT JOIN FETCH pv.extraProperties extra "
- + " WHERE pvcs.contentSource.id = :id " + " AND pv.packageBits IS NULL "),
+ + " FROM PackageVersionContentSource pvcs " //
+ + " LEFT JOIN FETCH pvcs.packageVersion pv " //
+ + " LEFT JOIN FETCH pv.generalPackage gp " //
+ + " LEFT JOIN FETCH gp.packageType pt " //
+ + " LEFT JOIN FETCH pv.architecture arch " //
+ + " LEFT JOIN FETCH pv.extraProperties extra " //
+ + " WHERE pvcs.contentSource.id = :id " //
+ + " AND pv.packageBits IS NULL " //
+ + " AND pv.id IN " //
+ + " (SELECT rpv.packageVersion.id FROM RepoPackageVersion rpv " //
+ + " WHERE rpv.repo.id = :repo_id)"),
@NamedQuery(name = PackageVersionContentSource.QUERY_FIND_BY_CONTENT_SOURCE_ID_AND_NOT_LOADED_COUNT, query = "SELECT COUNT(pvcs.contentSource.id) "
+ " FROM PackageVersionContentSource pvcs "
+ " WHERE pvcs.contentSource.id = :id "
- + " AND pvcs.packageVersion.packageBits IS NULL "),
+ + " AND pvcs.packageVersion.packageBits IS NULL "
+ + " AND pvcs.packageVersion.id IN " //
+ + " (SELECT rpv.packageVersion.id FROM RepoPackageVersion rpv " //
+ + " WHERE rpv.repo.id = :repo_id)"),
// finds the set of content sources that can deliver the pkg ver to the subscribed resource
@NamedQuery(name = PackageVersionContentSource.QUERY_FIND_BY_PKG_VER_ID_AND_RES_ID, query = "SELECT pvcs "
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoPackageVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoPackageVersion.java
index 6e603cb..668fa32 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoPackageVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/RepoPackageVersion.java
@@ -42,10 +42,21 @@ import javax.persistence.Table;
*/
@Entity
@IdClass(RepoPackageVersionPK.class)
-@NamedQueries( { @NamedQuery(name = RepoPackageVersion.DELETE_BY_REPO_ID, query = "DELETE RepoPackageVersion cpv WHERE cpv.repo.id = :repoId") })
+@NamedQueries( {
+ @NamedQuery(name = RepoPackageVersion.DELETE_BY_REPO_ID,
+ query = "DELETE RepoPackageVersion cpv WHERE cpv.repo.id = :repoId"),
+
+ // Deletes the repo <-> package mapping when the package has no providers for this package
+ @NamedQuery(name = RepoPackageVersion.DELETE_WHEN_NO_PROVIDER, query = "DELETE RepoPackageVersion rpv "
+ + "WHERE rpv.repo.id = :repoId " //
+ + " AND (SELECT COUNT(pvcs.packageVersion.id) "
+ + " FROM PackageVersionContentSource pvcs) = 0"
+ )
+})
@Table(name = "RHQ_REPO_PKG_VERSION_MAP")
public class RepoPackageVersion implements Serializable {
public static final String DELETE_BY_REPO_ID = "RepoPackageVersion.deleteByRepoId";
+ public static final String DELETE_WHEN_NO_PROVIDER = "RepoPackageVersion.deleteWhenNoProvider";
private static final long serialVersionUID = 1L;
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
index 40bc541..0a1a148 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java
@@ -383,7 +383,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
String repoName = createMe.getName();
- // Make sure the repo doesn't already exist. If we add twice, currently we'll get an exception
+ // Make sure the repo doesn't already exist. If we add twice, currently we'll get an exception
List<Repo> existingRepo = repoManager.getRepoByName(repoName);
if (existingRepo != null) {
continue;
@@ -639,8 +639,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
@SuppressWarnings("unchecked")
@RequiredPermission(Permission.MANAGE_INVENTORY)
- public PageList<PackageVersionContentSource> getUnloadedPackageVersionsFromContentSource(Subject subject,
- int contentSourceId, PageControl pc) {
+ public PageList<PackageVersionContentSource> getUnloadedPackageVersionsFromContentSourceInRepo(Subject subject,
+ int contentSourceId, int repoId, PageControl pc) {
pc.initDefaultOrderingField("pvcs.contentSource.id");
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager,
@@ -649,7 +649,9 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
PackageVersionContentSource.QUERY_FIND_BY_CONTENT_SOURCE_ID_AND_NOT_LOADED_COUNT);
query.setParameter("id", contentSourceId);
+ query.setParameter("repo_id", repoId);
countQuery.setParameter("id", contentSourceId);
+ countQuery.setParameter("repo_id", repoId);
List<PackageVersionContentSource> results = query.getResultList();
long count = (Long) countQuery.getSingleResult();
@@ -940,18 +942,18 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
//////////////////
// REMOVE
- syncResults = contentSourceManager._mergeContentSourceSyncReportREMOVE(contentSource, report, syncResults,
- progress);
+ syncResults = contentSourceManager._mergeDistributionSyncReportREMOVE(contentSource,
+ report, syncResults, progress);
//////////////////
// ADD
- syncResults = contentSourceManager._mergeContentSourceSyncReportADD(contentSource, report, syncResults,
- progress);
+ syncResults = contentSourceManager._mergeDistributionSyncReportADD(contentSource, report,
+ syncResults, progress);
// if we added/updated/deleted anything, change the last modified time of all repos
// that get content from this content source
if ((report.getDistributions().size() > 0) || (report.getDeletedDistributions().size() > 0)) {
- contentSourceManager._mergeContentSourceSyncReportUpdateRepo(contentSource.getId());
+ contentSourceManager._mergePackageSyncReportUpdateRepo(contentSource.getId());
}
// let our sync results object know that we completed the merge
@@ -972,7 +974,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
// we really want NEVER, but support tests that might be in a tx
- public ContentSourceSyncResults mergePackageSyncReport(ContentSource contentSource, PackageSyncReport report,
+ public ContentSourceSyncResults mergePackageSyncReport(ContentSource contentSource, Repo repo,
+ PackageSyncReport report,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults) {
try {
@@ -991,8 +994,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
//////////////////
// REMOVE
- syncResults = contentSourceManager._mergeContentSourceSyncReportREMOVE(contentSource, report, previous,
- syncResults, progress);
+ syncResults = contentSourceManager._mergePackageSyncReportREMOVE(contentSource, repo,
+ report, previous, syncResults, progress);
//////////////////
// ADD
@@ -1015,8 +1018,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
}
List<ContentProviderPackageDetails> pkgs = newPackages.subList(fromIndex, toIndex);
- syncResults = contentSourceManager._mergeContentSourceSyncReportADD(contentSource, pkgs, previous,
- syncResults, progress, fromIndex);
+ syncResults = contentSourceManager._mergePackageSyncReportADD(contentSource, repo,
+ pkgs, previous, syncResults, progress, fromIndex);
addedCount += pkgs.size();
fromIndex += chunkSize;
toIndex += chunkSize;
@@ -1028,14 +1031,14 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
//////////////////
// UPDATE
- syncResults = contentSourceManager._mergeContentSourceSyncReportUPDATE(contentSource, report, previous,
+ syncResults = contentSourceManager._mergePackageSyncReportUPDATE(contentSource, report, previous,
syncResults, progress);
// if we added/updated/deleted anything, change the last modified time of all repos
// that get content from this content source
if ((report.getNewPackages().size() > 0) || (report.getUpdatedPackages().size() > 0)
|| (report.getDeletedPackages().size() > 0)) {
- contentSourceManager._mergeContentSourceSyncReportUpdateRepo(contentSource.getId());
+ contentSourceManager._mergePackageSyncReportUpdateRepo(contentSource.getId());
}
// let our sync results object know that we completed the merge
@@ -1055,7 +1058,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void _mergeContentSourceSyncReportUpdateRepo(int contentSourceId) {
+ public void _mergePackageSyncReportUpdateRepo(int contentSourceId) {
// this method should be called only after a merge of a content source
// added/updated/removed one or more packages. When this happens, we need to change
// the last modified time for all repos that get content from the changed content source
@@ -1070,9 +1073,13 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergeContentSourceSyncReportREMOVE(ContentSource contentSource,
- PackageSyncReport report, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
- ContentSourceSyncResults syncResults, StringBuilder progress) {
+ public ContentSourceSyncResults _mergePackageSyncReportREMOVE(ContentSource contentSource,
+ Repo repo,
+ PackageSyncReport report,
+ Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
+ ContentSourceSyncResults syncResults,
+ StringBuilder progress) {
+
progress.append(new Date()).append(": ").append("Removing");
syncResults.setResults(progress.toString());
syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
@@ -1085,7 +1092,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
// for each removed package, we need to purge the PVCS mapping and the PV itself
for (ContentProviderPackageDetails doomedDetails : report.getDeletedPackages()) {
- // this is the mapping between the content source and the package version that needs to be deleted
+
+ // Delete the mapping between package version and content provider
ContentProviderPackageDetailsKey doomedDetailsKey = doomedDetails.getContentProviderPackageDetailsKey();
PackageVersionContentSource doomedPvcs = previous.get(doomedDetailsKey);
doomedPvcs = entityManager.find(PackageVersionContentSource.class, doomedPvcs
@@ -1094,17 +1102,20 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
entityManager.remove(doomedPvcs);
}
- // this is the package version itself that we want to remove
- // but only delete if there are no other content sources that also serve that PackageVersion
- // or repos that are directly associated with this package version
+ // Delete the relationship between package and repo IF no other providers provide the
+ // package
+ q = entityManager.createNamedQuery(RepoPackageVersion.DELETE_WHEN_NO_PROVIDER);
+ q.setParameter("repoId", repo.getId());
+ q.executeUpdate();
+
+ // Delete the package version if it is sufficiently orphaned:
+ // - No repos
+ // - No content providers
+ // - No installed packages
PackageVersion doomedPv = doomedPvcs.getPackageVersionContentSourcePK().getPackageVersion();
- q = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_BY_ID_IF_NO_CONTENT_SOURCES_OR_REPOS);
- q.setParameter("id", doomedPv.getId());
- try {
- doomedPv = (PackageVersion) q.getSingleResult();
- entityManager.remove(doomedPv);
- } catch (NoResultException nre) {
- }
+ q = entityManager.createNamedQuery(PackageVersion.DELETE_SINGLE_IF_NO_CONTENT_SOURCES_OR_REPOS);
+ q.setParameter("packageVersionId", doomedPv.getId());
+ q.executeUpdate();
if ((++flushCount % 200) == 0) {
entityManager.flush();
@@ -1125,78 +1136,10 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
return syncResults;
}
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergeContentSourceSyncReportREMOVE(ContentSource contentSource,
- DistributionSyncReport report, ContentSourceSyncResults syncResults, StringBuilder progress) {
-
- progress.append(new Date()).append(": ").append("Removing");
- syncResults.setResults(progress.toString());
- syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
-
- DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal();
- Subject overlord = LookupUtil.getSubjectManager().getOverlord();
-
- // remove all distributions that are no longer available on the remote repository
- for (DistributionDetails doomedDetails : report.getDeletedDistributions()) {
- Distribution doomedDist = distManager.getDistributionByLabel(doomedDetails.getLabel());
- distManager.deleteDistributionByDistId(overlord, doomedDist.getId());
- distManager.deleteDistributionFilesByDistId(overlord, doomedDist.getId());
- progress.append("Removed distribution & distribution files for: " + doomedDetails.getLabel());
- syncResults.setResults(progress.toString());
- syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
- }
-
- progress.append("Finished Distribution removal...").append('\n');
- syncResults.setResults(progress.toString());
- syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
-
- return syncResults;
- }
-
- @SuppressWarnings("unchecked")
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergeContentSourceSyncReportADD(ContentSource contentSource,
- DistributionSyncReport report, ContentSourceSyncResults syncResults, StringBuilder progress) {
-
- DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal();
- RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
- Subject overlord = LookupUtil.getSubjectManager().getOverlord();
- List<DistributionDetails> newDetails = report.getDistributions();
- for (DistributionDetails detail : newDetails) {
- try {
-
- log.debug("Attempting to create new distribution based off of: " + detail);
- DistributionType distType = distManager.getDistributionTypeByName(detail.getDistributionType());
- Distribution newDist = distManager.createDistribution(overlord, detail.getLabel(), detail
- .getDistributionPath(), distType);
- log.debug("Created new distribution: " + newDist);
- Repo repo = repoManager.getRepo(overlord, report.getRepoId());
- RepoDistribution repoDist = new RepoDistribution(repo, newDist);
- log.debug("Created new mapping of RepoDistribution repoId = " + repo.getId() + ", distId = "
- + newDist.getId());
- entityManager.persist(repoDist);
- List<DistributionFileDetails> files = detail.getFiles();
- for (DistributionFileDetails f : files) {
- log.debug("Creating DistributionFile for: " + f);
- DistributionFile df = new DistributionFile(newDist, f.getRelativeFilename(), f.getMd5sum());
- df.setLastModified(f.getLastModified());
- entityManager.persist(df);
- entityManager.flush();
- }
- } catch (DistributionException e) {
- progress.append("Caught exception when trying to add: " + detail.getLabel() + "\n");
- progress.append("Error is: " + e.getMessage());
- syncResults.setResults(progress.toString());
- syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
- log.error(e);
- }
- }
- return syncResults;
- }
-
@SuppressWarnings("unchecked")
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergeContentSourceSyncReportADD(ContentSource contentSource,
+ public ContentSourceSyncResults _mergePackageSyncReportADD(ContentSource contentSource,
+ Repo repo,
Collection<ContentProviderPackageDetails> newPackages,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress, int addCount) {
@@ -1206,10 +1149,12 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
Map<ResourceType, ResourceType> knownResourceTypes = new HashMap<ResourceType, ResourceType>();
Map<PackageType, PackageType> knownPackageTypes = new HashMap<PackageType, PackageType>();
Map<Architecture, Architecture> knownArchitectures = new HashMap<Architecture, Architecture>();
- List<Repo> associatedRepos = null;
Map<ResourceType, Map<String, ProductVersion>> knownProductVersions = new HashMap<ResourceType, Map<String, ProductVersion>>();
+ // Load this so we have the attached version in the repo <-> package mapping
+ repo = entityManager.find(Repo.class, repo.getId());
+
// add new packages that are new to the content source.
// for each new package, we have to find its resource type and package type
// (both of which must exist, or we abort that package and move on to the next);
@@ -1379,22 +1324,15 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
newPvcs = entityManager.merge(newPvcs);
// for all repos that are associated with this content source, add this package version directly to them
- if (associatedRepos == null) {
- q = entityManager.createNamedQuery(Repo.QUERY_FIND_IMPORTED_BY_CONTENT_SOURCE_ID_FETCH_CCS);
- q.setParameter("id", contentSource.getId());
- associatedRepos = q.getResultList();
- }
+ RepoPackageVersion mapping = new RepoPackageVersion(repo, pv);
+ entityManager.merge(mapping); // use merge just in case this mapping somehow already exists
- for (Repo associatedRepo : associatedRepos) {
- RepoPackageVersion mapping = new RepoPackageVersion(associatedRepo, pv);
- entityManager.merge(mapping); // use merge just in case this mapping somehow already exists
- }
+ // Cleanup
if ((++flushCount % 100) == 0) {
knownResourceTypes.clear();
knownPackageTypes.clear();
knownArchitectures.clear();
- associatedRepos = null;
knownProductVersions.clear();
entityManager.flush();
entityManager.clear();
@@ -1411,7 +1349,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergeContentSourceSyncReportUPDATE(ContentSource contentSource,
+ public ContentSourceSyncResults _mergePackageSyncReportUPDATE(ContentSource contentSource,
PackageSyncReport report, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress) {
progress.append(new Date()).append(": ").append("Updating");
@@ -1488,6 +1426,75 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
return syncResults;
}
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public ContentSourceSyncResults _mergeDistributionSyncReportREMOVE(ContentSource contentSource,
+ DistributionSyncReport report, ContentSourceSyncResults syncResults, StringBuilder progress) {
+
+ progress.append(new Date()).append(": ").append("Removing");
+ syncResults.setResults(progress.toString());
+ syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
+
+ DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal();
+ Subject overlord = LookupUtil.getSubjectManager().getOverlord();
+
+ // remove all distributions that are no longer available on the remote repository
+ for (DistributionDetails doomedDetails : report.getDeletedDistributions()) {
+ Distribution doomedDist = distManager.getDistributionByLabel(doomedDetails.getLabel());
+ distManager.deleteDistributionByDistId(overlord, doomedDist.getId());
+ distManager.deleteDistributionFilesByDistId(overlord, doomedDist.getId());
+ progress.append("Removed distribution & distribution files for: " + doomedDetails.getLabel());
+ syncResults.setResults(progress.toString());
+ syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
+ }
+
+ progress.append("Finished Distribution removal...").append('\n');
+ syncResults.setResults(progress.toString());
+ syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
+
+ return syncResults;
+ }
+
+ @SuppressWarnings("unchecked")
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public ContentSourceSyncResults _mergeDistributionSyncReportADD(ContentSource contentSource,
+ DistributionSyncReport report, ContentSourceSyncResults syncResults, StringBuilder progress) {
+
+ DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal();
+ RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
+ Subject overlord = LookupUtil.getSubjectManager().getOverlord();
+ List<DistributionDetails> newDetails = report.getDistributions();
+ for (DistributionDetails detail : newDetails) {
+ try {
+
+ log.debug("Attempting to create new distribution based off of: " + detail);
+ DistributionType distType = distManager.getDistributionTypeByName(detail.getDistributionType());
+ Distribution newDist = distManager.createDistribution(overlord, detail.getLabel(), detail
+ .getDistributionPath(), distType);
+ log.debug("Created new distribution: " + newDist);
+ Repo repo = repoManager.getRepo(overlord, report.getRepoId());
+ RepoDistribution repoDist = new RepoDistribution(repo, newDist);
+ log.debug("Created new mapping of RepoDistribution repoId = " + repo.getId() + ", distId = "
+ + newDist.getId());
+ entityManager.persist(repoDist);
+ List<DistributionFileDetails> files = detail.getFiles();
+ for (DistributionFileDetails f : files) {
+ log.debug("Creating DistributionFile for: " + f);
+ DistributionFile df = new DistributionFile(newDist, f.getRelativeFilename(), f.getMd5sum());
+ df.setLastModified(f.getLastModified());
+ entityManager.persist(df);
+ entityManager.flush();
+ }
+ } catch (DistributionException e) {
+ progress.append("Caught exception when trying to add: " + detail.getLabel() + "\n");
+ progress.append("Error is: " + e.getMessage());
+ syncResults.setResults(progress.toString());
+ syncResults = contentSourceManager.mergeContentSourceSyncResults(syncResults);
+ log.error(e);
+ }
+ }
+ return syncResults;
+ }
+
@SuppressWarnings("unchecked")
public PageList<PackageVersionMetadataComposite> getPackageVersionMetadata(int resourceId, PageControl pc) {
pc.initDefaultOrderingField("pv.id");
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerLocal.java
index c3eeb94..850cd6d 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerLocal.java
@@ -297,8 +297,8 @@ public interface ContentSourceManagerLocal {
* @return all unloaded package versions that the content source will be providing content for. The object returned
* also contains the location where those package versions are located in the content source
*/
- PageList<PackageVersionContentSource> getUnloadedPackageVersionsFromContentSource(Subject subject,
- int contentSourceId, PageControl pc);
+ PageList<PackageVersionContentSource> getUnloadedPackageVersionsFromContentSourceInRepo(Subject subject,
+ int contentSourceId, int repoId, PageControl pc);
@@ -402,6 +402,7 @@ public interface ContentSourceManagerLocal {
* was done
*/
ContentSourceSyncResults mergePackageSyncReport(ContentSource contentSource,
+ Repo repo,
PackageSyncReport report,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults);
@@ -420,25 +421,26 @@ public interface ContentSourceManagerLocal {
DistributionSyncReport report,
ContentSourceSyncResults syncResults);
- void _mergeContentSourceSyncReportUpdateRepo(int contentSourceId);
+ void _mergePackageSyncReportUpdateRepo(int contentSourceId);
- ContentSourceSyncResults _mergeContentSourceSyncReportREMOVE(ContentSource contentSource, PackageSyncReport report,
+ ContentSourceSyncResults _mergePackageSyncReportREMOVE(ContentSource contentSource,
+ Repo repo, PackageSyncReport report,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress);
- ContentSourceSyncResults _mergeContentSourceSyncReportADD(ContentSource contentSource,
- Collection<ContentProviderPackageDetails> newPackages,
+ ContentSourceSyncResults _mergePackageSyncReportADD(ContentSource contentSource,
+ Repo repo, Collection<ContentProviderPackageDetails> newPackages,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress, int addCount);
- ContentSourceSyncResults _mergeContentSourceSyncReportUPDATE(ContentSource contentSource, PackageSyncReport report,
+ ContentSourceSyncResults _mergePackageSyncReportUPDATE(ContentSource contentSource, PackageSyncReport report,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress);
- ContentSourceSyncResults _mergeContentSourceSyncReportREMOVE(ContentSource contentSource, DistributionSyncReport report,
+ ContentSourceSyncResults _mergeDistributionSyncReportREMOVE(ContentSource contentSource, DistributionSyncReport report,
ContentSourceSyncResults syncResults, StringBuilder progress);
- ContentSourceSyncResults _mergeContentSourceSyncReportADD(ContentSource contentSource,
+ ContentSourceSyncResults _mergeDistributionSyncReportADD(ContentSource contentSource,
DistributionSyncReport report, ContentSourceSyncResults syncResults, StringBuilder progress);
/**
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java
index 3d84178..6e6bc5a 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java
@@ -122,7 +122,7 @@ public class PackageSourceSynchronizer {
// --------------------------------------------
start = System.currentTimeMillis();
- contentSourceManager.mergePackageSyncReport(source, report, keyPVCSMap, null);
+ contentSourceManager.mergePackageSyncReport(source, repo, report, keyPVCSMap, null);
log.info("Synchronize Packages: [" + source.getName() +
"]: merged sync report=(" +
@@ -161,7 +161,7 @@ public class PackageSourceSynchronizer {
// TODO: jdob - Need to change this call to only load packages for this repo
List<PackageVersionContentSource> packageVersionContentSources = contentSourceManager
- .getUnloadedPackageVersionsFromContentSource(overlord, source.getId(), pc);
+ .getUnloadedPackageVersionsFromContentSourceInRepo(overlord, source.getId(), repo.getId(), pc);
log.info("Synchronize Package Bits: [" + source.getName() + "], repo [" + repo.getName() +
"]: loaded package list for sync (" + (System.currentTimeMillis() - start) + ")ms");
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
index 0208014..c79ec39 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java
@@ -69,8 +69,8 @@ import org.rhq.enterprise.server.plugin.pc.content.TestContentServerPluginServic
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
-@Test
public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
+
private static final boolean TESTS_ENABLED = true;
private ContentManagerLocal contentManager;
@@ -259,6 +259,11 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
contentSourceId = contentSource.getId();
assert contentSourceId > 0;
+ // create a repo
+ Repo repo = new Repo("testRepo");
+ repo = repoManager.createRepo(overlord, repo);
+ repoId = repo.getId();
+
// this report will add a mapping to PV->CS
// we didn't set up any mappings like that yet - this will be the first one
PackageSyncReport report = new PackageSyncReport();
@@ -279,7 +284,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
results = contentSourceManager.persistContentSourceSyncResults(results);
assert results != null;
- results = contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
// Verify the product version was created
@@ -306,14 +311,6 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
em.close();
}
- // create a repo
- pc = PageControl.getUnlimitedInstance();
- int origRepoCount = repoManager.findRepos(overlord, pc).size();
- Repo repo = new Repo("testMergeSyncReportRepo");
- repo = repoManager.createRepo(overlord, repo);
- assert (origRepoCount + 1) == repoManager.findRepos(overlord, pc).size();
- repoId = repo.getId();
-
// see that the resource sees no metadata yet - not subscribed yet
pc = PageControl.getUnlimitedInstance();
PageList<PackageVersionMetadataComposite> metadataList;
@@ -355,7 +352,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
// confirm that we didn't load the bits yet
pc = PageControl.getUnlimitedInstance();
List<PackageVersionContentSource> unloaded;
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSource(overlord, contentSourceId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
@@ -416,6 +413,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
List<PackageVersionContentSource> inCS;
PageControl pc = PageControl.getUnlimitedInstance();
int contentSourceId = 0;
+ int repoId = 0;
try {
// create content source type and content source
@@ -430,6 +428,11 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
contentSourceId = contentSource.getId();
assert contentSourceId > 0;
+ // create repo
+ Repo repo = new Repo("testRepo");
+ repo = repoManager.createRepo(overlord, repo);
+ repoId = repo.getId();
+
// just make sure there are no package versions yet
inCS = contentSourceManager.getPackageVersionsFromContentSource(overlord, contentSourceId, pc);
assert inCS != null;
@@ -452,7 +455,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
previous = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>();
// ADD: merge the report!
- results = contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
// see the package version has been assigned to the content source
@@ -462,7 +465,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
// confirm that we didn't load the bits yet
List<PackageVersionContentSource> unloaded;
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSource(overlord, contentSourceId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
@@ -483,7 +486,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
report.addUpdatedPackage(details);
// UPDATE: merge the report!
- results = contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
// see the package version is still assigned to the content source
@@ -492,7 +495,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
assert inCS.size() == 1 : inCS;
// it should still be unloaded, make sure and check that it really was updated
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSource(overlord, contentSourceId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
assert unloaded.get(0).getPackageVersionContentSourcePK().getPackageVersion().getFileSize() == 9999L;
@@ -504,7 +507,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
report.addDeletePackage(details);
// REMOVE: merge the report!
- results = contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
// see the package version is gone
@@ -522,6 +525,9 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
throw e;
} finally {
try {
+ if (repoId != 0) {
+ repoManager.deleteRepo(overlord, repoId);
+ }
if (contentSourceId != 0) {
contentSourceManager.deleteContentSource(overlord, contentSourceId);
}
@@ -550,8 +556,9 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
contentSourceId = contentSource.getId();
assert contentSourceId > 0;
+
Repo repo = new Repo("testMergeSyncReportAMU2Ch");
- repoManager.createRepo(overlord, repo);
+ repo = repoManager.createRepo(overlord, repo);
repoId = repo.getId();
assert repoId > 0;
repoManager.addContentSourcesToRepo(overlord, repoId, new int[] { contentSourceId });
@@ -576,15 +583,15 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
previous = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>();
// ADD: merge the report!
- results = contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
List<PackageVersionContentSource> unloaded;
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSource(overlord, contentSourceId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
- // check the count - since content source was in a repo, the repo gets the PV too
+ // check the count to make sure the pv was added to the repo
assert 1 == contentSourceManager.getPackageVersionCountFromContentSource(overlord, contentSourceId);
assert 1 == repoManager.getPackageVersionCountFromRepo(overlord, repoId);
@@ -597,12 +604,14 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
report.addDeletePackage(details);
// REMOVE: merge the report!
- results = contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
- // check the count - note the repo's PV remains intact!!
+ // check the count - since the pv does not have a provider nor an installed package,
+ // is it removed from the repo as well
assert 0 == contentSourceManager.getPackageVersionCountFromContentSource(overlord, contentSourceId);
- assert 1 == repoManager.getPackageVersionCountFromRepo(overlord, repoId);
+ long pvCountFromRepo = repoManager.getPackageVersionCountFromRepo(overlord, repoId);
+ assert 0 == pvCountFromRepo : "Expected: 0, Found: " + pvCountFromRepo;
} catch (Exception e) {
e.printStackTrace();
throw e;
@@ -853,7 +862,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
// create a repo and associate the new content source with it
Repo repo = new Repo("testMergeWithRepo");
- repoManager.createRepo(overlord, repo);
+ repo = repoManager.createRepo(overlord, repo);
repoManager.addContentSourcesToRepo(overlord, repo.getId(), new int[] { contentSourceId });
// this report will add a mapping to PV->CS
@@ -876,7 +885,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
results = contentSourceManager.persistContentSourceSyncResults(results);
assert results != null;
- contentSourceManager.mergePackageSyncReport(contentSource, report, previous, results);
+ contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
List<PackageVersion> inRepo;
inRepo = repoManager.findPackageVersionsInRepo(overlord, repo.getId(), PageControl.getUnlimitedInstance());
14 years, 5 months
[rhq] Branch 'content' - modules/enterprise
by Pradeep Kilambi
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnComm.java | 15 +
modules/enterprise/server/plugins/rhnhosted/src/main/xsd/sample/sample-rhnhosted-dump.errata.xml | 74 ++++++++
modules/enterprise/server/plugins/rhnhosted/src/main/xsd/schema0.xsd | 92 ++++++++--
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/BasicRHNTest.java | 54 +++++
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java | 27 ++
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnCommTest.java | 29 +++
6 files changed, 275 insertions(+), 16 deletions(-)
New commits:
commit a182a35aec803e5f6fba820b7345eaae3de54807
Author: Pradeep Kilambi <pkilambi(a)redhat.com>
Date: Mon Nov 30 15:34:12 2009 -0500
Adding errata metadata representation support to xmlrpc layer once the errata is fetched from hosted.
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnComm.java b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnComm.java
index 155096a..5f5a255 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnComm.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnComm.java
@@ -5,12 +5,13 @@ import java.util.List;
import javax.xml.bind.JAXBElement;
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlrpc.XmlRpcException;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamilyType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnErratumType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageShortType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageType;
@@ -91,4 +92,14 @@ public class RhnComm {
return sat.getRhnKickstartableTrees().getRhnKickstartableTree();
}
+ public List<RhnErratumType> getErrataMetadata(String systemId, List<String> erratumIds) throws IOException,
+ XmlRpcException {
+
+ log.debug("getErratum(" + erratumIds + ")");
+ Object[] params = new Object[] { systemId, erratumIds };
+ JAXBElement<RhnSatelliteType> result = (JAXBElement) dumpHandler.execute("dump.errata", params);
+ RhnSatelliteType sat = result.getValue();
+ return sat.getRhnErrata().getRhnErratum();
+ }
+
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/sample/sample-rhnhosted-dump.errata.xml b/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/sample/sample-rhnhosted-dump.errata.xml
new file mode 100644
index 0000000..7d11fe4
--- /dev/null
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/sample/sample-rhnhosted-dump.errata.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?><rhn-satellite generation="2" version="3.4"><rhn-errata><rhn-erratum channels="rhel-i386-client-5 rhel-x86_64-client-5 rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" advisory="RHSA-2007:0540-3" packages="rhn-package-410949 rhn-package-410950 rhn-package-410951 rhn-package-410952 rhn-package-422137 rhn-package-422138 rhn-package-422139 rhn-package-422140 rhn-package-422141 rhn-package-422142 rhn-package-422143 rhn-package-422144 rhn-package-422145 rhn-package-422146 rhn-package-422147 rhn-package-422148 rhn-package-422149 rhn-package-422150 rhn-package-422151 rhn-package-422152" id="rhn-erratum-6184" cve-names="CVE-2006-5052 CVE-2007-3102"><rhn-erratum-advisory-name>RHSA-2007:0540</rhn-erratum-advisory-name><rhn-erratum-advisory-rel>3</rhn-erratum-advisory-rel><rhn-erratum-advisory-type>Security Advisory</rhn-erratum-advisory-type><rhn-erratum-product>Red Hat Enterprise Linux</rhn-erratum-product><rhn-erratum-description>OpenSSH is OpenBSD's SSH (Secure SHell) protocol implementation. These
+packages include the core files necessary for both the OpenSSH client and
+server.
+
+A flaw was found in the way the ssh server wrote account names to the audit
+subsystem. An attacker could inject strings containing parts of audit
+messages, which could possibly mislead or confuse audit log parsing tools.
+(CVE-2007-3102)
+
+A flaw was found in the way the OpenSSH server processes GSSAPI
+authentication requests. When GSSAPI authentication was enabled in the
+OpenSSH server, a remote attacker was potentially able to determine if a
+username is valid. (CVE-2006-5052)
+
+The following bugs in SELinux MLS (Multi-Level Security) support has also
+been fixed in this update:
+
+* It was sometimes not possible to select a SELinux role and level when
+logging in using ssh.
+
+* If the user obtained a non-default SELinux role or level, the role change
+was not recorded in the audit subsystem.
+
+* In some cases, on labeled networks, sshd allowed logins from level ranges
+it should not allow.
+
+The updated packages also contain experimental support for using private
+keys stored in PKCS#11 tokens for client authentication. The support is
+provided through the NSS (Network Security Services) library.
+
+All users of openssh should upgrade to these updated packages, which
+contain patches to correct these issues.</rhn-erratum-description><rhn-erratum-synopsis>Moderate: openssh security and bug fix update</rhn-erratum-synopsis><rhn-erratum-topic>Updated openssh packages that fix a security issue and various bugs are now
+available.
+
+This update has been rated as having moderate security impact by the Red Hat
+Security Response Team.</rhn-erratum-topic><rhn-erratum-solution>Before applying this update, make sure that all previously-released
+errata relevant to your system have been applied.
+
+This update is available via Red Hat Network. Details on how to use
+the Red Hat Network to apply this update are available at
+http://kbase.redhat.com/faq/FAQ_58_10188
+</rhn-erratum-solution><rhn-erratum-refers-to>http://www.redhat.com/security/updates/classification/#moderate</rhn-erratum-refers-to><rhn-erratum-notes></rhn-erratum-notes><rhn-erratum-issue-date>1194411600</rhn-erratum-issue-date><rhn-erratum-update-date>1194411600</rhn-erratum-update-date><rhn-erratum-last-modified>1194452355</rhn-erratum-last-modified><rhn-erratum-keywords><rhn-erratum-keyword>GSSAPI</rhn-erratum-keyword><rhn-erratum-keyword>krb5</rhn-erratum-keyword><rhn-erratum-keyword>MLS</rhn-erratum-keyword><rhn-erratum-keyword>level</rhn-erratum-keyword><rhn-erratum-keyword>role</rhn-erratum-keyword><rhn-erratum-keyword>SELinux</rhn-erratum-keyword><rhn-erratum-keyword>NSS</rhn-erratum-keyword><rhn-erratum-keyword>token</rhn-erratum-keyword><rhn-erratum-keyword>audit</rhn-erratum-keyword></rhn-erratum-keywords><rhn-erratum-bugs><rhn-erratum-bug><rhn-erratum-bug-id>227733</rhn-erratum-bug-id><rhn-erratum-bug-summary>[LSPP] unable to ssh into a system as root/auditadm_r</rhn-erratum-bug-summary></rhn-erratum-bug><rhn-erratum-bug><rhn-erratum-bug-id>229278</rhn-erratum-bug-id><rhn-erratum-bug-summary>LSPP: ssh-mls allows a level through that it should not</rhn-erratum-bug-summary></rhn-erratum-bug><rhn-erratum-bug><rhn-erratum-bug-id>231695</rhn-erratum-bug-id><rhn-erratum-bug-summary>LSPP: user unable to ssh to system with user/role/level context</rhn-erratum-bug-summary></rhn-erratum-bug><rhn-erratum-bug><rhn-erratum-bug-id>234638</rhn-erratum-bug-id><rhn-erratum-bug-summary>CVE-2006-5052 GSSAPI information leak</rhn-erratum-bug-summary></rhn-erratum-bug><rhn-erratum-bug><rhn-erratum-bug-id>234951</rhn-erratum-bug-id><rhn-erratum-bug-summary>[LSPP] openssh server fails to parse level correctly</rhn-erratum-bug-summary></rhn-erratum-bug><rhn-erratum-bug><rhn-erratum-bug-id>248059</rhn-erratum-bug-id><rhn-erratum-bug-summary>CVE-2007-3102 audit logging of failed logins</rhn-erratum-bug-summary></rhn-erratum-bug></rhn-erratum-bugs><rhn-erratum-files><rhn-erratum-file channels="rhel-i386-client-5 rhel-x86_64-client-5" md5sum="153a17e8f011bde6d984ce73b92cebff" type="SRPM" source-package="rhn-package-source-43601" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/SRPMS/openssh-4.3p2-24.el5.src.rpm"/><rhn-erratum-file channels="rhel-i386-client-5" package="rhn-package-410949" md5sum="ba4d6b70e9de7860b5ebe370ca5cdf53" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/i386/openssh-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-i386-client-5" package="rhn-package-410950" md5sum="d7b28f340fe82d28660876ca6bcc0a35" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/i386/openssh-askpass-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-i386-client-5" package="rhn-package-410951" md5sum="c4216b9a462e5f0462096f1d9b6b8d5f" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/i386/openssh-clients-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-i386-client-5" package="rhn-package-410952" md5sum="9f17e3dfe06fbbed05f765abd6b2509a" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/i386/openssh-server-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-x86_64-client-5" package="rhn-package-422138" md5sum="67538525ad7cf2f1d310a429b44890c7" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/x86_64/openssh-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-x86_64-client-5" package="rhn-package-422151" md5sum="37118e168b7a55531459b4743d3522fb" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/x86_64/openssh-askpass-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-x86_64-client-5" package="rhn-package-422137" md5sum="6ce7070b90732f3c837df5cfc9287187" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/x86_64/openssh-clients-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-x86_64-client-5" package="rhn-package-422143" md5sum="a7141781bfe5f21f2fc5b192ebf6693e" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/x86_64/openssh-server-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" md5sum="153a17e8f011bde6d984ce73b92cebff" type="SRPM" source-package="rhn-package-source-43601" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/openssh-4.3p2-24.el5.src.rpm"/><rhn-erratum-file channels="rhel-i386-server-5" package="rhn-package-410949" md5sum="ba4d6b70e9de7860b5ebe370ca5cdf53" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/i386/openssh-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-i386-server-5" package="rhn-package-410950" md5sum="d7b28f340fe82d28660876ca6bcc0a35" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/i386/openssh-askpass-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-i386-server-5" package="rhn-package-410951" md5sum="c4216b9a462e5f0462096f1d9b6b8d5f" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/i386/openssh-clients-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-i386-server-5" package="rhn-package-410952" md5sum="9f17e3dfe06fbbed05f765abd6b2509a" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/i386/openssh-server-4.3p2-24.el5.i386.rpm"/><rhn-erratum-file channels="rhel-ia64-server-5" package="rhn-package-422150" md5sum="5a4b28d5af0be02b37e02ae0aed692aa" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ia64/openssh-4.3p2-24.el5.ia64.rpm"/><rhn-erratum-file channels="rhel-ia64-server-5" package="rhn-package-422149" md5sum="b2672d6bc6fbbd29414d23523631ac03" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ia64/openssh-askpass-4.3p2-24.el5.ia64.rpm"/><rhn-erratum-file channels="rhel-ia64-server-5" package="rhn-package-422142" md5sum="2e7e42fd888d7fb1a87531e3f7a58889" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ia64/openssh-clients-4.3p2-24.el5.ia64.rpm"/><rhn-erratum-file channels="rhel-ia64-server-5" package="rhn-package-422146" md5sum="e909c8bac59183dfe6f47f1e71c5306e" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ia64/openssh-server-4.3p2-24.el5.ia64.rpm"/><rhn-erratum-file channels="rhel-ppc-server-5" package="rhn-package-422152" md5sum="7c4fbb3d8e40b083acdbd6a5186e1db3" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ppc/openssh-4.3p2-24.el5.ppc.rpm"/><rhn-erratum-file channels="rhel-ppc-server-5" package="rhn-package-422145" md5sum="4f878a818e9fd07d16becbf66e35389f" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ppc/openssh-askpass-4.3p2-24.el5.ppc.rpm"/><rhn-erratum-file channels="rhel-ppc-server-5" package="rhn-package-422148" md5sum="9c31ff09ef6ca0a20bba14fb89c3e250" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ppc/openssh-clients-4.3p2-24.el5.ppc.rpm"/><rhn-erratum-file channels="rhel-ppc-server-5" package="rhn-package-422147" md5sum="3187b878bf79dc71e226ae8096f07081" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ppc/openssh-server-4.3p2-24.el5.ppc.rpm"/><rhn-erratum-file channels="rhel-s390x-server-5" package="rhn-package-422140" md5sum="f4c3b2d6c3b170376f0e3fce0b1f38ec" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/s390x/openssh-4.3p2-24.el5.s390x.rpm"/><rhn-erratum-file channels="rhel-s390x-server-5" package="rhn-package-422139" md5sum="ab38b48be3d112c5aa333296bd9cbc3f" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/s390x/openssh-askpass-4.3p2-24.el5.s390x.rpm"/><rhn-erratum-file channels="rhel-s390x-server-5" package="rhn-package-422144" md5sum="03643d364acf47e086c913c95dae8cb2" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/s390x/openssh-clients-4.3p2-24.el5.s390x.rpm"/><rhn-erratum-file channels="rhel-s390x-server-5" package="rhn-package-422141" md5sum="0d6286527c165d1df00ece5761fcefed" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/s390x/openssh-server-4.3p2-24.el5.s390x.rpm"/><rhn-erratum-file channels="rhel-x86_64-server-5" package="rhn-package-422138" md5sum="67538525ad7cf2f1d310a429b44890c7" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/x86_64/openssh-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-x86_64-server-5" package="rhn-package-422151" md5sum="37118e168b7a55531459b4743d3522fb" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/x86_64/openssh-askpass-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-x86_64-server-5" package="rhn-package-422137" md5sum="6ce7070b90732f3c837df5cfc9287187" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/x86_64/openssh-clients-4.3p2-24.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-x86_64-server-5" package="rhn-package-422143" md5sum="a7141781bfe5f21f2fc5b192ebf6693e" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/x86_64/openssh-server-4.3p2-24.el5.x86_64.rpm"/></rhn-erratum-files></rhn-erratum><rhn-erratum channels="rhel-i386-client-5 rhel-x86_64-client-5 rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" advisory="RHEA-2007:0653-2" packages="rhn-package-422130 rhn-package-422131 rhn-package-422132 rhn-package-422133 rhn-package-422134" id="rhn-erratum-6182" cve-names=""><rhn-erratum-advisory-name>RHEA-2007:0653</rhn-erratum-advisory-name><rhn-erratum-advisory-rel>2</rhn-erratum-advisory-rel><rhn-erratum-advisory-type>Product Enhancement Advisory</rhn-erratum-advisory-type><rhn-erratum-product>Red Hat Enterprise Linux</rhn-erratum-product><rhn-erratum-description>RHEA-2007:0643 errata update libvirt to version 0.2.3, but that
+updated version also requires dnsmasq for virtual network support
+which was added in libvirt.</rhn-erratum-description><rhn-erratum-synopsis>New package dnsmasq</rhn-erratum-synopsis><rhn-erratum-topic>This errata adds a new package which is required by libvirt
+update to version 0.2.3.</rhn-erratum-topic><rhn-erratum-solution>Before applying this update, make sure that all previously-released
+errata relevant to your system have been applied.
+
+This update is available via Red Hat Network. Details on how to use
+the Red Hat Network to apply this update are available at
+http://kbase.redhat.com/faq/FAQ_58_10188</rhn-erratum-solution><rhn-erratum-refers-to></rhn-erratum-refers-to><rhn-erratum-notes></rhn-erratum-notes><rhn-erratum-issue-date>1194449155</rhn-erratum-issue-date><rhn-erratum-update-date>1194449155</rhn-erratum-update-date><rhn-erratum-last-modified>1194449155</rhn-erratum-last-modified><rhn-erratum-keywords/><rhn-erratum-bugs><rhn-erratum-bug><rhn-erratum-bug-id>244247</rhn-erratum-bug-id><rhn-erratum-bug-summary>Add dnsmasq package to RHEL</rhn-erratum-bug-summary></rhn-erratum-bug></rhn-erratum-bugs><rhn-erratum-files><rhn-erratum-file channels="rhel-i386-client-5 rhel-x86_64-client-5" md5sum="ebf541cf1c9a5ec87e6a19568bf7ab16" type="SRPM" source-package="rhn-package-source-44247" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/SRPMS/dnsmasq-2.39-2.el5.src.rpm"/><rhn-erratum-file channels="rhel-i386-client-5" package="rhn-package-422134" md5sum="940f7604d9c6875b7ca59aeb6b2f0ada" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/i386/dnsmasq-2.39-2.el5.i386.rpm"/><rhn-erratum-file channels="rhel-x86_64-client-5" package="rhn-package-422130" md5sum="b586f231718aa47792196fb4d7fdf20b" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/x86_64/dnsmasq-2.39-2.el5.x86_64.rpm"/><rhn-erratum-file channels="rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" md5sum="ebf541cf1c9a5ec87e6a19568bf7ab16" type="SRPM" source-package="rhn-package-source-44247" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/dnsmasq-2.39-2.el5.src.rpm"/><rhn-erratum-file channels="rhel-i386-server-5" package="rhn-package-422134" md5sum="940f7604d9c6875b7ca59aeb6b2f0ada" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/i386/dnsmasq-2.39-2.el5.i386.rpm"/><rhn-erratum-file channels="rhel-ia64-server-5" package="rhn-package-422133" md5sum="8fc68ea1078f33dea9fee16daf51136a" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ia64/dnsmasq-2.39-2.el5.ia64.rpm"/><rhn-erratum-file channels="rhel-ppc-server-5" package="rhn-package-422132" md5sum="af86b03762d044c780f1b4f0136be18a" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/ppc/dnsmasq-2.39-2.el5.ppc.rpm"/><rhn-erratum-file channels="rhel-s390x-server-5" package="rhn-package-422131" md5sum="4b33f1fe6e075b242c07e4935609efdd" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/s390x/dnsmasq-2.39-2.el5.s390x.rpm"/><rhn-erratum-file channels="rhel-x86_64-server-5" package="rhn-package-422130" md5sum="b586f231718aa47792196fb4d7fdf20b" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/x86_64/dnsmasq-2.39-2.el5.x86_64.rpm"/></rhn-erratum-files></rhn-erratum><rhn-erratum channels="rhel-i386-client-5 rhel-x86_64-client-5 rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" advisory="RHBA-2007:0748-11" packages="rhn-package-422136" id="rhn-erratum-6183" cve-names=""><rhn-erratum-advisory-name>RHBA-2007:0748</rhn-erratum-advisory-name><rhn-erratum-advisory-rel>11</rhn-erratum-advisory-rel><rhn-erratum-advisory-type>Bug Fix Advisory</rhn-erratum-advisory-type><rhn-erratum-product>Red Hat Enterprise Linux</rhn-erratum-product><rhn-erratum-description>The booty package contains a python library which provides an interface for
+the creation of boot loader configuration files and the addition of stanzas
+to said configuration files. These boot loader configuration files are used
+by the anaconda installer.
+
+This updated package fixes the following bugs:
+
+* the "vmm=" line was missing in elilo.conf after installing Red Hat
+Enterprise Linux 5, with Xen virtualization packages selected, on Itanium
+architectures. This resulted in a kernel which was un-bootable. However,
+manually installing the kernel-xen RPM resolved this issue. The elilo.conf
+file is correctly created in this updated package.
+
+* in the previous package, booty incorrectly used disk names for all
+devices, causing boot failures in certain SCSI environments. In this
+updated package booty correctly uses disk names or labels depending on the
+device, which resolves this issue.
+
+All booty users should upgrade to this updated package, which resolves
+these issues.</rhn-erratum-description><rhn-erratum-synopsis>booty bug fix update</rhn-erratum-synopsis><rhn-erratum-topic>An updated booty package that fixes several bugs is now available.</rhn-erratum-topic><rhn-erratum-solution>Before applying this update, make sure that all previously-released
+errata relevant to your system have been applied.
+
+This update is available via Red Hat Network. Details on how to use
+the Red Hat Network to apply this update are available at
+http://kbase.redhat.com/faq/FAQ_58_10188</rhn-erratum-solution><rhn-erratum-refers-to></rhn-erratum-refers-to><rhn-erratum-notes></rhn-erratum-notes><rhn-erratum-issue-date>1194449155</rhn-erratum-issue-date><rhn-erratum-update-date>1194449155</rhn-erratum-update-date><rhn-erratum-last-modified>1194449155</rhn-erratum-last-modified><rhn-erratum-keywords/><rhn-erratum-bugs><rhn-erratum-bug><rhn-erratum-bug-id>250631</rhn-erratum-bug-id><rhn-erratum-bug-summary>[RHEL5.1 Beta] booty: not using LABEL for non-dm devices causes boot failure</rhn-erratum-bug-summary></rhn-erratum-bug></rhn-erratum-bugs><rhn-erratum-files><rhn-erratum-file channels="rhel-i386-client-5 rhel-x86_64-client-5" md5sum="532e2e85384916e5b35a81d54e3d29d8" type="SRPM" source-package="rhn-package-source-44248" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/SRPMS/booty-0.80.4-5.src.rpm"/><rhn-erratum-file channels="rhel-i386-client-5 rhel-x86_64-client-5" package="rhn-package-422136" md5sum="504644ee5352554dd01ec5a12d23806f" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Client/en/os/noarch/booty-0.80.4-5.noarch.rpm"/><rhn-erratum-file channels="rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" md5sum="532e2e85384916e5b35a81d54e3d29d8" type="SRPM" source-package="rhn-package-source-44248" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/booty-0.80.4-5.src.rpm"/><rhn-erratum-file channels="rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5 rhel-s390x-server-5" package="rhn-package-422136" md5sum="504644ee5352554dd01ec5a12d23806f" type="RPM" filename="/ftp/pub/redhat/linux/enterprise/5Server/en/os/noarch/booty-0.80.4-5.noarch.rpm"/></rhn-erratum-files></rhn-erratum></rhn-errata></rhn-satellite>
\ No newline at end of file
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/schema0.xsd b/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/schema0.xsd
index 708d481..0e87f84 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/schema0.xsd
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/xsd/schema0.xsd
@@ -51,11 +51,6 @@
<xs:element type="rhn-channel-familyType" name="rhn-channel-family" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="rhn-packages-shortType">
- <xs:sequence>
- <xs:element type="rhn-package-shortType" name="rhn-package-short" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="rhn-package-provides-entryType">
<xs:simpleContent>
<xs:extension base="xs:string">
@@ -65,6 +60,11 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
+ <xs:complexType name="rhn-packages-shortType">
+ <xs:sequence>
+ <xs:element type="rhn-package-shortType" name="rhn-package-short" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-product-namesType">
<xs:sequence>
<xs:element type="rhn-product-nameType" name="rhn-product-name" maxOccurs="unbounded" minOccurs="0"/>
@@ -88,6 +88,7 @@
<xs:sequence>
<xs:element type="rhn-channel-familiesType" name="rhn-channel-families" minOccurs="0"/>
<xs:element type="rhn-channelsType" name="rhn-channels" minOccurs="0"/>
+ <xs:element type="rhn-errataType" name="rhn-errata" minOccurs="0"/>
<xs:element type="rhn-kickstartable-treesType" name="rhn-kickstartable-trees" minOccurs="0"/>
<xs:element type="rhn-packages-shortType" name="rhn-packages-short" minOccurs="0"/>
<xs:element type="rhn-packagesType" name="rhn-packages" minOccurs="0"/>
@@ -115,6 +116,11 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
+ <xs:complexType name="rhn-erratum-filesType">
+ <xs:sequence>
+ <xs:element type="rhn-erratum-fileType" name="rhn-erratum-file" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-product-nameType">
<xs:simpleContent>
<xs:extension base="xs:string">
@@ -123,6 +129,11 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
+ <xs:complexType name="rhn-package-changelogType">
+ <xs:sequence>
+ <xs:element type="rhn-package-changelog-entryType" name="rhn-package-changelog-entry" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-package-changelog-entryType">
<xs:sequence>
<xs:element type="xs:string" name="rhn-package-changelog-entry-name"/>
@@ -130,11 +141,6 @@
<xs:element type="xs:string" name="rhn-package-changelog-entry-time"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="rhn-package-changelogType">
- <xs:sequence>
- <xs:element type="rhn-package-changelog-entryType" name="rhn-package-changelog-entry" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="rhn-package-shortType">
<xs:simpleContent>
<xs:extension base="xs:string">
@@ -211,6 +217,31 @@
<xs:attribute type="xs:string" name="virt-sub-level-label" use="optional"/>
<xs:attribute type="xs:string" name="virt-sub-level-name" use="optional"/>
</xs:complexType>
+ <xs:complexType name="rhn-erratumType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="rhn-erratum-advisory-name"/>
+ <xs:element type="xs:string" name="rhn-erratum-advisory-rel"/>
+ <xs:element type="xs:string" name="rhn-erratum-advisory-type"/>
+ <xs:element type="xs:string" name="rhn-erratum-product"/>
+ <xs:element type="xs:string" name="rhn-erratum-description"/>
+ <xs:element type="xs:string" name="rhn-erratum-synopsis"/>
+ <xs:element type="xs:string" name="rhn-erratum-topic"/>
+ <xs:element type="xs:string" name="rhn-erratum-solution"/>
+ <xs:element type="xs:string" name="rhn-erratum-refers-to"/>
+ <xs:element type="xs:string" name="rhn-erratum-notes"/>
+ <xs:element type="xs:string" name="rhn-erratum-issue-date"/>
+ <xs:element type="xs:string" name="rhn-erratum-update-date"/>
+ <xs:element type="xs:string" name="rhn-erratum-last-modified"/>
+ <xs:element type="rhn-erratum-keywordsType" name="rhn-erratum-keywords"/>
+ <xs:element type="rhn-erratum-bugsType" name="rhn-erratum-bugs"/>
+ <xs:element type="rhn-erratum-filesType" name="rhn-erratum-files"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="channels" use="optional"/>
+ <xs:attribute type="xs:string" name="advisory" use="optional"/>
+ <xs:attribute type="xs:string" name="packages" use="optional"/>
+ <xs:attribute type="xs:string" name="id" use="optional"/>
+ <xs:attribute type="xs:string" name="cve-names" use="optional"/>
+ </xs:complexType>
<xs:complexType name="rhn-kickstart-fileType">
<xs:simpleContent>
<xs:extension base="xs:string">
@@ -240,6 +271,11 @@
<xs:element type="xs:string" name="rhn-null"/>
</xs:sequence>
</xs:complexType>
+ <xs:complexType name="rhn-erratum-bugsType">
+ <xs:sequence>
+ <xs:element type="rhn-erratum-bugType" name="rhn-erratum-bug" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-source-packagesType">
<xs:sequence>
<xs:element type="rhn-source-packageType" name="rhn-source-package" maxOccurs="unbounded" minOccurs="0"/>
@@ -250,6 +286,11 @@
<xs:element type="rhn-kickstart-fileType" name="rhn-kickstart-file" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
+ <xs:complexType name="rhn-errataType">
+ <xs:sequence>
+ <xs:element type="rhn-erratumType" name="rhn-erratum" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-channel-descriptionType">
<xs:sequence>
<xs:element type="xs:string" name="rhn-null" minOccurs="0"/>
@@ -279,6 +320,12 @@
<xs:element type="rhn-kickstartable-treeType" name="rhn-kickstartable-tree" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
+ <xs:complexType name="rhn-erratum-bugType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="rhn-erratum-bug-id"/>
+ <xs:element type="xs:string" name="rhn-erratum-bug-summary"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-channelsType">
<xs:sequence>
<xs:element type="rhn-channelType" name="rhn-channel" maxOccurs="unbounded" minOccurs="0"/>
@@ -317,6 +364,11 @@
<xs:attribute type="xs:string" name="packages" use="optional"/>
<xs:attribute type="xs:string" name="channel-id" use="optional"/>
</xs:complexType>
+ <xs:complexType name="rhn-erratum-keywordsType" mixed="true">
+ <xs:sequence>
+ <xs:element type="xs:string" name="rhn-erratum-keyword" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="rhn-package-requires-entryType">
<xs:simpleContent>
<xs:extension base="xs:string">
@@ -326,14 +378,26 @@
</xs:extension>
</xs:simpleContent>
</xs:complexType>
- <xs:complexType name="source-packagesType">
- <xs:sequence>
- <xs:element type="source-packageType" name="source-package" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
+ <xs:complexType name="rhn-erratum-fileType">
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute type="xs:string" name="channels" use="optional"/>
+ <xs:attribute type="xs:string" name="md5sum" use="optional"/>
+ <xs:attribute type="xs:string" name="type" use="optional"/>
+ <xs:attribute type="xs:string" name="source-package" use="optional"/>
+ <xs:attribute type="xs:string" name="filename" use="optional"/>
+ <xs:attribute type="xs:string" name="package" use="optional"/>
+ </xs:extension>
+ </xs:simpleContent>
</xs:complexType>
<xs:complexType name="rhn-package-requiresType">
<xs:sequence>
<xs:element type="rhn-package-requires-entryType" name="rhn-package-requires-entry" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
+ <xs:complexType name="source-packagesType">
+ <xs:sequence>
+ <xs:element type="source-packageType" name="source-package" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
</xs:schema>
\ No newline at end of file
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/BasicRHNTest.java b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/BasicRHNTest.java
index 702960c..7ad8701 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/BasicRHNTest.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/BasicRHNTest.java
@@ -23,6 +23,7 @@ import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamilyType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnErratumType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageShortType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageType;
@@ -516,6 +517,59 @@ public class BasicRHNTest extends TestCase {
assertTrue(success);
}
+ public void testDumpErrata() throws Exception {
+ boolean success = true;
+
+ try {
+ String systemid = getSystemId();
+ if (StringUtils.isBlank(systemid)) {
+ System.out.println("Skipping test since systemid is not readable");
+ return;
+ }
+
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+ config.setServerURL(new URL(serverUrl + "/SAT-DUMP"));
+ XmlRpcClient client = new XmlRpcClient();
+ client.setConfig(config);
+
+ RhnJaxbTransportFactory transportFactory = new RhnJaxbTransportFactory(client);
+ transportFactory.setRequestProperties(getRequestProperties());
+ transportFactory.setJaxbDomain("org.rhq.enterprise.server.plugins.rhnhosted.xml");
+ transportFactory.setDumpMessageToFile(debugDumpFile);
+ transportFactory.setDumpFilePath("/tmp/sample-rhnhosted-dump.errata.xml");
+ client.setTransportFactory(transportFactory);
+
+ List<String> errataIds = new ArrayList<String>();
+
+ errataIds.add("rhn-erratum-6183");
+ errataIds.add("rhn-erratum-6184");
+ errataIds.add("rhn-erratum-6182");
+ Object[] params = new Object[] { systemid, errataIds };
+
+ JAXBElement<RhnSatelliteType> result = (JAXBElement) client.execute("dump.errata", params);
+ RhnSatelliteType sat = result.getValue();
+
+ List<RhnErratumType> errata = sat.getRhnErrata().getRhnErratum();
+
+ for (RhnErratumType e : errata) {
+ assertFalse(StringUtils.isBlank(e.getAdvisory()));
+ assertFalse(StringUtils.isBlank(e.getChannels()));
+ assertFalse(StringUtils.isBlank(e.getPackages()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumAdvisoryName()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumAdvisoryType()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumDescription()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumSynopsis()));
+ assertTrue(e.getRhnErratumBugs().getRhnErratumBug().size() > 0);
+
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ success = false;
+ }
+ assertTrue(success);
+ }
+
/**
Sample info
handler = /SAT/$RHN/rhel-x86_64-server-5/getPackage/ipsec-tools-0.6.5-6.x86_64.rpm
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
index bcdfe41..d201b3f 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
@@ -38,6 +38,8 @@ import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamiliesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamilyType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelsType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnErrataType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnErratumType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFileType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFilesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
@@ -177,6 +179,31 @@ public class MockRhnXmlRpcExecutor implements XmlRpcExecutor {
}
return element;
+ } else if (methodName.equals("dump.errata")) {
+ if (systemid.contains("<value><string>ID-0000000000</string></value>")) {
+ throw new XmlRpcException(-9, "Invalid System Credentials");
+ }
+ JAXBElement element = getRhnSatelliteType();
+ RhnSatelliteType retval = (RhnSatelliteType) element.getValue();
+ RhnErrataType errata = new RhnErrataType();
+ List<RhnErratumType> erratum = errata.getRhnErratum();
+ List<String> erratumIds = (List<String>) params[1];
+ List<RhnErratumType> rhnErrata = new LinkedList<RhnErratumType>();
+ for (String eid : erratumIds) {
+ RhnErratumType ptype = new RhnErratumType();
+ ptype.setAdvisory("RHSA-2007:0540");
+ ptype.setChannels("rhel-i386-server-5 rhel-x86_64-server-5 rhel-ia64-server-5 rhel-ppc-server-5");
+ ptype.setPackages("rhn-package-410949 rhn-package-410950");
+ ptype.setRhnErratumAdvisoryName("RHSA-2007:0540");
+ ptype.setRhnErratumAdvisoryType("Security Advisory");
+ ptype.setRhnErratumDescription("test errata description");
+ ptype.setRhnErratumSynopsis("New package test");
+ erratum.add(ptype);
+
+ retval.setRhnErrata(errata);
+ }
+ return element;
+
} else {
return getRhnSatelliteType();
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnCommTest.java b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnCommTest.java
index cc38228..056b3d7 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnCommTest.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/RhnCommTest.java
@@ -35,6 +35,7 @@ import org.apache.xmlrpc.XmlRpcException;
import org.rhq.enterprise.server.plugins.rhnhosted.BaseRHNTest;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamilyType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnErratumType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFileType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFilesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
@@ -364,4 +365,32 @@ public class RhnCommTest extends BaseRHNTest {
assertTrue(success);
}
+ public void testGetErrata() throws Exception {
+ boolean success = false;
+ try {
+ RhnComm comm = getRhnComm();
+
+ List<String> errataIds = new ArrayList<String>();
+
+ errataIds.add("rhn-erratum-6183");
+ errataIds.add("rhn-erratum-6184");
+ errataIds.add("rhn-erratum-6182");
+ List<RhnErratumType> errata = comm.getErrataMetadata(SYSTEM_ID, errataIds);
+ assertTrue(errata.size() == errataIds.size());
+ for (RhnErratumType e : errata) {
+ assertFalse(StringUtils.isBlank(e.getAdvisory()));
+ assertFalse(StringUtils.isBlank(e.getChannels()));
+ assertFalse(StringUtils.isBlank(e.getPackages()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumAdvisoryName()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumAdvisoryType()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumDescription()));
+ assertFalse(StringUtils.isBlank(e.getRhnErratumSynopsis()));
+
+ }
+ success = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
}
14 years, 5 months
[rhq] Branch 'linux-config-apacheplugin' - modules/plugins
by lkrejci
modules/plugins/apache/pom.xml | 6
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheDirectoryComponent.java | 73 +++++
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheFilesComponent.java | 74 +++++
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheLocationComponent.java | 74 +++++
modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java | 15 +
modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml | 134 +++++++++-
6 files changed, 373 insertions(+), 3 deletions(-)
New commits:
commit 8f4d6d32e8c793c7093a15c4116e388e3d758eec
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Mon Nov 30 20:37:52 2009 +0100
More work on apache res conf, future components stubs...
diff --git a/modules/plugins/apache/pom.xml b/modules/plugins/apache/pom.xml
index 2ed59c1..dec0090 100644
--- a/modules/plugins/apache/pom.xml
+++ b/modules/plugins/apache/pom.xml
@@ -32,6 +32,12 @@
<version>1.8.2</version>
</dependency>
+ <dependency>
+ <groupId>${rhq.groupId}</groupId>
+ <artifactId>rhq-platform-plugin</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheDirectoryComponent.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheDirectoryComponent.java
new file mode 100644
index 0000000..ea21527
--- /dev/null
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheDirectoryComponent.java
@@ -0,0 +1,73 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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.plugins.apache;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.plugins.platform.PlatformComponent;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class ApacheDirectoryComponent implements ResourceComponent<ApacheServerComponent>, ConfigurationFacet {
+
+ ResourceContext<ApacheServerComponent> resourceContext;
+
+ public void start(ResourceContext<ApacheServerComponent> context) throws InvalidPluginConfigurationException, Exception {
+ // TODO Auto-generated method stub
+ resourceContext = context;
+ }
+
+ public void stop() {
+ // TODO Auto-generated method stub
+ }
+
+ public AvailabilityType getAvailability() {
+ //TODO implement this
+ return AvailabilityType.UP;
+ }
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.configuration.ConfigurationFacet#loadResourceConfiguration()
+ */
+ public Configuration loadResourceConfiguration() throws Exception {
+ // TODO Auto-generated method stub
+ return resourceContext.getResourceType().getResourceConfigurationDefinition().getDefaultTemplate().createConfiguration();
+ }
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.configuration.ConfigurationFacet#updateResourceConfiguration(org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport)
+ */
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ // TODO Auto-generated method stub
+ }
+
+}
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheFilesComponent.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheFilesComponent.java
new file mode 100644
index 0000000..e0be3ee
--- /dev/null
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheFilesComponent.java
@@ -0,0 +1,74 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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.plugins.apache;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.plugins.platform.PlatformComponent;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class ApacheFilesComponent implements ResourceComponent<ApacheServerComponent>, ConfigurationFacet {
+
+ ResourceContext<ApacheServerComponent> resourceContext;
+
+ public void start(ResourceContext<ApacheServerComponent> context) throws InvalidPluginConfigurationException, Exception {
+ // TODO Auto-generated method stub
+ resourceContext = context;
+ }
+
+ public void stop() {
+ // TODO Auto-generated method stub
+ }
+
+ public AvailabilityType getAvailability() {
+ //TODO implement this
+ return AvailabilityType.UP;
+ }
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.configuration.ConfigurationFacet#loadResourceConfiguration()
+ */
+ public Configuration loadResourceConfiguration() throws Exception {
+ // TODO Auto-generated method stub
+ return resourceContext.getResourceType().getResourceConfigurationDefinition().getDefaultTemplate().createConfiguration();
+ }
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.configuration.ConfigurationFacet#updateResourceConfiguration(org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport)
+ */
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ // TODO Auto-generated method stub
+ }
+
+
+}
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheLocationComponent.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheLocationComponent.java
new file mode 100644
index 0000000..9df9d98
--- /dev/null
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheLocationComponent.java
@@ -0,0 +1,74 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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.plugins.apache;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.plugins.platform.PlatformComponent;
+
+/**
+ *
+ *
+ * @author Lukas Krejci
+ */
+public class ApacheLocationComponent implements ResourceComponent<ApacheServerComponent>, ConfigurationFacet {
+
+ ResourceContext<ApacheServerComponent> resourceContext;
+
+ public void start(ResourceContext<ApacheServerComponent> context) throws InvalidPluginConfigurationException, Exception {
+ // TODO Auto-generated method stub
+ resourceContext = context;
+ }
+
+ public void stop() {
+ // TODO Auto-generated method stub
+ }
+
+ public AvailabilityType getAvailability() {
+ //TODO implement this
+ return AvailabilityType.UP;
+ }
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.configuration.ConfigurationFacet#loadResourceConfiguration()
+ */
+ public Configuration loadResourceConfiguration() throws Exception {
+ // TODO Auto-generated method stub
+ return resourceContext.getResourceType().getResourceConfigurationDefinition().getDefaultTemplate().createConfiguration();
+ }
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.configuration.ConfigurationFacet#updateResourceConfiguration(org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport)
+ */
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ // TODO Auto-generated method stub
+ }
+
+
+}
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java
index c8fe799..22a5194 100644
--- a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java
@@ -40,6 +40,8 @@ import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementDataTrait;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.event.EventContext;
import org.rhq.core.pluginapi.event.EventPoller;
import org.rhq.core.pluginapi.event.log.LogFileEventPoller;
@@ -53,6 +55,7 @@ import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.system.OperatingSystemType;
import org.rhq.core.system.SystemInfo;
import org.rhq.plugins.apache.util.ApacheBinaryInfo;
+import org.rhq.plugins.platform.PlatformComponent;
import org.rhq.plugins.www.snmp.SNMPClient;
import org.rhq.plugins.www.snmp.SNMPException;
import org.rhq.plugins.www.snmp.SNMPSession;
@@ -64,7 +67,7 @@ import org.rhq.plugins.www.util.WWWUtils;
*
* @author Ian Springer
*/
-public class ApacheServerComponent implements ResourceComponent, MeasurementFacet, OperationFacet {
+public class ApacheServerComponent implements ResourceComponent<PlatformComponent>, MeasurementFacet, OperationFacet, ConfigurationFacet {
private final Log log = LogFactory.getLog(this.getClass());
public static final String PLUGIN_CONFIG_PROP_SERVER_ROOT = "serverRoot";
@@ -258,6 +261,16 @@ public class ApacheServerComponent implements ResourceComponent, MeasurementFace
return this.operationsDelegate.invokeOperation(name, params);
}
+ public Configuration loadResourceConfiguration() throws Exception {
+ //TODO this is nae right of course...
+ return resourceContext.getResourceType().getResourceConfigurationDefinition().getDefaultTemplate().createConfiguration();
+ }
+
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ // TODO Auto-generated method stub
+
+ }
+
/**
* Returns an SNMP session that can be used to communicate with this server's SNMP agent.
*
diff --git a/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml
index ba3dcd2..f7e6bd4 100644
--- a/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/apache/src/main/resources/META-INF/rhq-plugin.xml
@@ -43,6 +43,7 @@
The log entry format is documented fully in the Apache documentation http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats.
</c:description>
</c:simple-property>
+ <c:simple-property name="_index" readOnly="true" required="false" description="Helper property to retain the consistent ordering inside Apache configuration files."/>
</c:map-property>
</c:list-property>
'>
@@ -151,7 +152,74 @@
</c:simple-property>
'>
+<!ENTITY Options '
+ <c:list-property name="Options" required="false">
+ <c:description>
+ The Options directive controls which server features are available in a particular directory.
+ </c:description>
+ <c:map-property name="Options">
+ <c:simple-property name="Mode">
+ <c:property-options>
+ <c:option value="Set"/>
+ <c:option value="Add"/>
+ <c:option value="Remove"/>
+ </c:property-options>
+ </c:simple-property>
+ <c:simple-property name="Option">
+ <c:property-options>
+ <c:option value="All" default="true"/>
+ <c:option value="None"/>
+ <c:option value="ExecCGI"/>
+ <c:option value="FollowSymLinks"/>
+ <c:option value="Includes"/>
+ <c:option value="IncludesNOEXEC"/>
+ <c:option value="Indexes"/>
+ <c:option value="MultiViews"/>
+ <c:option value="SymLinksIfOwnerMatch"/>
+ </c:property-options>
+ </c:simple-property>
+ <c:simple-property name="_index" readOnly="true" required="false" description="Helper property to retain the consistent ordering inside Apache configuration files."/>
+ </c:map-property>
+ </c:list-property>
+'>
+
+<!ENTITY Order '
+ <c:simple-property name="Order" required="false">
+ <c:description>
+ The Order directive, along with the Allow and Deny directives, controls a three-pass access control system. The first pass processes either all Allow or all Deny directives, as specified by the Order directive. The second pass parses the rest of the directives (Deny or Allow). The third pass applies to all requests which do not match either of the first two.
+ </c:description>
+ <c:property-options>
+ <c:option value="Allow,Deny"/>
+ <c:option value="Deny,Allow"/>
+ </c:property-options>
+ </c:simple-property>
+'>
+
+<!ENTITY Allow '
+ <c:list-property name="Allow" required="false">
+ <c:description>
+ The Allow directive affects which hosts can access an area of the server. Access can be controlled by hostname, IP address, IP address range.
+ The environment variables settings are not supported in the user interface.
+ </c:description>
+ <c:map-property name="Allow">
+ <c:simple-property name="host"/>
+ </c:map-property>
+ </c:list-property>
+'>
+
+<!ENTITY Deny '
+ <c:list-property name="Deny" required="false">
+ <c:description>
+ The arguments for the Deny directive are identical to the arguments for the Allow directive.
+ </c:description>
+ <c:map-property name="Deny">
+ <c:simple-property name="host"/>
+ </c:map-property>
+ </c:list-property>
+'>
+
]>
+
<plugin name="Apache"
displayName="Apache HTTP Server"
description="Management of Apache web servers"
@@ -354,15 +422,17 @@
Note that the IP address of a name-based virtual host must exactly match the value of this property.
</c:description>
</c:simple-property>
+ &Options;
&UseCanonicalName;
- &UseCanonicalPhysicalPort;
+ &UseCanonicalPhysicalPort;
<c:group name="Logging">
&ErrorLog;
&CustomLogs;
</c:group>
+
</resource-configuration>
- <service name="Apache Virtual Host" discovery="ApacheVirtualHostServiceDiscoveryComponent" class="ApacheVirtualHostServiceComponent">
+ <service name="Apache Virtual Host" discovery="ApacheVirtualHostServiceDiscoveryComponent" class="ApacheVirtualHostServiceComponent" createDeletePolicy="both">
<plugin-configuration>
<c:simple-property name="url" displayName="URL"
@@ -559,9 +629,69 @@
&ErrorDocuments;
&ErrorLog;
&Timeout;
+ &Options;
&UseCanonicalName;
&UseCanonicalPhysicalPort;
</resource-configuration>
+
+ <service name="Directory" class="ApacheDirectoryComponent" createDeletePolicy="both">
+ <resource-configuration>
+ <c:simple-property name="path" />
+ <c:simple-property name="regularExpression" type="boolean" default="false"/>
+ &Order;
+ &Allow;
+ &Deny;
+ <c:map-property name="AllowOverride" required="false">
+ <c:description>
+ When the server finds an .htaccess file (as specified by AccessFileName) it needs to know which directives declared in that file can override earlier configuration directives.
+ </c:description>
+ <c:simple-property name="All" type="boolean" default="true" description="Any directive which has the .htaccess Context is allowed in .htaccess files" />
+ <c:simple-property name="None" type="boolean" description=".htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem."/>
+ <c:simple-property name="AuthConfig" type="boolean" description="Allow use of the authorization directives (AuthDBMGroupFile, AuthDBMUserFile, AuthGroupFile, AuthName, AuthType, AuthUserFile, Require, etc.)."/>
+ <c:simple-property name="FileInfo" type="boolean" description="Allow use of the directives controlling document types (DefaultType, ErrorDocument, ForceType, LanguagePriority, SetHandler, SetInputFilter, SetOutputFilter, and mod_mime Add* and Remove* directives, etc.), document meta data (Header, RequestHeader, SetEnvIf, SetEnvIfNoCase, BrowserMatch, CookieExpires, CookieDomain, CookieStyle, CookieTracking, CookieName), mod_rewrite directives RewriteEngine, RewriteOptions, RewriteBase, RewriteCond, RewriteRule) and Action from mod_actions."/>
+ <c:simple-property name="Indexes" type="boolean" description="Allow use of the directives controlling directory indexing (AddDescription, AddIcon, AddIconByEncoding, AddIconByType, DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName, IndexIgnore, IndexOptions, ReadmeName, etc.)."/>
+ <c:simple-property name="Limit" type="boolean" description="Allow use of the directives controlling host access (Allow, Deny and Order)."/>
+ <c:simple-property name="Options" type="boolean" description="Allow use of the directives controlling specific directory features (Options and XBitHack)."/>
+ </c:map-property>
+ &AddDefaultCharset;
+ &DefaultType;
+ &DirectoryIndex;
+ &ErrorDocuments;
+ &Options;
+ &UseCanonicalName;
+ &UseCanonicalPhysicalPort;
+ </resource-configuration>
+ </service>
+
+ <service name="Files" class="ApacheFilesComponent" createDeletePolicy="both">
+ <resource-configuration>
+ &Order;
+ &Allow;
+ &Deny;
+ &AddDefaultCharset;
+ &DefaultType;
+ &DirectoryIndex;
+ &ErrorDocuments;
+ &Options;
+ &UseCanonicalName;
+ &UseCanonicalPhysicalPort;
+ </resource-configuration>
+ </service>
+
+ <service name="Location" class="ApacheLocationComponent" createDeletePolicy="both">
+ <resource-configuration>
+ &Order;
+ &Allow;
+ &Deny;
+ &AddDefaultCharset;
+ &DefaultType;
+ &DirectoryIndex;
+ &ErrorDocuments;
+ &Options;
+ &UseCanonicalName;
+ &UseCanonicalPhysicalPort;
+ </resource-configuration>
+ </service>
</service>
<service name="Mod JK" description="Management of mod_jk"
14 years, 5 months
[rhq] Branch 'pc' - modules/enterprise
by jharris
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java | 40 +++++++---
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml | 15 ++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java | 4 -
3 files changed, 41 insertions(+), 18 deletions(-)
New commits:
commit 51c19a88267f01650244ee46e85f5b52bd9020f0
Author: Justin Harris <jharris(a)redhat.com>
Date: Mon Nov 30 13:44:45 2009 -0500
Adding the ability to edit server plugin configs and tweaking the display in the plugin tree.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java
index 2e7b96b..675dd9e 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java
@@ -21,9 +21,11 @@ package org.rhq.enterprise.gui.admin.plugin;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
+import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;
import org.rhq.core.clientapi.agent.metadata.ConfigurationMetadataParser;
import org.rhq.core.domain.auth.Subject;
@@ -44,24 +46,22 @@ import org.richfaces.event.NodeSelectedEvent;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;
+(a)Scope(ScopeType.PAGE)
@Name("pluginConfigUIBean")
public class PluginConfigurationUIBean {
@Logger
private Log log;
-
private final ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
-
private TreeNode root;
private ServerPlugin currentPlugin;
private ConfigurationDefinition pluginConfigurationDefinition;
private ConfigurationDefinition scheduledJobsDefinition;
-
public TreeNode getRoot() {
return root;
}
-
+
public ServerPlugin getCurrentPlugin() {
return currentPlugin;
}
@@ -74,6 +74,12 @@ public class PluginConfigurationUIBean {
return this.scheduledJobsDefinition;
}
+ public boolean isEditable() {
+ return this.currentPlugin != null && (
+ this.currentPlugin.getPluginConfiguration() != null ||
+ this.currentPlugin.getScheduledJobsConfiguration() != null);
+ }
+
@Create
public void createTree() {
hasPermission();
@@ -109,16 +115,14 @@ public class PluginConfigurationUIBean {
private TreeNode createPluginNode(PluginKey pluginKey) {
TreeNode pluginNode = new TreeNodeImpl();
- pluginNode.setData(pluginKey);
+ pluginNode.setData(serverPluginsBean.getServerPlugin(pluginKey));
return pluginNode;
}
public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getSource();
- PluginKey pluginKey = (PluginKey) tree.getRowData();
-
- this.currentPlugin = serverPluginsBean.getServerPlugin(pluginKey);
+ this.currentPlugin = (ServerPlugin) tree.getRowData();
this.currentPlugin = serverPluginsBean.getServerPluginRelationships(currentPlugin);
lookupConfigDefinitions();
@@ -127,7 +131,7 @@ public class PluginConfigurationUIBean {
public void lookupConfigDefinitions() {
if (this.currentPlugin.getDeployment() == PluginDeploymentType.SERVER) {
PluginKey pluginKey = new PluginKey(this.currentPlugin);
-
+
try {
ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginKey);
this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginKey.getPluginName(), descriptor.getPluginConfiguration());
@@ -140,6 +144,19 @@ public class PluginConfigurationUIBean {
}
}
+ public void updatePlugin() {
+ try {
+ ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ serverPlugins.updateServerPluginExceptContent(subject, this.currentPlugin);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration settings saved.");
+ } catch (Exception e) {
+ log.error("Error updating the plugin configurations.", e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
+ "There was an error changing the configuration settings.", e);
+ }
+ }
+
// TODO: Find a more centralized way to do this - maybe via annotation
// on the class??
/**
@@ -148,8 +165,7 @@ public class PluginConfigurationUIBean {
private void hasPermission() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
if (!LookupUtil.getAuthorizationManager().hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)) {
- throw new PermissionException("User [" + subject.getName()
- + "] does not have the proper permissions to view or manage plugins");
+ throw new PermissionException("User [" + subject.getName() + "] does not have the proper permissions to view or manage plugins");
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml
index 8172e02..49425e4 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml
@@ -61,7 +61,7 @@
<h:outputText value="#{item}s" />
</rich:treeNode>
<rich:treeNode type="plugin">
- <h:outputText value="#{item.pluginName}" />
+ <h:outputText value="#{item.displayName}" />
</rich:treeNode>
</rich:tree>
</rich:panel>
@@ -72,8 +72,7 @@
<h:outputText value="Plugin Configuration"/>
</f:facet>
<onc:config configurationDefinition="#{pluginConfigUIBean.pluginConfigurationDefinition}"
- configuration="#{pluginConfigUIBean.currentPlugin.pluginConfiguration}"
- readOnly="true" />
+ configuration="#{pluginConfigUIBean.currentPlugin.pluginConfiguration}" />
</rich:panel>
<rich:panel rendered="#{pluginConfigUIBean.currentPlugin.scheduledJobsConfiguration != null}">
@@ -81,9 +80,15 @@
<h:outputText value="Scheduled Jobs"/>
</f:facet>
<onc:config configurationDefinition="#{pluginConfigUIBean.scheduledJobsDefinition}"
- configuration="#{pluginConfigUIBean.currentPlugin.scheduledJobsConfiguration}"
- readOnly="true" />
+ configuration="#{pluginConfigUIBean.currentPlugin.scheduledJobsConfiguration}" />
</rich:panel>
+
+ <h:panelGroup id="pluginButtons" rendered="#{pluginConfigUIBean.editable}">
+ <h:commandButton value="SAVE" type="submit" action="#{pluginConfigUIBean.updatePlugin}"
+ alt="Click to Save Changes" styleClass="buttonmed" />
+ <h:commandButton value="RESET" type="reset" immediate="true"
+ title="Click to Reset Fields" styleClass="buttonmed"/>
+ </h:panelGroup>
</h:panelGroup>
</h:panelGrid>
</h:form>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java
index 3e6bb34..730e60e 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java
@@ -18,6 +18,7 @@
*/
package org.rhq.enterprise.server.plugin.pc;
+import org.rhq.core.domain.util.StringUtils;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -83,7 +84,8 @@ public class ServerPluginType {
@Override
public String toString() {
- return this.descriptorType.getSimpleName().replace("DescriptorType", "");
+ String typeName = this.descriptorType.getSimpleName().replace("DescriptorType", "");
+ return StringUtils.deCamelCase(typeName);
}
@Override
14 years, 5 months
[rhq] Branch 'pc' - modules/enterprise
by jharris
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java | 155 ++++++++++
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml | 94 ++++++
2 files changed, 249 insertions(+)
New commits:
commit 9aa21f67a40a33b54728a6db880625ac27c7811f
Author: Justin Harris <jharris(a)redhat.com>
Date: Mon Nov 30 11:51:26 2009 -0500
Adding in first cut at the server plugin config UI.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java
new file mode 100644
index 0000000..2e7b96b
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java
@@ -0,0 +1,155 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.admin.plugin;
+
+import java.util.List;
+import java.util.Map;
+import javax.faces.application.FacesMessage;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.log.Log;
+import org.rhq.core.clientapi.agent.metadata.ConfigurationMetadataParser;
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.gui.util.FacesContextUtility;
+import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
+import org.rhq.enterprise.server.authz.PermissionException;
+import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
+import org.rhq.enterprise.server.util.LookupUtil;
+import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
+import org.richfaces.component.html.HtmlTree;
+import org.richfaces.event.NodeSelectedEvent;
+import org.richfaces.model.TreeNode;
+import org.richfaces.model.TreeNodeImpl;
+
+@Name("pluginConfigUIBean")
+public class PluginConfigurationUIBean {
+
+ @Logger
+ private Log log;
+
+ private final ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
+
+ private TreeNode root;
+ private ServerPlugin currentPlugin;
+ private ConfigurationDefinition pluginConfigurationDefinition;
+ private ConfigurationDefinition scheduledJobsDefinition;
+
+
+ public TreeNode getRoot() {
+ return root;
+ }
+
+ public ServerPlugin getCurrentPlugin() {
+ return currentPlugin;
+ }
+
+ public ConfigurationDefinition getPluginConfigurationDefinition() {
+ return this.pluginConfigurationDefinition;
+ }
+
+ public ConfigurationDefinition getScheduledJobsDefinition() {
+ return this.scheduledJobsDefinition;
+ }
+
+ @Create
+ public void createTree() {
+ hasPermission();
+
+ this.root = new TreeNodeImpl();
+ Map<ServerPluginType, List<PluginKey>> types = serverPluginsBean.getInstalledServerPluginsGroupedByType();
+
+ for (ServerPluginType type : types.keySet()) {
+ TreeNode typeNode = createTypeNode(type, types.get(type));
+
+ if (typeNode != null) {
+ typeNode.setParent(root);
+ root.addChild(type, typeNode);
+ }
+ }
+ }
+
+ private TreeNode createTypeNode(ServerPluginType type, List<PluginKey> plugins) {
+ TreeNode typeNode = new TreeNodeImpl();
+ typeNode.setData(type);
+
+ if (plugins != null && plugins.size() > 0) {
+ for (PluginKey pluginKey : plugins) {
+ TreeNode pluginNode = createPluginNode(pluginKey);
+ pluginNode.setParent(typeNode);
+
+ typeNode.addChild(pluginKey, pluginNode);
+ }
+ }
+
+ return typeNode;
+ }
+
+ private TreeNode createPluginNode(PluginKey pluginKey) {
+ TreeNode pluginNode = new TreeNodeImpl();
+ pluginNode.setData(pluginKey);
+
+ return pluginNode;
+ }
+
+ public void processSelection(NodeSelectedEvent event) {
+ HtmlTree tree = (HtmlTree) event.getSource();
+ PluginKey pluginKey = (PluginKey) tree.getRowData();
+
+ this.currentPlugin = serverPluginsBean.getServerPlugin(pluginKey);
+ this.currentPlugin = serverPluginsBean.getServerPluginRelationships(currentPlugin);
+
+ lookupConfigDefinitions();
+ }
+
+ public void lookupConfigDefinitions() {
+ if (this.currentPlugin.getDeployment() == PluginDeploymentType.SERVER) {
+ PluginKey pluginKey = new PluginKey(this.currentPlugin);
+
+ try {
+ ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginKey);
+ this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginKey.getPluginName(), descriptor.getPluginConfiguration());
+ this.scheduledJobsDefinition = ConfigurationMetadataParser.parse("jobs:" + pluginKey.getPluginName(), descriptor.getScheduledJobs());
+ } catch (Exception e) {
+ String err = "Cannot determine what the plugin configuration or scheduled jobs configuration looks like";
+ log.error(err + " - Cause: " + e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, err, e);
+ }
+ }
+ }
+
+ // TODO: Find a more centralized way to do this - maybe via annotation
+ // on the class??
+ /**
+ * Throws a permission exception if the user is not allowed to access this functionality.
+ */
+ private void hasPermission() {
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ if (!LookupUtil.getAuthorizationManager().hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)) {
+ throw new PermissionException("User [" + subject.getName()
+ + "] does not have the proper permissions to view or manage plugins");
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml
new file mode 100644
index 0000000..8172e02
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:c="http://java.sun.com/jstl/core"
+ xmlns:onc="http://jboss.org/on/component"
+ xmlns:rich="http://richfaces.ajax4jsf.org/rich">
+
+<ui:composition template="/rhq/layout/main.xhtml">
+ <ui:param name="pageTitle" value="Server Plugins Configuration"/>
+
+ <ui:define name="metaHeaders">
+ <style>
+ .col1 {
+ width: 20%;
+ vertical-align: top;
+ }
+
+ .col2 {
+ width: 80%;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="breadcrumbs">
+ <h:outputLink value="plugin-config.xhtml" >Plugin Configuration</h:outputLink>
+ </ui:define>
+
+ <ui:define name="body">
+ <br/>
+ <h:messages showSummary="true"
+ showDetail="true"
+ infoClass="InfoBlock"
+ warnClass="WarnBlock"
+ errorClass="ErrorBlock"
+ fatalClass="FatalBlock"
+ globalOnly="true"
+ layout="table"
+ width="100%"/>
+
+ <h:form id="pluginsConfigForm">
+ <h:panelGrid columns="2" width="100%" columnClasses="col1,col2">
+ <rich:panel>
+ <f:facet name="header">
+ <h:outputText value="Available Plugins" />
+ </f:facet>
+
+ <rich:tree nodeSelectListener="#{pluginConfigUIBean.processSelection}"
+ reRender="pluginConfig"
+ value="#{pluginConfigUIBean.root}"
+ ajaxSubmitSelection="true"
+ switchType="client"
+ toggleOnClick="true"
+ treeNodeVar="node"
+ var="item"
+ nodeFace="#{node.leaf ? 'plugin' : 'pluginType'}">
+
+ <rich:treeNode type="pluginType" disabled="true">
+ <h:outputText value="#{item}s" />
+ </rich:treeNode>
+ <rich:treeNode type="plugin">
+ <h:outputText value="#{item.pluginName}" />
+ </rich:treeNode>
+ </rich:tree>
+ </rich:panel>
+
+ <h:panelGroup id="pluginConfig">
+ <rich:panel rendered="#{pluginConfigUIBean.currentPlugin.pluginConfiguration != null}">
+ <f:facet name="header">
+ <h:outputText value="Plugin Configuration"/>
+ </f:facet>
+ <onc:config configurationDefinition="#{pluginConfigUIBean.pluginConfigurationDefinition}"
+ configuration="#{pluginConfigUIBean.currentPlugin.pluginConfiguration}"
+ readOnly="true" />
+ </rich:panel>
+
+ <rich:panel rendered="#{pluginConfigUIBean.currentPlugin.scheduledJobsConfiguration != null}">
+ <f:facet name="header">
+ <h:outputText value="Scheduled Jobs"/>
+ </f:facet>
+ <onc:config configurationDefinition="#{pluginConfigUIBean.scheduledJobsDefinition}"
+ configuration="#{pluginConfigUIBean.currentPlugin.scheduledJobsConfiguration}"
+ readOnly="true" />
+ </rich:panel>
+ </h:panelGroup>
+ </h:panelGrid>
+ </h:form>
+ </ui:define>
+
+</ui:composition>
+
+</html>
\ No newline at end of file
14 years, 5 months
[rhq] Branch 'alertPlugin' - modules/enterprise
by Heiko W. Rupp
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java | 27 +++++-----
1 file changed, 14 insertions(+), 13 deletions(-)
New commits:
commit e67beedcbfcf016cae615c4fd02d83dae2562349
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 16:30:52 2009 +0100
Use the defined alert sender
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
index 0c1a1a5..8946a8f 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
@@ -662,20 +662,21 @@ public class AlertManagerBean implements AlertManagerLocal, AlertManagerRemote {
sendAlertSnmpTrap(alert, snmpNotification);
}
- }
- AlertNotification test = new AlertNotification(alert.getAlertDefinition());
- test.setSenderName("Email");
- test.setConfiguration(new Configuration());
- Property prop = new PropertySimple("emailAddress","hwr(a)redhat.com");
- test.getConfiguration().getProperties().add(prop);
- AlertSender sender = getAlertSender(test);
- if (sender!=null) {
- try {
- SenderResult result = sender.send(alert);
- }
- catch (Throwable t) {
- log.error("Sender failed: " + t.getMessage());
+
+ // Send over the new AlertSenders
+ if (alertNotification.getSenderName()==null)
+ continue;
+
+ AlertSender sender = getAlertSender(alertNotification);
+ if (sender!=null) {
+ try {
+ SenderResult result = sender.send(alert);
+ // TODO log result
+ }
+ catch (Throwable t) {
+ log.error("Sender failed: " + t.getMessage());
+ }
}
}
14 years, 5 months
[rhq] Branch 'alertPlugin' - modules/enterprise
by Heiko W. Rupp
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml | 8 ++++++++
1 file changed, 8 insertions(+)
New commits:
commit 344cfe46e538fc771ead0a4e7c48a74d8df447d7
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 16:01:43 2009 +0100
Show the configuration
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
index f365463..dd24c0b 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
@@ -45,6 +45,7 @@
value="#{ListNotificationsUIBean.existingNotifications}"
var="notif"
width="100%"
+ columnWidth="5% 10% 85%"
headerClass="tableRowHeader"
footerClass="on-pager-footer"
onRowMouseOver="this.style.backgroundColor='#E7E7E7'"
@@ -65,6 +66,13 @@
<h:outputText value="#{notif.senderName}"/>
</rich:column>
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Configuration"/>
+ </f:facet>
+
+ <h:outputText value="#{notif.configuration.toString(true)}"/>
+ </rich:column>
<!-- TODO add configuration -->
</rich:dataTable>
14 years, 5 months
[rhq] Branch 'alertPlugin' - modules/core modules/enterprise
by Heiko W. Rupp
modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java | 2
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java | 27 +++-
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml | 8 -
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml | 29 +++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java | 57 +++++++++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java | 22 +++
6 files changed, 121 insertions(+), 24 deletions(-)
New commits:
commit a6aad438dc5aac56cbafb65464700d5901569a8e
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 15:52:48 2009 +0100
List exising notifications and be able to add new ones.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
index eec3a6c..7efa51b 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
@@ -75,7 +75,7 @@ public class AlertNotification implements Serializable {
private AlertDefinition alertDefinition;
@JoinColumn(name = "ALERT_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private Configuration configuration;
@Column(name = "ALERT_SENDER_NAME")
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
index 7e79bab..f50705a 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
@@ -18,20 +18,27 @@
*/
package org.rhq.enterprise.gui.alert;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.web.RequestParameter;
+import org.rhq.core.domain.alert.notification.AlertNotification;
+import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.alert.AlertNotificationManagerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -52,8 +59,9 @@ public class ListNotificationsUIBean {
private ConfigurationDefinition alertConfigurationDefinition;
private Configuration alertProperties;
- int ad;
+ @RequestParameter("ad")
+ private int alertDefinitionId;
public ListNotificationsUIBean() {
}
@@ -109,16 +117,17 @@ public class ListNotificationsUIBean {
}
public String mySubmitForm() {
- System.out.println("In submit Form ");
log.info("In submit Form ");
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ mgr.addAlertNotification(subject, alertDefinitionId,selectedSender,alertProperties);
return OUTCOME_SUCCESS;
}
- public int getAd() {
- return ad;
- }
-
- public void setAd(int ad) {
- this.ad = ad;
+ public Collection<AlertNotification> getExistingNotifications() {
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ List<AlertNotification> notifications = mgr.getNotificationsForAlertDefinition(subject,alertDefinitionId);
+ return notifications;
}
}
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
index d41bd31..8be8f7a 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
@@ -25,12 +25,4 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
- <!-- /rhq/resource/alert/notif -->
- <managed-bean>
- <description>Handling of alert senders</description>
- <managed-bean-name>ListNotificationsUIBean</managed-bean-name>
- <managed-bean-class>org.rhq.enterprise.gui.alert.ListNotificationsUIBean</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
-
</faces-config>
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
index e902b81..f365463 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
@@ -39,6 +39,35 @@
width="100%"/>
<p/>
+ <h:outputText>Existing notifications:</h:outputText>
+ <br/>
+ <rich:dataTable id="alertNotificationDataTable"
+ value="#{ListNotificationsUIBean.existingNotifications}"
+ var="notif"
+ width="100%"
+ headerClass="tableRowHeader"
+ footerClass="on-pager-footer"
+ onRowMouseOver="this.style.backgroundColor='#E7E7E7'"
+ onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="ID"/>
+ </f:facet>
+
+ <h:outputText value="#{notif.id}"/>
+ </rich:column>
+
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText styleClass="headerText" value="Sender"/>
+ </f:facet>
+
+ <h:outputText value="#{notif.senderName}"/>
+ </rich:column>
+
+ <!-- TODO add configuration -->
+ </rich:dataTable>
+
<h:outputText>Hello World</h:outputText>
<h:form id="listSenderForm">
<input type="hidden" name="id" value="${param.id}"/>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
index de7362e..9a0399c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
@@ -482,11 +482,6 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
}
}
- public Configuration getDefaultAlertConfiguration(ConfigurationDefinition def) {
- Configuration config = configManager.getConfigurationFromDefaultTemplate(def);
-
- return config;
- }
/**
* Return a list of all available AlertSenders in the system by their shortname.
@@ -497,4 +492,56 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc
List<String> senders = pluginmanager.getPluginList();
return senders;
}
+
+ /**
+ * Add a new AlertNotification to the passed definition
+ * @param user subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @param senderName shortName of the {@link AlertSender}
+ * @param configuration Properties for this alert sender.
+ */
+ public void addAlertNotification(Subject user, int alertDefinitionId, String senderName, Configuration configuration) {
+
+ AlertDefinition definition = alertDefinitionManager.getAlertDefinition(user,alertDefinitionId);
+ if (definition==null) {
+ LOG.error("DId not find definition for id [" + alertDefinitionId+ "]");
+ return;
+ }
+
+ entityManager.persist(configuration);
+ AlertNotification notif = new AlertNotification(definition);
+ notif.setSenderName(senderName);
+ notif.setConfiguration(configuration);
+ entityManager.persist(notif);
+ definition.getAlertNotifications().add(notif);
+
+ }
+
+ /**
+ * Return notifications for a certain alertDefinitionId
+ *
+ * NOTE: this only returns notifications that have an AlertSender defined.
+ *
+ * @param user Subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @return list of defined notification of the passed alert definition
+ *
+ *
+ */
+ public List<AlertNotification> getNotificationsForAlertDefinition(Subject user, int alertDefinitionId) {
+ AlertDefinition definition = alertDefinitionManager.getAlertDefinition(user,alertDefinitionId);
+ if (definition==null) {
+ LOG.error("DId not find definition for id [" + alertDefinitionId+ "]");
+ return new ArrayList<AlertNotification>();
+ }
+ Set<AlertNotification> notifs = definition.getAlertNotifications();
+ List<AlertNotification> result = new ArrayList<AlertNotification>();
+ for (AlertNotification notif : notifs) {
+ if (notif.getSenderName()!=null) {
+ notif.getConfiguration().getProperties().size(); // Eager load
+ result.add(notif);
+ }
+ }
+ return result;
+ }
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
index 532bd95..debec43 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
@@ -82,5 +82,25 @@ public interface AlertNotificationManagerLocal {
ConfigurationDefinition getConfigurationDefinitionForSender(String shortName);
- Configuration getDefaultAlertConfiguration(ConfigurationDefinition def);
+ /**
+ * Add a new AlertNotification to the passed definition
+ * @param user subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @param senderName shortName of the {@link AlertSender}
+ * @param configuration Properties for this alert sender.
+ */
+ void addAlertNotification(Subject user, int alertDefinitionId, String senderName, Configuration configuration);
+
+ /**
+ * Return notifications for a certain alertDefinitionId
+ *
+ * NOTE: this only returns notifications that have an AlertSender defined.
+ *
+ * @param user Subject of the caller
+ * @param alertDefinitionId Id of the alert definition
+ * @return list of defined notification of the passed alert definition
+ *
+ *
+ */
+ List<AlertNotification> getNotificationsForAlertDefinition(Subject user, int alertDefinitionId);
}
\ No newline at end of file
14 years, 5 months
[rhq] Branch 'content' - 42 commits - etc/eclipse-tools etc/samples modules/core modules/enterprise modules/helpers
by jdob
etc/eclipse-tools/templates/schema.xmlcatalog | 8
etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java | 2
modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml | 5
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 235 +--
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java | 68
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/DeepCopyable.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Property.java | 7
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java | 12
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java | 12
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertySimple.java | 30
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/RawConfiguration.java | 7
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java | 401 +++++
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java | 493 ------
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java | 153 +
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginStatusType.java | 29
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java | 293 +++
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationTest.java | 111 +
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyListTest.java | 59
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyMapTest.java | 53
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertySimpleTest.java | 16
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/RawConfigurationTest.java | 32
modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java | 145 +
modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java | 650 ++++++++
modules/core/util/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java | 9
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java | 87 +
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java | 78 -
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java | 71
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java | 2
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/components.xml | 1
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/admin-beans.xml | 7
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml | 11
modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp | 778 +++++-----
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit.xhtml | 24
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml | 28
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml | 15
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml | 13
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java | 70
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java | 353 +++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java | 117 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java | 36
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java | 34
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java | 114 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java | 12
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java | 18
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java | 16
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java | 36
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java | 382 ++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java | 17
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java | 23
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java | 4
modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java | 4
modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java | 9
modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl | 5
56 files changed, 3806 insertions(+), 1397 deletions(-)
New commits:
commit 584889fb68aed084752714e08092fe8c46f62aad
Merge: 9e72807... fa1d597...
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 30 08:52:11 2009 -0500
Merge branch 'master' into content
Conflicts:
modules/core/dbutils/pom.xml
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
diff --cc modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 2198180,c28b862..e07e42d
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@@ -2172,509 -2170,36 +2170,538 @@@
REFERENCES RHQ_CONFIG (ID)
</statement>
</schema-directSQL>
+
+ <!-- Fix bug:538157 -->
+ <schema-directSQL>
+ <statement>
+ CREATE INDEX RHQ_REPO_PKG_VER_MAP_IDX
+ ON RHQ_REPO_PKG_VERSION_MAP ( PACKAGE_VERSION_ID )
+ </statement>
+ </schema-directSQL>
</schemaSpec>
-
+
- <schemaSpec version="2.69.1">
- <!-- add the new column that indicates if this is plugin has been deleted -->
- <schema-addColumn table="RHQ_PLUGIN" column="STATUS" columnType="VARCHAR2" precision="16"/>
++ <schemaSpec version="2.69.1">
++ <!-- add the new column that indicates if this is plugin has been deleted -->
++ <schema-addColumn table="RHQ_PLUGIN" column="STATUS" columnType="VARCHAR2" precision="16"/>
++ <schema-directSQL>
++ <statement desc="Updating existing plugins with status of INSTALLED">
++ UPDATE RHQ_PLUGIN SET STATUS = 'INSTALLED'
++ </statement>
++ </schema-directSQL>
++ <schema-alterColumn table="RHQ_PLUGIN" column="STATUS" nullable="FALSE"/>
++ </schemaSpec>
++
++ <schemaSpec version="2.69.2">
++ <!-- plugin names must be unique only if they are deployed on the same side (agent vs. server) -->
++ <schema-directSQL>
++ <statement desc="Dropping unique index on RHQ_PLUGIN (NAME)">
++ DROP INDEX RHQ_PLUGIN_NAME_IDX
++ </statement>
++ <statement desc="Creating unique index on RHQ_PLUGIN (NAME, DEPLOYMENT) so server plugin names need not be unique with agent plugins">
++ CREATE UNIQUE INDEX RHQ_PLUGIN_NAME_DEPLOY_IDX ON RHQ_PLUGIN (NAME, DEPLOYMENT)
++ </statement>
++ </schema-directSQL>
++ </schemaSpec>
++
++ <schemaSpec version="2.69.3">
++ <!-- add the new column that indicates what type of plugin this is (e.g. alert, generic, content) - for server plugins only -->
++ <schema-addColumn table="RHQ_PLUGIN" column="PTYPE" columnType="VARCHAR2" precision="200"/>
++ </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>
+ <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-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-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-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-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-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 desc="Updating existing plugins with status of INSTALLED">
- UPDATE RHQ_PLUGIN SET STATUS = 'INSTALLED'
+ <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>
+ </schema-directSQL>
- <schema-alterColumn table="RHQ_PLUGIN" column="STATUS" nullable="FALSE"/>
- </schemaSpec>
- <schemaSpec version="2.69.2">
- <!-- plugin names must be unique only if they are deployed on the same side (agent vs. server) -->
<schema-directSQL>
- <statement desc="Dropping unique index on RHQ_PLUGIN (NAME)">
- DROP INDEX RHQ_PLUGIN_NAME_IDX
+ <statement targetDBVendor="postgresql">
+ CREATE INDEX RHQ_ADVISORY_UDATE_IDX
+ ON RHQ_ADVISORY (UPDATE_DATE )
</statement>
- <statement desc="Creating unique index on RHQ_PLUGIN (NAME, DEPLOYMENT) so server plugin names need not be unique with agent plugins">
- CREATE UNIQUE INDEX RHQ_PLUGIN_NAME_DEPLOY_IDX ON RHQ_PLUGIN (NAME, DEPLOYMENT)
+ <statement targetDBVendor="oracle">
+ CREATE INDEX RHQ_ADVISORY_UDATE_IDX
+ ON RHQ_ADVISORY (UPDATE_DATE )
</statement>
</schema-directSQL>
- </schemaSpec>
+ <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>
+ <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>
+ <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-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-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>
++ </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>
++ </statement>
+ </schema-directSQL>
- <schema-createSequence name="RHQ_CVE_SEQ" initial="101" />
++ <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-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-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>
++ </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-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-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-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-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>
++ </statement>
+ </schema-directSQL>
- </schemaSpec>
++ </schemaSpec>
- <schemaSpec version="2.69.3">
- <!-- add the new column that indicates what type of plugin this is (e.g. alert, generic, content) - for server plugins only -->
- <schema-addColumn table="RHQ_PLUGIN" column="PTYPE" columnType="VARCHAR2" precision="200"/>
+ <!-- Adding repo_sync support -->
+ <schemaSpec version="2.72">
+ <schema-createSequence name="RHQ_REPO_SYNC_ID_SEQ" initial="10001" />
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_REPO_SYNC ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_REPO_SYNC" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="STATUS" precision="16" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_REPO_SYNC" column="STATUS" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="START_TIME" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_REPO_SYNC" column="START_TIME" nullable="false" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="END_TIME" columnType="INTEGER" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="RESULTS" columnType="LONGVARCHAR" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="PERCENT_COMPLETE" columnType="LONG" />
+ <schema-addColumn table="RHQ_REPO_SYNC" column="REPO_ID" columnType="INTEGER" />
+ <schema-alterColumn table="RHQ_REPO_SYNC" column="REPO_ID" nullable="false" />
+ <schema-directSQL>
+ <statement desc="Creating RHQ_REPO_SYNC foreign key relation to RHQ_REPO for scheduled jobs">
+ ALTER TABLE RHQ_REPO_SYNC
+ ADD CONSTRAINT RHQ_REPO_SYNC_REPO_ID_FKEY
+ FOREIGN KEY (REPO_ID)
+ REFERENCES RHQ_REPO (ID)
+ </statement>
+ </schema-directSQL>
</schemaSpec>
-
+
</dbupgrade>
</target>
</project>
commit fa1d59755426ed42ac85b2a36a874dc12aeeed75
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 12:05:47 2009 -0500
opps... forgot to fix the control.jsp to call the new API
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
index 2c47b0a..25f3e25 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
@@ -24,7 +24,9 @@
<%@ page import="org.rhq.enterprise.server.system.SystemManagerLocal" %>
<%@ page import="org.rhq.enterprise.server.auth.SubjectManagerLocal" %>
<%@ page import="org.rhq.enterprise.server.support.SupportManagerLocal" %>
-<%@page import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%><html>
+<%@page import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%>
+<%@page import="org.rhq.core.domain.plugin.PluginKey"%>
+<%@page import="org.rhq.core.domain.plugin.PluginDeploymentType"%><html>
<%@ page import="org.rhq.enterprise.server.util.LookupUtil" %>
<%@ page import="org.rhq.enterprise.server.scheduler.jobs.DataPurgeJob"%>
@@ -203,7 +205,8 @@
else if ("purgeServerPlugin".equals(mode))
{
String serverPluginName = request.getParameter("serverPluginName");
- serverPlugins.purgeServerPlugin(subjectManager.getOverlord(), serverPluginName);
+ PluginKey key = new PluginKey(PluginDeploymentType.SERVER, "not-needed", serverPluginName);
+ serverPlugins.purgeServerPlugin(subjectManager.getOverlord(), key);
result = "OK - you can now try to re-register a plugin with the name [" + serverPluginName + "]";
}
else if ("typeManagerRemote".equals(mode))
commit 46b2dc39e618652087bbd0c3b6b8f4cddefb4df2
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 11:19:32 2009 -0500
use != to check for deployment type inequality
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
index 0d28937..5240a65 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
@@ -145,7 +145,7 @@ public class PluginKey {
return false;
}
- if (!deployment.equals(other.deployment)) {
+ if (deployment != other.deployment) {
return false;
}
return true;
commit 2838e6492a4db53a5cb066d599d7176f86138303
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 11:04:56 2009 -0500
plugin configs are now only valid for server plugins. do the check on the UI bean def, since that will be null for agent plugins
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
index cc11203..5e32efa 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
@@ -75,7 +75,7 @@
<ui:insert name="pre-config" />
- <rich:panel rendered="#{InstalledPluginUIBean.plugin.pluginConfiguration != null}">
+ <rich:panel rendered="#{InstalledPluginUIBean.pluginConfigurationDefinition != null}">
<f:facet name="header">
<h:outputText value="Plugin Configuration"/>
</f:facet>
@@ -85,7 +85,7 @@
readOnly="#{not editMode}" />
</rich:panel>
- <rich:panel rendered="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration != null}">
+ <rich:panel rendered="#{InstalledPluginUIBean.scheduledJobsDefinition != null}">
<f:facet name="header">
<h:outputText value="Scheduled Jobs"/>
</f:facet>
commit d2e2d1e98759c5fb5d2fd678c3d01b829e315270
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 02:17:25 2009 -0500
first attempt to see what this looks like if i use plugin key vs. just plugin name in API
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 8f466be..83fa2a2 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.1</db.schema.version>
+ <db.schema.version>2.69.3</db.schema.version>
</properties>
<dependencies>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
index dbc4a19..1d111cf 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
@@ -19,12 +19,14 @@
<column name="CTIME" type="LONG" required="true"/>
<column name="MTIME" type="LONG" required="true"/>
<column name="DEPLOYMENT" size="8" type="VARCHAR2" required="true"/>
+ <column name="PTYPE" size="200" type="VARCHAR2" required="false"/>
<column name="PLUGIN_CONFIG_ID" type="INTEGER" references="RHQ_CONFIG" required="false"/>
<column name="JOBS_CONFIG_ID" type="INTEGER" references="RHQ_CONFIG" required="false"/>
<column name="CONTENT" type="BLOB" required="false"/>
- <index name="RHQ_PLUGIN_NAME_IDX" unique="true">
+ <index name="RHQ_PLUGIN_NAME_DEPLOY_IDX" unique="true">
<field ref="NAME"/>
+ <field ref="DEPLOYMENT"/>
</index>
</table>
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 07831eb..c28b862 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2183,6 +2183,23 @@
<schema-alterColumn table="RHQ_PLUGIN" column="STATUS" nullable="FALSE"/>
</schemaSpec>
+ <schemaSpec version="2.69.2">
+ <!-- plugin names must be unique only if they are deployed on the same side (agent vs. server) -->
+ <schema-directSQL>
+ <statement desc="Dropping unique index on RHQ_PLUGIN (NAME)">
+ DROP INDEX RHQ_PLUGIN_NAME_IDX
+ </statement>
+ <statement desc="Creating unique index on RHQ_PLUGIN (NAME, DEPLOYMENT) so server plugin names need not be unique with agent plugins">
+ CREATE UNIQUE INDEX RHQ_PLUGIN_NAME_DEPLOY_IDX ON RHQ_PLUGIN (NAME, DEPLOYMENT)
+ </statement>
+ </schema-directSQL>
+ </schemaSpec>
+
+ <schemaSpec version="2.69.3">
+ <!-- add the new column that indicates what type of plugin this is (e.g. alert, generic, content) - for server plugins only -->
+ <schema-addColumn table="RHQ_PLUGIN" column="PTYPE" columnType="VARCHAR2" precision="200"/>
+ </schemaSpec>
+
</dbupgrade>
</target>
</project>
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
index 4f7809d..0d28937 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
@@ -33,13 +33,13 @@ public class PluginKey {
* Creates a plugin key that identifies an agent plugin. There is only
* one plugin container that runs in the agent, thus there is only
* one "type" of an agent plugin. Therefore, {@link #getPluginType()} on the
- * returned object will return an empty string to signify this.
+ * returned object will return <code>null</code> to signify this.
*
* @param pluginName the name of the plugin
* @return the plugin key for the agent plugin
*/
public static PluginKey createAgentPluginKey(String pluginName) {
- return new PluginKey(PluginDeploymentType.AGENT, "", pluginName);
+ return new PluginKey(PluginDeploymentType.AGENT, null, pluginName);
}
/**
@@ -58,12 +58,33 @@ public class PluginKey {
return new PluginKey(PluginDeploymentType.SERVER, pluginType, pluginName);
}
+ /**
+ * Create a plugin key that identifies the given agent plugin.
+ *
+ * @param plugin agent plugin
+ */
+ public PluginKey(Plugin plugin) {
+ this(plugin.getDeployment(), null, plugin.getName());
+ }
+
+ /**
+ * Create a plugin key that identifies the given server plugin.
+ *
+ * @param plugin server plugin
+ */
+ public PluginKey(ServerPlugin plugin) {
+ this(plugin.getDeployment(), plugin.getType(), plugin.getName());
+ }
+
public PluginKey(PluginDeploymentType deployment, String pluginType, String pluginName) {
if (deployment == null) {
throw new IllegalArgumentException("deployment==null");
}
- if (pluginType == null) {
- throw new IllegalArgumentException("pluginType==null");
+ if (pluginType == null && deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("only agent plugins can have null type");
+ }
+ if (pluginType != null && deployment == PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("agent plugins must have null type");
}
if (pluginName == null || pluginName.length() == 0) {
throw new IllegalArgumentException("invalid pluginName: " + pluginName);
@@ -99,7 +120,7 @@ public class PluginKey {
final int prime = 31;
int result = 1;
result = prime * result + deployment.hashCode();
- result = prime * result + pluginType.hashCode();
+ result = prime * result + ((pluginType == null) ? 0 : pluginType.hashCode());
result = prime * result + pluginName.hashCode();
return result;
}
@@ -116,8 +137,13 @@ public class PluginKey {
if (!pluginName.equals(other.pluginName)) {
return false;
}
- if (!pluginType.equals(other.pluginType)) {
+ if (pluginType == null) {
+ if (other.pluginType != null) {
+ return false;
+ }
+ } else if (!pluginType.equals(other.pluginType)) {
return false;
+
}
if (!deployment.equals(other.deployment)) {
return false;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
index d233365..aa06ea9 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -23,6 +23,7 @@
package org.rhq.core.domain.plugin;
import javax.persistence.CascadeType;
+import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -50,7 +51,10 @@ import org.rhq.core.domain.configuration.Configuration;
// helps you determine which installed plugins are enabled or disabled
@NamedQuery(name = ServerPlugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
- + " SELECT p.name " //
+ + " SELECT new org.rhq.core.domain.plugin.PluginKey( " //
+ + " p.deployment, " //
+ + " p.type, " //
+ + " p.name) " //
+ " FROM ServerPlugin AS p " //
+ " WHERE p.enabled = :enabled " //
+ " AND p.status = 'INSTALLED' "), //
@@ -71,6 +75,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -95,6 +100,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -120,6 +126,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -144,6 +151,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -178,6 +186,9 @@ public class ServerPlugin extends AbstractPlugin {
@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private Configuration pluginConfiguration;
+ @Column(name = "PTYPE")
+ private String type;
+
public ServerPlugin() {
super();
setDeployment(PluginDeploymentType.SERVER);
@@ -200,12 +211,13 @@ public class ServerPlugin extends AbstractPlugin {
public ServerPlugin(int id, String name, String path, String displayName, boolean enabled, PluginStatusType status,
String description, String help, String md5, String version, String ampsVersion, Configuration pluginConfig,
- Configuration scheduledJobsConfig, long ctime, long mtime) {
+ Configuration scheduledJobsConfig, String type, long ctime, long mtime) {
super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
PluginDeploymentType.SERVER, ctime, mtime);
this.pluginConfiguration = pluginConfig;
this.scheduledJobsConfiguration = scheduledJobsConfig;
+ this.type = type;
}
@Override
@@ -223,7 +235,7 @@ public class ServerPlugin extends AbstractPlugin {
* @return the configuration associated with the plugin itself
*/
public Configuration getPluginConfiguration() {
- return pluginConfiguration;
+ return this.pluginConfiguration;
}
public void setPluginConfiguration(Configuration pluginConfiguration) {
@@ -236,13 +248,26 @@ public class ServerPlugin extends AbstractPlugin {
* @return scheduled job configuration for jobs that the plugin defined.
*/
public Configuration getScheduledJobsConfiguration() {
- return scheduledJobsConfiguration;
+ return this.scheduledJobsConfiguration;
}
public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
this.scheduledJobsConfiguration = scheduledJobsConfiguration;
}
+ /**
+ * Plugin type string.
+ *
+ * @return plugin type
+ */
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
index 31d4188..a1400ac 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
@@ -26,6 +26,7 @@ import org.jboss.seam.annotations.web.RequestParameter;
import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -41,8 +42,10 @@ public class InstalledPluginComponent {
@RequestParameter("plugin")
private String name;
+ @RequestParameter("deployment")
+ private PluginDeploymentType deployment;
@RequestParameter("pluginType")
- private PluginDeploymentType type;
+ private String pluginType;
public String getName() {
return this.name;
@@ -52,21 +55,30 @@ public class InstalledPluginComponent {
this.name = name;
}
- public PluginDeploymentType getType() {
- return this.type;
+ public PluginDeploymentType getDeployment() {
+ return this.deployment;
}
- public void setType(PluginDeploymentType type) {
- this.type = type;
+ public void setType(PluginDeploymentType deployment) {
+ this.deployment = deployment;
+ }
+
+ public String getPluginType() {
+ return this.pluginType;
+ }
+
+ public void setPluginType(String pluginType) {
+ this.pluginType = pluginType;
}
@Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
public AbstractPlugin lookupPlugin() {
- if (this.type == PluginDeploymentType.AGENT) {
+ if (this.deployment == PluginDeploymentType.AGENT) {
return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
- } else if (this.type == PluginDeploymentType.SERVER) {
+ } else if (this.deployment == PluginDeploymentType.SERVER) {
+ PluginKey pluginKey = new PluginKey(this.deployment, this.pluginType, this.name);
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- ServerPlugin plugin = serverPluginsBean.getServerPlugin(this.name);
+ ServerPlugin plugin = serverPluginsBean.getServerPlugin(pluginKey);
return serverPluginsBean.getServerPluginRelationships(plugin);
}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
index 2f7d73a..9351385 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
@@ -35,6 +35,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
@@ -51,7 +52,7 @@ import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
@Name("InstalledPluginUIBean")
public class InstalledPluginUIBean {
- private static final String OUTCOME_SUCCESS = "success";
+ private static final String OUTCOME_SUCCESS_SERVER_PLUGIN = "successServerPlugin";
public static final String MANAGED_BEAN_NAME = InstalledPluginUIBean.class.getSimpleName();
private final Log log = LogFactory.getLog(InstalledPluginUIBean.class);
@In
@@ -67,6 +68,14 @@ public class InstalledPluginUIBean {
this.plugin = plugin;
}
+ public ServerPlugin getServerPlugin() {
+ return (ServerPlugin) this.plugin;
+ }
+
+ public void setServerPlugin(ServerPlugin plugin) {
+ this.plugin = plugin;
+ }
+
public ConfigurationDefinition getPluginConfigurationDefinition() {
return this.pluginConfigurationDefinition;
}
@@ -80,14 +89,14 @@ public class InstalledPluginUIBean {
}
public String updatePlugin() {
- ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
-
+ // note we assume we are editing a server plugin - we don't support editing agent plugins yet
try {
- serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(),
- (ServerPlugin) plugin);
+ ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ serverPlugins.updateServerPluginExceptContent(subject, getServerPlugin());
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration settings saved.");
- return OUTCOME_SUCCESS;
+ return OUTCOME_SUCCESS_SERVER_PLUGIN;
} catch (Exception e) {
log.error("Error updating the plugin configurations.", e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
@@ -105,7 +114,8 @@ public class InstalledPluginUIBean {
if (this.plugin.getDeployment() == PluginDeploymentType.SERVER) {
try {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginName);
+ PluginKey pluginKey = new PluginKey((ServerPlugin) plugin);
+ ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginKey);
this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginName, descriptor
.getPluginConfiguration());
this.scheduledJobsDefinition = ConfigurationMetadataParser.parse("jobs:" + pluginName, descriptor
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
index 7f19f4d..37b3bad 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
@@ -33,8 +33,8 @@
<from-view-id>/rhq/admin/plugin/plugin-details-edit.xhtml</from-view-id>
<navigation-case>
- <from-outcome>success</from-outcome>
- <to-view-id>/rhq/admin/plugin/plugin-details-view.xhtml?plugin=#{plugin.name}&pluginType=#{plugin.deployment}</to-view-id>
+ <from-outcome>successServerPlugin</from-outcome>
+ <to-view-id>/rhq/admin/plugin/plugin-details-view.xhtml?plugin=#{plugin.name}&deployment=#{plugin.deployment}&pluginType=#{serverPlugin.type}</to-view-id>
<redirect/>
</navigation-case>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
index 389923a..92d36f3 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
@@ -17,7 +17,8 @@
<h:outputLink value="/rhq/admin/plugin/plugin-details-edit.xhtml"
styleClass="buttonmed">
<f:param name="plugin" value="#{installedPlugin.name}"/>
- <f:param name="pluginType" value="#{installedPlugin.type}"/>
+ <f:param name="deployment" value="#{installedPlugin.deployment}"/>
+ <f:param name="pluginType" value="#{installedPlugin.pluginType}"/>
<h:outputText value="EDIT"/>
</h:outputLink>
</h:panelGrid>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
index 5654368..ba128c1 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
@@ -77,7 +77,7 @@
<h:outputLink value="/rhq/admin/plugin/plugin-details-view.xhtml">
<f:param name="plugin" value="#{agentPlugin.name}"/>
- <f:param name="pluginType" value="AGENT"/>
+ <f:param name="deployment" value="AGENT"/>
<h:outputText value="#{agentPlugin.displayName}"/>
</h:outputLink>
@@ -162,7 +162,8 @@
<h:outputLink value="/rhq/admin/plugin/plugin-details-view.xhtml">
<f:param name="plugin" value="#{serverPlugin.name}"/>
- <f:param name="pluginType" value="SERVER"/>
+ <f:param name="deployment" value="SERVER"/>
+ <f:param name="pluginType" value="#{serverPlugin.type}"/>
<h:outputText value="#{serverPlugin.displayName}"/>
</h:outputLink>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index de8857b..853ce9c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
@@ -51,7 +51,7 @@ import org.rhq.core.db.PostgresqlDatabaseType;
import org.rhq.core.db.SQLServerDatabaseType;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.MessageDigestGenerator;
@@ -59,6 +59,7 @@ import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil;
@@ -160,7 +161,6 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "], version " + version);
ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
- plugin.setDeployment(PluginDeploymentType.SERVER);
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
plugin.setDescription(descriptor.getDescription());
@@ -170,6 +170,7 @@ public class ServerPluginScanner {
plugin.setMD5(MessageDigestGenerator.getDigestString(pluginFile));
plugin.setPluginConfiguration(getDefaultPluginConfiguration(descriptor));
plugin.setScheduledJobsConfiguration(getDefaultScheduledJobsConfiguration(descriptor));
+ plugin.setType(new ServerPluginType(descriptor).stringify());
if (descriptor.getHelp() != null && !descriptor.getHelp().getContent().isEmpty()) {
plugin.setHelp(String.valueOf(descriptor.getHelp().getContent().get(0)));
@@ -178,7 +179,7 @@ public class ServerPluginScanner {
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
// see if this plugin has been deleted previously; if so, don't register and delete the file
- PluginStatusType status = serverPluginsManager.getServerPluginStatus(pluginName);
+ PluginStatusType status = serverPluginsManager.getServerPluginStatus(new PluginKey(plugin));
if (PluginStatusType.DELETED == status) {
log.warn("Plugin file [" + pluginFile + "] has been detected but that plugin with name [" + pluginName
+ "] was previously undeployed. Will not re-register that plugin and the file will be deleted.");
@@ -451,7 +452,6 @@ public class ServerPluginScanner {
ServerPlugin plugin = new ServerPlugin(name, path, md5);
plugin.setMtime(mtime);
plugin.setVersion(version);
- plugin.setDeployment(PluginDeploymentType.SERVER);
updatedPlugins.add(plugin);
this.serverPluginsOnFilesystem.remove(expectedFile); // paranoia, make sure the cache doesn't have this
}
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 6839cfc..b3808ab 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
@@ -132,7 +132,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
+ return query.getResultList();
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@ -171,8 +171,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- PluginKey pluginKey = ;
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
doomedPlugins.add(pluginKey);
if (master != null) {
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
@@ -215,8 +214,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- PluginKey pluginKey = ;
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
doomedPlugins.add(pluginKey);
if (master != null) {
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
@@ -307,7 +305,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPlugin existingPlugin = null;
boolean newOrUpdated = false;
try {
- existingPlugin = getServerPlugin(plugin.getName());
+ existingPlugin = getServerPlugin(new PluginKey(plugin));
} catch (NoResultException nre) {
newOrUpdated = true; // this is expected for new plugins
}
@@ -331,7 +329,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (plugin.getId() == 0) {
- PluginStatusType status = getServerPluginStatus(plugin.getName());
+ PluginStatusType status = getServerPluginStatus(new PluginKey(plugin));
if (PluginStatusType.DELETED == status) {
throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
+ "], it has been previously marked as deleted.");
@@ -401,6 +399,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
pluginEntity.setDeployment(plugin.getDeployment());
pluginEntity.setPluginConfiguration(plugin.getPluginConfiguration());
pluginEntity.setScheduledJobsConfiguration(plugin.getScheduledJobsConfiguration());
+ pluginEntity.setType(plugin.getType());
pluginEntity.setDescription(plugin.getDescription());
pluginEntity.setHelp(plugin.getHelp());
pluginEntity.setMtime(plugin.getMtime());
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index a4bd9b1..87f2575 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
@@ -311,7 +311,7 @@ public class ServerPluginManager {
protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
+ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey());
return plugin;
}
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 cd1921b..63f2e1d 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
@@ -35,11 +35,14 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
+import org.rhq.enterprise.server.xmlschema.generated.serverplugin.generic.GenericPluginDescriptorType;
/**
* @author John Mazzitelli
@@ -100,14 +103,16 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testGetPlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
ServerPlugin p2 = registerPlugin(2);
- List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
-
- ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
+ List<PluginKey> pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
+
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1key);
assert plugin.getId() == p1.getId() : plugin;
assert plugin.getName().equals(p1.getName()) : plugin;
assetLazyInitializationException(plugin);
@@ -137,7 +142,9 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testUpdatePlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
- p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
+ PluginKey p1key = new PluginKey(p1);
+
+ p1 = this.serverPluginsBean.getServerPlugin(p1key);
p1 = this.serverPluginsBean.getServerPluginRelationships(p1);
ServerPlugin p1update = this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
@@ -156,39 +163,41 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testDisableEnablePlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<String> disabled = this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
+ List<PluginKey> disabled = this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
assert disabled.size() == 2 : disabled;
- assert disabled.contains(p1.getName()) : disabled;
- assert disabled.contains(p2.getName()) : disabled;
+ assert disabled.contains(p1key) : disabled;
+ assert disabled.contains(p2key) : 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;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ assert this.serverPluginsBean.getServerPlugin(p1key).getStatus() == PluginStatusType.INSTALLED; // still installed
+ assert this.serverPluginsBean.getServerPlugin(p2key).getStatus() == PluginStatusType.INSTALLED; // still installed
+ List<PluginKey> pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
// re-enable them
this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
// make sure none of these enable/disable settings lost our config
- ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1key);
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
- plugin = this.serverPluginsBean.getServerPlugin(p2.getName());
+ plugin = this.serverPluginsBean.getServerPlugin(p2key);
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
@@ -198,63 +207,77 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
PluginStatusType status;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "1");
+ PluginKey missingKey;
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "1");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
ServerPlugin p1 = registerPlugin(1);
ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
- status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p1key);
assert status == PluginStatusType.INSTALLED;
- status = this.serverPluginsBean.getServerPluginStatus(p2.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p2key);
assert status == PluginStatusType.INSTALLED;
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<String> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
+ List<PluginKey> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
- assert undeployed.contains(p1.getName()) : undeployed;
- assert undeployed.contains(p2.getName()) : undeployed;
+ assert undeployed.contains(p1key) : undeployed;
+ assert undeployed.contains(p2key) : undeployed;
ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
ServerPlugin 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;
- assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be returned even here" + pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ List<PluginKey> pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : "deleted plugins should not be returned even here" + pluginKeys;
+ assert !pluginKeys.contains(p2key) : "deleted plugins should not be returned even here" + pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert !pluginKeys.contains(p1.getName()) : pluginKeys;
+ assert !pluginKeys.contains(p2.getName()) : pluginKeys;
}
public void testReRegisterPlugins() throws Exception {
PluginStatusType status;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "1");
+ PluginKey missingKey;
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "1");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
ServerPlugin p1 = registerPlugin(1);
ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
- status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p1key);
assert status == PluginStatusType.INSTALLED;
- status = this.serverPluginsBean.getServerPluginStatus(p2.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p2key);
assert status == PluginStatusType.INSTALLED;
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<String> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
+ List<PluginKey> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
- assert undeployed.contains(p1.getName()) : undeployed;
- assert undeployed.contains(p2.getName()) : undeployed;
+ assert undeployed.contains(p1key) : undeployed;
+ assert undeployed.contains(p2key) : undeployed;
ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p1deleted.getPluginConfiguration() == null; // undeploy should have removed this
@@ -264,16 +287,16 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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;
- assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be returned even here" + pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ List<PluginKey> pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : "deleted plugins should not be returned even here" + pluginKeys;
+ assert !pluginKeys.contains(p2key) : "deleted plugins should not be returned even here" + pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
// purge them completely from the DB to prepare to re-register them
- this.serverPluginsBean.purgeServerPlugin(getOverlord(), p1.getName());
- this.serverPluginsBean.purgeServerPlugin(getOverlord(), p2.getName());
+ this.serverPluginsBean.purgeServerPlugin(getOverlord(), p1key);
+ this.serverPluginsBean.purgeServerPlugin(getOverlord(), p2key);
// we just purged the database, make sure our entity ID's are all zero, since the original IDs are gone
p1.setId(0);
@@ -287,21 +310,21 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
ServerPlugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p1, null);
ServerPlugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p2, null);
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
assert p1again.getStatus() == PluginStatusType.INSTALLED;
assert p2again.getStatus() == PluginStatusType.INSTALLED;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
}
private ServerPlugin registerPlugin(int index) throws Exception {
ServerPlugin plugin = new ServerPlugin(0, TEST_PLUGIN_NAME_PREFIX + index, "path", "displayName", true,
PluginStatusType.INSTALLED, "description", "help", "md5", "version", "ampsVersion",
- createPluginConfiguration(), createScheduledJobsConfiguration(), System.currentTimeMillis(), System
- .currentTimeMillis());
+ createPluginConfiguration(), createScheduledJobsConfiguration(), new ServerPluginType(
+ GenericPluginDescriptorType.class).stringify(), System.currentTimeMillis(), System.currentTimeMillis());
plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
assert plugin.getId() > 0;
@@ -310,6 +333,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert plugin.getStatus() == PluginStatusType.INSTALLED;
assert plugin.getPluginConfiguration() != null;
assert plugin.getScheduledJobsConfiguration() != null;
+ assert plugin.getType().equals(new ServerPluginType(GenericPluginDescriptorType.class).stringify());
return plugin;
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
index 9f0026b..48a5db7 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
@@ -32,6 +32,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
@@ -82,11 +83,11 @@ public class GenericServerPluginTest extends AbstractEJB3Test {
assert schedules == null;
ServerPluginsLocal serverPluginsLocal = LookupUtil.getServerPlugins();
- Map<ServerPluginType, List<String>> map = serverPluginsLocal.getAllPluginsGroupedByType();
+ Map<ServerPluginType, List<PluginKey>> map = serverPluginsLocal.getAllPluginsGroupedByType();
assert map.size() == 1;
- List<String> pluginNames = map.get(new ServerPluginType(GenericPluginDescriptorType.class));
+ List<PluginKey> pluginNames = map.get(new ServerPluginType(GenericPluginDescriptorType.class));
assert pluginNames.size() == 1;
- assert pluginNames.get(0).equals("TestSimpleGenericPlugin");
+ assert pluginNames.get(0).getPluginName().equals("TestSimpleGenericPlugin");
// make sure everything is shutdown
this.pluginService.stopMasterPluginContainer();
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index cd95053..1b577fe 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
@@ -38,6 +38,7 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -198,8 +199,9 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
.getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
- .getVersion(), pluginDescriptor.getVersion(), pluginConfig,
- scheduledJobsConfig, System.currentTimeMillis(), System.currentTimeMillis());
+ .getVersion(), pluginDescriptor.getVersion(), pluginConfig, scheduledJobsConfig,
+ new ServerPluginType(pluginDescriptor).stringify(), System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit 2bb5e6e39a106fe9a3f023b0216651954d50f3a6
Merge: b038b80... 3e3f767...
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 00:21:30 2009 -0500
Merge branch 'plugin-name-refactor' into pc2
Conflicts:
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index 5bee8c0,aa75432..6839cfc
--- 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
@@@ -46,9 -46,10 +46,10 @@@ import org.apache.commons.logging.LogFa
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+ import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.enterprise.server.RHQConstants;
@@@ -83,15 -84,23 +84,17 @@@ public class ServerPluginsBean implemen
return q.getResultList();
}
- public ServerPlugin getServerPlugin(String name) {
- public Plugin getServerPlugin(PluginKey key) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
++ public ServerPlugin getServerPlugin(PluginKey key) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
+ query.setParameter("name", key.getPluginName());
- Plugin plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + key + "] is not a server plugin");
- }
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
++ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
- plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] is not a server plugin");
- }
++ plugin = (ServerPlugin) query.getSingleResult();
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@@ -117,8 -126,9 +120,8 @@@
- query.setParameter("type", PluginDeploymentType.SERVER);
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- ServerPlugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception {
- Plugin plugin = getServerPlugin(pluginKey);
++ ServerPlugin plugin = getServerPlugin(pluginKey);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@@ -126,10 -136,11 +129,10 @@@
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- return query.getResultList();
- query.setParameter("type", PluginDeploymentType.SERVER);
+ return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@@ -159,12 -170,12 +162,12 @@@
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
- List<String> doomedPlugins = new ArrayList<String>();
+ List<PluginKey> doomedPlugins = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = null;
+ ServerPlugin doomedPlugin = null;
try {
- doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ doomedPlugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
@@@ -202,12 -214,12 +206,12 @@@
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
- List<String> doomedPlugins = new ArrayList<String>();
+ List<PluginKey> doomedPlugins = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = null;
+ ServerPlugin doomedPlugin = null;
try {
- doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ doomedPlugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
@@@ -348,16 -361,17 +353,16 @@@
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
- Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
- q.setParameter("type", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
// get the reference to attach to em and use the em.remove. this cascade deletes too.
- doomed = this.entityManager.getReference(Plugin.class, doomed.getId());
+ doomed = this.entityManager.getReference(ServerPlugin.class, doomed.getId());
this.entityManager.remove(doomed);
- log.debug("Server plugin [" + pluginName + "] has been purged from the db");
+ log.debug("Server plugin [" + pluginKey + "] has been purged from the db");
return;
}
@@@ -409,9 -428,10 +414,9 @@@
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
- q.setParameter("type", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
index e5375c4,2f84337..a1e0a40
--- 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
@@@ -8,8 -8,9 +8,9 @@@ import javax.ejb.Local
import javax.persistence.NoResultException;
import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.plugin.Plugin;
+ import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@@ -25,15 -26,15 +26,15 @@@ public interface ServerPluginsLocal
*
* @return all plugins found in the DB
*/
- List<Plugin> getServerPlugins();
+ List<ServerPlugin> getServerPlugins();
/**
- * Returns a plugin with the given name.
- * @param name name of plugin to find
+ * Returns a plugin with the given key.
+ * @param key identifies the plugin to find
* @return the named plugin
* @throws NoResultException when no plugin with that name exists
*/
- ServerPlugin getServerPlugin(String name);
- Plugin getServerPlugin(PluginKey key);
++ ServerPlugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
@@@ -54,12 -55,12 +55,12 @@@
* @param pluginIds the IDs of the plugins to load.
* @return plugins matching the given IDs
*/
- List<Plugin> getServerPluginsById(List<Integer> pluginIds);
+ List<ServerPlugin> getServerPluginsById(List<Integer> pluginIds);
/**
- * Given a plugin name, returns the descriptor for that plugin.
+ * Given a plugin key, returns the descriptor for that plugin.
*
- * @param pluginName
+ * @param pluginKey
* @return descriptor parsed from the file in the plugin jar
* @throws Exception if the descriptor could not be retrieved or parsed for the given plugin
*/
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index 43e07fc,350ca61..a4bd9b1
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
@@@ -306,12 -306,12 +306,12 @@@ public class ServerPluginManager
* the plugin configuration and scheduled jobs configuration.
*
* @param pluginEnv
- * @return the Plugin object for the given plugin
+ * @return the ServerPlugin object for the given plugin
*/
- protected Plugin getPlugin(ServerPluginEnvironment pluginEnv) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
++ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
return plugin;
}
diff --cc modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 44d03c3,e80ed1f..cd95053
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
@@@ -27,8 -27,10 +27,9 @@@ import java.util.Map
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
-import org.rhq.core.domain.plugin.PluginDeploymentType;
+ import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
@@@ -194,11 -196,11 +195,11 @@@ public class TestGenericServerPluginSer
}
File pluginFile = new File(env.getPluginUrl().toURI());
- ServerPlugin plugin = new ServerPlugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
- .getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor.getDescription(), "",
- MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor
- .getVersion(), pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
- .currentTimeMillis());
- Plugin plugin = new Plugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
++ ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
+ .getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
- .getVersion(), pluginDescriptor.getVersion(), PluginDeploymentType.SERVER, pluginConfig,
++ .getVersion(), pluginDescriptor.getVersion(), pluginConfig,
+ scheduledJobsConfig, System.currentTimeMillis(), System.currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit b038b80610293eb628ea5f8c34eb14fce7e2edd5
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 23:42:16 2009 -0500
fix copyright
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
index ff68860..6ff9cb5 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
@@ -4,17 +4,21 @@
* 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 as published by
- * the Free Software Foundation version 2 of the License.
+ * 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 for more details.
+ * 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
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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.domain.plugin;
@@ -36,8 +40,6 @@ import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
-import org.jetbrains.annotations.NotNull;
-
import org.rhq.core.util.MessageDigestGenerator;
/**
@@ -113,7 +115,7 @@ public class AbstractPlugin implements Serializable {
* @param name the logical name of the plugin
* @param path the actual filename of the plugin jar (see {@link #getPath()})
*/
- public AbstractPlugin(@NotNull String name, String path) {
+ public AbstractPlugin(String name, String path) {
this.name = name;
this.path = path;
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index bf1b438..b3c370d 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2009 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -27,8 +27,6 @@ import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
-import org.jetbrains.annotations.NotNull;
-
/**
* An agent plugin.
*
@@ -180,7 +178,7 @@ public class Plugin extends AbstractPlugin {
setDeployment(PluginDeploymentType.AGENT);
}
- public Plugin(@NotNull String name, String path) {
+ public Plugin(String name, String path) {
super(name, path);
setDeployment(PluginDeploymentType.AGENT);
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
index bb897b1..d233365 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2009 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -31,8 +31,6 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
-import org.jetbrains.annotations.NotNull;
-
import org.rhq.core.domain.configuration.Configuration;
/**
@@ -185,7 +183,7 @@ public class ServerPlugin extends AbstractPlugin {
setDeployment(PluginDeploymentType.SERVER);
}
- public ServerPlugin(@NotNull String name, String path) {
+ public ServerPlugin(String name, String path) {
super(name, path);
setDeployment(PluginDeploymentType.SERVER);
}
commit 816db190b25e5b1b8169fdae865f9e60ce371a3f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 19:54:33 2009 -0500
finish JPA discriminator refactoring so there is now ServerPlugin entity (Plugin entity is now only for agent plugins)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
index 757fa6a..ff68860 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
@@ -22,27 +22,22 @@ package org.rhq.core.domain.plugin;
import java.io.ByteArrayInputStream;
import java.io.Serializable;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.jetbrains.annotations.NotNull;
-import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.util.MessageDigestGenerator;
/**
@@ -69,14 +64,6 @@ public class AbstractPlugin implements Serializable {
@Enumerated(EnumType.STRING)
private PluginDeploymentType deployment;
- @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
- private Configuration scheduledJobsConfiguration;
-
- @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
- private Configuration pluginConfiguration;
-
@Column(name = "NAME", nullable = false)
private String name;
@@ -172,28 +159,10 @@ public class AbstractPlugin implements Serializable {
* Constructor that can build the full object except for the content byte array.
* This is used mainly for the named queries that want to return a Plugin object
* but does not eagerly load in the content array.
- *
- * @param id
- * @param name
- * @param path
- * @param displayName
- * @param enabled
- * @param status
- * @param description
- * @param help
- * @param md5
- * @param version
- * @param ampsVersion
- * @param deployment
- * @param pluginConfig
- * @param scheduledJobsConfig
- * @param ctime
- * @param mtime
*/
public AbstractPlugin(int id, String name, String path, String displayName, boolean enabled,
PluginStatusType status, String description, String help, String md5, String version, String ampsVersion,
- PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
- long mtime) {
+ PluginDeploymentType deployment, long ctime, long mtime) {
this.id = id;
this.name = name;
this.path = path;
@@ -206,8 +175,6 @@ public class AbstractPlugin implements Serializable {
this.version = version;
this.ampsVersion = ampsVersion;
this.deployment = deployment;
- this.pluginConfiguration = pluginConfig;
- this.scheduledJobsConfiguration = scheduledJobsConfig;
this.ctime = ctime;
this.mtime = mtime;
}
@@ -387,32 +354,6 @@ public class AbstractPlugin implements Serializable {
}
/**
- * If the plugin has jobs associated with it, this is the configuration for those jobs.
- *
- * @return scheduled job configuration for jobs that the plugin defined.
- */
- public Configuration getScheduledJobsConfiguration() {
- return scheduledJobsConfiguration;
- }
-
- public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
- this.scheduledJobsConfiguration = scheduledJobsConfiguration;
- }
-
- /**
- * If the plugin, itself, has configuration associated with it, this is that configuration.
- *
- * @return the configuration associated with the plugin itself
- */
- public Configuration getPluginConfiguration() {
- return pluginConfiguration;
- }
-
- public void setPluginConfiguration(Configuration pluginConfiguration) {
- this.pluginConfiguration = pluginConfiguration;
- }
-
- /**
* Returns the actual content of the plugin file. Be careful calling this
* in an entity context - the entire plugin file content will be loaded in
* memory (which may trigger an OutOfMemoryError if the file is very large).
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index 1b4c693..bf1b438 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -29,8 +29,6 @@ import javax.persistence.NamedQuery;
import org.jetbrains.annotations.NotNull;
-import org.rhq.core.domain.configuration.Configuration;
-
/**
* An agent plugin.
*
@@ -67,14 +65,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.id IN (:ids) " //
+ " AND p.status = 'INSTALLED' "), //
@@ -92,14 +85,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.name=:name " //
+ " AND p.status = 'INSTALLED' "), //
@@ -118,14 +106,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.name=:name "), //
// finds all installed - ignores those plugins marked as deleted
@@ -143,14 +126,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.status = 'INSTALLED' "), //
// this query is how you enable and disable plugins
@@ -173,14 +151,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.status = 'INSTALLED' AND " //
+ " p.name IN ( SELECT rt.plugin " //
+ " FROM Resource res " //
@@ -223,16 +196,10 @@ public class Plugin extends AbstractPlugin {
}
public Plugin(int id, String name, String path, String displayName, boolean enabled, PluginStatusType status,
- String description, String help, String md5, String version, String ampsVersion,
- PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
- long mtime) {
-
- super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
- pluginConfig, scheduledJobsConfig, ctime, mtime);
+ String description, String help, String md5, String version, String ampsVersion, long ctime, long mtime) {
- if (deployment != PluginDeploymentType.AGENT) {
- throw new IllegalArgumentException("Plugin must only ever be of deployment type == AGENT: " + deployment);
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
+ PluginDeploymentType.AGENT, ctime, mtime);
}
@Override
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
index 0c406c3..bb897b1 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -22,10 +22,14 @@
*/
package org.rhq.core.domain.plugin;
+import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
import org.jetbrains.annotations.NotNull;
@@ -67,7 +71,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -92,7 +95,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -118,7 +120,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -143,7 +144,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -172,6 +172,14 @@ public class ServerPlugin extends AbstractPlugin {
public static final String QUERY_FIND_ALL_INSTALLED = "ServerPlugin.findAllInstalled";
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "ServerPlugin.updatePluginsEnabledByIds";
+ @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID")
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ private Configuration scheduledJobsConfiguration;
+
+ @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName = "ID")
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ private Configuration pluginConfiguration;
+
public ServerPlugin() {
super();
setDeployment(PluginDeploymentType.SERVER);
@@ -193,17 +201,13 @@ public class ServerPlugin extends AbstractPlugin {
}
public ServerPlugin(int id, String name, String path, String displayName, boolean enabled, PluginStatusType status,
- String description, String help, String md5, String version, String ampsVersion,
- PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
- long mtime) {
+ String description, String help, String md5, String version, String ampsVersion, Configuration pluginConfig,
+ Configuration scheduledJobsConfig, long ctime, long mtime) {
- super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
- pluginConfig, scheduledJobsConfig, ctime, mtime);
-
- if (deployment != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("ServerPlugin must only ever be of deployment type == SERVER: "
- + deployment);
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
+ PluginDeploymentType.SERVER, ctime, mtime);
+ this.pluginConfiguration = pluginConfig;
+ this.scheduledJobsConfiguration = scheduledJobsConfig;
}
@Override
@@ -215,6 +219,32 @@ public class ServerPlugin extends AbstractPlugin {
super.setDeployment(deployment);
}
+ /**
+ * If the plugin, itself, has configuration associated with it, this is that configuration.
+ *
+ * @return the configuration associated with the plugin itself
+ */
+ public Configuration getPluginConfiguration() {
+ return pluginConfiguration;
+ }
+
+ public void setPluginConfiguration(Configuration pluginConfiguration) {
+ this.pluginConfiguration = pluginConfiguration;
+ }
+
+ /**
+ * If the plugin has jobs associated with it, this is the configuration for those jobs.
+ *
+ * @return scheduled job configuration for jobs that the plugin defined.
+ */
+ public Configuration getScheduledJobsConfiguration() {
+ return scheduledJobsConfiguration;
+ }
+
+ public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
+ this.scheduledJobsConfiguration = scheduledJobsConfiguration;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index be2deb3..c7afe81 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -80,8 +80,6 @@ public class PluginTest extends AbstractEJB3Test {
em.persist(plugin);
id = plugin.getId();
assert id > 0;
- assert plugin.getPluginConfiguration() == null : "there was no config that should have been here";
- assert plugin.getScheduledJobsConfiguration() == null : "there was no config that should have been here";
q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", plugin.getName());
@@ -99,8 +97,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert new String(plugin.getContent()).equals(new String(content));
@@ -115,32 +111,14 @@ public class PluginTest extends AbstractEJB3Test {
String description = "description-UPDATED";
String help = "help-UPDATED";
PluginDeploymentType deployment = PluginDeploymentType.AGENT;
- Configuration pluginConfig = new Configuration();
- Configuration jobsConfig = new Configuration();
- pluginConfig.put(new PropertySimple("first", "last"));
- jobsConfig.put(new PropertySimple("aaa", "bbb"));
em.close();
getTransactionManager().commit(); // we will be doing an update - needs to be in own tx
getTransactionManager().begin();
em = getEntityManager();
- em.persist(pluginConfig);
- em.persist(jobsConfig);
em.flush(); // gotta get those two persists to flush to the DB
- // do what ServerPluginsBean/ResourceMetadataManagerBean.updateServerPluginExceptContent does
- Configuration config = plugin.getPluginConfiguration();
- if (config != null) {
- config = em.merge(config);
- plugin.setPluginConfiguration(config);
- }
- config = plugin.getScheduledJobsConfiguration();
- if (config != null) {
- config = em.merge(config);
- plugin.setScheduledJobsConfiguration(config);
- }
-
Plugin pluginEntity = em.getReference(Plugin.class, plugin.getId());
pluginEntity.setName(name);
pluginEntity.setPath(path);
@@ -151,8 +129,6 @@ public class PluginTest extends AbstractEJB3Test {
pluginEntity.setVersion(version);
pluginEntity.setAmpsVersion(ampsVersion);
pluginEntity.setDeployment(deployment);
- pluginEntity.setPluginConfiguration(pluginConfig);
- pluginEntity.setScheduledJobsConfiguration(jobsConfig);
pluginEntity.setDescription(description);
pluginEntity.setHelp(help);
pluginEntity.setMtime(System.currentTimeMillis());
@@ -180,8 +156,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
// and what we really want to test - ensure the content remained intact after the update
assert new String(plugin.getContent()).equals(new String(content));
@@ -248,8 +222,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert plugin.getContent() == null;
@@ -299,8 +271,6 @@ public class PluginTest extends AbstractEJB3Test {
plugin.setHelp(help);
plugin.setContent(content);
plugin.setDeployment(deployment);
- plugin.setPluginConfiguration(pluginConfig);
- plugin.setScheduledJobsConfiguration(jobsConfig);
em.persist(plugin);
assert plugin.getId() > 0;
@@ -317,8 +287,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert new String(plugin.getContent()).equals(new String(content));
@@ -337,8 +305,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getContent() == null;
@@ -356,8 +322,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getContent() == null;
@@ -377,8 +341,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert p.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert p.getHelp().equals(help);
assert p.getContent() == null;
break;
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
index 0bb87bd..31d4188 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
@@ -19,12 +19,14 @@
package org.rhq.enterprise.gui.admin.plugin;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.web.RequestParameter;
+
+import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -58,13 +60,13 @@ public class InstalledPluginComponent {
this.type = type;
}
- @Factory(value="plugin", autoCreate=true, scope=ScopeType.PAGE)
- public Plugin lookupPlugin() {
+ @Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
+ public AbstractPlugin lookupPlugin() {
if (this.type == PluginDeploymentType.AGENT) {
return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
} else if (this.type == PluginDeploymentType.SERVER) {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsBean.getServerPlugin(this.name);
+ ServerPlugin plugin = serverPluginsBean.getServerPlugin(this.name);
return serverPluginsBean.getServerPluginRelationships(plugin);
}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
index 3fe6988..2f7d73a 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
@@ -21,19 +21,21 @@ package org.rhq.enterprise.gui.admin.plugin;
import javax.faces.application.FacesMessage;
import org.apache.commons.logging.Log;
-
import org.apache.commons.logging.LogFactory;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+
import org.rhq.core.clientapi.agent.metadata.ConfigurationMetadataParser;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.authz.PermissionException;
@@ -53,15 +55,15 @@ public class InstalledPluginUIBean {
public static final String MANAGED_BEAN_NAME = InstalledPluginUIBean.class.getSimpleName();
private final Log log = LogFactory.getLog(InstalledPluginUIBean.class);
@In
- private Plugin plugin;
+ private AbstractPlugin plugin;
private ConfigurationDefinition pluginConfigurationDefinition;
private ConfigurationDefinition scheduledJobsDefinition;
- public Plugin getPlugin() {
+ public AbstractPlugin getPlugin() {
return plugin;
}
- public void setPlugin(Plugin plugin) {
+ public void setPlugin(AbstractPlugin plugin) {
this.plugin = plugin;
}
@@ -81,15 +83,15 @@ public class InstalledPluginUIBean {
ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
try {
- serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
- "Configuration settings saved.");
+ serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(),
+ (ServerPlugin) plugin);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration settings saved.");
return OUTCOME_SUCCESS;
} catch (Exception e) {
log.error("Error updating the plugin configurations.", e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "There was an error changing the configuration settings.", e);
+ "There was an error changing the configuration settings.", e);
return null;
}
@@ -104,8 +106,10 @@ public class InstalledPluginUIBean {
try {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginName);
- this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginName, descriptor.getPluginConfiguration());
- this.scheduledJobsDefinition = ConfigurationMetadataParser.parse("jobs:" + pluginName, descriptor.getScheduledJobs());
+ this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginName, descriptor
+ .getPluginConfiguration());
+ this.scheduledJobsDefinition = ConfigurationMetadataParser.parse("jobs:" + pluginName, descriptor
+ .getScheduledJobs());
} catch (Exception e) {
String err = "Cannot determine what the plugin configuration or scheduled jobs configuration looks like";
log.error(err + " - Cause: " + e);
@@ -121,7 +125,8 @@ public class InstalledPluginUIBean {
private void hasPermission() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
if (!LookupUtil.getAuthorizationManager().hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)) {
- throw new PermissionException("User [" + subject.getName() + "] does not have the proper permissions to view or manage plugins");
+ throw new PermissionException("User [" + subject.getName()
+ + "] does not have the proper permissions to view or manage plugins");
}
}
}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
index cfc99cf..6fac7a3 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
@@ -35,7 +35,9 @@ import org.richfaces.event.UploadEvent;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.core.gui.util.StringUtility;
import org.rhq.core.util.exception.ThrowableUtil;
@@ -66,7 +68,7 @@ public class InstalledPluginsUIBean {
return resourceMetadataManagerBean.getPlugins();
}
- public Collection<Plugin> getInstalledServerPlugins() {
+ public Collection<ServerPlugin> getInstalledServerPlugins() {
hasPermission();
return serverPluginsBean.getServerPlugins();
@@ -124,9 +126,9 @@ public class InstalledPluginsUIBean {
}
public void enableServerPlugins() {
- List<Plugin> selectedPlugins = getSelectedServerPlugins();
+ List<ServerPlugin> selectedPlugins = getSelectedServerPlugins();
List<String> selectedPluginNames = new ArrayList<String>();
- for (Plugin selectedPlugin : selectedPlugins) {
+ for (ServerPlugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
@@ -142,9 +144,9 @@ public class InstalledPluginsUIBean {
}
public void disableServerPlugins() {
- List<Plugin> selectedPlugins = getSelectedServerPlugins();
+ List<ServerPlugin> selectedPlugins = getSelectedServerPlugins();
List<String> selectedPluginNames = new ArrayList<String>();
- for (Plugin selectedPlugin : selectedPlugins) {
+ for (ServerPlugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
@@ -160,9 +162,9 @@ public class InstalledPluginsUIBean {
}
public void undeployServerPlugins() {
- List<Plugin> selectedPlugins = getSelectedServerPlugins();
+ List<? extends AbstractPlugin> selectedPlugins = getSelectedServerPlugins();
List<String> selectedPluginNames = new ArrayList<String>();
- for (Plugin selectedPlugin : selectedPlugins) {
+ for (AbstractPlugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
@@ -177,18 +179,18 @@ public class InstalledPluginsUIBean {
return;
}
- private List<Integer> getIds(List<Plugin> plugins) {
+ private List<Integer> getIds(List<? extends AbstractPlugin> plugins) {
ArrayList<Integer> ids = new ArrayList<Integer>(plugins.size());
- for (Plugin plugin : plugins) {
+ for (AbstractPlugin plugin : plugins) {
ids.add(plugin.getId());
}
return ids;
}
- private List<Plugin> getSelectedServerPlugins() {
+ private List<ServerPlugin> getSelectedServerPlugins() {
Integer[] integerItems = getSelectedPluginIds();
List<Integer> ids = Arrays.asList(integerItems);
- List<Plugin> plugins = serverPluginsBean.getServerPluginsById(ids);
+ List<ServerPlugin> plugins = serverPluginsBean.getServerPluginsById(ids);
return plugins;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
index 8695d35..4eeb177 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
@@ -259,7 +259,7 @@ public class CoreServerServiceImpl implements CoreServerService {
try {
em = LookupUtil.getEntityManager();
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ALL_AGENT);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
List<Plugin> resultList = q.getResultList();
for (Plugin potentialPlugin : resultList) {
if (potentialPlugin.isEnabled()) {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index 6bd8c0f..de8857b 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
@@ -51,9 +51,9 @@ import org.rhq.core.db.PostgresqlDatabaseType;
import org.rhq.core.db.SQLServerDatabaseType;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.core.util.stream.StreamUtil;
@@ -159,7 +159,7 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "], version " + version);
- Plugin plugin = new Plugin(pluginName, pluginFile.getName());
+ ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
plugin.setDeployment(PluginDeploymentType.SERVER);
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
@@ -251,7 +251,7 @@ public class ServerPluginScanner {
String md5 = null;
PluginWithDescriptor pluginWithDescriptor = this.serverPluginsOnFilesystem.get(pluginJar);
- Plugin plugin = null;
+ ServerPlugin plugin = null;
if (pluginWithDescriptor != null) {
plugin = pluginWithDescriptor.plugin;
}
@@ -283,15 +283,16 @@ public class ServerPluginScanner {
// Let's check to see if there are any obsolete plugins that need to be deleted.
// This is needed if plugin-A-1.0.jar exists and someone deployed plugin-A-1.1.jar but fails to delete plugin-A-1.0.jar.
doomedPluginFiles.clear();
- HashMap<String, Plugin> pluginsByName = new HashMap<String, Plugin>();
+ HashMap<String, ServerPlugin> pluginsByName = new HashMap<String, ServerPlugin>();
for (Entry<File, PluginWithDescriptor> currentPluginFileEntry : this.serverPluginsOnFilesystem.entrySet()) {
- Plugin currentPlugin = currentPluginFileEntry.getValue().plugin;
- Plugin existingPlugin = pluginsByName.get(currentPlugin.getName());
+ ServerPlugin currentPlugin = currentPluginFileEntry.getValue().plugin;
+ ServerPlugin existingPlugin = pluginsByName.get(currentPlugin.getName());
if (existingPlugin == null) {
// this is the usual case - this is the only plugin with the given name we've seen
pluginsByName.put(currentPlugin.getName(), currentPlugin);
} else {
- Plugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(currentPlugin, existingPlugin);
+ ServerPlugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(currentPlugin,
+ existingPlugin);
if (obsolete == null) {
obsolete = currentPlugin; // both were identical, but we only want one file so pick one to get rid of
}
@@ -317,13 +318,13 @@ public class ServerPluginScanner {
}
/**
- * Creates a {@link Plugin} object for the given plugin jar and caches it.
+ * Creates a {@link ServerPlugin} object for the given plugin jar and caches it.
* @param pluginJar information about this plugin jar will be cached
* @param md5 if known, this is the plugin jar's MD5, <code>null</code> if not known
* @return the plugin jar files's information that has been cached
* @throws Exception if failed to get information about the plugin
*/
- private Plugin cacheFilesystemServerPluginJar(File pluginJar, String md5) throws Exception {
+ private ServerPlugin cacheFilesystemServerPluginJar(File pluginJar, String md5) throws Exception {
if (md5 == null) { // don't calculate the MD5 is we've already done it before
md5 = MessageDigestGenerator.getDigestString(pluginJar);
}
@@ -331,11 +332,10 @@ public class ServerPluginScanner {
ServerPluginDescriptorType descriptor = ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
String version = ServerPluginDescriptorUtil.getPluginVersion(pluginJar, descriptor).toString();
String name = descriptor.getName();
- Plugin plugin = new Plugin(name, pluginJar.getName());
+ ServerPlugin plugin = new ServerPlugin(name, pluginJar.getName());
plugin.setMd5(md5);
plugin.setVersion(version);
plugin.setMtime(pluginJar.lastModified());
- plugin.setDeployment(PluginDeploymentType.SERVER);
this.serverPluginsOnFilesystem.put(pluginJar, new PluginWithDescriptor(plugin, descriptor));
return plugin;
}
@@ -352,7 +352,7 @@ public class ServerPluginScanner {
ResultSet rs = null;
// these are plugins (name/path/md5/mtime) that have changed in the DB but are missing from the file system
- List<Plugin> updatedPlugins = new ArrayList<Plugin>();
+ List<ServerPlugin> updatedPlugins = new ArrayList<ServerPlugin>();
// the same list as above, only they are the files that are written to the filesystem and no longer missing
List<File> updatedFiles = new ArrayList<File>();
@@ -362,7 +362,7 @@ public class ServerPluginScanner {
conn = ds.getConnection();
// get all the plugins
- ps = conn.prepareStatement("SELECT NAME, PATH, MD5, MTIME, VERSION FROM " + Plugin.TABLE_NAME
+ ps = conn.prepareStatement("SELECT NAME, PATH, MD5, MTIME, VERSION FROM " + ServerPlugin.TABLE_NAME
+ " WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' ");
rs = ps.executeQuery();
while (rs.next()) {
@@ -402,13 +402,12 @@ public class ServerPluginScanner {
}
if (pluginWithDescriptor != null && currentFile != null && currentFile.exists()) {
- Plugin dbPlugin = new Plugin(name, path);
+ ServerPlugin dbPlugin = new ServerPlugin(name, path);
dbPlugin.setMd5(md5);
dbPlugin.setVersion(version);
dbPlugin.setMtime(mtime);
- dbPlugin.setDeployment(PluginDeploymentType.SERVER);
- Plugin obsoletePlugin = ServerPluginDescriptorUtil.determineObsoletePlugin(dbPlugin,
+ ServerPlugin obsoletePlugin = ServerPluginDescriptorUtil.determineObsoletePlugin(dbPlugin,
pluginWithDescriptor.plugin);
if (obsoletePlugin == pluginWithDescriptor.plugin) { // yes use == for reference equality!
@@ -449,7 +448,7 @@ public class ServerPluginScanner {
}
} else {
log.info("Found server plugin in the DB that we do not yet have: " + name);
- Plugin plugin = new Plugin(name, path, md5);
+ ServerPlugin plugin = new ServerPlugin(name, path, md5);
plugin.setMtime(mtime);
plugin.setVersion(version);
plugin.setDeployment(PluginDeploymentType.SERVER);
@@ -460,9 +459,9 @@ public class ServerPluginScanner {
JDBCUtil.safeClose(ps, rs);
// write all our updated plugins to the file system
- ps = conn.prepareStatement("SELECT CONTENT FROM " + Plugin.TABLE_NAME
+ ps = conn.prepareStatement("SELECT CONTENT FROM " + ServerPlugin.TABLE_NAME
+ " WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' AND NAME = ?");
- for (Plugin plugin : updatedPlugins) {
+ for (ServerPlugin plugin : updatedPlugins) {
File file = new File(this.getServerPluginDir(), plugin.getPath());
ps.setString(1, plugin.getName());
@@ -527,7 +526,7 @@ public class ServerPluginScanner {
TransactionManager tm = null;
String sql = "UPDATE "
- + Plugin.TABLE_NAME
+ + ServerPlugin.TABLE_NAME
+ " SET CONTENT = ?, MD5 = ?, MTIME = ?, PATH = ? WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' AND NAME = ?";
// if 'different' is true, give bogus data so the plugin deployer will think the plugin on the file system is new
@@ -573,12 +572,12 @@ public class ServerPluginScanner {
}
private class PluginWithDescriptor {
- public PluginWithDescriptor(Plugin plugin, ServerPluginDescriptorType descriptor) {
+ public PluginWithDescriptor(ServerPlugin plugin, ServerPluginDescriptorType descriptor) {
this.plugin = plugin;
this.descriptor = descriptor;
}
- public Plugin plugin;
+ public ServerPlugin plugin;
public ServerPluginDescriptorType descriptor;
}
}
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 e139241..5bee8c0 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
@@ -46,9 +46,9 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.enterprise.server.RHQConstants;
@@ -78,22 +78,19 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@EJB
private ServerPluginsLocal serverPluginsBean; //self
- public List<Plugin> getServerPlugins() {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ public List<ServerPlugin> getServerPlugins() {
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
return q.getResultList();
}
- public Plugin getServerPlugin(String name) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ public ServerPlugin getServerPlugin(String name) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
query.setParameter("name", name);
- Plugin plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin named [" + name + "] is not a server plugin");
- }
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
Configuration config = plugin.getPluginConfiguration();
@@ -111,18 +108,17 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
- public List<Plugin> getServerPluginsById(List<Integer> pluginIds) {
+ public List<ServerPlugin> getServerPluginsById(List<Integer> pluginIds) {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<Plugin>(); // nothing to do
+ return new ArrayList<ServerPlugin>(); // nothing to do
}
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_DEPLOYMENT);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", pluginIds);
- query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ ServerPlugin plugin = getServerPlugin(pluginName);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -131,9 +127,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_DEPLOYMENT);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -167,9 +162,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
List<String> doomedPlugins = new ArrayList<String>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = null;
+ ServerPlugin doomedPlugin = null;
try {
- doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ doomedPlugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
@@ -210,9 +205,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
List<String> doomedPlugins = new ArrayList<String>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = null;
+ ServerPlugin doomedPlugin = null;
try {
- doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ doomedPlugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
@@ -269,7 +264,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
- Query q = entityManager.createNamedQuery(Plugin.UPDATE_PLUGINS_ENABLED_BY_IDS);
+ Query q = entityManager.createNamedQuery(ServerPlugin.UPDATE_PLUGINS_ENABLED_BY_IDS);
q.setParameter("ids", pluginIds);
q.setParameter("enabled", Boolean.valueOf(enabled));
int count = q.executeUpdate();
@@ -288,8 +283,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
- List<Plugin> plugins = getServerPluginsById(pluginIds);
- for (Plugin plugin : plugins) {
+ List<ServerPlugin> plugins = getServerPluginsById(pluginIds);
+ for (ServerPlugin plugin : plugins) {
plugin.setStatus(status);
updateServerPluginExceptContent(subject, plugin);
}
@@ -297,14 +292,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception {
+ public ServerPlugin registerServerPlugin(Subject subject, ServerPlugin plugin, File pluginFile) throws Exception {
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
throw new IllegalArgumentException("Plugin [" + plugin.getName()
+ "] must be a server plugin to be registered");
}
- Plugin existingPlugin = null;
+ ServerPlugin existingPlugin = null;
boolean newOrUpdated = false;
try {
existingPlugin = getServerPlugin(plugin.getName());
@@ -317,7 +312,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
+ "], it has been marked as deleted");
}
- Plugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
+ ServerPlugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
if (obsolete == existingPlugin) { // yes use == for reference equality
newOrUpdated = true;
}
@@ -354,13 +349,12 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void purgeServerPlugin(Subject subject, String pluginName) {
- Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
+ Query q = this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
// get the reference to attach to em and use the em.remove. this cascade deletes too.
- doomed = this.entityManager.getReference(Plugin.class, doomed.getId());
+ doomed = this.entityManager.getReference(ServerPlugin.class, doomed.getId());
this.entityManager.remove(doomed);
log.debug("Server plugin [" + pluginName + "] has been purged from the db");
@@ -368,18 +362,13 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws Exception {
+ public ServerPlugin updateServerPluginExceptContent(Subject subject, ServerPlugin plugin) throws Exception {
// this method is here because we need a way to update the plugin's information
// without blowing away the content data. Because we do not want to load the
// content blob in memory, the plugin's content field will be null - if we were
// to entityManager.merge that plugin POJO, it would null out that blob column.
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName()
- + "] must be a server plugin to be updated");
- }
-
if (plugin.getId() == 0) {
throw new IllegalArgumentException("Plugin must already exist to update it");
} else {
@@ -395,7 +384,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
plugin.setScheduledJobsConfiguration(config);
}
- Plugin pluginEntity = entityManager.getReference(Plugin.class, plugin.getId());
+ ServerPlugin pluginEntity = entityManager.getReference(ServerPlugin.class, plugin.getId());
pluginEntity.setName(plugin.getName());
pluginEntity.setPath(plugin.getPath());
pluginEntity.setDisplayName(plugin.getDisplayName());
@@ -421,9 +410,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_DEPLOYMENT);
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
@@ -474,7 +462,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
try {
conn = this.dataSource.getConnection();
- ps = conn.prepareStatement("UPDATE " + Plugin.TABLE_NAME + " SET CONTENT = ? WHERE ID = ?");
+ ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME + " SET CONTENT = ? WHERE ID = ?");
ps.setBinaryStream(1, new BufferedInputStream(fis), (int) file.length());
ps.setInt(2, id);
int updateResults = ps.executeUpdate();
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 a6a09bf..e5375c4 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
@@ -8,8 +8,8 @@ import javax.ejb.Local;
import javax.persistence.NoResultException;
import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -25,7 +25,7 @@ public interface ServerPluginsLocal {
*
* @return all plugins found in the DB
*/
- List<Plugin> getServerPlugins();
+ List<ServerPlugin> getServerPlugins();
/**
* Returns a plugin with the given name.
@@ -33,7 +33,7 @@ public interface ServerPluginsLocal {
* @return the named plugin
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPlugin(String name);
+ ServerPlugin getServerPlugin(String name);
/**
* Methods in this object that return plugins normally do not include
@@ -46,7 +46,7 @@ public interface ServerPluginsLocal {
* @return the same plugin, with the relationship data loaded
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPluginRelationships(Plugin plugin);
+ ServerPlugin getServerPluginRelationships(ServerPlugin plugin);
/**
* Get a list of plugins from their IDs.
@@ -54,7 +54,7 @@ public interface ServerPluginsLocal {
* @param pluginIds the IDs of the plugins to load.
* @return plugins matching the given IDs
*/
- List<Plugin> getServerPluginsById(List<Integer> pluginIds);
+ List<ServerPlugin> getServerPluginsById(List<Integer> pluginIds);
/**
* Given a plugin name, returns the descriptor for that plugin.
@@ -138,7 +138,7 @@ public interface ServerPluginsLocal {
* @return the plugin after being persisted
* @throws Exception if failed to fully register the plugin
*/
- Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception;
+ ServerPlugin registerServerPlugin(Subject subject, ServerPlugin plugin, File pluginFile) throws Exception;
/**
* Given a plugin that already exists, this will update that plugin's data in the database,
@@ -150,14 +150,14 @@ public interface ServerPluginsLocal {
* @return the updated plugin
* @throws Exception if the plugin did not already exist or an error occurred that caused the update to fail
*/
- Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws Exception;
+ ServerPlugin updateServerPluginExceptContent(Subject subject, ServerPlugin plugin) throws Exception;
/**
* Purges the server plugin from the database. This ensures that, after this method returns,
* the given plugin will be unknown. The plugin can be installed again later.
*
* This has "requires new" semantics, so the results are committed immediately upon return.
- * This is really a supporting method for {@link #reRegisterServerPlugin(Subject, Plugin, File)} - you'll
+ * This is really a supporting method for {@link #reRegisterServerPlugin(Subject, ServerPlugin, File)} - you'll
* probably want to use that instead. Do not blindly purge server plugins using this method unless you
* know what you are doing.
*
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index 36fa5bd..43e07fc 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
@@ -30,7 +30,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ScheduledJobDefinition;
@@ -288,7 +288,7 @@ public class ServerPluginManager {
List<ScheduledJobDefinition> schedules;
try {
- Plugin plugin = getPlugin(env);
+ ServerPlugin plugin = getPlugin(env);
plugnConfig = plugin.getPluginConfiguration();
Configuration scheduledJobsConfig = plugin.getScheduledJobsConfiguration();
schedules = ServerPluginDescriptorMetadataParser.getScheduledJobs(scheduledJobsConfig);
@@ -306,12 +306,12 @@ public class ServerPluginManager {
* the plugin configuration and scheduled jobs configuration.
*
* @param pluginEnv
- * @return the Plugin object for the given plugin
+ * @return the ServerPlugin object for the given plugin
*/
- protected Plugin getPlugin(ServerPluginEnvironment pluginEnv) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
+ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
return plugin;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index d502f4e..a72c8c3 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -50,7 +50,6 @@ import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.event.EventDefinition;
@@ -125,7 +124,7 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
*/
@SuppressWarnings("unchecked")
public List<Plugin> getPlugins() {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_FIND_ALL_AGENT);
+ Query q = entityManager.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
return q.getResultList();
}
@@ -197,19 +196,6 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
if (plugin.getId() == 0) {
entityManager.persist(plugin);
} else {
- // agent plugins don't support these configs, but if/when they do in the future, this will support it
- // make sure we create (if necessary) and attach the configs
- Configuration config = plugin.getPluginConfiguration();
- if (config != null) {
- config = entityManager.merge(config);
- plugin.setPluginConfiguration(config);
- }
- config = plugin.getScheduledJobsConfiguration();
- if (config != null) {
- config = entityManager.merge(config);
- plugin.setScheduledJobsConfiguration(config);
- }
-
// update all the fields except content
Plugin pluginEntity = entityManager.getReference(Plugin.class, plugin.getId());
pluginEntity.setName(plugin.getName());
@@ -221,8 +207,6 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
pluginEntity.setVersion(plugin.getVersion());
pluginEntity.setAmpsVersion(plugin.getAmpsVersion());
pluginEntity.setDeployment(plugin.getDeployment());
- pluginEntity.setPluginConfiguration(plugin.getPluginConfiguration());
- pluginEntity.setScheduledJobsConfiguration(plugin.getScheduledJobsConfiguration());
pluginEntity.setDescription(plugin.getDescription());
pluginEntity.setHelp(plugin.getHelp());
pluginEntity.setMtime(plugin.getMtime());
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 e39f570..cd1921b 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
@@ -34,9 +34,9 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -75,10 +75,10 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
em = getEntityManager();
Query q = em
- .createQuery("SELECT p FROM Plugin p LEFT JOIN FETCH p.pluginConfiguration LEFT JOIN FETCH p.scheduledJobsConfiguration WHERE p.name LIKE 'serverplugintest%'");
- List<Plugin> doomed = q.getResultList();
- for (Plugin plugin : doomed) {
- em.remove(em.getReference(Plugin.class, plugin.getId()));
+ .createQuery("SELECT p FROM ServerPlugin p LEFT JOIN FETCH p.pluginConfiguration LEFT JOIN FETCH p.scheduledJobsConfiguration WHERE p.name LIKE 'serverplugintest%'");
+ List<ServerPlugin> doomed = q.getResultList();
+ for (ServerPlugin plugin : doomed) {
+ em.remove(em.getReference(ServerPlugin.class, plugin.getId()));
}
getTransactionManager().commit();
@@ -98,8 +98,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testGetPlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
@@ -107,7 +107,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
assert plugin.getId() == p1.getId() : plugin;
assert plugin.getName().equals(p1.getName()) : plugin;
assetLazyInitializationException(plugin);
@@ -118,7 +118,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
assert plugin.getScheduledJobsConfiguration().equals(p1.getScheduledJobsConfiguration());
- List<Plugin> plugins = this.serverPluginsBean.getServerPlugins();
+ List<ServerPlugin> plugins = this.serverPluginsBean.getServerPlugins();
assert plugins.contains(p1) : plugins;
assert plugins.contains(p2) : plugins;
assetLazyInitializationException(plugins.get(0));
@@ -136,11 +136,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testUpdatePlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
+ ServerPlugin p1 = registerPlugin(1);
p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
p1 = this.serverPluginsBean.getServerPluginRelationships(p1);
- Plugin p1update = this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
+ ServerPlugin p1update = this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
p1update = this.serverPluginsBean.getServerPluginRelationships(p1update);
assert p1update.getId() == p1.getId() : p1update;
@@ -154,8 +154,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testDisableEnablePlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
@@ -184,7 +184,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p2.getName()) : pluginNames;
// make sure none of these enable/disable settings lost our config
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
@@ -203,8 +203,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
assert status == PluginStatusType.INSTALLED;
@@ -218,8 +218,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1.getName()) : undeployed;
assert undeployed.contains(p2.getName()) : undeployed;
- Plugin p1deleted = getDeletedPluginInTx(p1.getName());
- Plugin p2deleted = getDeletedPluginInTx(p2.getName());
+ ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
+ ServerPlugin p2deleted = getDeletedPluginInTx(p2.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p2deleted.getStatus() == PluginStatusType.DELETED;
@@ -240,8 +240,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
assert status == PluginStatusType.INSTALLED;
@@ -255,11 +255,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1.getName()) : undeployed;
assert undeployed.contains(p2.getName()) : undeployed;
- Plugin p1deleted = getDeletedPluginInTx(p1.getName());
+ ServerPlugin 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());
+ ServerPlugin 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
@@ -284,8 +284,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
p2.setScheduledJobsConfiguration(p2.getScheduledJobsConfiguration().deepCopy(false));
// re-register them now
- Plugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p1, null);
- Plugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p2, null);
+ ServerPlugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p1, null);
+ ServerPlugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p2, null);
pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert pluginNames.contains(p1.getName()) : pluginNames;
@@ -297,11 +297,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p2.getName()) : pluginNames;
}
- private Plugin registerPlugin(int index) throws Exception {
- Plugin plugin = new Plugin(0, TEST_PLUGIN_NAME_PREFIX + index, "path", "displayName", true,
+ private ServerPlugin registerPlugin(int index) throws Exception {
+ ServerPlugin plugin = new ServerPlugin(0, TEST_PLUGIN_NAME_PREFIX + index, "path", "displayName", true,
PluginStatusType.INSTALLED, "description", "help", "md5", "version", "ampsVersion",
- PluginDeploymentType.SERVER, createPluginConfiguration(), createScheduledJobsConfiguration(), System
- .currentTimeMillis(), System.currentTimeMillis());
+ createPluginConfiguration(), createScheduledJobsConfiguration(), System.currentTimeMillis(), System
+ .currentTimeMillis());
plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
assert plugin.getId() > 0;
@@ -313,7 +313,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
return plugin;
}
- private void assetLazyInitializationException(Plugin plugin) {
+ private void assetLazyInitializationException(ServerPlugin plugin) {
try {
plugin.getPluginConfiguration().toString();
assert false : "Should have thrown a lazy-initialization exception - we didn't load config";
@@ -344,14 +344,13 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
return LookupUtil.getSubjectManager().getOverlord();
}
- private Plugin getDeletedPluginInTx(String pluginName) throws Exception {
+ private ServerPlugin getDeletedPluginInTx(String pluginName) throws Exception {
EntityManager em = getEntityManager();
getTransactionManager().begin();
try {
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
- return (Plugin) q.getSingleResult();
+ return (ServerPlugin) q.getSingleResult();
} finally {
getTransactionManager().rollback();
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 592a3d9..44d03c3 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
@@ -27,9 +27,8 @@ import java.util.Map;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
-import org.rhq.core.domain.plugin.PluginDeploymentType;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
@@ -175,7 +174,7 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
@Override
- protected Plugin getPlugin(ServerPluginEnvironment env) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
try {
Configuration pluginConfig = null;
@@ -195,11 +194,11 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
File pluginFile = new File(env.getPluginUrl().toURI());
- Plugin plugin = new Plugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
+ ServerPlugin plugin = new ServerPlugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor.getDescription(), "",
MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor
- .getVersion(), PluginDeploymentType.SERVER, pluginConfig, scheduledJobsConfig, System
- .currentTimeMillis(), System.currentTimeMillis());
+ .getVersion(), pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
diff --git a/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java b/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
index ac89223..0487d19 100644
--- a/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
+++ b/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
@@ -48,7 +48,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.artifact.versioning.ComparableVersion;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -103,7 +103,7 @@ public abstract class ServerPluginDescriptorUtil {
* <code>null</code> is returned if they are the same (i.e. they have the same MD5)
* @throws IllegalArgumentException if the two plugins have different logical names
*/
- public static Plugin determineObsoletePlugin(Plugin plugin1, Plugin plugin2) {
+ public static ServerPlugin determineObsoletePlugin(ServerPlugin plugin1, ServerPlugin plugin2) {
if (!plugin1.getName().equals(plugin2.getName())) {
throw new IllegalArgumentException("The two plugins don't have the same name:" + plugin1 + ":" + plugin2);
}
commit 00d502f86cea6a401c172316e395b6ff76c41d98
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 16:44:26 2009 -0500
start to adding JPA discriminators to plugin entities
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
new file mode 100644
index 0000000..757fa6a
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
@@ -0,0 +1,458 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.domain.plugin;
+
+import java.io.ByteArrayInputStream;
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.PrePersist;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.jetbrains.annotations.NotNull;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.util.MessageDigestGenerator;
+
+/**
+ * Base plugin implementation that agent and server plugin implementations extend.
+ *
+ * @author John Mazzitelli
+ */
+@DiscriminatorColumn(name = "DEPLOYMENT")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@Entity
+@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_PLUGIN_ID_SEQ")
+@Table(name = Plugin.TABLE_NAME)
+public class AbstractPlugin implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public static final String TABLE_NAME = "RHQ_PLUGIN";
+
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
+ @Id
+ private int id;
+
+ @Column(name = "DEPLOYMENT", nullable = false, insertable = false, updatable = false)
+ @Enumerated(EnumType.STRING)
+ private PluginDeploymentType deployment;
+
+ @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID")
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ private Configuration scheduledJobsConfiguration;
+
+ @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName = "ID")
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ private Configuration pluginConfiguration;
+
+ @Column(name = "NAME", nullable = false)
+ private String name;
+
+ @Column(name = "DISPLAY_NAME", nullable = false)
+ private String displayName;
+
+ @Column(name = "DESCRIPTION", nullable = true)
+ private String description;
+
+ @Column(name = "ENABLED", nullable = false)
+ private boolean enabled = true;
+
+ @Column(name = "STATUS", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private PluginStatusType status = PluginStatusType.INSTALLED;
+
+ @Column(name = "HELP", nullable = true)
+ private String help;
+
+ @Column(name = "VERSION", nullable = true)
+ private String version;
+
+ @Column(name = "AMPS_VERSION", nullable = true)
+ private String ampsVersion;
+
+ @Column(name = "PATH", nullable = false)
+ private String path;
+
+ @Column(name = "MD5", nullable = false)
+ private String md5;
+
+ @Column(name = "CTIME", nullable = false)
+ private long ctime;
+
+ @Column(name = "MTIME", nullable = false)
+ private long mtime;
+
+ @Column(name = "CONTENT", nullable = true)
+ private byte[] content;
+
+ public AbstractPlugin() {
+ }
+
+ /**
+ * Constructor for {@link Plugin}.
+ *
+ * @param name the logical name of the plugin
+ * @param path the actual filename of the plugin jar (see {@link #getPath()})
+ */
+ public AbstractPlugin(@NotNull String name, String path) {
+ this.name = name;
+ this.path = path;
+ }
+
+ /**
+ * Constructor for {@link Plugin}.
+ * Note that this allows you to provide an MD5 without providing the plugin's
+ * actual content. If you wish to persist this entity in the database, you should
+ * either provide the {@link #setContent(byte[]) content} or update the entity
+ * later by streaming the file content to the content column.
+ *
+ * @param name the logical name of the plugin
+ * @param path the actual filename of the plugin jar (see {@link #getPath()})
+ * @param md5 the MD5 hash string of the plugin jar contents
+ */
+ public AbstractPlugin(String name, String path, String md5) {
+ this.name = name;
+ this.path = path;
+ this.md5 = md5;
+ }
+
+ /**
+ * Constructor for {@link Plugin}.
+ *
+ * @param name the logical name of the plugin
+ * @param path the actual filename of the plugin jar (see {@link #getPath()})
+ * @param content the actual jar file contents (the MD5 hash string will be generated from this)
+ */
+ public AbstractPlugin(String name, String path, byte[] content) {
+ this.name = name;
+ this.path = path;
+ this.content = content;
+
+ try {
+ ByteArrayInputStream stream = new ByteArrayInputStream(content);
+ this.md5 = MessageDigestGenerator.getDigestString(stream);
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot determine plugin's MD5!", e);
+ }
+ }
+
+ /**
+ * Constructor that can build the full object except for the content byte array.
+ * This is used mainly for the named queries that want to return a Plugin object
+ * but does not eagerly load in the content array.
+ *
+ * @param id
+ * @param name
+ * @param path
+ * @param displayName
+ * @param enabled
+ * @param status
+ * @param description
+ * @param help
+ * @param md5
+ * @param version
+ * @param ampsVersion
+ * @param deployment
+ * @param pluginConfig
+ * @param scheduledJobsConfig
+ * @param ctime
+ * @param mtime
+ */
+ public AbstractPlugin(int id, String name, String path, String displayName, boolean enabled,
+ PluginStatusType status, String description, String help, String md5, String version, String ampsVersion,
+ PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
+ long mtime) {
+ this.id = id;
+ this.name = name;
+ this.path = path;
+ this.displayName = displayName;
+ this.enabled = enabled;
+ this.status = status;
+ this.description = description;
+ this.help = help;
+ this.md5 = md5;
+ this.version = version;
+ this.ampsVersion = ampsVersion;
+ this.deployment = deployment;
+ this.pluginConfiguration = pluginConfig;
+ this.scheduledJobsConfiguration = scheduledJobsConfig;
+ this.ctime = ctime;
+ this.mtime = mtime;
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * See the javadoc of {@link #getMtime()} for
+ * information about this field and its relationship
+ * with "mtime".
+ *
+ * @return the time when this entity was persisted
+ */
+ public long getCtime() {
+ return this.ctime;
+ }
+
+ public void setCtime(long ctime) {
+ this.ctime = ctime;
+ }
+
+ /**
+ * The "mtime" of the plugin has slightly different semantics
+ * than other "mtime" values found elsewhere. The "mtime"
+ * will typically be the time that the content field was modified,
+ * not necessarily the time when any field was modified. In other
+ * words, look at "mtime" if you want to know when the actual
+ * plugin content was last updated. Note that this "mtime" may in
+ * fact be the last modified time of the plugin file from which
+ * the content came from - this means mtime may actually be earlier
+ * in time than "ctime" (in the case when the plugin jar file was
+ * last touched prior to this entity being created).
+ *
+ * Note that the "ctime" field semantics remains the same as always,
+ * it is the time when this entity was originally created.
+ *
+ * @return mtime of the content
+ */
+ public long getMtime() {
+ return this.mtime;
+ }
+
+ /**
+ * This entity does not automatically update the "mtime" when it
+ * is updated via a PreUpdate annotation, therefore, the owner of
+ * this entity needs to explicitly call this setter in order to
+ * set the "mtime". You normally set this value to the last
+ * modified time of the plugin jar that provided
+ * this plugin entity's {@link #getContent() content}.
+ *
+ * @param mtime
+ */
+ public void setMtime(long mtime) {
+ this.mtime = mtime;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public PluginStatusType getStatus() {
+ return status;
+ }
+
+ public void setStatus(PluginStatusType status) {
+ this.status = status;
+ if (this.status == PluginStatusType.DELETED) {
+ this.enabled = false;
+ }
+ }
+
+ public String getHelp() {
+ return help;
+ }
+
+ public void setHelp(String help) {
+ this.help = help;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getAmpsVersion() {
+ return ampsVersion;
+ }
+
+ public void setAmpsVersion(String ampsVersion) {
+ this.ampsVersion = ampsVersion;
+ }
+
+ public String getMd5() {
+ return md5;
+ }
+
+ public void setMd5(String md5) {
+ this.md5 = md5;
+ }
+
+ public String getMD5() {
+ return getMd5();
+ }
+
+ public void setMD5(String md5) {
+ setMd5(md5);
+ }
+
+ /**
+ * Returns the actual name of the plugin jar. This is not the absolute path, in fact, it does not include any
+ * directory paths. It is strictly the name of the plugin jar as found on the file system (aka the filename).
+ *
+ * @return plugin filename
+ */
+ public String getPath() {
+ return this.path;
+ }
+
+ /**
+ * Ensure that the path being set does not include any directory names. The plugin path is the filename. See
+ * {@link #getPath()}.
+ *
+ * @param path the filename of the plugin, not including directory names
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Indicates how the plugin gets deployed (e.g. running in the agent or in the server).
+ *
+ * @return plugin deployment type
+ */
+ public PluginDeploymentType getDeployment() {
+ return deployment;
+ }
+
+ public void setDeployment(PluginDeploymentType deployment) {
+ this.deployment = deployment;
+ }
+
+ /**
+ * If the plugin has jobs associated with it, this is the configuration for those jobs.
+ *
+ * @return scheduled job configuration for jobs that the plugin defined.
+ */
+ public Configuration getScheduledJobsConfiguration() {
+ return scheduledJobsConfiguration;
+ }
+
+ public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
+ this.scheduledJobsConfiguration = scheduledJobsConfiguration;
+ }
+
+ /**
+ * If the plugin, itself, has configuration associated with it, this is that configuration.
+ *
+ * @return the configuration associated with the plugin itself
+ */
+ public Configuration getPluginConfiguration() {
+ return pluginConfiguration;
+ }
+
+ public void setPluginConfiguration(Configuration pluginConfiguration) {
+ this.pluginConfiguration = pluginConfiguration;
+ }
+
+ /**
+ * Returns the actual content of the plugin file. Be careful calling this
+ * in an entity context - the entire plugin file content will be loaded in
+ * memory (which may trigger an OutOfMemoryError if the file is very large).
+ *
+ * @return the content of the plugin file
+ */
+ public byte[] getContent() {
+ return this.content;
+ }
+
+ public void setContent(byte[] content) {
+ this.content = content;
+ }
+
+ @PrePersist
+ void onPersist() {
+ this.ctime = System.currentTimeMillis();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || !(obj instanceof AbstractPlugin)) {
+ return false;
+ }
+
+ AbstractPlugin that = (AbstractPlugin) obj;
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "[id=" + id + ", name=" + name + ", md5=" + md5 + "]";
+ }
+}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index 4047d10..1b4c693 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -22,30 +22,14 @@
*/
package org.rhq.core.domain.plugin;
-import java.io.ByteArrayInputStream;
-import java.io.Serializable;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
-import javax.persistence.OneToOne;
-import javax.persistence.PrePersist;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
import org.jetbrains.annotations.NotNull;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.util.MessageDigestGenerator;
/**
* An agent plugin.
@@ -53,21 +37,24 @@ import org.rhq.core.util.MessageDigestGenerator;
* This object contains information about the plugin jar itself (e.g. its name and MD5).
* It may also contain the jar contents ({@link #getContent()}).
*/
-@Entity
+@DiscriminatorValue("AGENT")
@NamedQueries( {
//
- @NamedQuery(name = Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE, query = "" //
+ // helps you determine if a plugin is installed or was deleted
+ @NamedQuery(name = Plugin.QUERY_GET_STATUS_BY_NAME, query = "" //
+ " SELECT p.status " //
+ " FROM Plugin AS p " //
- + " WHERE p.name = :name AND p.deployment = :type "), //
+ + " WHERE p.name = :name)"), //
- @NamedQuery(name = Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE, query = "" //
+ // helps you determine which installed plugins are enabled or disabled
+ @NamedQuery(name = Plugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
+ " SELECT p.name " //
+ " FROM Plugin AS p " //
- + " WHERE p.enabled = :enabled AND p.deployment = :type AND p.status = 'INSTALLED' "), //
+ + " WHERE p.enabled = :enabled " //
+ + " AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_BY_IDS_AND_TYPE, query = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_BY_IDS, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -88,7 +75,8 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.id IN (:ids) AND p.deployment = :type AND p.status = 'INSTALLED' "), //
+ + " WHERE p.id IN (:ids) " //
+ + " AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_BY_NAME, query = "" //
@@ -112,11 +100,12 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name AND p.status = 'INSTALLED' "), //
+ + " WHERE p.name=:name " //
+ + " AND p.status = 'INSTALLED' "), //
// gets the plugin, even if it is deleted
// this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE, query = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -137,34 +126,11 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name AND p.deployment = :type "), //
-
- // this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_ALL_AGENT, query = "" //
- + " SELECT new org.rhq.core.domain.plugin.Plugin( " //
- + " p.id, " //
- + " p.name, " //
- + " p.path, " //
- + " p.displayName, " //
- + " p.enabled, " //
- + " p.status, " //
- + " p.description, " //
- + " p.help, " //
- + " p.md5, " //
- + " p.version, " //
- + " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
- + " p.ctime, " //
- + " p.mtime) " //
- + " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.deployment = 'AGENT' AND p.status = 'INSTALLED' "), //
+ + " WHERE p.name=:name "), //
+ // finds all installed - ignores those plugins marked as deleted
// this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_ALL_SERVER, query = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_ALL_INSTALLED, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -185,7 +151,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.deployment = 'SERVER' AND p.status = 'INSTALLED' "), //
+ + " WHERE p.status = 'INSTALLED' "), //
// this query is how you enable and disable plugins
@NamedQuery(name = Plugin.UPDATE_PLUGINS_ENABLED_BY_IDS, query = "" //
@@ -221,394 +187,60 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " JOIN res.resourceType rt " //
+ " WHERE ( rt.category = :resourceCategory OR :resourceCategory IS NULL ) " //
+ " AND ( rt.name = :resourceTypeName OR :resourceTypeName IS NULL ) ) " //
- + "ORDER BY p.name") })
-@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_PLUGIN_ID_SEQ")
-@Table(name = Plugin.TABLE_NAME)
-public class Plugin implements Serializable {
+ + " ORDER BY p.name") //
+})
+@Entity
+public class Plugin extends AbstractPlugin {
private static final long serialVersionUID = 1L;
- public static final String TABLE_NAME = "RHQ_PLUGIN";
-
- public static final String QUERY_FIND_BY_RESOURCE_TYPE_AND_CATEGORY = "Plugin.findByResourceType";
- public static final String QUERY_FIND_ALL_AGENT = "Plugin.findAllAgent";
- public static final String QUERY_FIND_ALL_SERVER = "Plugin.findAllServer";
+ public static final String QUERY_GET_STATUS_BY_NAME = "Plugin.queryGetStatusByName";
+ public static final String QUERY_GET_NAMES_BY_ENABLED = "Plugin.queryGetNamesByEnabled";
+ public static final String QUERY_FIND_BY_IDS = "Plugin.findByIds";
public static final String QUERY_FIND_BY_NAME = "Plugin.findByName";
- public static final String QUERY_FIND_ANY_BY_NAME_AND_TYPE = "Plugin.findAnyByNameAndType";
- public static final String QUERY_FIND_BY_IDS_AND_TYPE = "Plugin.findByIdsAndType";
- public static final String QUERY_GET_NAMES_BY_ENABLED_AND_TYPE = "Plugin.findByEnabledAndType";
- public static final String QUERY_GET_STATUS_BY_NAME_AND_TYPE = "Plugin.getStatusByNameAndType";
+ public static final String QUERY_FIND_ANY_BY_NAME = "Plugin.findAnyByName";
+ public static final String QUERY_FIND_ALL_INSTALLED = "Plugin.findAllInstalled";
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "Plugin.updatePluginsEnabledByIds";
-
- @Column(name = "ID", nullable = false)
- @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
- @Id
- private int id;
-
- @Column(name = "DEPLOYMENT", nullable = false)
- @Enumerated(EnumType.STRING)
- private PluginDeploymentType deployment = PluginDeploymentType.AGENT; // assume agent
-
- @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
- private Configuration scheduledJobsConfiguration;
-
- @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName = "ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
- private Configuration pluginConfiguration;
-
- @Column(name = "NAME", nullable = false)
- private String name;
-
- @Column(name = "DISPLAY_NAME", nullable = false)
- private String displayName;
-
- @Column(name = "DESCRIPTION", nullable = true)
- private String description;
-
- @Column(name = "ENABLED", nullable = false)
- private boolean enabled = true;
-
- @Column(name = "STATUS", nullable = false)
- @Enumerated(EnumType.STRING)
- private PluginStatusType status = PluginStatusType.INSTALLED;
-
- @Column(name = "HELP", nullable = true)
- private String help;
-
- @Column(name = "VERSION", nullable = true)
- private String version;
-
- @Column(name = "AMPS_VERSION", nullable = true)
- private String ampsVersion;
-
- @Column(name = "PATH", nullable = false)
- private String path;
-
- @Column(name = "MD5", nullable = false)
- private String md5;
-
- @Column(name = "CTIME", nullable = false)
- private long ctime;
-
- @Column(name = "MTIME", nullable = false)
- private long mtime;
-
- @Column(name = "CONTENT", nullable = true)
- private byte[] content;
+ public static final String QUERY_FIND_BY_RESOURCE_TYPE_AND_CATEGORY = "Plugin.findByResourceType";
public Plugin() {
+ super();
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor for {@link Plugin}.
- *
- * @param name the logical name of the plugin
- * @param path the actual filename of the plugin jar (see {@link #getPath()})
- */
public Plugin(@NotNull String name, String path) {
- this.name = name;
- this.path = path;
+ super(name, path);
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor for {@link Plugin}.
- * Note that this allows you to provide an MD5 without providing the plugin's
- * actual content. If you wish to persist this entity in the database, you should
- * either provide the {@link #setContent(byte[]) content} or update the entity
- * later by streaming the file content to the content column.
- *
- * @param name the logical name of the plugin
- * @param path the actual filename of the plugin jar (see {@link #getPath()})
- * @param md5 the MD5 hash string of the plugin jar contents
- */
public Plugin(String name, String path, String md5) {
- this.name = name;
- this.path = path;
- this.md5 = md5;
+ super(name, path, md5);
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor for {@link Plugin}.
- *
- * @param name the logical name of the plugin
- * @param path the actual filename of the plugin jar (see {@link #getPath()})
- * @param content the actual jar file contents (the MD5 hash string will be generated from this)
- */
public Plugin(String name, String path, byte[] content) {
- this.name = name;
- this.path = path;
- this.content = content;
-
- try {
- ByteArrayInputStream stream = new ByteArrayInputStream(content);
- this.md5 = MessageDigestGenerator.getDigestString(stream);
- } catch (Exception e) {
- throw new RuntimeException("Cannot determine plugin's MD5!", e);
- }
+ super(name, path, content);
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor that can build the full object except for the content byte array.
- * This is used mainly for the named queries that want to return a Plugin object
- * but does not eagerly load in the content array.
- *
- * @param id
- * @param name
- * @param path
- * @param displayName
- * @param enabled
- * @param status
- * @param description
- * @param help
- * @param md5
- * @param version
- * @param ampsVersion
- * @param deployment
- * @param pluginConfig
- * @param scheduledJobsConfig
- * @param ctime
- * @param mtime
- */
public Plugin(int id, String name, String path, String displayName, boolean enabled, PluginStatusType status,
String description, String help, String md5, String version, String ampsVersion,
PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
long mtime) {
- this.id = id;
- this.name = name;
- this.path = path;
- this.displayName = displayName;
- this.enabled = enabled;
- this.status = status;
- this.description = description;
- this.help = help;
- this.md5 = md5;
- this.version = version;
- this.ampsVersion = ampsVersion;
- this.deployment = deployment;
- this.pluginConfiguration = pluginConfig;
- this.scheduledJobsConfiguration = scheduledJobsConfig;
- this.ctime = ctime;
- this.mtime = mtime;
- }
-
- public int getId() {
- return this.id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return this.name;
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
+ pluginConfig, scheduledJobsConfig, ctime, mtime);
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * See the javadoc of {@link #getMtime()} for
- * information about this field and its relationship
- * with "mtime".
- *
- * @return the time when this entity was persisted
- */
- public long getCtime() {
- return this.ctime;
- }
-
- public void setCtime(long ctime) {
- this.ctime = ctime;
- }
-
- /**
- * The "mtime" of the plugin has slightly different semantics
- * than other "mtime" values found elsewhere. The "mtime"
- * will typically be the time that the content field was modified,
- * not necessarily the time when any field was modified. In other
- * words, look at "mtime" if you want to know when the actual
- * plugin content was last updated. Note that this "mtime" may in
- * fact be the last modified time of the plugin file from which
- * the content came from - this means mtime may actually be earlier
- * in time than "ctime" (in the case when the plugin jar file was
- * last touched prior to this entity being created).
- *
- * Note that the "ctime" field semantics remains the same as always,
- * it is the time when this entity was originally created.
- *
- * @return mtime of the content
- */
- public long getMtime() {
- return this.mtime;
- }
-
- /**
- * This entity does not automatically update the "mtime" when it
- * is updated via a PreUpdate annotation, therefore, the owner of
- * this entity needs to explicitly call this setter in order to
- * set the "mtime". You normally set this value to the last
- * modified time of the plugin jar that provided
- * this plugin entity's {@link #getContent() content}.
- *
- * @param mtime
- */
- public void setMtime(long mtime) {
- this.mtime = mtime;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public PluginStatusType getStatus() {
- return status;
- }
-
- public void setStatus(PluginStatusType status) {
- this.status = status;
- if (this.status == PluginStatusType.DELETED) {
- this.enabled = false;
+ if (deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("Plugin must only ever be of deployment type == AGENT: " + deployment);
}
}
- public String getHelp() {
- return help;
- }
-
- public void setHelp(String help) {
- this.help = help;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getAmpsVersion() {
- return ampsVersion;
- }
-
- public void setAmpsVersion(String ampsVersion) {
- this.ampsVersion = ampsVersion;
- }
-
- public String getMd5() {
- return md5;
- }
-
- public void setMd5(String md5) {
- this.md5 = md5;
- }
-
- public String getMD5() {
- return getMd5();
- }
-
- public void setMD5(String md5) {
- setMd5(md5);
- }
-
- /**
- * Returns the actual name of the plugin jar. This is not the absolute path, in fact, it does not include any
- * directory paths. It is strictly the name of the plugin jar as found on the file system (aka the filename).
- *
- * @return plugin filename
- */
- public String getPath() {
- return this.path;
- }
-
- /**
- * Ensure that the path being set does not include any directory names. The plugin path is the filename. See
- * {@link #getPath()}.
- *
- * @param path the filename of the plugin, not including directory names
- */
- public void setPath(String path) {
- this.path = path;
- }
-
- /**
- * Indicates how the plugin gets deployed (e.g. running in the agent or in the server).
- *
- * @return plugin deployment type
- */
- public PluginDeploymentType getDeployment() {
- return deployment;
- }
-
+ @Override
public void setDeployment(PluginDeploymentType deployment) {
- this.deployment = deployment;
- }
-
- /**
- * If the plugin has jobs associated with it, this is the configuration for those jobs.
- *
- * @return scheduled job configuration for jobs that the plugin defined.
- */
- public Configuration getScheduledJobsConfiguration() {
- return scheduledJobsConfiguration;
- }
-
- public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
- this.scheduledJobsConfiguration = scheduledJobsConfiguration;
- }
-
- /**
- * If the plugin, itself, has configuration associated with it, this is that configuration.
- *
- * @return the configuration associated with the plugin itself
- */
- public Configuration getPluginConfiguration() {
- return pluginConfiguration;
- }
-
- public void setPluginConfiguration(Configuration pluginConfiguration) {
- this.pluginConfiguration = pluginConfiguration;
- }
-
- /**
- * Returns the actual content of the plugin file. Be careful calling this
- * in an entity context - the entire plugin file content will be loaded in
- * memory (which may trigger an OutOfMemoryError if the file is very large).
- *
- * @return the content of the plugin file
- */
- public byte[] getContent() {
- return this.content;
- }
-
- public void setContent(byte[] content) {
- this.content = content;
- }
-
- @PrePersist
- void onPersist() {
- this.ctime = System.currentTimeMillis();
+ if (deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("Plugin can only ever have deployment type of AGENT: " + deployment);
+ }
+ super.setDeployment(deployment);
}
@Override
@@ -621,17 +253,16 @@ public class Plugin implements Serializable {
return false;
}
- Plugin that = (Plugin) obj;
- return name.equals(that.name);
+ return super.equals(obj);
}
@Override
public int hashCode() {
- return name.hashCode();
+ return super.hashCode();
}
@Override
public String toString() {
- return "Plugin[id=" + id + ", name=" + name + ", md5=" + md5 + "]";
+ return "AgentPlugin " + super.toString();
}
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
new file mode 100644
index 0000000..0c406c3
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -0,0 +1,240 @@
+/*
+ * 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.domain.plugin;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.jetbrains.annotations.NotNull;
+
+import org.rhq.core.domain.configuration.Configuration;
+
+/**
+ * A server plugin.
+ *
+ * This object contains information about the plugin jar itself (e.g. its name and MD5).
+ * It may also contain the jar contents ({@link #getContent()}).
+ */
+@DiscriminatorValue("SERVER")
+@NamedQueries( {
+//
+ // helps you determine if a plugin is installed or was deleted
+ @NamedQuery(name = ServerPlugin.QUERY_GET_STATUS_BY_NAME, query = "" //
+ + " SELECT p.status " //
+ + " FROM ServerPlugin AS p " //
+ + " WHERE p.name = :name)"), //
+
+ // helps you determine which installed plugins are enabled or disabled
+ @NamedQuery(name = ServerPlugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
+ + " SELECT p.name " //
+ + " FROM ServerPlugin AS p " //
+ + " WHERE p.enabled = :enabled " //
+ + " AND p.status = 'INSTALLED' "), //
+
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_BY_IDS, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.id IN (:ids) " //
+ + " AND p.status = 'INSTALLED' "), //
+
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_BY_NAME, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.name=:name " //
+ + " AND p.status = 'INSTALLED' "), //
+
+ // gets the plugin, even if it is deleted
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_ANY_BY_NAME, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.name=:name "), //
+
+ // finds all installed - ignores those plugins marked as deleted
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_ALL_INSTALLED, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.status = 'INSTALLED' "), //
+
+ // this query is how you enable and disable plugins
+ @NamedQuery(name = ServerPlugin.UPDATE_PLUGINS_ENABLED_BY_IDS, query = "" //
+ + "UPDATE ServerPlugin p " //
+ + " SET p.enabled = :enabled " //
+ + " WHERE p.id IN (:ids)")
+
+})
+@Entity
+public class ServerPlugin extends AbstractPlugin {
+ private static final long serialVersionUID = 1L;
+
+ public static final String QUERY_GET_STATUS_BY_NAME = "ServerPlugin.queryGetStatusByName";
+ public static final String QUERY_GET_NAMES_BY_ENABLED = "ServerPlugin.queryGetNamesByEnabled";
+ public static final String QUERY_FIND_BY_IDS = "ServerPlugin.findByIds";
+ public static final String QUERY_FIND_BY_NAME = "ServerPlugin.findByName";
+ public static final String QUERY_FIND_ANY_BY_NAME = "ServerPlugin.findAnyByName";
+ public static final String QUERY_FIND_ALL_INSTALLED = "ServerPlugin.findAllInstalled";
+ public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "ServerPlugin.updatePluginsEnabledByIds";
+
+ public ServerPlugin() {
+ super();
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(@NotNull String name, String path) {
+ super(name, path);
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(String name, String path, String md5) {
+ super(name, path, md5);
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(String name, String path, byte[] content) {
+ super(name, path, content);
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(int id, String name, String path, String displayName, boolean enabled, PluginStatusType status,
+ String description, String help, String md5, String version, String ampsVersion,
+ PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
+ long mtime) {
+
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
+ pluginConfig, scheduledJobsConfig, ctime, mtime);
+
+ if (deployment != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("ServerPlugin must only ever be of deployment type == SERVER: "
+ + deployment);
+ }
+ }
+
+ @Override
+ public void setDeployment(PluginDeploymentType deployment) {
+ if (deployment != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("ServerPlugin can only ever have deployment type of SERVER: "
+ + deployment);
+ }
+ super.setDeployment(deployment);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || !(obj instanceof ServerPlugin)) {
+ return false;
+ }
+
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "ServerPlugin " + super.toString();
+ }
+}
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index 729f7c2..be2deb3 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -73,9 +73,8 @@ public class PluginTest extends AbstractEJB3Test {
plugin.setHelp(null);
plugin.setContent(content);
- Query q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
assert q.getResultList().size() == 0; // not in the db yet
em.persist(plugin);
@@ -84,9 +83,8 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getPluginConfiguration() == null : "there was no config that should have been here";
assert plugin.getScheduledJobsConfiguration() == null : "there was no config that should have been here";
- q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
assert ((PluginStatusType) q.getSingleResult()) == PluginStatusType.INSTALLED;
plugin = em.find(Plugin.class, id);
@@ -100,7 +98,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getMD5().equals(md5);
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
- assert plugin.getDeployment() == PluginDeploymentType.AGENT; // default is agent
+ assert plugin.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration() == null;
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
@@ -116,7 +114,7 @@ public class PluginTest extends AbstractEJB3Test {
String ampsVersion = "2.1";
String description = "description-UPDATED";
String help = "help-UPDATED";
- PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ PluginDeploymentType deployment = PluginDeploymentType.AGENT;
Configuration pluginConfig = new Configuration();
Configuration jobsConfig = new Configuration();
pluginConfig.put(new PropertySimple("first", "last"));
@@ -181,7 +179,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion().equals(version);
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
- assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
@@ -193,9 +191,8 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
Plugin doomed = (Plugin) q.getSingleResult();
doomed = em.getReference(Plugin.class, doomed.getId());
em.remove(doomed);
@@ -250,7 +247,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getMD5().equals(md5);
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
- assert plugin.getDeployment() == PluginDeploymentType.AGENT; // default is agent
+ assert plugin.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration() == null;
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
@@ -284,7 +281,7 @@ public class PluginTest extends AbstractEJB3Test {
String help = "the test help string is here";
byte[] content = "this is the test content".getBytes();
String md5 = MessageDigestGenerator.getDigestString(new String(content));
- PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ PluginDeploymentType deployment = PluginDeploymentType.AGENT;
String ampsVersion = "1.2";
Configuration pluginConfig = new Configuration();
@@ -345,9 +342,8 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getHelp().equals(help);
assert plugin.getContent() == null;
- query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
- query.setParameter("type", plugin.getDeployment());
plugin = (Plugin) query.getSingleResult();
assert plugin != null;
assert plugin.getId() > 0;
@@ -365,7 +361,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getHelp().equals(help);
assert plugin.getContent() == null;
- query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
List<Plugin> all = query.getResultList();
boolean got_it = false;
for (Plugin p : all) {
@@ -399,13 +395,12 @@ public class PluginTest extends AbstractEJB3Test {
List<?> results = query.getResultList();
assert results.size() == 0;
- query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
- query.setParameter("type", plugin.getDeployment());
results = query.getResultList();
assert results.size() == 0;
- query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
results = query.getResultList();
assert results.size() == 0;
@@ -513,9 +508,8 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
Plugin doomed = (Plugin) q.getSingleResult();
doomed = em.getReference(Plugin.class, doomed.getId());
em.remove(doomed);
@@ -628,9 +622,8 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
Plugin doomed = (Plugin) q.getSingleResult();
doomed = em.getReference(Plugin.class, doomed.getId());
em.remove(doomed);
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java
new file mode 100644
index 0000000..c8acf79
--- /dev/null
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java
@@ -0,0 +1,650 @@
+/*
+ * 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.domain.resource.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.sql.DataSource;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.domain.test.AbstractEJB3Test;
+import org.rhq.core.util.MessageDigestGenerator;
+import org.rhq.core.util.stream.StreamUtil;
+
+@Test
+public class ServerPluginTest extends AbstractEJB3Test {
+ public void testUpdate() throws Throwable {
+ boolean done = false;
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ int id;
+
+ String name = "ServerPluginTest-testUpdate";
+ String path = "/test/Update";
+ String displayName = "Server Plugin Test - testUpdate";
+ boolean enabled = true;
+ PluginStatusType status = PluginStatusType.INSTALLED;
+ String md5 = "abcdef";
+ byte[] content = "the content is here".getBytes();
+
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setStatus(status);
+ plugin.setMD5(md5);
+ plugin.setVersion(null);
+ plugin.setDescription(null);
+ plugin.setHelp(null);
+ plugin.setContent(content);
+
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ assert q.getResultList().size() == 0; // not in the db yet
+
+ em.persist(plugin);
+ id = plugin.getId();
+ assert id > 0;
+ assert plugin.getPluginConfiguration() == null : "there was no config that should have been here";
+ assert plugin.getScheduledJobsConfiguration() == null : "there was no config that should have been here";
+
+ q = em.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ assert ((PluginStatusType) q.getSingleResult()) == PluginStatusType.INSTALLED;
+
+ plugin = em.find(ServerPlugin.class, id);
+ assert plugin != null;
+ assert plugin.getId() == id;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion() == null;
+ assert plugin.getDescription() == null;
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getPluginConfiguration() == null;
+ assert plugin.getScheduledJobsConfiguration() == null;
+ assert plugin.getHelp() == null;
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ // everything persisted fine, let's update it and see the content is left alone
+ name = name + "-UPDATED";
+ path = path + "-UPDATED";
+ displayName = displayName + "-UPDATED";
+ enabled = !enabled;
+ md5 = md5 + "00000";
+ String version = "version-UPDATED";
+ String ampsVersion = "2.1";
+ String description = "description-UPDATED";
+ String help = "help-UPDATED";
+ PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ Configuration pluginConfig = new Configuration();
+ Configuration jobsConfig = new Configuration();
+ pluginConfig.put(new PropertySimple("first", "last"));
+ jobsConfig.put(new PropertySimple("aaa", "bbb"));
+
+ em.close();
+ getTransactionManager().commit(); // we will be doing an update - needs to be in own tx
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ em.persist(pluginConfig);
+ em.persist(jobsConfig);
+ em.flush(); // gotta get those two persists to flush to the DB
+
+ // do what ServerPluginsBean.updateServerPluginExceptContent does
+ Configuration config = plugin.getPluginConfiguration();
+ if (config != null) {
+ config = em.merge(config);
+ plugin.setPluginConfiguration(config);
+ }
+ config = plugin.getScheduledJobsConfiguration();
+ if (config != null) {
+ config = em.merge(config);
+ plugin.setScheduledJobsConfiguration(config);
+ }
+
+ ServerPlugin pluginEntity = em.getReference(ServerPlugin.class, plugin.getId());
+ pluginEntity.setName(name);
+ pluginEntity.setPath(path);
+ pluginEntity.setDisplayName(displayName);
+ pluginEntity.setEnabled(enabled);
+ pluginEntity.setStatus(status);
+ pluginEntity.setMd5(md5);
+ pluginEntity.setVersion(version);
+ pluginEntity.setAmpsVersion(ampsVersion);
+ pluginEntity.setDeployment(deployment);
+ pluginEntity.setPluginConfiguration(pluginConfig);
+ pluginEntity.setScheduledJobsConfiguration(jobsConfig);
+ pluginEntity.setDescription(description);
+ pluginEntity.setHelp(help);
+ pluginEntity.setMtime(System.currentTimeMillis());
+
+ try {
+ em.flush(); // make sure we push this out to the DB now
+ } catch (Exception e) {
+ throw new Exception("Failed to update a plugin that matches [" + plugin + "]", e);
+ }
+
+ em.close();
+ getTransactionManager().commit(); // must commit now
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ plugin = em.find(ServerPlugin.class, id);
+ assert plugin != null;
+ assert plugin.getId() == id;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ // and what we really want to test - ensure the content remained intact after the update
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ // clean up - delete our test plugin
+ em.close();
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+ q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
+ doomed = em.getReference(ServerPlugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the plugin";
+ em.close();
+ getTransactionManager().commit();
+ done = true;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ throw t;
+ } finally {
+ if (!done) {
+ getTransactionManager().rollback();
+ }
+ }
+ }
+
+ public void testPersistMinimal() throws Exception {
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ String name = "ServerPluginTest-testPersist";
+ String path = "/test/Persist";
+ String displayName = "Server Plugin Test - testPersist";
+ boolean enabled = true;
+ PluginStatusType status = PluginStatusType.INSTALLED;
+ String md5 = "abcdef";
+
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setStatus(status);
+ plugin.setMD5(md5);
+
+ // the following are the only nullable fields
+ plugin.setVersion(null);
+ plugin.setDescription(null);
+ plugin.setHelp(null);
+ plugin.setContent(null);
+
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion() == null;
+ assert plugin.getDescription() == null;
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getPluginConfiguration() == null;
+ assert plugin.getScheduledJobsConfiguration() == null;
+ assert plugin.getHelp() == null;
+ assert plugin.getContent() == null;
+
+ // side check - see that "deleting" a plugin also sets enabled to false
+ assert plugin.isEnabled() == true;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ plugin.setStatus(PluginStatusType.DELETED);
+ assert plugin.getStatus() == PluginStatusType.DELETED;
+ assert plugin.isEnabled() == false;
+ plugin = em.merge(plugin);
+ assert plugin.getStatus() == PluginStatusType.DELETED;
+ assert plugin.isEnabled() == false;
+
+ } finally {
+ getTransactionManager().rollback();
+ }
+ }
+
+ public void testPersistFull() throws Exception {
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ String name = "ServerPluginTest-testPersist";
+ String path = "/test/Persist";
+ String displayName = "Server Plugin Test - testPersist";
+ boolean enabled = true;
+ String version = "1.0";
+ String description = "the test description is here";
+ String help = "the test help string is here";
+ byte[] content = "this is the test content".getBytes();
+ String md5 = MessageDigestGenerator.getDigestString(new String(content));
+ PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ String ampsVersion = "1.2";
+
+ Configuration pluginConfig = new Configuration();
+ Configuration jobsConfig = new Configuration();
+ pluginConfig.put(new PropertySimple("first", "last"));
+ jobsConfig.put(new PropertySimple("aaa", "bbb"));
+
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setMD5(md5);
+ plugin.setVersion(version);
+ plugin.setAmpsVersion(ampsVersion);
+ plugin.setDescription(description);
+ plugin.setHelp(help);
+ plugin.setContent(content);
+ plugin.setDeployment(deployment);
+ plugin.setPluginConfiguration(pluginConfig);
+ plugin.setScheduledJobsConfiguration(jobsConfig);
+
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ // test our queries that purposefully do not load in the content blob
+ Query query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", name);
+ plugin = (ServerPlugin) query.getSingleResult();
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ assert plugin.getContent() == null;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
+ query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
+ plugin = (ServerPlugin) query.getSingleResult();
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ assert plugin.getContent() == null;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
+ List<ServerPlugin> all = query.getResultList();
+ boolean got_it = false;
+ for (ServerPlugin p : all) {
+ if (p.getName().equals(name)) {
+ got_it = true;
+ assert p.getId() > 0;
+ assert p.getName().equals(name);
+ assert p.getPath().equals(path);
+ assert p.getDisplayName().equals(displayName);
+ assert p.isEnabled() == enabled;
+ assert p.getMD5().equals(md5);
+ assert p.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert p.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert p.getHelp().equals(help);
+ assert p.getContent() == null;
+ break;
+ }
+ }
+ assert got_it : "findAll query failed to get our plugin";
+
+ // mark a plugin deleted - all of our queries should then never see it
+ plugin.setStatus(PluginStatusType.DELETED);
+ em.merge(plugin);
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", name);
+ List<?> results = query.getResultList();
+ assert results.size() == 0;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
+ query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
+ results = query.getResultList();
+ assert results.size() == 0;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
+ results = query.getResultList();
+ assert results.size() == 0;
+
+ } finally {
+ getTransactionManager().rollback();
+ }
+ }
+
+ public void testPersistStreamContent() throws Exception {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ boolean done = false;
+
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ String name = "ServerPluginTest-testPersist";
+ String path = "/test/Persist";
+ String displayName = "Server Plugin Test - testPersist";
+ boolean enabled = true;
+ String version = "1.0";
+ String description = "the test description is here";
+ String help = "the test help string is here";
+ byte[] content = "this is the test content".getBytes();
+ String md5 = MessageDigestGenerator.getDigestString(new String(content));
+
+ // persist the plugin, but without any content
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setMD5(md5);
+ plugin.setVersion(version);
+ plugin.setDescription(description);
+ plugin.setHelp(help);
+
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ // verify we have a content-less plugin in the db
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getHelp().equals(help);
+ assert plugin.getContent() == null;
+
+ em.close();
+ getTransactionManager().commit(); // must commit since we are going to use a second connection now
+ getTransactionManager().begin();
+
+ // now stream the content into the plugin's table
+ InitialContext context = getInitialContext();
+ DataSource ds = (DataSource) context.lookup("java:/RHQDS");
+ assert ds != null : "Could not get the data source!";
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME + " SET CONTENT = ? WHERE ID = ?");
+ ps.setBinaryStream(1, new ByteArrayInputStream(content), content.length);
+ ps.setInt(2, plugin.getId());
+ int updateResults = ps.executeUpdate();
+ assert updateResults == 1 : "Failed to stream the content blob: " + updateResults;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ // verify the content made it into the database via hibernate
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ em.close();
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+
+ // verify the content made it into the database via jdbc streaming
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("SELECT CONTENT FROM " + ServerPlugin.TABLE_NAME + " WHERE ID = ?");
+ ps.setInt(1, plugin.getId());
+ rs = ps.executeQuery();
+ rs.next();
+ InputStream dbStream = rs.getBinaryStream(1);
+ assert dbStream != null : "Could not read the plugin content stream from the db";
+ byte[] contentFromDb = StreamUtil.slurp(dbStream);
+ assert contentFromDb.length == content.length;
+ assert new String(contentFromDb).equals(new String(content));
+ assert MessageDigestGenerator.getDigestString(new String(contentFromDb)).equals(md5);
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ // clean up - delete our test plugin
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
+ doomed = em.getReference(ServerPlugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the plugin";
+ em.close();
+ getTransactionManager().commit();
+ done = true;
+
+ } finally {
+ if (rs != null) {
+ rs.close();
+ }
+ if (ps != null) {
+ ps.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ if (!done) {
+ getTransactionManager().rollback();
+ }
+ }
+ }
+
+ public void testPersistStreamContent2() throws Exception {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ boolean done = false;
+
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ byte[] content = "this is the test content".getBytes();
+ String path = "/test/Persist";
+
+ // persist a content-less plugin
+ ServerPlugin plugin = new ServerPlugin("ServerPluginTest-testPersist", path);
+ plugin.setDisplayName("Server Plugin Test - testPersist");
+ plugin.setEnabled(true);
+ plugin.setMD5(MessageDigestGenerator.getDigestString(new String(content)));
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ em.close();
+ getTransactionManager().commit(); // must commit since we are going to use a second connection now
+ getTransactionManager().begin();
+
+ // test that we can get a null content stream
+ InitialContext context = getInitialContext();
+ DataSource ds = (DataSource) context.lookup("java:/RHQDS");
+ assert ds != null : "Could not get the data source!";
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("SELECT PATH, CONTENT FROM " + ServerPlugin.TABLE_NAME + " WHERE ID = ?");
+ ps.setInt(1, plugin.getId());
+ rs = ps.executeQuery();
+ rs.next();
+ String dbPath = rs.getString(1);
+ assert dbPath.equals(path);
+ InputStream dbStream = rs.getBinaryStream(2);
+ assert dbStream == null : "Was expecting a null stream but got a non-null stream from db";
+ rs.close();
+ ps.close();
+ conn.close();
+ rs = null;
+ ps = null;
+ conn = null;
+
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+
+ // now stream the content into the plugin's table
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME + " SET CONTENT = ? WHERE ID = ?");
+ ps.setBinaryStream(1, new ByteArrayInputStream(content), content.length);
+ ps.setInt(2, plugin.getId());
+ int updateResults = ps.executeUpdate();
+ assert updateResults == 1 : "Failed to stream the content blob: " + updateResults;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+
+ // verify we can get the content stream along with another column in the same query
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("SELECT PATH, CONTENT FROM " + ServerPlugin.TABLE_NAME + " WHERE ID = ?");
+ ps.setInt(1, plugin.getId());
+ rs = ps.executeQuery();
+ rs.next();
+ dbPath = rs.getString(1);
+ assert dbPath.equals(path);
+ dbStream = rs.getBinaryStream(2);
+ assert dbStream != null : "Could not read the plugin content stream from the db";
+ byte[] contentFromDb = StreamUtil.slurp(dbStream);
+ assert contentFromDb.length == content.length;
+ assert new String(contentFromDb).equals(new String(content));
+ assert MessageDigestGenerator.getDigestString(new String(contentFromDb)).equals(
+ MessageDigestGenerator.getDigestString(new String(content)));
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ // clean up - delete our test plugin
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
+ doomed = em.getReference(ServerPlugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the plugin";
+ getTransactionManager().commit();
+ done = true;
+
+ } finally {
+ if (rs != null) {
+ rs.close();
+ }
+ if (ps != null) {
+ ps.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ if (!done) {
+ getTransactionManager().rollback();
+ }
+ }
+ }
+
+}
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 49d6e53..e139241 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
@@ -115,9 +115,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return new ArrayList<Plugin>(); // nothing to do
}
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_DEPLOYMENT);
query.setParameter("ids", pluginIds);
- query.setParameter("type", PluginDeploymentType.SERVER);
+ query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -131,9 +131,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_DEPLOYMENT);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("type", PluginDeploymentType.SERVER);
+ query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -354,9 +354,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void purgeServerPlugin(Subject subject, String pluginName) {
- Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
Plugin doomed = (Plugin) q.getSingleResult();
// get the reference to attach to em and use the em.remove. this cascade deletes too.
@@ -421,9 +421,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
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 d1a6aba..e39f570 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
@@ -348,9 +348,9 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
EntityManager em = getEntityManager();
getTransactionManager().begin();
try {
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
return (Plugin) q.getSingleResult();
} finally {
getTransactionManager().rollback();
commit 3e3f767e11d3fc680d6ad846d7f745d39a39a8fc
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 11:22:43 2009 -0500
start with plugin key impl
diff --git a/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java b/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
index 699ac49..51397c6 100644
--- a/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
+++ b/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
@@ -66,7 +66,7 @@ public class MyLifecycleListener implements ServerPluginComponent {
}
StringBuilder str = new StringBuilder();
- str.append("plugin-name=").append(this.context.getPluginEnvironment().getPluginName()).append(",");
+ str.append("plugin-key=").append(this.context.getPluginEnvironment().getPluginKey()).append(",");
str.append("plugin-url=").append(this.context.getPluginEnvironment().getPluginUrl()).append(",");
str.append("plugin-config=[").append(getPluginConfigurationString()).append(']'); // do not append ,
return str.toString();
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
new file mode 100644
index 0000000..4f7809d
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
@@ -0,0 +1,127 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.domain.plugin;
+
+/**
+ * Encapsulates informaton that can uniquely identify a plugin.
+ *
+ * @author John Mazzitelli
+ */
+public class PluginKey {
+ private final PluginDeploymentType deployment;
+ private final String pluginType;
+ private final String pluginName;
+
+ /**
+ * Creates a plugin key that identifies an agent plugin. There is only
+ * one plugin container that runs in the agent, thus there is only
+ * one "type" of an agent plugin. Therefore, {@link #getPluginType()} on the
+ * returned object will return an empty string to signify this.
+ *
+ * @param pluginName the name of the plugin
+ * @return the plugin key for the agent plugin
+ */
+ public static PluginKey createAgentPluginKey(String pluginName) {
+ return new PluginKey(PluginDeploymentType.AGENT, "", pluginName);
+ }
+
+ /**
+ * Creates a plugin key that identifies a server plugin. All server plugins
+ * must have a type and a name.
+ *
+ * @param pluginType the type of plugin - must not be null or an empty string
+ * @param pluginName the name of the plugin
+ * @return the plugin key for the server plugin
+ */
+ public static PluginKey createServerPluginKey(String pluginType, String pluginName) {
+ // for server plugins, cannot allow an empty string for plugin type
+ if (pluginType == null || pluginType.length() == 0) {
+ throw new IllegalArgumentException("invalid pluginType: " + pluginType);
+ }
+ return new PluginKey(PluginDeploymentType.SERVER, pluginType, pluginName);
+ }
+
+ public PluginKey(PluginDeploymentType deployment, String pluginType, String pluginName) {
+ if (deployment == null) {
+ throw new IllegalArgumentException("deployment==null");
+ }
+ if (pluginType == null) {
+ throw new IllegalArgumentException("pluginType==null");
+ }
+ if (pluginName == null || pluginName.length() == 0) {
+ throw new IllegalArgumentException("invalid pluginName: " + pluginName);
+ }
+
+ this.deployment = deployment;
+ this.pluginType = pluginType;
+ this.pluginName = pluginName;
+ }
+
+ public PluginDeploymentType getDeployment() {
+ return deployment;
+ }
+
+ public String getPluginName() {
+ return pluginName;
+ }
+
+ public String getPluginType() {
+ return pluginType;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("PluginKey [deployment=").append(deployment).append(", pluginType=").append(pluginType).append(
+ ", pluginName=").append(pluginName).append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + deployment.hashCode();
+ result = prime * result + pluginType.hashCode();
+ result = prime * result + pluginName.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof PluginKey)) {
+ return false;
+ }
+ PluginKey other = (PluginKey) obj;
+ if (!pluginName.equals(other.pluginName)) {
+ return false;
+ }
+ if (!pluginType.equals(other.pluginType)) {
+ return false;
+ }
+ if (!deployment.equals(other.deployment)) {
+ return false;
+ }
+ return true;
+ }
+}
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 49d6e53..aa75432 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
@@ -48,6 +48,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
@@ -83,18 +84,23 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return q.getResultList();
}
- public Plugin getServerPlugin(String name) {
+ public Plugin getServerPlugin(PluginKey key) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
+ query.setParameter("name", key.getPluginName());
Plugin plugin = (Plugin) query.getSingleResult();
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin named [" + name + "] is not a server plugin");
+ throw new IllegalArgumentException("Plugin [" + key + "] is not a server plugin");
}
return plugin;
}
public Plugin getServerPluginRelationships(Plugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
+ plugin = (Plugin) query.getSingleResult();
+ if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] is not a server plugin");
+ }
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@ -121,8 +127,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception {
+ Plugin plugin = getServerPlugin(pluginKey);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -130,11 +136,11 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
query.setParameter("enabled", Boolean.valueOf(enabled));
query.setParameter("type", PluginDeploymentType.SERVER);
- return query.getResultList();
+ return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@ -154,9 +160,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public List<String> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ public List<PluginKey> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<String>(); // nothing to do
+ return new ArrayList<PluginKey>(); // nothing to do
}
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
@@ -164,7 +170,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
- List<String> doomedPlugins = new ArrayList<String>();
+ List<PluginKey> doomedPlugins = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
Plugin doomedPlugin = null;
@@ -174,14 +180,15 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (doomedPlugin != null) {
String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = ;
+ doomedPlugins.add(pluginKey);
if (master != null) {
- AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginName);
+ AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
if (pc != null) {
try {
- pc.unschedulePluginJobs(pluginName);
+ pc.unschedulePluginJobs(pluginKey);
} catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" + pluginName + "]", e);
+ log.warn("Failed to unschedule jobs for plugin [" + pluginKey + "]", e);
}
}
}
@@ -197,9 +204,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public List<String> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ public List<PluginKey> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<String>(); // nothing to do
+ return new ArrayList<PluginKey>(); // nothing to do
}
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
@@ -207,7 +214,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
- List<String> doomedPlugins = new ArrayList<String>();
+ List<PluginKey> doomedPlugins = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
Plugin doomedPlugin = null;
@@ -217,14 +224,15 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (doomedPlugin != null) {
String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = ;
+ doomedPlugins.add(pluginKey);
if (master != null) {
- AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginName);
+ AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
if (pc != null) {
try {
- pc.unschedulePluginJobs(pluginName);
+ pc.unschedulePluginJobs(pluginKey);
} catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" + pluginName + "]", e);
+ log.warn("Failed to unschedule jobs for plugin [" + pluginKey + "]", e);
}
}
}
@@ -353,9 +361,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
q.setParameter("type", PluginDeploymentType.SERVER);
Plugin doomed = (Plugin) q.getSingleResult();
@@ -363,7 +371,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
doomed = this.entityManager.getReference(Plugin.class, doomed.getId());
this.entityManager.remove(doomed);
- log.debug("Server plugin [" + pluginName + "] has been purged from the db");
+ log.debug("Server plugin [" + pluginKey + "] has been purged from the db");
return;
}
@@ -420,9 +428,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
q.setParameter("type", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
@@ -439,14 +447,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
// if of type "alert plugin" or "generic plugin". That is only known when the plugin descriptor
// is parsed, which happens when the master plugin container is initialized. Therefore, this
// needs to get plugin info from the master plugin container while the master is running.
- public Map<ServerPluginType, List<String>> getAllPluginsGroupedByType() {
- Map<ServerPluginType, List<String>> allPlugins = new HashMap<ServerPluginType, List<String>>();
+ public Map<ServerPluginType, List<PluginKey>> getAllPluginsGroupedByType() {
+ Map<ServerPluginType, List<PluginKey>> allPlugins = new HashMap<ServerPluginType, List<PluginKey>>();
MasterServerPluginContainer master = LookupUtil.getServerPluginService().getMasterPluginContainer();
if (master != null) {
List<ServerPluginType> types = master.getServerPluginTypes();
for (ServerPluginType type : types) {
- List<String> plugins = master.getAllPluginsByPluginType(type);
+ List<PluginKey> plugins = master.getAllPluginsByPluginType(type);
allPlugins.put(type, plugins);
}
}
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 a6a09bf..2f84337 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
@@ -9,6 +9,7 @@ import javax.persistence.NoResultException;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -28,12 +29,12 @@ public interface ServerPluginsLocal {
List<Plugin> getServerPlugins();
/**
- * Returns a plugin with the given name.
- * @param name name of plugin to find
+ * Returns a plugin with the given key.
+ * @param key identifies the plugin to find
* @return the named plugin
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPlugin(String name);
+ Plugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
@@ -57,23 +58,23 @@ public interface ServerPluginsLocal {
List<Plugin> getServerPluginsById(List<Integer> pluginIds);
/**
- * Given a plugin name, returns the descriptor for that plugin.
+ * Given a plugin key, returns the descriptor for that plugin.
*
- * @param pluginName
+ * @param pluginKey
* @return descriptor parsed from the file in the plugin jar
* @throws Exception if the descriptor could not be retrieved or parsed for the given plugin
*/
- ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception;
+ ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception;
/**
- * Returns a list of plugin names for only those server plugins whose
+ * Returns a list of plugin keys for only those server plugins whose
* enabled flag is equal to the given parameter.
*
- * @param enabled if <code>true</code>, return only the names of plugins that are enabled;
- * if <code>false</code>, return only the names of plugins that are disabled.
- * @return list of plugin names that match the enabled criteria
+ * @param enabled if <code>true</code>, return only the keys of plugins that are enabled;
+ * if <code>false</code>, return only the keys of plugins that are disabled.
+ * @return list of plugin keys that match the enabled criteria
*/
- List<String> getServerPluginNamesByEnabled(boolean enabled);
+ List<PluginKey> getServerPluginKeysByEnabled(boolean enabled);
/**
* Enables the plugins and restarts the server plugin container.
@@ -89,20 +90,20 @@ public interface ServerPluginsLocal {
*
* @param subject user making the request
* @param pluginIds the plugins to be disabled
- * @return the list of names of the plugins that were disabled
+ * @return the list of keys of the plugins that were disabled
* @throws Exception if failed to disable a plugin
*/
- List<String> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
+ List<PluginKey> 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 names of plugins that were undeployed
+ * @return the list of keys of plugins that were undeployed
* @throws Exception if failed to undeploy a plugin
*/
- List<String> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
+ List<PluginKey> 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.
@@ -162,26 +163,26 @@ public interface ServerPluginsLocal {
* know what you are doing.
*
* @param subject user making the request
- * @param pluginName the name of the server plugin to delete
+ * @param pluginKey the key of the server plugin to delete
*/
- void purgeServerPlugin(Subject subject, String pluginName);
+ void purgeServerPlugin(Subject subject, PluginKey pluginKey);
/**
- * Given the name of a server plugin, this will return the status of that plugin.
+ * Given the key of a server plugin, this will return the status of that plugin.
* Use this to determine if a plugin has been deleted or not.
*
- * @param pluginName the name of the plugin whose status is to be returned.
+ * @param pluginKey the key of the plugin whose status is to be returned.
* @return the status of the plugin, to indicate if the plugin has been deleted or is installed.
* <code>null</code> indicates an unknown plugin.
*/
- PluginStatusType getServerPluginStatus(String pluginName);
+ PluginStatusType getServerPluginStatus(PluginKey pluginKey);
/**
* This will return a map containing all plugins currently known to the master plugin container.
* This will return installed plugins that are both enabled and disabled.
* Note that if the master plugin container is not running, an empty map is returned.
*
- * @return names of all enabled and disabled plugins, keyed on their types
+ * @return keys of all enabled and disabled plugins, keyed on their types
*/
- Map<ServerPluginType, List<String>> getAllPluginsGroupedByType();
+ Map<ServerPluginType, List<PluginKey>> getAllPluginsGroupedByType();
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
index e88e5fd..3301dcc 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.enterprise.server.scheduler.SchedulerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.CronScheduleType;
@@ -131,7 +132,7 @@ public abstract class AbstractTypeServerPluginContainer {
try {
unloadPlugin(env);
} catch (Exception e) {
- this.log.warn("Failed to unload plugin [" + env.getPluginName() + "].", e);
+ this.log.warn("Failed to unload plugin [" + env.getPluginKey().getPluginName() + "].", e);
}
}
@@ -195,14 +196,14 @@ public abstract class AbstractTypeServerPluginContainer {
// process all known plugins and schedule their jobs
List<ScheduledJobDefinition> jobs;
for (ServerPluginEnvironment pluginEnv : this.pluginManager.getPluginEnvironments()) {
- String pluginName = pluginEnv.getPluginName();
+ String pluginName = pluginEnv.getPluginKey().getPluginName();
try {
jobs = this.pluginManager.getServerPluginContext(pluginEnv).getSchedules();
if (jobs != null) {
for (ScheduledJobDefinition job : jobs) {
try {
- scheduleJob(job, pluginName);
+ scheduleJob(job, pluginEnv.getPluginKey());
} catch (Throwable t) {
log.warn("Failed to schedule job [" + job + "] for plugin [" + pluginName + "]", t);
}
@@ -231,13 +232,14 @@ public abstract class AbstractTypeServerPluginContainer {
* and able to process the jobs. This method should only be called when a plugin
* is being disabled or removed.
*
+ * @param pluginKey
* @throws Exception if failed to unschedule jobs
*/
- public void unschedulePluginJobs(String pluginName) throws Exception {
+ public void unschedulePluginJobs(PluginKey pluginKey) throws Exception {
SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
// note: all jobs for a plugin are placed in the same group, where the group name is the plugin name
- String groupName = pluginName;
+ String groupName = pluginKey.getPluginName();
scheduler.pauseJobGroup(groupName);
String[] jobNames = scheduler.getJobNames(groupName);
@@ -245,7 +247,7 @@ public abstract class AbstractTypeServerPluginContainer {
for (String jobName : jobNames) {
boolean deleted = scheduler.deleteJob(jobName, groupName);
if (!deleted) {
- log.warn("Plugin [" + pluginName + "] failed to get its job [" + jobName + "] unscheduled!");
+ log.warn("Plugin [" + pluginKey + "] failed to get its job [" + jobName + "] unscheduled!");
}
}
}
@@ -278,17 +280,17 @@ public abstract class AbstractTypeServerPluginContainer {
* job is not enabled, this method returns immediately as a no-op.
*
* @param schedule instructs how the job should be scheduled
- * @param pluginName the name of the plugin scheduling the job
+ * @param pluginKey the key of the plugin scheduling the job
*
* @throws Exception if failed to schedule the job
*/
- protected void scheduleJob(ScheduledJobDefinition schedule, String pluginName) throws Exception {
+ protected void scheduleJob(ScheduledJobDefinition schedule, PluginKey pluginKey) throws Exception {
if (!schedule.isEnabled()) {
return;
}
- String groupName = pluginName;
+ String groupName = pluginKey.getPluginName();
boolean rescheduleIfExists = true; // just in case the parameters change, we'll always want to reschedule it if it exists
boolean isVolatile = true; // if plugin is removed, this allows for the schedule to go away upon restart automatically
@@ -302,8 +304,8 @@ public abstract class AbstractTypeServerPluginContainer {
// build the data map for the job, setting some values we need, plus adding the callback data for the plugin itself
JobDataMap jobData = new JobDataMap();
- jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_NAME, pluginName);
- jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_TYPE, getSupportedServerPluginType().stringify());
+ jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_NAME, pluginKey.getPluginName());
+ jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_TYPE, pluginKey.getPluginType().toString());
jobData.put(AbstractJobWrapper.DATAMAP_JOB_ID, schedule.getJobId());
jobData.put(AbstractJobWrapper.DATAMAP_SCHEDULE_TYPE, schedule.getScheduleType().getTypeName());
jobData.put(AbstractJobWrapper.DATAMAP_SCHEDULE_TRIGGER, schedule.getScheduleType().getScheduleTrigger());
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
index 0a9b61c..ae3bbe4 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
@@ -34,6 +34,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -50,9 +51,9 @@ public class ClassLoaderManager {
private final File tmpDir;
/**
- * Provides a map keyed on plugin name whose values are the URLs to those plugin jars.
+ * Provides a map keyed on plugin keys whose values are the URLs to those plugin jars.
*/
- private final Map<String, URL> pluginNamesUrls;
+ private final Map<PluginKey, URL> pluginKeysUrls;
/**
* The parent classloader for those classloaders at the top of the classloader hierarchy.
@@ -61,11 +62,10 @@ public class ClassLoaderManager {
/**
* These are the classloaders that are built for each plugin.
- * This map is keyed on plugin name.
*
* @see #obtainServerPluginClassLoader(String)
*/
- private final Map<String, ClassLoader> serverPluginClassLoaders;
+ private final Map<PluginKey, ClassLoader> serverPluginClassLoaders;
/**
* Creates the object that will manage all classloaders for the plugins deployed in the server.
@@ -79,11 +79,13 @@ public class ClassLoaderManager {
this.rootClassLoader = rootClassLoader;
this.tmpDir = tmpDir;
- this.serverPluginClassLoaders = new HashMap<String, ClassLoader>();
+ this.serverPluginClassLoaders = new HashMap<PluginKey, ClassLoader>();
- this.pluginNamesUrls = new HashMap<String, URL>(plugins.size());
+ this.pluginKeysUrls = new HashMap<PluginKey, URL>(plugins.size());
for (Map.Entry<URL, ? extends ServerPluginDescriptorType> entry : plugins.entrySet()) {
- this.pluginNamesUrls.put(entry.getValue().getName(), entry.getKey());
+ ServerPluginType pluginType = new ServerPluginType(entry.getValue());
+ PluginKey pluginKey = PluginKey.createServerPluginKey(pluginType.stringify(), entry.getValue().getName());
+ this.pluginKeysUrls.put(pluginKey, entry.getKey());
}
return;
@@ -133,24 +135,24 @@ public class ClassLoaderManager {
/**
* Returns a plugin classloader (creating it if necessary).
*
- * @param pluginName the plugin whose classloader is to be created
+ * @param pluginKey the plugin whose classloader is to be created
* @return the plugin classloader
* @throws Exception
*/
- public synchronized ClassLoader obtainServerPluginClassLoader(String pluginName) throws Exception {
+ public synchronized ClassLoader obtainServerPluginClassLoader(PluginKey pluginKey) throws Exception {
- ClassLoader cl = this.serverPluginClassLoaders.get(pluginName);
+ ClassLoader cl = this.serverPluginClassLoaders.get(pluginKey);
if (cl == null) {
- URL pluginJarUrl = this.pluginNamesUrls.get(pluginName);
+ URL pluginJarUrl = this.pluginKeysUrls.get(pluginKey);
if (log.isDebugEnabled()) {
- log.debug("Creating classloader for plugin [" + pluginName + "] from URL [" + pluginJarUrl + ']');
+ log.debug("Creating classloader for plugin [" + pluginKey + "] from URL [" + pluginJarUrl + ']');
}
ClassLoader parentClassLoader = this.rootClassLoader;
cl = createClassLoader(pluginJarUrl, null, parentClassLoader);
- this.serverPluginClassLoaders.put(pluginName, cl);
+ this.serverPluginClassLoaders.put(pluginKey, cl);
}
return cl;
@@ -167,7 +169,7 @@ public class ClassLoaderManager {
}
/**
- * Returns a shallow copy of the plugin classloaders keyed on plugin name. This method is here
+ * Returns a shallow copy of the plugin classloaders keyed on plugin key. This method is here
* just to support a plugin container management MBean.
*
* Do not use this method to obtain a plugin's classloader, instead, you want to use
@@ -175,8 +177,8 @@ public class ClassLoaderManager {
*
* @return all plugin classloaders currently assigned to plugins (will never be <code>null</code>)
*/
- public synchronized Map<String, ClassLoader> getServerPluginClassLoaders() {
- return new HashMap<String, ClassLoader>(this.serverPluginClassLoaders);
+ public synchronized Map<PluginKey, ClassLoader> getServerPluginClassLoaders() {
+ return new HashMap<PluginKey, ClassLoader>(this.serverPluginClassLoaders);
}
private synchronized Set<ClassLoader> getUniqueServerPluginClassLoaders() {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
index 4ab3fb2..2d2eea7 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
@@ -30,6 +30,7 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.enterprise.server.plugin.pc.alert.AlertServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.content.ContentServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.generic.GenericServerPluginContainer;
@@ -60,7 +61,7 @@ public class MasterServerPluginContainer {
* Because the individual plugin containers are only managing enabled plugins (they are never told about plugins that disabled).
* this map contains the lists of plugins that are disabled so others can find out what plugins are registered but not running.
*/
- private Map<ServerPluginType, List<String>> disabledPlugins = new HashMap<ServerPluginType, List<String>>();
+ private Map<ServerPluginType, List<PluginKey>> disabledPlugins = new HashMap<ServerPluginType, List<PluginKey>>();
/**
* Starts the master plugin container, which will load all plugins and begin managing them.
@@ -115,7 +116,9 @@ public class MasterServerPluginContainer {
URL pluginUrl = entry.getKey();
ServerPluginDescriptorType descriptor = entry.getValue();
String pluginName = descriptor.getName();
- ClassLoader classLoader = this.classLoaderManager.obtainServerPluginClassLoader(pluginName);
+ ServerPluginType pluginType = new ServerPluginType(descriptor);
+ PluginKey pluginKey = PluginKey.createServerPluginKey(pluginType.stringify(), pluginName);
+ ClassLoader classLoader = this.classLoaderManager.obtainServerPluginClassLoader(pluginKey);
AbstractTypeServerPluginContainer pc = getPluginContainerByDescriptor(descriptor);
if (pc != null) {
log.debug("Loading server plugin [" + pluginUrl + "] into its plugin container");
@@ -251,7 +254,7 @@ public class MasterServerPluginContainer {
}
/**
- * Given a plugin type, this will return the names of all known plugins of that type.
+ * Given a plugin type, this will return the keys of all known plugins of that type.
* This includes all types that are currently started as well as plugins
* that have been disabled.
*
@@ -261,8 +264,8 @@ public class MasterServerPluginContainer {
*
* @return list of both enabled and disabled plugins of the given type
*/
- public List<String> getAllPluginsByPluginType(ServerPluginType pluginType) {
- List<String> allPlugins = new ArrayList<String>();
+ public List<PluginKey> getAllPluginsByPluginType(ServerPluginType pluginType) {
+ List<PluginKey> allPlugins = new ArrayList<PluginKey>();
AbstractTypeServerPluginContainer pc = getPluginContainerByPluginType(pluginType);
if (pc != null) {
@@ -272,13 +275,13 @@ public class MasterServerPluginContainer {
Collection<ServerPluginEnvironment> envs = pluginManager.getPluginEnvironments();
if (envs != null) {
for (ServerPluginEnvironment env : envs) {
- allPlugins.add(env.getPluginName());
+ allPlugins.add(env.getPluginKey());
}
}
}
// add the disabled plugins
- List<String> disabled = this.disabledPlugins.get(pluginType);
+ List<PluginKey> disabled = this.disabledPlugins.get(pluginType);
if (disabled != null) {
allPlugins.addAll(disabled);
}
@@ -317,17 +320,24 @@ public class MasterServerPluginContainer {
}
/**
- * Given the name of a deployed plugin, this returns the plugin container that is hosting
- * that plugin. If there is no plugin with the given name or that plugin is not
+ * Given the key of a deployed plugin, this returns the plugin container that is hosting
+ * that plugin. If there is no plugin with the given key or that plugin is not
* loaded in any plugin container (e.g. when it is disabled), then <code>null</code> is returned.
*
- * @param pluginName
- * @return the plugin container that is managing the named plugin of <code>null</code>
+ * @param pluginKey
+ * @return the plugin container that is managing the named plugin or <code>null</code>
*/
- public synchronized <T extends AbstractTypeServerPluginContainer> T getPluginContainerByPlugin(String pluginName) {
+ public synchronized <T extends AbstractTypeServerPluginContainer> T getPluginContainerByPlugin(PluginKey pluginKey) {
for (AbstractTypeServerPluginContainer pc : this.pluginContainers.values()) {
- if (null != pc.getPluginManager().getPluginEnvironment(pluginName)) {
- return (T) pc;
+ try {
+ if (pc.getSupportedServerPluginType().equals(new ServerPluginType(pluginKey.getPluginType()))) {
+ if (null != pc.getPluginManager().getPluginEnvironment(pluginKey.getPluginName())) {
+ return (T) pc;
+ }
+ }
+ } catch (Exception skip) {
+ // should never really happen
+ log.error("Bad plugin key: " + pluginKey);
}
}
return null;
@@ -381,7 +391,7 @@ public class MasterServerPluginContainer {
if (pluginFiles != null) {
- List<String> allDisabledPlugins = getDisabledPluginNames();
+ List<PluginKey> allDisabledPlugins = getDisabledPluginNames();
for (File pluginFile : pluginFiles) {
if (pluginFile.getName().endsWith(".jar")) {
@@ -391,19 +401,22 @@ public class MasterServerPluginContainer {
ServerPluginDescriptorType descriptor;
descriptor = ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
if (descriptor != null) {
- if (!allDisabledPlugins.contains(descriptor.getName())) {
+ PluginKey pluginKey = PluginKey.createServerPluginKey(new ServerPluginType(descriptor)
+ .stringify(), descriptor.getName());
+
+ if (!allDisabledPlugins.contains(pluginKey)) {
log.debug("pre-loaded server plugin from URL: " + pluginUrl);
plugins.put(pluginUrl, descriptor);
} else {
log.info("Server plugin [" + descriptor.getName()
+ "] is disabled and will not be initialized");
ServerPluginType pluginType = new ServerPluginType(descriptor);
- List<String> disabledByType = this.disabledPlugins.get(pluginType);
+ List<PluginKey> disabledByType = this.disabledPlugins.get(pluginType);
if (disabledByType == null) {
- disabledByType = new ArrayList<String>(1);
+ disabledByType = new ArrayList<PluginKey>(1);
this.disabledPlugins.put(pluginType, disabledByType);
}
- disabledByType.add(descriptor.getName());
+ disabledByType.add(pluginKey);
}
}
} catch (Throwable t) {
@@ -419,14 +432,14 @@ public class MasterServerPluginContainer {
}
/**
- * This will return a list of plugin names that represent all the plugins that are to be
- * disabled. If a plugin jar is found on the filesystem, its plugin name should be checked with
- * this "blacklist" if it its name is found, that plugin should not be loaded.
+ * This will return a list of plugin keys that represent all the plugins that are to be
+ * disabled. If a plugin jar is found on the filesystem, its plugin key should be checked with
+ * this "blacklist" - if its key is found, that plugin should not be loaded.
*
* @return names of "blacklisted" plugins that should not be loaded
*/
- protected List<String> getDisabledPluginNames() {
- List<String> disabledPlugins = LookupUtil.getServerPlugins().getServerPluginNamesByEnabled(false);
+ protected List<PluginKey> getDisabledPluginNames() {
+ List<PluginKey> disabledPlugins = LookupUtil.getServerPlugins().getServerPluginKeysByEnabled(false);
return disabledPlugins;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
index e0809a6..5a7dc61 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
@@ -20,6 +20,7 @@ package org.rhq.enterprise.server.plugin.pc;
import java.net.URL;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -29,7 +30,7 @@ import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
*/
public class ServerPluginEnvironment {
private final URL pluginUrl;
- private final String pluginName;
+ private final PluginKey pluginKey;
private final ClassLoader pluginClassLoader;
private final ServerPluginDescriptorType pluginDescriptor;
@@ -47,11 +48,12 @@ public class ServerPluginEnvironment {
this.pluginUrl = pluginUrl;
this.pluginClassLoader = classLoader;
this.pluginDescriptor = descriptor;
- this.pluginName = this.pluginDescriptor.getName();
+ String pluginTypeStr = new ServerPluginType(descriptor).stringify();
+ this.pluginKey = PluginKey.createServerPluginKey(pluginTypeStr, this.pluginDescriptor.getName());
}
- public String getPluginName() {
- return this.pluginName;
+ public PluginKey getPluginKey() {
+ return this.pluginKey;
}
public URL getPluginUrl() {
@@ -68,6 +70,6 @@ public class ServerPluginEnvironment {
@Override
public String toString() {
- return this.pluginName + ": url=[" + this.pluginUrl + "]";
+ return this.pluginKey + ": url=[" + this.pluginUrl + "]";
}
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index 36fa5bd..350ca61 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
@@ -117,7 +117,7 @@ public class ServerPluginManager {
* @throws Exception if the plugin manager cannot load the plugin or deems the plugin invalid
*/
public void loadPlugin(ServerPluginEnvironment env) throws Exception {
- String pluginName = env.getPluginName();
+ String pluginName = env.getPluginKey().getPluginName();
log.debug("Loading server plugin [" + pluginName + "] from: " + env.getPluginUrl());
// tell the plugin we are loading it
@@ -198,7 +198,7 @@ public class ServerPluginManager {
* @throws Exception if the plugin manager cannot unload the plugin
*/
public void unloadPlugin(ServerPluginEnvironment env) throws Exception {
- String pluginName = env.getPluginName();
+ String pluginName = env.getPluginKey().getPluginName();
log.debug("Unloading server plugin [" + pluginName + "]");
try {
@@ -271,7 +271,7 @@ public class ServerPluginManager {
protected ServerPluginContext getServerPluginContext(ServerPluginEnvironment env) {
- String pluginName = env.getPluginName();
+ String pluginName = env.getPluginKey().getPluginName();
ServerPluginContext context = this.pluginContextCache.get(pluginName);
// if we already created it, return it immediately and don't create another
@@ -311,7 +311,7 @@ public class ServerPluginManager {
protected Plugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
+ Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
return plugin;
}
@@ -332,7 +332,7 @@ public class ServerPluginManager {
*/
protected ServerPluginComponent createServerPluginComponent(ServerPluginEnvironment environment) throws Exception {
- String pluginName = environment.getPluginName();
+ String pluginName = environment.getPluginKey().getPluginName();
ServerPluginComponent instance = null;
ServerPluginComponentType componentXml = environment.getPluginDescriptor().getPluginComponent();
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
index 6f42c5e..8d690f9 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
@@ -112,7 +112,7 @@ public class ContentServerPluginManager extends ServerPluginManager {
@Override
public void unloadPlugin(ServerPluginEnvironment env) throws Exception {
- metadataManager.unloadPlugin(env.getPluginName());
+ metadataManager.unloadPlugin(env.getPluginKey().getPluginName());
super.unloadPlugin(env);
};
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 592a3d9..e80ed1f 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
@@ -29,6 +29,7 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
@@ -96,9 +97,9 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
@Override
- protected List<String> getDisabledPluginNames() {
+ protected List<PluginKey> getDisabledPluginNames() {
// in the real world, the db is checked for enable flag, here we say all plugins are enabled
- return new ArrayList<String>();
+ return new ArrayList<PluginKey>();
}
}
@@ -195,11 +196,11 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
File pluginFile = new File(env.getPluginUrl().toURI());
- Plugin plugin = new Plugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
- .getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor.getDescription(), "",
- MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor
- .getVersion(), PluginDeploymentType.SERVER, pluginConfig, scheduledJobsConfig, System
- .currentTimeMillis(), System.currentTimeMillis());
+ Plugin plugin = new Plugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
+ .getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
+ .getVersion(), pluginDescriptor.getVersion(), PluginDeploymentType.SERVER, pluginConfig,
+ scheduledJobsConfig, System.currentTimeMillis(), System.currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -210,7 +211,7 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
protected ServerPluginComponent createServerPluginComponent(ServerPluginEnvironment environment)
throws Exception {
ServerPluginComponent component = super.createServerPluginComponent(environment);
- components.put(environment.getPluginName(), component);
+ components.put(environment.getPluginKey().getPluginName(), component);
return component;
}
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
index 0b095e5..9b84ddd 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
@@ -18,8 +18,8 @@
*/
package org.rhq.enterprise.server.plugin.pc.generic;
-import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
/**
* A sample lifecycle listener for the sample generic plugin. This listener will be
@@ -82,7 +82,7 @@ public class TestLifecycleListener implements ServerPluginComponent {
}
StringBuilder str = new StringBuilder();
- str.append("plugin-name=").append(this.context.getPluginEnvironment().getPluginName()).append(",");
+ str.append("plugin-key=").append(this.context.getPluginEnvironment().getPluginKey()).append(",");
str.append("plugin-url=").append(this.context.getPluginEnvironment().getPluginUrl()).append(",");
str.append("data-dir=").append(this.context.getDataDirectory()).append(",");
str.append("tmp-dir=").append(this.context.getTemporaryDirectory()); // do not append ,
commit db605e78ebfb82d01f0ce4130f327c45170540c7
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 17:18:29 2009 -0500
get rid of the update query we don't need anymore
fix tests so they don't rely on that old update query
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index eda26d8..4047d10 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -187,25 +187,6 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.deployment = 'SERVER' AND p.status = 'INSTALLED' "), //
- // this query does not update the content blob or ctime
- @NamedQuery(name = Plugin.UPDATE_ALL_BUT_CONTENT, query = "" //
- + "UPDATE Plugin p " //
- + " SET p.name = :name, " //
- + " p.displayName = :displayName, " //
- + " p.description = :description, " //
- + " p.enabled = :enabled, " //
- + " p.status = :status, " //
- + " p.help = :help, " //
- + " p.version = :version, " //
- + " p.ampsVersion = :ampsVersion," //
- + " p.deployment = :deployment, " //
- + " p.pluginConfiguration = :pluginConfiguration, " //
- + " p.scheduledJobsConfiguration = :scheduledJobsConfiguration, " //
- + " p.path = :path, " //
- + " p.md5 = :md5, " //
- + " p.mtime = :mtime " //
- + " WHERE p.id = :id"),
-
// this query is how you enable and disable plugins
@NamedQuery(name = Plugin.UPDATE_PLUGINS_ENABLED_BY_IDS, query = "" //
+ "UPDATE Plugin p " //
@@ -256,7 +237,6 @@ public class Plugin implements Serializable {
public static final String QUERY_FIND_BY_IDS_AND_TYPE = "Plugin.findByIdsAndType";
public static final String QUERY_GET_NAMES_BY_ENABLED_AND_TYPE = "Plugin.findByEnabledAndType";
public static final String QUERY_GET_STATUS_BY_NAME_AND_TYPE = "Plugin.getStatusByNameAndType";
- public static final String UPDATE_ALL_BUT_CONTENT = "Plugin.updateAllButContent";
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "Plugin.updatePluginsEnabledByIds";
@Column(name = "ID", nullable = false)
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index 07f8f97..729f7c2 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -131,23 +131,39 @@ public class PluginTest extends AbstractEJB3Test {
em.persist(jobsConfig);
em.flush(); // gotta get those two persists to flush to the DB
- q = em.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
- q.setParameter("id", id); // same as the one we just persisted
- q.setParameter("name", name);
- q.setParameter("path", path);
- q.setParameter("displayName", displayName);
- q.setParameter("enabled", enabled);
- q.setParameter("status", status);
- q.setParameter("md5", md5);
- q.setParameter("version", version);
- q.setParameter("ampsVersion", ampsVersion);
- q.setParameter("deployment", deployment);
- q.setParameter("pluginConfiguration", pluginConfig);
- q.setParameter("scheduledJobsConfiguration", jobsConfig);
- q.setParameter("description", description);
- q.setParameter("help", help);
- q.setParameter("mtime", System.currentTimeMillis());
- assert q.executeUpdate() == 1 : "Failed to update the plugin";
+ // do what ServerPluginsBean/ResourceMetadataManagerBean.updateServerPluginExceptContent does
+ Configuration config = plugin.getPluginConfiguration();
+ if (config != null) {
+ config = em.merge(config);
+ plugin.setPluginConfiguration(config);
+ }
+ config = plugin.getScheduledJobsConfiguration();
+ if (config != null) {
+ config = em.merge(config);
+ plugin.setScheduledJobsConfiguration(config);
+ }
+
+ Plugin pluginEntity = em.getReference(Plugin.class, plugin.getId());
+ pluginEntity.setName(name);
+ pluginEntity.setPath(path);
+ pluginEntity.setDisplayName(displayName);
+ pluginEntity.setEnabled(enabled);
+ pluginEntity.setStatus(status);
+ pluginEntity.setMd5(md5);
+ pluginEntity.setVersion(version);
+ pluginEntity.setAmpsVersion(ampsVersion);
+ pluginEntity.setDeployment(deployment);
+ pluginEntity.setPluginConfiguration(pluginConfig);
+ pluginEntity.setScheduledJobsConfiguration(jobsConfig);
+ pluginEntity.setDescription(description);
+ pluginEntity.setHelp(help);
+ pluginEntity.setMtime(System.currentTimeMillis());
+
+ try {
+ em.flush(); // make sure we push this out to the DB now
+ } catch (Exception e) {
+ throw new Exception("Failed to update a plugin that matches [" + plugin + "]", e);
+ }
em.close();
getTransactionManager().commit(); // must commit now
@@ -163,7 +179,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.isEnabled() == enabled;
assert plugin.getMD5().equals(md5);
assert plugin.getVersion().equals(version);
- q.setParameter("ampsVersion", ampsVersion);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == PluginDeploymentType.SERVER;
assert plugin.getPluginConfiguration().equals(pluginConfig);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index 9c971e0..d502f4e 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -198,49 +198,38 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
entityManager.persist(plugin);
} else {
// agent plugins don't support these configs, but if/when they do in the future, this will support it
- boolean needFlush = false;
+ // make sure we create (if necessary) and attach the configs
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
- if (config.getId() > 0) {
- config = entityManager.getReference(Configuration.class, config.getId());
- plugin.setPluginConfiguration(config);
- } else {
- entityManager.persist(config);
- needFlush = true;
- }
+ config = entityManager.merge(config);
+ plugin.setPluginConfiguration(config);
}
config = plugin.getScheduledJobsConfiguration();
if (config != null) {
- if (config.getId() > 0) {
- config = entityManager.getReference(Configuration.class, config.getId());
- plugin.setScheduledJobsConfiguration(config);
- } else {
- entityManager.persist(config);
- needFlush = true;
- }
- }
- if (needFlush) {
- entityManager.flush(); // must be flushed to the DB so the JPQL update below works
+ config = entityManager.merge(config);
+ plugin.setScheduledJobsConfiguration(config);
}
// update all the fields except content
- Query q = entityManager.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
- q.setParameter("id", plugin.getId());
- q.setParameter("name", plugin.getName());
- q.setParameter("path", plugin.getPath());
- q.setParameter("displayName", plugin.getDisplayName());
- q.setParameter("enabled", plugin.isEnabled());
- q.setParameter("status", plugin.getStatus());
- q.setParameter("md5", plugin.getMD5());
- q.setParameter("version", plugin.getVersion());
- q.setParameter("ampsVersion", plugin.getAmpsVersion());
- q.setParameter("deployment", plugin.getDeployment());
- 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());
- if (q.executeUpdate() != 1) {
+ Plugin pluginEntity = entityManager.getReference(Plugin.class, plugin.getId());
+ pluginEntity.setName(plugin.getName());
+ pluginEntity.setPath(plugin.getPath());
+ pluginEntity.setDisplayName(plugin.getDisplayName());
+ pluginEntity.setEnabled(plugin.isEnabled());
+ pluginEntity.setStatus(plugin.getStatus());
+ pluginEntity.setMd5(plugin.getMD5());
+ pluginEntity.setVersion(plugin.getVersion());
+ pluginEntity.setAmpsVersion(plugin.getAmpsVersion());
+ pluginEntity.setDeployment(plugin.getDeployment());
+ pluginEntity.setPluginConfiguration(plugin.getPluginConfiguration());
+ pluginEntity.setScheduledJobsConfiguration(plugin.getScheduledJobsConfiguration());
+ pluginEntity.setDescription(plugin.getDescription());
+ pluginEntity.setHelp(plugin.getHelp());
+ pluginEntity.setMtime(plugin.getMtime());
+
+ try {
+ entityManager.flush(); // make sure we push this out to the DB now
+ } catch (Exception e) {
throw new Exception("Failed to update a plugin that matches [" + plugin + "]");
}
}
commit dfd17347dd6d8c2707bfab6ced27bd44b66f9120
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 16:42:23 2009 -0500
fix the update method so it can handle the config updates
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 ff7d6ca..49d6e53 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
@@ -383,56 +383,39 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (plugin.getId() == 0) {
throw new IllegalArgumentException("Plugin must already exist to update it");
} else {
- // make sure the configs are in the DB properly and we have their refs
- // this is because we are using JPQL update, so we need to do some of this "manually"
- boolean needFlush = false;
+ // make sure we create (if necessary) and attach the configs
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
- if (config.getId() > 0) {
- config = entityManager.getReference(Configuration.class, config.getId());
- plugin.setPluginConfiguration(config);
- } else {
- entityManager.persist(config);
- needFlush = true;
- }
+ config = entityManager.merge(config);
+ plugin.setPluginConfiguration(config);
}
config = plugin.getScheduledJobsConfiguration();
if (config != null) {
- if (config.getId() > 0) {
- config = entityManager.getReference(Configuration.class, config.getId());
- plugin.setScheduledJobsConfiguration(config);
- } else {
- entityManager.persist(config);
- needFlush = true;
- }
- }
- if (needFlush) {
- entityManager.flush(); // must be flushed to the DB so the JPQL update below works
+ config = entityManager.merge(config);
+ plugin.setScheduledJobsConfiguration(config);
}
- // now we can JPQL update the row - all but content is updated here.
- // we assured our configs are persisted/attached above
- Query q = entityManager.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
- q.setParameter("id", plugin.getId());
- q.setParameter("name", plugin.getName());
- q.setParameter("path", plugin.getPath());
- q.setParameter("displayName", plugin.getDisplayName());
- q.setParameter("enabled", plugin.isEnabled());
- q.setParameter("status", plugin.getStatus());
- q.setParameter("md5", plugin.getMD5());
- q.setParameter("version", plugin.getVersion());
- q.setParameter("ampsVersion", plugin.getAmpsVersion());
- q.setParameter("deployment", plugin.getDeployment());
- 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());
- if (q.executeUpdate() != 1) {
- throw new Exception("Failed to update a plugin that matches [" + plugin + "]");
- }
+ Plugin pluginEntity = entityManager.getReference(Plugin.class, plugin.getId());
+ pluginEntity.setName(plugin.getName());
+ pluginEntity.setPath(plugin.getPath());
+ pluginEntity.setDisplayName(plugin.getDisplayName());
+ pluginEntity.setEnabled(plugin.isEnabled());
+ pluginEntity.setStatus(plugin.getStatus());
+ pluginEntity.setMd5(plugin.getMD5());
+ pluginEntity.setVersion(plugin.getVersion());
+ pluginEntity.setAmpsVersion(plugin.getAmpsVersion());
+ pluginEntity.setDeployment(plugin.getDeployment());
+ pluginEntity.setPluginConfiguration(plugin.getPluginConfiguration());
+ pluginEntity.setScheduledJobsConfiguration(plugin.getScheduledJobsConfiguration());
+ pluginEntity.setDescription(plugin.getDescription());
+ pluginEntity.setHelp(plugin.getHelp());
+ pluginEntity.setMtime(plugin.getMtime());
- entityManager.flush(); // make sure we push this out to the DB now
+ try {
+ entityManager.flush(); // make sure we push this out to the DB now
+ } catch (Exception e) {
+ throw new Exception("Failed to update a plugin that matches [" + plugin + "]", e);
+ }
}
return plugin;
}
commit aadfbe12066b4cab890bc04fbd9a55c76df87fb4
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 13:19:15 2009 -0500
provide an API to get a list of all enabled and disabled plugins grouped by their type
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java
index a79dff5..bbeb84c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentManagerHelper.java
@@ -42,7 +42,7 @@ public class ContentManagerHelper {
}
MasterServerPluginContainer master = mbean.getMasterPluginContainer();
- pc = master.getPluginContainer(ContentServerPluginContainer.class);
+ pc = master.getPluginContainerByClass(ContentServerPluginContainer.class);
} catch (IllegalStateException ise) {
throw ise;
} catch (Exception e) {
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 2d67f3f..ff7d6ca 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
@@ -26,7 +26,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.ejb.EJB;
import javax.ejb.Stateless;
@@ -54,6 +56,7 @@ import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -173,7 +176,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
String pluginName = doomedPlugin.getName();
doomedPlugins.add(pluginName);
if (master != null) {
- AbstractTypeServerPluginContainer pc = master.getPluginContainer(pluginName);
+ AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginName);
if (pc != null) {
try {
pc.unschedulePluginJobs(pluginName);
@@ -216,7 +219,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
String pluginName = doomedPlugin.getName();
doomedPlugins.add(pluginName);
if (master != null) {
- AbstractTypeServerPluginContainer pc = master.getPluginContainer(pluginName);
+ AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginName);
if (pc != null) {
try {
pc.unschedulePluginJobs(pluginName);
@@ -447,6 +450,27 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return status;
}
+ // we need this method to talk to the master plugin container because the plugin data model
+ // does not contain information as to what type a plugin is. It only has information about
+ // where the plugin is deployed (agent or server) but it doesn't indicate if a plugin
+ // if of type "alert plugin" or "generic plugin". That is only known when the plugin descriptor
+ // is parsed, which happens when the master plugin container is initialized. Therefore, this
+ // needs to get plugin info from the master plugin container while the master is running.
+ public Map<ServerPluginType, List<String>> getAllPluginsGroupedByType() {
+ Map<ServerPluginType, List<String>> allPlugins = new HashMap<ServerPluginType, List<String>>();
+
+ MasterServerPluginContainer master = LookupUtil.getServerPluginService().getMasterPluginContainer();
+ if (master != null) {
+ List<ServerPluginType> types = master.getServerPluginTypes();
+ for (ServerPluginType type : types) {
+ List<String> plugins = master.getAllPluginsByPluginType(type);
+ allPlugins.put(type, plugins);
+ }
+ }
+
+ return allPlugins;
+ }
+
/**
* This will write the contents of the given plugin file to the database.
* This will assume the MD5 in the database is already correct, so this
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 df685d4..a6a09bf 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
@@ -2,6 +2,7 @@ package org.rhq.enterprise.server.plugin;
import java.io.File;
import java.util.List;
+import java.util.Map;
import javax.ejb.Local;
import javax.persistence.NoResultException;
@@ -9,6 +10,7 @@ import javax.persistence.NoResultException;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -173,4 +175,13 @@ public interface ServerPluginsLocal {
* <code>null</code> indicates an unknown plugin.
*/
PluginStatusType getServerPluginStatus(String pluginName);
+
+ /**
+ * This will return a map containing all plugins currently known to the master plugin container.
+ * This will return installed plugins that are both enabled and disabled.
+ * Note that if the master plugin container is not running, an empty map is returned.
+ *
+ * @return names of all enabled and disabled plugins, keyed on their types
+ */
+ Map<ServerPluginType, List<String>> getAllPluginsGroupedByType();
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
index 8ebabd4..4ab3fb2 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
@@ -21,6 +21,7 @@ package org.rhq.enterprise.server.plugin.pc;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -46,11 +47,22 @@ import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
public class MasterServerPluginContainer {
private static final Log log = LogFactory.getLog(MasterServerPluginContainer.class);
+ /** The configuration for the master plugin container itself. */
private MasterServerPluginContainerConfiguration configuration;
+
+ /** the plugin containers for all the different types of plugins that are supported */
private Map<ServerPluginType, AbstractTypeServerPluginContainer> pluginContainers = new HashMap<ServerPluginType, AbstractTypeServerPluginContainer>();
+
+ /** the object that provides all the classloaders for all plugins */
private ClassLoaderManager classLoaderManager;
/**
+ * Because the individual plugin containers are only managing enabled plugins (they are never told about plugins that disabled).
+ * this map contains the lists of plugins that are disabled so others can find out what plugins are registered but not running.
+ */
+ private Map<ServerPluginType, List<String>> disabledPlugins = new HashMap<ServerPluginType, List<String>>();
+
+ /**
* Starts the master plugin container, which will load all plugins and begin managing them.
*
* @param config the master configuration
@@ -188,6 +200,7 @@ public class MasterServerPluginContainer {
}
this.pluginContainers.clear();
+ this.disabledPlugins.clear();
this.classLoaderManager = null;
this.configuration = null;
@@ -238,6 +251,55 @@ public class MasterServerPluginContainer {
}
/**
+ * Given a plugin type, this will return the names of all known plugins of that type.
+ * This includes all types that are currently started as well as plugins
+ * that have been disabled.
+ *
+ * If the master plugin container has not been started, this returns an empty list.
+ *
+ * @param pluginType
+ *
+ * @return list of both enabled and disabled plugins of the given type
+ */
+ public List<String> getAllPluginsByPluginType(ServerPluginType pluginType) {
+ List<String> allPlugins = new ArrayList<String>();
+
+ AbstractTypeServerPluginContainer pc = getPluginContainerByPluginType(pluginType);
+ if (pc != null) {
+ // add the enabled plugins
+ ServerPluginManager pluginManager = pc.getPluginManager();
+ if (pluginManager != null) {
+ Collection<ServerPluginEnvironment> envs = pluginManager.getPluginEnvironments();
+ if (envs != null) {
+ for (ServerPluginEnvironment env : envs) {
+ allPlugins.add(env.getPluginName());
+ }
+ }
+ }
+
+ // add the disabled plugins
+ List<String> disabled = this.disabledPlugins.get(pluginType);
+ if (disabled != null) {
+ allPlugins.addAll(disabled);
+ }
+ }
+
+ return allPlugins;
+ }
+
+ /**
+ * This will return all known server plugins types. These are the types of plugins
+ * that are supported by a server plugin container. You can obtain the server
+ * plugin container that manages a particular server plugin type via
+ * {@link #getPluginContainerByPluginType(ServerPluginType)}.
+ *
+ * @return all known server plugin types
+ */
+ public synchronized List<ServerPluginType> getServerPluginTypes() {
+ return new ArrayList<ServerPluginType>(this.pluginContainers.keySet());
+ }
+
+ /**
* Get the plugin container of the given class. This method provides a strongly typed return value,
* based on the type of plugin container the caller wants returned.
*
@@ -245,7 +307,7 @@ public class MasterServerPluginContainer {
* @return the plugin container of the given class (<code>null</code> if none found)
*/
@SuppressWarnings("unchecked")
- public synchronized <T extends AbstractTypeServerPluginContainer> T getPluginContainer(Class<T> clazz) {
+ public synchronized <T extends AbstractTypeServerPluginContainer> T getPluginContainerByClass(Class<T> clazz) {
for (AbstractTypeServerPluginContainer pc : this.pluginContainers.values()) {
if (clazz.isInstance(pc)) {
return (T) pc;
@@ -262,7 +324,7 @@ public class MasterServerPluginContainer {
* @param pluginName
* @return the plugin container that is managing the named plugin of <code>null</code>
*/
- public synchronized <T extends AbstractTypeServerPluginContainer> T getPluginContainer(String pluginName) {
+ public synchronized <T extends AbstractTypeServerPluginContainer> T getPluginContainerByPlugin(String pluginName) {
for (AbstractTypeServerPluginContainer pc : this.pluginContainers.values()) {
if (null != pc.getPluginManager().getPluginEnvironment(pluginName)) {
return (T) pc;
@@ -319,7 +381,7 @@ public class MasterServerPluginContainer {
if (pluginFiles != null) {
- List<String> disabledPlugins = getDisabledPluginNames();
+ List<String> allDisabledPlugins = getDisabledPluginNames();
for (File pluginFile : pluginFiles) {
if (pluginFile.getName().endsWith(".jar")) {
@@ -329,12 +391,19 @@ public class MasterServerPluginContainer {
ServerPluginDescriptorType descriptor;
descriptor = ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
if (descriptor != null) {
- if (!disabledPlugins.contains(descriptor.getName())) {
+ if (!allDisabledPlugins.contains(descriptor.getName())) {
log.debug("pre-loaded server plugin from URL: " + pluginUrl);
plugins.put(pluginUrl, descriptor);
} else {
log.info("Server plugin [" + descriptor.getName()
+ "] is disabled and will not be initialized");
+ ServerPluginType pluginType = new ServerPluginType(descriptor);
+ List<String> disabledByType = this.disabledPlugins.get(pluginType);
+ if (disabledByType == null) {
+ disabledByType = new ArrayList<String>(1);
+ this.disabledPlugins.put(pluginType, disabledByType);
+ }
+ disabledByType.add(descriptor.getName());
}
}
} catch (Throwable t) {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java
index feba2fc..3e6bb34 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginType.java
@@ -29,6 +29,22 @@ import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
public class ServerPluginType {
private final Class<? extends ServerPluginDescriptorType> descriptorType;
+ /**
+ * Given an actual plugin descriptor object, this will create a plugin type
+ * that represents that kind of plugin.
+ *
+ * @param descriptor an actual descriptor parsed from a plugin
+ */
+ public ServerPluginType(ServerPluginDescriptorType descriptor) {
+ this((descriptor != null) ? descriptor.getClass() : null);
+ }
+
+ /**
+ * Given a type of plugin descriptor, this will create a plugin type
+ * that represents that kind of plugin.
+ *
+ * @param descriptorType
+ */
public ServerPluginType(Class<? extends ServerPluginDescriptorType> descriptorType) {
if (descriptorType == null) {
throw new NullPointerException("descriptorType must not be null");
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
index 1dace0b..9f0026b 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
+import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@@ -32,12 +33,16 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.util.stream.StreamUtil;
+import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService.State;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService.TestGenericPluginManager;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService.TestGenericServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.generic.TestLifecycleListener.LifecycleState;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
+import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ScheduledJobDefinition;
+import org.rhq.enterprise.server.xmlschema.generated.serverplugin.generic.GenericPluginDescriptorType;
@Test
public class GenericServerPluginTest extends AbstractEJB3Test {
@@ -76,10 +81,21 @@ public class GenericServerPluginTest extends AbstractEJB3Test {
List<ScheduledJobDefinition> schedules = component.context.getSchedules();
assert schedules == null;
+ ServerPluginsLocal serverPluginsLocal = LookupUtil.getServerPlugins();
+ Map<ServerPluginType, List<String>> map = serverPluginsLocal.getAllPluginsGroupedByType();
+ assert map.size() == 1;
+ List<String> pluginNames = map.get(new ServerPluginType(GenericPluginDescriptorType.class));
+ assert pluginNames.size() == 1;
+ assert pluginNames.get(0).equals("TestSimpleGenericPlugin");
+
// make sure everything is shutdown
this.pluginService.stopMasterPluginContainer();
assert pc.state == State.UNINITIALIZED;
assert component.state == LifecycleState.UNINITIALIZED;
+
+ // with the master down, this method should return an empty map
+ map = serverPluginsLocal.getAllPluginsGroupedByType();
+ assert map.size() == 0;
}
private File createPluginJar(String jarName, String descriptorXmlFilename) throws Exception {
commit 07ae93f34338458daa75082ef519b4b1851ddc0c
Merge: 5e17b2f... 2d97557...
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 11:08:38 2009 -0500
Merge branch 'master' into pc
commit 2d97557a1e09ab13248f5da0e81a8d530731ed78
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Nov 25 11:03:16 2009 -0500
Eagerly initializing underlying list and map in PropertyList and PropertyMap to avoid NPEs
This change was already made in the raw-config branch a while back, and needed to be
ported over.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java
index 2bc77f9..c3e26a0 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java
@@ -68,7 +68,7 @@ public class PropertyList extends Property {
@Cascade( { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DELETE_ORPHAN })
@OneToMany(mappedBy = "parentList", targetEntity = Property.class, fetch = FetchType.EAGER)
//@IndexColumn(name = "list_index") TODO GH: This seems broken
- private List<Property> list;
+ private List<Property> list = new ArrayList<Property>();
@Transient
String memberPropertyName;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java
index 114720f..e8e15b7 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java
@@ -68,7 +68,7 @@ public class PropertyMap extends Property implements AbstractPropertyMap {
@Cascade( { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DELETE_ORPHAN })
@MapKey(name = "name")
@OneToMany(mappedBy = "parentMap", fetch = FetchType.EAGER)
- private Map<String, Property> map;
+ private Map<String, Property> map = new LinkedHashMap<String, Property>();
/**
* Creates a new unnamed and empty {@link PropertyMap} object.
commit 5e17b2f3837504924ab1ec1b7ba48d017f258ef2
Merge: 45e0f2f... ee2e8e8...
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 10:17:56 2009 -0500
Merge branch 'master' into pc
commit 45e0f2f25b7230d65bc561bc63bd1e1cdd7c65f8
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 10:15:39 2009 -0500
use the new deepCopy()
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 8cbffc9..2d67f3f 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
@@ -96,13 +96,13 @@ public class ServerPluginsBean implements ServerPluginsLocal {
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
config = entityManager.find(Configuration.class, config.getId());
- plugin.setPluginConfiguration(config.deepCopyWithoutProxies());
+ plugin.setPluginConfiguration(config.deepCopy());
}
config = plugin.getScheduledJobsConfiguration();
if (config != null) {
config = entityManager.find(Configuration.class, config.getId());
- plugin.setScheduledJobsConfiguration(config.deepCopyWithoutProxies());
+ plugin.setScheduledJobsConfiguration(config.deepCopy());
}
return plugin;
commit b3a962cfa61b2f05b4258b9a25e6e72819473191
Merge: c995032... 37bb080...
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 09:57:31 2009 -0500
Merge branch 'master' into pc
commit ee2e8e847b18491a6093135b6ca906d6063679de
Merge: 1bca0f7... 37bb080...
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Nov 25 09:54:22 2009 -0500
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 1bca0f7c0327498c0dcb7ccb5953d3158c83a563
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Nov 25 09:53:41 2009 -0500
Fixing compilation error that happened as a result of my refactoring RawConfiguration.deepCopy()
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java
index a4ce93b..491612a 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java
@@ -165,7 +165,7 @@ public class RawConfigCollection implements Serializable {
String u2 = updated.substring(2);
String original = new String(getCurrent().getContents());
if (!u2.equals(original)) {
- current = current.deepCopy();
+ current = current.deepCopy(false);
current.setContents(updated.getBytes());
//TODO update other values like MD5
modified.put(current.getPath(), current);
commit c995032cbc61261e353c523259810d076d586519
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Nov 25 09:51:34 2009 -0500
fix NPE when plugin config or scheduled jobs config is null
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 1415bb5..8cbffc9 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
@@ -93,12 +93,17 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public Plugin getServerPluginRelationships(Plugin plugin) {
plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
- 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());
+ Configuration config = plugin.getPluginConfiguration();
+ if (config != null) {
+ config = entityManager.find(Configuration.class, config.getId());
+ plugin.setPluginConfiguration(config.deepCopyWithoutProxies());
+ }
+
+ config = plugin.getScheduledJobsConfiguration();
+ if (config != null) {
+ config = entityManager.find(Configuration.class, config.getId());
+ plugin.setScheduledJobsConfiguration(config.deepCopyWithoutProxies());
+ }
return plugin;
}
@@ -239,7 +244,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
File currentFile = new File(pluginDir, doomedPlugin.getPath());
currentFile.delete();
} catch (Exception e) {
- log.error("Failed to delete the undeployed plugin [" + doomedPlugin.getPath() + "]. Cause: " + ThrowableUtil.getAllMessages(e));
+ log.error("Failed to delete the undeployed plugin [" + doomedPlugin.getPath() + "]. Cause: "
+ + ThrowableUtil.getAllMessages(e));
}
}
}
@@ -275,7 +281,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void setServerPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status)
- throws Exception {
+ throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
@@ -291,7 +297,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception {
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] must be a server plugin to be registered");
+ throw new IllegalArgumentException("Plugin [" + plugin.getName()
+ + "] must be a server plugin to be registered");
}
Plugin existingPlugin = null;
@@ -304,7 +311,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (existingPlugin != null) {
if (existingPlugin.getStatus() == PluginStatusType.DELETED) {
- throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName() + "], it has been marked as deleted");
+ throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
+ + "], it has been marked as deleted");
}
Plugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
if (obsolete == existingPlugin) { // yes use == for reference equality
@@ -322,7 +330,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (plugin.getId() == 0) {
PluginStatusType status = getServerPluginStatus(plugin.getName());
if (PluginStatusType.DELETED == status) {
- throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName() + "], it has been previously marked as deleted.");
+ throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
+ + "], it has been previously marked as deleted.");
}
entityManager.persist(plugin);
} else {
@@ -364,7 +373,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
// to entityManager.merge that plugin POJO, it would null out that blob column.
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] must be a server plugin to be updated");
+ throw new IllegalArgumentException("Plugin [" + plugin.getName()
+ + "] must be a server plugin to be updated");
}
if (plugin.getId() == 0) {
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 803f7cf..df685d4 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
@@ -42,6 +42,7 @@ public interface ServerPluginsLocal {
*
* @param plugin
* @return the same plugin, with the relationship data loaded
+ * @throws NoResultException when no plugin with that name exists
*/
Plugin getServerPluginRelationships(Plugin plugin);
commit 37bb080675c956c976ffc3110361c11e19ae87a0
Author: Galder Zamarreno <rnd(a)zamarreno.com>
Date: Wed Nov 25 15:20:34 2009 +0100
Operation returns only one result now.
diff --git a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
index 0388d8a..a657f42 100644
--- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
+++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
@@ -527,7 +527,7 @@ public class Props {
private String displayName;
private String description;
private Set<SimpleProperty> params = new LinkedHashSet<SimpleProperty>();
- private Set<SimpleProperty> results = new LinkedHashSet<SimpleProperty>();
+ private SimpleProperty result;
public OperationProps(String name) {
this.name = name;
@@ -557,8 +557,12 @@ public class Props {
return params;
}
- public Set<SimpleProperty> getResults() {
- return results;
+ public SimpleProperty getResult() {
+ return result;
+ }
+
+ public void setResult(SimpleProperty result) {
+ this.result = result;
}
}
}
diff --git a/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl b/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl
index ca498b5..0343787 100644
--- a/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl
+++ b/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl
@@ -60,11 +60,9 @@ name="${props.name}" <#-- TODO separate out plugin name and service name -->
</#list>
</parameters>
</#if>
- <#if operation.results?has_content>
+ <#if operation.result??>
<results>
- <#list operation.results as results>
- <c:simple-property name="${results.name}" />
- </#list>
+ <c:simple-property name="${operation.result.name}" />
</results>
</#if>
</operation>
commit cc1b2af501010b1734b42d4a70e30a43db65d3ee
Author: Galder Zamarreno <rnd(a)zamarreno.com>
Date: Wed Nov 25 14:37:33 2009 +0100
Returns for operations can now be generated.
diff --git a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
index 76b374b..0388d8a 100644
--- a/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
+++ b/modules/helpers/pluginGen/src/main/java/org/rhq/helpers/pluginGen/Props.java
@@ -527,6 +527,7 @@ public class Props {
private String displayName;
private String description;
private Set<SimpleProperty> params = new LinkedHashSet<SimpleProperty>();
+ private Set<SimpleProperty> results = new LinkedHashSet<SimpleProperty>();
public OperationProps(String name) {
this.name = name;
@@ -555,5 +556,9 @@ public class Props {
public Set<SimpleProperty> getParams() {
return params;
}
+
+ public Set<SimpleProperty> getResults() {
+ return results;
+ }
}
}
diff --git a/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl b/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl
index a148a61..ca498b5 100644
--- a/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl
+++ b/modules/helpers/pluginGen/src/main/resources/descriptorMain.ftl
@@ -60,6 +60,13 @@ name="${props.name}" <#-- TODO separate out plugin name and service name -->
</#list>
</parameters>
</#if>
+ <#if operation.results?has_content>
+ <results>
+ <#list operation.results as results>
+ <c:simple-property name="${results.name}" />
+ </#list>
+ </results>
+ </#if>
</operation>
</#list>
<#else>
commit a0ab1b28c3ef8ab152c4decf9e8dbaebbede80dd
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Nov 25 00:08:22 2009 -0500
Deleting directory that accidentally included in a previous commit
diff --git a/modules/core/domain/src/main/java/META-INF/MANIFEST.MF b/modules/core/domain/src/main/java/META-INF/MANIFEST.MF
deleted file mode 100644
index 3090f97..0000000
--- a/modules/core/domain/src/main/java/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,4 +0,0 @@
-Manifest-Version: 1.0
-Class-Path: i18nlog-1.0.9.jar jaxb-api-2.1.jar stax-api-1.0-2.jar acti
- vation-1.1.jar rhq-core-util-1.4.0-SNAPSHOT.jar jdom-1.0.jar
-
commit 1643800fb94b472d11bedc1d5d4d756b4ad54ee0
Author: John Sanda <john(a)localhost.localdomain>
Date: Wed Nov 25 00:07:18 2009 -0500
[US 6] Refactoring Configuration.deepCopy() to properly handle hibernate proxies.
Refactoring implementors of DeepCopyable to take a boolean flag that indicates
whether or not to copy the id field. Unit tests have been updated to reflect the change.
Conflicts:
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/RawConfigurationTest.java
diff --git a/modules/core/domain/src/main/java/META-INF/MANIFEST.MF b/modules/core/domain/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..3090f97
--- /dev/null
+++ b/modules/core/domain/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Class-Path: i18nlog-1.0.9.jar jaxb-api-2.1.jar stax-api-1.0-2.jar acti
+ vation-1.1.jar rhq-core-util-1.4.0-SNAPSHOT.jar jdom-1.0.jar
+
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
index 3ce2965..62bd8ce 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
@@ -454,55 +454,40 @@ public class Configuration implements Externalizable, Cloneable, AbstractPropert
* @return the new copy
*/
public Configuration deepCopy(boolean keepIds) {
- Configuration copy;
+ Configuration copy = new Configuration();
- try {
- copy = clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException("CloneNotSupported can't happen");
+ if (keepIds) {
+ copy.id = this.id;
}
- if (!keepIds) {
- copy.id = 0;
-
- for (Property property : copy.properties.values()) {
- clearIds(property);
- }
- }
+ copy.notes = this.notes;
+ copy.version = this.version;
+ createDeepCopyOfProperties(copy, keepIds);
+ createDeepCopyOfRawConfigs(copy, keepIds);
return copy;
}
- private void clearIds(Property property) {
- property.setId(0);
-
- if (property instanceof PropertyList) {
- for (Property childProperty : ((PropertyList) property).getList()) {
- clearIds(childProperty);
- }
- } else if (property instanceof PropertyMap) {
- for (Property childProperty : ((PropertyMap) property).getMap().values()) {
- clearIds(childProperty);
- }
- }
-
- return;
- }
-
public Configuration deepCopyWithoutProxies() {
Configuration copy = new Configuration();
copy.notes = this.notes;
copy.version = this.version;
+ createDeepCopyOfProperties(copy, false);
+ createDeepCopyOfRawConfigs(copy, false);
- for (Property property : this.properties.values()) {
- copy.put(property.deepCopy());
- }
+ return copy;
+ }
+ private void createDeepCopyOfRawConfigs(Configuration copy, boolean keepId) {
for (RawConfiguration rawConfig : rawConfigurations) {
- copy.addRawConfiguration(rawConfig.deepCopy());
+ copy.addRawConfiguration(rawConfig.deepCopy(keepId));
}
+ }
- return copy;
+ private void createDeepCopyOfProperties(Configuration copy, boolean keepId) {
+ for (Property property : this.properties.values()) {
+ copy.put(property.deepCopy(keepId));
+ }
}
/**
@@ -664,7 +649,22 @@ public class Configuration implements Externalizable, Cloneable, AbstractPropert
out.writeLong(version);
out.writeLong(ctime);
out.writeLong(mtime);
+ }
// Explicitly do not send the history relationship
+ private Map<String, Property> createDeepCopyOfMap() {
+ Map<String, Property> copy = new HashMap<String, Property>();
+ for (Map.Entry<String, Property> entry : this.properties.entrySet()) {
+ copy.put(entry.getKey(), entry.getValue().deepCopy(true));
+ }
+ return copy;
+ }
+
+ private Set<RawConfiguration> createDeepCopyOfRawConfigs() {
+ Set<RawConfiguration> copy = new HashSet<RawConfiguration>();
+ for (RawConfiguration rawConfig : this.rawConfigurations) {
+ copy.add(rawConfig.deepCopy(true));
+ }
+ return copy;
}
@SuppressWarnings("unchecked")
@@ -694,4 +694,4 @@ public class Configuration implements Externalizable, Cloneable, AbstractPropert
public Map<String, Property> getAllProperties() {
return this.properties;
}
-}
\ No newline at end of file
+}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/DeepCopyable.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/DeepCopyable.java
index e3e56d5..c680b04 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/DeepCopyable.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/DeepCopyable.java
@@ -25,6 +25,6 @@ package org.rhq.core.domain.configuration;
public interface DeepCopyable<T> {
- T deepCopy();
+ T deepCopy(boolean keepId);
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Property.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Property.java
index f4494c8..5c1ba79 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Property.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Property.java
@@ -127,7 +127,10 @@ public class Property implements Externalizable, DeepCopyable<Property> {
public Property() {
}
- protected Property(Property original) {
+ protected Property(Property original, boolean keepId) {
+ if (keepId) {
+ this.id = original.id;
+ }
this.errorMessage = original.errorMessage;
this.name = original.name;
}
@@ -284,7 +287,7 @@ public class Property implements Externalizable, DeepCopyable<Property> {
return ((this.name != null) ? this.name.hashCode() : 0);
}
- public Property deepCopy() {
+ public Property deepCopy(boolean keepId) {
return null;
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java
index a2223d9..2bc77f9 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyList.java
@@ -86,8 +86,8 @@ public class PropertyList extends Property {
setName(name);
}
- protected PropertyList(PropertyList original) {
- super(original);
+ protected PropertyList(PropertyList original, boolean keepId) {
+ super(original, keepId);
}
/**
@@ -212,11 +212,11 @@ public class PropertyList extends Property {
return result;
}
- public PropertyList deepCopy() {
- PropertyList copy = new PropertyList(this);
+ public PropertyList deepCopy(boolean keepId) {
+ PropertyList copy = new PropertyList(this, keepId);
for (Property property : list) {
- copy.add(property.deepCopy());
+ copy.add(property.deepCopy(false));
}
return copy;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java
index 137c6fe..114720f 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertyMap.java
@@ -76,8 +76,8 @@ public class PropertyMap extends Property implements AbstractPropertyMap {
public PropertyMap() {
}
- protected PropertyMap(PropertyMap original) {
- super(original);
+ protected PropertyMap(PropertyMap original, boolean keepId) {
+ super(original, keepId);
}
/**
@@ -263,11 +263,11 @@ public class PropertyMap extends Property implements AbstractPropertyMap {
return result;
}
- public PropertyMap deepCopy() {
- PropertyMap copy = new PropertyMap(this);
+ public PropertyMap deepCopy(boolean keepId) {
+ PropertyMap copy = new PropertyMap(this, keepId);
for (Property property : map.values()) {
- copy.put(property.deepCopy());
+ copy.put(property.deepCopy(keepId));
}
return copy;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertySimple.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertySimple.java
index 0824553..04aeb7e 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertySimple.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/PropertySimple.java
@@ -70,8 +70,8 @@ public class PropertySimple extends Property implements Externalizable {
override = Boolean.FALSE;
}
- protected PropertySimple(PropertySimple original) {
- super(original);
+ protected PropertySimple(PropertySimple original, boolean keepId) {
+ super(original, keepId);
this.override = original.override;
this.unmaskedStringValue = original.unmaskedStringValue;
this.stringValue = original.stringValue;
@@ -85,9 +85,7 @@ public class PropertySimple extends Property implements Externalizable {
* @param name
* @param value
*/
- public PropertySimple(@NotNull
- String name, @Nullable
- Object value) {
+ public PropertySimple(@NotNull String name, @Nullable Object value) {
setName(name);
setValue(value);
}
@@ -98,8 +96,7 @@ public class PropertySimple extends Property implements Externalizable {
*
* @param value
*/
- public void setValue(@Nullable
- Object value) {
+ public void setValue(@Nullable Object value) {
if (value == null) {
stringValue = null;
return;
@@ -131,8 +128,7 @@ public class PropertySimple extends Property implements Externalizable {
*
* @param value
*/
- public void setStringValue(@Nullable
- String value) {
+ public void setStringValue(@Nullable String value) {
this.setValue(value);
}
@@ -157,8 +153,7 @@ public class PropertySimple extends Property implements Externalizable {
*
* @param value
*/
- public void setBooleanValue(@Nullable
- Boolean value) {
+ public void setBooleanValue(@Nullable Boolean value) {
this.setValue(value);
}
@@ -207,8 +202,7 @@ public class PropertySimple extends Property implements Externalizable {
*
* @param value
*/
- public void setIntegerValue(@Nullable
- Integer value) {
+ public void setIntegerValue(@Nullable Integer value) {
this.setValue(value);
}
@@ -232,8 +226,7 @@ public class PropertySimple extends Property implements Externalizable {
*
* @param value
*/
- public void setFloatValue(@Nullable
- Float value) {
+ public void setFloatValue(@Nullable Float value) {
this.setValue(value);
}
@@ -257,8 +250,7 @@ public class PropertySimple extends Property implements Externalizable {
*
* @param value
*/
- public void setDoubleValue(@Nullable
- Double value) {
+ public void setDoubleValue(@Nullable Double value) {
this.setValue(value);
}
@@ -336,8 +328,8 @@ public class PropertySimple extends Property implements Externalizable {
return result;
}
- public PropertySimple deepCopy() {
- return new PropertySimple(this);
+ public PropertySimple deepCopy(boolean keepId) {
+ return new PropertySimple(this, keepId);
}
@Override
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/RawConfiguration.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/RawConfiguration.java
index ca02070..22a7161 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/RawConfiguration.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/RawConfiguration.java
@@ -243,9 +243,14 @@ public class RawConfiguration implements Serializable, DeepCopyable<RawConfigura
.toString();
}
- public RawConfiguration deepCopy() {
+ public RawConfiguration deepCopy(boolean keepId) {
RawConfiguration copy = new RawConfiguration();
+ if (keepId) {
+ copy.id = this.id;
+ }
+
copy.path = this.path;
+
if (this.contents != null) {
copy.setContents(this.getContents());
}
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationTest.java
index 36084ec..85afc00 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationTest.java
@@ -38,59 +38,107 @@ import java.util.Set;
public class ConfigurationTest {
@Test
- public void deepCopyWithoutProxiesShouldNotReturnReferenceToOriginalObject() {
+ public void deepCopyShouldNotReturnReferenceToOriginalObjectWhenKeepingIds() {
Configuration original = createConfiguration();
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(true);
assertNotSame(copy, original, "Expected a reference to a new Configuration object, not the original object being copied");
}
@Test
- public void deepCopyWithoutProxiesShouldCopySimpleFields() {
+ public void deepCopyShouldNotReturnReferenceToOriginalObjectWhenNotKeepingIds() {
Configuration original = createConfiguration();
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(false);
+ assertNotSame(copy, original, "Expected a reference to a new Configuration object, not the original object being copied");
+ }
+
+ @Test
+ public void deepCopyShouldCopyAllSimpleFieldsWhenKeepingIds() {
+ Configuration original = createConfiguration();
+ Configuration copy = original.deepCopy(true);
+
+ assertEquals(copy.getId(), original.getId(), "Failed to copy the id property");
assertEquals(copy.getNotes(), original.getNotes(), "Failed to copy the notes property");
assertEquals(copy.getVersion(), original.getVersion(), "Failed to copy version property");
}
@Test
- public void deepCopyWithoutProxiesShouldNotCopyIdProperty() {
+ public void deepCopyShouldNotCopyIdWhenNotKeepingIds() {
Configuration original = createConfiguration();
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(false);
assertFalse(copy.getId() == original.getId(), "The original id property should not be copied");
+ assertEquals(copy.getNotes(), original.getNotes(), "Failed to copy the notes property");
+ assertEquals(copy.getVersion(), original.getVersion(), "Failed to copy version property");
+ }
+
+ @Test
+ public void deepCopyShouldCopyPropertiesWhenKeepingIds() {
+ Configuration original = createConfiguration();
+ original.put(new PropertySimple("simpleProperty", "Simple Property"));
+
+ Configuration copy = original.deepCopy(true);
+
+ assertNotSame(copy.getProperties(), original.getProperties(), "The properties property should not refer to the properties in the original object");
+ assertEquals(copy.getProperties(), original.getProperties(), "Failed to copy the contents of the properties collection");
}
@Test
- public void deepCopyWithoutProxiesShouldCopyProperties() {
+ public void deepCopyShouldCopyPropertiesWhenNotKeepingIds() {
Configuration original = createConfiguration();
original.put(new PropertySimple("simpleProperty", "Simple Property"));
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(false);
assertNotSame(copy.getProperties(), original.getProperties(), "The properties property should not refer to the properties in the original object");
assertEquals(copy.getProperties(), original.getProperties(), "Failed to copy the contents of the properties collection");
}
@Test
- public void deepCopyWithoutProxiesShouldNotReturnCopyReferenceOfOriginalProperty() {
+ public void deepCopyShouldNotReturnCopyReferenceOfOriginalPropertyWhenKeepingIds() {
Configuration original = createConfiguration();
String propertyName = "simpleProperty";
original.put(new PropertySimple(propertyName, "Simple Property"));
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(true);
assertNotSame(copy.get(propertyName), original.get(propertyName), "Expected a refernce to a new property, not the original property being copied");
}
@Test
- public void deepCopyWithoutProxiesShouldSetParentReferenceOfCopiedProperties() {
+ public void deepCopyShouldNotReturnCopyReferenceOfOriginalPropertyWhenNotKeepingIds() {
+ Configuration original = createConfiguration();
+ String propertyName = "simpleProperty";
+ original.put(new PropertySimple(propertyName, "Simple Property"));
+
+ Configuration copy = original.deepCopy(false);
+
+ assertNotSame(copy.get(propertyName), original.get(propertyName), "Expected a refernce to a new property, not the original property being copied");
+ }
+
+ @Test
+ public void deepCopyShouldSetParentReferenceOfCopiedPropertiesWhenKeepingIds() {
+ Configuration original = createConfiguration();
+ String propertyName = "simpleProperty";
+ original.put(new PropertySimple(propertyName, "Simple Property"));
+
+ Configuration copy = original.deepCopy(true);
+
+ assertSame(
+ copy.get(propertyName).getConfiguration(),
+ copy,
+ "The reference to the parent configuration should point to the newly copied configuration, not the original configuration"
+ );
+ }
+
+ @Test
+ public void deepCopyShouldSetParentReferenceOfCopiedPropertiesWhenNotKeepingIds() {
Configuration original = createConfiguration();
String propertyName = "simpleProperty";
original.put(new PropertySimple(propertyName, "Simple Property"));
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(false);
assertSame(
copy.get(propertyName).getConfiguration(),
@@ -100,11 +148,27 @@ public class ConfigurationTest {
}
@Test
- public void deepCopyWithoutProxiesShouldCopyRawConfigurations() {
+ public void deepCopyShouldCopyRawConfigurationsWhenKeepingIds() {
Configuration original = createConfiguration();
original.addRawConfiguration(createRawConfiguration("/tmp/foo"));
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(true);
+
+ assertNotSame(
+ copy.getRawConfigurations(),
+ original.getRawConfigurations(),
+ "The rawConfigurations property should not refer to the original rawConfigurations of the copied object."
+ );
+
+ assertRawConfigurationsEquals(copy.getRawConfigurations(), original.getRawConfigurations(), "Failed to copy rawConfigurations property.");
+ }
+
+ @Test
+ public void deepCopyShouldCopyRawConfigurationsWhenNotKeepingIds() {
+ Configuration original = createConfiguration();
+ original.addRawConfiguration(createRawConfiguration("/tmp/foo"));
+
+ Configuration copy = original.deepCopy(false);
assertNotSame(
copy.getRawConfigurations(),
@@ -123,11 +187,26 @@ public class ConfigurationTest {
}
@Test
- public void deepCopyWithoutProxiesShouldSetParentReferenceOfCopiedRawConfigurations() {
+ public void deepCopyShouldSetParentReferenceOfCopiedRawConfigurationsWhenKeepingIds() {
+ Configuration original = createConfiguration();
+ original.addRawConfiguration(createRawConfiguration("/tmp/foo"));
+
+ Configuration copy = original.deepCopy(true);
+ RawConfiguration copiedRawConfig = getCopiedRawConfiguration(copy);
+
+ assertSame(
+ copiedRawConfig.getConfiguration(),
+ copy,
+ "The reference to the parent configuration should point to the newly copied configuration, not the original configuration."
+ );
+ }
+
+ @Test
+ public void deepCopyShouldSetParentReferenceOfCopiedRawConfigurationsWhenNotKeepingIds() {
Configuration original = createConfiguration();
original.addRawConfiguration(createRawConfiguration("/tmp/foo"));
- Configuration copy = original.deepCopyWithoutProxies();
+ Configuration copy = original.deepCopy(false);
RawConfiguration copiedRawConfig = getCopiedRawConfiguration(copy);
assertSame(
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyListTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyListTest.java
index d298001..56d3887 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyListTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyListTest.java
@@ -30,41 +30,52 @@ import org.testng.annotations.Test;
public class PropertyListTest {
@Test
- public void deepCopyShouldCopySimpleFields() {
+ public void deepCopyShouldCopyAllSimpleFields() {
PropertyList original = createPropertyList();
- PropertyList copy = original.deepCopy();
+ PropertyList copy = original.deepCopy(true);
assertNotSame(copy, original, "The copy should not reference the original object");
-
+
+ assertEquals(copy.getId(), original.getId(), "Failed to copy the id property");
assertEquals(copy.getName(), original.getName(), "Failed to copy the name property");
assertEquals(copy.getErrorMessage(), original.getErrorMessage(), "Failed to copy the errorMessage property");
}
@Test
- public void deepCopyShouldNotCopyIdField() {
+ public void deepCopyShouldNotCopyIdFieldWhenFlagIsFalse() {
PropertyList original = createPropertyList();
- PropertyList copy = original.deepCopy();
+ PropertyList copy = original.deepCopy(false);
assertFalse(copy.getId() == original.getId(), "The original id property should not be copied.");
+ assertEquals(copy.getName(), original.getName(), "Failed to copy the name property");
+ assertEquals(copy.getErrorMessage(), original.getErrorMessage(), "Failed to copy the errorMessage property");
+ }
+
+ @Test
+ public void deepCopyShouldNotCopyReferenceOfUnderlyingListWhenIdIncluded() {
+ PropertyList original = createPropertyList();
+ PropertyList copy = original.deepCopy(true);
+
+ assertNotSame(original.getList(), copy.getList(), "The values in the underlying list should be copied, not the variable reference to the list.");
}
@Test
- public void deepCopyShouldNotCopyReferenceOfUnderlyingList() {
+ public void deepCopyShouldNotCopyReferenceOfUnderlyingListWhenIdNotIncluded() {
PropertyList original = createPropertyList();
- PropertyList copy = original.deepCopy();
+ PropertyList copy = original.deepCopy(false);
assertNotSame(original.getList(), copy.getList(), "The values in the underlying list should be copied, not the variable reference to the list.");
}
@Test
- public void deepCopyShouldCopyProperty() {
+ public void deepCopyShouldCopyPropertyWhenIdIncluded() {
PropertyList original = createPropertyList();
PropertySimple simpleProperty = new PropertySimple("simeplProperty", "Simple Property");
original.add(simpleProperty);
- PropertyList copy = original.deepCopy();
+ PropertyList copy = original.deepCopy(true);
assertEquals(copy.getList().size(), original.getList().size(), "Failed to copy simple property contained in original property list");
@@ -72,13 +83,39 @@ public class PropertyListTest {
}
@Test
- public void deepCopyShouldSetParentOfCopiedProperty() {
+ public void deepCopyShouldCopyPropertyWhenIdNotIncluded() {
+ PropertyList original = createPropertyList();
+
+ PropertySimple simpleProperty = new PropertySimple("simeplProperty", "Simple Property");
+ original.add(simpleProperty);
+
+ PropertyList copy = original.deepCopy(false);
+
+ assertEquals(copy.getList().size(), original.getList().size(), "Failed to copy simple property contained in original property list");
+
+ assertNotSame(copy.getList().get(0), original.getList().get(0), "Properties in the list should be copied by value as opposed to just copying the references");
+ }
+
+ @Test
+ public void deepCopyShouldSetParentOfCopiedPropertyWhenIdIncluded() {
+ PropertyList original = createPropertyList();
+
+ PropertySimple simpleProperty = new PropertySimple("simpleProperty", "Simple Property");
+ original.add(simpleProperty);
+
+ PropertyList copy = original.deepCopy(true);
+
+ assertSame(copy.getList().get(0).getParentList(), copy, "The parentList property of copied properties should be set to the new PropertyList");
+ }
+
+ @Test
+ public void deepCopyShouldSetParentOfCopiedPropertyWhenIdNotIncluded() {
PropertyList original = createPropertyList();
PropertySimple simpleProperty = new PropertySimple("simpleProperty", "Simple Property");
original.add(simpleProperty);
- PropertyList copy = original.deepCopy();
+ PropertyList copy = original.deepCopy(false);
assertSame(copy.getList().get(0).getParentList(), copy, "The parentList property of copied properties should be set to the new PropertyList");
}
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyMapTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyMapTest.java
index 4a999b6..e73d835 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyMapTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertyMapTest.java
@@ -30,40 +30,55 @@ import org.testng.annotations.Test;
public class PropertyMapTest {
@Test
- public void deepCopyShouldCopySimpleFields() {
+ public void deepCopyShouldCopyAllSimpleFields() {
PropertyMap original = createPropertyMap();
- PropertyMap copy = original.deepCopy();
+ PropertyMap copy = original.deepCopy(true);
assertNotSame(copy, original, "The copy should not reference the original object");
+ assertEquals(copy.getId(), original.getId(), "Failed to copy the id property");
assertEquals(copy.getName(), original.getName(), "Failed to copy the name property");
assertEquals(copy.getErrorMessage(), original.getErrorMessage(), "Failed to copy the errorMessage property");
}
@Test
- public void deepCopyShouldNotCopyIdField() {
+ public void deepCopyShouldNotCopyIdFieldWhenFlagIsFalse() {
PropertyMap original = createPropertyMap();
- PropertyMap copy = original.deepCopy();
+ PropertyMap copy = original.deepCopy(false);
+
+ assertNotSame(copy, original, "The copy should not reference the original object");
assertFalse(copy.getId() == original.getId(), "The original id property should not be copied.");
+ assertEquals(copy.getName(), original.getName(), "Failed to copy the name property");
+ assertEquals(copy.getErrorMessage(), original.getErrorMessage(), "Failed to copy the errorMessage property");
}
@Test
- public void deepCopyShouldNotCopyReferenceOfUnderlyingMap() {
+ public void deepCopyShouldCopyPropertyWhenIdIncluded() {
PropertyMap original = createPropertyMap();
- PropertyMap copy = original.deepCopy();
- assertNotSame(copy.getMap(), original.getMap(), "The values in the underlying map should be copied, not the reference to the map itself");
+ PropertySimple simpleProperty = new PropertySimple("simeplProperty", "Simple Property");
+ original.put(simpleProperty);
+
+ PropertyMap copy = original.deepCopy(true);
+
+ assertEquals(copy.getMap().size(), original.getMap().size(), "Failed to copy simple property contained in original property map");
+
+ assertNotSame(
+ copy.getMap().get(simpleProperty.getName()),
+ original.getMap().get(simpleProperty.getName()),
+ "Properties in the map should be copied by value as opposed to just copying the references"
+ );
}
@Test
- public void deepCopyShouldCopyProperty() {
+ public void deepCopyShouldCopyPropertyWhenIdNotIncluded() {
PropertyMap original = createPropertyMap();
PropertySimple simpleProperty = new PropertySimple("simeplProperty", "Simple Property");
original.put(simpleProperty);
- PropertyMap copy = original.deepCopy();
+ PropertyMap copy = original.deepCopy(false);
assertEquals(copy.getMap().size(), original.getMap().size(), "Failed to copy simple property contained in original property map");
@@ -75,13 +90,29 @@ public class PropertyMapTest {
}
@Test
- public void deepCopyShouldSetParentOfCopiedProperty() {
+ public void deepCopyShouldSetParentOfCopiedPropertyWhenIdIncluded() {
+ PropertyMap original = createPropertyMap();
+
+ PropertySimple simpleProperty = new PropertySimple("simpleProperty", "Simple Property");
+ original.put(simpleProperty);
+
+ PropertyMap copy = original.deepCopy(true);
+
+ assertSame(
+ copy.get(simpleProperty.getName()).getParentMap(),
+ copy,
+ "The parentMap property of copied properties should be set to the new PropertyMap"
+ );
+ }
+
+ @Test
+ public void deepCopyShouldSetParentOfCopiedPropertyWhenIdNotIncluded() {
PropertyMap original = createPropertyMap();
PropertySimple simpleProperty = new PropertySimple("simpleProperty", "Simple Property");
original.put(simpleProperty);
- PropertyMap copy = original.deepCopy();
+ PropertyMap copy = original.deepCopy(false);
assertSame(
copy.get(simpleProperty.getName()).getParentMap(),
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertySimpleTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertySimpleTest.java
index c1b76aa..7b49837 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertySimpleTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/PropertySimpleTest.java
@@ -30,13 +30,14 @@ import org.testng.annotations.Test;
public class PropertySimpleTest {
@Test
- public void deepCopyShouldCopySimpleFields() {
+ public void deepCopyShouldCopyAllSimpleFields() {
PropertySimple original = createProperty();
- PropertySimple copy = original.deepCopy();
+ PropertySimple copy = original.deepCopy(true);
assertNotSame(copy, original, "The copy should not reference the original object");
-
+
+ assertEquals(copy.getId(), original.getId(), "Failed to copy the id property");
assertEquals(copy.getName(), original.getName(), "Failed to copy the name property");
assertEquals(copy.getErrorMessage(), original.getErrorMessage(), "Failed to copy the errorMessage property");
assertEquals(copy.getOverride(), original.getOverride(), "Failed to copy the override property");
@@ -45,12 +46,17 @@ public class PropertySimpleTest {
}
@Test
- public void deepCopyShouldNotCopyIdField() {
+ public void deepCopyShouldNotCopyIdFieldWhenFlagIsFalse() {
PropertySimple original = createProperty();
- PropertySimple copy = original.deepCopy();
+ PropertySimple copy = original.deepCopy(false);
assertFalse(copy.getId() == original.getId(), "The original id property should not be copied.");
+ assertEquals(copy.getName(), original.getName(), "Failed to copy the name property");
+ assertEquals(copy.getErrorMessage(), original.getErrorMessage(), "Failed to copy the errorMessage property");
+ assertEquals(copy.getOverride(), original.getOverride(), "Failed to copy the override property");
+ assertEquals(copy.getUnmaskedStringValue(), original.getUnmaskedStringValue(), "Failed to copy the unmaskedStringValue property");
+ assertEquals(copy.getStringValue(), original.getStringValue(), "Failed to copy the stringValue property");
}
private PropertySimple createProperty() {
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/RawConfigurationTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/RawConfigurationTest.java
index fb926af..8f0aac8 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/RawConfigurationTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/RawConfigurationTest.java
@@ -212,33 +212,49 @@ public class RawConfigurationTest {
}
@Test
- public void deepCopyShouldCopyPath() {
+ public void deepCopyShouldCopyPathAndIdWhenIdIncluded() {
RawConfiguration original = new RawConfiguration();
original.setPath("/tmp/foo");
+ original.setId(-1);
- RawConfiguration copy = original.deepCopy();
+ RawConfiguration copy = original.deepCopy(true);
+ assertEquals(copy.getId(), copy.getId(), "Failed to copy the id property.");
assertEquals(copy.getPath(), original.getPath(), "Failed to copy the path property.");
}
@Test
- public void deepCopyShouldCopyContents() {
+ public void deepCopyShouldCopyPathAndIdWhenIdNotIncluded() {
+ RawConfiguration original = new RawConfiguration();
+ original.setPath("/tmp/foo");
+ original.setId(-1);
+
+ RawConfiguration copy = original.deepCopy(false);
+
+ assertFalse(copy.getId() == original.getId(), "The original id property should not be copied.");
+ assertEquals(copy.getPath(), original.getPath(), "Failed to copy the path property.");
+ }
+
+ @Test
+ public void deepCopyShouldCopyContentsWhenCopyingId() {
RawConfiguration original = new RawConfiguration();
original.setContents(new byte[] {1, 2, 3, 4, 5});
- RawConfiguration copy = original.deepCopy();
+ RawConfiguration copy = original.deepCopy(true);
assertFalse(original.getContents() == copy.getContents(), "The values in the contents array should be copied, not the reference to the original object.");
assertEquals(copy.getContents(), original.getContents(), "Failed to copy contents property.");
}
@Test
- public void deepCopyShouldNotCopyIdProperty() {
+ public void deepCopyShouldCopyContentsWhenNotCopyingId() {
RawConfiguration original = new RawConfiguration();
- original.setId(1);
+ original.setContents(new byte[] {1, 2, 3, 4, 5});
- RawConfiguration copy = original.deepCopy();
+ RawConfiguration copy = original.deepCopy(false);
- assertFalse(original.getId() == copy.getId(), "The id property should not be copied.");
+ assertFalse(original.getContents() == copy.getContents(), "The values in the contents array should be copied, not the reference to the original object.");
+ assertEquals(copy.getContents(), original.getContents(), "Failed to copy contents property.");
}
+
}
commit 9994ec529ecf93914ab48d25023327ee0eb3f503
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Nov 24 16:41:38 2009 -0500
add a test to confirm that snapshot versions are considered older than candidate releases or releases
diff --git a/modules/core/util/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/modules/core/util/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java
index d9c2a9f..dfee3a5 100644
--- a/modules/core/util/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java
+++ b/modules/core/util/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java
@@ -161,5 +161,14 @@ public class ComparableVersionTest {
assert ver2.compareTo(ver2) == 0;
assert ver1.compareTo(ver2) > 0; // ver1 is after ver2!
assert ver2.compareTo(ver1) < 0; // ver1 is after ver2!
+
+ ver1 = new ComparableVersion("4.0.0-SNAPSHOT");
+ ver2 = new ComparableVersion("4.0.0.CR2"); // CR is an alias for RC
+ assert !ver1.equals(ver2);
+ assert !ver2.equals(ver1);
+ assert ver1.compareTo(ver1) == 0;
+ assert ver2.compareTo(ver2) == 0;
+ assert ver1.compareTo(ver2) < 0;
+ assert ver2.compareTo(ver1) > 0;
}
}
commit 93cd6e74d101d7dc645ac38168b4d0157752bf8d
Author: Justin Harris <jharris(a)redhat.com>
Date: Tue Nov 24 14:57:46 2009 -0500
Moving in some seam functionality to allow for page scoped beans in form submission.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
new file mode 100644
index 0000000..0bb87bd
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
@@ -0,0 +1,73 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.admin.plugin;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.web.RequestParameter;
+import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * Component responsible for looking up a {@link Plugin}, obtaining
+ * the <code>name</code> and <code>type</code> from request parameters.
+ *
+ * @author jharris
+ */
+@Name("installedPlugin")
+public class InstalledPluginComponent {
+
+ @RequestParameter("plugin")
+ private String name;
+ @RequestParameter("pluginType")
+ private PluginDeploymentType type;
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public PluginDeploymentType getType() {
+ return this.type;
+ }
+
+ public void setType(PluginDeploymentType type) {
+ this.type = type;
+ }
+
+ @Factory(value="plugin", autoCreate=true, scope=ScopeType.PAGE)
+ public Plugin lookupPlugin() {
+ if (this.type == PluginDeploymentType.AGENT) {
+ return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
+ } else if (this.type == PluginDeploymentType.SERVER) {
+ ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
+ Plugin plugin = serverPluginsBean.getServerPlugin(this.name);
+ return serverPluginsBean.getServerPluginRelationships(plugin);
+ }
+
+ return null;
+ }
+}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
index b6db223..3fe6988 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
@@ -21,8 +21,13 @@ package org.rhq.enterprise.gui.admin.plugin;
import javax.faces.application.FacesMessage;
import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
import org.rhq.core.clientapi.agent.metadata.ConfigurationMetadataParser;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
@@ -40,21 +45,24 @@ import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
* @author Greg Hinkle
* @author John Mazzitelli
*/
+(a)Scope(ScopeType.PAGE)
+@Name("InstalledPluginUIBean")
public class InstalledPluginUIBean {
- private final Log log = LogFactory.getLog(InstalledPluginUIBean.class);
+ private static final String OUTCOME_SUCCESS = "success";
public static final String MANAGED_BEAN_NAME = InstalledPluginUIBean.class.getSimpleName();
-
+ private final Log log = LogFactory.getLog(InstalledPluginUIBean.class);
+ @In
private Plugin plugin;
private ConfigurationDefinition pluginConfigurationDefinition;
private ConfigurationDefinition scheduledJobsDefinition;
- public InstalledPluginUIBean() {
- lookupPlugin();
+ public Plugin getPlugin() {
+ return plugin;
}
- public Plugin getPlugin() {
- return this.plugin;
+ public void setPlugin(Plugin plugin) {
+ this.plugin = plugin;
}
public ConfigurationDefinition getPluginConfigurationDefinition() {
@@ -65,40 +73,39 @@ public class InstalledPluginUIBean {
return this.scheduledJobsDefinition;
}
- public void updatePlugin() {
+ public boolean isEditable() {
+ return this.pluginConfigurationDefinition != null || this.scheduledJobsDefinition != null;
+ }
+
+ public String updatePlugin() {
ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
try {
serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
-
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
- "Configuration settings saved.");
+ "Configuration settings saved.");
+
+ return OUTCOME_SUCCESS;
} catch (Exception e) {
log.error("Error updating the plugin configurations.", e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "There was an error changing the configuration settings.", e);
- }
+ "There was an error changing the configuration settings.", e);
- lookupPlugin();
+ return null;
+ }
}
- private void lookupPlugin() {
+ @Create
+ public void lookupConfigDefinitions() {
hasPermission();
- String pluginName = FacesContextUtility.getRequiredRequestParameter("plugin", String.class);
- String pluginType = FacesContextUtility.getRequiredRequestParameter("pluginType", String.class);
- PluginDeploymentType deploymentType = PluginDeploymentType.valueOf(pluginType);
- if (deploymentType == PluginDeploymentType.AGENT) {
- this.plugin = LookupUtil.getResourceMetadataManager().getPlugin(pluginName);
- } else {
- ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- this.plugin = serverPluginsBean.getServerPlugin(pluginName);
- this.plugin = serverPluginsBean.getServerPluginRelationships(this.plugin);
+ String pluginName = this.plugin.getName();
+
+ if (this.plugin.getDeployment() == PluginDeploymentType.SERVER) {
try {
+ ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginName);
- this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginName, descriptor
- .getPluginConfiguration());
- this.scheduledJobsDefinition = ConfigurationMetadataParser.parse("jobs:" + pluginName, descriptor
- .getScheduledJobs());
+ this.pluginConfigurationDefinition = ConfigurationMetadataParser.parse("pc:" + pluginName, descriptor.getPluginConfiguration());
+ this.scheduledJobsDefinition = ConfigurationMetadataParser.parse("jobs:" + pluginName, descriptor.getScheduledJobs());
} catch (Exception e) {
String err = "Cannot determine what the plugin configuration or scheduled jobs configuration looks like";
log.error(err + " - Cause: " + e);
@@ -114,8 +121,7 @@ public class InstalledPluginUIBean {
private void hasPermission() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
if (!LookupUtil.getAuthorizationManager().hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)) {
- throw new PermissionException("User [" + subject.getName()
- + "] does not have the proper permissions to view or manage plugins");
+ throw new PermissionException("User [" + subject.getName() + "] does not have the proper permissions to view or manage plugins");
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/components.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/components.xml
index bacb535..64bd31e 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/components.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/components.xml
@@ -11,6 +11,7 @@
<component name="org.jboss.seam.core.init">
<property name="debug">false</property> <!-- enable only when needed -->
<property name="transactionManagementEnabled">false</property>
+ <property name="jndi-pattern">rhq/#{ejbName}/local</property>
</component>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/admin-beans.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/admin-beans.xml
index 11dadd0..a80402b 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/admin-beans.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/admin-beans.xml
@@ -20,13 +20,6 @@
<managed-bean-class>org.rhq.enterprise.gui.admin.plugin.InstalledPluginsUIBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
- <managed-bean>
- <description>Visibility for the installed agent and server plugins</description>
- <display-name>Installed Plugin</display-name>
- <managed-bean-name>InstalledPluginUIBean</managed-bean-name>
- <managed-bean-class>org.rhq.enterprise.gui.admin.plugin.InstalledPluginUIBean</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
<managed-bean>
<description>Access to downloads information</description>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
index 93932df..7f19f4d 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
@@ -28,6 +28,17 @@
</navigation-case>
</navigation-rule>
+
+ <navigation-rule>
+ <from-view-id>/rhq/admin/plugin/plugin-details-edit.xhtml</from-view-id>
+
+ <navigation-case>
+ <from-outcome>success</from-outcome>
+ <to-view-id>/rhq/admin/plugin/plugin-details-view.xhtml?plugin=#{plugin.name}&pluginType=#{plugin.deployment}</to-view-id>
+ <redirect/>
+ </navigation-case>
+
+ </navigation-rule>
<navigation-rule>
<navigation-case>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit.xhtml
new file mode 100644
index 0000000..d88afe7
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit.xhtml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:c="http://java.sun.com/jstl/core"
+ xmlns:onc="http://jboss.org/on/component"
+ xmlns:rich="http://richfaces.ajax4jsf.org/rich">
+
+<ui:composition template="/rhq/admin/plugin/plugin-details.xhtml">
+ <ui:param name="editMode" value="true"/>
+
+ <ui:define name="post-config">
+ <rich:panel rendered="#{InstalledPluginUIBean.editable}">
+ <h:commandButton value="SAVE" type="submit" action="#{InstalledPluginUIBean.updatePlugin}"
+ alt="Click to Save Changes" styleClass="buttonmed" />
+ <h:commandButton value="RESET" type="reset" immediate="true"
+ title="Click to Reset Fields" styleClass="buttonmed"/>
+ </rich:panel>
+ </ui:define>
+</ui:composition>
+
+</html>
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
new file mode 100644
index 0000000..389923a
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:c="http://java.sun.com/jstl/core"
+ xmlns:onc="http://jboss.org/on/component"
+ xmlns:rich="http://richfaces.ajax4jsf.org/rich">
+
+<ui:composition template="/rhq/admin/plugin/plugin-details.xhtml">
+ <ui:param name="editMode" value="false"/>
+
+ <ui:define name="pre-config">
+ <h:panelGrid columns="1" styleClass="buttons-table" columnClasses="button-cell"
+ rendered="#{InstalledPluginUIBean.editable}">
+ <h:outputLink value="/rhq/admin/plugin/plugin-details-edit.xhtml"
+ styleClass="buttonmed">
+ <f:param name="plugin" value="#{installedPlugin.name}"/>
+ <f:param name="pluginType" value="#{installedPlugin.type}"/>
+ <h:outputText value="EDIT"/>
+ </h:outputLink>
+ </h:panelGrid>
+ </ui:define>
+ </ui:composition>
+
+</html>
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
index fa46dc8..cc11203 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
@@ -35,8 +35,6 @@
layout="table"
width="100%"/>
-
-
<h:form id="pluginsForm">
<rich:panel>
@@ -66,7 +64,6 @@
</h:panelGrid>
-
<rich:panel>
<f:facet name="header">
<h:outputText value="Plugin Help"/>
@@ -76,6 +73,7 @@
</rich:panel>
+ <ui:insert name="pre-config" />
<rich:panel rendered="#{InstalledPluginUIBean.plugin.pluginConfiguration != null}">
<f:facet name="header">
@@ -83,7 +81,8 @@
</f:facet>
<onc:config
configurationDefinition="#{InstalledPluginUIBean.pluginConfigurationDefinition}"
- configuration="#{InstalledPluginUIBean.plugin.pluginConfiguration}" />
+ configuration="#{InstalledPluginUIBean.plugin.pluginConfiguration}"
+ readOnly="#{not editMode}" />
</rich:panel>
<rich:panel rendered="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration != null}">
@@ -92,17 +91,11 @@
</f:facet>
<onc:config
configurationDefinition="#{InstalledPluginUIBean.scheduledJobsDefinition}"
- configuration="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration}" />
+ configuration="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration}"
+ readOnly="#{not editMode}" />
</rich:panel>
- <input type="hidden" name="plugin" value="#{param.plugin}"/>
- <input type="hidden" name="pluginType" value="#{param.pluginType}"/>
-
- <rich:panel rendered="#{InstalledPluginUIBean.plugin.pluginConfiguration != null ||
- InstalledPluginUIBean.plugin.scheduledJobsConfiguration != null}">
- <h:commandButton value="OK" type="submit" action="#{InstalledPluginUIBean.updatePlugin}"
- alt="Click to Save Plugin" styleClass="buttonmed" />
- </rich:panel>
+ <ui:insert name="post-config" />
</rich:panel>
</h:form>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
index 72f941e..5654368 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
@@ -75,7 +75,7 @@
<h:outputText styleClass="headerText" value="Name"/>
</f:facet>
- <h:outputLink value="/rhq/admin/plugin/plugin-details.xhtml">
+ <h:outputLink value="/rhq/admin/plugin/plugin-details-view.xhtml">
<f:param name="plugin" value="#{agentPlugin.name}"/>
<f:param name="pluginType" value="AGENT"/>
<h:outputText value="#{agentPlugin.displayName}"/>
@@ -160,7 +160,7 @@
<h:outputText styleClass="headerText" value="Name"/>
</f:facet>
- <h:outputLink value="/rhq/admin/plugin/plugin-details.xhtml">
+ <h:outputLink value="/rhq/admin/plugin/plugin-details-view.xhtml">
<f:param name="plugin" value="#{serverPlugin.name}"/>
<f:param name="pluginType" value="SERVER"/>
<h:outputText value="#{serverPlugin.displayName}"/>
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 ce603da..1415bb5 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
@@ -16,7 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
package org.rhq.enterprise.server.plugin;
import java.io.BufferedInputStream;
@@ -67,14 +66,12 @@ import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
@Stateless
@javax.annotation.Resource(name = "RHQ_DS", mappedName = RHQConstants.DATASOURCE_JNDI_NAME)
public class ServerPluginsBean implements ServerPluginsLocal {
- private final Log log = LogFactory.getLog(ServerPluginsBean.class);
+ private final Log log = LogFactory.getLog(ServerPluginsBean.class);
@PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
private EntityManager entityManager;
-
@javax.annotation.Resource(name = "RHQ_DS")
private DataSource dataSource;
-
@EJB
private ServerPluginsLocal serverPluginsBean; //self
@@ -242,8 +239,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
File currentFile = new File(pluginDir, doomedPlugin.getPath());
currentFile.delete();
} catch (Exception e) {
- log.error("Failed to delete the undeployed plugin [" + doomedPlugin.getPath() + "]. Cause: "
- + ThrowableUtil.getAllMessages(e));
+ log.error("Failed to delete the undeployed plugin [" + doomedPlugin.getPath() + "]. Cause: " + ThrowableUtil.getAllMessages(e));
}
}
}
@@ -279,7 +275,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void setServerPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status)
- throws Exception {
+ throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
@@ -295,8 +291,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception {
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName()
- + "] must be a server plugin to be registered");
+ throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] must be a server plugin to be registered");
}
Plugin existingPlugin = null;
@@ -309,8 +304,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (existingPlugin != null) {
if (existingPlugin.getStatus() == PluginStatusType.DELETED) {
- throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
- + "], it has been marked as deleted");
+ throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName() + "], it has been marked as deleted");
}
Plugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
if (obsolete == existingPlugin) { // yes use == for reference equality
@@ -328,8 +322,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (plugin.getId() == 0) {
PluginStatusType status = getServerPluginStatus(plugin.getName());
if (PluginStatusType.DELETED == status) {
- throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
- + "], it has been previously marked as deleted.");
+ throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName() + "], it has been previously marked as deleted.");
}
entityManager.persist(plugin);
} else {
@@ -371,8 +364,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
// to entityManager.merge that plugin POJO, it would null out that blob column.
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName()
- + "] must be a server plugin to be updated");
+ throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] must be a server plugin to be updated");
}
if (plugin.getId() == 0) {
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();
+ }
+ }
}
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());
commit e77a657abf17907a25dba4498b6e4993604ed38c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Mon Nov 23 10:48:13 2009 -0500
the column should be "enabled" since everywhere else we talk about a plugin being enabled or disabled, not active/inactive
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
index 9f7f6b7..72f941e 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
@@ -105,7 +105,7 @@
<rich:column>
<f:facet name="header">
- <h:outputText styleClass="headerText" value="Active"/>
+ <h:outputText styleClass="headerText" value="Enabled"/>
</f:facet>
<h:outputText value="#{agentPlugin.enabled}"/>
@@ -190,7 +190,7 @@
<rich:column>
<f:facet name="header">
- <h:outputText styleClass="headerText" value="Active"/>
+ <h:outputText styleClass="headerText" value="Enabled"/>
</f:facet>
<h:outputText value="#{serverPlugin.enabled}"/>
commit 9af95de196ccc8b854a8f1c952af3a6cfa18e78d
Author: Justin Harris <jharris(a)redhat.com>
Date: Mon Nov 23 10:18:55 2009 -0500
Updating update plugin call to new naming scheme.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
index fac4661..b6db223 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
@@ -69,7 +69,7 @@ public class InstalledPluginUIBean {
ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
try {
- serverPlugins.updatePluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
+ serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
"Configuration settings saved.");
@@ -78,6 +78,8 @@ public class InstalledPluginUIBean {
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
"There was an error changing the configuration settings.", e);
}
+
+ lookupPlugin();
}
private void lookupPlugin() {
commit 556be90ec7e0285dc9205766805aaa91da2ef258
Author: Justin Harris <jharris(a)redhat.com>
Date: Fri Nov 20 18:34:52 2009 -0500
Adding save button to plugin details page.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
index f6eee0d..fac4661 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
@@ -65,6 +65,21 @@ public class InstalledPluginUIBean {
return this.scheduledJobsDefinition;
}
+ public void updatePlugin() {
+ ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
+
+ try {
+ serverPlugins.updatePluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
+
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
+ "Configuration settings saved.");
+ } catch (Exception e) {
+ log.error("Error updating the plugin configurations.", e);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
+ "There was an error changing the configuration settings.", e);
+ }
+ }
+
private void lookupPlugin() {
hasPermission();
String pluginName = FacesContextUtility.getRequiredRequestParameter("plugin", String.class);
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
index 3921b8e..fa46dc8 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
@@ -76,24 +76,32 @@
</rich:panel>
- <rich:panel>
+
+ <rich:panel rendered="#{InstalledPluginUIBean.plugin.pluginConfiguration != null}">
<f:facet name="header">
<h:outputText value="Plugin Configuration"/>
</f:facet>
<onc:config
configurationDefinition="#{InstalledPluginUIBean.pluginConfigurationDefinition}"
- configuration="#{InstalledPluginUIBean.plugin.pluginConfiguration}"
- readOnly="true" />
+ configuration="#{InstalledPluginUIBean.plugin.pluginConfiguration}" />
</rich:panel>
- <rich:panel>
+ <rich:panel rendered="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration != null}">
<f:facet name="header">
<h:outputText value="Scheduled Jobs"/>
</f:facet>
<onc:config
configurationDefinition="#{InstalledPluginUIBean.scheduledJobsDefinition}"
- configuration="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration}"
- readOnly="true" />
+ configuration="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration}" />
+ </rich:panel>
+
+ <input type="hidden" name="plugin" value="#{param.plugin}"/>
+ <input type="hidden" name="pluginType" value="#{param.pluginType}"/>
+
+ <rich:panel rendered="#{InstalledPluginUIBean.plugin.pluginConfiguration != null ||
+ InstalledPluginUIBean.plugin.scheduledJobsConfiguration != null}">
+ <h:commandButton value="OK" type="submit" action="#{InstalledPluginUIBean.updatePlugin}"
+ alt="Click to Save Plugin" styleClass="buttonmed" />
</rich:panel>
</rich:panel>
commit e144f9a55590182e130ae768b9b494b13f03c2a6
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sun Nov 22 22:42:30 2009 -0500
convert CRLF to LF
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
index a7c0cbc..2c47b0a 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
@@ -1,397 +1,397 @@
-<%@ page import="java.io.ByteArrayOutputStream" %>
-<%@ page import="java.io.PrintStream" %>
-
-<%@ page import="org.rhq.core.domain.auth.Subject" %>
-<%@ page import="org.rhq.core.domain.util.PersistenceUtility" %>
-
-<%@ page import="org.rhq.enterprise.gui.legacy.util.SessionUtils"%>
-<%@ page import="org.rhq.enterprise.gui.util.WebUtility"%>
-
-<%@ page import="org.rhq.enterprise.server.measurement.MeasurementPreferences" %>
-<%@ page import="org.rhq.enterprise.server.measurement.MeasurementPreferences.MetricRangePreferences" %>
-
-<%@ page import="org.rhq.enterprise.server.test.CoreTestLocal" %>
-<%@ page import="org.rhq.enterprise.server.test.DiscoveryTestLocal" %>
-<%@ page import="org.rhq.enterprise.server.test.MeasurementTestLocal" %>
-<%@ page import="org.rhq.enterprise.server.test.ResourceGroupTestBeanLocal" %>
-<%@ page import="org.rhq.enterprise.server.test.SubjectRoleTestBeanLocal" %>
-<%@ page import="org.rhq.enterprise.server.test.AlertTemplateTestLocal" %>
-<%@ page import="org.rhq.enterprise.server.cloud.instance.ServerManagerLocal" %>
-<%@ page import="org.rhq.enterprise.server.test.ResourceGroupTestBeanLocal" %>
-<%@ page import="org.rhq.enterprise.server.measurement.MeasurementBaselineManagerLocal" %>
-<%@ page import="org.rhq.enterprise.server.measurement.MeasurementScheduleManagerLocal" %>
-<%@ page import="org.rhq.enterprise.server.core.AgentManagerLocal" %>
-<%@ page import="org.rhq.enterprise.server.system.SystemManagerLocal" %>
-<%@ page import="org.rhq.enterprise.server.auth.SubjectManagerLocal" %>
-<%@ page import="org.rhq.enterprise.server.support.SupportManagerLocal" %>
-<%@page import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%><html>
-<%@ page import="org.rhq.enterprise.server.util.LookupUtil" %>
-<%@ page import="org.rhq.enterprise.server.scheduler.jobs.DataPurgeJob"%>
-
-<%@ page import="org.rhq.enterprise.server.resource.ResourceTypeManagerRemote"%>
-<%@ page import="org.rhq.core.domain.criteria.ResourceTypeCriteria"%>
-<%@ page import="org.rhq.core.domain.resource.ResourceType"%>
-
-<%@ page import="javax.naming.NamingException" %>
-
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
-<html>
-<head><title>RHQ Test Control Page</title></head>
-<body>
-
-<jsp:include page="/admin/include/adminTestLinks.html" flush="true" />
-
-<%
- CoreTestLocal coreTestBean;
- DiscoveryTestLocal discoveryTestBean;
- MeasurementTestLocal measurementTestBean;
- ResourceGroupTestBeanLocal resourceGroupTestBean;
- SubjectRoleTestBeanLocal subjectRoleTestBean;
- ServerManagerLocal serverManager;
- AlertTemplateTestLocal alertTemplateTestBean;
- MeasurementBaselineManagerLocal measurementBaselineManager;
- MeasurementScheduleManagerLocal measurementScheduleManager;
- AgentManagerLocal agentManager;
- SystemManagerLocal systemManager;
- SubjectManagerLocal subjectManager;
- SupportManagerLocal supportManager;
- ResourceTypeManagerRemote typeManager;
- ServerPluginsLocal serverPlugins;
-
- coreTestBean = LookupUtil.getCoreTest();
- discoveryTestBean = LookupUtil.getDiscoveryTest();
- measurementTestBean = LookupUtil.getMeasurementTest();
- resourceGroupTestBean = LookupUtil.getResourceGroupTestBean();
- subjectRoleTestBean = LookupUtil.getSubjectRoleTestBean();
- serverManager = LookupUtil.getServerManager();
- alertTemplateTestBean = LookupUtil.getAlertTemplateTestBean();
- measurementBaselineManager = LookupUtil.getMeasurementBaselineManager();
- measurementScheduleManager = LookupUtil.getMeasurementScheduleManager();
- agentManager = LookupUtil.getAgentManager();
- systemManager = LookupUtil.getSystemManager();
- subjectManager = LookupUtil.getSubjectManager();
- supportManager = LookupUtil.getSupportManager();
- typeManager = LookupUtil.getResourceTypeManagerRemote();
- serverPlugins = LookupUtil.getServerPlugins();
-
- String result = null;
- String mode = pageContext.getRequest().getParameter("mode");
- String failure = null;
- try
- {
- if ("registerTestAgent".equals(mode))
- {
- coreTestBean.registerTestAgent();
- }
- else if ("registerTestPluginAndTypeInfo".equals(mode))
- {
- discoveryTestBean.registerTestPluginAndTypeInfo();
- }
- else if ("removeTestPluginAndTypeInfo".equals(mode))
- {
- discoveryTestBean.removeTestPluginAndTypeInfo();
- }
- else if ("sendTestFullInventoryReport".equals(mode))
- {
- discoveryTestBean.sendTestFullInventoryReport();
- }
- else if ("sendTestRuntimeInventoryReport".equals(mode))
- {
- discoveryTestBean.sendTestRuntimeInventoryReport();
- }
- else if ("sendTestMeasurementReport".equals(mode))
- {
- measurementTestBean.sendTestMeasurementReport();
- }
- else if ("sendNewPlatform".equals(mode))
- {
- String address = request.getParameter("address");
- int servers = Integer.parseInt(request.getParameter("servers"));
- int servicesPerServer = Integer.parseInt(request.getParameter("servicesPerServer"));
- discoveryTestBean.sendNewPlatform(address, servers, servicesPerServer);
- }
- else if ("setupCompatibleGroups".equals(mode))
- {
- resourceGroupTestBean.setupCompatibleGroups();
- }
- else if ("setupUberMixedGroup".equals(mode))
- {
- resourceGroupTestBean.setupUberMixedGroup();
- }
- else if ("startStats".equals(mode))
- {
- coreTestBean.enableHibernateStatistics();
- }
- else if ("addProblemResource".equals(mode))
- {
- measurementTestBean.addProblemResource();
- }
- else if ("setAgentCurrentlyScheduledMetrics".equals(mode))
- {
- String value = pageContext.getRequest().getParameter("v");
- measurementTestBean.setAgentCurrentlyScheduledMetrics(Double.valueOf(value));
- }
- else if ("addSubjectsAndRoles".equals(mode))
- {
- String roleCount = pageContext.getRequest().getParameter("roleCount");
- String usersInRoleCount = pageContext.getRequest().getParameter("usersInRoleCount");
- subjectRoleTestBean.createRolesAndUsers(Integer.parseInt(roleCount), Integer.parseInt(usersInRoleCount));
- }
- else if ("clusterGetIdentity".equals(mode))
- {
- String serverName = serverManager.getIdentity();
- pageContext.setAttribute("serverName", "(serverName = " + serverName + ")");
- }
- else if ("cloneAlertTemplate".equals(mode))
- {
- String alertTemplateId = pageContext.getRequest().getParameter("alertTemplateId");
- String numberOfClones = pageContext.getRequest().getParameter("numberOfClones");
- alertTemplateTestBean.cloneAlertTemplate(Integer.parseInt(alertTemplateId), Integer.parseInt(numberOfClones));
- }
- else if ("calculateAutoBaselines".equals(mode))
- {
- // for now, baselines aren't calculated until we hit our day limit, we force it here
- java.util.Properties props = systemManager.getSystemConfiguration();
- props.put("CAM_BASELINE_LASTTIME", "0");
- systemManager.setSystemConfiguration(subjectManager.getOverlord(), props,true);
-
- measurementBaselineManager.calculateAutoBaselines();
- }
- else if ("calculateOOBs".equals(mode))
- {
- DataPurgeJob dpj = new DataPurgeJob();
- dpj.calculateOOBs();
- }
- else if ("checkForSuspectAgents".equals(mode))
- {
- agentManager.checkForSuspectAgents();
- }
- else if ("dataPurgeJob".equals(mode))
- {
- DataPurgeJob.purgeNow();
- }
- else if ("dbMaintenance".equals(mode))
- {
- systemManager.vacuum(subjectManager.getOverlord());
- systemManager.reindex(subjectManager.getOverlord());
- systemManager.analyze(subjectManager.getOverlord());
- }
- else if ("metricDisplayRange".equals(mode))
- {
- int lastHours = Integer.parseInt(pageContext.getRequest().getParameter("lastHours"));
- Subject subject = WebUtility.getSubject(request);
- MeasurementPreferences prefs = new MeasurementPreferences(subject);
- MetricRangePreferences rangePrefs = prefs.getMetricRangePreferences();
- rangePrefs.lastN = lastHours;
- prefs.setMetricRangePreferences(rangePrefs);
- }
- else if ("errorCorrectSchedules".equals("mode"))
- {
- measurementScheduleManager.errorCorrectSchedules();
- }
- else if ("generateSnapshotReport".equals(mode))
- {
- int resourceId = Integer.parseInt(request.getParameter("resourceId"));
- String name = request.getParameter("name");
- String description = request.getParameter("description");
- java.net.URL url = supportManager.getSnapshotReport(subjectManager.getOverlord(), resourceId, name, description);
- result = "Snapshot Report is located here: " + url.toString();
- }
- else if ("purgeServerPlugin".equals(mode))
- {
- String serverPluginName = request.getParameter("serverPluginName");
- serverPlugins.purgeServerPlugin(subjectManager.getOverlord(), serverPluginName);
- result = "OK - you can now try to re-register a plugin with the name [" + serverPluginName + "]";
- }
- else if ("typeManagerRemote".equals(mode))
- {
- int typeId = Integer.parseInt(request.getParameter("typeId"));
- ResourceTypeCriteria criteria = new ResourceTypeCriteria();
- criteria.addFilterId(typeId);
- criteria.fetchMetricDefinitions(true);
- java.util.List<ResourceType> types = typeManager.findResourceTypesByCriteria(subjectManager.getOverlord(), criteria);
- result = "";
- for (ResourceType type : types) {
- result += type.getName() + " has " + (type.getMetricDefinitions() != null ? type.getMetricDefinitions().size() : "empty") + " metric definitions";
- }
- }
- }
- catch (Exception e)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- e.printStackTrace(new PrintStream(baos));
- failure = baos.toString();
- }
-
- pageContext.setAttribute("executed", mode);
- pageContext.setAttribute("result", result);
- pageContext.setAttribute("failure", failure);
- pageContext.setAttribute("testAgentReported", Boolean.valueOf(coreTestBean.isTestAgentReported()));
-
-%>
-
-<c:if test="${executed != null}">
- <b>Executed <c:out value="${executed}"/>: </b> <c:out value="${result}"/><br>
- <c:if test="${failure != null}">
- <pre style="background-color: yellow;"><c:out value="${failure}"/></pre>
- </c:if>
-</c:if>
-
-<h2>Administration</h2>
-
-<c:url var="url" value="/admin/test/control.jsp?mode=addSubjectsAndRoles"/>
-Add Lots of Users and Roles
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="addSubjectsAndRoles"/>
- Number of Roles: <input type="text" name="roleCount" size="5"/><br/>
- Number of Users in each Role: <input type="text" name="usersInRoleCount" size="5"/><br/>
- <input type="submit" value="Send" name="Send"/>
-</form>
-
-
-<ul>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=addSubjectsAndRoles"/>
- <a href="<c:out value="${url}"/>">Report Test Agent</a> (done = <c:out value="${testAgentReported}"/>)</li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=registerTestPluginAndTypeInfo"/>
- <a href="<c:out value="${url}"/>">Register test plugin metadata</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=removeTestPluginAndTypeInfo"/>
- <a href="<c:out value="${url}"/>">Remove test plugin metadata</a></li>
-</ul>
-
-<h2>Core</h2>
-
-<ul>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=registerTestAgent"/>
- <a href="<c:out value="${url}"/>">Report Test Agent</a> (done = <c:out value="${testAgentReported}"/>)</li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=registerTestPluginAndTypeInfo"/>
- <a href="<c:out value="${url}"/>">Register test plugin metadata</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=removeTestPluginAndTypeInfo"/>
- <a href="<c:out value="${url}"/>">Remove test plugin metadata</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=dbMaintenance"/>
- <a href="<c:out value="${url}"/>">Perform All Database Maintenance Now</a></li>
-</ul>
-
-<h2>Cluster</h2>
-
-<ul>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=clusterGetIdentity"/>
- <a href="<c:out value="${url}"/>">Get Identity</a> <c:out value="${serverName}"/></li>
-</ul>
-
-<h2>Inventory</h2>
-
-<ul>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=sendTestFullInventoryReport"/>
- <a href="<c:out value="${url}"/>">Send Full Inventory Report</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=sendTestRuntimeInventoryReport"/>
- <a href="<c:out value="${url}"/>">Send Runtime Inventory Report</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=setupCompatibleGroups"/>
- <a href="<c:out value="${url}"/>">Setup Compatible Groups</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=setupUberMixedGroup"/>
- <a href="<c:out value="${url}"/>">Setup Uber Mixed Group</a></li>
-</ul>
-
-<c:url var="url" value="/admin/test/control.jsp?mode=sendNewPlatform"/>
-Send New Platform Inventory Report
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="sendNewPlatform"/>
- Address: <input type="text" name="address" size="30"/><br/>
- Servers: <input type="text" name="servers" size="5"/><br/>
- Services Per Server: <input type="text" name="servicesPerServer" size="5"/><br/>
- <input type="submit" value="Send" name="Send"/>
-</form>
-
-
-<h2>Measurement</h2>
-
-<ul>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=calculateAutoBaselines"/>
- <a href="<c:out value="${url}"/>">Calculate Auto Baselines</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=sendTestMeasurementReport"/>
- <a href="<c:out value="${url}"/>">Send Measurement Report</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=addProblemResource"/>
- <a href="<c:out value="${url}"/>">Add problem Resource</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=setAgentCurrentlyScheduledMetrics&v=100"/>
- <a href="<c:out value="${url}"/>">Set RHQ Agent 'CurrentlyScheduleMetrics' to 100</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=setAgentCurrentlyScheduledMetrics&v=50"/>
- <a href="<c:out value="${url}"/>">Set RHQ Agent 'CurrentlyScheduleMetrics' to 50</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=checkForSuspectAgents"/>
- <a href="<c:out value="${url}"/>">Check For Suspect Agents</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=dataPurgeJob"/>
- <a href="<c:out value="${url}"/>">Force Data Purge Now</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=calculateOOBs"/>
- <a href="<c:out value="${url}"/>">Force calculation of OOBs</a></li>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=errorCorrectSchedules"/>
- <a href="<c:out value="${url}"/>">Error-Correct Measurement Schedules</a></li>
-</ul>
-
-<h2>Alerts</h2>
-
-<c:url var="url" value="/admin/test/control.jsp?mode=cloneAlertTemplate"/>
-Template Cloning
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="cloneAlertTemplate"/>
- Alert Template ID: <input type="text" name="alertTemplateId" size="5"/><br/>
- Number of Clones: <input type="text" name="numberOfClones" size="5"/><br/>
- <input type="submit" value="Send" name="Send"/>
-</form>
-
-<h2>Utilities</h2>
-<ul>
- <li><c:url var="url" value="/admin/test/control.jsp?mode=startStats"/>
- <a href="<c:out value="${url}"/>">Start Hibernate Statistics Collection</a></li>
-</ul>
-
-
-<h2>User Preferences</h2>
-<%
- Subject subject = WebUtility.getSubject(request);
- MeasurementPreferences prefs = new MeasurementPreferences(subject);
- MetricRangePreferences rangePrefs = prefs.getMetricRangePreferences();
- pageContext.setAttribute("lastHours", String.valueOf(rangePrefs.lastN));
-%>
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="metricDisplayRange"/>
- Last X hours: <input type="text" name="lastHours" size="5" value="<c:out value="${lastHours}"/>"/><br/>
- <input type="submit" value="Send" name="Send"/>
-</form>
-
-<h2>Snapshot Report</h2>
-
-<c:url var="url" value="/admin/test/control.jsp?mode=generateSnapshotReport"/>
-Generate Snapshot Report
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="generateSnapshotReport"/>
- Resource ID: <input type="text" name="resourceId" size="10"/><br/>
- Name: <input type="text" name="name" size="30"/><br/>
- Description: <input type="text" name="description" size="100"/><br/>
- <input type="submit" value="Generate Snapshot" name="Generate Snapshot"/>
-</form>
-
-<h2>Server Plugins</h2>
-
-<c:url var="url" value="/admin/test/control.jsp?mode=purgeServerPlugin"/>
-Purge Server Plugin (allowing you to re-register it again later)
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="purgeServerPlugin"/>
- ServerPluginName: <input type="text" name="serverPluginName" size="30"/><br/>
- <input type="submit" value="Purge Server Plugin" name="Purge Server Plugin"/>
-</form>
-
-<h2>Resource Type Criteria</h2>
-
-<c:url var="url" value="/admin/test/control.jsp?mode=typeManagerRemote"/>
-Query ResourceTypes by Criteria
-<form action="<c:out value="${url}"/>" method="get">
- <input type="hidden" name="mode" value="typeManagerRemote"/>
- ResourceType ID: <input type="text" name="typeId" size="10"/><br/>
- <input type="submit" value="Query by Criteria" name="Query by Criteria"/>
-</form>
-
-
-
-</body>
-</html>
+<%@ page import="java.io.ByteArrayOutputStream" %>
+<%@ page import="java.io.PrintStream" %>
+
+<%@ page import="org.rhq.core.domain.auth.Subject" %>
+<%@ page import="org.rhq.core.domain.util.PersistenceUtility" %>
+
+<%@ page import="org.rhq.enterprise.gui.legacy.util.SessionUtils"%>
+<%@ page import="org.rhq.enterprise.gui.util.WebUtility"%>
+
+<%@ page import="org.rhq.enterprise.server.measurement.MeasurementPreferences" %>
+<%@ page import="org.rhq.enterprise.server.measurement.MeasurementPreferences.MetricRangePreferences" %>
+
+<%@ page import="org.rhq.enterprise.server.test.CoreTestLocal" %>
+<%@ page import="org.rhq.enterprise.server.test.DiscoveryTestLocal" %>
+<%@ page import="org.rhq.enterprise.server.test.MeasurementTestLocal" %>
+<%@ page import="org.rhq.enterprise.server.test.ResourceGroupTestBeanLocal" %>
+<%@ page import="org.rhq.enterprise.server.test.SubjectRoleTestBeanLocal" %>
+<%@ page import="org.rhq.enterprise.server.test.AlertTemplateTestLocal" %>
+<%@ page import="org.rhq.enterprise.server.cloud.instance.ServerManagerLocal" %>
+<%@ page import="org.rhq.enterprise.server.test.ResourceGroupTestBeanLocal" %>
+<%@ page import="org.rhq.enterprise.server.measurement.MeasurementBaselineManagerLocal" %>
+<%@ page import="org.rhq.enterprise.server.measurement.MeasurementScheduleManagerLocal" %>
+<%@ page import="org.rhq.enterprise.server.core.AgentManagerLocal" %>
+<%@ page import="org.rhq.enterprise.server.system.SystemManagerLocal" %>
+<%@ page import="org.rhq.enterprise.server.auth.SubjectManagerLocal" %>
+<%@ page import="org.rhq.enterprise.server.support.SupportManagerLocal" %>
+<%@page import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%><html>
+<%@ page import="org.rhq.enterprise.server.util.LookupUtil" %>
+<%@ page import="org.rhq.enterprise.server.scheduler.jobs.DataPurgeJob"%>
+
+<%@ page import="org.rhq.enterprise.server.resource.ResourceTypeManagerRemote"%>
+<%@ page import="org.rhq.core.domain.criteria.ResourceTypeCriteria"%>
+<%@ page import="org.rhq.core.domain.resource.ResourceType"%>
+
+<%@ page import="javax.naming.NamingException" %>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<html>
+<head><title>RHQ Test Control Page</title></head>
+<body>
+
+<jsp:include page="/admin/include/adminTestLinks.html" flush="true" />
+
+<%
+ CoreTestLocal coreTestBean;
+ DiscoveryTestLocal discoveryTestBean;
+ MeasurementTestLocal measurementTestBean;
+ ResourceGroupTestBeanLocal resourceGroupTestBean;
+ SubjectRoleTestBeanLocal subjectRoleTestBean;
+ ServerManagerLocal serverManager;
+ AlertTemplateTestLocal alertTemplateTestBean;
+ MeasurementBaselineManagerLocal measurementBaselineManager;
+ MeasurementScheduleManagerLocal measurementScheduleManager;
+ AgentManagerLocal agentManager;
+ SystemManagerLocal systemManager;
+ SubjectManagerLocal subjectManager;
+ SupportManagerLocal supportManager;
+ ResourceTypeManagerRemote typeManager;
+ ServerPluginsLocal serverPlugins;
+
+ coreTestBean = LookupUtil.getCoreTest();
+ discoveryTestBean = LookupUtil.getDiscoveryTest();
+ measurementTestBean = LookupUtil.getMeasurementTest();
+ resourceGroupTestBean = LookupUtil.getResourceGroupTestBean();
+ subjectRoleTestBean = LookupUtil.getSubjectRoleTestBean();
+ serverManager = LookupUtil.getServerManager();
+ alertTemplateTestBean = LookupUtil.getAlertTemplateTestBean();
+ measurementBaselineManager = LookupUtil.getMeasurementBaselineManager();
+ measurementScheduleManager = LookupUtil.getMeasurementScheduleManager();
+ agentManager = LookupUtil.getAgentManager();
+ systemManager = LookupUtil.getSystemManager();
+ subjectManager = LookupUtil.getSubjectManager();
+ supportManager = LookupUtil.getSupportManager();
+ typeManager = LookupUtil.getResourceTypeManagerRemote();
+ serverPlugins = LookupUtil.getServerPlugins();
+
+ String result = null;
+ String mode = pageContext.getRequest().getParameter("mode");
+ String failure = null;
+ try
+ {
+ if ("registerTestAgent".equals(mode))
+ {
+ coreTestBean.registerTestAgent();
+ }
+ else if ("registerTestPluginAndTypeInfo".equals(mode))
+ {
+ discoveryTestBean.registerTestPluginAndTypeInfo();
+ }
+ else if ("removeTestPluginAndTypeInfo".equals(mode))
+ {
+ discoveryTestBean.removeTestPluginAndTypeInfo();
+ }
+ else if ("sendTestFullInventoryReport".equals(mode))
+ {
+ discoveryTestBean.sendTestFullInventoryReport();
+ }
+ else if ("sendTestRuntimeInventoryReport".equals(mode))
+ {
+ discoveryTestBean.sendTestRuntimeInventoryReport();
+ }
+ else if ("sendTestMeasurementReport".equals(mode))
+ {
+ measurementTestBean.sendTestMeasurementReport();
+ }
+ else if ("sendNewPlatform".equals(mode))
+ {
+ String address = request.getParameter("address");
+ int servers = Integer.parseInt(request.getParameter("servers"));
+ int servicesPerServer = Integer.parseInt(request.getParameter("servicesPerServer"));
+ discoveryTestBean.sendNewPlatform(address, servers, servicesPerServer);
+ }
+ else if ("setupCompatibleGroups".equals(mode))
+ {
+ resourceGroupTestBean.setupCompatibleGroups();
+ }
+ else if ("setupUberMixedGroup".equals(mode))
+ {
+ resourceGroupTestBean.setupUberMixedGroup();
+ }
+ else if ("startStats".equals(mode))
+ {
+ coreTestBean.enableHibernateStatistics();
+ }
+ else if ("addProblemResource".equals(mode))
+ {
+ measurementTestBean.addProblemResource();
+ }
+ else if ("setAgentCurrentlyScheduledMetrics".equals(mode))
+ {
+ String value = pageContext.getRequest().getParameter("v");
+ measurementTestBean.setAgentCurrentlyScheduledMetrics(Double.valueOf(value));
+ }
+ else if ("addSubjectsAndRoles".equals(mode))
+ {
+ String roleCount = pageContext.getRequest().getParameter("roleCount");
+ String usersInRoleCount = pageContext.getRequest().getParameter("usersInRoleCount");
+ subjectRoleTestBean.createRolesAndUsers(Integer.parseInt(roleCount), Integer.parseInt(usersInRoleCount));
+ }
+ else if ("clusterGetIdentity".equals(mode))
+ {
+ String serverName = serverManager.getIdentity();
+ pageContext.setAttribute("serverName", "(serverName = " + serverName + ")");
+ }
+ else if ("cloneAlertTemplate".equals(mode))
+ {
+ String alertTemplateId = pageContext.getRequest().getParameter("alertTemplateId");
+ String numberOfClones = pageContext.getRequest().getParameter("numberOfClones");
+ alertTemplateTestBean.cloneAlertTemplate(Integer.parseInt(alertTemplateId), Integer.parseInt(numberOfClones));
+ }
+ else if ("calculateAutoBaselines".equals(mode))
+ {
+ // for now, baselines aren't calculated until we hit our day limit, we force it here
+ java.util.Properties props = systemManager.getSystemConfiguration();
+ props.put("CAM_BASELINE_LASTTIME", "0");
+ systemManager.setSystemConfiguration(subjectManager.getOverlord(), props,true);
+
+ measurementBaselineManager.calculateAutoBaselines();
+ }
+ else if ("calculateOOBs".equals(mode))
+ {
+ DataPurgeJob dpj = new DataPurgeJob();
+ dpj.calculateOOBs();
+ }
+ else if ("checkForSuspectAgents".equals(mode))
+ {
+ agentManager.checkForSuspectAgents();
+ }
+ else if ("dataPurgeJob".equals(mode))
+ {
+ DataPurgeJob.purgeNow();
+ }
+ else if ("dbMaintenance".equals(mode))
+ {
+ systemManager.vacuum(subjectManager.getOverlord());
+ systemManager.reindex(subjectManager.getOverlord());
+ systemManager.analyze(subjectManager.getOverlord());
+ }
+ else if ("metricDisplayRange".equals(mode))
+ {
+ int lastHours = Integer.parseInt(pageContext.getRequest().getParameter("lastHours"));
+ Subject subject = WebUtility.getSubject(request);
+ MeasurementPreferences prefs = new MeasurementPreferences(subject);
+ MetricRangePreferences rangePrefs = prefs.getMetricRangePreferences();
+ rangePrefs.lastN = lastHours;
+ prefs.setMetricRangePreferences(rangePrefs);
+ }
+ else if ("errorCorrectSchedules".equals("mode"))
+ {
+ measurementScheduleManager.errorCorrectSchedules();
+ }
+ else if ("generateSnapshotReport".equals(mode))
+ {
+ int resourceId = Integer.parseInt(request.getParameter("resourceId"));
+ String name = request.getParameter("name");
+ String description = request.getParameter("description");
+ java.net.URL url = supportManager.getSnapshotReport(subjectManager.getOverlord(), resourceId, name, description);
+ result = "Snapshot Report is located here: " + url.toString();
+ }
+ else if ("purgeServerPlugin".equals(mode))
+ {
+ String serverPluginName = request.getParameter("serverPluginName");
+ serverPlugins.purgeServerPlugin(subjectManager.getOverlord(), serverPluginName);
+ result = "OK - you can now try to re-register a plugin with the name [" + serverPluginName + "]";
+ }
+ else if ("typeManagerRemote".equals(mode))
+ {
+ int typeId = Integer.parseInt(request.getParameter("typeId"));
+ ResourceTypeCriteria criteria = new ResourceTypeCriteria();
+ criteria.addFilterId(typeId);
+ criteria.fetchMetricDefinitions(true);
+ java.util.List<ResourceType> types = typeManager.findResourceTypesByCriteria(subjectManager.getOverlord(), criteria);
+ result = "";
+ for (ResourceType type : types) {
+ result += type.getName() + " has " + (type.getMetricDefinitions() != null ? type.getMetricDefinitions().size() : "empty") + " metric definitions";
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(baos));
+ failure = baos.toString();
+ }
+
+ pageContext.setAttribute("executed", mode);
+ pageContext.setAttribute("result", result);
+ pageContext.setAttribute("failure", failure);
+ pageContext.setAttribute("testAgentReported", Boolean.valueOf(coreTestBean.isTestAgentReported()));
+
+%>
+
+<c:if test="${executed != null}">
+ <b>Executed <c:out value="${executed}"/>: </b> <c:out value="${result}"/><br>
+ <c:if test="${failure != null}">
+ <pre style="background-color: yellow;"><c:out value="${failure}"/></pre>
+ </c:if>
+</c:if>
+
+<h2>Administration</h2>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=addSubjectsAndRoles"/>
+Add Lots of Users and Roles
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="addSubjectsAndRoles"/>
+ Number of Roles: <input type="text" name="roleCount" size="5"/><br/>
+ Number of Users in each Role: <input type="text" name="usersInRoleCount" size="5"/><br/>
+ <input type="submit" value="Send" name="Send"/>
+</form>
+
+
+<ul>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=addSubjectsAndRoles"/>
+ <a href="<c:out value="${url}"/>">Report Test Agent</a> (done = <c:out value="${testAgentReported}"/>)</li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=registerTestPluginAndTypeInfo"/>
+ <a href="<c:out value="${url}"/>">Register test plugin metadata</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=removeTestPluginAndTypeInfo"/>
+ <a href="<c:out value="${url}"/>">Remove test plugin metadata</a></li>
+</ul>
+
+<h2>Core</h2>
+
+<ul>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=registerTestAgent"/>
+ <a href="<c:out value="${url}"/>">Report Test Agent</a> (done = <c:out value="${testAgentReported}"/>)</li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=registerTestPluginAndTypeInfo"/>
+ <a href="<c:out value="${url}"/>">Register test plugin metadata</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=removeTestPluginAndTypeInfo"/>
+ <a href="<c:out value="${url}"/>">Remove test plugin metadata</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=dbMaintenance"/>
+ <a href="<c:out value="${url}"/>">Perform All Database Maintenance Now</a></li>
+</ul>
+
+<h2>Cluster</h2>
+
+<ul>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=clusterGetIdentity"/>
+ <a href="<c:out value="${url}"/>">Get Identity</a> <c:out value="${serverName}"/></li>
+</ul>
+
+<h2>Inventory</h2>
+
+<ul>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=sendTestFullInventoryReport"/>
+ <a href="<c:out value="${url}"/>">Send Full Inventory Report</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=sendTestRuntimeInventoryReport"/>
+ <a href="<c:out value="${url}"/>">Send Runtime Inventory Report</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=setupCompatibleGroups"/>
+ <a href="<c:out value="${url}"/>">Setup Compatible Groups</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=setupUberMixedGroup"/>
+ <a href="<c:out value="${url}"/>">Setup Uber Mixed Group</a></li>
+</ul>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=sendNewPlatform"/>
+Send New Platform Inventory Report
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="sendNewPlatform"/>
+ Address: <input type="text" name="address" size="30"/><br/>
+ Servers: <input type="text" name="servers" size="5"/><br/>
+ Services Per Server: <input type="text" name="servicesPerServer" size="5"/><br/>
+ <input type="submit" value="Send" name="Send"/>
+</form>
+
+
+<h2>Measurement</h2>
+
+<ul>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=calculateAutoBaselines"/>
+ <a href="<c:out value="${url}"/>">Calculate Auto Baselines</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=sendTestMeasurementReport"/>
+ <a href="<c:out value="${url}"/>">Send Measurement Report</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=addProblemResource"/>
+ <a href="<c:out value="${url}"/>">Add problem Resource</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=setAgentCurrentlyScheduledMetrics&v=100"/>
+ <a href="<c:out value="${url}"/>">Set RHQ Agent 'CurrentlyScheduleMetrics' to 100</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=setAgentCurrentlyScheduledMetrics&v=50"/>
+ <a href="<c:out value="${url}"/>">Set RHQ Agent 'CurrentlyScheduleMetrics' to 50</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=checkForSuspectAgents"/>
+ <a href="<c:out value="${url}"/>">Check For Suspect Agents</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=dataPurgeJob"/>
+ <a href="<c:out value="${url}"/>">Force Data Purge Now</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=calculateOOBs"/>
+ <a href="<c:out value="${url}"/>">Force calculation of OOBs</a></li>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=errorCorrectSchedules"/>
+ <a href="<c:out value="${url}"/>">Error-Correct Measurement Schedules</a></li>
+</ul>
+
+<h2>Alerts</h2>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=cloneAlertTemplate"/>
+Template Cloning
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="cloneAlertTemplate"/>
+ Alert Template ID: <input type="text" name="alertTemplateId" size="5"/><br/>
+ Number of Clones: <input type="text" name="numberOfClones" size="5"/><br/>
+ <input type="submit" value="Send" name="Send"/>
+</form>
+
+<h2>Utilities</h2>
+<ul>
+ <li><c:url var="url" value="/admin/test/control.jsp?mode=startStats"/>
+ <a href="<c:out value="${url}"/>">Start Hibernate Statistics Collection</a></li>
+</ul>
+
+
+<h2>User Preferences</h2>
+<%
+ Subject subject = WebUtility.getSubject(request);
+ MeasurementPreferences prefs = new MeasurementPreferences(subject);
+ MetricRangePreferences rangePrefs = prefs.getMetricRangePreferences();
+ pageContext.setAttribute("lastHours", String.valueOf(rangePrefs.lastN));
+%>
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="metricDisplayRange"/>
+ Last X hours: <input type="text" name="lastHours" size="5" value="<c:out value="${lastHours}"/>"/><br/>
+ <input type="submit" value="Send" name="Send"/>
+</form>
+
+<h2>Snapshot Report</h2>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=generateSnapshotReport"/>
+Generate Snapshot Report
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="generateSnapshotReport"/>
+ Resource ID: <input type="text" name="resourceId" size="10"/><br/>
+ Name: <input type="text" name="name" size="30"/><br/>
+ Description: <input type="text" name="description" size="100"/><br/>
+ <input type="submit" value="Generate Snapshot" name="Generate Snapshot"/>
+</form>
+
+<h2>Server Plugins</h2>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=purgeServerPlugin"/>
+Purge Server Plugin (allowing you to re-register it again later)
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="purgeServerPlugin"/>
+ ServerPluginName: <input type="text" name="serverPluginName" size="30"/><br/>
+ <input type="submit" value="Purge Server Plugin" name="Purge Server Plugin"/>
+</form>
+
+<h2>Resource Type Criteria</h2>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=typeManagerRemote"/>
+Query ResourceTypes by Criteria
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="typeManagerRemote"/>
+ ResourceType ID: <input type="text" name="typeId" size="10"/><br/>
+ <input type="submit" value="Query by Criteria" name="Query by Criteria"/>
+</form>
+
+
+
+</body>
+</html>
commit f04ef82719012571ecfa157eb270c6b0424ad0ac
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sun Nov 22 22:39:34 2009 -0500
mistakenly deleted the html tag, put it back
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
index 4d5cfd5..a7c0cbc 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
@@ -38,7 +38,7 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
+<html>
<head><title>RHQ Test Control Page</title></head>
<body>
commit a5fcd064dc1d1eea47c2806754c3244e1c000235
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sun Nov 22 01:59:12 2009 -0500
since there is no current way to "revive" a undeployed plugin from the real GUI, at least provide _some_ way to get back to a state that will let you re-register a plugin again using the test control.jsp page
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
index f3f0a35..4d5cfd5 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
@@ -24,6 +24,7 @@
<%@ page import="org.rhq.enterprise.server.system.SystemManagerLocal" %>
<%@ page import="org.rhq.enterprise.server.auth.SubjectManagerLocal" %>
<%@ page import="org.rhq.enterprise.server.support.SupportManagerLocal" %>
+<%@page import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%><html>
<%@ page import="org.rhq.enterprise.server.util.LookupUtil" %>
<%@ page import="org.rhq.enterprise.server.scheduler.jobs.DataPurgeJob"%>
@@ -37,7 +38,7 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-<html>
+
<head><title>RHQ Test Control Page</title></head>
<body>
@@ -58,6 +59,7 @@
SubjectManagerLocal subjectManager;
SupportManagerLocal supportManager;
ResourceTypeManagerRemote typeManager;
+ ServerPluginsLocal serverPlugins;
coreTestBean = LookupUtil.getCoreTest();
discoveryTestBean = LookupUtil.getDiscoveryTest();
@@ -73,6 +75,7 @@
subjectManager = LookupUtil.getSubjectManager();
supportManager = LookupUtil.getSupportManager();
typeManager = LookupUtil.getResourceTypeManagerRemote();
+ serverPlugins = LookupUtil.getServerPlugins();
String result = null;
String mode = pageContext.getRequest().getParameter("mode");
@@ -197,6 +200,12 @@
java.net.URL url = supportManager.getSnapshotReport(subjectManager.getOverlord(), resourceId, name, description);
result = "Snapshot Report is located here: " + url.toString();
}
+ else if ("purgeServerPlugin".equals(mode))
+ {
+ String serverPluginName = request.getParameter("serverPluginName");
+ serverPlugins.purgeServerPlugin(subjectManager.getOverlord(), serverPluginName);
+ result = "OK - you can now try to re-register a plugin with the name [" + serverPluginName + "]";
+ }
else if ("typeManagerRemote".equals(mode))
{
int typeId = Integer.parseInt(request.getParameter("typeId"));
@@ -362,6 +371,16 @@ Generate Snapshot Report
<input type="submit" value="Generate Snapshot" name="Generate Snapshot"/>
</form>
+<h2>Server Plugins</h2>
+
+<c:url var="url" value="/admin/test/control.jsp?mode=purgeServerPlugin"/>
+Purge Server Plugin (allowing you to re-register it again later)
+<form action="<c:out value="${url}"/>" method="get">
+ <input type="hidden" name="mode" value="purgeServerPlugin"/>
+ ServerPluginName: <input type="text" name="serverPluginName" size="30"/><br/>
+ <input type="submit" value="Purge Server Plugin" name="Purge Server Plugin"/>
+</form>
+
<h2>Resource Type Criteria</h2>
<c:url var="url" value="/admin/test/control.jsp?mode=typeManagerRemote"/>
commit 5413dbb476c615effd97d698ae54b051bcfa02c5
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 21 16:17:38 2009 -0500
actually remove all jobs for the undeployed server plugin
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 8a4ab80..3697caa 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
@@ -235,6 +235,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
}
+ log.info("Server plugins " + doomedPlugins + " have been undeployed");
+
// only restart if the master was started to begin with; otherwise, leave it down
if (master != null) {
serverPluginService.restartMasterPluginContainer();
@@ -257,6 +259,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
throw new Exception("Failed to update [" + pluginIds.size() + "] plugins. Count was [" + count + "]");
}
+ log.info((enabled ? "Enabling" : "Disabling") + " server plugins with plugin IDs of " + pluginIds);
return;
}
@@ -324,7 +327,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
entityManager.flush();
streamPluginFileContentToDatabase(plugin.getId(), pluginFile);
}
- log.debug("Updated plugin entity [" + plugin + "]");
+ log.info("Server plugin [" + plugin.getName() + "] has been registered in the database");
}
return plugin;
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
index 3256bf5..e88e5fd 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
@@ -235,7 +235,21 @@ public abstract class AbstractTypeServerPluginContainer {
*/
public void unschedulePluginJobs(String pluginName) throws Exception {
SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
- scheduler.resumeJobGroup(pluginName);
+
+ // note: all jobs for a plugin are placed in the same group, where the group name is the plugin name
+ String groupName = pluginName;
+
+ scheduler.pauseJobGroup(groupName);
+ String[] jobNames = scheduler.getJobNames(groupName);
+ if (jobNames != null) {
+ for (String jobName : jobNames) {
+ boolean deleted = scheduler.deleteJob(jobName, groupName);
+ if (!deleted) {
+ log.warn("Plugin [" + pluginName + "] failed to get its job [" + jobName + "] unscheduled!");
+ }
+ }
+ }
+
return;
}
commit 1093e91f666af1848a7bd5d4fb93ed6cdb9b9c50
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 21 13:24:26 2009 -0500
provide API that will allow us to later build a user interface to "resurrect" a deleted plugin - to re-install it if it was undelpoyed before.
this also fixes some tests - server/jar and core/domain plugin tests now all pass properly
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index 67ffc53..eda26d8 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -114,6 +114,31 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.name=:name AND p.status = 'INSTALLED' "), //
+ // gets the plugin, even if it is deleted
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM Plugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.name=:name AND p.deployment = :type "), //
+
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_ALL_AGENT, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
@@ -227,6 +252,7 @@ public class Plugin implements Serializable {
public static final String QUERY_FIND_ALL_AGENT = "Plugin.findAllAgent";
public static final String QUERY_FIND_ALL_SERVER = "Plugin.findAllServer";
public static final String QUERY_FIND_BY_NAME = "Plugin.findByName";
+ public static final String QUERY_FIND_ANY_BY_NAME_AND_TYPE = "Plugin.findAnyByNameAndType";
public static final String QUERY_FIND_BY_IDS_AND_TYPE = "Plugin.findByIdsAndType";
public static final String QUERY_GET_NAMES_BY_ENABLED_AND_TYPE = "Plugin.findByEnabledAndType";
public static final String QUERY_GET_STATUS_BY_NAME_AND_TYPE = "Plugin.getStatusByNameAndType";
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index 8ab3171..07f8f97 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -48,7 +48,7 @@ import org.rhq.core.util.stream.StreamUtil;
@Test
public class PluginTest extends AbstractEJB3Test {
- public void testUpdate() throws Exception {
+ public void testUpdate() throws Throwable {
boolean done = false;
getTransactionManager().begin();
EntityManager em = getEntityManager();
@@ -81,8 +81,8 @@ public class PluginTest extends AbstractEJB3Test {
em.persist(plugin);
id = plugin.getId();
assert id > 0;
- assert plugin.getPluginConfiguration().getId() > 0 : "did not persist config";
- assert plugin.getScheduledJobsConfiguration().getId() > 0 : "did not persist jobs config";
+ assert plugin.getPluginConfiguration() == null : "there was no config that should have been here";
+ assert plugin.getScheduledJobsConfiguration() == null : "there was no config that should have been here";
q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
q.setParameter("name", plugin.getName());
@@ -127,6 +127,10 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().begin();
em = getEntityManager();
+ em.persist(pluginConfig);
+ em.persist(jobsConfig);
+ em.flush(); // gotta get those two persists to flush to the DB
+
q = em.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
q.setParameter("id", id); // same as the one we just persisted
q.setParameter("name", name);
@@ -173,12 +177,19 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- em.createNativeQuery("DELETE FROM " + Plugin.TABLE_NAME + " WHERE ID = " + id).executeUpdate();
+ q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q.setParameter("name", plugin.getName());
+ q.setParameter("type", plugin.getDeployment());
+ Plugin doomed = (Plugin) q.getSingleResult();
+ doomed = em.getReference(Plugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the plugin";
em.close();
getTransactionManager().commit();
done = true;
} catch (Throwable t) {
t.printStackTrace();
+ throw t;
} finally {
if (!done) {
getTransactionManager().rollback();
@@ -486,7 +497,13 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- em.createNativeQuery("DELETE FROM " + Plugin.TABLE_NAME + " WHERE ID = " + plugin.getId()).executeUpdate();
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q.setParameter("name", plugin.getName());
+ q.setParameter("type", plugin.getDeployment());
+ Plugin doomed = (Plugin) q.getSingleResult();
+ doomed = em.getReference(Plugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the plugin";
em.close();
getTransactionManager().commit();
done = true;
@@ -595,8 +612,13 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- em.createNativeQuery("DELETE FROM " + Plugin.TABLE_NAME + " WHERE ID = " + plugin.getId()).executeUpdate();
- em.close();
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q.setParameter("name", plugin.getName());
+ q.setParameter("type", plugin.getDeployment());
+ Plugin doomed = (Plugin) q.getSingleResult();
+ doomed = em.getReference(Plugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the plugin";
getTransactionManager().commit();
done = true;
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 67d5efd..8a4ab80 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
@@ -44,6 +44,7 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
import org.rhq.core.domain.plugin.PluginStatusType;
@@ -213,8 +214,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
// if this plugin ever gets re-installed, let's support the use-case where the new plugin
// will have different config metadata. Here we null out the old config so the new
// config can be set to the new cofig definition's default values.
- doomedPlugin.setPluginConfiguration(null);
- doomedPlugin.setScheduledJobsConfiguration(null);
+ if (doomedPlugin.getPluginConfiguration() != null) {
+ entityManager.remove(doomedPlugin.getPluginConfiguration());
+ doomedPlugin.setPluginConfiguration(null);
+ }
+ if (doomedPlugin.getScheduledJobsConfiguration() != null) {
+ entityManager.remove(doomedPlugin.getScheduledJobsConfiguration());
+ doomedPlugin.setScheduledJobsConfiguration(null);
+ }
doomedPlugin.setStatus(PluginStatusType.DELETED);
try {
@@ -324,6 +331,22 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void purgeServerPlugin(Subject subject, String pluginName) {
+ Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q.setParameter("name", pluginName);
+ q.setParameter("type", PluginDeploymentType.SERVER);
+ Plugin doomed = (Plugin) q.getSingleResult();
+
+ // get the reference to attach to em and use the em.remove. this cascade deletes too.
+ doomed = this.entityManager.getReference(Plugin.class, doomed.getId());
+ this.entityManager.remove(doomed);
+
+ log.debug("Server plugin [" + pluginName + "] has been purged from the db");
+ return;
+ }
+
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
public Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws Exception {
// this method is here because we need a way to update the plugin's information
@@ -339,6 +362,35 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (plugin.getId() == 0) {
throw new IllegalArgumentException("Plugin must already exist to update it");
} else {
+ // make sure the configs are in the DB properly and we have their refs
+ // this is because we are using JPQL update, so we need to do some of this "manually"
+ boolean needFlush = false;
+ Configuration config = plugin.getPluginConfiguration();
+ if (config != null) {
+ if (config.getId() > 0) {
+ config = entityManager.getReference(Configuration.class, config.getId());
+ plugin.setPluginConfiguration(config);
+ } else {
+ entityManager.persist(config);
+ needFlush = true;
+ }
+ }
+ config = plugin.getScheduledJobsConfiguration();
+ if (config != null) {
+ if (config.getId() > 0) {
+ config = entityManager.getReference(Configuration.class, config.getId());
+ plugin.setScheduledJobsConfiguration(config);
+ } else {
+ entityManager.persist(config);
+ needFlush = true;
+ }
+ }
+ if (needFlush) {
+ entityManager.flush(); // must be flushed to the DB so the JPQL update below works
+ }
+
+ // now we can JPQL update the row - all but content is updated here.
+ // we assured our configs are persisted/attached above
Query q = entityManager.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
q.setParameter("id", plugin.getId());
q.setParameter("name", plugin.getName());
@@ -350,14 +402,16 @@ public class ServerPluginsBean implements ServerPluginsLocal {
q.setParameter("version", plugin.getVersion());
q.setParameter("ampsVersion", plugin.getAmpsVersion());
q.setParameter("deployment", plugin.getDeployment());
- q.setParameter("pluginConfiguration", plugin.getPluginConfiguration());
- q.setParameter("scheduledJobsConfiguration", plugin.getScheduledJobsConfiguration());
+ q.setParameter("pluginConfiguration", config);
+ q.setParameter("scheduledJobsConfiguration", config);
q.setParameter("description", plugin.getDescription());
q.setParameter("help", plugin.getHelp());
q.setParameter("mtime", plugin.getMtime());
if (q.executeUpdate() != 1) {
throw new Exception("Failed to update a plugin that matches [" + plugin + "]");
}
+
+ entityManager.flush(); // make sure we push this out to the DB now
}
return plugin;
}
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 68afc0e..6f3600e 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
@@ -126,7 +126,8 @@ public interface ServerPluginsLocal {
void setServerPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status) throws Exception;
/**
- * Registers the given plugin to the database.
+ * Registers the given plugin to the database. This does nothing with the master plugin container,
+ * all it does is ensure the database is up-to-date with this new plugin.
*
* @param subject the user that needs to have permissions to add a plugin to the system
* @param plugin the plugin definition
@@ -149,6 +150,20 @@ public interface ServerPluginsLocal {
Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws Exception;
/**
+ * Purges the server plugin from the database. This ensures that, after this method returns,
+ * the given plugin will be unknown. The plugin can be installed again later.
+ *
+ * This has "requires new" semantics, so the results are committed immediately upon return.
+ * This is really a supporting method for {@link #reRegisterServerPlugin(Subject, Plugin, File)} - you'll
+ * probably want to use that instead. Do not blindly purge server plugins using this method unless you
+ * know what you are doing.
+ *
+ * @param subject user making the request
+ * @param pluginName the name of the server plugin to delete
+ */
+ void purgeServerPlugin(Subject subject, String pluginName);
+
+ /**
* Given the name of a server plugin, this will return the status of that plugin.
* Use this to determine if a plugin has been deleted or not.
*
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index 8250c7d..9c971e0 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -50,6 +50,7 @@ import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.event.EventDefinition;
@@ -196,6 +197,33 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
if (plugin.getId() == 0) {
entityManager.persist(plugin);
} else {
+ // agent plugins don't support these configs, but if/when they do in the future, this will support it
+ boolean needFlush = false;
+ Configuration config = plugin.getPluginConfiguration();
+ if (config != null) {
+ if (config.getId() > 0) {
+ config = entityManager.getReference(Configuration.class, config.getId());
+ plugin.setPluginConfiguration(config);
+ } else {
+ entityManager.persist(config);
+ needFlush = true;
+ }
+ }
+ config = plugin.getScheduledJobsConfiguration();
+ if (config != null) {
+ if (config.getId() > 0) {
+ config = entityManager.getReference(Configuration.class, config.getId());
+ plugin.setScheduledJobsConfiguration(config);
+ } else {
+ entityManager.persist(config);
+ needFlush = true;
+ }
+ }
+ if (needFlush) {
+ entityManager.flush(); // must be flushed to the DB so the JPQL update below works
+ }
+
+ // update all the fields except content
Query q = entityManager.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
q.setParameter("id", plugin.getId());
q.setParameter("name", plugin.getName());
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 d5817a2..e1796bf 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
@@ -74,10 +74,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
getTransactionManager().begin();
em = getEntityManager();
- Query q = em.createQuery("SELECT p FROM Plugin p WHERE p.name LIKE 'serverplugintest%'");
+ Query q = em
+ .createQuery("SELECT p FROM Plugin p LEFT JOIN FETCH p.pluginConfiguration LEFT JOIN FETCH p.scheduledJobsConfiguration WHERE p.name LIKE 'serverplugintest%'");
List<Plugin> doomed = q.getResultList();
for (Plugin plugin : doomed) {
- em.remove(plugin);
+ em.remove(em.getReference(Plugin.class, plugin.getId()));
}
getTransactionManager().commit();
@@ -207,17 +208,70 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
+ }
+
+ public void testReRegisterPlugins() throws Exception {
+
+ PluginStatusType status;
+
+ status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "1");
+ assert status == null;
+ status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
+ assert status == null;
+
+ Plugin p1 = registerPlugin(1);
+ Plugin p2 = registerPlugin(2);
+
+ status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
+ assert status == PluginStatusType.INSTALLED;
+ status = this.serverPluginsBean.getServerPluginStatus(p2.getName());
+ assert status == PluginStatusType.INSTALLED;
- // re-install them - need to implement this feature
- // this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
- // pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
- // assert pluginNames.contains(p1.getName()) : pluginNames;
- // assert pluginNames.contains(p2.getName()) : pluginNames;
- // assert undeployed.get(0).getStatus() == PluginStatusType.INSTALLED;
- // assert undeployed.get(1).getStatus() == PluginStatusType.INSTALLED;
- // pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
- // assert !pluginNames.contains(p1.getName()) : pluginNames;
- // assert !pluginNames.contains(p2.getName()) : pluginNames;
+ List<Integer> ids = new ArrayList<Integer>(2);
+ ids.add(p1.getId());
+ ids.add(p2.getId());
+ List<Plugin> 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
+
+ List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
+ assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be returned even here" + pluginNames;
+ assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be returned even here" + pluginNames;
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
+ assert !pluginNames.contains(p1.getName()) : pluginNames;
+ assert !pluginNames.contains(p2.getName()) : pluginNames;
+
+ // purge them completely from the DB to prepare to re-register them
+ this.serverPluginsBean.purgeServerPlugin(getOverlord(), p1.getName());
+ this.serverPluginsBean.purgeServerPlugin(getOverlord(), p2.getName());
+
+ // we just purged the database, make sure our entity ID's are all zero, since the original IDs are gone
+ p1.setId(0);
+ p2.setId(0);
+ p1.setPluginConfiguration(p1.getPluginConfiguration().deepCopy(false));
+ p2.setPluginConfiguration(p2.getPluginConfiguration().deepCopy(false));
+ p1.setScheduledJobsConfiguration(p1.getScheduledJobsConfiguration().deepCopy(false));
+ p2.setScheduledJobsConfiguration(p2.getScheduledJobsConfiguration().deepCopy(false));
+
+ // re-register them now
+ Plugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p1, null);
+ Plugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p2, null);
+
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
+ assert pluginNames.contains(p1.getName()) : pluginNames;
+ assert pluginNames.contains(p2.getName()) : pluginNames;
+ assert p1again.getStatus() == PluginStatusType.INSTALLED;
+ assert p2again.getStatus() == PluginStatusType.INSTALLED;
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
+ assert !pluginNames.contains(p1.getName()) : pluginNames;
+ assert !pluginNames.contains(p2.getName()) : pluginNames;
}
private Plugin registerPlugin(int index) throws Exception {
commit 45180dcd79713f2f29e7051b2f1bed396dce9d2b
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 21 10:42:18 2009 -0500
do not attempt to register plugins that were previously undeployed.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index 552179f..67ffc53 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -56,6 +56,11 @@ import org.rhq.core.util.MessageDigestGenerator;
@Entity
@NamedQueries( {
//
+ @NamedQuery(name = Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE, query = "" //
+ + " SELECT p.status " //
+ + " FROM Plugin AS p " //
+ + " WHERE p.name = :name AND p.deployment = :type "), //
+
@NamedQuery(name = Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE, query = "" //
+ " SELECT p.name " //
+ " FROM Plugin AS p " //
@@ -224,6 +229,7 @@ public class Plugin implements Serializable {
public static final String QUERY_FIND_BY_NAME = "Plugin.findByName";
public static final String QUERY_FIND_BY_IDS_AND_TYPE = "Plugin.findByIdsAndType";
public static final String QUERY_GET_NAMES_BY_ENABLED_AND_TYPE = "Plugin.findByEnabledAndType";
+ public static final String QUERY_GET_STATUS_BY_NAME_AND_TYPE = "Plugin.getStatusByNameAndType";
public static final String UPDATE_ALL_BUT_CONTENT = "Plugin.updateAllButContent";
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "Plugin.updatePluginsEnabledByIds";
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index 7e3ad25..8ab3171 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -73,12 +73,22 @@ public class PluginTest extends AbstractEJB3Test {
plugin.setHelp(null);
plugin.setContent(content);
+ Query q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ q.setParameter("name", plugin.getName());
+ q.setParameter("type", plugin.getDeployment());
+ assert q.getResultList().size() == 0; // not in the db yet
+
em.persist(plugin);
id = plugin.getId();
assert id > 0;
assert plugin.getPluginConfiguration().getId() > 0 : "did not persist config";
assert plugin.getScheduledJobsConfiguration().getId() > 0 : "did not persist jobs config";
+ q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ q.setParameter("name", plugin.getName());
+ q.setParameter("type", plugin.getDeployment());
+ assert ((PluginStatusType) q.getSingleResult()) == PluginStatusType.INSTALLED;
+
plugin = em.find(Plugin.class, id);
assert plugin != null;
assert plugin.getId() == id;
@@ -117,7 +127,7 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().begin();
em = getEntityManager();
- Query q = em.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
+ q = em.createNamedQuery(Plugin.UPDATE_ALL_BUT_CONTENT);
q.setParameter("id", id); // same as the one we just persisted
q.setParameter("name", name);
q.setParameter("path", path);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index a172719..6bd8c0f 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
@@ -53,6 +53,7 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.core.util.stream.StreamUtil;
@@ -175,8 +176,17 @@ public class ServerPluginScanner {
}
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
- serverPluginsManager.registerPlugin(subjectManager.getOverlord(), plugin, pluginFile);
+
+ // see if this plugin has been deleted previously; if so, don't register and delete the file
+ PluginStatusType status = serverPluginsManager.getServerPluginStatus(pluginName);
+ if (PluginStatusType.DELETED == status) {
+ log.warn("Plugin file [" + pluginFile + "] has been detected but that plugin with name [" + pluginName
+ + "] was previously undeployed. Will not re-register that plugin and the file will be deleted.");
+ pluginFile.delete();
+ } else {
+ SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
+ serverPluginsManager.registerServerPlugin(subjectManager.getOverlord(), plugin, pluginFile);
+ }
} catch (Exception e) {
log.error("Failed to register RHQ plugin file [" + pluginFile + "]", e);
}
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 577ea92..67d5efd 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
@@ -121,7 +121,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return descriptor;
}
- public List<String> getPluginNamesByEnabled(boolean enabled) {
+ public List<String> getServerPluginNamesByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
query.setParameter("enabled", Boolean.valueOf(enabled));
query.setParameter("type", PluginDeploymentType.SERVER);
@@ -134,7 +134,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return; // nothing to do
}
- serverPluginsBean.setPluginEnabledFlag(subject, pluginIds, true);
+ serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, true);
// only restart the master if it was started to begin with
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
@@ -150,7 +150,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return new ArrayList<Plugin>(); // nothing to do
}
- serverPluginsBean.setPluginEnabledFlag(subject, pluginIds, false);
+ serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
@@ -188,7 +188,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return new ArrayList<Plugin>(); // nothing to do
}
- serverPluginsBean.setPluginEnabledFlag(subject, pluginIds, false);
+ serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
@@ -238,7 +238,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void setPluginEnabledFlag(Subject subject, List<Integer> pluginIds, boolean enabled) throws Exception {
+ public void setServerPluginEnabledFlag(Subject subject, List<Integer> pluginIds, boolean enabled) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
@@ -255,20 +255,21 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void setPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status) throws Exception {
+ public void setServerPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status)
+ throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
List<Plugin> plugins = getServerPluginsById(pluginIds);
for (Plugin plugin : plugins) {
plugin.setStatus(status);
- updatePluginExceptContent(subject, plugin);
+ updateServerPluginExceptContent(subject, plugin);
}
return;
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public Plugin registerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception {
+ public Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception {
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
throw new IllegalArgumentException("Plugin [" + plugin.getName()
@@ -302,9 +303,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (plugin.getId() == 0) {
+ PluginStatusType status = getServerPluginStatus(plugin.getName());
+ if (PluginStatusType.DELETED == status) {
+ throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
+ + "], it has been previously marked as deleted.");
+ }
entityManager.persist(plugin);
} else {
- plugin = updatePluginExceptContent(subject, plugin);
+ plugin = updateServerPluginExceptContent(subject, plugin);
}
if (pluginFile != null) {
@@ -318,11 +324,18 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public Plugin updatePluginExceptContent(Subject subject, Plugin plugin) throws Exception {
+ public Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws Exception {
+
// this method is here because we need a way to update the plugin's information
// without blowing away the content data. Because we do not want to load the
// content blob in memory, the plugin's content field will be null - if we were
// to entityManager.merge that plugin POJO, it would null out that blob column.
+
+ if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("Plugin [" + plugin.getName()
+ + "] must be a server plugin to be updated");
+ }
+
if (plugin.getId() == 0) {
throw new IllegalArgumentException("Plugin must already exist to update it");
} else {
@@ -349,6 +362,19 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
+ public PluginStatusType getServerPluginStatus(String pluginName) {
+ Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ q.setParameter("name", pluginName);
+ q.setParameter("type", PluginDeploymentType.SERVER);
+ PluginStatusType status;
+ try {
+ status = (PluginStatusType) q.getSingleResult();
+ } catch (NoResultException nre) {
+ status = null; // doesn't exist in the DB, tell the caller this by returning null
+ }
+ return status;
+ }
+
/**
* This will write the contents of the given plugin file to the database.
* This will assume the MD5 in the database is already correct, so this
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 528d87c..68afc0e 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
@@ -70,7 +70,7 @@ public interface ServerPluginsLocal {
* if <code>false</code>, return only the names of plugins that are disabled.
* @return list of plugin names that match the enabled criteria
*/
- List<String> getPluginNamesByEnabled(boolean enabled);
+ List<String> getServerPluginNamesByEnabled(boolean enabled);
/**
* Enables the plugins and restarts the server plugin container.
@@ -110,7 +110,7 @@ public interface ServerPluginsLocal {
* @param enabled the value of the enabled flag for the plugins
* @throws if failed to update a plugin
*/
- void setPluginEnabledFlag(Subject subject, List<Integer> pluginIds, boolean enabled) throws Exception;
+ void setServerPluginEnabledFlag(Subject subject, List<Integer> pluginIds, boolean enabled) throws Exception;
/**
* Sets the status flag in the database but does NOT restart the server plugin container.
@@ -123,7 +123,7 @@ public interface ServerPluginsLocal {
* @param enabled the value of the enabled flag for the plugins
* @throws if failed to update one of the plugins
*/
- void setPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status) throws Exception;
+ void setServerPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status) throws Exception;
/**
* Registers the given plugin to the database.
@@ -134,7 +134,7 @@ public interface ServerPluginsLocal {
* @return the plugin after being persisted
* @throws Exception if failed to fully register the plugin
*/
- Plugin registerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception;
+ Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception;
/**
* Given a plugin that already exists, this will update that plugin's data in the database,
@@ -146,5 +146,15 @@ public interface ServerPluginsLocal {
* @return the updated plugin
* @throws Exception if the plugin did not already exist or an error occurred that caused the update to fail
*/
- public Plugin updatePluginExceptContent(Subject subject, Plugin plugin) throws Exception;
+ Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws Exception;
+
+ /**
+ * Given the name of a server plugin, this will return the status of that plugin.
+ * Use this to determine if a plugin has been deleted or not.
+ *
+ * @param pluginName the name of the plugin whose status is to be returned.
+ * @return the status of the plugin, to indicate if the plugin has been deleted or is installed.
+ * <code>null</code> indicates an unknown plugin.
+ */
+ PluginStatusType getServerPluginStatus(String pluginName);
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
index 40bb776..8ebabd4 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
@@ -357,7 +357,7 @@ public class MasterServerPluginContainer {
* @return names of "blacklisted" plugins that should not be loaded
*/
protected List<String> getDisabledPluginNames() {
- List<String> disabledPlugins = LookupUtil.getServerPlugins().getPluginNamesByEnabled(false);
+ List<String> disabledPlugins = LookupUtil.getServerPlugins().getServerPluginNamesByEnabled(false);
return disabledPlugins;
}
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 3301ba0..d5817a2 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
@@ -46,6 +46,9 @@ import org.rhq.enterprise.server.util.LookupUtil;
*/
@Test
public class ServerPluginsBeanTest extends AbstractEJB3Test {
+
+ private static final String TEST_PLUGIN_NAME_PREFIX = "serverplugintest";
+
private ServerPluginsLocal serverPluginsBean;
@BeforeMethod
@@ -96,10 +99,10 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testGetPlugins() throws Exception {
Plugin p1 = registerPlugin(1);
Plugin p2 = registerPlugin(2);
- List<String> pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
@@ -144,19 +147,19 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert disabled.contains(p2) : disabled;
assert disabled.get(0).getStatus() == PluginStatusType.INSTALLED; // still installed
assert disabled.get(1).getStatus() == PluginStatusType.INSTALLED; // still installed
- List<String> pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
// re-enable them
this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
- pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
@@ -173,9 +176,21 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testUndeployPlugins() throws Exception {
+ PluginStatusType status;
+
+ status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "1");
+ assert status == null;
+ status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
+ assert status == null;
+
Plugin p1 = registerPlugin(1);
Plugin p2 = registerPlugin(2);
+ status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
+ assert status == PluginStatusType.INSTALLED;
+ status = this.serverPluginsBean.getServerPluginStatus(p2.getName());
+ assert status == PluginStatusType.INSTALLED;
+
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
@@ -186,10 +201,10 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert undeployed.get(0).getStatus() == PluginStatusType.DELETED;
assert undeployed.get(1).getStatus() == PluginStatusType.DELETED;
- List<String> pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be returned even here" + pluginNames;
assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be returned even here" + pluginNames;
- pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
@@ -206,12 +221,12 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
private Plugin registerPlugin(int index) throws Exception {
- Plugin plugin = new Plugin(0, "serverplugintest" + index, "path", "displayName", true,
+ Plugin plugin = new Plugin(0, TEST_PLUGIN_NAME_PREFIX + index, "path", "displayName", true,
PluginStatusType.INSTALLED, "description", "help", "md5", "version", "ampsVersion",
PluginDeploymentType.SERVER, createPluginConfiguration(), createScheduledJobsConfiguration(), System
.currentTimeMillis(), System.currentTimeMillis());
- plugin = this.serverPluginsBean.registerPlugin(getOverlord(), plugin, null);
+ plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
assert plugin.getId() > 0;
assert plugin.isEnabled() == true;
assert plugin.getDeployment() == PluginDeploymentType.SERVER;
commit 26c981d4720dbb65e02ea9ae5994d0888e8275c5
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 20 18:20:27 2009 -0500
do not stream plugins to filesystem if the database flagged it as deleted
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index d6cf6fe..a172719 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
@@ -353,7 +353,7 @@ public class ServerPluginScanner {
// get all the plugins
ps = conn.prepareStatement("SELECT NAME, PATH, MD5, MTIME, VERSION FROM " + Plugin.TABLE_NAME
- + " WHERE DEPLOYMENT = 'SERVER'");
+ + " WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' ");
rs = ps.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
@@ -451,7 +451,7 @@ public class ServerPluginScanner {
// write all our updated plugins to the file system
ps = conn.prepareStatement("SELECT CONTENT FROM " + Plugin.TABLE_NAME
- + " WHERE DEPLOYMENT = 'SERVER' AND NAME = ?");
+ + " WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' AND NAME = ?");
for (Plugin plugin : updatedPlugins) {
File file = new File(this.getServerPluginDir(), plugin.getPath());
@@ -516,8 +516,9 @@ public class ServerPluginScanner {
ResultSet rs = null;
TransactionManager tm = null;
- String sql = "UPDATE " + Plugin.TABLE_NAME
- + " SET CONTENT = ?, MD5 = ?, MTIME = ?, PATH = ? WHERE DEPLOYMENT = 'SERVER' AND NAME = ?";
+ String sql = "UPDATE "
+ + Plugin.TABLE_NAME
+ + " SET CONTENT = ?, MD5 = ?, MTIME = ?, PATH = ? WHERE DEPLOYMENT = 'SERVER' AND STATUS = 'INSTALLED' AND NAME = ?";
// if 'different' is true, give bogus data so the plugin deployer will think the plugin on the file system is new
String md5 = (!different) ? MessageDigestGenerator.getDigestString(file) : "TO BE UPDATED";
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 bfd828d..577ea92 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
@@ -284,6 +284,10 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (existingPlugin != null) {
+ if (existingPlugin.getStatus() == PluginStatusType.DELETED) {
+ throw new IllegalArgumentException("Cannot register plugin [" + plugin.getName()
+ + "], it has been marked as deleted");
+ }
Plugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
if (obsolete == existingPlugin) { // yes use == for reference equality
newOrUpdated = true;
commit 487407253bff60da59588b7bc814e6d14b0fb04c
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 20 17:47:29 2009 -0500
add the ability to mark a plugin DELETED. add authz to server plugin SLSB calls. add tests
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 6f6f12b..8f466be 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.69.1</db.schema.version>
</properties>
<dependencies>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
index 5120803..dbc4a19 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
@@ -12,6 +12,7 @@
<column name="VERSION" size="200" type="VARCHAR2" required="false"/>
<column name="AMPS_VERSION" size="16" type="VARCHAR2" required="false"/>
<column name="ENABLED" type="BOOLEAN" required="true"/>
+ <column name="STATUS" size="16" type="VARCHAR2" required="true"/>
<column name="HELP" type="CLOB" required="false"/>
<column name="PATH" size="500" type="VARCHAR2" required="true"/>
<column name="MD5" size="100" type="VARCHAR2" required="true"/>
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 4cc035a..07831eb 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2172,6 +2172,17 @@
</schema-directSQL>
</schemaSpec>
+ <schemaSpec version="2.69.1">
+ <!-- add the new column that indicates if this is plugin has been deleted -->
+ <schema-addColumn table="RHQ_PLUGIN" column="STATUS" columnType="VARCHAR2" precision="16"/>
+ <schema-directSQL>
+ <statement desc="Updating existing plugins with status of INSTALLED">
+ UPDATE RHQ_PLUGIN SET STATUS = 'INSTALLED'
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_PLUGIN" column="STATUS" nullable="FALSE"/>
+ </schemaSpec>
+
</dbupgrade>
</target>
</project>
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index 2b3913d..552179f 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -59,7 +59,7 @@ import org.rhq.core.util.MessageDigestGenerator;
@NamedQuery(name = Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE, query = "" //
+ " SELECT p.name " //
+ " FROM Plugin AS p " //
- + " WHERE p.enabled = :enabled AND p.deployment = :type"), //
+ + " WHERE p.enabled = :enabled AND p.deployment = :type AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_BY_IDS_AND_TYPE, query = "" //
@@ -69,6 +69,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.path, " //
+ " p.displayName, " //
+ " p.enabled, " //
+ + " p.status, " //
+ " p.description, " //
+ " p.help, " //
+ " p.md5, " //
@@ -82,7 +83,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.id IN (:ids) AND p.deployment = :type"), //
+ + " WHERE p.id IN (:ids) AND p.deployment = :type AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_BY_NAME, query = "" //
@@ -92,6 +93,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.path, " //
+ " p.displayName, " //
+ " p.enabled, " //
+ + " p.status, " //
+ " p.description, " //
+ " p.help, " //
+ " p.md5, " //
@@ -105,7 +107,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name"), //
+ + " WHERE p.name=:name AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_ALL_AGENT, query = "" //
@@ -115,6 +117,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.path, " //
+ " p.displayName, " //
+ " p.enabled, " //
+ + " p.status, " //
+ " p.description, " //
+ " p.help, " //
+ " p.md5, " //
@@ -128,7 +131,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.deployment = 'AGENT'"), //
+ + " WHERE p.deployment = 'AGENT' AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_ALL_SERVER, query = "" //
@@ -138,6 +141,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.path, " //
+ " p.displayName, " //
+ " p.enabled, " //
+ + " p.status, " //
+ " p.description, " //
+ " p.help, " //
+ " p.md5, " //
@@ -151,7 +155,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.deployment = 'SERVER'"), //
+ + " WHERE p.deployment = 'SERVER' AND p.status = 'INSTALLED' "), //
// this query does not update the content blob or ctime
@NamedQuery(name = Plugin.UPDATE_ALL_BUT_CONTENT, query = "" //
@@ -160,6 +164,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.displayName = :displayName, " //
+ " p.description = :description, " //
+ " p.enabled = :enabled, " //
+ + " p.status = :status, " //
+ " p.help = :help, " //
+ " p.version = :version, " //
+ " p.ampsVersion = :ampsVersion," //
@@ -185,6 +190,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.path, " //
+ " p.displayName, " //
+ " p.enabled, " //
+ + " p.status, " //
+ " p.description, " //
+ " p.help, " //
+ " p.md5, " //
@@ -198,7 +204,8 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name IN ( SELECT rt.plugin " //
+ + " WHERE p.status = 'INSTALLED' AND " //
+ + " p.name IN ( SELECT rt.plugin " //
+ " FROM Resource res " //
+ " JOIN res.resourceType rt " //
+ " WHERE ( rt.category = :resourceCategory OR :resourceCategory IS NULL ) " //
@@ -249,6 +256,10 @@ public class Plugin implements Serializable {
@Column(name = "ENABLED", nullable = false)
private boolean enabled = true;
+ @Column(name = "STATUS", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private PluginStatusType status = PluginStatusType.INSTALLED;
+
@Column(name = "HELP", nullable = true)
private String help;
@@ -334,6 +345,7 @@ public class Plugin implements Serializable {
* @param path
* @param displayName
* @param enabled
+ * @param status
* @param description
* @param help
* @param md5
@@ -345,14 +357,16 @@ public class Plugin implements Serializable {
* @param ctime
* @param mtime
*/
- public Plugin(int id, String name, String path, String displayName, boolean enabled, String description,
- String help, String md5, String version, String ampsVersion, PluginDeploymentType deployment,
- Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime, long mtime) {
+ public Plugin(int id, String name, String path, String displayName, boolean enabled, PluginStatusType status,
+ String description, String help, String md5, String version, String ampsVersion,
+ PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
+ long mtime) {
this.id = id;
this.name = name;
this.path = path;
this.displayName = displayName;
this.enabled = enabled;
+ this.status = status;
this.description = description;
this.help = help;
this.md5 = md5;
@@ -455,6 +469,17 @@ public class Plugin implements Serializable {
this.enabled = enabled;
}
+ public PluginStatusType getStatus() {
+ return status;
+ }
+
+ public void setStatus(PluginStatusType status) {
+ this.status = status;
+ if (this.status == PluginStatusType.DELETED) {
+ this.enabled = false;
+ }
+ }
+
public String getHelp() {
return help;
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginStatusType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginStatusType.java
new file mode 100644
index 0000000..40fd9ab
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginStatusType.java
@@ -0,0 +1,29 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.domain.plugin;
+
+/**
+ * Indicates if a plugin is installed or has been deleted.
+ *
+ * @author John Mazzitelli
+ */
+public enum PluginStatusType {
+ INSTALLED, DELETED
+}
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index 77d9312..7e3ad25 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -41,6 +41,7 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.domain.test.AbstractEJB3Test;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.stream.StreamUtil;
@@ -58,12 +59,14 @@ public class PluginTest extends AbstractEJB3Test {
String path = "/test/Update";
String displayName = "Plugin Test - testUpdate";
boolean enabled = true;
+ PluginStatusType status = PluginStatusType.INSTALLED;
String md5 = "abcdef";
byte[] content = "the content is here".getBytes();
Plugin plugin = new Plugin(name, path);
plugin.setDisplayName(displayName);
plugin.setEnabled(enabled);
+ plugin.setStatus(status);
plugin.setMD5(md5);
plugin.setVersion(null);
plugin.setDescription(null);
@@ -83,6 +86,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getPath().equals(path);
assert plugin.getDisplayName().equals(displayName);
assert plugin.isEnabled() == enabled;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
assert plugin.getMD5().equals(md5);
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
@@ -119,6 +123,7 @@ public class PluginTest extends AbstractEJB3Test {
q.setParameter("path", path);
q.setParameter("displayName", displayName);
q.setParameter("enabled", enabled);
+ q.setParameter("status", status);
q.setParameter("md5", md5);
q.setParameter("version", version);
q.setParameter("ampsVersion", ampsVersion);
@@ -179,11 +184,13 @@ public class PluginTest extends AbstractEJB3Test {
String path = "/test/Persist";
String displayName = "Plugin Test - testPersist";
boolean enabled = true;
+ PluginStatusType status = PluginStatusType.INSTALLED;
String md5 = "abcdef";
Plugin plugin = new Plugin(name, path);
plugin.setDisplayName(displayName);
plugin.setEnabled(enabled);
+ plugin.setStatus(status);
plugin.setMD5(md5);
// the following are the only nullable fields
@@ -202,6 +209,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getPath().equals(path);
assert plugin.getDisplayName().equals(displayName);
assert plugin.isEnabled() == enabled;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
assert plugin.getMD5().equals(md5);
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
@@ -210,6 +218,17 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert plugin.getContent() == null;
+
+ // side check - see that "deleting" a plugin also sets enabled to false
+ assert plugin.isEnabled() == true;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ plugin.setStatus(PluginStatusType.DELETED);
+ assert plugin.getStatus() == PluginStatusType.DELETED;
+ assert plugin.isEnabled() == false;
+ plugin = em.merge(plugin);
+ assert plugin.getStatus() == PluginStatusType.DELETED;
+ assert plugin.isEnabled() == false;
+
} finally {
getTransactionManager().rollback();
}
@@ -334,6 +353,25 @@ public class PluginTest extends AbstractEJB3Test {
}
assert got_it : "findAll query failed to get our plugin";
+ // mark a plugin deleted - all of our queries should then never see it
+ plugin.setStatus(PluginStatusType.DELETED);
+ em.merge(plugin);
+
+ query = em.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", name);
+ List<?> results = query.getResultList();
+ assert results.size() == 0;
+
+ query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ query.setParameter("ids", Arrays.asList(Integer.valueOf(plugin.getId())));
+ query.setParameter("type", plugin.getDeployment());
+ results = query.getResultList();
+ assert results.size() == 0;
+
+ query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ results = query.getResultList();
+ assert results.size() == 0;
+
} finally {
getTransactionManager().rollback();
}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
index 9fd46f2..cfc99cf 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
@@ -38,6 +38,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.core.gui.util.StringUtility;
+import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.authz.PermissionException;
@@ -79,9 +80,7 @@ public class InstalledPluginsUIBean {
scanner.scanAndRegister();
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Done scanning for updated plugins.");
} catch (Exception e) {
- String err = "Failed to scan for updated plugins";
- log.error(err + " - Cause: " + e);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, err, e);
+ processException("Failed to scan for updated plugins", e);
}
}
@@ -118,9 +117,7 @@ public class InstalledPluginsUIBean {
+ "]. A scan is required now in order to register it.");
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "New plugin uploaded: " + newPluginFilename);
} catch (Exception e) {
- String err = "Failed to process uploaded plugin";
- log.error(err + " - Cause: " + e);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, err, e);
+ processException("Failed to process uploaded plugin", e);
}
return;
@@ -132,8 +129,15 @@ public class InstalledPluginsUIBean {
for (Plugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
- serverPluginsBean.enableServerPlugins(getIds(selectedPlugins));
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Enabled server plugins: " + selectedPluginNames);
+
+ try {
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ serverPluginsBean.enableServerPlugins(subject, getIds(selectedPlugins));
+ FacesContextUtility
+ .addMessage(FacesMessage.SEVERITY_INFO, "Enabled server plugins: " + selectedPluginNames);
+ } catch (Exception e) {
+ processException("Failed to enable server plugins", e);
+ }
return;
}
@@ -143,8 +147,15 @@ public class InstalledPluginsUIBean {
for (Plugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
- serverPluginsBean.disableServerPlugins(getIds(selectedPlugins));
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Disabled server plugins: " + selectedPluginNames);
+
+ try {
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ serverPluginsBean.disableServerPlugins(subject, getIds(selectedPlugins));
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Disabled server plugins: "
+ + selectedPluginNames);
+ } catch (Exception e) {
+ processException("Failed to disable server plugins", e);
+ }
return;
}
@@ -154,8 +165,15 @@ public class InstalledPluginsUIBean {
for (Plugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
- serverPluginsBean.undeployServerPlugins(getIds(selectedPlugins));
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Undeployed server plugins: " + selectedPluginNames);
+
+ try {
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ serverPluginsBean.undeployServerPlugins(subject, getIds(selectedPlugins));
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Undeployed server plugins: "
+ + selectedPluginNames);
+ } catch (Exception e) {
+ processException("Failed to undeploy server plugins", e);
+ }
return;
}
@@ -193,4 +211,9 @@ public class InstalledPluginsUIBean {
+ "] does not have the proper permissions to view or manage plugins");
}
}
+
+ private void processException(String errMsg, Exception e) {
+ log.error(errMsg + ". Cause: " + ThrowableUtil.getAllMessages(e));
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, errMsg, e);
+ }
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index fc4b6eb..d6cf6fe 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
@@ -176,7 +176,7 @@ public class ServerPluginScanner {
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
- serverPluginsManager.registerPlugin(subjectManager.getOverlord(), plugin, descriptor, pluginFile);
+ serverPluginsManager.registerPlugin(subjectManager.getOverlord(), plugin, pluginFile);
} catch (Exception e) {
log.error("Failed to register RHQ plugin file [" + pluginFile + "]", e);
}
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 27234f8..bfd828d 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
@@ -46,6 +46,8 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.authz.RequiredPermission;
@@ -102,7 +104,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public List<Plugin> getServerPluginsById(List<Integer> pluginIds) {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<Plugin>();
+ return new ArrayList<Plugin>(); // nothing to do
}
Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
query.setParameter("ids", pluginIds);
@@ -126,14 +128,29 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return query.getResultList();
}
- public void enableServerPlugins(List<Integer> pluginIds) {
- serverPluginsBean.setPluginEnabledFlag(pluginIds, true);
- LookupUtil.getServerPluginService().restartMasterPluginContainer();
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
+ public void enableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ if (pluginIds == null || pluginIds.size() == 0) {
+ return; // nothing to do
+ }
+
+ serverPluginsBean.setPluginEnabledFlag(subject, pluginIds, true);
+
+ // only restart the master if it was started to begin with
+ ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
+ if (serverPluginService.isMasterPluginContainerStarted()) {
+ serverPluginService.restartMasterPluginContainer();
+ }
return;
}
- public List<Plugin> disableServerPlugins(List<Integer> pluginIds) {
- serverPluginsBean.setPluginEnabledFlag(pluginIds, false);
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
+ public List<Plugin> disableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ if (pluginIds == null || pluginIds.size() == 0) {
+ return new ArrayList<Plugin>(); // nothing to do
+ }
+
+ serverPluginsBean.setPluginEnabledFlag(subject, pluginIds, false);
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
@@ -144,23 +161,34 @@ public class ServerPluginsBean implements ServerPluginsLocal {
Plugin doomedPlugin = entityManager.find(Plugin.class, pluginId);
if (doomedPlugin != null) {
doomedPlugins.add(doomedPlugin);
- AbstractTypeServerPluginContainer pc = master.getPluginContainer(doomedPlugin.getName());
- if (pc != null) {
- try {
- pc.unschedulePluginJobs(doomedPlugin.getName());
- } catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" + doomedPlugin.getName() + "]", e);
+ if (master != null) {
+ AbstractTypeServerPluginContainer pc = master.getPluginContainer(doomedPlugin.getName());
+ if (pc != null) {
+ try {
+ pc.unschedulePluginJobs(doomedPlugin.getName());
+ } catch (Exception e) {
+ log.warn("Failed to unschedule jobs for plugin [" + doomedPlugin.getName() + "]", e);
+ }
}
}
}
}
- serverPluginService.restartMasterPluginContainer();
+ // only restart if the master was started to begin with; otherwise, leave it down
+ if (master != null) {
+ serverPluginService.restartMasterPluginContainer();
+ }
+
return doomedPlugins;
}
- public List<Plugin> undeployServerPlugins(List<Integer> pluginIds) {
- serverPluginsBean.setPluginEnabledFlag(pluginIds, false);
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
+ public List<Plugin> undeployServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception {
+ if (pluginIds == null || pluginIds.size() == 0) {
+ return new ArrayList<Plugin>(); // nothing to do
+ }
+
+ serverPluginsBean.setPluginEnabledFlag(subject, pluginIds, false);
ServerPluginServiceManagement serverPluginService = LookupUtil.getServerPluginService();
MasterServerPluginContainer master = serverPluginService.getMasterPluginContainer();
@@ -171,12 +199,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
Plugin doomedPlugin = entityManager.find(Plugin.class, pluginId);
if (doomedPlugin != null) {
doomedPlugins.add(doomedPlugin);
- AbstractTypeServerPluginContainer pc = master.getPluginContainer(doomedPlugin.getName());
- if (pc != null) {
- try {
- pc.unschedulePluginJobs(doomedPlugin.getName());
- } catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" + doomedPlugin.getName() + "]", e);
+ if (master != null) {
+ AbstractTypeServerPluginContainer pc = master.getPluginContainer(doomedPlugin.getName());
+ if (pc != null) {
+ try {
+ pc.unschedulePluginJobs(doomedPlugin.getName());
+ } catch (Exception e) {
+ log.warn("Failed to unschedule jobs for plugin [" + doomedPlugin.getName() + "]", e);
+ }
}
}
@@ -185,35 +215,65 @@ public class ServerPluginsBean implements ServerPluginsLocal {
// config can be set to the new cofig definition's default values.
doomedPlugin.setPluginConfiguration(null);
doomedPlugin.setScheduledJobsConfiguration(null);
-
- // TODO: this really won't do anything, our server plugin scanner will see it missing
- // and stream it back on the file system. Need to add a DELETED column to RHQ_PLUGIN
- // and call doomedPlugin.setDeleted(true). When deleted is true, our scanner can
- // skip writing the file to disk. All plugin queries should avoid returning
- // plugin rows that have deleted=true. Only then will removing it from the
- // file system as we do below actually help.
- File pluginDir = serverPluginService.getServerPluginsDirectory();
- File currentFile = new File(pluginDir, doomedPlugin.getPath());
- currentFile.delete();
+ doomedPlugin.setStatus(PluginStatusType.DELETED);
+
+ try {
+ File pluginDir = serverPluginService.getServerPluginsDirectory();
+ File currentFile = new File(pluginDir, doomedPlugin.getPath());
+ currentFile.delete();
+ } catch (Exception e) {
+ log.error("Failed to delete the undeployed plugin [" + doomedPlugin.getPath() + "]. Cause: "
+ + ThrowableUtil.getAllMessages(e));
+ }
}
}
- serverPluginService.restartMasterPluginContainer();
+ // only restart if the master was started to begin with; otherwise, leave it down
+ if (master != null) {
+ serverPluginService.restartMasterPluginContainer();
+ }
+
return doomedPlugins;
}
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void setPluginEnabledFlag(List<Integer> pluginIds, boolean enabled) {
+ public void setPluginEnabledFlag(Subject subject, List<Integer> pluginIds, boolean enabled) throws Exception {
+ if (pluginIds == null || pluginIds.size() == 0) {
+ return; // nothing to do
+ }
Query q = entityManager.createNamedQuery(Plugin.UPDATE_PLUGINS_ENABLED_BY_IDS);
q.setParameter("ids", pluginIds);
q.setParameter("enabled", Boolean.valueOf(enabled));
- q.executeUpdate();
+ int count = q.executeUpdate();
+ if (count != pluginIds.size()) {
+ throw new Exception("Failed to update [" + pluginIds.size() + "] plugins. Count was [" + count + "]");
+ }
+
+ return;
+ }
+
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void setPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status) throws Exception {
+ if (pluginIds == null || pluginIds.size() == 0) {
+ return; // nothing to do
+ }
+ List<Plugin> plugins = getServerPluginsById(pluginIds);
+ for (Plugin plugin : plugins) {
+ plugin.setStatus(status);
+ updatePluginExceptContent(subject, plugin);
+ }
return;
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public void registerPlugin(Subject subject, Plugin plugin, ServerPluginDescriptorType descriptor, File pluginFile)
- throws Exception {
+ public Plugin registerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception {
+
+ if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("Plugin [" + plugin.getName()
+ + "] must be a server plugin to be registered");
+ }
Plugin existingPlugin = null;
boolean newOrUpdated = false;
@@ -240,7 +300,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (plugin.getId() == 0) {
entityManager.persist(plugin);
} else {
- plugin = updatePluginExceptContent(plugin);
+ plugin = updatePluginExceptContent(subject, plugin);
}
if (pluginFile != null) {
@@ -250,10 +310,11 @@ public class ServerPluginsBean implements ServerPluginsLocal {
log.debug("Updated plugin entity [" + plugin + "]");
}
- return;
+ return plugin;
}
- public Plugin updatePluginExceptContent(Plugin plugin) throws Exception {
+ @RequiredPermission(Permission.MANAGE_SETTINGS)
+ public Plugin updatePluginExceptContent(Subject subject, Plugin plugin) throws Exception {
// this method is here because we need a way to update the plugin's information
// without blowing away the content data. Because we do not want to load the
// content blob in memory, the plugin's content field will be null - if we were
@@ -267,6 +328,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
q.setParameter("path", plugin.getPath());
q.setParameter("displayName", plugin.getDisplayName());
q.setParameter("enabled", plugin.isEnabled());
+ q.setParameter("status", plugin.getStatus());
q.setParameter("md5", plugin.getMD5());
q.setParameter("version", plugin.getVersion());
q.setParameter("ampsVersion", plugin.getAmpsVersion());
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 64efe4d..528d87c 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
@@ -8,6 +8,7 @@ import javax.persistence.NoResultException;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -40,7 +41,6 @@ public interface ServerPluginsLocal {
* Call this method to fill in that data that wasn't originally loaded.
*
* @param plugin
- *
* @return the same plugin, with the relationship data loaded
*/
Plugin getServerPluginRelationships(Plugin plugin);
@@ -49,7 +49,6 @@ public interface ServerPluginsLocal {
* Get a list of plugins from their IDs.
*
* @param pluginIds the IDs of the plugins to load.
- *
* @return plugins matching the given IDs
*/
List<Plugin> getServerPluginsById(List<Integer> pluginIds);
@@ -76,56 +75,76 @@ public interface ServerPluginsLocal {
/**
* Enables the plugins and restarts the server plugin container.
*
+ * @param subject user making the request
* @param pluginIds the plugins to be enabled
+ * @throws Exception if failed to disable a plugin
*/
- void enableServerPlugins(List<Integer> pluginIds);
+ void enableServerPlugins(Subject subject, List<Integer> pluginIds) throws Exception;
/**
* Disables the plugins and restarts the server plugin container.
*
+ * @param subject user making the request
* @param pluginIds the plugins to be disabled
- *
* @return the list of plugins that were disabled
+ * @throws Exception if failed to disable a plugin
*/
- List<Plugin> disableServerPlugins(List<Integer> pluginIds);
+ List<Plugin> 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
+ * @throws Exception if failed to undeploy a plugin
*/
- List<Plugin> undeployServerPlugins(List<Integer> pluginIds);
+ List<Plugin> 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.
+ * This has "requires new" semantics, so the results are committed immediately upon return.
+ *
+ * @param subject user making the request
+ * @param pluginIds the plugins to be enabled
+ * @param enabled the value of the enabled flag for the plugins
+ * @throws if failed to update a plugin
+ */
+ void setPluginEnabledFlag(Subject subject, List<Integer> pluginIds, boolean enabled) throws Exception;
+
+ /**
+ * Sets the status flag in the database but does NOT restart the server plugin container.
+ * If the status is {@link PluginStatusType#DELETED}, the enabled flag is also flipped to <code>false</code>.
*
+ * This has "requires new" semantics, so the results are committed immediately upon return.
+ *
+ * @param subject user making the request
* @param pluginIds the plugins to be enabled
* @param enabled the value of the enabled flag for the plugins
+ * @throws if failed to update one of the plugins
*/
- void setPluginEnabledFlag(List<Integer> pluginIds, boolean enabled);
+ void setPluginStatus(Subject subject, List<Integer> pluginIds, PluginStatusType status) throws Exception;
/**
* Registers the given plugin to the database.
*
* @param subject the user that needs to have permissions to add a plugin to the system
* @param plugin the plugin definition
- * @param descriptor the plugin descriptor that was found in the plugin file
* @param pluginFile the actual plugin file itself
+ * @return the plugin after being persisted
* @throws Exception if failed to fully register the plugin
*/
- void registerPlugin(Subject subject, Plugin plugin, ServerPluginDescriptorType descriptor, File pluginFile)
- throws Exception;
+ Plugin registerPlugin(Subject subject, Plugin plugin, File pluginFile) throws Exception;
/**
* Given a plugin that already exists, this will update that plugin's data in the database,
* except for the content, which is left as-is. If the plugin did not yet exist, an exception is thrown.
* You can use this to update the plugin's scheduled jobs configuration and plugin configuration.
*
+ * @param subject user making the request
* @param plugin existing plugin with updated data
* @return the updated plugin
* @throws Exception if the plugin did not already exist or an error occurred that caused the update to fail
*/
- public Plugin updatePluginExceptContent(Plugin plugin) throws Exception;
+ public Plugin updatePluginExceptContent(Subject subject, Plugin plugin) throws Exception;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index 90639d2..8250c7d 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -202,6 +202,7 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
q.setParameter("path", plugin.getPath());
q.setParameter("displayName", plugin.getDisplayName());
q.setParameter("enabled", plugin.isEnabled());
+ q.setParameter("status", plugin.getStatus());
q.setParameter("md5", plugin.getMD5());
q.setParameter("version", plugin.getVersion());
q.setParameter("ampsVersion", plugin.getAmpsVersion());
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
new file mode 100644
index 0000000..3301ba0
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
@@ -0,0 +1,254 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.server.plugin;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.hibernate.LazyInitializationException;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * @author John Mazzitelli
+ */
+@Test
+public class ServerPluginsBeanTest extends AbstractEJB3Test {
+ private ServerPluginsLocal serverPluginsBean;
+
+ @BeforeMethod
+ public void beforeMethod() {
+ TestGenericServerPluginService pluginService;
+ pluginService = new TestGenericServerPluginService();
+ prepareCustomServerPluginService(pluginService);
+
+ serverPluginsBean = LookupUtil.getServerPlugins();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void afterMethod() {
+
+ EntityManager em = null;
+
+ try {
+ unprepareServerPluginService();
+ } catch (Exception e) {
+ }
+
+ try {
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ Query q = em.createQuery("SELECT p FROM Plugin p WHERE p.name LIKE 'serverplugintest%'");
+ List<Plugin> doomed = q.getResultList();
+ for (Plugin plugin : doomed) {
+ em.remove(plugin);
+ }
+
+ getTransactionManager().commit();
+ em.close();
+ em = null;
+ } catch (Exception e) {
+ try {
+ System.out.println("CANNOT CLEAN UP TEST: Cause: " + e);
+ getTransactionManager().rollback();
+ } catch (Exception ignore) {
+ }
+ } finally {
+ if (null != em) {
+ em.close();
+ }
+ }
+ }
+
+ public void testGetPlugins() throws Exception {
+ Plugin p1 = registerPlugin(1);
+ Plugin p2 = registerPlugin(2);
+ List<String> pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ assert pluginNames.contains(p1.getName()) : pluginNames;
+ assert pluginNames.contains(p2.getName()) : pluginNames;
+ pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ assert !pluginNames.contains(p1.getName()) : pluginNames;
+ assert !pluginNames.contains(p2.getName()) : pluginNames;
+
+ Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ assert plugin.getId() == p1.getId() : plugin;
+ assert plugin.getName().equals(p1.getName()) : plugin;
+ assetLazyInitializationException(plugin);
+
+ plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
+ assert plugin.getPluginConfiguration() != null;
+ assert plugin.getScheduledJobsConfiguration() != null;
+ assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
+ assert plugin.getScheduledJobsConfiguration().equals(p1.getScheduledJobsConfiguration());
+
+ List<Plugin> plugins = this.serverPluginsBean.getServerPlugins();
+ assert plugins.contains(p1) : plugins;
+ assert plugins.contains(p2) : plugins;
+ assetLazyInitializationException(plugins.get(0));
+ assetLazyInitializationException(plugins.get(1));
+
+ List<Integer> ids = new ArrayList<Integer>(2);
+ ids.add(p1.getId());
+ ids.add(p2.getId());
+ plugins = this.serverPluginsBean.getServerPluginsById(ids);
+ assert plugins.size() == 2 : plugins;
+ assert plugins.contains(p1) : plugins;
+ assert plugins.contains(p2) : plugins;
+ assetLazyInitializationException(plugins.get(0));
+ assetLazyInitializationException(plugins.get(1));
+ }
+
+ public void testDisableEnablePlugins() throws Exception {
+ Plugin p1 = registerPlugin(1);
+ Plugin p2 = registerPlugin(2);
+
+ List<Integer> ids = new ArrayList<Integer>(2);
+ ids.add(p1.getId());
+ ids.add(p2.getId());
+ List<Plugin> 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
+ List<String> pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ assert pluginNames.contains(p1.getName()) : pluginNames;
+ assert pluginNames.contains(p2.getName()) : pluginNames;
+ pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ assert !pluginNames.contains(p1.getName()) : pluginNames;
+ assert !pluginNames.contains(p2.getName()) : pluginNames;
+
+ // re-enable them
+ this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
+ pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ assert pluginNames.contains(p1.getName()) : pluginNames;
+ assert pluginNames.contains(p2.getName()) : pluginNames;
+ pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ assert !pluginNames.contains(p1.getName()) : pluginNames;
+ assert !pluginNames.contains(p2.getName()) : pluginNames;
+
+ // make sure none of these enable/disable settings lost our config
+ Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
+ assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
+ assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
+ plugin = this.serverPluginsBean.getServerPlugin(p2.getName());
+ plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
+ assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
+ assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
+ }
+
+ public void testUndeployPlugins() throws Exception {
+
+ Plugin p1 = registerPlugin(1);
+ Plugin p2 = registerPlugin(2);
+
+ List<Integer> ids = new ArrayList<Integer>(2);
+ ids.add(p1.getId());
+ ids.add(p2.getId());
+ List<Plugin> 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;
+
+ List<String> pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be returned even here" + pluginNames;
+ assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be returned even here" + pluginNames;
+ pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ assert !pluginNames.contains(p1.getName()) : pluginNames;
+ assert !pluginNames.contains(p2.getName()) : pluginNames;
+
+ // re-install them - need to implement this feature
+ // this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
+ // pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(true);
+ // assert pluginNames.contains(p1.getName()) : pluginNames;
+ // assert pluginNames.contains(p2.getName()) : pluginNames;
+ // assert undeployed.get(0).getStatus() == PluginStatusType.INSTALLED;
+ // assert undeployed.get(1).getStatus() == PluginStatusType.INSTALLED;
+ // pluginNames = this.serverPluginsBean.getPluginNamesByEnabled(false);
+ // assert !pluginNames.contains(p1.getName()) : pluginNames;
+ // assert !pluginNames.contains(p2.getName()) : pluginNames;
+ }
+
+ private Plugin registerPlugin(int index) throws Exception {
+ Plugin plugin = new Plugin(0, "serverplugintest" + index, "path", "displayName", true,
+ PluginStatusType.INSTALLED, "description", "help", "md5", "version", "ampsVersion",
+ PluginDeploymentType.SERVER, createPluginConfiguration(), createScheduledJobsConfiguration(), System
+ .currentTimeMillis(), System.currentTimeMillis());
+
+ plugin = this.serverPluginsBean.registerPlugin(getOverlord(), plugin, null);
+ assert plugin.getId() > 0;
+ assert plugin.isEnabled() == true;
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ assert plugin.getPluginConfiguration() != null;
+ assert plugin.getScheduledJobsConfiguration() != null;
+ return plugin;
+ }
+
+ private void assetLazyInitializationException(Plugin plugin) {
+ try {
+ plugin.getPluginConfiguration().toString();
+ assert false : "Should have thrown a lazy-initialization exception - we didn't load config";
+ } catch (LazyInitializationException ok) {
+ }
+ try {
+ plugin.getScheduledJobsConfiguration().toString();
+ assert false : "Should have thrown a lazy-initialization exception - we didn't load config";
+ } catch (LazyInitializationException ok) {
+ }
+ }
+
+ private Configuration createPluginConfiguration() {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("simpleprop1", "simpleprop1value"));
+ return config;
+ }
+
+ private Configuration createScheduledJobsConfiguration() {
+ Configuration config = new Configuration();
+ PropertyMap map = new PropertyMap("jobname");
+ config.put(map);
+ map.put(new PropertySimple("methodName", "methodNameValue"));
+ return config;
+ }
+
+ private Subject getOverlord() {
+ return LookupUtil.getSubjectManager().getOverlord();
+ }
+}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 2d30403..592a3d9 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
@@ -29,6 +29,7 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
@@ -195,10 +196,10 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
File pluginFile = new File(env.getPluginUrl().toURI());
Plugin plugin = new Plugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
- .getDisplayName(), true, pluginDescriptor.getDescription(), "", MessageDigestGenerator
- .getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor.getVersion(),
- PluginDeploymentType.SERVER, pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
- .currentTimeMillis());
+ .getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor.getDescription(), "",
+ MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor
+ .getVersion(), PluginDeploymentType.SERVER, pluginConfig, scheduledJobsConfig, System
+ .currentTimeMillis(), System.currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit d191decc1328210999f7ace3be051dde164b29f9
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 20 14:52:19 2009 -0500
out out tabs! fix formatting
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..4cc035a 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -1484,39 +1484,39 @@
</schema-directSQL>
<schema-addColumn table="RHQ_RAW_CONFIG" column="CONFIG_ID" columnType="INTEGER"/>
- <schema-alterColumn table="RHQ_RAW_CONFIG"
- column="CONFIG_ID"
+ <schema-alterColumn table="RHQ_RAW_CONFIG"
+ column="CONFIG_ID"
columnType="INTEGER"
nullable="false"/>
<schema-addColumn table="RHQ_RAW_CONFIG" column="PATH" columnType="VARCHAR2"/>
- <schema-alterColumn table="RHQ_RAW_CONFIG"
- column="PATH"
+ <schema-alterColumn table="RHQ_RAW_CONFIG"
+ column="PATH"
columnType="VARCHAR2"
precision="512"/>
<schema-addColumn table="RHQ_RAW_CONFIG" column="CONTENTS" columnType="BLOB"/>
- <schema-alterColumn table="RHQ_RAW_CONFIG"
- column="CONTENTS"
+ <schema-alterColumn table="RHQ_RAW_CONFIG"
+ column="CONTENTS"
columnType="BLOB"
nullable="false"/>
<schema-addColumn table="RHQ_RAW_CONFIG" column="SHA256" columnType="VARCHAR2"/>
- <schema-alterColumn table="RHQ_RAW_CONFIG"
- column="SHA256"
+ <schema-alterColumn table="RHQ_RAW_CONFIG"
+ column="SHA256"
columnType="VARCHAR2"
- precision="64"
+ precision="64"
nullable="false"/>
<schema-addColumn table="RHQ_RAW_CONFIG" column="CTIME" columnType="LONG"/>
- <schema-alterColumn table="RHQ_RAW_CONFIG"
- column="CTIME"
+ <schema-alterColumn table="RHQ_RAW_CONFIG"
+ column="CTIME"
columnType="LONG"
nullable="false"/>
<schema-addColumn table="RHQ_RAW_CONFIG" column="MTIME" columnType="LONG"/>
- <schema-alterColumn table="RHQ_RAW_CONFIG"
- column="MTIME"
+ <schema-alterColumn table="RHQ_RAW_CONFIG"
+ column="MTIME"
columnType="LONG"
nullable="false"/>
@@ -2024,62 +2024,60 @@
<schema-addColumn table="RHQ_REPO" column="IS_CANDIDATE" columnType="BOOLEAN"/>
<schema-alterColumn table="RHQ_REPO" column="IS_CANDIDATE" nullable="false" />
</schemaSpec>
-
- <!-- Generic tagging support -->
+
+ <!-- Generic tagging support -->
<schemaSpec version="2.64">
- <schema-createSequence name="RHQ_TAG_ID_SEQ" initial="10001" />
- <schema-directSQL>
- <statement>
- CREATE TABLE RHQ_TAG ( ID INTEGER PRIMARY KEY )
- </statement>
- </schema-directSQL>
- <schema-alterColumn table="RHQ_TAG" column="ID" nullable="false" />
- <schema-addColumn table="RHQ_TAG" column="NAME" precision="200" columnType="VARCHAR2" />
- <schema-alterColumn table="RHQ_TAG" column="NAME" nullable="false" />
- <schema-addColumn table="RHQ_TAG" column="DESCRIPTION" precision="500" columnType="VARCHAR2" />
- </schemaSpec>
-
- <!-- Distribution Files -->
- <schemaSpec version="2.65">
- <schema-directSQL>
- <statement>
- CREATE TABLE RHQ_DISTRIBUTION_FILE ( DISTRIBUTION_ID INTEGER )
- </statement>
- </schema-directSQL>
- <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="DISTRIBUTION_ID" nullable="false" />
- <schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="RELATIVE_FILENAME" precision="256" columnType="VARCHAR2" />
- <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="RELATIVE_FILENAME" nullable="false" />
- <schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="MD5SUM" precision="64" columnType="VARCHAR2" />
- <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="MD5SUM" nullable="false" />
- <schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="LAST_MODIFIED" columnType="LONG" />
- <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="LAST_MODIFIED" nullable="false" />
- <schema-directSQL>
- <statement targetDBVendor="postgresql">
- CREATE UNIQUE INDEX RHQ_DISTRIBUTION_FILE_IDX
- ON RHQ_DISTRIBUTION_FILE ( DISTRIBUTION_ID, RELATIVE_FILENAME )
- </statement>
- <statement targetDBVendor="oracle">
- CREATE UNIQUE INDEX RHQ_DISTRIBUTION_FILE_IDX
- ON RHQ_DISTRIBUTION_FILE ( DISTRIBUTION_ID, RELATIVE_FILENAME )
- </statement>
- </schema-directSQL>
- <schema-directSQL>
- <statement targetDBVendor="oracle">
- ALTER TABLE RHQ_DISTRIBUTION_FILE
- ADD CONSTRAINT RHQ_DIST_FILE_FKEY
- FOREIGN KEY ( DISTRIBUTION_ID)
- REFERENCES RHQ_DISTRIBUTION ( ID )
- </statement>
- <statement targetDBVendor="postgresql">
- ALTER TABLE RHQ_DISTRIBUTION_FILE
- ADD CONSTRAINT RHQ_DIST_FILE_FKEY
- FOREIGN KEY ( DISTRIBUTION_ID)
- REFERENCES RHQ_DISTRIBUTION ( ID )
- </statement>
- </schema-directSQL>
-
+ <schema-createSequence name="RHQ_TAG_ID_SEQ" initial="10001" />
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_TAG ( ID INTEGER PRIMARY KEY )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_TAG" column="ID" nullable="false" />
+ <schema-addColumn table="RHQ_TAG" column="NAME" precision="200" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_TAG" column="NAME" nullable="false" />
+ <schema-addColumn table="RHQ_TAG" column="DESCRIPTION" precision="500" columnType="VARCHAR2" />
</schemaSpec>
+ <!-- Distribution Files -->
+ <schemaSpec version="2.65">
+ <schema-directSQL>
+ <statement>
+ CREATE TABLE RHQ_DISTRIBUTION_FILE ( DISTRIBUTION_ID INTEGER )
+ </statement>
+ </schema-directSQL>
+ <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="DISTRIBUTION_ID" nullable="false" />
+ <schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="RELATIVE_FILENAME" precision="256" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="RELATIVE_FILENAME" nullable="false" />
+ <schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="MD5SUM" precision="64" columnType="VARCHAR2" />
+ <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="MD5SUM" nullable="false" />
+ <schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="LAST_MODIFIED" columnType="LONG" />
+ <schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="LAST_MODIFIED" nullable="false" />
+ <schema-directSQL>
+ <statement targetDBVendor="postgresql">
+ CREATE UNIQUE INDEX RHQ_DISTRIBUTION_FILE_IDX
+ ON RHQ_DISTRIBUTION_FILE ( DISTRIBUTION_ID, RELATIVE_FILENAME )
+ </statement>
+ <statement targetDBVendor="oracle">
+ CREATE UNIQUE INDEX RHQ_DISTRIBUTION_FILE_IDX
+ ON RHQ_DISTRIBUTION_FILE ( DISTRIBUTION_ID, RELATIVE_FILENAME )
+ </statement>
+ </schema-directSQL>
+ <schema-directSQL>
+ <statement targetDBVendor="oracle">
+ ALTER TABLE RHQ_DISTRIBUTION_FILE
+ ADD CONSTRAINT RHQ_DIST_FILE_FKEY
+ FOREIGN KEY ( DISTRIBUTION_ID)
+ REFERENCES RHQ_DISTRIBUTION ( ID )
+ </statement>
+ <statement targetDBVendor="postgresql">
+ ALTER TABLE RHQ_DISTRIBUTION_FILE
+ ADD CONSTRAINT RHQ_DIST_FILE_FKEY
+ FOREIGN KEY ( DISTRIBUTION_ID)
+ REFERENCES RHQ_DISTRIBUTION ( ID )
+ </statement>
+ </schema-directSQL>
+ </schemaSpec>
<!-- RHQ_REPO_TAG_MAP -->
<schemaSpec version="2.66">
@@ -2123,23 +2121,23 @@
</schemaSpec>
<schemaSpec version="2.68">
- <schema-createSequence name="RHQ_DISTRIBUTION_FILE_SEQ" initial="10001" />
+ <schema-createSequence name="RHQ_DISTRIBUTION_FILE_SEQ" initial="10001" />
<schema-directSQL>
- <statement>
- ALTER TABLE RHQ_DISTRIBUTION_FILE DROP CONSTRAINT RHQ_DISTRIBUTION_FILE_PKEY
- </statement>
+ <statement>
+ ALTER TABLE RHQ_DISTRIBUTION_FILE DROP CONSTRAINT RHQ_DISTRIBUTION_FILE_PKEY
+ </statement>
</schema-directSQL>
-
+
<schema-addColumn table="RHQ_DISTRIBUTION_FILE" column="ID" columnType="INTEGER" />
<schema-alterColumn table="RHQ_DISTRIBUTION_FILE" column="ID" nullable="false" />
-
- <schema-directSQL>
- <statement>
- ALTER TABLE RHQ_DISTRIBUTION_FILE ALTER COLUMN ID SET DEFAULT NEXTVAL('RHQ_DISTRIBUTION_FILE_ID_SEQ')
- </statement>
+
+ <schema-directSQL>
+ <statement>
+ ALTER TABLE RHQ_DISTRIBUTION_FILE ALTER COLUMN ID SET DEFAULT NEXTVAL('RHQ_DISTRIBUTION_FILE_ID_SEQ')
+ </statement>
</schema-directSQL>
- </schemaSpec>
-
+ </schemaSpec>
+
<!-- Add support for server-side plugins -->
<schemaSpec version="2.69">
<!-- add the new column that indicates if this is deployed on the SERVER or AGENT -->
commit ccefb1d4df35a99cc4b241781668662380f65625
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 20 13:58:48 2009 -0500
update schema catalog for eclipse usrs
diff --git a/etc/eclipse-tools/templates/schema.xmlcatalog b/etc/eclipse-tools/templates/schema.xmlcatalog
index 3107878..d4054bb 100644
--- a/etc/eclipse-tools/templates/schema.xmlcatalog
+++ b/etc/eclipse-tools/templates/schema.xmlcatalog
@@ -2,6 +2,10 @@
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uri name="urn:xmlns:rhq-configuration" uri="platform:/resource/rhq/modules/core/client-api/src/main/resources/rhq-configuration.xsd"/>
<uri name="urn:xmlns:rhq-plugin" uri="platform:/resource/rhq/modules/core/client-api/src/main/resources/rhq-plugin.xsd"/>
-<uri name="urn:xmlns:rhq-serverplugin.content" uri="platform:/resource/rhq/modules/core/client-api/src/main/resources/rhq-serverplugin-content.xsd"/>
-<uri name="urn:xmlns:rhq-perspective" uri="platform:/resource/rhq/modules/core/client-api/src/main/resources/rhq-perspective.xsd"/>
+<uri name="urn:xmlns:rhq-contentsource-packagedetails" uri="platform:/resource/rhq/modules/enterprise/server/xml-schemas/src/main/resources/rhq-contentsource-packagedetails.xsd"/>
+<uri name="urn:xmlns:rhq-serverplugin" uri="platform:/resource/rhq/modules/enterprise/server/xml-schemas/src/main/resources/rhq-serverplugin.xsd"/>
+<uri name="urn:xmlns:rhq-serverplugin.generic" uri="platform:/resource/rhq/modules/enterprise/server/xml-schemas/src/main/resources/rhq-serverplugin-generic.xsd"/>
+<uri name="urn:xmlns:rhq-serverplugin.alert" uri="platform:/resource/rhq/modules/enterprise/server/xml-schemas/src/main/resources/rhq-serverplugin-alert.xsd"/>
+<uri name="urn:xmlns:rhq-serverplugin.content" uri="platform:/resource/rhq/modules/enterprise/server/xml-schemas/src/main/resources/rhq-serverplugin-content.xsd"/>
+<uri name="urn:xmlns:rhq-serverplugin.perspective" uri="platform:/resource/rhq/modules/enterprise/server/xml-schemas/src/main/resources/rhq-serverplugin-perspective.xsd"/>
</catalog>
14 years, 5 months
[rhq] Changes to 'linux-config-apacheplugin'
by lkrejci
New branch 'linux-config-apacheplugin' available with the following commits:
commit 5cb404c685ce55c3184b23b66e4f1265adbac885
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Nov 27 16:58:16 2009 +0100
first draft of the apache resource config. not connected to any code or anything.
14 years, 5 months