Author: charles.crouch(a)jboss.com
Date: 2008-12-02 15:39:59 -0500 (Tue, 02 Dec 2008)
New Revision: 61
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/SingleResourceAction.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java
trunk/core/src/main/java/org/jboss/on/embedded/ui/nav/BaseTreeNode.java
trunk/core/src/test/java/org/jboss/on/embedded/ui/test/TreeNodeTest.java
Log:
EMBJOPR-45 move the raising of events from the UI layer into the ResourceManager to make
sure all clients doing create/update/delete etc will trigger the appropriate change
event.
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java 2008-11-25
23:28:30 UTC (rev 60)
+++
trunk/core/src/main/java/org/jboss/on/embedded/manager/pc/PluginContainerResourceManager.java 2008-12-02
20:39:59 UTC (rev 61)
@@ -28,6 +28,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.on.embedded.manager.ResourceManager;
+import org.jboss.seam.core.Events;
import org.jetbrains.annotations.NotNull;
import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.clientapi.agent.configuration.ConfigurationAgentService;
@@ -252,6 +253,7 @@
if (response.getStatus() == DeleteResourceStatus.SUCCESS)
{
discoverServicesSync();
+ Events.instance().raiseEvent("resourceDeleted", resource);
}
}
catch (PluginContainerException e)
@@ -262,11 +264,11 @@
return response;
}
- public CreateResourceResponse createResource(String resourceName, ResourceType
resourceType, Resource ancestorResource, Configuration pluginConfiguration, Configuration
resourceConfiguration)
+ public CreateResourceResponse createResource(String resourceName, ResourceType
resourceType, Resource parentResource, Configuration pluginConfiguration, Configuration
resourceConfiguration)
{
CreateResourceResponse response;
- CreateResourceRequest request = new CreateResourceRequest(1,
ancestorResource.getId(), resourceName, resourceType.getName(), resourceType.getPlugin(),
pluginConfiguration, resourceConfiguration);
- response = createResource(resourceType, request);
+ CreateResourceRequest request = new CreateResourceRequest(1,
parentResource.getId(), resourceName, resourceType.getName(), resourceType.getPlugin(),
pluginConfiguration, resourceConfiguration);
+ response = createResource(resourceType, parentResource, request);
return response;
}
@@ -274,13 +276,13 @@
{
CreateResourceResponse response;
CreateResourceRequest request = new CreateResourceRequest(1,
parentResource.getId(), resourceName, resourceType.getName(), resourceType.getPlugin(),
pluginConfiguration, packageDetails);
- response = createResource(resourceType, request);
+ response = createResource(resourceType, parentResource, request);
return response;
}
// tries to create a resource using the specified CreateResourceRequest
// if successful it will try to refresh the inventory by calling
discoverServicesSync
- private CreateResourceResponse createResource(ResourceType resourceType,
CreateResourceRequest request)
+ private CreateResourceResponse createResource(ResourceType resourceType, Resource
parentResource, CreateResourceRequest request)
{
CreateResourceResponse response;
try
@@ -288,7 +290,8 @@
response =
getResourceFactoryService().executeCreateResourceImmediately(request);
if (response.getStatus() == CreateResourceStatus.SUCCESS)
{
- discoverServicesSync();
+ discoverServicesSync();
+ Events.instance().raiseEvent("resourceCreated", resourceType,
parentResource);
}
}
catch (PluginContainerException e)
@@ -315,6 +318,7 @@
{
// As ccrouch recalls, we do a service scan to pickup any change to the
updated Resource's name.
discoverServicesSync();
+ Events.instance().raiseEvent("resourceUpdated", resource);
}
}
catch (PluginContainerException e)
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2008-11-25
23:28:30 UTC (rev 60)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2008-12-02
20:39:59 UTC (rev 61)
@@ -404,6 +404,7 @@
// String errorMsg = "Unable to find node with path [" +
this.currentPath + "]; defaulting to platform node...";
// LOG.error(errorMsg);
// this.facesMessages.add(FacesMessage.SEVERITY_ERROR, errorMsg);
+ log.debug("Unable to find node with path [" + this.currentPath +
"]; defaulting to platform node...");
ResourceManager resourceManager = ResourceManagerFactory.resourceManager();
this.currentPath = getResourcePath(resourceManager.getPlatform());
selectedNode = getRootNode().findNode(this.currentPath);
@@ -440,10 +441,11 @@
}
@Observer("resourceCreated")
- public void updateNavWithNewResource(ResourceType typeOfNewResource)
+ public void updateNavWithNewResource(ResourceType typeOfNewResource, Resource
parentResource)
{
- log.info("Resource of type [" + typeOfNewResource + "]
added.");
- JONTreeNode node = findNodeByResourceType(typeOfNewResource);
+ log.info("Resource of type [" + typeOfNewResource + "] added
beneath Resource [" + parentResource + "].");
+ JONTreeNode parentNode = findNode(getResourcePath(parentResource));
+ JONTreeNode node = findNodeByResourceTypeAndParent(typeOfNewResource,
parentNode);
node.reInitializeChildrenMap();
}
@@ -462,11 +464,20 @@
JONTreeNode parent = node.getParent();
parent.reInitializeChildrenMap();
}
-
+
+ @Observer("resourceUpdated")
+ public void updateNavWithUpdatedResource(Resource updatedResource)
+ {
+ // doesn't do anything right now, but in the future this could
+ // regenerate the nav similar to how updateNavWithDeletedResource
+ // does it. This would catch any resource renames that happened
+ // as part of the update
+ }
+
// TODO consider have this return TreeNodeWithResourceType
- public ResourceTypeTreeNode findNodeByResourceType(ResourceType resourceType)
+ public ResourceTypeTreeNode findNodeByResourceTypeAndParent(ResourceType
resourceType, JONTreeNode parentResourceNode)
{
- return ((BaseTreeNode) getRootNode()).findNodeByType(resourceType);
+ return ((BaseTreeNode) parentResourceNode).findNodeByType(resourceType);
}
public Boolean openNodeAdvisor(UITree tree) {
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/SingleResourceAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/SingleResourceAction.java 2008-11-25
23:28:30 UTC (rev 60)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/SingleResourceAction.java 2008-12-02
20:39:59 UTC (rev 61)
@@ -128,8 +128,7 @@
switch (deleteResourceResponse.getStatus()) {
case SUCCESS:
facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO,
"resource.status.remove.success",
- resource.getResourceType().getName(), resource.getName());
- Events.instance().raiseEvent("resourceDeleted", resource);
+ resource.getResourceType().getName(), resource.getName());
return Constants.OUTCOME_SUCCESS;
default:
String details = (deleteResourceResponse.getErrorMessage() != null) ?
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java
===================================================================
---
trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java 2008-11-25
23:28:30 UTC (rev 60)
+++
trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java 2008-12-02
20:39:59 UTC (rev 61)
@@ -223,12 +223,7 @@
case SUCCESS:
{
facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_INFO,
"resource.status.create.success", serviceType.getName());
- result = Constants.OUTCOME_SUCCESS;
- // TODO this event should really be passed ancestorResource
- // that way its much easier to tell associated resources to regenerate
- // based on the parent, rather than just the serviceType
- // on 2nd thoughts maybe it should pass both
- Events.instance().raiseEvent("resourceCreated", serviceType);
+ result = Constants.OUTCOME_SUCCESS;
break;
}
case TIMED_OUT:
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/nav/BaseTreeNode.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/nav/BaseTreeNode.java 2008-11-25
23:28:30 UTC (rev 60)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/nav/BaseTreeNode.java 2008-12-02
20:39:59 UTC (rev 61)
@@ -314,7 +314,9 @@
* Looks at this node and its children recursively as necessary
*/
// TODO move these to navigation action, as well as the NodeFinder impls
- // TODO i dont think this is going to work when we have the same resource types
+ // In order for this to work it must be executed against an appropriate
+ // instance of BaseTreeNode, i.e. the parent, otherwise you are going to have
+ // problems due to having the same resource types
// appearing under multiple resources, see JBMANCON-365
public
@Nullable
@@ -328,7 +330,9 @@
}
//TODO move these to navigation action
- // TODO i dont think this is going to work when we have the same resource types
+ // In order for this to work it must be executed against an appropriate
+ // instance of BaseTreeNode, i.e. the parent, otherwise you are going to have
+ // problems due to having the same resource types
// appearing under multiple resources, see JBMANCON-365
public ResourceTypeTreeNode findNodeByType(@NotNull ResourceType resourceType)
{
Modified: trunk/core/src/test/java/org/jboss/on/embedded/ui/test/TreeNodeTest.java
===================================================================
--- trunk/core/src/test/java/org/jboss/on/embedded/ui/test/TreeNodeTest.java 2008-11-25
23:28:30 UTC (rev 60)
+++ trunk/core/src/test/java/org/jboss/on/embedded/ui/test/TreeNodeTest.java 2008-12-02
20:39:59 UTC (rev 61)
@@ -177,7 +177,7 @@
assert localDS != null;
NavigationAction navAction = getNavigationAction();
- ResourceTypeTreeNode retrievedNode = navAction.findNodeByResourceType(localDS);
+ ResourceTypeTreeNode retrievedNode =
navAction.findNodeByResourceTypeAndParent(localDS, getPlatformNode());
assert retrievedNode != null;
assert localDS.equals(retrievedNode.getResourceType());