1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.rhq.plugin;
25
26 import java.util.HashSet;
27 import java.util.Set;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.jboss.managed.api.ComponentType;
32 import org.jboss.managed.api.ManagedComponent;
33 import org.jboss.metatype.api.values.MetaValue;
34 import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
35 import org.modeshape.rhq.plugin.util.PluginConstants;
36 import org.modeshape.rhq.plugin.util.ProfileServiceUtil;
37 import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
38 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
39 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
40 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
41 import org.rhq.plugins.jbossas5.ApplicationServerComponent;
42
43
44
45
46 public class EngineDiscoveryComponent implements
47 ResourceDiscoveryComponent<EngineComponent> {
48
49 private final Log log = LogFactory
50 .getLog(PluginConstants.DEFAULT_LOGGER_CATEGORY);
51
52
53
54
55
56
57 public Set<DiscoveredResourceDetails> discoverResources(
58 ResourceDiscoveryContext discoveryContext)
59 throws InvalidPluginConfigurationException, Exception {
60
61 Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
62
63 ManagedComponent mc = ProfileServiceUtil
64 .getManagedComponent(((ApplicationServerComponent) discoveryContext
65 .getParentResourceComponent()).getConnection(),
66 new ComponentType(
67 PluginConstants.ComponentType.Engine.MODESHAPE_TYPE,
68 PluginConstants.ComponentType.Engine.MODESHAPE_SUB_TYPE),
69 PluginConstants.ComponentType.Engine.MODESHAPE_ENGINE);
70
71 String version = ProfileServiceUtil.stringValue(ModeShapeManagementView.executeManagedOperation(mc, "getVersion", new MetaValue[]{null}));
72
73
74
75
76
77
78 DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
79 discoveryContext.getResourceType(),
80 mc.getName(),
81 PluginConstants.ComponentType.Engine.MODESHAPE_DISPLAYNAME,
82
83 version,
84 PluginConstants.ComponentType.Engine.MODESHAPE_ENGINE,
85 discoveryContext.getDefaultPluginConfiguration(),
86 null
87 );
88
89
90 discoveredResources.add(detail);
91 log.info("Discovered ModeShape Engine");
92 return discoveredResources;
93
94 }
95 }