modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java
| 44 +++++-----
modules/plugins/pom.xml
| 2
modules/plugins/twitter/src/main/java/org/rhq/plugins/twitter/FeedComponent.java
| 25 ++++-
3 files changed, 44 insertions(+), 27 deletions(-)
New commits:
commit 440f9cb6105d66367389b72f58e76744c361a076
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Jul 28 12:08:34 2010 +0200
Small refactoring to be less verbose.
Don't retrhow the plugin container exception
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java
index 6d58302..e090b51 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ChildResourceTypeDiscoveryRunner.java
@@ -6,6 +6,7 @@ import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCategory;
@@ -24,9 +25,9 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
//private MeasurementManager measurementManager;
//private int resourceId;
- //TODO: maybe to be implemented for later usage
+ //TODO: maybe to be implemented for later usage
// public ChildResourceTypeDiscoveryRunner(MeasurementManager measurementManager)
{
- //
+ //
// }
// public ChildResourceTypeDiscoveryRunner(int resourceId) {
@@ -56,29 +57,31 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
InventoryManager im = PluginContainer.getInstance().getInventoryManager();
log.info("InventoryManager instance created");
- //TODO: Do testing and split code to more than one method if it works well
+ //TODO: Do testing and split code to more than one method if it works well
// Run a full scan for all resources in the inventory
Resource platform = im.getPlatform();
log.info("Platform returned with name: " + platform.getName());
// Next discover all other services and non-top-level servers
- Set<Resource> servers = platform.getChildResources();
- log.info("Platform " + platform.getName() + " has " +
servers.size() + " ChildResources");
-
- if (servers != null) {
- for (Resource server : servers) {
- log.info("Name of server: " + server.getName());
- log.info("Id of server: " + server.getId());
- log.info("Category of server: " +
server.getResourceType().getCategory().toString());
+ Set<Resource> children = platform.getChildResources();
+ log.info("Platform " + platform.getName() + " has " +
children.size() + " ChildResources");
+
+ if (children != null) {
+ for (Resource child : children) {
+ if (log.isDebugEnabled()) {
+ log.debug("Name of server: " + child.getName());
+ log.debug("Id of server: " + child.getId());
+ log.debug("Category of server: " +
child.getResourceType().getCategory().toString());
+ }
//Check if really is of Category SERVER
- if (server.getResourceType().getCategory() == ResourceCategory.SERVER) {
+ if (child.getResourceType().getCategory() == ResourceCategory.SERVER) {
- log.info("Server " + server.getName() + "has passed
the Server Category test succesfull");
+ log.info("Server " + child.getName() + "has passed the
Server Category test succesfull");
//ChildResourceTypeDiscoveryFacet.class.isAssignableFrom(server.getClass())
//check if child resource implements the interface
ChildResourceTypeDiscoveryFacet
- //if (server instanceof ChildResourceTypeDiscoveryFacet)
+ //if (server instanceof ChildResourceTypeDiscoveryFacet)
//if
(ChildResourceTypeDiscoveryFacet.class.isAssignableFrom(server.getClass())) {
@@ -86,9 +89,9 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
// + " implements the interface
ChildResourceTypeDiscoveryFacet");
// //Get ResourceContainer for each server
instance
- ResourceContainer container =
im.getResourceContainer(server.getId());
+ ResourceContainer container =
im.getResourceContainer(child.getId());
- log.info("Server " + server.getName() + " is running
in ResourceContainer " + container.toString());
+ log.info("Server " + child.getName() + " is running in
ResourceContainer " + container.toString());
if (container.getResourceComponentState() !=
ResourceContainer.ResourceComponentState.STARTED
|| container.getAvailability() == null
@@ -101,7 +104,7 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
try {
- ChildResourceTypeDiscoveryFacet discoveryComponent =
ComponentUtil.getComponent(server
+ ChildResourceTypeDiscoveryFacet discoveryComponent =
ComponentUtil.getComponent(child
.getId(), ChildResourceTypeDiscoveryFacet.class,
FacetLockType.READ, 30 * 1000, true,
true);
@@ -111,9 +114,12 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
//Iterate over all the ResourceTypes contained in the Set
for (ResourceType type : resourceTypes) {
- //Create a new ResourceType in the DB for the selected
type
+ //Create a new ResourceType in the DB for the selected
type
im.createNewResourceType(type.getName(), type.getName() +
"Metric");
}
+ } catch (PluginContainerException pce) {
+ // This is expected when the ResourceComponent does not
implement the ChildResourceTypeDiscoveryFacet
+ log.warn("Error submitting service scan: " +
pce.getMessage());
} catch (Exception e) {
throw new RuntimeException("Error submitting service
scan", e);
}
@@ -134,7 +140,7 @@ public class ChildResourceTypeDiscoveryRunner implements
Callable<Set<ResourceTy
}
/**
- *
+ *
* @param discoveryComponent
* @return
*/
commit 2dc344c10e0e88630229900405d5bc4951b09c01
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Jul 28 12:05:31 2010 +0200
Re-enable twitter plugin
diff --git a/modules/plugins/pom.xml b/modules/plugins/pom.xml
index 204c00c..84dfda0 100644
--- a/modules/plugins/pom.xml
+++ b/modules/plugins/pom.xml
@@ -178,7 +178,7 @@
<module>perftest</module>
<module>script2</module>
<module>snmptrapd</module>
- <!--<module>twitter</module>-->
+ <module>twitter</module>
<module>virt</module>
<module>kickstart</module>
commit 5075f68e6a2c383e1352c57dc6e04a3baed131f3
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Thu Jun 24 22:14:13 2010 +0200
Fix last compile error.
diff --git
a/modules/plugins/twitter/src/main/java/org/rhq/plugins/twitter/FeedComponent.java
b/modules/plugins/twitter/src/main/java/org/rhq/plugins/twitter/FeedComponent.java
index 8c7da3a..9f7bfc4 100644
--- a/modules/plugins/twitter/src/main/java/org/rhq/plugins/twitter/FeedComponent.java
+++ b/modules/plugins/twitter/src/main/java/org/rhq/plugins/twitter/FeedComponent.java
@@ -19,6 +19,7 @@
package org.rhq.plugins.twitter;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
import twitter4j.Paging;
@@ -27,6 +28,8 @@ import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Tweet;
import twitter4j.Twitter;
+import twitter4j.TwitterFactory;
+import twitter4j.conf.PropertyConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -61,10 +64,9 @@ public class FeedComponent implements
ResourceComponent<TwitterComponent>, Measu
private boolean isSearch = false;
private String keyword;
private TwitterEventPoller eventPoller;
- private String serverUrl;
- private String searchBase;
+ private TwitterFactory tFactory;
- /**
+ /**
* Return availability of this resource
* @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
*/
@@ -86,13 +88,23 @@ public class FeedComponent implements
ResourceComponent<TwitterComponent>, Measu
isSearch = true;
keyword = conf.getSimpleValue("keyword","Jopr"); // Jopr is
fallback .. just in case
- serverUrl = context.getParentResourceComponent().getServerUrl();
- searchBase = context.getParentResourceComponent().getSearchUrl();
+ String serverUrl = context.getParentResourceComponent().getServerUrl();
+ String searchBase = context.getParentResourceComponent().getSearchUrl();
eventContext = context.getEventContext();
eventPoller = new TwitterEventPoller(TOPIC_EVENT);
eventContext.registerEventPoller(eventPoller, 63);
+ Properties props = new Properties();
+ props.put(PropertyConfiguration.SOURCE,"Jopr");
+ props.put(PropertyConfiguration.HTTP_USER_AGENT,"Jopr");
+ props.put(PropertyConfiguration.SEARCH_BASE_URL, searchBase);
+ props.put(PropertyConfiguration.REST_BASE_URL, serverUrl);
+ twitter4j.conf.Configuration tconf = new PropertyConfiguration(props);
+
+ tFactory = new TwitterFactory(tconf);
+
+
}
@@ -116,12 +128,11 @@ public class FeedComponent implements
ResourceComponent<TwitterComponent>, Measu
for (MeasurementScheduleRequest req : metrics) {
if (req.getName().equals("tweetCount")) {
- Twitter twitter = new Twitter(serverUrl);
+ Twitter twitter = tFactory.getInstance();
Paging paging = new Paging();
MeasurementDataNumeric res;
if (isSearch) {
- twitter.setSearchBaseURL(searchBase);
Query q = new Query(keyword);
q.setSinceId(lastId);
if (lastId == NOT_YET_SET)
Show replies by date