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.ManagedComponent;
32 import org.jboss.metatype.api.values.CollectionValueSupport;
33 import org.jboss.metatype.api.values.CompositeValueSupport;
34 import org.jboss.metatype.api.values.MetaValue;
35 import org.jboss.metatype.api.values.MetaValueFactory;
36 import org.modeshape.jboss.managed.ManagedEngine;
37 import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
38 import org.modeshape.rhq.plugin.util.PluginConstants;
39 import org.modeshape.rhq.plugin.util.ProfileServiceUtil;
40 import org.rhq.core.domain.configuration.Configuration;
41 import org.rhq.core.domain.configuration.PropertyList;
42 import org.rhq.core.domain.configuration.PropertyMap;
43 import org.rhq.core.domain.configuration.PropertySimple;
44 import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
45 import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
46 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
47 import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
48
49
50
51
52 public class ConnectorDiscoveryComponent implements
53 ResourceDiscoveryComponent<ConnectorComponent> {
54
55 private final Log log = LogFactory
56 .getLog(PluginConstants.DEFAULT_LOGGER_CATEGORY);
57
58
59
60
61
62
63 public Set<DiscoveredResourceDetails> discoverResources(
64 ResourceDiscoveryContext discoveryContext)
65 throws InvalidPluginConfigurationException, Exception {
66
67 Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
68
69 ManagedComponent mc = ProfileServiceUtil
70 .getManagedEngine(
71 ((EngineComponent) discoveryContext
72 .getParentResourceComponent()).getConnection());
73
74 String operation = "getConnectors";
75
76 MetaValue connectors = ModeShapeManagementView.executeManagedOperation(
77 mc, operation, new MetaValue[] { null });
78
79 if (connectors == null) {
80 return discoveredResources;
81 }
82
83 MetaValue[] mvConnectorArray = ((CollectionValueSupport) connectors)
84 .getElements();
85
86 for (MetaValue value : mvConnectorArray) {
87
88 CompositeValueSupport cvs = (CompositeValueSupport) value;
89 String name = ProfileServiceUtil.stringValue(cvs.get("name"));
90
91
92
93
94
95
96 DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
97 discoveryContext.getResourceType(),
98 name,
99 name,
100 null,
101 PluginConstants.ComponentType.Connector.DESCRIPTION,
102 discoveryContext.getDefaultPluginConfiguration(),
103
104 null
105 );
106
107 Configuration c = detail.getPluginConfiguration();
108
109
110
111 operation = "getProperties";
112
113 MetaValue[] args = new MetaValue[] {
114 MetaValueFactory.getInstance().create(name),
115 MetaValueFactory.getInstance().create(
116 ManagedEngine.Component.CONNECTOR) };
117
118 MetaValue properties = ModeShapeManagementView
119 .executeManagedOperation(mc, operation, args);
120
121 MetaValue[] propertyArray = ((CollectionValueSupport) properties)
122 .getElements();
123
124 PropertyList connectorlist = new PropertyList("connectorPropertyList");
125 c.put(connectorlist);
126 loadProperties(propertyArray, connectorlist);
127
128
129 args = new MetaValue[] {
130 MetaValueFactory.getInstance().create(name),
131 MetaValueFactory.getInstance().create(
132 ManagedEngine.Component.CONNECTIONPOOL) };
133
134 properties = ModeShapeManagementView
135 .executeManagedOperation(mc, operation, args);
136
137 propertyArray = ((CollectionValueSupport) properties)
138 .getElements();
139 PropertyList connectionPoollist = new PropertyList("connectionpoolPropertyList");
140 c.put(connectionPoollist);
141 loadProperties(propertyArray, connectionPoollist);
142
143 detail.setPluginConfiguration(c);
144
145
146 discoveredResources.add(detail);
147 log.info("Discovered ModeShape repositories: " + mc.getName());
148 }
149
150 return discoveredResources;
151
152 }
153
154
155
156
157
158
159 private void loadProperties(MetaValue[] propertyArray, PropertyList list)
160 throws Exception {
161 PropertyMap propMap;
162 for (MetaValue property : propertyArray) {
163
164 CompositeValueSupport proCvs = (CompositeValueSupport) property;
165 propMap = new PropertyMap("map");
166 propMap.put(new PropertySimple("label", ProfileServiceUtil
167 .stringValue(proCvs.get("label"))));
168 propMap.put(new PropertySimple("value", ProfileServiceUtil
169 .stringValue(proCvs.get("value"))));
170 propMap.put(new PropertySimple("description", ProfileServiceUtil
171 .stringValue(proCvs.get("description"))));
172 list.add(propMap);
173 }
174 }
175 }