View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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 org.mc4j.ems.connection.EmsConnection;
31  import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
32  import org.modeshape.rhq.plugin.util.PluginConstants;
33  import org.rhq.core.domain.measurement.MeasurementDataTrait;
34  import org.rhq.core.domain.measurement.MeasurementReport;
35  import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
36  import org.rhq.core.pluginapi.inventory.CreateResourceReport;
37  import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
38  
39  public class SequencingServiceComponent extends Facet {
40  
41  	/**
42  	 * {@inheritDoc}
43  	 * 
44  	 * @see org.modeshape.rhq.plugin.Facet#getComponentType()
45  	 */
46  	@Override
47  	String getComponentType() {
48  		return PluginConstants.ComponentType.SequencingService.NAME;
49  	}
50  
51  	/**
52  	 * {@inheritDoc}
53  	 * 
54  	 * @see org.modeshape.rhq.plugin.Facet#getValues(org.rhq.core.domain.measurement.MeasurementReport,
55  	 *      java.util.Set)
56  	 */
57  	@Override
58  	public void getValues(MeasurementReport report,
59  			Set<MeasurementScheduleRequest> requests) throws Exception {
60  
61  		ModeShapeManagementView view = new ModeShapeManagementView();
62  
63  		Map<String, Object> valueMap = new HashMap<String, Object>();
64  		valueMap.put(PluginConstants.ComponentType.SequencingService.NAME,
65  				this.resourceContext.getResourceKey());
66  
67  		for (MeasurementScheduleRequest request : requests) {
68  			String name = request.getName();
69  			LOG.debug("Measurement name = " + name); //$NON-NLS-1$
70  
71  			Object metricReturnObject = view.getMetric(getConnection(),
72  					getComponentType(), this.getComponentIdentifier(), name,
73  					valueMap);
74  
75  			try {
76  				if (request
77  						.getName()
78  						.equals(
79  								PluginConstants.ComponentType.SequencingService.Metrics.NUM_NODES_SEQUENCED)) {
80  					report.addData(new MeasurementDataTrait(request, (String) metricReturnObject));
81  				} else {
82  					if (request
83  							.getName()
84  							.equals(
85  									PluginConstants.ComponentType.SequencingService.Metrics.NUM_NODES_SKIPPED)) {
86  						report.addData(new MeasurementDataTrait(request, (String) metricReturnObject));
87  					}
88  
89  				}
90  
91  			} catch (Exception e) {
92  				LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
93  						+ "]. Cause: " + e); //$NON-NLS-1$
94  				// throw(e);
95  			}
96  		}
97  
98  	}
99  
100 	/**
101 	 * {@inheritDoc}
102 	 * 
103 	 * @see org.rhq.core.pluginapi.inventory.CreateChildResourceFacet#createResource(org.rhq.core.pluginapi.inventory.CreateResourceReport)
104 	 */
105 	@Override
106 	public CreateResourceReport createResource(CreateResourceReport arg0) {
107 		return null;
108 	}
109 
110 	/**
111 	 * {@inheritDoc}
112 	 * 
113 	 * @see org.rhq.plugins.jbossas5.ProfileServiceComponent#getConnection()
114 	 */
115 	@Override
116 	public ProfileServiceConnection getConnection() {
117 		return ((EngineComponent) this.resourceContext
118 				.getParentResourceComponent()).getConnection();
119 	}
120 
121 	/**
122 	 * {@inheritDoc}
123 	 * 
124 	 * @see org.rhq.plugins.jmx.JMXComponent#getEmsConnection()
125 	 */
126 	@Override
127 	public EmsConnection getEmsConnection() {
128 		return null;
129 	}
130 
131 }