[rhq] Branch 'content' - modules/enterprise
by Mike McCune
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java | 38 ++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerLocal.java | 31 +---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/DistributionSourceSynchronizer.java | 37 ++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/PackageSourceSynchronizer.java | 73 ++++------
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/ContentTestHelper.java | 37 +++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java | 12 +
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java | 12 -
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java | 10 -
8 files changed, 124 insertions(+), 126 deletions(-)
New commits:
commit 821577efc8012111e1b9d3c7ba89fe15883e6c87
Author: Mike McCune <mmccune(a)gibson.pdx.redhat.com>
Date: Mon Nov 30 15:55:03 2009 -0800
1103 - fixing NPE when syncing content. still broken thou
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 450a905..c7fd5a5 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
@@ -59,8 +59,8 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.Distribution;
import org.rhq.core.domain.content.DistributionFile;
import org.rhq.core.domain.content.DistributionType;
@@ -942,13 +942,13 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
//////////////////
// REMOVE
- syncResults = contentSourceManager._mergeDistributionSyncReportREMOVE(contentSource,
- report, syncResults, progress);
+ syncResults = contentSourceManager._mergeDistributionSyncReportREMOVE(contentSource, report, syncResults,
+ progress);
//////////////////
// ADD
- syncResults = contentSourceManager._mergeDistributionSyncReportADD(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
@@ -965,7 +965,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
// ThrowableUtil will dump SQL nextException messages, too
String errorMsg = "Could not process sync report from [" + contentSource + "]. Cause: "
+ ThrowableUtil.getAllMessages(t);
- log.error(errorMsg);
+ log.error(errorMsg, t);
throw new RuntimeException(errorMsg, t);
}
@@ -975,8 +975,7 @@ 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, Repo repo,
- PackageSyncReport report,
- Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
+ PackageSyncReport report, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults) {
try {
StringBuilder progress = new StringBuilder();
@@ -994,8 +993,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
//////////////////
// REMOVE
- syncResults = contentSourceManager._mergePackageSyncReportREMOVE(contentSource, repo,
- report, previous, syncResults, progress);
+ syncResults = contentSourceManager._mergePackageSyncReportREMOVE(contentSource, repo, report, previous,
+ syncResults, progress);
//////////////////
// ADD
@@ -1018,8 +1017,8 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
}
List<ContentProviderPackageDetails> pkgs = newPackages.subList(fromIndex, toIndex);
- syncResults = contentSourceManager._mergePackageSyncReportADD(contentSource, repo,
- pkgs, previous, syncResults, progress, fromIndex);
+ syncResults = contentSourceManager._mergePackageSyncReportADD(contentSource, repo, pkgs, previous,
+ syncResults, progress, fromIndex);
addedCount += pkgs.size();
fromIndex += chunkSize;
toIndex += chunkSize;
@@ -1050,7 +1049,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
// ThrowableUtil will dump SQL nextException messages, too
String errorMsg = "Could not process sync report from [" + contentSource + "]. Cause: "
+ ThrowableUtil.getAllMessages(t);
- log.error(errorMsg);
+ log.error(errorMsg, t);
throw new RuntimeException(errorMsg, t);
}
@@ -1073,12 +1072,9 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergePackageSyncReportREMOVE(ContentSource contentSource,
- Repo repo,
- 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());
@@ -1138,8 +1134,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
@SuppressWarnings("unchecked")
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public ContentSourceSyncResults _mergePackageSyncReportADD(ContentSource contentSource,
- Repo repo,
+ public ContentSourceSyncResults _mergePackageSyncReportADD(ContentSource contentSource, Repo repo,
Collection<ContentProviderPackageDetails> newPackages,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress, int addCount) {
@@ -1327,7 +1322,6 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
RepoPackageVersion mapping = new RepoPackageVersion(repo, pv);
entityManager.merge(mapping); // use merge just in case this mapping somehow already exists
-
// Cleanup
if ((++flushCount % 100) == 0) {
knownResourceTypes.clear();
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 850cd6d..9dfa9a1 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
@@ -41,9 +41,9 @@ import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.server.plugin.pc.content.ContentProviderPackageDetails;
import org.rhq.enterprise.server.plugin.pc.content.ContentProviderPackageDetailsKey;
+import org.rhq.enterprise.server.plugin.pc.content.DistributionSyncReport;
import org.rhq.enterprise.server.plugin.pc.content.PackageSyncReport;
import org.rhq.enterprise.server.plugin.pc.content.RepoDetails;
-import org.rhq.enterprise.server.plugin.pc.content.DistributionSyncReport;
/**
* Interface that provides access to the {@link ContentSource} objects deployed in the server, allowing the callers to
@@ -245,7 +245,7 @@ public interface ContentSourceManagerLocal {
* contains the location where those package versions are located in the content source
*/
List<PackageVersionContentSource> getPackageVersionsFromContentSourceForRepo(Subject subject, int contentSourceId,
- int repoId);
+ int repoId);
/**
* Returns count of PackageVersions associated with the given content source.
@@ -284,8 +284,6 @@ public interface ContentSourceManagerLocal {
PageList<PackageVersionContentSource> getPackageVersionsFromContentSources(Subject subject, int[] contentSourceIds,
PageControl pc);
-
-
/**
* Returns all the package versions that are served by the content source identified by the given ID but whose
* {@link PackageVersion#getPackageBits() package bits} have not been loaded yet.
@@ -300,8 +298,6 @@ public interface ContentSourceManagerLocal {
PageList<PackageVersionContentSource> getUnloadedPackageVersionsFromContentSourceInRepo(Subject subject,
int contentSourceId, int repoId, PageControl pc);
-
-
/**
* This will download all the distribution bits associated with a specific content source.
*
@@ -310,7 +306,6 @@ public interface ContentSourceManagerLocal {
*/
void downloadDistributionBits(Subject subject, ContentSource contentSource);
-
/**
* Given a {@link PackageVersionContentSource} which contains the ID of a content source, an ID of a package
* version, and the location of that package version on the remote content source repo, this will download the
@@ -401,9 +396,7 @@ public interface ContentSourceManagerLocal {
* @return the updated syncResults that includes more summary information in the results string that indicates what
* was done
*/
- ContentSourceSyncResults mergePackageSyncReport(ContentSource contentSource,
- Repo repo,
- PackageSyncReport report,
+ ContentSourceSyncResults mergePackageSyncReport(ContentSource contentSource, Repo repo, PackageSyncReport report,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults);
@@ -417,19 +410,17 @@ public interface ContentSourceManagerLocal {
* @return the updated syncResults that includes more summary information in the results string that indicates what
* was done
*/
- ContentSourceSyncResults mergeDistributionSyncReport(ContentSource contentSource,
- DistributionSyncReport report,
- ContentSourceSyncResults syncResults);
+ ContentSourceSyncResults mergeDistributionSyncReport(ContentSource contentSource, DistributionSyncReport report,
+ ContentSourceSyncResults syncResults);
void _mergePackageSyncReportUpdateRepo(int contentSourceId);
- ContentSourceSyncResults _mergePackageSyncReportREMOVE(ContentSource contentSource,
- Repo repo, PackageSyncReport report,
- Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
+ ContentSourceSyncResults _mergePackageSyncReportREMOVE(ContentSource contentSource, Repo repo,
+ PackageSyncReport report, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress);
- ContentSourceSyncResults _mergePackageSyncReportADD(ContentSource contentSource,
- Repo repo, Collection<ContentProviderPackageDetails> newPackages,
+ ContentSourceSyncResults _mergePackageSyncReportADD(ContentSource contentSource, Repo repo,
+ Collection<ContentProviderPackageDetails> newPackages,
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress, int addCount);
@@ -437,8 +428,8 @@ public interface ContentSourceManagerLocal {
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
ContentSourceSyncResults syncResults, StringBuilder progress);
- ContentSourceSyncResults _mergeDistributionSyncReportREMOVE(ContentSource contentSource, DistributionSyncReport report,
- ContentSourceSyncResults syncResults, StringBuilder progress);
+ ContentSourceSyncResults _mergeDistributionSyncReportREMOVE(ContentSource contentSource,
+ DistributionSyncReport report, ContentSourceSyncResults syncResults, StringBuilder progress);
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/DistributionSourceSynchronizer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/DistributionSourceSynchronizer.java
index 062390e..2171bbf 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/DistributionSourceSynchronizer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/sync/DistributionSourceSynchronizer.java
@@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.ContentSource;
+import org.rhq.core.domain.content.ContentSourceSyncResults;
import org.rhq.core.domain.content.Distribution;
import org.rhq.core.domain.content.DistributionFile;
import org.rhq.core.domain.content.Repo;
@@ -63,8 +64,7 @@ public class DistributionSourceSynchronizer {
private ContentSource source;
private ContentProvider provider;
- public DistributionSourceSynchronizer(Repo repo, ContentSource source,
- ContentProvider provider) {
+ public DistributionSourceSynchronizer(Repo repo, ContentSource source, ContentProvider provider) {
this.repo = repo;
this.source = source;
this.provider = provider;
@@ -81,8 +81,7 @@ public class DistributionSourceSynchronizer {
DistributionSource distributionSource = (DistributionSource) provider;
- log.info("Synchronize Distributions: [" + source.getName() +
- "]: syncing repo [" + repo.getName() + "]");
+ log.info("Synchronize Distributions: [" + source.getName() + "]: syncing repo [" + repo.getName() + "]");
// Load existing distributions to send to source
// --------------------------------------------
@@ -90,18 +89,15 @@ public class DistributionSourceSynchronizer {
PageControl pc = PageControl.getUnlimitedInstance();
Subject overlord = subjectManager.getOverlord();
- List<Distribution> dists = repoManager
- .findAssociatedDistributions(overlord, repo.getId(), pc);
+ List<Distribution> dists = repoManager.findAssociatedDistributions(overlord, repo.getId(), pc);
log.debug("Found " + dists.size() + " distributions for repo " + repo.getId());
DistributionSyncReport distReport = new DistributionSyncReport(repo.getId());
- List<DistributionDetails> distDetails =
- new ArrayList<DistributionDetails>(dists.size());
+ List<DistributionDetails> distDetails = new ArrayList<DistributionDetails>(dists.size());
translateDomainToDto(dists, distDetails);
- log.info("Synchronize Distributions: [" + source.getName() +
- "]: loaded existing list of size=["
- + dists.size() + "] (" + (System.currentTimeMillis() - start) + ")ms");
+ log.info("Synchronize Distributions: [" + source.getName() + "]: loaded existing list of size=[" + dists.size()
+ + "] (" + (System.currentTimeMillis() - start) + ")ms");
// Ask source to do the sync
// --------------------------------------------
@@ -109,11 +105,11 @@ public class DistributionSourceSynchronizer {
distributionSource.synchronizeDistribution(repo.getName(), distReport, distDetails);
- log.info("Synchronize Distributions: [" + source.getName() +
- "]: got sync report from adapter=["
- + distReport + "] (" + (System.currentTimeMillis() - start) + ")ms");
+ log.info("Synchronize Distributions: [" + source.getName() + "]: got sync report from adapter=[" + distReport
+ + "] (" + (System.currentTimeMillis() - start) + ")ms");
- contentSourceManager.mergeDistributionSyncReport(source, distReport, null);
+ ContentSourceSyncResults syncResults = new ContentSourceSyncResults(source);
+ contentSourceManager.mergeDistributionSyncReport(source, distReport, syncResults);
}
public void synchronizeDistributionBits() throws Exception {
@@ -121,21 +117,18 @@ public class DistributionSourceSynchronizer {
contentSourceManager.downloadDistributionBits(overlord, source);
}
- private void translateDomainToDto(List<Distribution> dists,
- List<DistributionDetails> distDetails) {
+ private void translateDomainToDto(List<Distribution> dists, List<DistributionDetails> distDetails) {
DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal();
for (Distribution d : dists) {
- DistributionDetails detail = new DistributionDetails(d.getLabel(),
- d.getDistributionType().getName());
+ DistributionDetails detail = new DistributionDetails(d.getLabel(), d.getDistributionType().getName());
detail.setLabel(d.getLabel());
detail.setDistributionPath(d.getBasePath());
detail.setDescription(d.getDistributionType().getDescription());
List<DistributionFile> files = distManager.getDistributionFilesByDistId(d.getId());
for (DistributionFile f : files) {
- DistributionFileDetails dfd =
- new DistributionFileDetails(f.getRelativeFilename(), f.getLastModified(),
- f.getMd5sum());
+ DistributionFileDetails dfd = new DistributionFileDetails(f.getRelativeFilename(), f.getLastModified(),
+ f.getMd5sum());
detail.addFile(dfd);
}
distDetails.add(detail);
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 6e6bc5a..cff3ba7 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
@@ -34,11 +34,12 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.content.ContentSource;
+import org.rhq.core.domain.content.ContentSourceSyncResults;
+import org.rhq.core.domain.content.DownloadMode;
import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.content.PackageVersionContentSource;
import org.rhq.core.domain.content.PackageVersionContentSourcePK;
import org.rhq.core.domain.content.Repo;
-import org.rhq.core.domain.content.DownloadMode;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageControl;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
@@ -67,8 +68,7 @@ public class PackageSourceSynchronizer {
private ContentSource source;
private ContentProvider provider;
- public PackageSourceSynchronizer(Repo repo, ContentSource source,
- ContentProvider provider) {
+ public PackageSourceSynchronizer(Repo repo, ContentSource source, ContentProvider provider) {
this.repo = repo;
this.source = source;
this.provider = provider;
@@ -93,19 +93,17 @@ public class PackageSourceSynchronizer {
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> keyPVCSMap;
Subject overlord = subjectManager.getOverlord();
- existingPVCS = contentSourceManager.getPackageVersionsFromContentSourceForRepo(
- overlord, source.getId(), repo.getId());
+ existingPVCS = contentSourceManager.getPackageVersionsFromContentSourceForRepo(overlord, source.getId(), repo
+ .getId());
int existingCount = existingPVCS.size();
- keyPVCSMap = new HashMap<ContentProviderPackageDetailsKey,
- PackageVersionContentSource>(existingCount);
+ keyPVCSMap = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>(existingCount);
allDetails = new HashSet<ContentProviderPackageDetails>(existingCount);
translateDomainToDto(existingPVCS, allDetails, keyPVCSMap);
- log.info("Synchronize Packages: [" + source.getName() +
- "]: loaded existing list of size=[" + existingCount + "] (" +
- (System.currentTimeMillis() - start) + ")ms");
+ log.info("Synchronize Packages: [" + source.getName() + "]: loaded existing list of size=[" + existingCount
+ + "] (" + (System.currentTimeMillis() - start) + ")ms");
// Ask source to do the sync
// --------------------------------------------
@@ -114,19 +112,17 @@ public class PackageSourceSynchronizer {
PackageSyncReport report = new PackageSyncReport();
packageSource.synchronizePackages(repo.getName(), report, allDetails);
- log.info("Synchronize Packages: [" + source.getName() +
- "]: got sync report from adapter=[" + report + "] (" +
- (System.currentTimeMillis() - start) + ")ms");
+ log.info("Synchronize Packages: [" + source.getName() + "]: got sync report from adapter=[" + report + "] ("
+ + (System.currentTimeMillis() - start) + ")ms");
// Merge in the results of the synchronization
// --------------------------------------------
start = System.currentTimeMillis();
+ ContentSourceSyncResults syncResults = new ContentSourceSyncResults(source);
+ syncResults = contentSourceManager.mergePackageSyncReport(source, repo, report, keyPVCSMap, syncResults);
- contentSourceManager.mergePackageSyncReport(source, repo, report, keyPVCSMap, null);
-
- log.info("Synchronize Packages: [" + source.getName() +
- "]: merged sync report=(" +
- (System.currentTimeMillis() - start) + ")ms");
+ log.info("Synchronize Packages: [" + source.getName() + "]: merged sync report=("
+ + (System.currentTimeMillis() - start) + ")ms");
}
public void synchronizePackageBits() throws Exception {
@@ -137,18 +133,17 @@ public class PackageSourceSynchronizer {
}
if (source.getDownloadMode() == DownloadMode.NEVER) {
- log.info("Download mode of NEVER for source [" + source.getName() + "], skipping " +
- "package bits sync for repo [" + repo.getName() + "]");
+ log.info("Download mode of NEVER for source [" + source.getName() + "], skipping "
+ + "package bits sync for repo [" + repo.getName() + "]");
return;
}
if (source.isLazyLoad()) {
- log.info("Lazy load enabled for source [" + source.getName() + "], skipping " +
- "package bits sync for repo [" + repo.getName() + "]");
+ log.info("Lazy load enabled for source [" + source.getName() + "], skipping "
+ + "package bits sync for repo [" + repo.getName() + "]");
return;
}
-
long start;
// Determine which packages need bit synccing
@@ -162,8 +157,8 @@ public class PackageSourceSynchronizer {
// TODO: jdob - Need to change this call to only load packages for this repo
List<PackageVersionContentSource> packageVersionContentSources = contentSourceManager
.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");
+ log.info("Synchronize Package Bits: [" + source.getName() + "], repo [" + repo.getName()
+ + "]: loaded package list for sync (" + (System.currentTimeMillis() - start) + ")ms");
// Download the bits for each unloaded package version. Abort the entire download if we
// fail getting just one package.
@@ -174,27 +169,22 @@ public class PackageSourceSynchronizer {
try {
if (log.isDebugEnabled()) {
- log.debug(
- "Downloading package version [" + pk.getPackageVersion() + "] located at ["
- + item.getLocation() + "]" + "] from [" + pk.getContentSource() + "]...");
+ log.debug("Downloading package version [" + pk.getPackageVersion() + "] located at ["
+ + item.getLocation() + "]" + "] from [" + pk.getContentSource() + "]...");
}
overlord = subjectManager.getOverlord();
contentSourceManager.downloadPackageBits(overlord, item);
- }
- catch (Exception e) {
- String errorMsg =
- "Failed to load package bits for package version [" + pk.getPackageVersion()
- + "] from content source [" + pk.getContentSource() + "] at location [" +
- item.getLocation()
- + "]." + "No more packages will be downloaded for this content source.";
+ } catch (Exception e) {
+ String errorMsg = "Failed to load package bits for package version [" + pk.getPackageVersion()
+ + "] from content source [" + pk.getContentSource() + "] at location [" + item.getLocation() + "]."
+ + "No more packages will be downloaded for this content source.";
throw new Exception(errorMsg, e);
}
}
- log.info("All package bits for content source [" + source.getName() +
- "] have been downloaded."
+ log.info("All package bits for content source [" + source.getName() + "] have been downloaded."
+ "The downloads started at [" + new Date(start) + "] and ended at [" + new Date() + "]");
}
@@ -210,8 +200,8 @@ public class PackageSourceSynchronizer {
* @param keyPVCSMap mapping of package version key to package domain object
*/
private void translateDomainToDto(List<PackageVersionContentSource> existingPVCS,
- Set<ContentProviderPackageDetails> allDetails,
- Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> keyPVCSMap) {
+ Set<ContentProviderPackageDetails> allDetails,
+ Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> keyPVCSMap) {
for (PackageVersionContentSource pvcs : existingPVCS) {
PackageVersion pv = pvcs.getPackageVersionContentSourcePK().getPackageVersion();
@@ -219,9 +209,8 @@ public class PackageSourceSynchronizer {
ResourceType rt = p.getPackageType().getResourceType();
ContentProviderPackageDetailsKey key;
- key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(),
- p.getPackageType()
- .getName(), pv.getArchitecture().getName(), rt.getName(), rt.getPlugin());
+ key = new ContentProviderPackageDetailsKey(p.getName(), pv.getVersion(), p.getPackageType().getName(), pv
+ .getArchitecture().getName(), rt.getName(), rt.getPlugin());
ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
details.setClassification(pv.getGeneralPackage().getClassification());
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/ContentTestHelper.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/ContentTestHelper.java
new file mode 100644
index 0000000..960231e
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/ContentTestHelper.java
@@ -0,0 +1,37 @@
+package org.rhq.enterprise.server.content;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.content.ContentSource;
+import org.rhq.core.domain.content.ContentSourceType;
+import org.rhq.core.domain.content.Repo;
+import org.rhq.enterprise.server.content.metadata.ContentSourceMetadataManagerLocal;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+public class ContentTestHelper {
+
+ public static ContentSource getTestContentSource() throws Exception {
+ Subject overlord = LookupUtil.getSubjectManager().getOverlord();
+ ContentSourceMetadataManagerLocal contentSourceMetadataManager = LookupUtil.getContentSourceMetadataManager();
+ ContentSourceManagerLocal contentSourceManager = LookupUtil.getContentSourceManager();
+ ContentSourceType type = new ContentSourceType("testGetSyncResultsListCST");
+ Set<ContentSourceType> types = new HashSet<ContentSourceType>();
+ types.add(type);
+ contentSourceMetadataManager.registerTypes(types); // this blows away any previous existing types
+ ContentSource contentSource = new ContentSource("testGetSyncResultsListCS", type);
+ contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
+ return contentSource;
+ }
+
+ public static Repo getTestRepoWithContentSource() throws Exception {
+ Repo repo = new Repo("testSyncRepos");
+ Subject overlord = LookupUtil.getSubjectManager().getOverlord();
+ LookupUtil.getRepoManagerLocal().createRepo(overlord, repo);
+ ContentSource contentSource = getTestContentSource();
+ repo.addContentSource(contentSource);
+ return repo;
+ }
+
+}
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 afe2593..f418715 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
@@ -349,7 +349,8 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
// confirm that we didn't load the bits yet
pc = PageControl.getUnlimitedInstance();
List<PackageVersionContentSource> unloaded;
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
+ contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
@@ -462,7 +463,8 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
// confirm that we didn't load the bits yet
List<PackageVersionContentSource> unloaded;
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
+ contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
@@ -492,7 +494,8 @@ 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.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
+ contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
assert unloaded.get(0).getPackageVersionContentSourcePK().getPackageVersion().getFileSize() == 9999L;
@@ -584,7 +587,8 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
assert results != null;
List<PackageVersionContentSource> unloaded;
- unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord, contentSourceId, repoId, pc);
+ unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
+ contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
index 935bae9..a31ef46 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
@@ -47,6 +47,7 @@ import org.rhq.core.domain.criteria.RepoCriteria;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
+import org.rhq.enterprise.server.content.ContentTestHelper;
import org.rhq.enterprise.server.content.RepoException;
import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.content.metadata.ContentSourceMetadataManagerLocal;
@@ -108,17 +109,8 @@ public class RepoManagerBeanTest extends AbstractEJB3Test {
@Test(enabled = true)
public void testSyncRepos() throws Exception {
- Repo repo = new Repo("testSyncStatus");
-
- ContentSourceType type = new ContentSourceType("testGetSyncResultsListCST");
- Set<ContentSourceType> types = new HashSet<ContentSourceType>();
- types.add(type);
- contentSourceMetadataManager.registerTypes(types); // this blows away any previous existing types
- ContentSource contentSource = new ContentSource("testGetSyncResultsListCS", type);
- contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
- repo.addContentSource(contentSource);
+ Repo repo = ContentTestHelper.getTestRepoWithContentSource();
- repoManager.createRepo(overlord, repo);
Integer[] ids = { repo.getId() };
int syncCount = repoManager.synchronizeRepos(overlord, ids);
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java
index a0c6b7c..1ffae7b 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java
@@ -6,11 +6,10 @@ 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.content.Repo;
+import org.rhq.enterprise.server.content.ContentTestHelper;
import org.rhq.enterprise.server.plugin.pc.content.TestContentServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
-import org.rhq.enterprise.server.util.LookupUtil;
public class RepoSyncingTest extends AbstractEJB3Test {
@@ -24,12 +23,11 @@ public class RepoSyncingTest extends AbstractEJB3Test {
public void testSyncRepos() throws Exception {
TestContentServerPluginService pluginService = new TestContentServerPluginService(this);
- Repo repo = new Repo("testSyncRepos");
-
- Subject overlord = LookupUtil.getSubjectManager().getOverlord();
- LookupUtil.getRepoManagerLocal().createRepo(overlord, repo);
+ Repo repo = ContentTestHelper.getTestRepoWithContentSource();
+ assert repo.getContentSources().size() == 1;
boolean synced = pluginService.getContentProviderManager().synchronizeRepo(repo.getId());
+
assert synced;
}
14 years
[rhq] Branch 'content' - modules/core modules/enterprise
by Mike McCune
modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java | 4
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java | 2
modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/listRepos.xhtml | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java | 2
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/ContentSourceManagerBeanTest.java | 7
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java | 32 +--
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java | 47 ++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManagerTest.java | 100 +---------
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentProvider.java | 72 +++++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentServerPluginService.java | 99 ++-------
10 files changed, 178 insertions(+), 189 deletions(-)
New commits:
commit 45826a4216d055d6ca0a9caca79f0ddd030a4eba
Author: Mike McCune <mmccune(a)gibson.pdx.redhat.com>
Date: Mon Nov 30 14:48:40 2009 -0800
1102 - test refactoring to unify TestContentProvider
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java b/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
index efcaa0c..061dea5 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
@@ -820,8 +820,8 @@ public class Repo implements Serializable, Taggable {
Comparator dc = new Comparator() {
public int compare(Object arg0, Object arg1) {
long currTime = System.currentTimeMillis();
- ContentSourceSyncResults c1 = (ContentSourceSyncResults) arg0;
- ContentSourceSyncResults c2 = (ContentSourceSyncResults) arg1;
+ RepoSyncResults c1 = (RepoSyncResults) arg0;
+ RepoSyncResults c2 = (RepoSyncResults) arg1;
Date d1 = null;
Date d2 = null;
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java
index e4041c5..4c923ec 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/content/ListReposUIBean.java
@@ -57,7 +57,7 @@ public class ListReposUIBean extends PagedDataTableUIBean {
return "importRepos";
}
- public String syncSelectedContentSources() {
+ public String syncSelectedRepos() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
String[] selected = getSelectedRepos();
Integer[] repoIds = getIntegerArray(selected);
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/listRepos.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/listRepos.xhtml
index 5e05070..284dd88 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/listRepos.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/content/listRepos.xhtml
@@ -147,7 +147,7 @@
<onc:selectCommandButton action="#{ListReposUIBean.deleteSelectedRepos}"
value="DELETE SELECTED" target="selectedRepos" styleClass="on-pager-button buttonsmall"/>
- <onc:selectCommandButton action="#{ListReposUIBean.syncSelectedContentSources}"
+ <onc:selectCommandButton action="#{ListReposUIBean.syncSelectedRepos}"
value="SYNC SELECTED" target="selectedRepos" styleClass="on-pager-button buttonsmall"/>
<ui:param name="paginationDataTableName" value="reposDataTable"/>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
index 1e195fb..08ad3c4 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManager.java
@@ -508,7 +508,7 @@ public class ContentProviderManager {
* @param contentSource the source that the adapter will connect to
* @return an adapter instance; will be <code>null</code> if failed to create adapter
*/
- private ContentProvider instantiateAdapter(ContentSource contentSource) {
+ protected ContentProvider instantiateAdapter(ContentSource contentSource) {
ContentProvider adapter = null;
String apiClassName = "?";
String pluginName = "?";
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 c79ec39..afe2593 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
@@ -40,8 +40,8 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.content.Architecture;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceSyncResults;
-import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.ContentSourceType;
+import org.rhq.core.domain.content.ContentSyncStatus;
import org.rhq.core.domain.content.DownloadMode;
import org.rhq.core.domain.content.InstalledPackage;
import org.rhq.core.domain.content.Package;
@@ -151,10 +151,7 @@ public class ContentSourceManagerBeanTest extends AbstractEJB3Test {
setupTestEnvironment();
overlord = LookupUtil.getSubjectManager().getOverlord();
prepareScheduler();
- TestContentServerPluginService pluginService = new TestContentServerPluginService();
- prepareCustomServerPluginService(pluginService);
- pluginService.startMasterPluginContainer();
-
+ TestContentServerPluginService pluginService = new TestContentServerPluginService(this);
cleanupPreviousTestRuns();
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
index f545530..935bae9 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoManagerBeanTest.java
@@ -66,6 +66,7 @@ public class RepoManagerBeanTest extends AbstractEJB3Test {
@BeforeMethod
public void setupBeforeMethod() throws Exception {
+
TransactionManager tx = getTransactionManager();
tx.begin();
@@ -73,10 +74,7 @@ public class RepoManagerBeanTest extends AbstractEJB3Test {
contentSourceManager = LookupUtil.getContentSourceManager();
contentSourceMetadataManager = LookupUtil.getContentSourceMetadataManager();
- TestContentServerPluginService pluginService = new TestContentServerPluginService();
- prepareCustomServerPluginService(pluginService);
- pluginService.startMasterPluginContainer();
-
+ TestContentServerPluginService pluginService = new TestContentServerPluginService(this);
overlord = LookupUtil.getSubjectManager().getOverlord();
}
@@ -100,7 +98,7 @@ public class RepoManagerBeanTest extends AbstractEJB3Test {
for (int i = 0; i < 10; i++) {
Random r = new Random(System.currentTimeMillis());
Repo repo = new Repo(r.nextLong() + "");
- repoManager.createRepo(overlord, repo).getId();
+ repoManager.createRepo(overlord, repo);
}
repos = repoManager.findRepos(overlord, new PageControl());
@@ -108,26 +106,24 @@ public class RepoManagerBeanTest extends AbstractEJB3Test {
}
- @Test(enabled = ENABLED)
+ @Test(enabled = true)
public void testSyncRepos() throws Exception {
Repo repo = new Repo("testSyncStatus");
+
+ ContentSourceType type = new ContentSourceType("testGetSyncResultsListCST");
+ Set<ContentSourceType> types = new HashSet<ContentSourceType>();
+ types.add(type);
+ contentSourceMetadataManager.registerTypes(types); // this blows away any previous existing types
+ ContentSource contentSource = new ContentSource("testGetSyncResultsListCS", type);
+ contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
+ repo.addContentSource(contentSource);
+
repoManager.createRepo(overlord, repo);
Integer[] ids = { repo.getId() };
int syncCount = repoManager.synchronizeRepos(overlord, ids);
- assert syncCount == 0;
-
- ContentSourceType cst = new ContentSourceType("testSyncStatus");
- ContentSource cs = new ContentSource("testSyncStatus", cst);
-
- EntityManager em = getEntityManager();
- em.persist(cst);
- em.persist(cs);
-
- repo.addContentSource(cs);
- syncCount = repoManager.synchronizeRepos(overlord, ids);
-
assert syncCount == 1;
+
}
@Test(enabled = ENABLED)
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java
new file mode 100644
index 0000000..a0c6b7c
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/content/test/RepoSyncingTest.java
@@ -0,0 +1,47 @@
+package org.rhq.enterprise.server.content.test;
+
+import javax.transaction.TransactionManager;
+
+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.content.Repo;
+import org.rhq.enterprise.server.plugin.pc.content.TestContentServerPluginService;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+public class RepoSyncingTest extends AbstractEJB3Test {
+
+ @BeforeMethod
+ public void setupBeforeMethod() throws Exception {
+ TransactionManager tx = getTransactionManager();
+ tx.begin();
+ }
+
+ @Test(enabled = true)
+ public void testSyncRepos() throws Exception {
+
+ TestContentServerPluginService pluginService = new TestContentServerPluginService(this);
+ Repo repo = new Repo("testSyncRepos");
+
+ Subject overlord = LookupUtil.getSubjectManager().getOverlord();
+ LookupUtil.getRepoManagerLocal().createRepo(overlord, repo);
+
+ boolean synced = pluginService.getContentProviderManager().synchronizeRepo(repo.getId());
+ assert synced;
+
+ }
+
+ @AfterMethod
+ public void tearDownAfterMethod() throws Exception {
+ unprepareServerPluginService();
+
+ TransactionManager tx = getTransactionManager();
+ if (tx != null) {
+ tx.rollback();
+ }
+ }
+
+}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManagerTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManagerTest.java
index d022a6d..d8328a9 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManagerTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/ContentProviderManagerTest.java
@@ -22,12 +22,10 @@
*/
package org.rhq.enterprise.server.plugin.pc.content;
-import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
import javax.persistence.EntityManager;
import javax.transaction.TransactionManager;
@@ -37,7 +35,6 @@ 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.content.ContentSource;
import org.rhq.core.domain.content.ContentSourceType;
import org.rhq.core.domain.content.PackageType;
@@ -68,12 +65,12 @@ public class ContentProviderManagerTest extends AbstractEJB3Test {
private static final String PLUGIN_NAME = "testPlugin";
private static final String CUSTOM_IMPORTED_REPO_NAME = "customImportedRepo";
- private static final String EXISTING_IMPORTED_REPO_NAME = "testRepoImportedExisting";
- private static final String EXISTING_CANDIDATE_REPO_NAME = "testRepoCandidateExisting";
+ public static final String EXISTING_IMPORTED_REPO_NAME = TestContentProvider.EXISTING_IMPORTED_REPO_NAME;
+ public static final String EXISTING_CANDIDATE_REPO_NAME = TestContentProvider.EXISTING_CANDIDATE_REPO_NAME;
private static final String PREVIOUS_CANDIDATE_REPO_NAME = "testPreviousCandidate";
- private TestContentProvider testProvider = new TestContentProvider();
+ TestContentServerPluginService pluginService;
// The following variables need to be cleaned up at the end of the test
@@ -98,9 +95,7 @@ public class ContentProviderManagerTest extends AbstractEJB3Test {
// Plugin service setup
prepareScheduler();
- TestContentServerPluginService pluginService = new TestContentServerPluginService();
- prepareCustomServerPluginService(pluginService);
- pluginService.startMasterPluginContainer();
+ pluginService = new TestContentServerPluginService(this);
// Because of the (current) transaction settings of some of the nested methods (i.e. REQUIRES_NEW),
// this test must commit its data and clean up after itself, as compared to simply rolling back the
@@ -224,8 +219,6 @@ public class ContentProviderManagerTest extends AbstractEJB3Test {
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
Subject overlord = subjectManager.getOverlord();
- TestContentProviderManager providerManager = new TestContentProviderManager();
-
Set<String> reposThatShouldBeSyncced = new HashSet();
// -> Add an already imported repo to the system so it already exists when the report introduces it
@@ -258,7 +251,11 @@ public class ContentProviderManagerTest extends AbstractEJB3Test {
// Test
// --------------------------------------------
- boolean completed = providerManager.synchronizeContentProvider(syncSource.getId());
+ // TestContentProviderManager providerManager = new TestContentProviderManager();
+ boolean tested = pluginService.getContentProviderManager().testConnection(syncSource.getId());
+ assert tested;
+
+ boolean completed = pluginService.getContentProviderManager().synchronizeContentProvider(syncSource.getId());
assert completed;
// Verify RepoGroups
@@ -346,81 +343,4 @@ public class ContentProviderManagerTest extends AbstractEJB3Test {
assert retrievedRepos.size() == 0;
}
-
- /**
- * Mock implementation of a content provider that will return known data.
- */
- private class TestContentProvider implements ContentProvider, PackageSource, RepoSource {
-
- public RepoImportReport importRepos() throws Exception {
- RepoImportReport report = new RepoImportReport();
-
- // Create a repo group in the system
- RepoGroupDetails group1 = new RepoGroupDetails("testRepoGroup", "family");
- report.addRepoGroup(group1);
-
- // Simple repo
- RepoDetails repo1 = new RepoDetails("testRepo1");
- repo1.setDescription("First test repo");
- report.addRepo(repo1);
-
- // Repo belonging to a group that was created in the sync
- RepoDetails repo2 = new RepoDetails("testRepo2");
- repo2.setRepoGroup("testRepoGroup");
- report.addRepo(repo2);
-
- // Repo with a parent repo created in this sync
- // Parent explicitly added to this list *after* this child to ensure that's not a problem
- RepoDetails repo3 = new RepoDetails("testRepo3");
- report.addRepo(repo3);
-
- RepoDetails repo4 = new RepoDetails("testRepo4");
- repo4.setParentRepoName("testRepo3");
- report.addRepo(repo4);
-
- // Repo that was already imported in the system
- RepoDetails repo5 = new RepoDetails(EXISTING_IMPORTED_REPO_NAME);
- report.addRepo(repo5);
-
- // Repo that was already a candidate in the system
- RepoDetails repo6 = new RepoDetails(EXISTING_CANDIDATE_REPO_NAME);
- report.addRepo(repo6);
-
- return report;
- }
-
- public void synchronizePackages(String repoName, PackageSyncReport report,
- Collection<ContentProviderPackageDetails> existingPackages) throws Exception {
- // No-op
- }
-
- public void initialize(Configuration configuration) throws Exception {
- // No-op
- }
-
- public void shutdown() {
- // No-op
- }
-
- public void testConnection() throws Exception {
- // No-op
- }
-
- public InputStream getInputStream(String location) throws Exception {
- // No-op
- return null;
- }
- }
-
- /**
- * Stubs out the methods in {@link ContentProviderManager} that would go out and expect a fully packaged plugin.
- * Instead, use the mock implementation provided above.
- */
- private class TestContentProviderManager extends ContentProviderManager {
-
- public ContentProvider getIsolatedContentProvider(int contentProviderId) throws RuntimeException {
- return testProvider;
- }
- }
-
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentProvider.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentProvider.java
new file mode 100644
index 0000000..99de8d3
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentProvider.java
@@ -0,0 +1,72 @@
+package org.rhq.enterprise.server.plugin.pc.content;
+
+import java.io.InputStream;
+import java.util.Collection;
+
+import org.rhq.core.domain.configuration.Configuration;
+
+public class TestContentProvider implements ContentProvider, PackageSource, RepoSource {
+
+ public static final String EXISTING_IMPORTED_REPO_NAME = "testRepoImportedExisting";
+ public static final String EXISTING_CANDIDATE_REPO_NAME = "testRepoCandidateExisting";
+
+ public RepoImportReport importRepos() throws Exception {
+ RepoImportReport report = new RepoImportReport();
+
+ // Create a repo group in the system
+ RepoGroupDetails group1 = new RepoGroupDetails("testRepoGroup", "family");
+ report.addRepoGroup(group1);
+
+ // Simple repo
+ RepoDetails repo1 = new RepoDetails("testRepo1");
+ repo1.setDescription("First test repo");
+ report.addRepo(repo1);
+
+ // Repo belonging to a group that was created in the sync
+ RepoDetails repo2 = new RepoDetails("testRepo2");
+ repo2.setRepoGroup("testRepoGroup");
+ report.addRepo(repo2);
+
+ // Repo with a parent repo created in this sync
+ // Parent explicitly added to this list *after* this child to ensure that's not a problem
+ RepoDetails repo3 = new RepoDetails("testRepo3");
+ report.addRepo(repo3);
+
+ RepoDetails repo4 = new RepoDetails("testRepo4");
+ repo4.setParentRepoName("testRepo3");
+ report.addRepo(repo4);
+
+ // Repo that was already imported in the system
+ RepoDetails repo5 = new RepoDetails(EXISTING_IMPORTED_REPO_NAME);
+ report.addRepo(repo5);
+
+ // Repo that was already a candidate in the system
+ RepoDetails repo6 = new RepoDetails(EXISTING_CANDIDATE_REPO_NAME);
+ report.addRepo(repo6);
+
+ return report;
+ }
+
+ public void synchronizePackages(String repoName, PackageSyncReport report,
+ Collection<ContentProviderPackageDetails> existingPackages) throws Exception {
+ // No-op
+ }
+
+ public void initialize(Configuration configuration) throws Exception {
+ // No-op
+ }
+
+ public void shutdown() {
+ // No-op
+ }
+
+ public void testConnection() throws Exception {
+ // No-op
+ System.out.println("Connection tested.");
+ }
+
+ public InputStream getInputStream(String location) throws Exception {
+ // No-op
+ return null;
+ }
+}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentServerPluginService.java
index 3716282..485118b 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentServerPluginService.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/content/TestContentServerPluginService.java
@@ -18,30 +18,20 @@
*/
package org.rhq.enterprise.server.plugin.pc.content;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.rhq.core.domain.content.ContentSource;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainerConfiguration;
import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
-import org.rhq.enterprise.server.plugin.pc.content.ContentProvider;
-import org.rhq.enterprise.server.plugin.pc.content.ContentProviderManager;
-import org.rhq.enterprise.server.plugin.pc.content.ContentProviderPackageDetails;
-import org.rhq.enterprise.server.plugin.pc.content.ContentServerPluginContainer;
-import org.rhq.enterprise.server.plugin.pc.content.ContentServerPluginManager;
-import org.rhq.enterprise.server.plugin.pc.content.PackageSource;
-import org.rhq.enterprise.server.plugin.pc.content.PackageSyncReport;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -53,6 +43,24 @@ public class TestContentServerPluginService extends ServerPluginService implemen
public PackageSyncReport testLastSyncReport;
public Map<ContentSource, Collection<ContentProviderPackageDetails>> testExistingPackages;
public TestMasterServerPluginContainer master;
+ public TestContentProviderManager contentProviderManager;
+ public TestContentProvider testContentProvider;
+
+ // AbstractEJB3Test
+ public TestContentServerPluginService(AbstractEJB3Test testContainer) {
+ super();
+ testContentProvider = new TestContentProvider();
+ testContainer.prepareCustomServerPluginService(this);
+ this.startMasterPluginContainer();
+ }
+
+ public TestContentServerPluginService() {
+ super();
+ }
+
+ public TestContentProviderManager getContentProviderManager() {
+ return contentProviderManager;
+ }
@Override
protected MasterServerPluginContainer createMasterPluginContainer() {
@@ -96,8 +104,8 @@ public class TestContentServerPluginService extends ServerPluginService implemen
@Override
protected ContentProviderManager createAdapterManager() {
- TestContentProviderManager am = new TestContentProviderManager();
- return am;
+ contentProviderManager = new TestContentProviderManager();
+ return contentProviderManager;
}
@Override
@@ -119,69 +127,18 @@ public class TestContentServerPluginService extends ServerPluginService implemen
/**
* The test adapter manager.
*/
- class TestContentProviderManager extends ContentProviderManager {
- @Override
- public Set<ContentSource> getAllContentSources() {
- return (testAdapters != null) ? testAdapters.keySet() : new HashSet<ContentSource>();
- }
-
- @Override
- protected void initialize(ContentServerPluginManager pluginManager) {
- createInitialAdaptersMap();
- }
-
- @Override
- public void shutdown() {
- }
+ public class TestContentProviderManager extends ContentProviderManager {
- @Override
- public InputStream loadPackageBits(int contentSourceId, String location) throws Exception {
- if (testAdapters != null) {
- for (ContentSource cs : testAdapters.keySet()) {
- if (cs.getId() == contentSourceId) {
- PackageSource packageSource = (PackageSource) testAdapters.get(cs);
- return packageSource.getInputStream(location);
- }
- }
- }
-
- System.out.println("!!!!!!!!!!");
- System.out.println("STREAM: TEST DID NOT SETUP ADAPTER - EMPTY STREAM FOR [" + contentSourceId + "]");
- return new ByteArrayInputStream(new byte[0]);
+ public ContentProvider getIsolatedContentProvider(int contentProviderId) throws RuntimeException {
+ return testContentProvider;
}
- @Override
- public boolean synchronizeContentProvider(int contentSourceId) throws Exception {
- if (testAdapters != null) {
- for (ContentSource cs : testAdapters.keySet()) {
- if (cs.getId() == contentSourceId) {
- testLastSyncReport = new PackageSyncReport();
- PackageSource packageSource = (PackageSource) testAdapters.get(cs);
- packageSource.synchronizePackages(null, testLastSyncReport, testExistingPackages.get(cs));
- return true;
- }
- }
- }
-
- System.out.println("!!!!!!!!!!");
- System.out.println("SYNC: TEST DID NOT SETUP ADAPTER - NO-OP FOR [" + contentSourceId + "]");
- return true;
+ protected ContentProvider getIsolatedContentSourceAdapter(ContentSource contentSource) throws RuntimeException {
+ return testContentProvider;
}
- @Override
- public boolean testConnection(int contentSourceId) throws Exception {
- if (testAdapters != null) {
- for (ContentSource cs : testAdapters.keySet()) {
- if (cs.getId() == contentSourceId) {
- testAdapters.get(cs).testConnection();
- return true;
- }
- }
- }
-
- System.out.println("!!!!!!!!!!");
- System.out.println("CONN: TEST DID NOT SETUP ADAPTER - NO-OP FOR [" + contentSourceId + "]");
- return true;
+ protected ContentProvider instantiateAdapter(ContentSource contentSource) {
+ return testContentProvider;
}
}
}
\ No newline at end of file
14 years
[rhq] Branch 'raw-config' - 3 commits - modules/enterprise
by Adam Young
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java | 312 ++++++++
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java | 364 ----------
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegate.java | 100 --
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegateMap.java | 58 -
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDownload.java | 53 -
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigViewer.java | 69 -
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/configuration-beans.xml | 8
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit-raw.xhtml | 22
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit.xhtml | 4
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/view-raw.xhtml | 6
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java | 30
11 files changed, 332 insertions(+), 694 deletions(-)
New commits:
commit b28233475d75e80c01c217ac16e86c897ec262f1
Author: Adam Young <ayoung(a)redhat.com>
Date: Mon Nov 30 17:29:21 2009 -0500
Removed additional files that break the build
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java
index 8097b32..ef7d7df 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java
@@ -152,7 +152,7 @@ public class ExistingResourceConfigurationUIBean extends AbstractConfigurationUI
return configuration;
}
- private final Log log = LogFactory.getLog(RawConfigCollection.class);
+ private final Log log = LogFactory.getLog(AbstractConfigurationUIBean.class);
private Integer resourceId = null;
private static final long serialVersionUID = 4837157548556168146L;
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDownload.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDownload.java
deleted file mode 100644
index 7c4859d..0000000
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDownload.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.rhq.enterprise.gui.configuration.resource;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Logger;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.log.Log;
-
-@Name("rawConfigDownload")
-(a)Scope(ScopeType.PAGE)
-public class RawConfigDownload {
-
- @Logger
- private Log log;
-
- @In(value = "#{rawConfigCollection}")
- RawConfigCollection rawConfigCollection;
-
- @In(value = "#{facesContext}")
- FacesContext facesContext;
-
- @In(value = "#{facesContext.externalContext}")
- private ExternalContext extCtx;
-
- @Create
- public void init() {
- log.error("starting");
- }
-
- public String download() {
- HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
- response.setContentType("text/plain");
- response.addHeader("Content-disposition", "attachment; filename=\"testing.txt\"");
- try {
- ServletOutputStream os = response.getOutputStream();
- os.write(rawConfigCollection.getCurrent().getContents());
- os.flush();
- os.close();
- facesContext.responseComplete();
- } catch (Exception e) {
- log.error("\nFailure : " + e.toString() + "\n");
- }
-
- return null;
- }
-}
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigViewer.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigViewer.java
deleted file mode 100644
index d794c37..0000000
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigViewer.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.rhq.enterprise.gui.configuration.resource;
-
-import java.util.Iterator;
-import java.util.TreeMap;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
-
-@Name("RawConfigViewer")
-(a)Scope(ScopeType.SESSION)
-public class RawConfigViewer {
-
- RawConfigDelegate rawConfigDelegate;
-
- int getResourceId() {
- int resourceId = EnterpriseFacesContextUtility.getResource().getId();
- return resourceId;
- }
-
- public RawConfigDelegate getRawConfigDelegate() {
- if (null == rawConfigDelegate || (getResourceId() != rawConfigDelegate.resourceId)) {
- rawConfigDelegate = new RawConfigDelegate(getResourceId());
- }
- return rawConfigDelegate;
- }
-
- public TreeMap<String, RawConfiguration> getRaws() {
- return getRawConfigDelegate().getRaws();
- }
-
- public void setCurrentPath(String path) {
- RawConfiguration raw = getRaws().get(path);
- if (null != raw) {
- getRawConfigDelegate().current = raw;
- }
- }
-
- public String getCurrentContents() {
- return new String(getCurrent().getContents());
- }
-
- public Object[] getPaths() {
- return getRaws().keySet().toArray();
- }
-
- public void select(String s) {
- getRawConfigDelegate().selectedPath = s;
- setCurrentPath(getRawConfigDelegate().selectedPath);
- }
-
- public RawConfiguration getCurrent() {
- if (null == getRawConfigDelegate().current) {
- Iterator<RawConfiguration> iterator = getRaws().values().iterator();
- if (iterator.hasNext()) {
- getRawConfigDelegate().current = iterator.next();
- } else {
- getRawConfigDelegate().current = new RawConfiguration();
- getRawConfigDelegate().current.setPath("/dev/null");
- getRawConfigDelegate().current.setContents("".getBytes());
- }
- }
- return getRawConfigDelegate().current;
- }
-
-}
commit 66ca6b483d297a7f7dc6185f09525a66a6a76b85
Merge: 6da3b35... f013bcd...
Author: Adam Young <ayoung(a)redhat.com>
Date: Mon Nov 30 17:00:28 2009 -0500
Merge branch 'raw-config' of ssh://git.fedorahosted.org/git/rhq/rhq into raw-config
commit 6da3b35c0f05f6b959efe944dd2fc1a3a6d15b04
Author: Adam Young <ayoung(a)redhat.com>
Date: Mon Nov 30 17:00:01 2009 -0500
Merged Raw Config Collection Functionality into the class used for Structured, and dropped the ability to maintain multiple edits going at once.
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java
index 846b867..8097b32 100644
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java
+++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/ExistingResourceConfigurationUIBean.java
@@ -18,18 +18,29 @@
*/
package org.rhq.enterprise.gui.configuration.resource;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.TreeMap;
+
import javax.faces.application.FacesMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.Nullable;
+import org.richfaces.event.UploadEvent;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Create;
+import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.AbstractResourceConfigurationUpdate;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.RawConfiguration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
import org.rhq.core.gui.configuration.ConfigurationMaskingUtility;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.enterprise.gui.configuration.AbstractConfigurationUIBean;
@@ -40,8 +51,8 @@ import org.rhq.enterprise.server.util.LookupUtil;
/**
* @author Ian Springer
*/
-@Name(value = "ExistingResourceConfigurationUIBean")
-(a)Scope(ScopeType.PAGE)
+//@ Name(value = "ExistingResourceConfigurationUIBean")
+//@ Scope(ScopeType.PAGE)
public class ExistingResourceConfigurationUIBean extends AbstractConfigurationUIBean {
public static final String MANAGED_BEAN_NAME = "ExistingResourceConfigurationUIBean";
@@ -129,8 +140,6 @@ public class ExistingResourceConfigurationUIBean extends AbstractConfigurationUI
@Nullable
protected Configuration lookupConfiguration() {
-
- /*
Subject subject = EnterpriseFacesContextUtility.getSubject();
int resourceId = EnterpriseFacesContextUtility.getResource().getId();
AbstractResourceConfigurationUpdate configurationUpdate = this.configurationManager
@@ -141,21 +150,292 @@ public class ExistingResourceConfigurationUIBean extends AbstractConfigurationUI
}
return configuration;
- */
+ }
+
+ private final Log log = LogFactory.getLog(RawConfigCollection.class);
+ private Integer resourceId = null;
+
+ private static final long serialVersionUID = 4837157548556168146L;
+
+ public String commit() {
+
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ LookupUtil.getConfigurationManager().updateResourceConfiguration(subject, getResourceId(),
+ getMergedConfiguration());
+
+ nullify();
+
+ return "/rhq/resource/configuration/view.xhtml?id=" + getResourceId();
+ }
+
+ private Configuration getMergedConfiguration() {
+ for (RawConfiguration raw : getModified().values()) {
+ getRaws().put(raw.getPath(), raw);
+ log.error("Just merged in raw path =[" + raw.getPath() + "]");
+ log.error(" file =[" + new String(raw.getContents()) + "]");
+
+ }
+ getConfiguration().getRawConfigurations().clear();
+ getConfiguration().getRawConfigurations().addAll(getRaws().values());
+ return getConfiguration();
+ }
+
+ public String discard() {
+ nullify();
+ return "/rhq/resource/configuration/view.xhtml?id=" + getResourceId();
+ }
+
+ public void fileUploadListener(UploadEvent event) throws Exception {
+ File uploadFile;
+ log.error("fileUploadListener called");
+ uploadFile = event.getUploadItem().getFile();
+ if (uploadFile != null) {
+ log.debug("fileUploadListener got file named " + event.getUploadItem().getFileName());
+ log.debug("content type is " + event.getUploadItem().getContentType());
+ if (uploadFile != null) {
+ try {
+ FileReader fileReader = new FileReader(uploadFile);
+ char[] buff = new char[1024];
+ StringBuffer stringBuffer = new StringBuffer();
+ for (int count = fileReader.read(buff); count != -1; count = fileReader.read(buff)) {
+ stringBuffer.append(buff, 0, count);
+ }
+ setCurrentContents(stringBuffer.toString());
+ } catch (IOException e) {
+ log.error("problem reading uploaded file", e);
+ }
+ }
+ }
+ }
+
+ public int getConfigId() {
+ return getConfiguration().getId();
+ }
+
+ /*
+ public Configuration getConfiguration() {
+ if (null == configuration) {
+
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ int resourceId = EnterpriseFacesContextUtility.getResource().getId();
+ AbstractResourceConfigurationUpdate configurationUpdate = LookupUtil.getConfigurationManager()
+ .getLatestResourceConfigurationUpdate(subject, resourceId);
+ Configuration configuration = (configurationUpdate != null) ? configurationUpdate.getConfiguration() : null;
+ if (configuration != null) {
+ //ConfigurationMaskingUtility.maskConfiguration(configuration, getConfigurationDefinition());
+ }
+
+ return configuration;
+
+ }
+ return configuration;
+
+ }
+ */
+
+ private ConfigurationFormat getConfigurationFormat() {
+ return getConfigurationDefinition().getConfigurationFormat();
+ }
+
+ public RawConfiguration getCurrent() {
+ if (null == current) {
+ Iterator<RawConfiguration> iterator = getRaws().values().iterator();
+ if (iterator.hasNext()) {
+ current = iterator.next();
+ } else {
+ current = new RawConfiguration();
+ current.setPath("/dev/null");
+ current.setContents("".getBytes());
+ }
+ }
+ return current;
+ }
+
+ public String getCurrentContents() {
+ return new String(getCurrent().getContents());
+ }
+
+ public String getCurrentPath() {
+ return getCurrent().getPath();
+ }
+
+ public TreeMap<String, RawConfiguration> getModified() {
+ if (modified == null) {
+ modified = new TreeMap<String, RawConfiguration>();
+ }
+ return modified;
+ }
+
+ public Object[] getPaths() {
+ return getRaws().keySet().toArray();
+ }
+
+ /**
+ *
+ * @return the id associated with the resource.
+ * The value Cached in order to be available on the upload page,
+ * where seeing the resource id conflicts with the rich upload tag.
+ */
+ public int getResourceId() {
+ if (resourceId == null) {
+ resourceId = EnterpriseFacesContextUtility.getResource().getId();
+ }
+ return resourceId;
+ }
+
+ /**
+ * Hack Alert. This bean needs to be initialized on one of the pages that has id or resourceId set
+ * In order to capture the resource. It will then Keep track of that particular resources until
+ * commit is called. Ideally, this should be a conversation scoped bean, but that has other issues
+ *
+ */
+ @Create
+ public void init() {
- return getRawConfigCollection().getConfiguration();
+ }
+
+ public boolean isModified(String path) {
+ return getModified().keySet().contains(path);
+ }
+
+ public boolean isRawSupported() {
+ return getConfigurationFormat().isRawSupported();
+ }
+
+ public boolean isStructuredSupported() {
+ return getConfigurationFormat().isStructuredSupported();
+ }
+
+ void nullify() {
+
+ }
+
+ /**
+ * Indicates which of the raw configuration files is currently selected.
+ * @param s
+ */
+ public void select(String s) {
+ selectedPath = s;
+ setCurrentPath(selectedPath);
+ }
+
+ public void setCurrentContents(String updated) {
+
+ String original = new String(getCurrent().getContents());
+ if (!updated.equals(original)) {
+ current = current.deepCopy(false);
+ current.setContents(updated.getBytes());
+ //TODO update other values like MD5
+ getModified().put(current.getPath(), current);
+ }
+ }
+
+ public void setCurrentPath(String path) {
+ RawConfiguration raw = getModified().get(path);
+ if (null == raw) {
+ raw = getRaws().get(path);
+ }
+ if (null != raw) {
+ current = raw;
+ }
+ }
+
+ public void setModified(RawConfiguration raw) {
+ getModified().put(raw.getPath(), raw);
+ }
+
+ /**
+ * This is a no-op, since the upload work was done by upload file
+ * But is kept as a target for the "save" icon from the full screen page
+ */
+ public String update() {
+ return "/rhq/resource/configuration/edit-raw.xhtml?currentResourceId=" + getResourceId();
+ }
+ /**
+ * This is a no-op, since the upload work was done by upload file
+ * But is kept as a target for the "action" value
+ */
+ public String upload() {
+ return "/rhq/resource/configuration/edit-raw.xhtml?currentResourceId=" + getResourceId();
}
- @In(create = true, required = true, value = "rawConfigCollection")
- RawConfigCollection rawConfigCollection;
+ public String switchToraw() {
+ log.error("switch2raw called");
+ dumpProperties(getConfiguration(), log);
+ Configuration configuration = LookupUtil.getConfigurationManager().translateResourceConfiguration(
+ EnterpriseFacesContextUtility.getSubject(), getResourceId(), getMergedConfiguration(), true);
+ log.error("switch2raw post merge");
+ dumpProperties(getConfiguration(), log);
- public RawConfigCollection getRawConfigCollection() {
- return rawConfigCollection;
+ setConfiguration(configuration);
+ for (RawConfiguration raw : configuration.getRawConfigurations()) {
+ getRaws().put(raw.getPath(), raw);
+ }
+ current = null;
+ setConfiguration(configuration);
+
+ return "/rhq/resource/configuration/edit-raw.xhtml?currentResourceId=" + getResourceId();
+ }
+
+ void dumpProperties(Configuration conf, Log log) {
+ for (String key : conf.getAllProperties().keySet()) {
+ log.error("property=" + conf.getAllProperties().get(key));
+ }
+ }
+
+ public String switchTostructured() {
+ log.error("switch2structured called");
+
+ dumpProperties(getConfiguration(), log);
+ Configuration configuration = LookupUtil.getConfigurationManager().translateResourceConfiguration(
+ EnterpriseFacesContextUtility.getSubject(), getResourceId(), getMergedConfiguration(), false);
+ log.error("switch2structured post merge");
+
+ dumpProperties(configuration, log);
+
+ for (Property property : configuration.getAllProperties().values()) {
+ property.setConfiguration(configuration);
+ }
+
+ for (RawConfiguration raw : configuration.getRawConfigurations()) {
+ getRaws().put(raw.getPath(), raw);
+ setConfiguration(configuration);
+ }
+ current = null;
+ setConfiguration(configuration);
+
+ return "/rhq/resource/configuration/edit.xhtml?currentResourceId=" + getResourceId();
+ }
+
+ void populateRaws() {
+ Collection<RawConfiguration> rawConfigurations = getConfiguration().getRawConfigurations();
+
+ for (RawConfiguration raw : rawConfigurations) {
+ raws.put(raw.getPath(), raw);
+ }
}
- public void setRawConfigCollection(RawConfigCollection rawConfigCollection) {
- this.rawConfigCollection = rawConfigCollection;
+ public void setRaws(TreeMap<String, RawConfiguration> raws) {
+ this.raws = raws;
}
+ public TreeMap<String, RawConfiguration> getRaws() {
+
+ if (null == raws) {
+ raws = new TreeMap<String, RawConfiguration>();
+ populateRaws();
+ }
+
+ return raws;
+ }
+
+ /**
+ *
+ */
+ String selectedPath;
+ private TreeMap<String, RawConfiguration> raws;
+ TreeMap<String, RawConfiguration> modified = new TreeMap<String, RawConfiguration>();
+ RawConfiguration current = null;
+
}
\ No newline at end of file
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
deleted file mode 100644
index 29dbe4b..0000000
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigCollection.java
+++ /dev/null
@@ -1,364 +0,0 @@
-package org.rhq.enterprise.gui.configuration.resource;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.TreeMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.richfaces.event.UploadEvent;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.End;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-
-import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
-import org.rhq.enterprise.gui.configuration.AbstractConfigurationUIBean;
-import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
-import org.rhq.enterprise.server.util.LookupUtil;
-
-@Name("rawConfigCollection")
-(a)Scope(ScopeType.PAGE)
-/**
- * The backing class for all Web based activities for manipulating the set of
- * raw configuration files associated with a resource
- */
-public class RawConfigCollection extends AbstractConfigurationUIBean implements Serializable {
-
- private RawConfigDelegate rawConfigDelegate = null;
- private RawConfigDelegateMap rawConfigDelegateMap;
-
- /*This is for development, to prevent actually going to the EJBs.
- TODO It should be set to false prior to check in*/
- private static final boolean useMock = false;
-
- private final Log log = LogFactory.getLog(RawConfigCollection.class);
- private Integer resourceId = null;
-
- private static final long serialVersionUID = 4837157548556168146L;
-
- public RawConfigCollection() {
- }
-
- @End
- public String commit() {
-
- Subject subject = EnterpriseFacesContextUtility.getSubject();
- LookupUtil.getConfigurationManager().updateResourceConfiguration(subject, getResourceId(),
- getMergedConfiguration());
-
- nullify();
-
- return "/rhq/resource/configuration/view.xhtml?id=" + getResourceId();
- }
-
- private Configuration getMergedConfiguration() {
- for (RawConfiguration raw : getRawConfigDelegate().modified.values()) {
- getRaws().put(raw.getPath(), raw);
- log.error("Just merged in raw path =[" + raw.getPath() + "]");
- log.error(" file =[" + new String(raw.getContents()) + "]");
-
- }
- getConfiguration().getRawConfigurations().clear();
- getConfiguration().getRawConfigurations().addAll(getRaws().values());
- return getConfiguration();
- }
-
- public String discard() {
- nullify();
- return "/rhq/resource/configuration/view.xhtml?id=" + getResourceId();
- }
-
- public void fileUploadListener(UploadEvent event) throws Exception {
- File uploadFile;
- log.error("fileUploadListener called");
- uploadFile = event.getUploadItem().getFile();
- if (uploadFile != null) {
- log.debug("fileUploadListener got file named " + event.getUploadItem().getFileName());
- log.debug("content type is " + event.getUploadItem().getContentType());
- if (uploadFile != null) {
- try {
- FileReader fileReader = new FileReader(uploadFile);
- char[] buff = new char[1024];
- StringBuffer stringBuffer = new StringBuffer();
- for (int count = fileReader.read(buff); count != -1; count = fileReader.read(buff)) {
- stringBuffer.append(buff, 0, count);
- }
- setCurrentContents(stringBuffer.toString());
- } catch (IOException e) {
- log.error("problem reading uploaded file", e);
- }
- }
- }
- }
-
- public int getConfigId() {
- return getConfiguration().getId();
- }
-
- public Configuration getConfiguration() {
- return getRawConfigDelegate().getConfiguration();
- }
-
- //TODO Sync this up with the baseclass
- public ConfigurationDefinition getConfigurationDefinition() {
- if (null == getRawConfigDelegate().configurationDefinition) {
-
- getRawConfigDelegate().configurationDefinition = LookupUtil.getConfigurationManager()
- .getResourceConfigurationDefinitionForResourceType(EnterpriseFacesContextUtility.getSubject(),
- EnterpriseFacesContextUtility.getResource().getResourceType().getId());
- }
- return getRawConfigDelegate().configurationDefinition;
- }
-
- private ConfigurationFormat getConfigurationFormat() {
- if (useMock)
- return ConfigurationFormat.STRUCTURED_AND_RAW;
- return getConfigurationDefinition().getConfigurationFormat();
- }
-
- public RawConfiguration getCurrent() {
- if (null == getRawConfigDelegate().current) {
- Iterator<RawConfiguration> iterator = getRaws().values().iterator();
- if (iterator.hasNext()) {
- getRawConfigDelegate().current = iterator.next();
- } else {
- getRawConfigDelegate().current = new RawConfiguration();
- getRawConfigDelegate().current.setPath("/dev/null");
- getRawConfigDelegate().current.setContents("".getBytes());
- }
- }
- return getRawConfigDelegate().current;
- }
-
- public String getCurrentContents() {
- return new String(getCurrent().getContents());
- }
-
- public String getCurrentPath() {
- return getCurrent().getPath();
- }
-
- private RawConfigDelegateMap getDelegates() {
- return rawConfigDelegateMap;
- }
-
- public TreeMap<String, RawConfiguration> getModified() {
- if (getRawConfigDelegate().modified == null) {
- getRawConfigDelegate().modified = new TreeMap<String, RawConfiguration>();
- }
- return getRawConfigDelegate().modified;
- }
-
- public Object[] getPaths() {
- return getRaws().keySet().toArray();
- }
-
- RawConfigDelegate getRawConfigDelegate() {
- if (null == rawConfigDelegate) {
- rawConfigDelegate = getDelegates().get(getResourceId());
- if (null == rawConfigDelegate) {
- rawConfigDelegate = new RawConfigDelegate(getResourceId());
- getDelegates().put(getResourceId(), rawConfigDelegate);
- }
- }
- return rawConfigDelegate;
- }
-
- public RawConfigDelegateMap getRawConfigDelegateMap() {
- return rawConfigDelegateMap;
- }
-
- public TreeMap<String, RawConfiguration> getRaws() {
- return getRawConfigDelegate().getRaws();
- }
-
- /**
- *
- * @return the id associated with the resource.
- * The value Cached in order to be available on the upload page,
- * where seeing the resource id conflicts with the rich upload tag.
- */
- public int getResourceId() {
- if (resourceId == null) {
- resourceId = EnterpriseFacesContextUtility.getResource().getId();
- }
- return resourceId;
- }
-
- /**
- * Hack Alert. This bean needs to be initialized on one of the pages that has id or resourceId set
- * In order to capture the resource. It will then Keep track of that particular resources until
- * commit is called. Ideally, this should be a conversation scoped bean, but that has other issues
- *
- */
- @Create
- public void init() {
-
- }
-
- public boolean isModified(String path) {
- return getModified().keySet().contains(path);
- }
-
- public boolean isRawSupported() {
- return getConfigurationFormat().isRawSupported();
- }
-
- public boolean isStructuredSupported() {
- return getConfigurationFormat().isStructuredSupported();
- }
-
- void nullify() {
- getDelegates().remove(getResourceId());
- setRawConfigDelegate(null);
- }
-
- /**
- * Indicates which of the raw configuration files is currently selected.
- * @param s
- */
- public void select(String s) {
- getRawConfigDelegate().selectedPath = s;
- setCurrentPath(getRawConfigDelegate().selectedPath);
- }
-
- public void setCurrentContents(String updated) {
-
- String original = new String(getCurrent().getContents());
- if (!updated.equals(original)) {
- getRawConfigDelegate().current = getRawConfigDelegate().current.deepCopy(false);
- getRawConfigDelegate().current.setContents(updated.getBytes());
- //TODO update other values like MD5
- getModified().put(getRawConfigDelegate().current.getPath(), getRawConfigDelegate().current);
- }
- }
-
- public void setCurrentPath(String path) {
- RawConfiguration raw = getModified().get(path);
- if (null == raw) {
- raw = getRaws().get(path);
- }
- if (null != raw) {
- getRawConfigDelegate().current = raw;
- }
- }
-
- void setDelegates(RawConfigDelegateMap delegates) {
- this.rawConfigDelegateMap = delegates;
- }
-
- public void setModified(RawConfiguration raw) {
- getRawConfigDelegate().modified.put(raw.getPath(), raw);
- }
-
- void setRawConfigDelegate(RawConfigDelegate rawConfigDelegate) {
- this.rawConfigDelegate = rawConfigDelegate;
- }
-
- @In(create = true, required = true)
- public void setRawConfigDelegateMap(RawConfigDelegateMap rawConfigDelegateMap) {
- this.rawConfigDelegateMap = rawConfigDelegateMap;
- }
-
- /**
- * This is a no-op, since the upload work was done by upload file
- * But is kept as a target for the "save" icon from the full screen page
- */
- public String update() {
- return "/rhq/resource/configuration/edit-raw.xhtml?currentResourceId=" + getResourceId();
- }
-
- /**
- * This is a no-op, since the upload work was done by upload file
- * But is kept as a target for the "action" value
- */
- public String upload() {
- return "/rhq/resource/configuration/edit-raw.xhtml?currentResourceId=" + getResourceId();
- }
-
- public String switchToraw() {
- log.error("switch2raw called");
- dumpProperties(getConfiguration(), log);
- Configuration configuration = LookupUtil.getConfigurationManager().translateResourceConfiguration(
- EnterpriseFacesContextUtility.getSubject(), getResourceId(), getMergedConfiguration(), true);
- log.error("switch2raw post merge");
- dumpProperties(getConfiguration(), log);
-
- getRawConfigDelegate().setConfiguration(configuration);
- for (RawConfiguration raw : configuration.getRawConfigurations()) {
- getRawConfigDelegate().getRaws().put(raw.getPath(), raw);
- }
- getRawConfigDelegate().current = null;
- getRawConfigDelegate().setConfiguration(configuration);
- getRawConfigDelegateMap().put(getResourceId(), getRawConfigDelegate());
-
- return "/rhq/resource/configuration/edit-raw.xhtml?currentResourceId=" + getResourceId();
- }
-
- void dumpProperties(Configuration conf, Log log) {
- for (String key : conf.getAllProperties().keySet()) {
- log.error("property=" + conf.getAllProperties().get(key));
- }
- }
-
- public String switchTostructured() {
- log.error("switch2structured called");
-
- dumpProperties(getConfiguration(), log);
- Configuration configuration = LookupUtil.getConfigurationManager().translateResourceConfiguration(
- EnterpriseFacesContextUtility.getSubject(), getResourceId(), getMergedConfiguration(), false);
- log.error("switch2structured post merge");
-
- dumpProperties(configuration, log);
-
- for (Property property : configuration.getAllProperties().values()) {
- property.setConfiguration(configuration);
- }
-
- for (RawConfiguration raw : configuration.getRawConfigurations()) {
- getRawConfigDelegate().getRaws().put(raw.getPath(), raw);
- getRawConfigDelegate().setConfiguration(configuration);
- }
- getRawConfigDelegate().current = null;
- getRawConfigDelegate().setConfiguration(configuration);
-
- return "/rhq/resource/configuration/edit.xhtml?currentResourceId=" + getResourceId();
- }
-
- @Override
- protected int getConfigurationDefinitionKey() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- protected int getConfigurationKey() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- protected Configuration lookupConfiguration() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected ConfigurationDefinition lookupConfigurationDefinition() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegate.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegate.java
deleted file mode 100644
index d049f35..0000000
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegate.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.configuration.resource;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.TreeMap;
-
-import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.configuration.AbstractResourceConfigurationUpdate;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
-import org.rhq.enterprise.server.util.LookupUtil;
-
-public class RawConfigDelegate implements Serializable {
-
- void populateRaws() {
- Collection<RawConfiguration> rawConfigurations = LookupUtil.getConfigurationManager()
- .getLatestResourceConfigurationUpdate(EnterpriseFacesContextUtility.getSubject(), resourceId)
- .getConfiguration().getRawConfigurations();
-
- for (RawConfiguration raw : rawConfigurations) {
- raws.put(raw.getPath(), raw);
- }
- }
-
- public RawConfigDelegate(int resourceId) {
- super();
- this.resourceId = resourceId;
- }
-
- public void setRaws(TreeMap<String, RawConfiguration> raws) {
- this.raws = raws;
- }
-
- public TreeMap<String, RawConfiguration> getRaws() {
-
- if (null == raws) {
- raws = new TreeMap<String, RawConfiguration>();
- populateRaws();
- }
-
- return raws;
- }
-
- public void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- }
-
- public Configuration getConfiguration() {
- if (null == configuration) {
-
- Subject subject = EnterpriseFacesContextUtility.getSubject();
- int resourceId = EnterpriseFacesContextUtility.getResource().getId();
- AbstractResourceConfigurationUpdate configurationUpdate = LookupUtil.getConfigurationManager()
- .getLatestResourceConfigurationUpdate(subject, resourceId);
- Configuration configuration = (configurationUpdate != null) ? configurationUpdate.getConfiguration() : null;
- if (configuration != null) {
- //ConfigurationMaskingUtility.maskConfiguration(configuration, getConfigurationDefinition());
- }
-
- return configuration;
-
- }
- return configuration;
- }
-
- /**
- *
- */
- private static final long serialVersionUID = -9058700205958371765L;
-
- int resourceId = 0;
- String selectedPath;
- private TreeMap<String, RawConfiguration> raws;
- TreeMap<String, RawConfiguration> modified = new TreeMap<String, RawConfiguration>();
- RawConfiguration current = null;
- ConfigurationDefinition configurationDefinition = null;
- private Configuration configuration;
-
-}
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegateMap.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegateMap.java
deleted file mode 100644
index 44b79b7..0000000
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/resource/RawConfigDelegateMap.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.configuration.resource;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-
-@Name("rawConfigDelegateMap")
-(a)Scope(ScopeType.SESSION)
-public class RawConfigDelegateMap extends HashMap<Integer, RawConfigDelegate> {
-
- /**
- *
- */
- private static final long serialVersionUID = 941352750819758987L;
-
- public RawConfigDelegateMap() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- public RawConfigDelegateMap(int initialCapacity, float loadFactor) {
- super(initialCapacity, loadFactor);
- // TODO Auto-generated constructor stub
- }
-
- public RawConfigDelegateMap(int initialCapacity) {
- super(initialCapacity);
- // TODO Auto-generated constructor stub
- }
-
- public RawConfigDelegateMap(Map<? extends Integer, ? extends RawConfigDelegate> m) {
- super(m);
- // TODO Auto-generated constructor stub
- }
-
-}
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/configuration-beans.xml b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/configuration-beans.xml
index de0dace..70d3f99 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/configuration-beans.xml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/configuration-beans.xml
@@ -4,19 +4,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
- <!-- /rhq/resource/configuration/view.xhtml, /rhq/resource/configuration/view-map.xhtml
+ <!-- /rhq/resource/configuration/view.xhtml, /rhq/resource/configuration/view-map.xhtml -->
<managed-bean>
<managed-bean-name>ExistingResourceConfigurationViewUIBean</managed-bean-name>
<managed-bean-class>org.rhq.enterprise.gui.configuration.resource.ExistingResourceConfigurationUIBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
- </managed-bean> -->
+ </managed-bean>
<!-- /rhq/resource/configuration/history.xhtml, /rhq/resource/configuration/edit.xhtml, and
- /rhq/resource/configuration/edit-map.xhtml
+ /rhq/resource/configuration/edit-map.xhtml -->
<managed-bean>
<managed-bean-name>ExistingResourceConfigurationUIBean</managed-bean-name>
<managed-bean-class>org.rhq.enterprise.gui.configuration.resource.ExistingResourceConfigurationUIBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
- </managed-bean> -->
+ </managed-bean>
<!-- /rhq/resource/configuration/add-new-simple.xhtml -->
<managed-bean>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit-raw.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit-raw.xhtml
index 4bbb24f..060dfc4 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit-raw.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit-raw.xhtml
@@ -35,9 +35,9 @@
<a4j:form id="editResourceConfigurationForm">
<h:outputText value="#{messages.youareviewingraw}" />
- <h:panelGroup rendered="#{rawConfigCollection.structuredSupported}">
+ <h:panelGroup rendered="#{ExistingResourceConfigurationUIBean.structuredSupported}">
<h:outputText value=" #{messages.switch2}" />
- <h:commandLink action="#{rawConfigCollection.switchTostructured}">
+ <h:commandLink action="#{ExistingResourceConfigurationUIBean.switchTostructured}">
<s:conversationId />
<f:param name="id" value="#{ResourceUIBean.id}" />
<h:outputText value=" #{messages.structured}" />
@@ -53,23 +53,23 @@
<h:panelGroup
id="changedFiles" layout="vertical">
- <ui:repeat value="#{rawConfigCollection.paths}" var="path">
+ <ui:repeat value="#{ExistingResourceConfigurationUIBean.paths}" var="path">
<div><h:outputText value="*"
- rendered="#{rawConfigCollection.isModified(path) }" /> <h:commandLink
- value="#{path}" action="#{rawConfigCollection.select(path)}"
- rendered="#{path != rawConfigCollection.current.path}">
+ rendered="#{ExistingResourceConfigurationUIBean.isModified(path) }" /> <h:commandLink
+ value="#{path}" action="#{ExistingResourceConfigurationUIBean.select(path)}"
+ rendered="#{path != ExistingResourceConfigurationUIBean.current.path}">
<f:param name="currentPath" value="#{path}" />
</h:commandLink> <h:outputText value="#{path}"
- rendered="#{path == rawConfigCollection.current.path}" /></div>
+ rendered="#{path == ExistingResourceConfigurationUIBean.current.path}" /></div>
</ui:repeat>
</h:panelGroup>
<div>______________________________________</div>
<div>* <h:outputText value="#{messages.uncommitted}" /></div>
<h:panelGrid columns="2" styleClass="buttons-table" columnClasses="button-cell">
- <a4j:commandButton action="#{rawConfigCollection.commit}"
+ <a4j:commandButton action="#{ExistingResourceConfigurationUIBean.commit}"
value="#{messages.commit}" reRender="changedFiles" styleClass="buttonmed"/>
<a4j:commandButton
- action="#{rawConfigCollection.discard}" value="#{messages.discard}"
+ action="#{ExistingResourceConfigurationUIBean.discard}" value="#{messages.discard}"
reRender="changedFiles" styleClass="buttonmed"/>
</h:panelGrid>
</td>
@@ -77,7 +77,7 @@
<div>
<h:outputText value="#{messages.currentfile}" />
: <h:outputText
- value="#{rawConfigCollection.current.path}" styleClass="outhello" />
+ value="#{ExistingResourceConfigurationUIBean.current.path}" styleClass="outhello" />
</div>
<h:outputLink value="edit-raw-full.xhtml" action="navigateToFullScreen">
<img src="/images/viewfullscreen.png" />
@@ -96,7 +96,7 @@
</s:link>
<div><h:inputTextarea cols="80" rows="40"
- value="#{rawConfigCollection.currentContents}" /></div>
+ value="#{ExistingResourceConfigurationUIBean.currentContents}" /></div>
</td>
</tr>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit.xhtml
index b28ade4..d067d8a 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/edit.xhtml
@@ -30,9 +30,9 @@ THIS TEXT WILL BE REMOVED.
<h:outputText value="#{messages.youareviewingstructured}" />
- <h:panelGroup rendered="#{rawConfigCollection.rawSupported}" >
+ <h:panelGroup rendered="#{ExistingResourceConfigurationUIBean.rawSupported}" >
<h:outputText value=" #{messages.switch2}" />
- <h:commandLink action="#{rawConfigCollection.switchToraw}" >
+ <h:commandLink action="#{ExistingResourceConfigurationUIBean.switchToraw}" >
<f:param name="conversationId" value="#{conversation.id}"/>
<f:param name="id" value="#{ResourceUIBean.id}"/>
<h:outputText value=" files mode"/>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/view-raw.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/view-raw.xhtml
index 65ac139..b0b3002 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/view-raw.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/configuration/view-raw.xhtml
@@ -34,7 +34,7 @@
</script>
<h:outputText value="#{messages.youareviewingraw}" />
- <h:panelGroup rendered="#{rawConfigCollection.structuredSupported}">
+ <h:panelGroup rendered="#{ExistingResourceConfigurationViewUIBean.structuredSupported}">
<h:outputText value=" #{messages.switch2}" />
<h:outputLink value="view.xhtml">
<s:conversationId />
@@ -53,10 +53,10 @@
<h:commandButton value="#{messages.editstructured}" action="#{ExistingResourceConfigurationUIBean.editConfiguration}"
title="Edit this Configuration" styleClass="buttonmed"
- rendered="${ResourceUIBean.permissions.configure and rawConfigCollection.structuredSupported and !ExistingResourceConfigurationUIBean.updateInProgress}" />
+ rendered="${ResourceUIBean.permissions.configure and ExistingResourceConfigurationViewUIBean.structuredSupported and !ExistingResourceConfigurationUIBean.updateInProgress}" />
<h:commandButton value="#{messages.editraw}" action="#{ExistingResourceConfigurationUIBean.editRawConfiguration}"
title="Advanced Mode Edit of Raw Configuration Files" styleClass="buttonmed"
- rendered="${ResourceUIBean.permissions.configure and rawConfigCollection.rawSupported and !ExistingResourceConfigurationUIBean.updateInProgress}" />
+ rendered="${ResourceUIBean.permissions.configure and ExistingResourceConfigurationViewUIBean.rawSupported and !ExistingResourceConfigurationUIBean.updateInProgress}" />
</h:panelGrid>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
index 36f35c0..caecff7 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
@@ -20,12 +20,12 @@ package org.rhq.enterprise.server.configuration;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Collections;
-import java.util.Collection;
import javax.ejb.EJB;
import javax.ejb.Stateless;
@@ -48,9 +48,9 @@ import org.quartz.JobDetail;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
-import org.rhq.core.clientapi.agent.configuration.ConfigurationUpdateRequest;
-import org.rhq.core.clientapi.agent.configuration.ConfigurationAgentService;
import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.clientapi.agent.configuration.ConfigurationAgentService;
+import org.rhq.core.clientapi.agent.configuration.ConfigurationUpdateRequest;
import org.rhq.core.clientapi.server.configuration.ConfigurationUpdateResponse;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
@@ -59,8 +59,8 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
import org.rhq.core.domain.configuration.PluginConfigurationUpdate;
import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.ResourceConfigurationUpdate;
import org.rhq.core.domain.configuration.RawConfiguration;
+import org.rhq.core.domain.configuration.ResourceConfigurationUpdate;
import org.rhq.core.domain.configuration.composite.ConfigurationUpdateComposite;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.group.AbstractGroupConfigurationUpdate;
@@ -702,7 +702,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
}
public Configuration getLiveResourceConfiguration(Subject subject, int resourceId, boolean pingAgentFirst,
- boolean fromStructured) throws Exception {
+ boolean fromStructured) throws Exception {
Resource resource = entityManager.find(Resource.class, resourceId);
if (resource == null) {
@@ -980,6 +980,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
return;
}
+ private void dumpProperties(Configuration configuration) {
+ for (String key : configuration.getAllProperties().keySet()) {
+ log.error("key = ");
+ }
+ }
+
@Nullable
public ResourceConfigurationUpdate updateResourceConfiguration(Subject subject, int resourceId,
@XmlJavaTypeAdapter(ConfigurationAdapter.class) Configuration newConfiguration)
@@ -988,7 +994,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
// (consider synchronizing to avoid the condition where someone calls this method twice quickly
// in two different txs which would put two updates in INPROGRESS and cause havoc)
ResourceConfigurationUpdate newUpdate;
-
+ dumpProperties(newConfiguration);
// here we call ourself, but we do so via the EJB interface so we pick up the REQUIRES_NEW semantics
// this can return null if newConfiguration is not actually different.
newUpdate = configurationManager.persistNewResourceConfigurationUpdateHistory(subject, resourceId,
@@ -1321,8 +1327,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
*
* @return the resource's live configuration or <code>null</code> if it could not be retrieved from the agent
*/
- private Configuration getLiveResourceConfiguration(Resource resource, boolean pingAgentFirst,
- boolean fromStructured) {
+ private Configuration getLiveResourceConfiguration(Resource resource, boolean pingAgentFirst, boolean fromStructured) {
Configuration liveConfig = null;
try {
@@ -1355,8 +1360,6 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
return liveConfig;
}
-
-
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public AbstractResourceConfigurationUpdate mergeConfigurationUpdate(
AbstractResourceConfigurationUpdate configurationUpdate) {
@@ -1900,11 +1903,10 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
ConfigurationAgentService configService = agentClient.getConfigurationAgentService();
return configService.merge(configuration, resourceId, fromStructured);
- }
- catch (PluginContainerException e) {
+ } catch (PluginContainerException e) {
log.error("An error occurred while trying to translate the configuration.", e);
return null;
}
}
-
+
}
14 years
[rhq] Branch 'pc' - 2 commits - modules/enterprise
by jharris
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java | 3
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java | 142 ----------
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml | 11
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 | 46 ---
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml | 2
7 files changed, 12 insertions(+), 244 deletions(-)
New commits:
commit 4fc48faeb13369a38ac1b602237672bd60038865
Author: Justin Harris <jharris(a)redhat.com>
Date: Mon Nov 30 17:30:10 2009 -0500
Pulling out old admin navigation rules.
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 37b3bad..93932df 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,17 +28,6 @@
</navigation-case>
</navigation-rule>
-
- <navigation-rule>
- <from-view-id>/rhq/admin/plugin/plugin-details-edit.xhtml</from-view-id>
-
- <navigation-case>
- <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>
-
- </navigation-rule>
<navigation-rule>
<navigation-case>
commit 591b1f7c41600eeed97f5e307fb426fc1904cc69
Author: Justin Harris <jharris(a)redhat.com>
Date: Mon Nov 30 16:22:06 2009 -0500
Cleaning out editing of server plugins on details page.
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 a1400ac..43e9e41 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
@@ -18,7 +18,6 @@
*/
package org.rhq.enterprise.gui.admin.plugin;
-import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.web.RequestParameter;
@@ -71,7 +70,7 @@ public class InstalledPluginComponent {
this.pluginType = pluginType;
}
- @Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
+ @Factory(value = "plugin", autoCreate = true)
public AbstractPlugin lookupPlugin() {
if (this.deployment == PluginDeploymentType.AGENT) {
return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
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
deleted file mode 100644
index 9351385..0000000
--- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License 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 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.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;
-import org.rhq.enterprise.server.authz.PermissionException;
-import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
-import org.rhq.enterprise.server.util.LookupUtil;
-import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
-
-/**
- * @author Greg Hinkle
- * @author John Mazzitelli
- */
-(a)Scope(ScopeType.PAGE)
-@Name("InstalledPluginUIBean")
-public class InstalledPluginUIBean {
-
- 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
- private AbstractPlugin plugin;
- private ConfigurationDefinition pluginConfigurationDefinition;
- private ConfigurationDefinition scheduledJobsDefinition;
-
- public AbstractPlugin getPlugin() {
- return plugin;
- }
-
- public void setPlugin(AbstractPlugin plugin) {
- this.plugin = plugin;
- }
-
- public ServerPlugin getServerPlugin() {
- return (ServerPlugin) this.plugin;
- }
-
- public void setServerPlugin(ServerPlugin plugin) {
- this.plugin = plugin;
- }
-
- public ConfigurationDefinition getPluginConfigurationDefinition() {
- return this.pluginConfigurationDefinition;
- }
-
- public ConfigurationDefinition getScheduledJobsDefinition() {
- return this.scheduledJobsDefinition;
- }
-
- public boolean isEditable() {
- return this.pluginConfigurationDefinition != null || this.scheduledJobsDefinition != null;
- }
-
- public String updatePlugin() {
- // note we assume we are editing a server plugin - we don't support editing agent plugins yet
- try {
- ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
- Subject subject = EnterpriseFacesContextUtility.getSubject();
- serverPlugins.updateServerPluginExceptContent(subject, getServerPlugin());
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration settings saved.");
-
- return OUTCOME_SUCCESS_SERVER_PLUGIN;
- } 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);
-
- return null;
- }
- }
-
- @Create
- public void lookupConfigDefinitions() {
- hasPermission();
- String pluginName = this.plugin.getName();
-
- if (this.plugin.getDeployment() == PluginDeploymentType.SERVER) {
- try {
- ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- 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
- .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);
- return;
- }
- }
- }
-
- /**
- * 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");
- }
- }
-}
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
deleted file mode 100644
index d88afe7..0000000
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit.xhtml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?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
deleted file mode 100644
index 92d36f3..0000000
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?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="deployment" value="#{installedPlugin.deployment}"/>
- <f:param name="pluginType" value="#{installedPlugin.pluginType}"/>
- <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 5e32efa..aba7769 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
@@ -9,7 +9,7 @@
xmlns:rich="http://richfaces.ajax4jsf.org/rich">
<ui:composition template="/rhq/layout/main.xhtml">
- <ui:param name="pageTitle" value="#{InstalledPluginUIBean.plugin.name}"/>
+ <ui:param name="pageTitle" value="#{plugin.name}"/>
<ui:define name="breadcrumbs">
<h:outputLink value="plugin-list.xhtml" >
@@ -17,7 +17,7 @@
</h:outputLink>
>
<h:outputLink value="#" >
- <h:outputText value="#{InstalledPluginUIBean.plugin.displayName}"/>
+ <h:outputText value="#{plugin.displayName}"/>
</h:outputLink>
</ui:define>
@@ -39,28 +39,28 @@
<rich:panel>
<f:facet name="header">
- <h:outputText value="Plugin: #{InstalledPluginUIBean.plugin.displayName} (#{InstalledPluginUIBean.plugin.name})"/>
+ <h:outputText value="Plugin: #{plugin.displayName} (#{plugin.name})"/>
</f:facet>
<h:panelGrid styleClass="BlockContent" columns="4" width="100%">
<h:outputLabel styleClass="BlockLabel" value="Version:"/>
- <h:outputText styleClass="BlockContent" value="#{InstalledPluginUIBean.plugin.version}"/>
+ <h:outputText styleClass="BlockContent" value="#{plugin.version}"/>
<h:outputLabel styleClass="BlockLabel" value="Enabled:"/>
- <h:outputText value="#{InstalledPluginUIBean.plugin.enabled}"/>
+ <h:outputText value="#{plugin.enabled}"/>
<h:outputLabel styleClass="BlockLabel" value="Type:"/>
- <h:outputText value="#{InstalledPluginUIBean.plugin.deployment}"/>
+ <h:outputText value="#{plugin.deployment}"/>
<h:outputLabel styleClass="BlockLabel" value="MD5:"/>
- <h:outputText value="#{InstalledPluginUIBean.plugin.md5}"/>
+ <h:outputText value="#{plugin.md5}"/>
<h:outputLabel styleClass="BlockLabel" value="Description:"/>
- <h:outputText value="#{InstalledPluginUIBean.plugin.description}"/>
+ <h:outputText value="#{plugin.description}"/>
<h:outputLabel styleClass="BlockLabel" value="Path:"/>
- <h:outputText value="#{InstalledPluginUIBean.plugin.path}"/>
+ <h:outputText value="#{plugin.path}"/>
</h:panelGrid>
@@ -69,38 +69,12 @@
<h:outputText value="Plugin Help"/>
</f:facet>
- <h:outputText escape="false" value="<pre> #{InstalledPluginUIBean.plugin.help} </pre>"/>
+ <h:outputText escape="false" value="<pre> #{plugin.help} </pre>"/>
</rich:panel>
-
- <ui:insert name="pre-config" />
-
- <rich:panel rendered="#{InstalledPluginUIBean.pluginConfigurationDefinition != null}">
- <f:facet name="header">
- <h:outputText value="Plugin Configuration"/>
- </f:facet>
- <onc:config
- configurationDefinition="#{InstalledPluginUIBean.pluginConfigurationDefinition}"
- configuration="#{InstalledPluginUIBean.plugin.pluginConfiguration}"
- readOnly="#{not editMode}" />
- </rich:panel>
-
- <rich:panel rendered="#{InstalledPluginUIBean.scheduledJobsDefinition != null}">
- <f:facet name="header">
- <h:outputText value="Scheduled Jobs"/>
- </f:facet>
- <onc:config
- configurationDefinition="#{InstalledPluginUIBean.scheduledJobsDefinition}"
- configuration="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration}"
- readOnly="#{not editMode}" />
- </rich:panel>
-
- <ui:insert name="post-config" />
</rich:panel>
-
</h:form>
-
</ui:define>
</ui:composition>
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 ba128c1..0b020b3 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
@@ -160,7 +160,7 @@
<h:outputText styleClass="headerText" value="Name"/>
</f:facet>
- <h:outputLink value="/rhq/admin/plugin/plugin-details-view.xhtml">
+ <h:outputLink value="/rhq/admin/plugin/plugin-details.xhtml">
<f:param name="plugin" value="#{serverPlugin.name}"/>
<f:param name="deployment" value="SERVER"/>
<f:param name="pluginType" value="#{serverPlugin.type}"/>
14 years
[rhq] Branch 'raw-config' - modules/core
by John Sanda
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java | 4
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java | 73 ---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java | 90 ----
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java | 90 ++++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java | 75 +++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java | 8
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java | 191 ----------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java | 126 ------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java | 191 ++++++++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java | 147 +++++++
10 files changed, 509 insertions(+), 486 deletions(-)
New commits:
commit f013bcd501ef15a8e5f93790629a44ba6796a741
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:57:00 2009 -0500
[US 6] Adding support for updates of structured config with new ResourceConfigurationFacet
Renaming some classes to be consistent with renamed interface.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
index 66aef29..6193fd2 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
@@ -64,7 +64,7 @@ public class ConfigManagementFactoryImpl implements ConfigManagementFactory {
ResourceType resourceType = componentService.getResourceType(resourceId);
if (isStructured(resourceType)) {
- return new LoadStructured();
+ return new StructuredConfigManagement();
}
if (isRaw(resourceType)) {
@@ -72,7 +72,7 @@ public class ConfigManagementFactoryImpl implements ConfigManagementFactory {
}
// else format is both structured and raw
- return new LoadStructuredAndRaw();
+ return new StructuredAndRawConfigManagement();
}
private boolean isLegacyVersion(String ampsVersion) {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java
deleted file mode 100644
index 5e76590..0000000
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.clientapi.agent.PluginContainerException;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.List;
-
-public class LoadStructured extends ConfigManagementSupport {
-
- private final Log log = LogFactory.getLog(LoadStructured.class);
-
- public Configuration execute(int resourceId) throws PluginContainerException {
- ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
-
- Configuration configuration = facet.loadStructuredConfiguration();
-
- if (configuration == null) {
- return null;
- }
-
- ResourceType resourceType = componentService.getResourceType(resourceId);
-
- if (configuration.getNotes() == null) {
- configuration.setNotes("Resource config for " + resourceType.getName() + " Resource w/ id " + resourceId);
- }
-
- configUtilityService.normalizeConfiguration(configuration, resourceType.getResourceConfigurationDefinition());
- List<String> errorMsgs = configUtilityService.validateConfiguration(configuration,
- resourceType.getResourceConfigurationDefinition());
-
- logErrorMsgs(errorMsgs, resourceType);
-
- return configuration;
- }
-
- private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
- for (String errorMessage : errorMsgs) {
- log.warn("Plugin Error: Invalid " + resourceType.getName() + " Resource configuration returned by "
- + resourceType.getPlugin() + " plugin - " + errorMessage);
- }
- }
-
- public void executeUpdate(int resourceId, Configuration configuration)
- throws PluginContainerException {
- }
-}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java
deleted file mode 100644
index cbfca94..0000000
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import static java.util.Collections.EMPTY_SET;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.clientapi.agent.PluginContainerException;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.List;
-import java.util.Set;
-
-public class LoadStructuredAndRaw extends ConfigManagementSupport {
-
- private final Log log = LogFactory.getLog(LoadStructuredAndRaw.class);
-
- public Configuration execute(int resourceId) throws PluginContainerException {
- ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
-
- Configuration configuration = facet.loadStructuredConfiguration();
- Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations();
-
- if (configuration == null && rawConfigs == null) {
- return null;
- }
-
- if (configuration == null) {
- configuration = new Configuration();
- }
-
- if (rawConfigs == null) {
- rawConfigs = EMPTY_SET;
- }
-
- for (RawConfiguration rawConfig : rawConfigs) {
- configuration.addRawConfiguration(rawConfig);
- }
-
- ResourceType resourceType = componentService.getResourceType(resourceId);
-
- if (configuration.getNotes() == null) {
- configuration.setNotes("Resource config for " + resourceType.getName() + " Resource w/ id " + resourceId);
- }
-
- configUtilityService.normalizeConfiguration(configuration, resourceType.getResourceConfigurationDefinition());
- List<String> errorMsgs = configUtilityService.validateConfiguration(configuration,
- resourceType.getResourceConfigurationDefinition());
-
- logErrorMsgs(errorMsgs, resourceType);
-
- return configuration;
- }
-
- private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
- for (String errorMessage : errorMsgs) {
- log.warn("Plugin Error: Invalid " + resourceType.getName() + " Resource configuration returned by "
- + resourceType.getPlugin() + " plugin - " + errorMessage);
- }
- }
-
- public void executeUpdate(int resourceId, Configuration configuration)
- throws PluginContainerException {
- }
-}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java
new file mode 100644
index 0000000..d8a9ed1
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java
@@ -0,0 +1,90 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import static java.util.Collections.EMPTY_SET;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.RawConfiguration;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.List;
+import java.util.Set;
+
+public class StructuredAndRawConfigManagement extends ConfigManagementSupport {
+
+ private final Log log = LogFactory.getLog(StructuredAndRawConfigManagement.class);
+
+ public Configuration execute(int resourceId) throws PluginContainerException {
+ ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
+
+ Configuration configuration = facet.loadStructuredConfiguration();
+ Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations();
+
+ if (configuration == null && rawConfigs == null) {
+ return null;
+ }
+
+ if (configuration == null) {
+ configuration = new Configuration();
+ }
+
+ if (rawConfigs == null) {
+ rawConfigs = EMPTY_SET;
+ }
+
+ for (RawConfiguration rawConfig : rawConfigs) {
+ configuration.addRawConfiguration(rawConfig);
+ }
+
+ ResourceType resourceType = componentService.getResourceType(resourceId);
+
+ if (configuration.getNotes() == null) {
+ configuration.setNotes("Resource config for " + resourceType.getName() + " Resource w/ id " + resourceId);
+ }
+
+ configUtilityService.normalizeConfiguration(configuration, resourceType.getResourceConfigurationDefinition());
+ List<String> errorMsgs = configUtilityService.validateConfiguration(configuration,
+ resourceType.getResourceConfigurationDefinition());
+
+ logErrorMsgs(errorMsgs, resourceType);
+
+ return configuration;
+ }
+
+ private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
+ for (String errorMessage : errorMsgs) {
+ log.warn("Plugin Error: Invalid " + resourceType.getName() + " Resource configuration returned by "
+ + resourceType.getPlugin() + " plugin - " + errorMessage);
+ }
+ }
+
+ public void executeUpdate(int resourceId, Configuration configuration)
+ throws PluginContainerException {
+ }
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java
new file mode 100644
index 0000000..7a04d04
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java
@@ -0,0 +1,75 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.List;
+
+public class StructuredConfigManagement extends ConfigManagementSupport {
+
+ private final Log log = LogFactory.getLog(StructuredConfigManagement.class);
+
+ public Configuration execute(int resourceId) throws PluginContainerException {
+ ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
+
+ Configuration configuration = facet.loadStructuredConfiguration();
+
+ if (configuration == null) {
+ return null;
+ }
+
+ ResourceType resourceType = componentService.getResourceType(resourceId);
+
+ if (configuration.getNotes() == null) {
+ configuration.setNotes("Resource config for " + resourceType.getName() + " Resource w/ id " + resourceId);
+ }
+
+ configUtilityService.normalizeConfiguration(configuration, resourceType.getResourceConfigurationDefinition());
+ List<String> errorMsgs = configUtilityService.validateConfiguration(configuration,
+ resourceType.getResourceConfigurationDefinition());
+
+ logErrorMsgs(errorMsgs, resourceType);
+
+ return configuration;
+ }
+
+ private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
+ for (String errorMessage : errorMsgs) {
+ log.warn("Plugin Error: Invalid " + resourceType.getName() + " Resource configuration returned by "
+ + resourceType.getPlugin() + " plugin - " + errorMessage);
+ }
+ }
+
+ public void executeUpdate(int resourceId, Configuration configuration) throws PluginContainerException {
+ ResourceConfigurationFacet facet = loadResourceConfigFacetWithWriteLock(resourceId);
+
+ facet.persistStructuredConfiguration(configuration);
+ }
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
index 8ea73cf..4e58e9c 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
@@ -103,8 +103,8 @@ public class ConfigManagementFactoryImplTest extends JMockTest {
ConfigManagement loadConfig = factory.getStrategy(resourceId);
assertTrue(
- loadConfig instanceof LoadStructured,
- "Expected to get an instance of " + LoadStructured.class.getSimpleName() +
+ loadConfig instanceof StructuredConfigManagement,
+ "Expected to get an instance of " + StructuredConfigManagement.class.getSimpleName() +
"when resource is from a plugin having an ampsversion >= " + NON_LEGACY_AMPS_VERSION + " and the resource " +
"configuration format is structured."
);
@@ -197,8 +197,8 @@ public class ConfigManagementFactoryImplTest extends JMockTest {
ConfigManagement loadConfig = factory.getStrategy(resourceId);
assertTrue(
- loadConfig instanceof LoadStructuredAndRaw,
- "Expected to get an instance of" + LoadStructuredAndRaw.class.getSimpleName() +
+ loadConfig instanceof StructuredAndRawConfigManagement,
+ "Expected to get an instance of" + StructuredAndRawConfigManagement.class.getSimpleName() +
" when resource is from a plugin having an ampsVersion >= " + NON_LEGACY_AMPS_VERSION + " and the " +
"resource configuration format is both (structured and raw)."
);
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java
deleted file mode 100644
index e275f82..0000000
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import static org.testng.Assert.*;
-import static java.util.Collections.*;
-
-import org.rhq.core.pc.util.ComponentService;
-import org.rhq.core.pc.util.FacetLockType;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.resource.ResourceType;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.jmock.Expectations;
-
-import java.util.Set;
-
-public class LoadStructuredAndRawTest extends ConfigManagementTest {
-
- ComponentService componentService;
-
- ConfigurationUtilityService configUtilityService;
-
- ResourceConfigurationFacet configFacet;
-
- LoadStructuredAndRaw loadStructuredAndRaw;
-
- @BeforeMethod
- public void setup() {
- resourceType = new ResourceType();
- resourceType.setResourceConfigurationDefinition(new ConfigurationDefinition("", ""));
-
- componentService = context.mock(ComponentService.class);
- configUtilityService = context.mock(ConfigurationUtilityService.class);
-
- configFacet = context.mock(ResourceConfigurationFacet.class);
-
- loadStructuredAndRaw = new LoadStructuredAndRaw();
- loadStructuredAndRaw.setComponentService(componentService);
- loadStructuredAndRaw.setConfigurationUtilityService(configUtilityService);
- }
-
- @Test
- public void rawConfigshouldGetLoaded() throws Exception {
- Configuration config = new Configuration();
-
- Set<RawConfiguration> rawConfigs = toSet(
- createRawConfiguration("/tmp/foo.txt"),
- createRawConfiguration("/tmp/bar.txt")
- );
-
-
- addDefaultExpectations(config, rawConfigs);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertRawsLoaded(rawConfigs, loadedConfig);
- }
-
- @Test
- public void structuredConfigShouldGetLoaded() throws Exception {
- Configuration config = new Configuration();
- config.put(new PropertySimple("x", "1"));
- config.put(new PropertySimple("y", "2"));
-
- addDefaultExpectations(config, EMPTY_SET);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertStructuredLoaded(config, loadedConfig);
- }
-
- @Test
- public void theConfigNotesShouldGetSet() throws Exception {
- Configuration config = new Configuration();
- config.setNotes(null);
-
- addDefaultExpectations(config, EMPTY_SET);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertNotesSetToDefault(loadedConfig);
- }
-
- @Test
- public void nullStructuredShouldBeIgnored() throws Exception {
- Configuration config = null;
-
- Set<RawConfiguration> rawConfigs = toSet(createRawConfiguration("/tmp/foo.txt"));
-
- addDefaultExpectations(config, rawConfigs);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- Configuration emptyStructured = new Configuration();
-
- assertRawsLoaded(rawConfigs, loadedConfig);
- assertStructuredLoaded(emptyStructured, loadedConfig);
- }
-
- @Test
- public void nullRawsShouldBeIgnored() throws Exception {
- Configuration config = new Configuration();
- config.put(new PropertySimple("x", "1"));
- config.put(new PropertySimple("y", "2"));
-
- Set<RawConfiguration> rawConfigs = null;
-
- addDefaultExpectations(config, rawConfigs);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertRawsLoaded(EMPTY_SET, loadedConfig);
- assertStructuredLoaded(config, loadedConfig);
- }
-
- @Test
- public void nullShouldBeReturnedWhenStructuredAndRawAreNull() throws Exception {
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
- ResourceConfigurationFacet.class,
- FacetLockType.READ,
- ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
-
- oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(null));
-
- oneOf(configFacet).loadRawConfigurations(); will(returnValue(null));
- }});
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertNull(loadedConfig, "Expected null to be returned when facet returns null for both structured and raw.");
- }
-
- private void addDefaultExpectations(final Configuration config, final Set<RawConfiguration> rawConfigs)
- throws Exception {
-
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
- ResourceConfigurationFacet.class,
- FacetLockType.READ,
- ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
-
- oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(config));
-
- oneOf(configFacet).loadRawConfigurations(); will(returnValue(rawConfigs));
-
- atLeast(1).of(configUtilityService).normalizeConfiguration(with(any(Configuration.class)),
- with(getResourceConfigDefinition()));
-
- atLeast(1).of(configUtilityService).validateConfiguration(with(any(Configuration.class)),
- with(getResourceConfigDefinition()));
- }});
- }
-
-}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java
deleted file mode 100644
index 3941afd..0000000
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import org.jmock.Expectations;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.pc.util.ComponentService;
-import org.rhq.core.pc.util.FacetLockType;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import static org.testng.Assert.assertNull;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class LoadStructuredTest extends ConfigManagementTest {
-
- ComponentService componentService;
-
- ConfigurationUtilityService configUtilityService;
-
- ResourceConfigurationFacet configFacet;
-
- LoadStructured loadStructured;
-
- @BeforeMethod
- public void setup() {
- componentService = context.mock(ComponentService.class);
- configUtilityService = context.mock(ConfigurationUtilityService.class);
-
- configFacet = context.mock(ResourceConfigurationFacet.class);
-
- loadStructured = new LoadStructured();
- loadStructured.setComponentService(componentService);
- loadStructured.setConfigurationUtilityService(configUtilityService);
- }
-
- @Test
- public void structuredConfigShouldGetLoaded() throws Exception {
- Configuration config = new Configuration();
- config.put(new PropertySimple("x", "1"));
- config.put(new PropertySimple("y", "2"));
-
- addDefaultExpectations(config);
-
- Configuration loadedConfig = loadStructured.execute(resourceId);
-
- assertStructuredLoaded(config, loadedConfig);
- }
-
- @Test
- public void theConfigNotesShouldGetSet() throws Exception {
- final Configuration config = new Configuration();
- config.setNotes(null);
-
- addDefaultExpectations(config);
-
- Configuration loadedConfig = loadStructured.execute(resourceId);
-
- assertNotesSetToDefault(loadedConfig);
- }
-
- @Test
- public void nullShouldBeReturnedWhenStructuredIsNull() throws Exception {
- final Configuration config = null;
-
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
- ResourceConfigurationFacet.class,
- FacetLockType.READ,
- ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
-
- atLeast(1).of(configFacet).loadStructuredConfiguration(); will(returnValue(null));
- }});
-
- Configuration loadedConfig = loadStructured.execute(resourceId);
-
- assertNull(loadedConfig, "Expected null to be returned when facet returns null for structured.");
- }
-
- private void addDefaultExpectations(final Configuration config) throws Exception {
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
- ResourceConfigurationFacet.class,
- FacetLockType.READ,
- ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
-
- atLeast(1).of(configFacet).loadStructuredConfiguration(); will(returnValue(config));
-
- atLeast(1).of(configUtilityService).normalizeConfiguration(config, getResourceConfigDefinition());
-
- atLeast(1).of(configUtilityService).validateConfiguration(config, getResourceConfigDefinition());
- }});
- }
-
-}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java
new file mode 100644
index 0000000..7dbc1b6
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java
@@ -0,0 +1,191 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import static org.testng.Assert.*;
+import static java.util.Collections.*;
+
+import org.rhq.core.pc.util.ComponentService;
+import org.rhq.core.pc.util.FacetLockType;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.RawConfiguration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.resource.ResourceType;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.jmock.Expectations;
+
+import java.util.Set;
+
+public class StructuredAndRawConfigManagementTest extends ConfigManagementTest {
+
+ ComponentService componentService;
+
+ ConfigurationUtilityService configUtilityService;
+
+ ResourceConfigurationFacet configFacet;
+
+ StructuredAndRawConfigManagement structuredAndRawConfigManagement;
+
+ @BeforeMethod
+ public void setup() {
+ resourceType = new ResourceType();
+ resourceType.setResourceConfigurationDefinition(new ConfigurationDefinition("", ""));
+
+ componentService = context.mock(ComponentService.class);
+ configUtilityService = context.mock(ConfigurationUtilityService.class);
+
+ configFacet = context.mock(ResourceConfigurationFacet.class);
+
+ structuredAndRawConfigManagement = new StructuredAndRawConfigManagement();
+ structuredAndRawConfigManagement.setComponentService(componentService);
+ structuredAndRawConfigManagement.setConfigurationUtilityService(configUtilityService);
+ }
+
+ @Test
+ public void rawConfigshouldGetLoaded() throws Exception {
+ Configuration config = new Configuration();
+
+ Set<RawConfiguration> rawConfigs = toSet(
+ createRawConfiguration("/tmp/foo.txt"),
+ createRawConfiguration("/tmp/bar.txt")
+ );
+
+
+ addDefaultExpectations(config, rawConfigs);
+
+ Configuration loadedConfig = structuredAndRawConfigManagement.execute(resourceId);
+
+ assertRawsLoaded(rawConfigs, loadedConfig);
+ }
+
+ @Test
+ public void structuredConfigShouldGetLoaded() throws Exception {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("x", "1"));
+ config.put(new PropertySimple("y", "2"));
+
+ addDefaultExpectations(config, EMPTY_SET);
+
+ Configuration loadedConfig = structuredAndRawConfigManagement.execute(resourceId);
+
+ assertStructuredLoaded(config, loadedConfig);
+ }
+
+ @Test
+ public void theConfigNotesShouldGetSet() throws Exception {
+ Configuration config = new Configuration();
+ config.setNotes(null);
+
+ addDefaultExpectations(config, EMPTY_SET);
+
+ Configuration loadedConfig = structuredAndRawConfigManagement.execute(resourceId);
+
+ assertNotesSetToDefault(loadedConfig);
+ }
+
+ @Test
+ public void nullStructuredShouldBeIgnored() throws Exception {
+ Configuration config = null;
+
+ Set<RawConfiguration> rawConfigs = toSet(createRawConfiguration("/tmp/foo.txt"));
+
+ addDefaultExpectations(config, rawConfigs);
+
+ Configuration loadedConfig = structuredAndRawConfigManagement.execute(resourceId);
+
+ Configuration emptyStructured = new Configuration();
+
+ assertRawsLoaded(rawConfigs, loadedConfig);
+ assertStructuredLoaded(emptyStructured, loadedConfig);
+ }
+
+ @Test
+ public void nullRawsShouldBeIgnored() throws Exception {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("x", "1"));
+ config.put(new PropertySimple("y", "2"));
+
+ Set<RawConfiguration> rawConfigs = null;
+
+ addDefaultExpectations(config, rawConfigs);
+
+ Configuration loadedConfig = structuredAndRawConfigManagement.execute(resourceId);
+
+ assertRawsLoaded(EMPTY_SET, loadedConfig);
+ assertStructuredLoaded(config, loadedConfig);
+ }
+
+ @Test
+ public void nullShouldBeReturnedWhenStructuredAndRawAreNull() throws Exception {
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+ ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
+
+ oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(null));
+
+ oneOf(configFacet).loadRawConfigurations(); will(returnValue(null));
+ }});
+
+ Configuration loadedConfig = structuredAndRawConfigManagement.execute(resourceId);
+
+ assertNull(loadedConfig, "Expected null to be returned when facet returns null for both structured and raw.");
+ }
+
+ private void addDefaultExpectations(final Configuration config, final Set<RawConfiguration> rawConfigs)
+ throws Exception {
+
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+ ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
+
+ oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(config));
+
+ oneOf(configFacet).loadRawConfigurations(); will(returnValue(rawConfigs));
+
+ atLeast(1).of(configUtilityService).normalizeConfiguration(with(any(Configuration.class)),
+ with(getResourceConfigDefinition()));
+
+ atLeast(1).of(configUtilityService).validateConfiguration(with(any(Configuration.class)),
+ with(getResourceConfigDefinition()));
+ }});
+ }
+
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java
new file mode 100644
index 0000000..cac0ca4
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java
@@ -0,0 +1,147 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import org.jmock.Expectations;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pc.util.ComponentService;
+import org.rhq.core.pc.util.FacetLockType;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import static org.testng.Assert.assertNull;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class StructuredConfigManagementTest extends ConfigManagementTest {
+
+ ComponentService componentService;
+
+ ConfigurationUtilityService configUtilityService;
+
+ ResourceConfigurationFacet configFacet;
+
+ StructuredConfigManagement structuredMgmt;
+
+ @BeforeMethod
+ public void setup() {
+ componentService = context.mock(ComponentService.class);
+ configUtilityService = context.mock(ConfigurationUtilityService.class);
+
+ configFacet = context.mock(ResourceConfigurationFacet.class);
+
+ structuredMgmt = new StructuredConfigManagement();
+ structuredMgmt.setComponentService(componentService);
+ structuredMgmt.setConfigurationUtilityService(configUtilityService);
+ }
+
+ @Test
+ public void structuredConfigShouldGetLoaded() throws Exception {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("x", "1"));
+ config.put(new PropertySimple("y", "2"));
+
+ addDefaultExpectationsForLoad(config);
+
+ Configuration loadedConfig = structuredMgmt.execute(resourceId);
+
+ assertStructuredLoaded(config, loadedConfig);
+ }
+
+ @Test
+ public void theConfigNotesShouldGetSet() throws Exception {
+ final Configuration config = new Configuration();
+ config.setNotes(null);
+
+ addDefaultExpectationsForLoad(config);
+
+ Configuration loadedConfig = structuredMgmt.execute(resourceId);
+
+ assertNotesSetToDefault(loadedConfig);
+ }
+
+ @Test
+ public void nullShouldBeReturnedWhenStructuredIsNull() throws Exception {
+ final Configuration config = null;
+
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+ ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
+
+ atLeast(1).of(configFacet).loadStructuredConfiguration(); will(returnValue(null));
+ }});
+
+ Configuration loadedConfig = structuredMgmt.execute(resourceId);
+
+ assertNull(loadedConfig, "Expected null to be returned when facet returns null for structured.");
+ }
+
+ private void addDefaultExpectationsForLoad(final Configuration config) throws Exception {
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+ ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType));
+
+ atLeast(1).of(configFacet).loadStructuredConfiguration(); will(returnValue(config));
+
+ atLeast(1).of(configUtilityService).normalizeConfiguration(config, getResourceConfigDefinition());
+
+ atLeast(1).of(configUtilityService).validateConfiguration(config, getResourceConfigDefinition());
+ }});
+ }
+
+ @Test
+ public void facetShouldBeCalledToUpdateStructured() throws Exception {
+ final Configuration structuredConfig = new Configuration();
+
+ final boolean isDaemonThread = false;
+
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.WRITE,
+ ConfigManagement.FACET_METHOD_TIMEOUT,
+ isDaemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ atLeast(1).of(configFacet).persistStructuredConfiguration(structuredConfig);
+ }});
+
+ structuredMgmt.executeUpdate(resourceId, structuredConfig);
+ }
+
+}
14 years
[rhq] Branch 'content' - modules/enterprise
by jdob
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java | 6 +++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java | 7 ++-----
2 files changed, 5 insertions(+), 8 deletions(-)
New commits:
commit 66b7130a35f1c0f87d460eda8a094ed99383fac6
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 30 16:31:49 2009 -0500
One more renaming.
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 384c948..450a905 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
@@ -224,7 +224,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
// make sure we stop its adapter and unschedule any sync job associated with it
try {
ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
- pc.unscheduleSyncJob(cs);
+ pc.unscheduleProviderSyncJob(cs);
pc.getAdapterManager().shutdownAdapter(cs);
} catch (Exception e) {
log.warn("Failed to shutdown adapter for [" + cs + "]", e);
@@ -477,7 +477,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
+ "]. Will now unschedule the old sync job");
try {
ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
- pc.unscheduleSyncJob(loaded);
+ pc.unscheduleProviderSyncJob(loaded);
} catch (Exception e) {
log.warn("Failed to unschedule obsolete content source sync job for [" + loaded + "]", e);
}
@@ -492,7 +492,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
// synchronize it now, too
try {
ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
- pc.unscheduleSyncJob(contentSource);
+ pc.unscheduleProviderSyncJob(contentSource);
pc.getAdapterManager().restartAdapter(contentSource);
pc.scheduleProviderSyncJob(contentSource);
pc.syncProviderNow(contentSource);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
index 97e270e..9a79c88 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
@@ -169,18 +169,15 @@ public class ContentServerPluginContainer extends AbstractTypeServerPluginContai
* This will unschedule the sync job for the given content source. Once unscheduled, the content source's adapter
* will not be asked to synchronize with the remote content source.
*
- * @param contentSource
+ * @param contentSource cannot be <code>null</code>
*
* @throws SchedulerException if failed to unschedule the job
*/
- public void unscheduleSyncJob(ContentSource contentSource) throws SchedulerException {
+ public void unscheduleProviderSyncJob(ContentSource contentSource) throws SchedulerException {
SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
scheduler.deleteJob(ContentProviderSyncJob.createJobName(contentSource), SYNC_JOB_GROUP_NAME);
-
- return;
}
- @Override
protected ServerPluginManager createPluginManager() {
return new ContentServerPluginManager(this);
}
14 years
[rhq] Branch 'content' - modules/enterprise
by jdob
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java | 6 +++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java | 5 ++---
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java | 9 +++------
3 files changed, 8 insertions(+), 12 deletions(-)
New commits:
commit cae22c0c76b5b5124b53f05334c33de21d4bb77f
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 30 16:29:51 2009 -0500
Renamed sync to reflect which sync its running.
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 1cabd8d..384c948 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
@@ -428,7 +428,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
// Schedule a job for the future
pc.scheduleProviderSyncJob(contentSource);
// Also sync immediately so we have the metadata
- pc.syncNow(contentSource);
+ pc.syncProviderNow(contentSource);
} catch (InitializationException ie) {
log.warn("Failed to start adapter for [" + contentSource + "]", ie);
@@ -495,7 +495,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
pc.unscheduleSyncJob(contentSource);
pc.getAdapterManager().restartAdapter(contentSource);
pc.scheduleProviderSyncJob(contentSource);
- pc.syncNow(contentSource);
+ pc.syncProviderNow(contentSource);
} catch (Exception e) {
log.warn("Failed to restart adapter for [" + contentSource + "]", e);
}
@@ -547,7 +547,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
ContentSource contentSource = entityManager.find(ContentSource.class, contentSourceId);
if (contentSource != null) {
- pc.syncNow(contentSource);
+ pc.syncProviderNow(contentSource);
} else {
log.warn("Asked to synchronize a non-existing content source [" + contentSourceId + "]");
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
index b34c324..ca2f1a7 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
@@ -20,7 +20,6 @@ package org.rhq.enterprise.server.content;
import java.util.ArrayList;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -556,7 +555,7 @@ public class RepoManagerBean implements RepoManagerLocal, RepoManagerRemote {
entityManager.clear();
// ask to synchronize the content source immediately (is this the right thing to do?)
- pc.syncNow(cs);
+ pc.syncProviderNow(cs);
}
return;
@@ -894,7 +893,7 @@ public class RepoManagerBean implements RepoManagerLocal, RepoManagerRemote {
Repo found = this.getRepo(subject, repoId);
Set<ContentSyncStatus> stati = new HashSet<ContentSyncStatus>();
List<RepoSyncResults> syncResults = found.getSyncResults();
- // Add the most recent sync results status
+ // Add the most recent sync results status
if (syncResults != null && (!syncResults.isEmpty()) && syncResults.get(0) != null) {
stati.add(syncResults.get(0).getStatus());
} else {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
index 6204e28..97e270e 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
@@ -105,7 +105,7 @@ public class ContentServerPluginContainer extends AbstractTypeServerPluginContai
*
* @throws SchedulerException if failed to schedule the job for immediate execution
*/
- public void syncNow(final ContentSource contentSource) throws SchedulerException {
+ public void syncProviderNow(final ContentSource contentSource) throws SchedulerException {
// Create our job with a trigger that fires immediately and doesn't repeat.
// Make the name unique - we may already have our cron job schedules.
// What happens if this is triggered when our cron job is triggered? the job will abort and let the current job finish
@@ -120,11 +120,8 @@ public class ContentServerPluginContainer extends AbstractTypeServerPluginContai
SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
Date next = scheduler.scheduleJob(job, trigger);
- getLog().info(
- "Scheduled content source sync job [" + job.getName() + ':' + job.getGroup() + "] to fire now at [" + next
- + "] for [" + contentSource + "]");
-
- return;
+ getLog().info("Scheduled content source sync job [" + job.getName() + ':' + job.getGroup() +
+ "] to fire now at [" + next + "] for [" + contentSource + "]");
}
/**
14 years
[rhq] Branch 'raw-config' - 3 commits - modules/enterprise
by John Sanda
modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js | 94 ++++++++--
1 file changed, 81 insertions(+), 13 deletions(-)
New commits:
commit 9e269d8ce6dc397d83bb3836748f23fca49a58e0
Merge: 2f7c427... 8bdcdaf...
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:25:51 2009 -0500
Merge branch 'raw-config' of ssh://git.fedorahosted.org/git/rhq/rhq into raw-config
commit 2f7c42750ea87ff28fbb86adf36f3ed6315839ee
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:23:07 2009 -0500
[US 910] Refactoring testGetAndUpdateRawConfiguration() to eliminate some duplicate code
diff --git a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
index f70682d..ed964ef 100644
--- a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
+++ b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
@@ -60,21 +60,8 @@ function testGetAndUpdateRawConfiguration() {
Assert.assertNotNull(rawServer, "Failed to find '" + resourceName + "'");
- var latestUpdate = ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
-
- Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration update for '" + resourceName + "'");
- Assert.assertTrue(
- latestUpdate.configuration.rawConfigurations.size() > 0,
- "Expected to find at least one raw config file for '" + "'"
- );
-
- var rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
- var rawConfig = rawConfigs.get(0);
-
- Assert.assertTrue(
- rawConfig.contents.length > 0,
- "Contents of raw config file for '" + resourceName + "' should not be empty."
- );
+ var latestUpdate = loadLatestResourceConfigurationUpdate(resourceName, rawServer.id);
+ var rawConfig = getRawConfig(resourceName, latestUpdate.configuration, 0);
var contents = java.lang.String(rawConfig.contents);
var modifiedContents = java.lang.StringBuilder(contents).append("\nModified at ").append(getDate()).toString();
@@ -83,16 +70,9 @@ function testGetAndUpdateRawConfiguration() {
var configUdpate = ConfigurationManager.updateResourceConfiguration(rawServer.id, latestUpdate.configuration);
- while (ConfigurationManager.isResourceConfigurationUpdateInProgress(rawServer.id)) {
- java.lang.Thread.sleep(1000);
- }
+ waitForResourceConfigUpdateToComplete(rawServer.id);
- latestUpdate = ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
- Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration update for '" + resourceName + "'");
- Assert.assertTrue(
- latestUpdate.configuration.rawConfigurations.size() > 0,
- "Expected to find at least one raw config file for '" + "'"
- );
+ latestUpdate = loadLatestResourceConfigurationUpdate(resourceName, rawServer.id);
rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
rawConfig = rawConfigs.get(0);
@@ -105,11 +85,41 @@ function testGetAndUpdateRawConfiguration() {
);
}
+function loadLatestResourceConfigurationUpdate(resourceName, resourceId) {
+ var latestUpdate = ConfigurationManager.getLatestResourceConfigurationUpdate(resourceId);
+
+ Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration update for '" + resourceName + "'");
+ Assert.assertTrue(
+ latestUpdate.configuration.rawConfigurations.size() > 0,
+ "Expected to find at least one raw config file for '" + "'"
+ );
+
+ return latestUpdate;
+}
+
+function getRawConfig(resourceName, configuration, index) {
+ var rawConfigs = java.util.LinkedList(configuration.rawConfigurations);
+ var rawConfig = rawConfigs.get(index);
+
+ Assert.assertTrue(
+ rawConfig.contents.length > 0,
+ "Contents of raw config file for '" + resourceName + "' should not be empty."
+ );
+
+ return rawConfig;
+}
+
function getDate() {
var format = java.text.DateFormat.getDateInstance();
return format.format(java.util.Date());
}
+function waitForResourceConfigUpdateToComplete(resourceId) {
+ while (ConfigurationManager.isResourceConfigurationUpdateInProgress(resourceId)) {
+ java.lang.Thread.sleep(1000);
+ }
+}
+
//function testUpdatePluginConfiguration() {
// var resource = findService('service-beta-0', 'server-omega-0');
// var pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
commit 9735ccd93be5c8d7bbd7578f014106f655fcbf25
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:05:12 2009 -0500
[US 910]
Adding a CLI script test to read and update a raw config.
diff --git a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
index 7157fb9..f70682d 100644
--- a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
+++ b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
@@ -26,11 +26,12 @@ rhq.login('rhqadmin', 'rhqadmin');
skippedTests.push('testUpdateResourceGroupConfiguration');
executeAllTests();
+//executeTests(['testGetAndUpdateRawConfiguration']);
rhq.logout();
function testUpdateResourceConfiguration() {
- var resource = findService('service-beta-1', 'server-omega-1');
+ var resource = findResourceByNameAndParentName('service-beta-1', 'server-omega-1');
var config = ConfigurationManager.getResourceConfiguration(resource.id);
var propertyName = 'beta-config0';
@@ -53,25 +54,81 @@ function testUpdateResourceConfiguration() {
Assert.assertEquals(updatedProperty.stringValue, propertyValue, 'Failed to update resource configuration');
}
-function testUpdatePluginConfiguration() {
- var resource = findService('service-beta-0', 'server-omega-0');
- var pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
+function testGetAndUpdateRawConfiguration() {
+ var resourceName = 'Raw Server'
+ var rawServer = findResourceByNameAndParentName(resourceName, 'localhost');
- var propertyName = 'beta-property0';
- var propertyValue = 'updated property value -- ' + java.util.Date();
+ Assert.assertNotNull(rawServer, "Failed to find '" + resourceName + "'");
- var property = pluginConfig.getSimple(propertyName);
+ var latestUpdate = ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
- property.setStringValue(propertyValue);
+ Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration update for '" + resourceName + "'");
+ Assert.assertTrue(
+ latestUpdate.configuration.rawConfigurations.size() > 0,
+ "Expected to find at least one raw config file for '" + "'"
+ );
+
+ var rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
+ var rawConfig = rawConfigs.get(0);
+
+ Assert.assertTrue(
+ rawConfig.contents.length > 0,
+ "Contents of raw config file for '" + resourceName + "' should not be empty."
+ );
+
+ var contents = java.lang.String(rawConfig.contents);
+ var modifiedContents = java.lang.StringBuilder(contents).append("\nModified at ").append(getDate()).toString();
+
+ rawConfig.contents = modifiedContents.getBytes();
- var configUpdate = ConfigurationManager.updatePluginConfiguration(resource.id, pluginConfig);
+ var configUdpate = ConfigurationManager.updateResourceConfiguration(rawServer.id, latestUpdate.configuration);
- pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
- var updatedProperty = pluginConfig.getSimple(propertyName);
+ while (ConfigurationManager.isResourceConfigurationUpdateInProgress(rawServer.id)) {
+ java.lang.Thread.sleep(1000);
+ }
+
+ latestUpdate = ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
+ Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration update for '" + resourceName + "'");
+ Assert.assertTrue(
+ latestUpdate.configuration.rawConfigurations.size() > 0,
+ "Expected to find at least one raw config file for '" + "'"
+ );
+
+ rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
+ rawConfig = rawConfigs.get(0);
+ var updatedContents = rawConfig.contents;
+
+ Assert.assertEquals(
+ java.lang.String(updatedContents),
+ java.lang.String(modifiedContents),
+ "Failed to update raw config for '" + resourceName + "'"
+ );
+}
- Assert.assertEquals(updatedProperty.stringValue, propertyValue, 'Failed to update plugin configuration');
+function getDate() {
+ var format = java.text.DateFormat.getDateInstance();
+ return format.format(java.util.Date());
}
+//function testUpdatePluginConfiguration() {
+// var resource = findService('service-beta-0', 'server-omega-0');
+// var pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
+//
+// var propertyName = 'beta-property0';
+// var propertyValue = 'updated property value -- ' + java.util.Date();
+//
+// var property = pluginConfig.getSimple(propertyName);
+//
+// property.setStringValue(propertyValue);
+//
+// var configUpdate = ConfigurationManager.updatePluginConfiguration(resource.id, pluginConfig);
+//
+// pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
+// var updatedProperty = pluginConfig.getSimple(propertyName);
+//
+// Assert.assertEquals(updatedProperty.stringValue, propertyValue, 'Failed to update plugin configuration');
+//}
+
// This test is failing I think due to the asynchronous nature of the operations involved. I have verified through the
// web UI that the configuration updates are actually happening. I just need to figure out how to make the test wait
// so that it can (consistently) get the udpated values.
@@ -112,10 +169,11 @@ function testUpdateResourceGroupConfiguration() {
}
}
-function findService(name, parentName) {
+function findResourceByNameAndParentName(name, parentName) {
var criteria = ResourceCriteria();
criteria.addFilterName(name);
criteria.addFilterParentResourceName(parentName);
+ criteria.strict = true;
return ResourceManager.findResourcesByCriteria(criteria).get(0);
}
14 years
[rhq] Branch 'content' - modules/enterprise
by jdob
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/ContentSourceManagerBean.java | 4 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java | 14 +++-------
2 files changed, 7 insertions(+), 11 deletions(-)
New commits:
commit 18f435db715beeecf08b8c3ffd2802364b1fcde3
Author: Jason Dobies <jason.dobies(a)redhat.com>
Date: Mon Nov 30 16:11:20 2009 -0500
Renamed sync job scheduling methods due to different types of sync jobs that can be scheduled.
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 0a1a148..1cabd8d 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
@@ -426,7 +426,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
pc.getAdapterManager().startAdapter(contentSource);
// Schedule a job for the future
- pc.scheduleSyncJob(contentSource);
+ pc.scheduleProviderSyncJob(contentSource);
// Also sync immediately so we have the metadata
pc.syncNow(contentSource);
@@ -494,7 +494,7 @@ public class ContentSourceManagerBean implements ContentSourceManagerLocal {
ContentServerPluginContainer pc = ContentManagerHelper.getPluginContainer();
pc.unscheduleSyncJob(contentSource);
pc.getAdapterManager().restartAdapter(contentSource);
- pc.scheduleSyncJob(contentSource);
+ pc.scheduleProviderSyncJob(contentSource);
pc.syncNow(contentSource);
} catch (Exception e) {
log.warn("Failed to restart adapter for [" + contentSource + "]", e);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
index 9eb014e..6204e28 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginContainer.java
@@ -75,7 +75,7 @@ public class ContentServerPluginContainer extends AbstractTypeServerPluginContai
@Override
public void schedulePluginJobs() throws Exception {
super.schedulePluginJobs();
- scheduleSyncJobs();
+ scheduleProviderSyncJobs();
return;
}
@@ -135,11 +135,11 @@ public class ContentServerPluginContainer extends AbstractTypeServerPluginContai
* <p>If the content source's sync schedule is empty, this method assumes it should not be automatically sync'ed so
* no schedule will be created and this method simply returns.</p>
*
- * @param contentSource
+ * @param contentSource provider to sync
*
* @throws SchedulerException if failed to schedule the job
*/
- public void scheduleSyncJob(ContentSource contentSource) throws SchedulerException {
+ public void scheduleProviderSyncJob(ContentSource contentSource) throws SchedulerException {
String syncSchedule = contentSource.getSyncSchedule();
if ((syncSchedule == null) || (syncSchedule.trim().length() == 0)) {
getLog().debug(contentSource.toString() + " does not define a sync schedule - not scheduling");
@@ -150,26 +150,22 @@ public class ContentServerPluginContainer extends AbstractTypeServerPluginContai
scheduler.scheduleCronJob(ContentProviderSyncJob.createJobName(contentSource), SYNC_JOB_GROUP_NAME,
ContentProviderSyncJob.createJobDataMap(contentSource, null), ContentProviderSyncJob.class, true, false,
syncSchedule);
-
- return;
}
/**
* It will schedule one job per adapter such that each adapter is scheduled to be synchronized as per its defined
* sync schedule. This must only be called when all content source adapters have been initialized.
*/
- public void scheduleSyncJobs() {
+ public void scheduleProviderSyncJobs() {
if (this.adapterManager != null) {
for (ContentSource contentSource : this.adapterManager.getAllContentSources()) {
try {
- scheduleSyncJob(contentSource);
+ scheduleProviderSyncJob(contentSource);
} catch (Exception e) {
getLog().warn("Could not schedule sync job for content source [" + contentSource + "]", e);
}
}
}
-
- return;
}
/**
14 years
[rhq] Branch 'pc' - modules/enterprise
by jharris
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/PluginConfigurationUIBean.java | 10 ++--
modules/enterprise/gui/portal-war/src/main/webapp-filtered/WEB-INF/classes/ApplicationResources.properties | 2
modules/enterprise/gui/portal-war/src/main/webapp/admin/config/EditServerConfig.jsp | 3 +
modules/enterprise/gui/portal-war/src/main/webapp/admin/config/ServerConfigForm.jsp | 22 ++++++++++
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-config.xhtml | 8 +++
5 files changed, 40 insertions(+), 5 deletions(-)
New commits:
commit bc45354dc2691e227986b89fd86d13cb6b91bd5b
Author: Justin Harris <jharris(a)redhat.com>
Date: Mon Nov 30 15:43:59 2009 -0500
Adding in server plugins page link from the server settings page.
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 675dd9e..75747eb 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
@@ -75,8 +75,8 @@ public class PluginConfigurationUIBean {
}
public boolean isEditable() {
- return this.currentPlugin != null && (
- this.currentPlugin.getPluginConfiguration() != null ||
+ return this.currentPlugin != null &&
+ (this.currentPlugin.getPluginConfiguration() != null ||
this.currentPlugin.getScheduledJobsConfiguration() != null);
}
@@ -114,8 +114,11 @@ public class PluginConfigurationUIBean {
}
private TreeNode createPluginNode(PluginKey pluginKey) {
+ ServerPlugin plugin = serverPluginsBean.getServerPlugin(pluginKey);
+ plugin = serverPluginsBean.getServerPluginRelationships(plugin);
+
TreeNode pluginNode = new TreeNodeImpl();
- pluginNode.setData(serverPluginsBean.getServerPlugin(pluginKey));
+ pluginNode.setData(plugin);
return pluginNode;
}
@@ -123,7 +126,6 @@ public class PluginConfigurationUIBean {
public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getSource();
this.currentPlugin = (ServerPlugin) tree.getRowData();
- this.currentPlugin = serverPluginsBean.getServerPluginRelationships(currentPlugin);
lookupConfigDefinitions();
}
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp-filtered/WEB-INF/classes/ApplicationResources.properties b/modules/enterprise/gui/portal-war/src/main/webapp-filtered/WEB-INF/classes/ApplicationResources.properties
index 6ef4d86..34e1218 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp-filtered/WEB-INF/classes/ApplicationResources.properties
+++ b/modules/enterprise/gui/portal-war/src/main/webapp-filtered/WEB-INF/classes/ApplicationResources.properties
@@ -653,6 +653,8 @@ admin.settings.SNMPGenericID=Generic ID:
admin.settings.SNMPSpecificID=Specific ID:
admin.settings.SNMPAgentAddress=Agent Address:
+admin.settings.ServerPluginsConfigPropTab=Server Plugins Configuration Properties
+
admin.settings.UseCAMAuth=Use ${product.shortName} Internal Authentication
admin.settings.UseLDAPAuth=Use LDAP Authentication
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/EditServerConfig.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/EditServerConfig.jsp
index 99caf2c..e2c5478 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/EditServerConfig.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/EditServerConfig.jsp
@@ -50,6 +50,9 @@
<br>
<br>
<tiles:insert page="/admin/config/SNMPForm.jsp"/>
+<br>
+<br>
+<tiles:insert page="/admin/config/ServerConfigForm.jsp"/>
<%--<tiles:insert page="/admin/config/MiscForm.jsp"/>--%>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/ServerConfigForm.jsp b/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/ServerConfigForm.jsp
new file mode 100644
index 0000000..008f1cb
--- /dev/null
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/config/ServerConfigForm.jsp
@@ -0,0 +1,22 @@
+<%@ page language="java" %>
+<%@ page errorPage="/common/Error.jsp" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" prefix="html" %>
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<tiles:insert definition=".header.tab">
+ <tiles:put name="tabKey" value="admin.settings.ServerPluginsConfigPropTab"/>
+</tiles:insert>
+
+<table width="100%" cellpadding="0" cellspacing="0" border="0">
+ <tr>
+ <td class="BlockCheckboxLabel" align="left" colspan="4">
+ <a href="/rhq/admin/plugin/plugin-config.xhtml">Configure Server Plugins</a>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="4" class="BlockBottomLine"><html:img page="/images/spacer.gif" width="1" height="1" border="0"/></td>
+ </tr>
+</table>
\ 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 49425e4..fea1d29 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
@@ -25,7 +25,13 @@
</ui:define>
<ui:define name="breadcrumbs">
- <h:outputLink value="plugin-config.xhtml" >Plugin Configuration</h:outputLink>
+ <h:outputLink value="/admin/config/Config.do?mode=edit">
+ <h:outputText value="Server Settings"/>
+ </h:outputLink>
+ >
+ <h:outputLink value="plugin-config.xhtml">
+ <h:outputText value="Server Plugins Configuration"/>
+ </h:outputLink>
</ui:define>
<ui:define name="body">
14 years