[teiid-commits] teiid SVN: r2072 - in trunk/console/src/main: java/org/teiid/rhq/plugin and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Apr 22 13:22:36 EDT 2010


Author: tejones
Date: 2010-04-22 13:22:34 -0400 (Thu, 22 Apr 2010)
New Revision: 2072

Modified:
   trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java
   trunk/console/src/main/resources/META-INF/rhq-plugin.xml
Log:
Added getTransactions() and terminateTransaction(xid) operations on the Platform resource

Modified: trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java	2010-04-21 19:07:27 UTC (rev 2071)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java	2010-04-22 17:22:34 UTC (rev 2072)
@@ -32,6 +32,7 @@
 import org.rhq.core.domain.configuration.PropertySimple;
 import org.teiid.adminapi.Request;
 import org.teiid.adminapi.Session;
+import org.teiid.adminapi.Transaction;
 import org.teiid.rhq.comm.ExecutedResult;
 import org.teiid.rhq.plugin.util.PluginConstants;
 import org.teiid.rhq.plugin.util.ProfileServiceUtil;
@@ -144,7 +145,9 @@
 			final String operationName, final Map<String, Object> valueMap) {
 		Collection<Request> resultObject = new ArrayList<Request>();
 		Collection<Session> activeSessionsCollection = new ArrayList<Session>();
+		Collection<Transaction> transactionsCollection = new ArrayList<Transaction>();
 
+
 		if (operationName.equals(Platform.Operations.GET_LONGRUNNINGQUERIES)) {
 			Integer longRunningValue = (Integer) valueMap
 					.get(Operation.Value.LONG_RUNNING_QUERY_LIMIT);
@@ -165,6 +168,23 @@
 			getRequestCollectionValue(requestMetaValue, resultObject);
 			operationResult.setContent(createReportResultList(fieldNameList,
 					resultObject.iterator()));
+		} else if (operationName.equals(Platform.Operations.GET_TRANSACTIONS)) {
+			List<String> fieldNameList = operationResult.getFieldNameList();
+			MetaValue transactionMetaValue = getTransactions();
+			getTransactionCollectionValue(transactionMetaValue, transactionsCollection);
+			operationResult.setContent(createReportResultList(fieldNameList,
+					resultObject.iterator()));
+		} else if (operationName.equals(Platform.Operations.KILL_TRANSACTION)) {
+			Long sessionID = (Long) valueMap.get(Operation.Value.TRANSACTION_ID);
+			MetaValue[] args = new MetaValue[] { metaValueFactory
+					.create(sessionID) };
+			try {
+				executeManagedOperation(mc, Platform.Operations.KILL_TRANSACTION,
+						args);
+			} catch (Exception e) {
+				final String msg = "Exception executing operation: " + Platform.Operations.KILL_TRANSACTION; //$NON-NLS-1$
+				LOG.error(msg, e);
+			}
 		} else if (operationName.equals(Platform.Operations.KILL_SESSION)) {
 			Long sessionID = (Long) valueMap.get(Operation.Value.SESSION_ID);
 			MetaValue[] args = new MetaValue[] { metaValueFactory
@@ -257,6 +277,24 @@
 
 	}
 
+	protected MetaValue getTransactions() {
+
+		MetaValue transactionsCollection = null;
+		MetaValue args = null;
+
+		try {
+			transactionsCollection = executeManagedOperation(mc,
+					Platform.Operations.GET_TRANSACTIONS, args);
+		} catch (Exception e) {
+			final String msg = "Exception executing operation: " + Platform.Operations.GET_TRANSACTIONS; //$NON-NLS-1$
+			LOG.error(msg, e);
+		}
+
+		return transactionsCollection;
+
+	}
+
+	
 	public MetaValue getSessions() {
 
 		MetaValue sessionCollection = null;
@@ -468,7 +506,26 @@
 			}
 		}
 	}
+	
+	public static <T> void getTransactionCollectionValue(MetaValue pValue,
+			Collection<Transaction> list) {
+		MetaType metaType = pValue.getMetaType();
+		if (metaType.isCollection()) {
+			for (MetaValue value : ((CollectionValueSupport) pValue)
+					.getElements()) {
+				if (value.getMetaType().isComposite()) {
+					Transaction transaction = (Transaction) MetaValueFactory.getInstance()
+							.unwrap(value);
+					list.add(transaction);
+				} else {
+					throw new IllegalStateException(pValue
+							+ " is not a Composite type");
+				}
+			}
+		}
+	}
 
+
 	public static <T> void getSessionCollectionValue(MetaValue pValue,
 			Collection<Session> list) {
 		MetaType metaType = pValue.getMetaType();

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java	2010-04-21 19:07:27 UTC (rev 2071)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java	2010-04-22 17:22:34 UTC (rev 2072)
@@ -29,16 +29,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.managed.api.ManagedComponent;
-import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.RunState;
 import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
 import org.rhq.core.domain.measurement.AvailabilityType;
 import org.rhq.core.domain.measurement.MeasurementDataNumeric;
 import org.rhq.core.domain.measurement.MeasurementReport;
 import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
 import org.teiid.rhq.admin.DQPManagementView;
 import org.teiid.rhq.plugin.util.PluginConstants;
 import org.teiid.rhq.plugin.util.ProfileServiceUtil;
@@ -61,7 +57,7 @@
 
 	@Override
 	public AvailabilityType getAvailability() {
-				
+
 		RunState runState;
 		try {
 			runState = ProfileServiceUtil.getDQPManagementView().getRunState();
@@ -76,9 +72,9 @@
 							+ PluginConstants.ComponentType.Platform.TEIID_RUNTIME_ENGINE);
 			return AvailabilityType.DOWN;
 		}
-        return (runState == RunState.RUNNING) ? AvailabilityType.UP :
-                AvailabilityType.DOWN;
-				
+		return (runState == RunState.RUNNING) ? AvailabilityType.UP
+				: AvailabilityType.DOWN;
+
 	}
 
 	@Override
@@ -96,10 +92,13 @@
 					Operation.Value.REQUEST_ID).getLongValue());
 			valueMap.put(Operation.Value.SESSION_ID, configuration.getSimple(
 					Operation.Value.SESSION_ID).getLongValue());
+		} else if (name.equals(Platform.Operations.KILL_REQUEST)) {
+			valueMap.put(Operation.Value.TRANSACTION_ID, configuration.getSimple(
+					Operation.Value.TRANSACTION_ID).getLongValue());
 		} else if (name.equals(Platform.Operations.KILL_SESSION)) {
 			valueMap.put(Operation.Value.SESSION_ID, configuration.getSimple(
 					Operation.Value.SESSION_ID).getLongValue());
-		} 
+		}
 
 	}
 
@@ -111,60 +110,67 @@
 
 		Map<String, Object> valueMap = new HashMap<String, Object>();
 
-		for (MeasurementScheduleRequest request : requests) {
-			String name = request.getName();
-			LOG.debug("Measurement name = " + name); //$NON-NLS-1$
+		try {
+			for (MeasurementScheduleRequest request : requests) {
+				String name = request.getName();
+				LOG.debug("Measurement name = " + name); //$NON-NLS-1$
 
-			// Initialize any parameters to be used in the retrieval of metric
-			// values
-			if (request
-					.getName()
-					.equals(
-							PluginConstants.ComponentType.Platform.Metrics.LONG_RUNNING_QUERIES)) {
-				Integer value = getResourceConfiguration()
-						.getSimple(
-								PluginConstants.Operation.Value.LONG_RUNNING_QUERY_LIMIT)
-						.getIntegerValue();
-				valueMap
-						.put(
-								PluginConstants.Operation.Value.LONG_RUNNING_QUERY_LIMIT,
-								value);
-			}
-
-			Object metricReturnObject = view.getMetric(getComponentType(), this
-					.getComponentIdentifier(), name, valueMap);
-
-			try {
+				// Initialize any parameters to be used in the retrieval of
+				// metric
+				// values
 				if (request
 						.getName()
 						.equals(
-								PluginConstants.ComponentType.Platform.Metrics.QUERY_COUNT)) {
-					report.addData(new MeasurementDataNumeric(request,
-							(Double) metricReturnObject));
-				} else {
+								PluginConstants.ComponentType.Platform.Metrics.LONG_RUNNING_QUERIES)) {
+					Integer value = getResourceConfiguration()
+							.getSimple(
+									PluginConstants.Operation.Value.LONG_RUNNING_QUERY_LIMIT)
+							.getIntegerValue();
+					valueMap
+							.put(
+									PluginConstants.Operation.Value.LONG_RUNNING_QUERY_LIMIT,
+									value);
+				}
+
+				Object metricReturnObject = view.getMetric(getComponentType(),
+						this.getComponentIdentifier(), name, valueMap);
+
+				try {
 					if (request
 							.getName()
 							.equals(
-									PluginConstants.ComponentType.Platform.Metrics.SESSION_COUNT)) {
+									PluginConstants.ComponentType.Platform.Metrics.QUERY_COUNT)) {
 						report.addData(new MeasurementDataNumeric(request,
 								(Double) metricReturnObject));
 					} else {
 						if (request
 								.getName()
 								.equals(
-										PluginConstants.ComponentType.Platform.Metrics.LONG_RUNNING_QUERIES)) {
+										PluginConstants.ComponentType.Platform.Metrics.SESSION_COUNT)) {
 							report.addData(new MeasurementDataNumeric(request,
 									(Double) metricReturnObject));
+						} else {
+							if (request
+									.getName()
+									.equals(
+											PluginConstants.ComponentType.Platform.Metrics.LONG_RUNNING_QUERIES)) {
+								report.addData(new MeasurementDataNumeric(
+										request, (Double) metricReturnObject));
+							}
+
 						}
+					}
 
-					}
+				} catch (Exception e) {
+					LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
+							+ "]. Cause: " + e); //$NON-NLS-1$
+					throw (e);
 				}
-
-			} catch (Exception e) {
-				LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
-						+ "]. Cause: " + e); //$NON-NLS-1$
-				throw(e);
 			}
+		} catch (Exception e) {
+			LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
+					+ "]. Cause: " + e); //$NON-NLS-1$
+			throw (e);
 		}
 
 	}
@@ -175,5 +181,4 @@
 		super.stop();
 	}
 
-
 }
\ No newline at end of file

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java	2010-04-21 19:07:27 UTC (rev 2071)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java	2010-04-22 17:22:34 UTC (rev 2072)
@@ -73,8 +73,10 @@
 				public final static String GET_LONGRUNNINGQUERIES = "listLongRunningQueries"; //$NON-NLS-1$
 				public final static String KILL_REQUEST = "cancelRequest"; //$NON-NLS-1$
 				public final static String KILL_SESSION = "terminateSession"; //$NON-NLS-1$
+				public final static String KILL_TRANSACTION = "terminateTransaction"; //$NON-NLS-1$
 				public final static String GET_PROPERTIES = "getProperties"; //$NON-NLS-1$
 				public final static String GET_REQUESTS = "getRequests"; //$NON-NLS-1$
+				public final static String GET_TRANSACTIONS = "getTransactions"; //$NON-NLS-1$
 				public final static String GET_SESSIONS = "getSessions"; //$NON-NLS-1$
 
 			}
@@ -207,7 +209,7 @@
 			public final static String LONG_RUNNING_QUERY_LIMIT = "longRunningQueryLimit"; //$NON-NLS-1$
 
 			public final static String FIELD_LIST = "fieldList"; //$NON-NLS-1$
-
+			public final static String TRANSACTION_ID = "transactionID"; //$NON-NLS-1$
 			public final static String REQUEST_ID = "requestID"; //$NON-NLS-1$
 			public final static String SESSION_ID = "sessionID"; //$NON-NLS-1$
 

Modified: trunk/console/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- trunk/console/src/main/resources/META-INF/rhq-plugin.xml	2010-04-21 19:07:27 UTC (rev 2071)
+++ trunk/console/src/main/resources/META-INF/rhq-plugin.xml	2010-04-22 17:22:34 UTC (rev 2072)
@@ -16,7 +16,7 @@
 		Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
 		02110-1301 USA. */
 	-->
-	
+
 <plugin name="TeiidPlugin" displayName="Teiid Plugin" package="org.teiid.rhq.plugin"
 	version="2.0.0" description="Supports management and monitoring of JBoss Teiid"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:xmlns:rhq-plugin"
@@ -375,6 +375,37 @@
 				</results>
 			</operation>
 
+			<operation name="getTransactions" displayName="View current transactions"
+				description="Get current transactions executing against this VDB">
+				<results>
+					<c:list-property name="list" displayName="Current Transactions"
+						description="Transactions currently executing against the Teiid system"
+						required="false">
+						<c:map-property name="map">
+							<c:simple-property displayName="Transaction ID"
+								name="getId" type="string"
+								description="The Xid string for GLOBAL transactions or the Transaction id string LOCAL/REQUEST." />
+							<c:simple-property displayName="Session ID"
+								name="getAssociatedSession" type="string"
+								description="Get the session associated with the this transaction. May be null for an unassociated Global transaction." />
+							<c:simple-property displayName="Scope" name="getScope"
+								type="string"
+								description="Get the scope for the transaction.  Will be one of GLOBAL, LOCAL, or REQUEST" />
+							<c:simple-property displayName="Created Time"
+								name="getCreatedTime" type="string" description="The local creation time." />
+						</c:map-property>
+					</c:list-property>
+				</results>
+			</operation>
+
+			<operation name="terminateTransaction" displayName="Terminate Transaction"
+				description="Terminate a specified transaction">
+				<parameters>
+					<c:simple-property displayName="Transaction ID" name="transactionID"
+						type="long" required="true" description="The ID of the transaction to terminate" />
+				</parameters>
+			</operation>
+
 			<metric displayName="Status" defaultOn="true" dataType="trait"
 				displayType="summary" category="availability" property="status"
 				description="The status of this VDB" />



More information about the teiid-commits mailing list