[rhq] Branch 'resource-upgrade' - 8 commits - modules/core modules/enterprise
by lkrejci
modules/core/plugin-container/pom.xml | 100 ++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java | 164 ++--
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java | 223 +++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java | 344 ++------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java | 410 ++++++++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java | 80 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java | 67 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java | 63 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml | 39
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml | 32
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml | 31
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml | 32
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml | 31
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml | 25
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml | 28
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml | 25
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml | 45 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml | 43 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java | 8
19 files changed, 1454 insertions(+), 336 deletions(-)
New commits:
commit 14fd25e86c1a4013c1047c343f3860720a3f9c68
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Oct 1 12:55:37 2010 +0200
Adapted the resource upgrade test infrastructure to work with the new requirements of the failure handling tests and added the first round of the failure handling tests.
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
index adb3989..39597ee 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
@@ -59,68 +59,69 @@ public class FakeServerInventory {
private Map<String, Resource> resourceStore = new HashMap<String, Resource>();
private int counter;
private boolean failing;
-
+
private static final Comparator<Resource> ID_COMPARATOR = new Comparator<Resource>() {
public int compare(Resource o1, Resource o2) {
return o1.getId() - o2.getId();
}
};
-
+
private static final Comparator<Resource> RESOURCE_TYPE_COMPARATOR = new Comparator<Resource>() {
public int compare(Resource o1, Resource o2) {
return o1.getResourceType().equals(o2.getResourceType()) ? 0 : o1.getId() - o2.getId();
}
};
-
+
public FakeServerInventory() {
this(false);
}
-
+
public FakeServerInventory(boolean failing) {
this.failing = failing;
}
-
+
//need to synchronize, because resource upgrade is async and can overlap with
//resource discovery.
public synchronized CustomAction mergeInventoryReport(final InventoryStatus requiredInventoryStatus) {
return new CustomAction("updateServerSideInventory") {
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
+
InventoryReport inventoryReport = (InventoryReport) invocation.getParameter(0);
-
- for(Resource res : inventoryReport.getAddedRoots()) {
+
+ for (Resource res : inventoryReport.getAddedRoots()) {
+ Resource persisted = fakePersist(res, requiredInventoryStatus, new HashSet<String>());
+
if (res.getParentResource() == Resource.ROOT) {
- platform = fakePersist(res, requiredInventoryStatus, new HashSet<String>());
- break;
+ platform = persisted;
}
}
return getSyncInfo();
- }
+ }
};
}
-
+
public synchronized CustomAction clearPlatform() {
return new CustomAction("updateServerSideInventory - report platform deleted on the server") {
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
+
platform = null;
-
+
return getSyncInfo();
}
};
}
-
+
public synchronized CustomAction upgradeResources() {
return new CustomAction("upgradeServerSideInventory") {
- @SuppressWarnings({"serial", "unchecked"})
+ @SuppressWarnings({ "serial", "unchecked" })
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
+
Set<ResourceUpgradeRequest> requests = (Set<ResourceUpgradeRequest>) invocation.getParameter(0);
Set<ResourceUpgradeResponse> responses = new HashSet<ResourceUpgradeResponse>();
-
+
for (final ResourceUpgradeRequest request : requests) {
Resource resource = findResource(platform, new Resource() {
public int getId() {
@@ -134,16 +135,18 @@ public class FakeServerInventory {
if (request.getNewName() != null) {
resource.setName(request.getNewName());
}
-
+
if (request.getNewResourceKey() != null) {
resource.setResourceKey(request.getNewResourceKey());
}
-
+
if (request.getUpgradeErrorMessage() != null) {
- ResourceError error = new ResourceError(resource, ResourceErrorType.UPGRADE, request.getUpgradeErrorMessage(), request.getUpgradeErrorStackTrace(), request.getTimestamp());
+ ResourceError error = new ResourceError(resource, ResourceErrorType.UPGRADE,
+ request.getUpgradeErrorMessage(), request.getUpgradeErrorStackTrace(),
+ request.getTimestamp());
resource.getResourceErrors().add(error);
}
-
+
ResourceUpgradeResponse resp = new ResourceUpgradeResponse();
resp.setResourceId(resource.getId());
resp.setUpgradedResourceName(resource.getName());
@@ -156,21 +159,21 @@ public class FakeServerInventory {
}
};
}
-
+
public synchronized CustomAction getResources() {
return new CustomAction("getResources") {
@SuppressWarnings("unchecked")
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
- Set<Integer> resourceIds = (Set<Integer>)invocation.getParameter(0);
+
+ Set<Integer> resourceIds = (Set<Integer>) invocation.getParameter(0);
boolean includeDescendants = (Boolean) invocation.getParameter(1);
-
+
return getResources(resourceIds, includeDescendants);
}
- };
+ };
}
-
+
public boolean isFailing() {
return failing;
}
@@ -191,12 +194,12 @@ public class FakeServerInventory {
}
return result;
}
-
+
@SuppressWarnings("serial")
- private Set<Resource> getResources(Set<Integer> resourceIds, boolean includeDescendants) {
+ private Set<Resource> getResources(Set<Integer> resourceIds, boolean includeDescendants) {
Set<Resource> result = new HashSet<Resource>();
-
- for(final Integer id : resourceIds) {
+
+ for (final Integer id : resourceIds) {
Resource r = findResource(platform, new Resource() {
public int getId() {
return id;
@@ -204,19 +207,20 @@ public class FakeServerInventory {
}, ID_COMPARATOR);
if (r != null) {
result.add(r);
-
+
if (includeDescendants) {
- for(Resource child : r.getChildResources()) {
+ for (Resource child : r.getChildResources()) {
result.addAll(getResources(Collections.singleton(child.getId()), true));
}
}
}
}
-
+
return result;
}
-
- private Resource fakePersist(Resource agentSideResource, InventoryStatus requiredInventoryStatus, Set<String> inProgressUUIds) {
+
+ private Resource fakePersist(Resource agentSideResource, InventoryStatus requiredInventoryStatus,
+ Set<String> inProgressUUIds) {
Resource persisted = resourceStore.get(agentSideResource.getUuid());
if (!inProgressUUIds.add(agentSideResource.getUuid())) {
return persisted;
@@ -237,94 +241,114 @@ public class FakeServerInventory {
persisted.setInventoryStatus(requiredInventoryStatus);
persisted.setResourceKey(agentSideResource.getResourceKey());
persisted.setResourceType(agentSideResource.getResourceType());
-
+
Resource parent = agentSideResource.getParentResource();
if (parent != null && parent != Resource.ROOT) {
- persisted.setParentResource(fakePersist(agentSideResource.getParentResource(), requiredInventoryStatus, inProgressUUIds));
+ persisted.setParentResource(fakePersist(agentSideResource.getParentResource(), requiredInventoryStatus,
+ inProgressUUIds));
} else {
persisted.setParentResource(parent);
}
Set<Resource> childResources = new HashSet<Resource>();
persisted.setChildResources(childResources);
- for(Resource child : agentSideResource.getChildResources()) {
+ for (Resource child : agentSideResource.getChildResources()) {
childResources.add(fakePersist(child, requiredInventoryStatus, inProgressUUIds));
}
-
+
inProgressUUIds.remove(agentSideResource.getUuid());
-
+
return persisted;
}
-
+
private ResourceSyncInfo getSyncInfo() {
return platform != null ? convert(platform) : null;
}
-
+
private void throwIfFailing() {
if (failing) {
throw new RuntimeException("Fake server inventory is in the failing mode.");
}
}
-
+
private static ResourceSyncInfo convert(Resource root) {
+ return convertInternal(root, new HashMap<String, ResourceSyncInfo>());
+ }
+
+ private static ResourceSyncInfo convertInternal(Resource root, Map<String, ResourceSyncInfo> intermediateResults) {
+ ResourceSyncInfo ret = intermediateResults.get(root.getUuid());
+
+ if (ret != null) {
+ return ret;
+ }
+
try {
- ResourceSyncInfo ret = new ResourceSyncInfo();
-
+ ret = new ResourceSyncInfo();
+
+ intermediateResults.put(root.getUuid(), ret);
+
Class<ResourceSyncInfo> clazz = ResourceSyncInfo.class;
getPrivateField(clazz, "id").set(ret, root.getId());
getPrivateField(clazz, "uuid").set(ret, root.getUuid());
getPrivateField(clazz, "mtime").set(ret, root.getMtime());
getPrivateField(clazz, "inventoryStatus").set(ret, root.getInventoryStatus());
- getPrivateField(clazz, "parent").set(ret, null);
-
+
+ ResourceSyncInfo parent = root.getParentResource() == null ? null : convertInternal(
+ root.getParentResource(), intermediateResults);
+
+ getPrivateField(clazz, "parent").set(ret, parent);
+
Set<ResourceSyncInfo> children = new LinkedHashSet<ResourceSyncInfo>();
- for(Resource child : root.getChildResources()) {
- ResourceSyncInfo syncChild = convert(child);
- getPrivateField(clazz, "parent").set(syncChild, ret);
-
- children.add(convert(child));
- }
+ for (Resource child : root.getChildResources()) {
+ ResourceSyncInfo syncChild = convertInternal(child, intermediateResults);
+
+ children.add(syncChild);
+ }
getPrivateField(clazz, "childSyncInfos").set(ret, children);
-
+
return ret;
} catch (Exception e) {
fail("Failed to convert resource " + root + " to a ResourceSyncInfo. This should not happen.", e);
return null;
}
- }
-
+ }
+
private static Field getPrivateField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
Field field = clazz.getDeclaredField(fieldName);
if (!field.isAccessible()) {
field.setAccessible(true);
}
-
+
return field;
}
-
+
private static Resource findResource(Resource root, Resource template, Comparator<Resource> comparator) {
- if (root == null) return null;
+ if (root == null)
+ return null;
if (comparator.compare(root, template) == 0) {
return root;
} else {
- for(Resource child : root.getChildResources()) {
+ for (Resource child : root.getChildResources()) {
Resource found = findResource(child, template, comparator);
- if (found != null) return found;
+ if (found != null)
+ return found;
}
}
-
+
return null;
- }
-
- private static void findResources(Resource root, Resource template, Set<Resource> result, Comparator<Resource> comparator) {
- if (root == null) return;
+ }
+
+ private static void findResources(Resource root, Resource template, Set<Resource> result,
+ Comparator<Resource> comparator) {
+ if (root == null)
+ return;
if (comparator.compare(root, template) == 0) {
result.add(root);
} else {
- for(Resource child : root.getChildResources()) {
+ for (Resource child : root.getChildResources()) {
findResources(child, template, result, comparator);
}
- }
+ }
}
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
index 25eca30..5949b76 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
@@ -19,11 +19,29 @@
package org.rhq.core.pc.upgrade;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
import org.testng.annotations.Test;
+import org.rhq.core.clientapi.server.discovery.InvalidInventoryReportException;
+import org.rhq.core.clientapi.server.discovery.InventoryReport;
+import org.rhq.core.domain.resource.InventoryStatus;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.pluginapi.upgrade.ResourceUpgradeFacet;
+
/**
* The plugins and their resource types form the following dependency structure:
* <pre>
@@ -35,6 +53,10 @@ import org.testng.annotations.Test;
* </pre>
* The dependencies in the above "chart" are formed using either the <code><runs-inside></code>
* or <code>sourcePlugin/sourceType</code> approaches just to test that both are handled correctly.
+ * <p>
+ * The <code>parentdep</code>, <code>parentsibling</code>, <code>test</code> and <code>sibling</code> plugins are present
+ * in two versions and support the {@link ResourceUpgradeFacet}, while the rest of the plugins is
+ * present only in single version.
*
* @author Lukas Krejci
*/
@@ -53,29 +75,149 @@ public class ResourceUpgradeFailureHandlingTest extends ResourceUpgradeTestBase
private static final String TEST_V1_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-test-1.0.0.jar";
private static final String TEST_V2_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-test-2.0.0.jar";
+ private static final String UPGRADED_RESOURCE_KEY_PREFIX = "UPGRADED";
+
+ private static final HashMap<String, List<String>> DEPS;
+
+ static {
+ DEPS = new HashMap<String, List<String>>();
+
+ DEPS.put(BASE_PLUGIN_NAME, Collections.<String> emptyList());
+ DEPS.put(PARENT_DEP_V1_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME));
+ DEPS.put(PARENT_DEP_V2_PLUGIN_NAME, DEPS.get(PARENT_DEP_V1_PLUGIN_NAME));
+ DEPS.put(PARENT_SIBLING_V1_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME));
+ DEPS.put(PARENT_SIBLING_V2_PLUGIN_NAME, DEPS.get(PARENT_SIBLING_V1_PLUGIN_NAME));
+ DEPS.put(ROOT_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME));
+ DEPS.put(SIBLING_V1_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME));
+ DEPS.put(SIBLING_V2_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME, PARENT_DEP_V2_PLUGIN_NAME));
+ DEPS.put(TEST_V1_PLUGIN_NAME,
+ Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME, SIBLING_V1_PLUGIN_NAME));
+ DEPS.put(TEST_V2_PLUGIN_NAME,
+ Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME, SIBLING_V2_PLUGIN_NAME));
+ }
+
+ private static final ResType TEST_TYPE = new ResType("TestResource", "test");
+ private static final ResType SIBLING_TYPE = new ResType("TestResourceSibling", "test");
+ private static final ResType PARENT_TYPE = new ResType("TestResourceParent", "test");
+ private static final ResType PARENT_DEP_TYPE = new ResType("ParentDependency", "parentdep");
+ private static final ResType PARENT_SIBLING_TYPE = new ResType("ParentDepSibling", "parentsibling");
+ private static final ResType ROOT_TYPE = new ResType("Root", "root");
+
protected Collection<String> getRequiredPlugins() {
return Arrays.asList(BASE_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME, PARENT_DEP_V2_PLUGIN_NAME,
PARENT_SIBLING_V1_PLUGIN_NAME, PARENT_SIBLING_V2_PLUGIN_NAME, ROOT_PLUGIN_NAME, SIBLING_V1_PLUGIN_NAME,
SIBLING_V2_PLUGIN_NAME, TEST_V1_PLUGIN_NAME, TEST_V2_PLUGIN_NAME);
}
-
+
@Test
- public void testSuccess() {
- //TODO implement
- //check that all the stuff is properly upgraded on success
+ public void testSuccess() throws Exception {
+ setCurrentServerSideInventory(new FakeServerInventory());
+
+ //let it all run in v1
+ executeTestWithPlugins(getAllDepsFor(TEST_V1_PLUGIN_NAME, PARENT_SIBLING_V1_PLUGIN_NAME),
+ new AbstractTestPayload(true, Collections.<ResType> emptyList()) {
+ public void test(Map<ResType, Set<Resource>> resourceUpgradeTestResources) {
+ }
+
+ public Expectations getExpectations(Mockery context) throws Exception {
+ return new Expectations() {
+ {
+ defineDefaultExpectations(this);
+ }
+ };
+ }
+ });
+
+ //now let's run with v2 plugins and check the layout of the inventory
+ executeTestWithPlugins(
+ getAllDepsFor(TEST_V2_PLUGIN_NAME, PARENT_SIBLING_V2_PLUGIN_NAME),
+ new AbstractTestPayload(false, Arrays.asList(TEST_TYPE, SIBLING_TYPE, PARENT_TYPE, PARENT_DEP_TYPE,
+ PARENT_SIBLING_TYPE, ROOT_TYPE)) {
+
+ public void test(Map<ResType, Set<Resource>> resources) {
+ checkPresenceOfResourceTypes(resources, getExpectedResourceTypes());
+
+ checkNumberOfResources(resources, ROOT_TYPE, 1);
+ checkNumberOfResources(resources, PARENT_DEP_TYPE, 1);
+ checkNumberOfResources(resources, PARENT_SIBLING_TYPE, 1);
+ checkNumberOfResources(resources, PARENT_TYPE, 2);
+ checkNumberOfResources(resources, SIBLING_TYPE, 30);
+ checkNumberOfResources(resources, TEST_TYPE, 30);
+
+ //check that the resources are upgraded
+ checkResourcesUpgraded(resources.get(PARENT_SIBLING_TYPE));
+ checkResourcesUpgraded(resources.get(PARENT_TYPE));
+ checkResourcesUpgraded(resources.get(SIBLING_TYPE));
+ checkResourcesUpgraded(resources.get(TEST_TYPE));
+ }
+
+ public Expectations getExpectations(Mockery context) throws Exception {
+ return new Expectations() {
+ {
+ defineDefaultExpectations(this);
+ }
+ };
+ }
+ });
}
-
+
@Test
public void testFailureOnLeaf() {
//TODO implement
//check that the system behaves correctly if there is an upgrade failure
//at the leaf node of the plugin dep graph
}
-
+
@Test
public void testFailureOnDependencies() {
//TODO implement
//check that stuff works if there is an upgrade failure on some of the resources
//in the plugin some "in the middle" of the plugin dep graph
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void defineDefaultExpectations(Expectations expectations) {
+ super.defineDefaultExpectations(expectations);
+ try {
+ expectations.allowing(getCurrentDiscoveryServerService())
+ .mergeInventoryReport(expectations.with(Expectations.any(InventoryReport.class)));
+ expectations.will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
+
+ expectations.allowing(getCurrentDiscoveryServerService()).upgradeResources(expectations.with(Expectations.any(Set.class)));
+ expectations.will(getCurrentServerSideInventory().upgradeResources());
+
+ expectations.allowing(getCurrentDiscoveryServerService()).postProcessNewlyCommittedResources(
+ expectations.with(Expectations.any(Set.class)));
+
+ } catch (InvalidInventoryReportException e) {
+ //this is not going to happen because we're mocking the invocation
+ }
+ }
+
+ private Set<String> getAllDepsFor(String... plugins) {
+ HashSet<String> deps = new HashSet<String>();
+ for (String plugin : plugins) {
+ deps.add(plugin);
+ deps.addAll(DEPS.get(plugin));
+ }
+
+ return deps;
+ }
+
+ private static void checkPresenceOfResourceTypes(Map<ResType, Set<Resource>> resources, Set<ResType> expectedTypes) {
+ for (ResType resType : expectedTypes) {
+ assertNotNull(resources.get(resType), "Expecting some resources of type " + resType);
+ }
+ }
+
+ private static void checkNumberOfResources(Map<ResType, Set<Resource>> resources, ResType type, int count) {
+ assertEquals(resources.get(type).size(), count, "Unexpected number of " + type + " discovered.");
+ }
+
+ private static void checkResourcesUpgraded(Set<Resource> resources) {
+ for(Resource res : resources) {
+ assertTrue(res.getResourceKey().startsWith(UPGRADED_RESOURCE_KEY_PREFIX), "Resource " + res + " doesn't seem to be upgraded even though it should.");
+ }
+ }
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index 8cfec36..d47d00c 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -31,6 +31,8 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.jmock.Expectations;
@@ -54,8 +56,13 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private static final String PLUGIN_V2_FILENAME = "/resource-upgrade-test-plugin-2.0.0.jar";
private static final String FAILING_PLUGIN_FILE_NAME = "/resource-upgrade-test-plugin-3.0.0.jar";
- static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
- static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME = "ResourceUpgradeTest";
+ private static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
+ private static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME = "ResourceUpgradeTest";
+ private static final ResType SINGLETON_TYPE = new ResType(SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME);
+
+ private static List<ResType> getMyExpectedTypes() {
+ return Arrays.asList(SINGLETON_TYPE);
+ }
protected Collection<String> getRequiredPlugins() {
return Arrays.asList(PLUGIN_V1_FILENAME, PLUGIN_V2_FILENAME, FAILING_PLUGIN_FILE_NAME);
@@ -66,11 +73,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.NEW);
- TestPayload testNoChange = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ TestPayload testNoChange = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources) {
assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource = discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(), "resource-key-v1");
assertEquals(discoveredResource.getName(), "resource-name-v1");
@@ -111,11 +118,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
getCurrentServerSideInventory().setFailing(true);
- TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ TestPayload test = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources) {
assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource = discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(), "resource-key-v1");
assertEquals(discoveredResource.getName(), "resource-name-v1");
@@ -145,11 +152,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ TestPayload test = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources) {
assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource = discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(), "resource-key-v2");
assertEquals(discoveredResource.getName(), "resource-name-v2");
@@ -193,11 +200,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> resourceUpgradeTestResources) {
+ TestPayload test = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> resourceUpgradeTestResources) {
assertEquals(resourceUpgradeTestResources.size(), 1, "Expected single test resource but multiple found.");
- Resource discoveredResource = resourceUpgradeTestResources.iterator().next();
+ Resource discoveredResource = resourceUpgradeTestResources.get(SINGLETON_TYPE).iterator().next();
assertTrue(discoveredResource.getResourceErrors().size() > 0, "There should be upgrade errors persisted on the server side.");
@@ -231,11 +238,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private void initialSyncAndDiscovery(final InventoryStatus requiredInventoryStatus) throws Exception {
cleanDataDir();
- executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), new AbstractTestPayload(true, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), new AbstractTestPayload(true, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources) {
assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource = discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(), "resource-key-v1");
assertEquals(discoveredResource.getName(), "resource-name-v1");
@@ -260,11 +267,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private void upgradeTest(boolean clearInventoryDat) throws Exception {
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), new AbstractTestPayload(clearInventoryDat, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), new AbstractTestPayload(clearInventoryDat, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources) {
assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource = discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(), "resource-key-v2");
assertEquals(discoveredResource.getName(), "resource-name-v2");
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
index 3aa772b..0aefafd 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
@@ -25,6 +25,9 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
@@ -73,6 +76,78 @@ public abstract class ResourceUpgradeTestBase {
private ResourceFactoryServerService currentResourceFactoryServerService;
private FakeServerInventory currentServerSideInventory;
+ protected static class ResType {
+ private String resourceTypeName;
+ private String resourceTypePluginName;
+
+ public ResType(String resourceTypeName, String resourceTypePluginName) {
+ super();
+ this.resourceTypeName = resourceTypeName;
+ this.resourceTypePluginName = resourceTypePluginName;
+ }
+
+ public String getResourceTypeName() {
+ return resourceTypeName;
+ }
+
+ public String getResourceTypePluginName() {
+ return resourceTypePluginName;
+ }
+
+ @Override
+ public int hashCode() {
+ return resourceTypeName.hashCode() * resourceTypePluginName.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+
+ if (!(other instanceof ResType)) {
+ return false;
+ }
+
+ ResType o = (ResType)other;
+
+ return resourceTypeName.equals(o.getResourceTypeName()) && resourceTypePluginName.equals(o.getResourceTypePluginName());
+ }
+
+ @Override
+ public String toString() {
+ return "ResType[name='" + resourceTypeName + "', plugin='" + resourceTypePluginName + "']";
+ }
+ }
+
+ protected interface TestPayload {
+ Expectations getExpectations(Mockery context) throws Exception;
+
+ void test(Map<ResType,Set<Resource>> resourceUpgradeTestResources);
+
+ boolean isClearInventoryDat();
+
+ Set<ResType> getExpectedResourceTypes();
+ }
+
+ protected static abstract class AbstractTestPayload implements TestPayload {
+ private boolean clearInventoryDat;
+ private Set<ResType> resourceTypes;
+
+ public AbstractTestPayload(boolean clearInventoryDat, Collection<ResType> resourceTypes) {
+ this.clearInventoryDat = clearInventoryDat;
+ this.resourceTypes = new HashSet<ResType>(resourceTypes);
+ }
+
+ public boolean isClearInventoryDat() {
+ return clearInventoryDat;
+ }
+
+ public Set<ResType> getExpectedResourceTypes() {
+ return resourceTypes;
+ }
+ }
+
@BeforeClass
public void init() {
tmpDir = getTmpDirectory();
@@ -81,21 +156,21 @@ public abstract class ResourceUpgradeTestBase {
dataDir = new File(tmpDir, DATA_DIR_NAME);
assertTrue(dataDir.mkdir(), "Could not create plugin container data directory.");
}
-
+
@BeforeClass
public void verifyPluginsExist() {
for (String plugin : getRequiredPlugins()) {
verifyPluginExists(plugin);
}
}
-
+
@AfterClass
public void undeployPlugins() throws IOException {
FileUtils.deleteDirectory(tmpDir);
}
-
+
protected abstract Collection<String> getRequiredPlugins();
-
+
protected void setCurrentServerSideInventory(FakeServerInventory currentServerSideInventory) {
this.currentServerSideInventory = currentServerSideInventory;
}
@@ -103,8 +178,9 @@ public abstract class ResourceUpgradeTestBase {
protected FakeServerInventory getCurrentServerSideInventory() {
return currentServerSideInventory;
}
-
- protected void setCurrentResourceFactoryServerService(ResourceFactoryServerService currentResourceFactoryServerService) {
+
+ protected void setCurrentResourceFactoryServerService(
+ ResourceFactoryServerService currentResourceFactoryServerService) {
this.currentResourceFactoryServerService = currentResourceFactoryServerService;
}
@@ -178,24 +254,24 @@ public abstract class ResourceUpgradeTestBase {
protected static File getTmpDirectory() {
File ret = new File(System.getProperty("java.io.tmpdir"), "resource-upgrade-test" + System.currentTimeMillis());
-
+
while (ret.exists() || !ret.mkdir()) {
ret = new File(System.getProperty("java.io.tmpdir"), "resource-upgrade-test" + System.currentTimeMillis());
}
-
+
return ret;
}
private PluginContainerConfiguration createPluginContainerConfiguration(Mockery context) throws Exception {
PluginContainerConfiguration conf = new PluginContainerConfiguration();
-
+
conf.setPluginDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
conf.setDataDirectory(new File(tmpDir, DATA_DIR_NAME));
conf.setTemporaryDirectory(new File(tmpDir, TMP_DIR_NAME));
conf.setInsideAgent(true); //pc must think it's inside an agent so that it persists the inventory between restarts
conf.setPluginFinder(new FileSystemPluginFinder(conf.getPluginDirectory()));
- conf.setCreateResourceClassloaders(false);
-
+ conf.setCreateResourceClassloaders(false);
+
//we're not interested in any scans happening out of our control
conf.setAvailabilityScanInitialDelay(Long.MAX_VALUE);
conf.setConfigurationDiscoveryInitialDelay(Long.MAX_VALUE);
@@ -204,7 +280,7 @@ public abstract class ResourceUpgradeTestBase {
conf.setMeasurementCollectionInitialDelay(Long.MAX_VALUE);
conf.setServerDiscoveryInitialDelay(Long.MAX_VALUE);
conf.setServiceDiscoveryInitialDelay(Long.MAX_VALUE);
-
+
setCurrentBundleServerService(context.mock(BundleServerService.class));
setCurrentConfigurationServerService(context.mock(ConfigurationServerService.class));
setCurrentContentServerService(context.mock(ContentServerService.class));
@@ -214,7 +290,7 @@ public abstract class ResourceUpgradeTestBase {
setCurrentMeasurementServerService(context.mock(MeasurementServerService.class));
setCurrentOperationServerService(context.mock(OperationServerService.class));
setCurrentResourceFactoryServerService(context.mock(ResourceFactoryServerService.class));
-
+
ServerServices serverServices = new ServerServices();
serverServices.setBundleServerService(getCurrentBundleServerService());
serverServices.setConfigurationServerService(getCurrentConfigurationServerService());
@@ -225,9 +301,9 @@ public abstract class ResourceUpgradeTestBase {
serverServices.setMeasurementServerService(getCurrentMeasurementServerService());
serverServices.setOperationServerService(getCurrentOperationServerService());
serverServices.setResourceFactoryServerService(getCurrentResourceFactoryServerService());
-
+
conf.setServerServices(serverServices);
-
+
return conf;
}
@@ -236,104 +312,76 @@ public abstract class ResourceUpgradeTestBase {
*/
protected void verifyPluginExists(String pluginResourcePath) {
URL url = getClass().getResource(pluginResourcePath);
-
+
File pluginFile = FileUtils.toFile(url);
-
+
assertTrue(pluginFile.exists(), pluginFile.getAbsoluteFile() + " plugin jar could not be found.");
}
private void copyPlugin(String pluginResourcePath, File pluginDirectory) throws IOException {
URL pluginUrl = getClass().getResource(pluginResourcePath);
-
+
File pluginFile = new File(pluginResourcePath);
String pluginFileName = pluginFile.getName();
-
- FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
- }
-
- protected interface TestPayload {
- Expectations getExpectations(Mockery context) throws Exception;
- void test(Set<Resource> resourceUpgradeTestResources);
- boolean isClearInventoryDat();
- String getResourceTypeName();
- String getResourceTypePluginName();
- }
-
- protected static abstract class AbstractTestPayload implements TestPayload {
- private boolean clearInventoryDat;
- private String resourceTypeName;
- private String resourceTypePluginName;
-
- public AbstractTestPayload(boolean clearInventoryDat, String resourceTypeName, String resourceTypePluginName) {
- this.clearInventoryDat = clearInventoryDat;
- this.resourceTypeName = resourceTypeName;
- this.resourceTypePluginName = resourceTypePluginName;
- }
-
- public boolean isClearInventoryDat() {
- return clearInventoryDat;
- }
-
- public String getResourceTypeName() {
- return resourceTypeName;
- }
-
- public String getResourceTypePluginName() {
- return resourceTypePluginName;
- }
- }
- /**
- *
- */
- public ResourceUpgradeTestBase() {
- super();
+ FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
}
private Set<Resource> getTestingResources(String resourceTypeName, String resourceTypePluginName) {
- ResourceType resType = PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName, resourceTypePluginName);
-
+ ResourceType resType = PluginContainer.getInstance().getPluginManager().getMetadataManager()
+ .getType(resourceTypeName, resourceTypePluginName);
+
return getCurrentServerSideInventory().findResourcesByType(resType);
}
protected void executeTestWithPlugins(Set<String> pluginResourcePaths, TestPayload test) throws Exception {
FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
-
- for(String pluginResourcePath : pluginResourcePaths) {
+
+ for (String pluginResourcePath : pluginResourcePaths) {
copyPlugin(pluginResourcePath, pluginDir);
}
-
+
Mockery context = new Mockery();
-
+
PluginContainerConfiguration pcConfig = createPluginContainerConfiguration(context);
-
+
if (test.isClearInventoryDat()) {
File inventoryDat = new File(pcConfig.getDataDirectory(), "inventory.dat");
inventoryDat.delete();
}
-
+
context.checking(test.getExpectations(context));
-
+
PluginContainer.getInstance().setConfiguration(pcConfig);
PluginContainer.getInstance().initialize();
-
+
try {
//give the pc the time to finish resource upgrade
Thread.sleep(1000);
-
+
//execute full discovery
InventoryManager im = PluginContainer.getInstance().getInventoryManager();
im.executeServerScanImmediately();
- im.executeServiceScanImmediately();
-
- Set<Resource> resources = getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
-
+
+ //do the service scan a couple of times so that we can commit
+ //the resources deep in the type hierarchy
+ for(int i = 0; i < 10; ++i) {
+ im.executeServiceScanImmediately();
+ }
+
+ Map<ResType, Set<Resource>> resources = new HashMap<ResType, Set<Resource>>();
+
+ for(ResType type : test.getExpectedResourceTypes()) {
+ Set<Resource> rs = getTestingResources(type.getResourceTypeName(), type.getResourceTypePluginName());
+ resources.put(type, rs);
+ }
+
test.test(resources);
-
+
context.assertIsSatisfied();
} finally {
- PluginContainer.getInstance().shutdown();
- }
+ PluginContainer.getInstance().shutdown();
+ }
}
@SuppressWarnings("unchecked")
@@ -346,11 +394,13 @@ public abstract class ResourceUpgradeTestBase {
expectations.ignoring(getCurrentMeasurementServerService());
expectations.ignoring(getCurrentOperationServerService());
expectations.ignoring(getCurrentResourceFactoryServerService());
-
+
//just ignore these invocations if we get a availability scan in the PC...
- expectations.allowing(getCurrentDiscoveryServerService()).mergeAvailabilityReport(expectations.with(Expectations.any(AvailabilityReport.class)));
-
- expectations.allowing(getCurrentDiscoveryServerService()).getResources(expectations.with(Expectations.any(Set.class)), expectations.with(Expectations.any(boolean.class)));
+ expectations.allowing(getCurrentDiscoveryServerService()).mergeAvailabilityReport(
+ expectations.with(Expectations.any(AvailabilityReport.class)));
+
+ expectations.allowing(getCurrentDiscoveryServerService()).getResources(
+ expectations.with(Expectations.any(Set.class)), expectations.with(Expectations.any(boolean.class)));
expectations.will(getCurrentServerSideInventory().getResources());
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
index 61d4fe0..a03dff5 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
@@ -46,15 +46,25 @@ public class BaseDiscoveryComponent<T extends ResourceComponent> implements Reso
String keyTemplate = pluginConfig.getSimpleValue("key", null);
int count = pluginConfig.getSimple("count").getIntegerValue();
- int parentN = context.getParentResourceContext().getPluginConfiguration().getSimple("ordinal")
- .getIntegerValue();
+ int parentN = 0;
+
+ if (context.getParentResourceContext() != null) {
+ PropertySimple parentOrdinalProperty = context.getParentResourceContext().getPluginConfiguration()
+ .getSimple("ordinal");
+
+ if (parentOrdinalProperty != null) {
+ parentN = parentOrdinalProperty.getIntegerValue();
+ }
+ }
for (int i = 0; i < count; ++i) {
String key = getResourceKey(keyTemplate, i, parentN);
+ pluginConfig = context.getDefaultPluginConfiguration();
+
pluginConfig.put(new PropertySimple("ordinal", i));
-
+
DiscoveredResourceDetails detail = new DiscoveredResourceDetails(context.getResourceType(), key, key, null,
null, pluginConfig, null);
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
index beb36db..ec1cb20 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
@@ -28,34 +28,36 @@ import org.rhq.core.pluginapi.upgrade.ResourceUpgradeFacet;
*
* @author Lukas Krejci
*/
-public class BaseUpgradingDiscoveryComponent<T extends BaseResourceComponent> extends BaseDiscoveryComponent<T> implements ResourceUpgradeFacet<T> {
+public class BaseUpgradingDiscoveryComponent<T extends BaseResourceComponent> extends BaseDiscoveryComponent<T>
+ implements ResourceUpgradeFacet<T> {
public ResourceUpgradeReport upgrade(ResourceUpgradeContext<T> inventoriedResource) {
Configuration pluginConfig = inventoriedResource.getPluginConfiguration();
-
+
BaseResourceComponent<?> parent = inventoriedResource.getParentResourceComponent();
int ordinal = pluginConfig.getSimple("ordinal").getIntegerValue();
int parentOrdinal = parent == null ? 0 : parent.getOrdinal();
-
+
boolean fail = Boolean.getBoolean(pluginConfig.getSimpleValue("failUpgrade", "false"));
-
+
if (!fail && parent != null) {
fail = parent.getChildrenToFailUpgrade().contains(Integer.valueOf(ordinal));
}
-
+
if (fail) {
throw new RuntimeException("Failing the resource upgrade purposefully.");
}
-
+
String newKey = pluginConfig.getSimpleValue("upgradedKey", null);
-
+
if (newKey == null) {
return null;
}
-
+
ResourceUpgradeReport report = new ResourceUpgradeReport();
-
+
report.setNewResourceKey(getResourceKey(newKey, ordinal, parentOrdinal));
- return null;
+
+ return report;
}
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
index f5e6920..608793c 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
@@ -22,8 +22,8 @@
<plugin-configuration>
<c:simple-property name="count" default="1" />
- <c:simple-property name="key" default="test-resource-parent-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="key" default="test-resource-parent-dep-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-dep-sibling-%n,parent-%p" />
</plugin-configuration>
</server>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
index d138066..ddda11a 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
@@ -22,7 +22,7 @@
<plugin-configuration>
<c:simple-property name="count" default="1" />
- <c:simple-property name="key" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-parent-dep-sibling-%n,parent-%p" />
</plugin-configuration>
</server>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
index 44a1033..d3ea7b7 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
@@ -11,10 +11,18 @@
<depends plugin="base" useClasses="true"/>
- <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
- <service name="TestResourceSibling"
- discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent" />
+ <server name="Bogus" class="BaseDiscoveryComponent">
+ <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
+ <service name="TestResourceSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key" default="test-resource-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
+ </server>
</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
index aeab68f..f7f7a2c 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
@@ -10,10 +10,16 @@
<depends plugin="base" useClasses="true"/>
+ <server name="Bogus" class="BaseDiscoveryComponent">
<!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
<service name="TestResourceSibling"
discovery="BaseUpgradingDiscoveryComponent"
- class="BaseResourceComponent" />
-
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" /> <!-- This intentionally differs from v1 -->
+ <c:simple-property name="key" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
+ </server>
</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
index e934494..ebe9793 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
@@ -37,13 +37,8 @@
</plugin-configuration>
</service>
- <service name="TestResourceSibling" sourcePlugin="sibling" sourceType="TestResourceSibling">
- <plugin-configuration>
- <c:simple-property name="count" default="10" />
- <c:simple-property name="key" default="test-resource-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
- </service>
+ <service name="TestResourceSibling" sourcePlugin="sibling" sourceType="TestResourceSibling"
+ class="BaseResourceComponent" discovery="BaseDiscoveryComponent" />
</server>
</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
index 96658e3..3d709b0 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
@@ -26,7 +26,7 @@
</plugin-configuration>
<service name="TestResource"
- discovery="BaseDiscoveryComponent"
+ discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<plugin-configuration>
<c:simple-property name="count" default="15" /> <!-- This intentionally differs from v1 -->
@@ -35,13 +35,8 @@
</service>
- <service name="TestResourceSibling" sourcePlugin="sibling" sourceType="TestResourceSibling">
- <plugin-configuration>
- <c:simple-property name="count" default="15" /> <!-- This intentionally differs from v1 -->
- <c:simple-property name="key" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
- </service>
-
+ <service name="TestResourceSibling" sourcePlugin="sibling" sourceType="TestResourceSibling"
+ class="BaseResourceComponent" discovery="BaseUpgradingDiscoveryComponent" />
</server>
</plugin>
commit c99d68dd036f243a2f28e000e10385d27bbdb785
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:53:45 2010 +0200
Adding a skeleton of what will need to be tested for upgrade failure handling.
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
new file mode 100644
index 0000000..25eca30
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
@@ -0,0 +1,81 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.testng.annotations.Test;
+
+/**
+ * The plugins and their resource types form the following dependency structure:
+ * <pre>
+ * Root(root)
+ * / \
+ * ParentDependency(parentdep) ParentDepSibling(parentsibling)
+ * / \
+ * TestResource(test) TestResourceSibling(sibling)
+ * </pre>
+ * The dependencies in the above "chart" are formed using either the <code><runs-inside></code>
+ * or <code>sourcePlugin/sourceType</code> approaches just to test that both are handled correctly.
+ *
+ * @author Lukas Krejci
+ */
+@Test(sequential = true, invocationCount = 1)
+public class ResourceUpgradeFailureHandlingTest extends ResourceUpgradeTestBase {
+
+ //plugin names
+ private static final String BASE_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-base-1.0.0.jar";
+ private static final String PARENT_DEP_V1_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-parentdep-1.0.0.jar";
+ private static final String PARENT_DEP_V2_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-parentdep-2.0.0.jar";
+ private static final String PARENT_SIBLING_V1_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-parentsibling-1.0.0.jar";
+ private static final String PARENT_SIBLING_V2_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-parentsibling-2.0.0.jar";
+ private static final String ROOT_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-root-1.0.0.jar";
+ private static final String SIBLING_V1_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-sibling-1.0.0.jar";
+ private static final String SIBLING_V2_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-sibling-2.0.0.jar";
+ private static final String TEST_V1_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-test-1.0.0.jar";
+ private static final String TEST_V2_PLUGIN_NAME = "/resource-upgrade-test-plugin-multi-test-2.0.0.jar";
+
+ protected Collection<String> getRequiredPlugins() {
+ return Arrays.asList(BASE_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME, PARENT_DEP_V2_PLUGIN_NAME,
+ PARENT_SIBLING_V1_PLUGIN_NAME, PARENT_SIBLING_V2_PLUGIN_NAME, ROOT_PLUGIN_NAME, SIBLING_V1_PLUGIN_NAME,
+ SIBLING_V2_PLUGIN_NAME, TEST_V1_PLUGIN_NAME, TEST_V2_PLUGIN_NAME);
+ }
+
+ @Test
+ public void testSuccess() {
+ //TODO implement
+ //check that all the stuff is properly upgraded on success
+ }
+
+ @Test
+ public void testFailureOnLeaf() {
+ //TODO implement
+ //check that the system behaves correctly if there is an upgrade failure
+ //at the leaf node of the plugin dep graph
+ }
+
+ @Test
+ public void testFailureOnDependencies() {
+ //TODO implement
+ //check that stuff works if there is an upgrade failure on some of the resources
+ //in the plugin some "in the middle" of the plugin dep graph
+ }
+}
commit 4f504f582fc9040bcf5ed7f7dd24cfd3bc2adbad
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:49:24 2010 +0200
some more minor changes to class structure and plugin names.
diff --git a/modules/core/plugin-container/pom.xml b/modules/core/plugin-container/pom.xml
index 035bf36..4d6e753 100644
--- a/modules/core/plugin-container/pom.xml
+++ b/modules/core/plugin-container/pom.xml
@@ -281,7 +281,7 @@
<!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/v1/org/rhq/core/pc/upgrade/plugins/multi/v1">
<fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v1/*.class" />
</copy> -->
- <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-1.0.0.jar">
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-test-1.0.0.jar">
<fileset dir="${project.build.testOutputDirectory}/tmp/multi/v1" includes="**/*.class,**/rhq-plugin.xml" />
</jar>
@@ -291,7 +291,7 @@
<!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/v2/org/rhq/core/pc/upgrade/plugins/multi/v2">
<fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v2/*.class" />
</copy> -->
- <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-2.0.0.jar">
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-test-2.0.0.jar">
<fileset dir="${project.build.testOutputDirectory}/tmp/multi/v2" includes="**/*.class,**/rhq-plugin.xml" />
</jar>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index e13ea3d..8cfec36 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -28,6 +28,8 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@@ -38,7 +40,6 @@ import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.inventory.ResourceContainer;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
@@ -56,11 +57,8 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME = "ResourceUpgradeTest";
- @BeforeClass
- public void sanityCheck() {
- verifyPluginExists(PLUGIN_V1_FILENAME);
- verifyPluginExists(PLUGIN_V2_FILENAME);
- verifyPluginExists(FAILING_PLUGIN_FILE_NAME);
+ protected Collection<String> getRequiredPlugins() {
+ return Arrays.asList(PLUGIN_V1_FILENAME, PLUGIN_V2_FILENAME, FAILING_PLUGIN_FILE_NAME);
}
@Test
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
index f03f2a4..3aa772b 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.Collection;
import java.util.Set;
import org.apache.commons.io.FileUtils;
@@ -53,7 +54,7 @@ import org.testng.annotations.BeforeClass;
*
* @author Lukas Krejci
*/
-public class ResourceUpgradeTestBase {
+public abstract class ResourceUpgradeTestBase {
private static final String PLUGINS_DIR_NAME = "plugins";
private static final String DATA_DIR_NAME = "data";
@@ -81,11 +82,20 @@ public class ResourceUpgradeTestBase {
assertTrue(dataDir.mkdir(), "Could not create plugin container data directory.");
}
+ @BeforeClass
+ public void verifyPluginsExist() {
+ for (String plugin : getRequiredPlugins()) {
+ verifyPluginExists(plugin);
+ }
+ }
+
@AfterClass
public void undeployPlugins() throws IOException {
FileUtils.deleteDirectory(tmpDir);
}
+ protected abstract Collection<String> getRequiredPlugins();
+
protected void setCurrentServerSideInventory(FakeServerInventory currentServerSideInventory) {
this.currentServerSideInventory = currentServerSideInventory;
}
commit b97e79bcbd5c557fba29030f7aa0f8b4c629c56f
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:48:28 2010 +0200
Simplify plugin names, declare correct discovery components for upgrade failure test plugins.
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
index 7edfba1..d262c75 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestBase"
+<plugin name="base"
displayName=""
description=""
package="org.rhq.core.pc.upgrade.plugins.multi.base"
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
index 3612974..8cadc84 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentDep"
+<plugin name="parentdep"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDependency"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
index 6b95114..8169122 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentDep"
+<plugin name="parentdep"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDependency"
- discovery="BaseDiscoveryComponent"
+ discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
index fbade54..f5e6920 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentSibling"
+<plugin name="parentsibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDepSibling"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
index f16d526..d138066 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentSibling"
+<plugin name="parentsibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDepSibling"
- discovery="BaseDiscoveryComponent"
+ discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
index b5efbb1..e95c9bd 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestRoot"
+<plugin name="root"
displayName=""
description=""
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,6 +9,8 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
+ <depends plugin="base" useClasses="true"/>
+
<server name="Root"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
index f87ef4d..44a1033 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestSibling"
+<plugin name="sibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,30 +9,12 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
- <server name="TestResourceParentSibling"
- discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent">
-
- <plugin-configuration>
- <c:simple-property name="count" default="2" />
- <c:simple-property name="key" default="test-resource-parent-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- <service name="TestResourceSibling"
+ <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
+ <service name="TestResourceSibling"
discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="10" />
- <c:simple-property name="key" default="test-resource-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- </service>
- </server>
+ class="BaseResourceComponent" />
</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
index e6ab95f..aeab68f 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestSibling"
+<plugin name="sibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -8,34 +8,12 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
- <server name="TestResourceParentSibling"
- discovery="BaseUpgradingDiscoveryComponent"
- class="BaseResourceComponent">
-
- <runs-inside>
- <parent-resource-type name="ParentDependency" plugin="ResourceUpgradeMultiTestParentDep"/>
- </runs-inside>
-
- <plugin-configuration>
- <c:simple-property name="count" default="2" />
- <c:simple-property name="key" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- <service name="TestResourceSibling"
- discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="15" />
- <c:simple-property name="key" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- </service>
-
-
- </server>
+ <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
+ <service name="TestResourceSibling"
+ discovery="BaseUpgradingDiscoveryComponent"
+ class="BaseResourceComponent" />
</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
index 32ad438..e934494 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTest"
+<plugin name="test"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,16 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="parentdep"/>
+ <depends plugin="sibling" />
<server name="TestResourceParent"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="ParentDependency" plugin="ResourceUpgradeMultiTestParentDep"/>
+ <parent-resource-type name="ParentDependency" plugin="parentdep"/>
</runs-inside>
<plugin-configuration>
@@ -29,13 +30,20 @@
<service name="TestResource"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="10" />
- <c:simple-property name="key" default="test-resource-%n,parent-%p" />
- <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-%n,parent-%p" />
- </plugin-configuration>
-
- </service>
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key" default="test-resource-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
+
+ <service name="TestResourceSibling" sourcePlugin="sibling" sourceType="TestResourceSibling">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key" default="test-resource-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
</server>
</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
index 824d3fe..96658e3 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTest"
+<plugin name="test"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -8,15 +8,16 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="parentdep"/>
+ <depends plugin="sibling"/>
<server name="TestResourceParent"
discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="ParentDependency" plugin="ResourceUpgradeMultiTestParentDep"/>
+ <parent-resource-type name="ParentDependency" plugin="parentdep"/>
</runs-inside>
<plugin-configuration>
@@ -27,13 +28,19 @@
<service name="TestResource"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="15" />
- <c:simple-property name="key" default="UPGRADED-test-resource-%n,parent-%p" />
- </plugin-configuration>
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" /> <!-- This intentionally differs from v1 -->
+ <c:simple-property name="key" default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
</service>
+ <service name="TestResourceSibling" sourcePlugin="sibling" sourceType="TestResourceSibling">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" /> <!-- This intentionally differs from v1 -->
+ <c:simple-property name="key" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
</server>
commit 097f744dec27c5584cf6203bbaff6fc041753b26
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:12:09 2010 +0200
Extracted a base class from the upgrade test in preparation for adding another round of tests.
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index 0a2a660..e13ea3d 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -23,43 +23,23 @@
package org.rhq.core.pc.upgrade;
-import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import java.io.File;
-import java.io.IOException;
-import java.net.URL;
import java.util.Collections;
import java.util.Set;
-import org.apache.commons.io.FileUtils;
import org.jmock.Expectations;
import org.jmock.Mockery;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.rhq.core.clientapi.server.bundle.BundleServerService;
-import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
-import org.rhq.core.clientapi.server.content.ContentServerService;
-import org.rhq.core.clientapi.server.core.CoreServerService;
-import org.rhq.core.clientapi.server.discovery.DiscoveryServerService;
import org.rhq.core.clientapi.server.discovery.InventoryReport;
-import org.rhq.core.clientapi.server.event.EventServerService;
-import org.rhq.core.clientapi.server.inventory.ResourceFactoryServerService;
-import org.rhq.core.clientapi.server.measurement.MeasurementServerService;
-import org.rhq.core.clientapi.server.operation.OperationServerService;
-import org.rhq.core.domain.discovery.AvailabilityReport;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.PluginContainer;
-import org.rhq.core.pc.PluginContainerConfiguration;
-import org.rhq.core.pc.ServerServices;
-import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
-import org.rhq.core.pc.plugin.FileSystemPluginFinder;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
/**
* Test cases for resource upgrade.
@@ -67,39 +47,14 @@ import org.rhq.core.pc.plugin.FileSystemPluginFinder;
* @author Lukas Krejci
*/
@Test(sequential = true, invocationCount = 1)
-public class ResourceUpgradeTest {
+public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private static final String PLUGIN_V1_FILENAME = "/resource-upgrade-test-plugin-1.0.0.jar";
private static final String PLUGIN_V2_FILENAME = "/resource-upgrade-test-plugin-2.0.0.jar";
private static final String FAILING_PLUGIN_FILE_NAME = "/resource-upgrade-test-plugin-3.0.0.jar";
- private static final String PLUGINS_DIR_NAME = "plugins";
- private static final String DATA_DIR_NAME = "data";
- private static final String TMP_DIR_NAME = "tmp";
-
- private static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
- private static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME = "ResourceUpgradeTest";
-
- private File tmpDir;
- private File pluginDir;
- private File dataDir;
-
- private BundleServerService currentBundleServerService;
- private ConfigurationServerService currentConfigurationServerService;
- private ContentServerService currentContentServerService;
- private CoreServerService currentCoreServerService;
- private DiscoveryServerService currentDiscoveryServerService;
- private EventServerService currentEventServerService;
- private MeasurementServerService currentMeasurementServerService;
- private OperationServerService currentOperationServerService;
- private ResourceFactoryServerService currentResourceFactoryServerService;
-
- private FakeServerInventory currentServerSideInventory;
-
- @AfterClass
- public void undeployPlugins() throws IOException {
- FileUtils.deleteDirectory(tmpDir);
- }
+ static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
+ static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME = "ResourceUpgradeTest";
@BeforeClass
public void sanityCheck() {
@@ -108,18 +63,9 @@ public class ResourceUpgradeTest {
verifyPluginExists(FAILING_PLUGIN_FILE_NAME);
}
- @BeforeClass(dependsOnMethods = "sanityCheck")
- public void init() {
- tmpDir = getTmpDirectory();
- pluginDir = new File(tmpDir, PLUGINS_DIR_NAME);
- assertTrue(pluginDir.mkdir(), "Could not create plugin deploy directory.");
- dataDir = new File(tmpDir, DATA_DIR_NAME);
- assertTrue(dataDir.mkdir(), "Could not create plugin container data directory.");
- }
-
@Test
public void testIgnoreUncommittedResources() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.NEW);
TestPayload testNoChange = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
@@ -138,8 +84,8 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1, 4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1, 4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
}
};
}
@@ -150,22 +96,22 @@ public class ResourceUpgradeTest {
@Test
public void testUpgradeData() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
upgradeTest(false);
}
@Test
public void testInventoryReinitializationFromServerDuringUpgrade() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
upgradeTest(true);
}
@Test
public void testSkipUpgradeWhenServerUnavailable() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- currentServerSideInventory.setFailing(true);
+ getCurrentServerSideInventory().setFailing(true);
TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
public void test(Set<Resource> discoveredResources) {
@@ -184,10 +130,10 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1, 4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1, 4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
- never(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
+ never(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
}
};
}
@@ -198,7 +144,7 @@ public class ResourceUpgradeTest {
@Test
public void testUpgradeWithPlatformDeletedOnServer() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
@@ -227,15 +173,15 @@ public class ResourceUpgradeTest {
//the first merge will be triggered from within the upgrade process and we are
//going to report null sync.
- oneOf(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.clearPlatform());
+ oneOf(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().clearPlatform());
//the rest of the inventory merges are executed by discoveries, so let's import the
//discovered stuff into the server-side inventory.
- between(1, 3).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1, 3).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
- never(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
+ never(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
}
};
}
@@ -246,7 +192,7 @@ public class ResourceUpgradeTest {
@Test
public void testUpgradeFailureHandling() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
@@ -272,11 +218,11 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1, 4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1, 4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
- oneOf(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
- will(currentServerSideInventory.upgradeResources());
+ oneOf(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
+ will(getCurrentServerSideInventory().upgradeResources());
}
};
}
@@ -297,20 +243,21 @@ public class ResourceUpgradeTest {
assertEquals(discoveredResource.getName(), "resource-name-v1");
assertEquals(discoveredResource.getDescription(), "resource-description-v1");
}
-
+
public Expectations getExpectations(Mockery context) throws Exception {
return new Expectations() {
{
defineDefaultExpectations(this);
- between(1, 4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.mergeInventoryReport(requiredInventoryStatus));
+ between(1, 4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().mergeInventoryReport(requiredInventoryStatus));
}
};
}
});
}
+
private void upgradeTest(boolean clearInventoryDat) throws Exception {
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
@@ -339,189 +286,14 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1, 4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1, 4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
- oneOf(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
- will(currentServerSideInventory.upgradeResources());
+ oneOf(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
+ will(getCurrentServerSideInventory().upgradeResources());
}
};
}
});
}
-
- private PluginContainerConfiguration createPluginContainerConfiguration(Mockery context) throws Exception {
- PluginContainerConfiguration conf = new PluginContainerConfiguration();
-
- conf.setPluginDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
- conf.setDataDirectory(new File(tmpDir, DATA_DIR_NAME));
- conf.setTemporaryDirectory(new File(tmpDir, TMP_DIR_NAME));
- conf.setInsideAgent(true); //pc must think it's inside an agent so that it persists the inventory between restarts
- conf.setPluginFinder(new FileSystemPluginFinder(conf.getPluginDirectory()));
- conf.setCreateResourceClassloaders(false);
-
- //we're not interested in any scans happening out of our control
- conf.setAvailabilityScanInitialDelay(Long.MAX_VALUE);
- conf.setConfigurationDiscoveryInitialDelay(Long.MAX_VALUE);
- conf.setContentDiscoveryInitialDelay(Long.MAX_VALUE);
- conf.setEventSenderInitialDelay(Long.MAX_VALUE);
- conf.setMeasurementCollectionInitialDelay(Long.MAX_VALUE);
- conf.setServerDiscoveryInitialDelay(Long.MAX_VALUE);
- conf.setServiceDiscoveryInitialDelay(Long.MAX_VALUE);
-
- currentBundleServerService = context.mock(BundleServerService.class);
- currentConfigurationServerService = context.mock(ConfigurationServerService.class);
- currentContentServerService = context.mock(ContentServerService.class);
- currentCoreServerService = context.mock(CoreServerService.class);
- currentDiscoveryServerService = context.mock(DiscoveryServerService.class);
- currentEventServerService = context.mock(EventServerService.class);
- currentMeasurementServerService = context.mock(MeasurementServerService.class);
- currentOperationServerService = context.mock(OperationServerService.class);
- currentResourceFactoryServerService = context.mock(ResourceFactoryServerService.class);
-
- ServerServices serverServices = new ServerServices();
- serverServices.setBundleServerService(currentBundleServerService);
- serverServices.setConfigurationServerService(currentConfigurationServerService);
- serverServices.setContentServerService(currentContentServerService);
- serverServices.setCoreServerService(currentCoreServerService);
- serverServices.setDiscoveryServerService(currentDiscoveryServerService);
- serverServices.setEventServerService(currentEventServerService);
- serverServices.setMeasurementServerService(currentMeasurementServerService);
- serverServices.setOperationServerService(currentOperationServerService);
- serverServices.setResourceFactoryServerService(currentResourceFactoryServerService);
-
- conf.setServerServices(serverServices);
-
- return conf;
- }
-
- /**
- * @param pluginResourcePath
- */
- private void verifyPluginExists(String pluginResourcePath) {
- URL url = getClass().getResource(pluginResourcePath);
-
- File pluginFile = FileUtils.toFile(url);
-
- assertTrue(pluginFile.exists(), pluginFile.getAbsoluteFile() + " plugin jar could not be found.");
- }
-
- private void copyPlugin(String pluginResourcePath, File pluginDirectory) throws IOException {
- URL pluginUrl = getClass().getResource(pluginResourcePath);
-
- File pluginFile = new File(pluginResourcePath);
- String pluginFileName = pluginFile.getName();
-
- FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
- }
-
- private static File getTmpDirectory() {
- File ret = new File(System.getProperty("java.io.tmpdir"), "resource-upgrade-test" + System.currentTimeMillis());
-
- while (ret.exists() || !ret.mkdir()) {
- ret = new File(System.getProperty("java.io.tmpdir"), "resource-upgrade-test" + System.currentTimeMillis());
- }
-
- return ret;
- }
-
- private interface TestPayload {
- Expectations getExpectations(Mockery context) throws Exception;
- void test(Set<Resource> resourceUpgradeTestResources);
- boolean isClearInventoryDat();
- String getResourceTypeName();
- String getResourceTypePluginName();
- }
-
- private static abstract class AbstractTestPayload implements TestPayload {
- private boolean clearInventoryDat;
- private String resourceTypeName;
- private String resourceTypePluginName;
-
- public AbstractTestPayload(boolean clearInventoryDat, String resourceTypeName, String resourceTypePluginName) {
- this.clearInventoryDat = clearInventoryDat;
- this.resourceTypeName = resourceTypeName;
- this.resourceTypePluginName = resourceTypePluginName;
- }
-
- public boolean isClearInventoryDat() {
- return clearInventoryDat;
- }
-
- public String getResourceTypeName() {
- return resourceTypeName;
- }
-
- public String getResourceTypePluginName() {
- return resourceTypePluginName;
- }
- }
-
- private Set<Resource> getTestingResources(String resourceTypeName, String resourceTypePluginName) {
- ResourceType resType = PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName, resourceTypePluginName);
-
- return currentServerSideInventory.findResourcesByType(resType);
- }
-
- private void executeTestWithPlugins(Set<String> pluginResourcePaths, TestPayload test) throws Exception {
- FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
-
- for(String pluginResourcePath : pluginResourcePaths) {
- copyPlugin(pluginResourcePath, pluginDir);
- }
-
- Mockery context = new Mockery();
-
- PluginContainerConfiguration pcConfig = createPluginContainerConfiguration(context);
-
- if (test.isClearInventoryDat()) {
- File inventoryDat = new File(pcConfig.getDataDirectory(), "inventory.dat");
- inventoryDat.delete();
- }
-
- context.checking(test.getExpectations(context));
-
- PluginContainer.getInstance().setConfiguration(pcConfig);
- PluginContainer.getInstance().initialize();
-
- try {
- //give the pc the time to finish resource upgrade
- Thread.sleep(1000);
-
- //execute full discovery
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
- im.executeServerScanImmediately();
- im.executeServiceScanImmediately();
-
- Set<Resource> resources = getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
-
- test.test(resources);
-
- context.assertIsSatisfied();
- } finally {
- PluginContainer.getInstance().shutdown();
- }
- }
-
- @SuppressWarnings("unchecked")
- private void defineDefaultExpectations(Expectations expectations) {
- expectations.ignoring(currentBundleServerService);
- expectations.ignoring(currentConfigurationServerService);
- expectations.ignoring(currentContentServerService);
- expectations.ignoring(currentCoreServerService);
- expectations.ignoring(currentEventServerService);
- expectations.ignoring(currentMeasurementServerService);
- expectations.ignoring(currentOperationServerService);
- expectations.ignoring(currentResourceFactoryServerService);
-
- //just ignore these invocations if we get a availability scan in the PC...
- expectations.allowing(currentDiscoveryServerService).mergeAvailabilityReport(expectations.with(Expectations.any(AvailabilityReport.class)));
-
- expectations.allowing(currentDiscoveryServerService).getResources(expectations.with(Expectations.any(Set.class)), expectations.with(Expectations.any(boolean.class)));
- expectations.will(currentServerSideInventory.getResources());
- }
-
- private void cleanDataDir() throws IOException {
- FileUtils.cleanDirectory(new File(tmpDir, DATA_DIR_NAME));
- }
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
new file mode 100644
index 0000000..f03f2a4
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
@@ -0,0 +1,350 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade;
+
+import static org.testng.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.rhq.core.clientapi.server.bundle.BundleServerService;
+import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
+import org.rhq.core.clientapi.server.content.ContentServerService;
+import org.rhq.core.clientapi.server.core.CoreServerService;
+import org.rhq.core.clientapi.server.discovery.DiscoveryServerService;
+import org.rhq.core.clientapi.server.event.EventServerService;
+import org.rhq.core.clientapi.server.inventory.ResourceFactoryServerService;
+import org.rhq.core.clientapi.server.measurement.MeasurementServerService;
+import org.rhq.core.clientapi.server.operation.OperationServerService;
+import org.rhq.core.domain.discovery.AvailabilityReport;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pc.PluginContainer;
+import org.rhq.core.pc.PluginContainerConfiguration;
+import org.rhq.core.pc.ServerServices;
+import org.rhq.core.pc.inventory.InventoryManager;
+import org.rhq.core.pc.plugin.FileSystemPluginFinder;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class ResourceUpgradeTestBase {
+
+ private static final String PLUGINS_DIR_NAME = "plugins";
+ private static final String DATA_DIR_NAME = "data";
+ private static final String TMP_DIR_NAME = "tmp";
+ private File tmpDir;
+ private File pluginDir;
+ private File dataDir;
+ private BundleServerService currentBundleServerService;
+ private ConfigurationServerService currentConfigurationServerService;
+ private ContentServerService currentContentServerService;
+ private CoreServerService currentCoreServerService;
+ private DiscoveryServerService currentDiscoveryServerService;
+ private EventServerService currentEventServerService;
+ private MeasurementServerService currentMeasurementServerService;
+ private OperationServerService currentOperationServerService;
+ private ResourceFactoryServerService currentResourceFactoryServerService;
+ private FakeServerInventory currentServerSideInventory;
+
+ @BeforeClass
+ public void init() {
+ tmpDir = getTmpDirectory();
+ pluginDir = new File(tmpDir, PLUGINS_DIR_NAME);
+ assertTrue(pluginDir.mkdir(), "Could not create plugin deploy directory.");
+ dataDir = new File(tmpDir, DATA_DIR_NAME);
+ assertTrue(dataDir.mkdir(), "Could not create plugin container data directory.");
+ }
+
+ @AfterClass
+ public void undeployPlugins() throws IOException {
+ FileUtils.deleteDirectory(tmpDir);
+ }
+
+ protected void setCurrentServerSideInventory(FakeServerInventory currentServerSideInventory) {
+ this.currentServerSideInventory = currentServerSideInventory;
+ }
+
+ protected FakeServerInventory getCurrentServerSideInventory() {
+ return currentServerSideInventory;
+ }
+
+ protected void setCurrentResourceFactoryServerService(ResourceFactoryServerService currentResourceFactoryServerService) {
+ this.currentResourceFactoryServerService = currentResourceFactoryServerService;
+ }
+
+ protected ResourceFactoryServerService getCurrentResourceFactoryServerService() {
+ return currentResourceFactoryServerService;
+ }
+
+ protected void setCurrentOperationServerService(OperationServerService currentOperationServerService) {
+ this.currentOperationServerService = currentOperationServerService;
+ }
+
+ protected OperationServerService getCurrentOperationServerService() {
+ return currentOperationServerService;
+ }
+
+ protected void setCurrentMeasurementServerService(MeasurementServerService currentMeasurementServerService) {
+ this.currentMeasurementServerService = currentMeasurementServerService;
+ }
+
+ protected MeasurementServerService getCurrentMeasurementServerService() {
+ return currentMeasurementServerService;
+ }
+
+ protected void setCurrentEventServerService(EventServerService currentEventServerService) {
+ this.currentEventServerService = currentEventServerService;
+ }
+
+ protected EventServerService getCurrentEventServerService() {
+ return currentEventServerService;
+ }
+
+ protected void setCurrentDiscoveryServerService(DiscoveryServerService currentDiscoveryServerService) {
+ this.currentDiscoveryServerService = currentDiscoveryServerService;
+ }
+
+ protected DiscoveryServerService getCurrentDiscoveryServerService() {
+ return currentDiscoveryServerService;
+ }
+
+ protected void setCurrentCoreServerService(CoreServerService currentCoreServerService) {
+ this.currentCoreServerService = currentCoreServerService;
+ }
+
+ protected CoreServerService getCurrentCoreServerService() {
+ return currentCoreServerService;
+ }
+
+ protected void setCurrentContentServerService(ContentServerService currentContentServerService) {
+ this.currentContentServerService = currentContentServerService;
+ }
+
+ protected ContentServerService getCurrentContentServerService() {
+ return currentContentServerService;
+ }
+
+ protected void setCurrentConfigurationServerService(ConfigurationServerService currentConfigurationServerService) {
+ this.currentConfigurationServerService = currentConfigurationServerService;
+ }
+
+ protected ConfigurationServerService getCurrentConfigurationServerService() {
+ return currentConfigurationServerService;
+ }
+
+ protected void setCurrentBundleServerService(BundleServerService currentBundleServerService) {
+ this.currentBundleServerService = currentBundleServerService;
+ }
+
+ protected BundleServerService getCurrentBundleServerService() {
+ return currentBundleServerService;
+ }
+
+ protected static File getTmpDirectory() {
+ File ret = new File(System.getProperty("java.io.tmpdir"), "resource-upgrade-test" + System.currentTimeMillis());
+
+ while (ret.exists() || !ret.mkdir()) {
+ ret = new File(System.getProperty("java.io.tmpdir"), "resource-upgrade-test" + System.currentTimeMillis());
+ }
+
+ return ret;
+ }
+
+ private PluginContainerConfiguration createPluginContainerConfiguration(Mockery context) throws Exception {
+ PluginContainerConfiguration conf = new PluginContainerConfiguration();
+
+ conf.setPluginDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
+ conf.setDataDirectory(new File(tmpDir, DATA_DIR_NAME));
+ conf.setTemporaryDirectory(new File(tmpDir, TMP_DIR_NAME));
+ conf.setInsideAgent(true); //pc must think it's inside an agent so that it persists the inventory between restarts
+ conf.setPluginFinder(new FileSystemPluginFinder(conf.getPluginDirectory()));
+ conf.setCreateResourceClassloaders(false);
+
+ //we're not interested in any scans happening out of our control
+ conf.setAvailabilityScanInitialDelay(Long.MAX_VALUE);
+ conf.setConfigurationDiscoveryInitialDelay(Long.MAX_VALUE);
+ conf.setContentDiscoveryInitialDelay(Long.MAX_VALUE);
+ conf.setEventSenderInitialDelay(Long.MAX_VALUE);
+ conf.setMeasurementCollectionInitialDelay(Long.MAX_VALUE);
+ conf.setServerDiscoveryInitialDelay(Long.MAX_VALUE);
+ conf.setServiceDiscoveryInitialDelay(Long.MAX_VALUE);
+
+ setCurrentBundleServerService(context.mock(BundleServerService.class));
+ setCurrentConfigurationServerService(context.mock(ConfigurationServerService.class));
+ setCurrentContentServerService(context.mock(ContentServerService.class));
+ setCurrentCoreServerService(context.mock(CoreServerService.class));
+ setCurrentDiscoveryServerService(context.mock(DiscoveryServerService.class));
+ setCurrentEventServerService(context.mock(EventServerService.class));
+ setCurrentMeasurementServerService(context.mock(MeasurementServerService.class));
+ setCurrentOperationServerService(context.mock(OperationServerService.class));
+ setCurrentResourceFactoryServerService(context.mock(ResourceFactoryServerService.class));
+
+ ServerServices serverServices = new ServerServices();
+ serverServices.setBundleServerService(getCurrentBundleServerService());
+ serverServices.setConfigurationServerService(getCurrentConfigurationServerService());
+ serverServices.setContentServerService(getCurrentContentServerService());
+ serverServices.setCoreServerService(getCurrentCoreServerService());
+ serverServices.setDiscoveryServerService(getCurrentDiscoveryServerService());
+ serverServices.setEventServerService(getCurrentEventServerService());
+ serverServices.setMeasurementServerService(getCurrentMeasurementServerService());
+ serverServices.setOperationServerService(getCurrentOperationServerService());
+ serverServices.setResourceFactoryServerService(getCurrentResourceFactoryServerService());
+
+ conf.setServerServices(serverServices);
+
+ return conf;
+ }
+
+ /**
+ * @param pluginResourcePath
+ */
+ protected void verifyPluginExists(String pluginResourcePath) {
+ URL url = getClass().getResource(pluginResourcePath);
+
+ File pluginFile = FileUtils.toFile(url);
+
+ assertTrue(pluginFile.exists(), pluginFile.getAbsoluteFile() + " plugin jar could not be found.");
+ }
+
+ private void copyPlugin(String pluginResourcePath, File pluginDirectory) throws IOException {
+ URL pluginUrl = getClass().getResource(pluginResourcePath);
+
+ File pluginFile = new File(pluginResourcePath);
+ String pluginFileName = pluginFile.getName();
+
+ FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
+ }
+
+ protected interface TestPayload {
+ Expectations getExpectations(Mockery context) throws Exception;
+ void test(Set<Resource> resourceUpgradeTestResources);
+ boolean isClearInventoryDat();
+ String getResourceTypeName();
+ String getResourceTypePluginName();
+ }
+
+ protected static abstract class AbstractTestPayload implements TestPayload {
+ private boolean clearInventoryDat;
+ private String resourceTypeName;
+ private String resourceTypePluginName;
+
+ public AbstractTestPayload(boolean clearInventoryDat, String resourceTypeName, String resourceTypePluginName) {
+ this.clearInventoryDat = clearInventoryDat;
+ this.resourceTypeName = resourceTypeName;
+ this.resourceTypePluginName = resourceTypePluginName;
+ }
+
+ public boolean isClearInventoryDat() {
+ return clearInventoryDat;
+ }
+
+ public String getResourceTypeName() {
+ return resourceTypeName;
+ }
+
+ public String getResourceTypePluginName() {
+ return resourceTypePluginName;
+ }
+ }
+
+ /**
+ *
+ */
+ public ResourceUpgradeTestBase() {
+ super();
+ }
+
+ private Set<Resource> getTestingResources(String resourceTypeName, String resourceTypePluginName) {
+ ResourceType resType = PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName, resourceTypePluginName);
+
+ return getCurrentServerSideInventory().findResourcesByType(resType);
+ }
+
+ protected void executeTestWithPlugins(Set<String> pluginResourcePaths, TestPayload test) throws Exception {
+ FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
+
+ for(String pluginResourcePath : pluginResourcePaths) {
+ copyPlugin(pluginResourcePath, pluginDir);
+ }
+
+ Mockery context = new Mockery();
+
+ PluginContainerConfiguration pcConfig = createPluginContainerConfiguration(context);
+
+ if (test.isClearInventoryDat()) {
+ File inventoryDat = new File(pcConfig.getDataDirectory(), "inventory.dat");
+ inventoryDat.delete();
+ }
+
+ context.checking(test.getExpectations(context));
+
+ PluginContainer.getInstance().setConfiguration(pcConfig);
+ PluginContainer.getInstance().initialize();
+
+ try {
+ //give the pc the time to finish resource upgrade
+ Thread.sleep(1000);
+
+ //execute full discovery
+ InventoryManager im = PluginContainer.getInstance().getInventoryManager();
+ im.executeServerScanImmediately();
+ im.executeServiceScanImmediately();
+
+ Set<Resource> resources = getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
+
+ test.test(resources);
+
+ context.assertIsSatisfied();
+ } finally {
+ PluginContainer.getInstance().shutdown();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void defineDefaultExpectations(Expectations expectations) {
+ expectations.ignoring(getCurrentBundleServerService());
+ expectations.ignoring(getCurrentConfigurationServerService());
+ expectations.ignoring(getCurrentContentServerService());
+ expectations.ignoring(getCurrentCoreServerService());
+ expectations.ignoring(getCurrentEventServerService());
+ expectations.ignoring(getCurrentMeasurementServerService());
+ expectations.ignoring(getCurrentOperationServerService());
+ expectations.ignoring(getCurrentResourceFactoryServerService());
+
+ //just ignore these invocations if we get a availability scan in the PC...
+ expectations.allowing(getCurrentDiscoveryServerService()).mergeAvailabilityReport(expectations.with(Expectations.any(AvailabilityReport.class)));
+
+ expectations.allowing(getCurrentDiscoveryServerService()).getResources(expectations.with(Expectations.any(Set.class)), expectations.with(Expectations.any(boolean.class)));
+ expectations.will(getCurrentServerSideInventory().getResources());
+ }
+
+ protected void cleanDataDir() throws IOException {
+ FileUtils.cleanDirectory(new File(tmpDir, DATA_DIR_NAME));
+ }
+}
commit 1863f1ab0c4473e6a79c469c16b73b6810733325
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 12:58:32 2010 +0200
Preparing the upgrade tests to accept more complicated scenarios.
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index 1479345..0a2a660 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -77,6 +77,9 @@ public class ResourceUpgradeTest {
private static final String DATA_DIR_NAME = "data";
private static final String TMP_DIR_NAME = "tmp";
+ private static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
+ private static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME = "ResourceUpgradeTest";
+
private File tmpDir;
private File pluginDir;
private File dataDir;
@@ -119,8 +122,12 @@ public class ResourceUpgradeTest {
currentServerSideInventory = new FakeServerInventory();
initialSyncAndDiscovery(InventoryStatus.NEW);
- TestPayload testNoChange = new TestPayload() {
- public void test(Resource discoveredResource) {
+ TestPayload testNoChange = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(), "resource-key-v1");
assertEquals(discoveredResource.getName(), "resource-name-v1");
assertEquals(discoveredResource.getDescription(), "resource-description-v1");
@@ -138,7 +145,7 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), false, testNoChange);
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), testNoChange);
}
@Test
@@ -160,8 +167,12 @@ public class ResourceUpgradeTest {
currentServerSideInventory.setFailing(true);
- TestPayload test = new TestPayload() {
- public void test(Resource discoveredResource) {
+ TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(), "resource-key-v1");
assertEquals(discoveredResource.getName(), "resource-name-v1");
assertEquals(discoveredResource.getDescription(), "resource-description-v1");
@@ -182,7 +193,7 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), false, test);
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), test);
}
@Test
@@ -190,8 +201,12 @@ public class ResourceUpgradeTest {
currentServerSideInventory = new FakeServerInventory();
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new TestPayload() {
- public void test(Resource discoveredResource) {
+ TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(), "resource-key-v2");
assertEquals(discoveredResource.getName(), "resource-name-v2");
assertEquals(discoveredResource.getDescription(), "resource-description-v2");
@@ -226,7 +241,7 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), false, test);
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), test);
}
@Test
@@ -234,12 +249,16 @@ public class ResourceUpgradeTest {
currentServerSideInventory = new FakeServerInventory();
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new TestPayload() {
- public void test(Resource resourceUpgradeTestResource) {
- assertTrue(resourceUpgradeTestResource.getResourceErrors().size() > 0, "There should be upgrade errors persisted on the server side.");
+ TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> resourceUpgradeTestResources) {
+ assertEquals(resourceUpgradeTestResources.size(), 1, "Expected single test resource but multiple found.");
+
+ Resource discoveredResource = resourceUpgradeTestResources.iterator().next();
+
+ assertTrue(discoveredResource.getResourceErrors().size() > 0, "There should be upgrade errors persisted on the server side.");
//the discovery of the failed resource mustn't have run
- ResourceContainer container = PluginContainer.getInstance().getInventoryManager().getResourceContainer(resourceUpgradeTestResource);
+ ResourceContainer container = PluginContainer.getInstance().getInventoryManager().getResourceContainer(discoveredResource);
File dataDir = container.getResourceContext().getDataDirectory();
File marker = new File(dataDir, "failing-discovery-ran");
@@ -263,13 +282,17 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(FAILING_PLUGIN_FILE_NAME), false, test);
+ executeTestWithPlugins(Collections.singleton(FAILING_PLUGIN_FILE_NAME), test);
}
private void initialSyncAndDiscovery(final InventoryStatus requiredInventoryStatus) throws Exception {
cleanDataDir();
- executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), true, new TestPayload() {
- public void test(Resource discoveredResource) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), new AbstractTestPayload(true, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(), "resource-key-v1");
assertEquals(discoveredResource.getName(), "resource-name-v1");
assertEquals(discoveredResource.getDescription(), "resource-description-v1");
@@ -292,8 +315,12 @@ public class ResourceUpgradeTest {
private void upgradeTest(boolean clearInventoryDat) throws Exception {
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), clearInventoryDat, new TestPayload() {
- public void test(Resource discoveredResource) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), new AbstractTestPayload(clearInventoryDat, SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(), "resource-key-v2");
assertEquals(discoveredResource.getName(), "resource-name-v2");
assertEquals(discoveredResource.getDescription(), "resource-description-v2");
@@ -400,16 +427,43 @@ public class ResourceUpgradeTest {
private interface TestPayload {
Expectations getExpectations(Mockery context) throws Exception;
- void test(Resource resourceUpgradeTestResource);
+ void test(Set<Resource> resourceUpgradeTestResources);
+ boolean isClearInventoryDat();
+ String getResourceTypeName();
+ String getResourceTypePluginName();
}
- private Set<Resource> getTestingResources() {
- ResourceType resType = PluginContainer.getInstance().getPluginManager().getMetadataManager().getType("Resource", "ResourceUpgradeTest");
+ private static abstract class AbstractTestPayload implements TestPayload {
+ private boolean clearInventoryDat;
+ private String resourceTypeName;
+ private String resourceTypePluginName;
+
+ public AbstractTestPayload(boolean clearInventoryDat, String resourceTypeName, String resourceTypePluginName) {
+ this.clearInventoryDat = clearInventoryDat;
+ this.resourceTypeName = resourceTypeName;
+ this.resourceTypePluginName = resourceTypePluginName;
+ }
+
+ public boolean isClearInventoryDat() {
+ return clearInventoryDat;
+ }
+
+ public String getResourceTypeName() {
+ return resourceTypeName;
+ }
+
+ public String getResourceTypePluginName() {
+ return resourceTypePluginName;
+ }
+ }
+
+ private Set<Resource> getTestingResources(String resourceTypeName, String resourceTypePluginName) {
+ ResourceType resType = PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName, resourceTypePluginName);
return currentServerSideInventory.findResourcesByType(resType);
}
- private void executeTestWithPlugins(Set<String> pluginResourcePaths, boolean clearInventoryDat, TestPayload test) throws Exception {
+ private void executeTestWithPlugins(Set<String> pluginResourcePaths, TestPayload test) throws Exception {
FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
for(String pluginResourcePath : pluginResourcePaths) {
@@ -420,7 +474,7 @@ public class ResourceUpgradeTest {
PluginContainerConfiguration pcConfig = createPluginContainerConfiguration(context);
- if (clearInventoryDat) {
+ if (test.isClearInventoryDat()) {
File inventoryDat = new File(pcConfig.getDataDirectory(), "inventory.dat");
inventoryDat.delete();
}
@@ -439,14 +493,9 @@ public class ResourceUpgradeTest {
im.executeServerScanImmediately();
im.executeServiceScanImmediately();
- Set<Resource> resources = getTestingResources();
-
- assertEquals(resources.size(), 1, "There should be only a single testing resource but " + resources
- + " were found.");
-
- Resource discoveredResource = resources.iterator().next();
+ Set<Resource> resources = getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
- test.test(discoveredResource);
+ test.test(resources);
context.assertIsSatisfied();
} finally {
commit 659920513807b095cdd0ac91c3f1c2e091d090a7
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 12:57:21 2010 +0200
Setting the height of the errorsGrid to a fixed value so that it stays at the bottom of the page.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
index 95bec5f..b439d44 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
@@ -23,11 +23,7 @@ import org.rhq.core.domain.resource.composite.ResourceComposite;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-import com.smartgwt.client.data.DSCallback;
-import com.smartgwt.client.data.DSRequest;
-import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.GroupStartOpen;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
@@ -44,13 +40,11 @@ import com.smartgwt.client.widgets.grid.events.CellClickHandler;
*/
public class OverviewView extends LocatableVLayout {
- private ResourceComposite resourceComposite;
private OverviewForm form;
private Table errorsGrid;
public OverviewView(String locatorId, ResourceComposite resourceComposite) {
super(locatorId);
- this.resourceComposite = resourceComposite;
form = new OverviewForm(extendLocatorId("form"), resourceComposite);
errorsGrid = new Table(extendLocatorId("errors"), "Detected errors", null, null, new String[] { ResourceErrorsDataSource.DETAIL_ID });
@@ -61,7 +55,7 @@ public class OverviewView extends LocatableVLayout {
errorsGrid.setDataSource(errors);
form.setHeight("*");
- errorsGrid.setHeight("10%");
+ errorsGrid.setHeight(200); //this should be just enough to fit the maximum of 3 rows in this table (there's at most 1 error per type)
addMember(form);
addMember(errorsGrid);
commit c704c79f4acfedf4d959de6d7d27db1b22efa1f3
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 12:44:55 2010 +0200
Adding a bunch of test plugins for dependency resolution during resource upgrade failure handling.
diff --git a/modules/core/plugin-container/pom.xml b/modules/core/plugin-container/pom.xml
index 4b09ef8..035bf36 100644
--- a/modules/core/plugin-container/pom.xml
+++ b/modules/core/plugin-container/pom.xml
@@ -195,6 +195,106 @@
<fileset dir="${project.build.testOutputDirectory}/tmp/failing" includes="**/*.class,**/rhq-plugin.xml" />
</jar>
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/base/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml" />
+ </copy>
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/base/org/rhq/core/pc/upgrade/plugins/multi/base">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/base/*.class" />
+ </copy>
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-base-1.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/base" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep1/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep1/org/rhq/core/pc/upgrade/plugins/multi/parentdep1">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentdep-1.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/parentdep1" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep2/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep2/org/rhq/core/pc/upgrade/plugins/multi/parentdep2">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentdep-2.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/parentdep2" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling1/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling1/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentsibling-1.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/parentsibling1" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling2/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling2/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentsibling-2.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/parentsibling2" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/root/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/root/org/rhq/core/pc/upgrade/plugins/multi/root">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/root/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-root-1.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/root" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/sibling1/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/sibling1/org/rhq/core/pc/upgrade/plugins/multi/sibling1">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling1/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-sibling-1.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/sibling1" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/sibling2/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/sibling2/org/rhq/core/pc/upgrade/plugins/multi/sibling2">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling2/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-sibling-2.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/sibling2" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/v1/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/v1/org/rhq/core/pc/upgrade/plugins/multi/v1">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v1/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-1.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/v1" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy toDir="${project.build.testOutputDirectory}/tmp/multi/v2/META-INF">
+ <fileset file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml" />
+ </copy>
+ <!-- <copy toDir="${project.build.testOutputDirectory}/tmp/multi/v2/org/rhq/core/pc/upgrade/plugins/multi/v2">
+ <fileset file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v2/*.class" />
+ </copy> -->
+ <jar destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-2.0.0.jar">
+ <fileset dir="${project.build.testOutputDirectory}/tmp/multi/v2" includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
<delete dir="${project.build.testOutputDirectory}/tmp"/>
</tasks>
</configuration>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
new file mode 100644
index 0000000..61d4fe0
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
@@ -0,0 +1,70 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade.plugins.multi.base;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class BaseDiscoveryComponent<T extends ResourceComponent> implements ResourceDiscoveryComponent<T> {
+
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<T> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ HashSet<DiscoveredResourceDetails> results = new HashSet<DiscoveredResourceDetails>();
+
+ Configuration pluginConfig = context.getDefaultPluginConfiguration();
+
+ String keyTemplate = pluginConfig.getSimpleValue("key", null);
+ int count = pluginConfig.getSimple("count").getIntegerValue();
+
+ int parentN = context.getParentResourceContext().getPluginConfiguration().getSimple("ordinal")
+ .getIntegerValue();
+
+ for (int i = 0; i < count; ++i) {
+
+ String key = getResourceKey(keyTemplate, i, parentN);
+
+ pluginConfig.put(new PropertySimple("ordinal", i));
+
+ DiscoveredResourceDetails detail = new DiscoveredResourceDetails(context.getResourceType(), key, key, null,
+ null, pluginConfig, null);
+
+ results.add(detail);
+ }
+
+ return results;
+ }
+
+ protected static String getResourceKey(String template, int n, int parentN) {
+ return template.replace("%n", Integer.toString(n)).replace("%p", Integer.toString(parentN));
+ }
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java
new file mode 100644
index 0000000..c5bbf3a
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java
@@ -0,0 +1,67 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade.plugins.multi.base;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class BaseResourceComponent<T extends ResourceComponent> implements ResourceComponent<T> {
+
+ private ResourceContext<T> context;
+ private final Log log = LogFactory.getLog(getClass());
+
+ private Set<Integer> childrenToFailUpgrade;
+
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
+
+ public void start(ResourceContext<T> context) throws InvalidPluginConfigurationException, Exception {
+ log.info("Starting multi resource child component with resource key '" + context.getResourceKey() + "'.");
+ this.context = context;
+ }
+
+ public void stop() {
+ log.info("Stopping multi resource child component with resource key '" + context.getResourceKey() + "'.");
+ }
+
+ public int getOrdinal() {
+ return context.getPluginConfiguration().getSimple("ordinal").getIntegerValue();
+ }
+
+ public Set<Integer> getChildrenToFailUpgrade() {
+ return childrenToFailUpgrade == null ? Collections.<Integer>emptySet() : childrenToFailUpgrade;
+ }
+
+ public void setChildrenToFailUpgrade(Set<Integer> childrenToFailUpgrade) {
+ this.childrenToFailUpgrade = childrenToFailUpgrade;
+ }
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
new file mode 100644
index 0000000..beb36db
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
@@ -0,0 +1,61 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade.plugins.multi.base;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.resource.ResourceUpgradeReport;
+import org.rhq.core.pluginapi.upgrade.ResourceUpgradeContext;
+import org.rhq.core.pluginapi.upgrade.ResourceUpgradeFacet;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class BaseUpgradingDiscoveryComponent<T extends BaseResourceComponent> extends BaseDiscoveryComponent<T> implements ResourceUpgradeFacet<T> {
+
+ public ResourceUpgradeReport upgrade(ResourceUpgradeContext<T> inventoriedResource) {
+ Configuration pluginConfig = inventoriedResource.getPluginConfiguration();
+
+ BaseResourceComponent<?> parent = inventoriedResource.getParentResourceComponent();
+ int ordinal = pluginConfig.getSimple("ordinal").getIntegerValue();
+ int parentOrdinal = parent == null ? 0 : parent.getOrdinal();
+
+ boolean fail = Boolean.getBoolean(pluginConfig.getSimpleValue("failUpgrade", "false"));
+
+ if (!fail && parent != null) {
+ fail = parent.getChildrenToFailUpgrade().contains(Integer.valueOf(ordinal));
+ }
+
+ if (fail) {
+ throw new RuntimeException("Failing the resource upgrade purposefully.");
+ }
+
+ String newKey = pluginConfig.getSimpleValue("upgradedKey", null);
+
+ if (newKey == null) {
+ return null;
+ }
+
+ ResourceUpgradeReport report = new ResourceUpgradeReport();
+
+ report.setNewResourceKey(getResourceKey(newKey, ordinal, parentOrdinal));
+ return null;
+ }
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
new file mode 100644
index 0000000..7edfba1
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="ResourceUpgradeMultiTestBase"
+ displayName=""
+ description=""
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <!--
+ Only the inheriting plugins create the concrete resources based on the
+ classes defined in this abstract base plugin.
+
+ These are the plugin configuration properties needed by the base plugin:
+
+ key = the template to create the resource key from
+ count = the number of resources to discover
+ upgradedKey = this *must* be specified on the resource type *to be upgraded* and
+ *must* be the same as the key template on the resource type that
+ it is upgraded to (i.e. the plugin.v1.upgradedKey == plugin.v2.key)
+
+ the discovery add a new property called "ordinal" to the plugin config
+ of the created resources, which contains the index of that resource amongst
+ its siblings.
+
+ the key template can contain %n which is replaced by the ordinal and %p which
+ is replaced by the ordinal of its parent.
+
+
+
+ if the discovery component of the concrete resource is (or inherits from)
+ BaseUpgradingDiscoveryComponent, it can specify further plugin config properties
+ influencing the upgrade:
+
+ failUpgrade = true to throw an exception during upgrade
+ -->
+
+</plugin>
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
new file mode 100644
index 0000000..3612974
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentDep"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDependency"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key" default="test-resource-parent-dep-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-dep-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
new file mode 100644
index 0000000..6b95114
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentDep"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDependency"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-parent-dep-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
new file mode 100644
index 0000000..fbade54
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDepSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key" default="test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
new file mode 100644
index 0000000..f16d526
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDepSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root" plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
new file mode 100644
index 0000000..b5efbb1
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestRoot"
+ displayName=""
+ description=""
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <server name="Root"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key" default="test-resource-root-%n" />
+ </plugin-configuration>
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
new file mode 100644
index 0000000..f87ef4d
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParentSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key" default="test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResourceSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key" default="test-resource-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
new file mode 100644
index 0000000..e6ab95f
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="ResourceUpgradeMultiTestSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParentSibling"
+ discovery="BaseUpgradingDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="ParentDependency" plugin="ResourceUpgradeMultiTestParentDep"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResourceSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+
+
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
new file mode 100644
index 0000000..32ad438
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTest"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParent"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="ParentDependency" plugin="ResourceUpgradeMultiTestParentDep"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key" default="test-resource-parent-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-parent-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResource"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key" default="test-resource-%n,parent-%p" />
+ <c:simple-property name="upgradedKey" default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+ </server>
+
+</plugin>
+
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
new file mode 100644
index 0000000..824d3fe
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="ResourceUpgradeMultiTest"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase" useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParent"
+ discovery="BaseUpgradingDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="ParentDependency" plugin="ResourceUpgradeMultiTestParentDep"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-parent-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResource"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
+ <c:simple-property name="key" default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+
+
+ </server>
+
+</plugin>
+
13 years, 7 months
[rhq] 4 commits - modules/enterprise
by Joseph Marques
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/menu/SearchBarPane.java | 136 +++++-----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java | 18 -
3 files changed, 81 insertions(+), 75 deletions(-)
New commits:
commit 3c5a00e40f93589f3fd333502d3b0d4ffde0c743
Author: Joseph Marques <joseph(a)redhat.com>
Date: Thu Sep 30 22:19:06 2010 -0400
cosmetic - reformatting
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
index 242aa4b..8da5ef0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
@@ -82,6 +82,7 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
clearMessage();
this.label = createLabel(message);
+
addMember(this.label);
markForRedraw();
commit 4288e5e7ec99e01767be54eb91a2698b2e515036
Author: Joseph Marques <joseph(a)redhat.com>
Date: Thu Sep 30 22:18:48 2010 -0400
tweak display of top/center message
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
index 02d3e33..242aa4b 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
@@ -40,8 +40,7 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
private static final String LOCATOR_ID = "MessageBar";
private static final int AUTO_HIDE_DELAY_MILLIS = 30000; // 30 seconds
- private static final Map<Message.Severity, String> SEVERITY_TO_STYLE_NAME_MAP =
- new HashMap<Message.Severity, String>();
+ private static final Map<Message.Severity, String> SEVERITY_TO_STYLE_NAME_MAP = new HashMap<Message.Severity, String>();
static {
SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Info, "InfoBlock");
SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Warning, "WarnBlock");
@@ -49,8 +48,7 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Fatal, "FatalBlock");
}
- private static final Map<Message.Severity, String> SEVERITY_TO_ICON_MAP =
- new HashMap<Message.Severity, String>();
+ private static final Map<Message.Severity, String> SEVERITY_TO_ICON_MAP = new HashMap<Message.Severity, String>();
static {
SEVERITY_TO_ICON_MAP.put(Message.Severity.Info, "info/icn_info_blue.png");
SEVERITY_TO_ICON_MAP.put(Message.Severity.Warning, "info/icn_info_orange.png");
@@ -70,7 +68,6 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
super.onDraw();
setWidth100();
- setAutoHeight();
setHeight(35);
setAlign(Alignment.CENTER);
@@ -112,17 +109,15 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
private Label createLabel(Message message) {
Label label = new Label();
- String contents = (message.getConciseMessage() != null) ?
- message.getConciseMessage() : message.getDetailedMessage();
+ String contents = (message.getConciseMessage() != null) ? message.getConciseMessage() : message
+ .getDetailedMessage();
label.setContents(contents);
+ label.setAlign(Alignment.CENTER);
String styleName = (contents != null) ? SEVERITY_TO_STYLE_NAME_MAP.get(message.getSeverity()) : null;
label.setStyleName(styleName);
- label.setAutoHeight();
- label.setHeight(30);
- label.setAutoWidth();
- label.setWidth("75%");
+ label.setWidth(400);
String icon = (contents != null) ? SEVERITY_TO_ICON_MAP.get(message.getSeverity()) : null;
label.setIcon(icon);
commit be9e31c733dcb1e75299025ed32caa3af28584a1
Author: Joseph Marques <joseph(a)redhat.com>
Date: Thu Sep 30 19:14:57 2010 -0400
minor fixes to SearchBarPanel for maintainability
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/menu/SearchBarPane.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/menu/SearchBarPane.java
index 0d920ef..657c4d3 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/menu/SearchBarPane.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/menu/SearchBarPane.java
@@ -29,7 +29,6 @@ import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
-import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.grid.ListGridField;
@@ -44,6 +43,7 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
/**
* @author Greg Hinkle
+ * @author Joseph Marques
*/
public class SearchBarPane extends LocatableHLayout {
@@ -54,6 +54,31 @@ public class SearchBarPane extends LocatableHLayout {
setHeight(28);
}
+ public enum SearchType {
+ RESOURCE("Resources"), //
+ GROUP("Resource Groups");
+
+ private String displayName;
+
+ private SearchType(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public static String[] getValueMap() {
+ SearchType[] searchTypes = SearchType.values();
+ String[] results = new String[searchTypes.length];
+ int i = 0;
+ for (SearchType nextType : searchTypes) {
+ results[i++] = nextType.getDisplayName();
+ }
+ return results;
+ }
+ }
+
@Override
protected void onDraw() {
super.onDraw();
@@ -63,9 +88,10 @@ public class SearchBarPane extends LocatableHLayout {
form.setColWidths("120", "140", "400");
final SelectItem searchType = new SelectItem("searchType", "Search");
+ String[] valueMap = SearchType.getValueMap();
+ searchType.setValueMap(valueMap);
+ searchType.setValue(valueMap[0]);
searchType.setWidth(120);
- searchType.setValueMap("Resources", "Resource Groups"/*, "Bundles", "Packages", "Users", "Roles"*/);
- searchType.setValue("Resources");
searchType.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
@@ -74,21 +100,7 @@ public class SearchBarPane extends LocatableHLayout {
});
ComboBoxItem resourceSearch = getResourceComboBox();
- resourceSearch.setShowIfCondition(new FormItemIfFunction() {
- public boolean execute(FormItem formItem, Object o, DynamicForm dynamicForm) {
- return form.getValueAsString("searchType").equals("Resources");
- }
- });
-
ComboBoxItem groupSearch = getGroupComboBox();
- groupSearch.setShowIfCondition(new FormItemIfFunction() {
- public boolean execute(FormItem formItem, Object o, DynamicForm dynamicForm) {
- return form.getValueAsString("searchType").equals("Resource Groups");
- }
- });
-
- TextItem query = new TextItem("query");
- query.setShowTitle(false);
ButtonItem search = new ButtonItem("Search", "Search");
search.setStartRow(false);
@@ -102,14 +114,7 @@ public class SearchBarPane extends LocatableHLayout {
}
private ComboBoxItem getResourceComboBox() {
-
- final ComboBoxItem comboBox = new ComboBoxItem("query", "Query");
- comboBox.setWidth(400);
- comboBox.setShowTitle(false);
- comboBox.setHint("resource search");
- comboBox.setShowHintInField(true);
-
- comboBox.setOptionDataSource(new ResourceDatasource());
+ final ComboBoxItem comboBox = getBaseComboBox(SearchType.RESOURCE);
ListGridField nameField = ResourceDataSourceField.NAME.getListGridField(250);
ListGridField descriptionField = ResourceDataSourceField.DESCRIPTION.getListGridField();
@@ -124,38 +129,13 @@ public class SearchBarPane extends LocatableHLayout {
comboBox.setValueField("id");
comboBox.setDisplayField(ResourceDataSourceField.NAME.propertyName());
- comboBox.setPickListWidth(800);
- comboBox.setTextMatchStyle(TextMatchStyle.SUBSTRING);
- comboBox.setCompleteOnTab(true);
-
- comboBox.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent changedEvent) {
- try {
- Integer resourceId = (Integer) changedEvent.getValue();
- comboBox.setValue("");
-
- String link = LinkManager.getResourceLink(resourceId);
- if (!link.contains("#")) {
- com.google.gwt.user.client.Window.Location.assign(link);
- } else {
- History.newItem(link.substring(1));
- }
- } catch (Exception e) {
- }
- }
- });
+ comboBox.setOptionDataSource(new ResourceDatasource());
return comboBox;
}
private ComboBoxItem getGroupComboBox() {
- final ComboBoxItem comboBox = new ComboBoxItem("query", "Query");
- comboBox.setWidth(400);
- comboBox.setShowTitle(false);
- comboBox.setHint("group search");
- comboBox.setShowHintInField(true);
-
- comboBox.setOptionDataSource(new ResourceGroupsDataSource());
+ final ComboBoxItem comboBox = getBaseComboBox(SearchType.GROUP);
ListGridField nameField = ResourceGroupDataSourceField.NAME.getListGridField(250);
ListGridField descriptionField = ResourceGroupDataSourceField.DESCRIPTION.getListGridField();
@@ -167,27 +147,57 @@ public class SearchBarPane extends LocatableHLayout {
comboBox.setValueField("id");
comboBox.setDisplayField(ResourceGroupDataSourceField.NAME.propertyName());
+ comboBox.setOptionDataSource(new ResourceGroupsDataSource());
+
+ return comboBox;
+ }
+
+ private ComboBoxItem getBaseComboBox(final SearchType searchType) {
+ final ComboBoxItem comboBox = new ComboBoxItem("query", "Query");
+ comboBox.setWidth(400);
+ comboBox.setShowTitle(false);
+ comboBox.setHint("search");
+ comboBox.setShowHintInField(true);
+
comboBox.setPickListWidth(800);
comboBox.setTextMatchStyle(TextMatchStyle.SUBSTRING);
comboBox.setCompleteOnTab(true);
comboBox.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent changedEvent) {
- try {
- Integer groupId = (Integer) changedEvent.getValue();
- comboBox.setValue("");
-
- String link = LinkManager.getResourceGroupLink(groupId);
- if (!link.contains("#")) {
- com.google.gwt.user.client.Window.Location.assign(link);
- } else {
- History.newItem(link.substring(1));
- }
- } catch (Exception e) {
+ //System.out.println("ChangedEvent: " + changedEvent.getValue());
+
+ Object intermediate = changedEvent.getValue();
+ if (!(intermediate instanceof Integer)) {
+ return;
+ }
+
+ Integer id = (Integer) changedEvent.getValue();
+ comboBox.setValue("");
+
+ String link = null;
+ if (searchType == SearchType.RESOURCE) {
+ link = LinkManager.getResourceLink(id);
+ } else if (searchType == SearchType.GROUP) {
+ link = LinkManager.getResourceGroupLink(id);
+ } else {
+ throw new IllegalArgumentException("There is no global search type for " + searchType);
+ }
+
+ if (!link.contains("#")) {
+ com.google.gwt.user.client.Window.Location.assign(link);
+ } else {
+ History.newItem(link.substring(1));
}
}
});
+ comboBox.setShowIfCondition(new FormItemIfFunction() {
+ public boolean execute(FormItem formItem, Object o, DynamicForm dynamicForm) {
+ return dynamicForm.getValueAsString("searchType").equals(searchType.getDisplayName());
+ }
+ });
+
return comboBox;
}
commit acf0d09358c36e094bb041ebf5106a921009a51a
Author: Joseph Marques <joseph(a)redhat.com>
Date: Thu Sep 30 17:30:43 2010 -0400
prevent exceptions when using integer-based filters that might pass empty string instead of null
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java
index 1184697..a717108 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java
@@ -286,7 +286,7 @@ public abstract class RPCDataSource<T> extends DataSource {
S result = null;
Object value = criteriaMap.get(paramName);
- if (value == null) {
+ if (value == null || value.toString().equals("")) {
// nothing to do, result is already null
} else {
String strValue = value.toString();
13 years, 7 months
[rhq] modules/enterprise
by ips
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java | 22 +--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java | 33 ++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeEvent.java | 59 +++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeListener.java | 30 ++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ValidationStateChangeListener.java | 27 ----
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/wizard/GroupCreateWizard.java | 13 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/ResourceConfigurationEditView.java | 61 ++++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/inventory/PluginConfigurationEditView.java | 63 ++++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/ErrorHandler.java | 14 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java | 64 +++++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java | 21 +--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenter.java | 15 +-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java | 21 +--
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/TransientMessage.java | 48 -------
14 files changed, 288 insertions(+), 203 deletions(-)
New commits:
commit 3f5cc3fd0018b723b4082e9f31b20d94bed328c8
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Thu Sep 30 21:55:29 2010 -0400
implement v2 of the new MessageCenter API; fix a few bugs in resource and plugin config relating to authz checking and to Save button
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java
index 5e66764..9aaa0e9 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ResourceAlertDefinitionsView.java
@@ -39,7 +39,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository;
import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository.MetadataType;
-import org.rhq.enterprise.gui.coregui.client.util.message.TransientMessage;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
/**
@@ -129,13 +129,13 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
@Override
public void onSuccess(Integer result) {
CoreGUI.getMessageCenter().notify(
- new TransientMessage("[" + result + "] alert definitions enabled", Severity.Info));
+ new Message("[" + result + "] alert definitions enabled.", Severity.Info));
ResourceAlertDefinitionsView.this.refresh();
}
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleTransientError("Failed to enable alert definitions", caught);
+ CoreGUI.getErrorHandler().handleError("Failed to enable alert definitions", caught);
}
});
}
@@ -156,13 +156,13 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
@Override
public void onSuccess(Integer result) {
CoreGUI.getMessageCenter().notify(
- new TransientMessage("[" + result + "] alert definitions disabled", Severity.Info));
+ new Message("[" + result + "] alert definitions disabled.", Severity.Info));
ResourceAlertDefinitionsView.this.refresh();
}
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleTransientError("Failed to disable alert definitions", caught);
+ CoreGUI.getErrorHandler().handleError("Failed to disable alert definitions.", caught);
}
});
}
@@ -183,13 +183,13 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
@Override
public void onSuccess(Integer result) {
CoreGUI.getMessageCenter().notify(
- new TransientMessage("[" + result + "] alert definitions deleted", Severity.Info));
+ new Message("[" + result + "] alert definitions deleted.", Severity.Info));
ResourceAlertDefinitionsView.this.refresh();
}
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleTransientError("Failed to delete alert definitions", caught);
+ CoreGUI.getErrorHandler().handleError("Failed to delete alert definitions.", caught);
}
});
}
@@ -202,13 +202,13 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
@Override
public void onSuccess(Integer result) {
CoreGUI.getMessageCenter().notify(
- new TransientMessage("Alert definition is created", Severity.Info));
+ new Message("Alert definition is created", Severity.Info));
alertDefinition.setId(result.intValue());
}
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleTransientError("Failed to create alert definition", caught);
+ CoreGUI.getErrorHandler().handleError("Failed to create alert definition.", caught);
}
});
} else {
@@ -217,12 +217,12 @@ public class ResourceAlertDefinitionsView extends AbstractAlertDefinitionsView {
@Override
public void onSuccess(AlertDefinition result) {
CoreGUI.getMessageCenter().notify(
- new TransientMessage("Alert definition is updated", Severity.Info));
+ new Message("Alert definition is updated.", Severity.Info));
}
@Override
public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleTransientError("Failed to update alert definition", caught);
+ CoreGUI.getErrorHandler().handleError("Failed to update alert definition.", caught);
}
});
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
index 544ded9..eb1e2d2 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ConfigurationEditor.java
@@ -159,8 +159,8 @@ public class ConfigurationEditor extends LocatableVLayout {
private boolean readOnly = false;
private Set<String> invalidPropertyNames = new HashSet<String>();
- private Set<ValidationStateChangeListener> validationStateChangeListeners =
- new HashSet<ValidationStateChangeListener>();
+ private Set<PropertyValueChangeListener> validationStateChangeListeners =
+ new HashSet<PropertyValueChangeListener>();
public static enum ConfigType {
plugin, resource
@@ -218,7 +218,7 @@ public class ConfigurationEditor extends LocatableVLayout {
return this.valuesManager.hasErrors();
}
- public void addValidationStateChangeListener(ValidationStateChangeListener validationStateChangeListener) {
+ public void addValidationStateChangeListener(PropertyValueChangeListener validationStateChangeListener) {
this.validationStateChangeListeners.add(validationStateChangeListener);
}
@@ -250,11 +250,11 @@ public class ConfigurationEditor extends LocatableVLayout {
EnumSet.of(ResourceTypeRepository.MetadataType.resourceConfigurationDefinition),
new ResourceTypeRepository.TypesLoadedCallback() {
public void onTypesLoaded(Map<Integer, ResourceType> types) {
- System.out.println("ConfigDef retreived in: " + (System.currentTimeMillis() - start));
+ //System.out.println("ConfigDef retreived in: " + (System.currentTimeMillis() - start));
definition = types.get(resourceTypeId).getResourceConfigurationDefinition();
if (definition == null) {
loadingLabel.hide();
- showError("No configuration supported for this resource");
+ showError("Configuration is not supported by this Resource.");
}
reload();
}
@@ -276,10 +276,10 @@ public class ConfigurationEditor extends LocatableVLayout {
EnumSet.of(ResourceTypeRepository.MetadataType.pluginConfigurationDefinition),
new ResourceTypeRepository.TypesLoadedCallback() {
public void onTypesLoaded(Map<Integer, ResourceType> types) {
- System.out.println("ConfigDef retreived in: " + (System.currentTimeMillis() - start));
+ //System.out.println("ConfigDef retreived in: " + (System.currentTimeMillis() - start));
definition = types.get(resourceTypeId).getPluginConfigurationDefinition();
if (definition == null) {
- showError("No configuration supported for this resource");
+ showError("Connection settings are not supported by this Resource.");
}
reload();
}
@@ -556,6 +556,10 @@ public class ConfigurationEditor extends LocatableVLayout {
}
}
+ public Set<String> getInvalidPropertyNames() {
+ return this.invalidPropertyNames;
+ }
+
private void buildMapsField(ArrayList<FormItem> fields, PropertyDefinitionMap propertyDefinitionMap,
PropertyMap propertyMap) {
// create the property grid
@@ -564,7 +568,7 @@ public class ConfigurationEditor extends LocatableVLayout {
propertyGrid.getValuesField().setName("Value");
// create the editors
- HashMap<String, FormItem> editorsMap = new HashMap<String, FormItem>();
+ Map<String, FormItem> editorsMap = new HashMap<String, FormItem>();
TextItem textEditor = new TextItem();
editorsMap.put("simpleText", textEditor);
@@ -768,8 +772,8 @@ public class ConfigurationEditor extends LocatableVLayout {
return record;
}
- private FormItem buildSimpleField(ArrayList<FormItem> fields, PropertyDefinitionSimple propertyDefinition,
- boolean oddRow, Property property) {
+ private FormItem buildSimpleField(ArrayList<FormItem> fields, final PropertyDefinitionSimple propertyDefinition,
+ boolean oddRow, final Property property) {
final PropertySimple propertySimple = (PropertySimple) property;
FormItem valueItem = null;
@@ -887,10 +891,11 @@ public class ConfigurationEditor extends LocatableVLayout {
ConfigurationEditor.this.invalidPropertyNames.add(propertySimple.getName());
}
boolean isValidNow = ConfigurationEditor.this.invalidPropertyNames.isEmpty();
- if (isValidNow != wasValidBefore) {
- for (ValidationStateChangeListener validationStateChangeListener : ConfigurationEditor.this.validationStateChangeListeners) {
- validationStateChangeListener.validationStateChanged(isValidNow);
- }
+ boolean validationStateChanged = (isValidNow != wasValidBefore);
+ for (PropertyValueChangeListener validationStateChangeListener : ConfigurationEditor.this.validationStateChangeListeners) {
+ PropertyValueChangeEvent event = new PropertyValueChangeEvent(property, propertyDefinition,
+ validationStateChanged, ConfigurationEditor.this.invalidPropertyNames);
+ validationStateChangeListener.propertyValueChanged(event);
}
}
});
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeEvent.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeEvent.java
new file mode 100644
index 0000000..2ba852d
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeEvent.java
@@ -0,0 +1,59 @@
+/*
+ * RHQ Management Platform
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.coregui.client.components.configuration;
+
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+
+/**
+ * @author Ian Springer
+ */
+public class PropertyValueChangeEvent {
+ private Property property;
+ private PropertyDefinition propertyDefinition;
+ private boolean validationStateChanged;
+ private Set<String> invalidPropertyNames;
+
+ public PropertyValueChangeEvent(Property property, PropertyDefinition propertyDefinition, boolean validationStatechanged,
+ Set<String> invalidPropertyNames) {
+ this.property = property;
+ this.propertyDefinition = propertyDefinition;
+ this.validationStateChanged = validationStatechanged;
+ this.invalidPropertyNames = invalidPropertyNames;
+ }
+
+ public Property getProperty() {
+ return property;
+ }
+
+ public PropertyDefinition getPropertyDefinition() {
+ return propertyDefinition;
+ }
+
+ public boolean isValidationStateChanged() {
+ return validationStateChanged;
+ }
+
+ public Set<String> getInvalidPropertyNames() {
+ return invalidPropertyNames;
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeListener.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeListener.java
new file mode 100644
index 0000000..0ed46f4
--- /dev/null
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/PropertyValueChangeListener.java
@@ -0,0 +1,30 @@
+/*
+ * RHQ Management Platform
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.coregui.client.components.configuration;
+
+/**
+ * A listener that can register to be notified by a {@link ConfigurationEditor} when a configuration property's value
+ * changes.
+ *
+ * @author Ian Springer
+ */
+public interface PropertyValueChangeListener {
+ void propertyValueChanged(PropertyValueChangeEvent event);
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ValidationStateChangeListener.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ValidationStateChangeListener.java
deleted file mode 100644
index 154c731..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/configuration/ValidationStateChangeListener.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * 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.coregui.client.components.configuration;
-
-/**
- * @author Ian Springer
- */
-public interface ValidationStateChangeListener {
- void validationStateChanged(boolean isValid);
-}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/wizard/GroupCreateWizard.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/wizard/GroupCreateWizard.java
index 1008b83..4e66027 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/wizard/GroupCreateWizard.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/wizard/GroupCreateWizard.java
@@ -37,7 +37,6 @@ import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGroupGWTServiceAsync;
import org.rhq.enterprise.gui.coregui.client.inventory.groups.ResourceGroupListView;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-import org.rhq.enterprise.gui.coregui.client.util.message.TransientMessage;
/**
* A wizard for creating a new Resource group.
@@ -92,13 +91,11 @@ public class GroupCreateWizard extends AbstractWizard {
public void onSuccess(ResourceGroup result) {
String groupUrl = LinkManager.getResourceGroupLink(result.getId());
- CoreGUI.getMessageCenter().notify(
- new TransientMessage("Resource group created. [<a href='" + groupUrl + "'>View Group</a>]",
- Message.Severity.Info));
- CoreGUI.getMessageCenter().notify(
- new Message("Created new " + result.getGroupCategory().name().toLowerCase() + " Resource group '"
- + result.getName() + "' with " + memberStep.getSelectedResourceIds().length + " members.",
- Message.Severity.Info));
+ String conciseMessage = "Resource group created. [<a href='" + groupUrl + "'>View Group</a>]";
+ String detailedMessage =
+ "Created new " + result.getGroupCategory().name().toLowerCase() + " Resource group '"
+ + result.getName() + "' with " + memberStep.getSelectedResourceIds().length + " members.";
+ CoreGUI.getMessageCenter().notify(new Message(conciseMessage, detailedMessage));
resourceGroupListView.refresh();
}
});
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/ResourceConfigurationEditView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/ResourceConfigurationEditView.java
index b002f0b..f5afb2c 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/ResourceConfigurationEditView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/configuration/ResourceConfigurationEditView.java
@@ -18,6 +18,8 @@
*/
package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.configuration;
+import java.util.EnumSet;
+
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.IButton;
@@ -33,19 +35,21 @@ import org.rhq.core.domain.resource.composite.ResourceComposite;
import org.rhq.core.domain.resource.composite.ResourcePermission;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
-import org.rhq.enterprise.gui.coregui.client.components.configuration.ValidationStateChangeListener;
+import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent;
+import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.message.MessageCenter;
-import org.rhq.enterprise.gui.coregui.client.util.message.TransientMessage;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
+ * A view for editing a Resource's configuration.
+ *
* @author Greg Hinkle
* @author Ian Springer
*/
-public class ResourceConfigurationEditView extends LocatableVLayout implements ValidationStateChangeListener {
+public class ResourceConfigurationEditView extends LocatableVLayout implements PropertyValueChangeListener {
private Resource resource;
private ResourcePermission resourcePermission;
private ConfigurationEditor editor;
@@ -76,20 +80,30 @@ public class ResourceConfigurationEditView extends LocatableVLayout implements V
save();
}
});
- this.saveButton.disable();
toolStrip.addMember(saveButton);
+
+ addMember(toolStrip);
+ reloadConfiguration();
- editor = new ConfigurationEditor(this.getLocatorId(), resource.getId(), resource.getResourceType().getId());
+ if (!this.resourcePermission.isConfigureWrite()) {
+ Message message = new Message("You do not have permission to edit this Resource's configuration.",
+ Message.Severity.Info, EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
+ CoreGUI.getMessageCenter().notify(message);
+ }
+ }
+
+ private void reloadConfiguration() {
+ this.saveButton.disable();
+ if (editor != null) {
+ editor.destroy();
+ removeMember(editor);
+ }
+ editor = new ConfigurationEditor(this.extendLocatorId("Editor"), resource.getId(),
+ resource.getResourceType().getId());
editor.setOverflow(Overflow.AUTO);
editor.addValidationStateChangeListener(this);
editor.setReadOnly(!this.resourcePermission.isConfigureWrite());
-
- addMember(toolStrip);
addMember(editor);
-
- Message message = new TransientMessage("You do not have permission to edit this Resource's configuration.",
- Message.Severity.Info, true);
- CoreGUI.getMessageCenter().notify(message);
}
private void save() {
@@ -103,24 +117,31 @@ public class ResourceConfigurationEditView extends LocatableVLayout implements V
public void onSuccess(ResourceConfigurationUpdate result) {
CoreGUI.getMessageCenter().notify(
- new Message("Configuration updated for Resource [" + resource.getName() + "].",
+ new Message("Configuration updated.",
+ "Configuration updated for Resource [" + resource.getName() + "].",
Message.Severity.Info));
-
+ reloadConfiguration();
}
});
}
@Override
- public void validationStateChanged(boolean isValid) {
+ public void propertyValueChanged(PropertyValueChangeEvent event) {
MessageCenter messageCenter = CoreGUI.getMessageCenter();
Message message;
- if (isValid) {
- this.saveButton.enable();
- message = new TransientMessage("All configuration properties now have valid values, so the configuration can now be saved.", Message.Severity.Info);
+ if (event.isValidationStateChanged()) {
+ if (event.getInvalidPropertyNames().isEmpty()) {
+ this.saveButton.enable();
+ message = new Message("All configuration properties now have valid values, so the configuration can now be saved.",
+ Message.Severity.Info, EnumSet.of(Message.Option.Transient));
+ } else {
+ this.saveButton.disable();
+ message = new Message("One or more configuration properties have invalid values. The values must be corrected before the configuration can be saved.",
+ Message.Severity.Error, EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
+ }
+ messageCenter.notify(message);
} else {
- this.saveButton.disable();
- message = new TransientMessage("One or more configuration properties have invalid values. The values must be corrected before the configuration can be saved.", Message.Severity.Error, true);
+ this.saveButton.enable();
}
- messageCenter.notify(message);
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/inventory/PluginConfigurationEditView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/inventory/PluginConfigurationEditView.java
index 1483cfa..4556da0 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/inventory/PluginConfigurationEditView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/inventory/PluginConfigurationEditView.java
@@ -18,6 +18,8 @@
*/
package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.inventory;
+import java.util.EnumSet;
+
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.events.ClickEvent;
@@ -32,19 +34,21 @@ import org.rhq.core.domain.resource.composite.ResourceComposite;
import org.rhq.core.domain.resource.composite.ResourcePermission;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
-import org.rhq.enterprise.gui.coregui.client.components.configuration.ValidationStateChangeListener;
+import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent;
+import org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
import org.rhq.enterprise.gui.coregui.client.util.message.MessageCenter;
-import org.rhq.enterprise.gui.coregui.client.util.message.TransientMessage;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
+ * A view for editing a Resource's plugin configuration (aka connection settings).
+ *
* @author Greg Hinkle
* @author Ian Springer
*/
-public class PluginConfigurationEditView extends LocatableVLayout implements ValidationStateChangeListener {
+public class PluginConfigurationEditView extends LocatableVLayout implements PropertyValueChangeListener {
private Resource resource;
private ResourcePermission resourcePermission;
private ConfigurationEditor editor;
@@ -76,20 +80,30 @@ public class PluginConfigurationEditView extends LocatableVLayout implements Val
}
});
this.saveButton.disable();
- toolStrip.addMember(saveButton);
+ toolStrip.addMember(this.saveButton);
+
+ addMember(toolStrip);
+ reloadConfiguration();
+
+ if (!this.resourcePermission.isInventory()) {
+ Message message = new Message("You do not have permission to edit this Resource's connection settings.",
+ Message.Severity.Info, EnumSet.of(Message.Option.Transient));
+ CoreGUI.getMessageCenter().notify(message);
+ }
+ }
- editor = new ConfigurationEditor(this.getLocatorId(), resource.getId(), resource.getResourceType().getId(),
- ConfigurationEditor.ConfigType.plugin);
+ private void reloadConfiguration() {
+ this.saveButton.disable();
+ if (editor != null) {
+ editor.destroy();
+ removeMember(editor);
+ }
+ editor = new ConfigurationEditor(extendLocatorId("Editor"), resource.getId(),
+ resource.getResourceType().getId(), ConfigurationEditor.ConfigType.plugin);
editor.setOverflow(Overflow.AUTO);
editor.addValidationStateChangeListener(this);
editor.setReadOnly(!this.resourcePermission.isInventory());
-
- addMember(toolStrip);
addMember(editor);
-
- Message message = new TransientMessage("You do not have permission to edit this Resource's connection properties.",
- Message.Severity.Info, true);
- CoreGUI.getMessageCenter().notify(message);
}
private void save() {
@@ -103,24 +117,31 @@ public class PluginConfigurationEditView extends LocatableVLayout implements Val
public void onSuccess(PluginConfigurationUpdate result) {
CoreGUI.getMessageCenter().notify(
- new Message("Connection settings updated for Resource [" + resource.getName() + "].",
+ new Message("Connection settings updated.",
+ "Connection settings updated for Resource [" + resource.getName() + "].",
Message.Severity.Info));
-
+ reloadConfiguration();
}
});
}
@Override
- public void validationStateChanged(boolean isValid) {
+ public void propertyValueChanged(PropertyValueChangeEvent event) {
MessageCenter messageCenter = CoreGUI.getMessageCenter();
Message message;
- if (isValid) {
- this.saveButton.enable();
- message = new TransientMessage("All connection properties now have valid values, so the configuration can now be saved.", Message.Severity.Info);
+ if (event.isValidationStateChanged()) {
+ if (event.getInvalidPropertyNames().isEmpty()) {
+ this.saveButton.enable();
+ message = new Message("All connection settings now have valid values, so the settings can now be saved.",
+ Message.Severity.Info, EnumSet.of(Message.Option.Transient));
+ } else {
+ this.saveButton.disable();
+ message = new Message("One or more connection settings have invalid values. The values must be corrected before the settings can be saved.",
+ Message.Severity.Error, EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
+ }
+ messageCenter.notify(message);
} else {
- this.saveButton.disable();
- message = new TransientMessage("One or more connection properties have invalid values. The values must be corrected before the configuration can be saved.", Message.Severity.Error, true);
+ this.saveButton.enable();
}
- messageCenter.notify(message);
}
}
\ No newline at end of file
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/ErrorHandler.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/ErrorHandler.java
index 6e5f80b..49bb67e 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/ErrorHandler.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/ErrorHandler.java
@@ -20,31 +20,21 @@ package org.rhq.enterprise.gui.coregui.client.util;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-import org.rhq.enterprise.gui.coregui.client.util.message.TransientMessage;
/**
* @author Greg Hinkle
*/
public class ErrorHandler {
-
public void handleError(String message) {
handleError(message, null);
}
public void handleError(String message, Throwable t) {
- Message errorMessage = new Message(message, (t == null) ? null : t.toString(), Message.Severity.Error);
- CoreGUI.getMessageCenter().notify(errorMessage);
-
- if (t != null) {
- t.printStackTrace();
- }
- }
-
- public void handleTransientError(String message, Throwable t) {
- Message errorMessage = new TransientMessage(message, (t == null) ? null : t.toString(), Message.Severity.Error);
+ Message errorMessage = new Message(message, (t == null) ? null : t.toString(), Message.Severity.Fatal);
CoreGUI.getMessageCenter().notify(errorMessage);
if (t != null) {
+ System.err.println(message);
t.printStackTrace();
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java
index 97cc7ab..429ef36 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java
@@ -19,36 +19,55 @@
package org.rhq.enterprise.gui.coregui.client.util.message;
import java.util.Date;
+import java.util.EnumSet;
/**
+ * A message to be displayed to the user in one or more places.
+ *
* @author Greg Hinkle
+ * @author Ian Springer
*/
@SuppressWarnings({"UnnecessarySemicolon"})
public class Message {
- protected String title;
- protected String detail;
+ protected String conciseMessage;
+ protected String detailedMessage;
protected Date fired = new Date();
protected Severity severity;
+ protected EnumSet<Option> options;
// TODO: Add Debug severity?
- public enum Severity { Info, Warning, Error };
+ public enum Severity { Info, Warning, Error, Fatal };
+ public enum Option { Transient, Sticky, BackgroundJobResult };
+
+ public Message(String conciseMessage, Severity severity) {
+ this(conciseMessage, null, severity);
+ }
+
+ public Message(String conciseMessage, String detailedMessage) {
+ this(conciseMessage, detailedMessage, null);
+ }
+
+ public Message(String conciseMessage, String detailedMessage, Severity severity) {
+ this(conciseMessage, detailedMessage, severity, null);
+ }
- public Message(String title, Severity severity) {
- this(title, null, severity);
+ public Message(String conciseMessage, Severity severity, EnumSet<Option> options) {
+ this(conciseMessage, null, severity, options);
}
- public Message(String title, String detail, Severity severity) {
- this.title = title;
- this.detail = detail;
+ public Message(String conciseMessage, String detailedMessage, Severity severity, EnumSet<Option> options) {
+ this.conciseMessage = conciseMessage;
+ this.detailedMessage = detailedMessage;
this.severity = (severity != null) ? severity : Severity.Info;
+ this.options = (options != null) ? options : EnumSet.noneOf(Option.class);
}
- public String getTitle() {
- return title;
+ public String getConciseMessage() {
+ return conciseMessage;
}
- public String getDetail() {
- return detail;
+ public String getDetailedMessage() {
+ return detailedMessage;
}
public Date getFired() {
@@ -59,13 +78,26 @@ public class Message {
return severity;
}
+ public boolean isTransient() {
+ return options.contains(Option.Transient);
+ }
+
+ public boolean isSticky() {
+ return options.contains(Option.Sticky);
+ }
+
+ public boolean isBackgroundJobResult() {
+ return options.contains(Option.BackgroundJobResult);
+ }
+
@Override
public String toString() {
return "Message{" +
- "title='" + title + '\'' +
- ", detail='" + detail + '\'' +
- ", fired=" + fired +
- ", severity=" + severity +
+ "conciseMessage='" + this.conciseMessage + '\'' +
+ ", detailedMessage='" + this.detailedMessage + '\'' +
+ ", fired=" + this.fired +
+ ", severity=" + this.severity +
+ ", options=" + this.options +
'}';
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
index b03499f..02d3e33 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageBar.java
@@ -46,6 +46,7 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Info, "InfoBlock");
SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Warning, "WarnBlock");
SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Error, "ErrorBlock");
+ SEVERITY_TO_STYLE_NAME_MAP.put(Message.Severity.Fatal, "FatalBlock");
}
private static final Map<Message.Severity, String> SEVERITY_TO_ICON_MAP =
@@ -70,7 +71,7 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
setWidth100();
setAutoHeight();
- setHeight(40);
+ setHeight(35);
setAlign(Alignment.CENTER);
@@ -79,18 +80,16 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
@Override
public void onMessage(Message message) {
- if (message instanceof TransientMessage) {
- TransientMessage transientMessage = (TransientMessage)message;
-
+ if (!message.isBackgroundJobResult()) {
// First clear any previous message.
clearMessage();
- this.label = createLabel(transientMessage);
- addMember(this.label);
+ this.label = createLabel(message);
+ addMember(this.label);
markForRedraw();
// Auto-clear the message after 30 seconds unless it's been designated as sticky.
- if (!transientMessage.isSticky()) {
+ if (!message.isSticky()) {
Timer hideTimer = new Timer() {
@Override
public void run() {
@@ -113,17 +112,15 @@ public class MessageBar extends LocatableHLayout implements MessageCenter.Messag
private Label createLabel(Message message) {
Label label = new Label();
- String contents = message.getTitle();
- if (message.getDetail() != null) {
- contents += ": " + message.getDetail();
- }
+ String contents = (message.getConciseMessage() != null) ?
+ message.getConciseMessage() : message.getDetailedMessage();
label.setContents(contents);
String styleName = (contents != null) ? SEVERITY_TO_STYLE_NAME_MAP.get(message.getSeverity()) : null;
label.setStyleName(styleName);
label.setAutoHeight();
- label.setHeight(35);
+ label.setHeight(30);
label.setAutoWidth();
label.setWidth("75%");
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenter.java
index a3c29dd..a9070b1 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenter.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenter.java
@@ -29,12 +29,14 @@ public class MessageCenter {
private LinkedList<Message> messages = new LinkedList<Message>();
private List<MessageListener> listeners = new ArrayList<MessageListener>();
- private static final int MAX_MESSAGES = 100;
+ private static final int MAX_MESSAGES = 50;
public void notify(Message message) {
- this.messages.add(message);
- if (messages.size() > MAX_MESSAGES) {
- messages.removeFirst();
+ if (!message.isTransient()) {
+ this.messages.add(message);
+ if (messages.size() > MAX_MESSAGES) {
+ messages.removeFirst();
+ }
}
for (MessageListener listener : listeners) {
listener.onMessage(message);
@@ -45,6 +47,11 @@ public class MessageCenter {
this.listeners.add(listener);
}
+ /**
+ * Returns a list of recently published non-transient messages.
+ *
+ * @return a list of recently published non-transient messages
+ */
public List<Message> getMessages() {
return messages;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
index 5d81646..d51bc47 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
@@ -86,7 +86,7 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
MenuItem[] items = new MenuItem[messages.size()];
for (int i = 0, messagesSize = messages.size(); i < messagesSize; i++) {
final Message message = messages.get(i);
- MenuItem messageItem = new MenuItem(message.title, getSeverityIcon(message.severity));
+ MenuItem messageItem = new MenuItem(message.conciseMessage, getSeverityIcon(message.severity));
items[i] = messageItem;
@@ -116,7 +116,7 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
form.setWrapItemTitles(false);
StaticTextItem title = new StaticTextItem("title", "Title");
- title.setValue(message.title);
+ title.setValue(message.conciseMessage);
StaticTextItem severity = new StaticTextItem("severity", "Severity");
FormItemIcon severityIcon = new FormItemIcon();
@@ -129,7 +129,7 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
StaticTextItem detail = new StaticTextItem("detail", "Detail");
detail.setTitleOrientation(TitleOrientation.TOP);
- detail.setValue(message.detail);
+ detail.setValue(message.detailedMessage);
detail.setColSpan(2);
ButtonItem okButton = new ButtonItem("Ok", "Ok");
@@ -139,7 +139,7 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
form.setItems(title, severity, date, detail, okButton);
final Window window = new LocatableWindow(this.extendLocatorId("Message"));
- window.setTitle(message.title);
+ window.setTitle(message.conciseMessage);
window.setWidth(600);
window.setHeight(400);
window.setIsModal(true);
@@ -157,8 +157,8 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
}
public void onMessage(final Message message) {
- if (!(message instanceof TransientMessage)) {
- final Label label = new Label(message.title);
+ if (!message.isTransient()) {
+ final Label label = new Label(message.conciseMessage);
label.setMargin(5);
label.setAutoFit(true);
label.setHeight(25);
@@ -168,7 +168,7 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
label.setIcon(iconSrc);
- label.setTooltip(message.detail);
+ label.setTooltip(message.detailedMessage);
label.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
@@ -196,13 +196,14 @@ public class MessageCenterView extends LocatableHLayout implements MessageCenter
private String getSeverityIcon(Message.Severity severity) {
String iconSrc = null;
switch (severity) {
- case Info:
+ case Info:
iconSrc = "info/icn_info_blue.png";
break;
- case Warning:
+ case Warning:
iconSrc = "info/icn_info_orange.png";
break;
- case Error:
+ case Error:
+ case Fatal:
iconSrc = "info/icn_info_red.png";
break;
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/TransientMessage.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/TransientMessage.java
deleted file mode 100644
index 318c4a5..0000000
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/TransientMessage.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * 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.coregui.client.util.message;
-
-/**
- * @author Ian Springer
- */
-public class TransientMessage extends Message {
- private boolean sticky;
-
- public TransientMessage(String title, Severity severity) {
- super(title, severity);
- }
-
- public TransientMessage(String title, String detail, Severity severity) {
- super(title, detail, severity);
- }
-
- public TransientMessage(String title, Severity severity, boolean sticky) {
- this(title, null, severity, sticky);
- }
-
- public TransientMessage(String title, String detail, Severity severity, boolean sticky) {
- super(title, detail, severity);
- this.sticky = sticky;
- }
-
- public boolean isSticky() {
- return this.sticky;
- }
-}
13 years, 7 months