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 if (mc==null){
72 log.debug("No ModeShape Engine discovered");
73 return discoveredResources;
74 }
75
76 String version = ProfileServiceUtil.stringValue(ModeShapeManagementView.executeManagedOperation(mc, "getVersion", new MetaValue[]{null}));
77
78
79
80
81
82
83 DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
84 discoveryContext.getResourceType(),
85 mc.getName(),
86 PluginConstants.ComponentType.Engine.MODESHAPE_DISPLAYNAME,
87
88 version,
89 PluginConstants.ComponentType.Engine.MODESHAPE_ENGINE,
90 discoveryContext.getDefaultPluginConfiguration(),
91 null
92 );
93
94
95 discoveredResources.add(detail);
96 log.debug("Discovered ModeShape Engine");
97 return discoveredResources;
98
99 }
100 }