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.Map;
27  import java.util.Set;
28  
29  import javax.naming.NamingException;
30  
31  import org.jboss.managed.api.ManagedComponent;
32  import org.jboss.metatype.api.values.MetaValue;
33  import org.mc4j.ems.connection.EmsConnection;
34  import org.modeshape.rhq.plugin.util.ModeShapeManagementView;
35  import org.modeshape.rhq.plugin.util.ProfileServiceUtil;
36  import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType;
37  import org.modeshape.rhq.plugin.util.PluginConstants.ComponentType.Engine;
38  import org.rhq.core.domain.configuration.Configuration;
39  import org.rhq.core.domain.measurement.AvailabilityType;
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.ApplicationServerComponent;
44  import org.rhq.plugins.jbossas5.connection.ProfileServiceConnection;
45  
46  public class EngineComponent extends Facet {
47  	
48  	/**
49  	 * {@inheritDoc}
50  	 * 
51  	 * @see org.modeshape.rhq.plugin.Facet#getComponentType()
52  	 */
53  	@Override
54  	String getComponentType() {
55  		return ComponentType.Engine.MODESHAPE_ENGINE;
56  	}
57  
58  	/**
59  	 * {@inheritDoc}
60  	 * 
61  	 * @see org.modeshape.rhq.plugin.Facet#getAvailability()
62  	 */
63  	@Override
64  	public AvailabilityType getAvailability() {
65  		AvailabilityType isRunning = AvailabilityType.DOWN;
66  
67  		try {
68  			ManagedComponent mc = ProfileServiceUtil.getManagedEngine(this
69  					.getConnection());
70  			MetaValue running = ModeShapeManagementView
71  					.executeManagedOperation(mc, "isRunning",
72  							new MetaValue[] { null });
73  			if (ProfileServiceUtil.booleanValue(running).equals(Boolean.TRUE)) {
74  				isRunning = AvailabilityType.UP;
75  			}
76  		} catch (NamingException e) {
77  			LOG.error("NamingException in getAvailability", e);
78  		} catch (Exception e) {
79  			LOG.error("Exception in getAvailability", e);
80  		}
81  
82  		return isRunning;
83  	}
84  	
85  	
86  	/**
87  	 * {@inheritDoc}
88  	 *
89  	 * @see org.modeshape.rhq.plugin.Facet#setOperationArguments(java.lang.String, org.rhq.core.domain.configuration.Configuration, java.util.Map)
90  	 */
91  	@Override
92  	protected void setOperationArguments(String name,
93  			Configuration configuration, Map<String, Object> valueMap) {
94  		// Parameter logic for engine Operations
95  		if (name.equals(Engine.Operations.SHUTDOWN)) {
96  			//no parms
97  		} else if (name.equals(Engine.Operations.RESTART)) {
98  			//no parms
99  		} 
100 	}
101 
102 	
103 
104 
105 	/**
106 	 * {@inheritDoc}
107 	 * 
108 	 * @see org.modeshape.rhq.plugin.Facet#getValues(org.rhq.core.domain.measurement.MeasurementReport,
109 	 *      java.util.Set)
110 	 */
111 	@Override
112 	public void getValues(MeasurementReport arg0,
113 			Set<MeasurementScheduleRequest> arg1) throws Exception {
114 	}
115 
116 	/**
117 	 * {@inheritDoc}
118 	 * 
119 	 * @see org.rhq.core.pluginapi.inventory.CreateChildResourceFacet#createResource(org.rhq.core.pluginapi.inventory.CreateResourceReport)
120 	 */
121 	@Override
122 	public CreateResourceReport createResource(CreateResourceReport arg0) {
123 		return null;
124 	}
125 
126 	/**
127 	 * {@inheritDoc}
128 	 *
129 	 * @see org.rhq.plugins.jbossas5.ProfileServiceComponent#getConnection()
130 	 */
131 	@Override
132 	public ProfileServiceConnection getConnection() {
133 		return ((ApplicationServerComponent) this.resourceContext
134 				.getParentResourceComponent()).getConnection();
135 	}
136 
137 	/**
138 	 * {@inheritDoc}
139 	 *
140 	 * @see org.rhq.plugins.jmx.JMXComponent#getEmsConnection()
141 	 */
142 	@Override
143 	public EmsConnection getEmsConnection() {
144 		return null;
145 	}
146 
147 }