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.modeshape.rhq.plugin.util.PluginConstants.ComponentType;
34  import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType.Connector;
35  import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType.Engine;
36  import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType.Repository;
37  import org.rhq.core.domain.configuration.Configuration;
38  import org.rhq.core.domain.measurement.AvailabilityType;
39  import org.rhq.core.domain.measurement.MeasurementDataTrait;
40  import org.rhq.core.domain.measurement.MeasurementReport;
41  import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
42  import org.rhq.core.pluginapi.inventory.CreateResourceReport;
43  import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
44  import org.rhq.core.pluginapi.inventory.CreateResourceReport;
45  import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
46  
47  public class RepositoryComponent extends Facet {
48  
49  	/**
50  	 * {@inheritDoc}
51  	 *
52  	 * @see org.modeshape.rhq.plugin.Facet#getComponentType()
53  	 */
54  	@Override
55  	String getComponentType() {
56  		return ComponentType.Repository.NAME;
57  	}
58  	
59  	/**
60  	 * {@inheritDoc}
61  	 *
62  	 * @see org.modeshape.rhq.plugin.Facet#setOperationArguments(java.lang.String, org.rhq.core.domain.configuration.Configuration, java.util.Map)
63  	 */
64  	@Override
65  	protected void setOperationArguments(String name,
66  			Configuration configuration, Map<String, Object> valueMap) {
67  		// Parameter logic for engine Operations
68  		if (name.equals(Engine.Operations.SHUTDOWN)) {
69  			//no parms
70  		} else if (name.equals(Engine.Operations.RESTART)) {
71  			//no parms
72  		} 
73  	}
74  
75  	/**
76  	 * {@inheritDoc}
77  	 *
78  	 * @see org.modeshape.rhq.plugin.Facet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set)
79  	 */
80  	@Override
81  	public void getValues(MeasurementReport report,
82  			Set<MeasurementScheduleRequest> requests) throws Exception {
83  		
84  		ModeShapeManagementView view = new ModeShapeManagementView();
85  
86  		Map<String, Object> valueMap = new HashMap<String, Object>();
87  		valueMap.put(Repository.Operations.Parameters.REPOSITORY_NAME,
88  				this.resourceContext.getResourceKey());
89  
90  		for (MeasurementScheduleRequest request : requests) {
91  			String name = request.getName();
92  			LOG.debug("Measurement name = " + name); //$NON-NLS-1$
93  
94  			Object metricReturnObject = view.getMetric(getConnection(),
95  					getComponentType(), this.getComponentIdentifier(), name,
96  					valueMap);
97  
98  			try {
99  				if (request
100 						.getName()
101 						.equals(
102 								PluginConstants.ComponentType.Repository.Metrics.ACTIVESESSIONS)) {
103 					report.addData(new MeasurementDataTrait(request,
104 							(String) metricReturnObject));
105 				}
106 			} catch (Exception e) {
107 				LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
108 						+ "]. Cause: " + e); //$NON-NLS-1$
109 				// throw(e);
110 			}
111 		}
112 	}
113 
114 	/**
115 	 * {@inheritDoc}
116 	 *
117 	 * @see org.rhq.core.pluginapi.inventory.CreateChildResourceFacet#createResource(org.rhq.core.pluginapi.inventory.CreateResourceReport)
118 	 */
119 	@Override
120 	public CreateResourceReport createResource(CreateResourceReport arg0) {
121 		return null;
122 	}
123 
124 	/**
125 	 * {@inheritDoc}
126 	 *
127 	 * @see org.rhq.plugins.jbossas5.ProfileServiceComponent#getConnection()
128 	 */
129 	@Override
130 	public ProfileServiceConnection getConnection() {
131 		return ((EngineComponent) this.resourceContext
132 				.getParentResourceComponent()).getConnection();
133 	}
134 
135 	/**
136 	 * {@inheritDoc}
137 	 *
138 	 * @see org.rhq.plugins.jmx.JMXComponent#getEmsConnection()
139 	 */
140 	@Override
141 	public EmsConnection getEmsConnection() {
142 		return null;
143 	}
144 
145 }