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.HashMap;
27 import java.util.Map;
28 import java.util.Set;
29
30 import javax.naming.NamingException;
31
32 import org.jboss.metatype.api.values.MetaValue;
33 import org.jboss.metatype.api.values.SimpleValueSupport;
34 import org.mc4j.ems.connection.EmsConnection;
35 import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
36 import org.modeshape.rhq.plugin.util.PluginConstants;
37 import org.modeshape.rhq.plugin.util.ProfileServiceUtil;
38 import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType;
39 import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType.Connector;
40 import org.rhq.core.domain.configuration.Configuration;
41 import org.rhq.core.domain.measurement.AvailabilityType;
42 import org.rhq.core.domain.measurement.MeasurementDataTrait;
43 import org.rhq.core.domain.measurement.MeasurementReport;
44 import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
45 import org.rhq.core.pluginapi.inventory.CreateResourceReport;
46 import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
47
48 public class ConnectorComponent extends Facet {
49
50
51
52
53
54
55 @Override
56 String getComponentType() {
57 return ComponentType.Connector.NAME;
58 }
59
60
61
62
63
64
65 @Override
66 public AvailabilityType getAvailability() {
67
68 MetaValue value;
69 Boolean pingResultSuccess = new Boolean(false);
70 try {
71 String connectorName = this.resourceContext.getResourceKey();
72 MetaValue[] args = new MetaValue[] { SimpleValueSupport.wrap(connectorName) };
73 value = ModeShapeManagementView.executeManagedOperation(
74 ProfileServiceUtil.getManagedEngine(getConnection()),
75 "pingConnector", args);
76 pingResultSuccess = ProfileServiceUtil.booleanValue(value);
77 } catch (NamingException e) {
78 LOG.error("Naming exception getting: "
79 + PluginConstants.ComponentType.Engine.MODESHAPE_ENGINE);
80 return AvailabilityType.DOWN;
81 } catch (Exception e) {
82 LOG.error("Naming exception getting: "
83 + PluginConstants.ComponentType.Engine.MODESHAPE_ENGINE);
84 return AvailabilityType.DOWN;
85 }
86
87 return (pingResultSuccess) ? AvailabilityType.UP
88 : AvailabilityType.DOWN;
89 }
90
91
92
93
94
95
96
97 @Override
98 protected void setOperationArguments(String name,
99 Configuration configuration, Map<String, Object> valueMap) {
100 valueMap.put(Connector.Operations.Parameters.CONNECTOR_NAME,
101 this.resourceContext.getResourceKey());
102
103 if (name.equals(Connector.Operations.PING)) {
104
105 }
106 }
107
108
109
110
111
112
113
114 @Override
115 public void getValues(MeasurementReport report,
116 Set<MeasurementScheduleRequest> requests) throws Exception {
117
118 ModeShapeManagementView view = new ModeShapeManagementView();
119
120 Map<String, Object> valueMap = new HashMap<String, Object>();
121 valueMap.put(Connector.Operations.Parameters.CONNECTOR_NAME,
122 this.resourceContext.getResourceKey());
123
124 for (MeasurementScheduleRequest request : requests) {
125 String name = request.getName();
126 LOG.debug("Measurement name = " + name);
127
128 Object metricReturnObject = view.getMetric(getConnection(),
129 getComponentType(), this.getComponentIdentifier(), name,
130 valueMap);
131
132 try {
133 if (request
134 .getName()
135 .equals(
136 PluginConstants.ComponentType.Connector.Metrics.INUSECONNECTIONS)) {
137 report.addData(new MeasurementDataTrait(request,
138 (String) metricReturnObject));
139 }
140 } catch (Exception e) {
141 LOG.error("Failed to obtain measurement [" + name
142 + "]. Cause: " + e);
143
144 }
145 }
146
147 }
148
149
150
151
152
153
154 @Override
155 public CreateResourceReport createResource(CreateResourceReport arg0) {
156 return null;
157 }
158
159
160
161
162
163
164 @Override
165 public ProfileServiceConnection getConnection() {
166 return ((EngineComponent) this.resourceContext
167 .getParentResourceComponent()).getConnection();
168 }
169
170
171
172
173
174
175 @Override
176 public EmsConnection getEmsConnection() {
177 return null;
178 }
179
180 }