[teiid-commits] teiid SVN: r1846 - in trunk/console/src/main/java/org/teiid/rhq/admin: utils and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Feb 19 11:27:36 EST 2010


Author: tejones
Date: 2010-02-19 11:27:35 -0500 (Fri, 19 Feb 2010)
New Revision: 1846

Added:
   trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
Removed:
   trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java
   trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java
Log:
TEIID-807: Cleaned up legacy code and added VDB deployment/un-deployment. Also added operation execution framework.

Deleted: trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java	2010-02-19 16:26:46 UTC (rev 1845)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java	2010-02-19 16:27:35 UTC (rev 1846)
@@ -1,66 +0,0 @@
-package org.teiid.rhq.admin;
-
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
-
-
-public interface ConnectionMgr {
-
-	/**
-	 * Called to indicate that this manager should be initialized.
-	 * @param props
-	 * @param cl is the ClassLoader to use to instantiate any classes downstream
-	 */
-	void initialize(Properties props, ClassLoader cl);
-	
-	/**
-	 * Called to reset the pool.   A subsequent call to @see #initialize(Properties, ClassLoader)
-	 * would establish a new set of installations based on the properties.
-	 */
-	void shutdown();
-	
-	/**
-	 * Returns <code>true</code> if server installations have been configured and will be returned
-	 * in the {@link #getServerInstallations()} call.
-	 * @return true if servers are defined.
-	 */
-	
-	 boolean hasServersDefined();
-	 
-	 
-	 /**
-	  * Returns the unique set of keys for each installation
-	  * @return Set of unique keys 
-	  */
-	 Set getInstallationSystemKeys();
-	 
-
-	
-	/**
-     * this is called only during discovery to obtain a connection for each 
-     * system (or server installation) on the local machine.
-     * 
-     *  In cases where a connection cannot be obtained, an entry in the
-     *  <code>Map</code> will be added with a null set for the value <code>Connection</code>
-     * @return Map <key=installdir value=Connection>
-     * @throws Exception
-     * @since 1.0
-     */
-	 Map<String, Connection> getServerInstallations();
-
-    /**
-     * Called to get a {@link Connection} that will be used to
-     * call the MetaMatrix Server.
-     * @param key is the unique identifier for the system in
-     * which to obtain the connection for.  
-     * @return Connection for the system to communicate with.
-     * @throws Exception
-     * @since 1.0
-     */	
-    Connection getConnection(String key) throws ConnectionException;
-
-}

Added: trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java	                        (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java	2010-02-19 16:27:35 UTC (rev 1846)
@@ -0,0 +1,365 @@
+package org.teiid.rhq.admin;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.NamingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.teiid.adminapi.impl.RequestMetadata;
+import org.teiid.adminapi.impl.RequestMetadataMapper;
+import org.teiid.adminapi.impl.SessionMetadata;
+import org.teiid.adminapi.impl.SessionMetadataMapper;
+import org.teiid.rhq.comm.ExecutedResult;
+import org.teiid.rhq.plugin.util.PluginConstants;
+import org.teiid.rhq.plugin.util.ProfileServiceUtil;
+import org.teiid.rhq.plugin.util.PluginConstants.ComponentType.Platform;
+import org.teiid.rhq.plugin.util.PluginConstants.ComponentType.Platform.Metrics;
+import org.teiid.rhq.plugin.util.PluginConstants.ComponentType.Platform.Operations;
+
+import com.metamatrix.core.MetaMatrixRuntimeException;
+
+public class DQPManagementView implements PluginConstants{
+
+	private static ManagedComponent mc = null;
+	private static final Log LOG = LogFactory.getLog(DQPManagementView.class);
+
+	public DQPManagementView() {
+
+	}
+
+	/*
+	 * Metric methods
+	 */
+	public Object getMetric(String componentType, String identifier,
+			String metric, Map<String, Object> valueMap) {
+		Object resultObject = new Object();
+
+		if (componentType.equals(PluginConstants.ComponentType.Platform.NAME)) {
+			resultObject = getPlatformMetric(componentType, metric, valueMap);
+		} else if (componentType.equals(PluginConstants.ComponentType.VDB.NAME)) {
+			resultObject = getVdbMetric(componentType, identifier, metric,
+					valueMap);
+		}
+
+		return resultObject;
+	}
+
+	private Object getPlatformMetric(String componentType, String metric,
+			Map valueMap) {
+
+		Object resultObject = new Object();
+
+		if (metric
+				.equals(PluginConstants.ComponentType.Platform.Metrics.QUERY_COUNT)) {
+			resultObject = new Double(getQueryCount().doubleValue());
+		} else {
+			if (metric
+					.equals(PluginConstants.ComponentType.Platform.Metrics.SESSION_COUNT)) {
+				resultObject = new Double(getSessionCount().doubleValue());
+			} else {
+				if (metric
+						.equals(PluginConstants.ComponentType.Platform.Metrics.LONG_RUNNING_QUERIES)) {
+					Integer longRunningQueryLimit = (Integer) valueMap
+							.get(PluginConstants.Operation.Value.LONG_RUNNING_QUERY_LIMIT);
+					Collection<RequestMetadata> longRunningQueries = getLongRunningQueries(
+							longRunningQueryLimit);
+					resultObject = new Double(longRunningQueries.size());
+				}
+			}
+		}
+
+		return resultObject;
+	}
+
+	private Object getVdbMetric(String componentType, String identifier,
+			String metric, Map valueMap) {
+
+		Object resultObject = new Object();
+
+		// if (metric.equals(ComponentType.Metric.HIGH_WATER_MARK)) {
+		// resultObject = new Double(getHighWatermark(identifier));
+		// }
+
+		return resultObject;
+	}
+
+	/*
+	 * Operation methods
+	 */
+
+	public void executeOperation(ExecutedResult operationResult,
+			final Map valueMap) {
+
+		if (operationResult.getComponentType().equals(
+				PluginConstants.ComponentType.Platform.NAME)) {
+			executePlatformOperation(operationResult, operationResult
+					.getOperationName(), valueMap);
+		}
+
+		// else if
+		// (operationResult.getComponentType().equals(ConnectionConstants.ComponentType.Runtime.System.TYPE))
+		// {
+		// executeSystemOperation(operationResult,
+		// operationResult.getOperationName(), valueMap);
+		// } else if (operationResult.getComponentType().equals(
+		// Runtime.Process.TYPE)) {
+		// executeProcessOperation(operationResult,
+		// operationResult.getOperationName(), valueMap);
+		// } else if
+		// (operationResult.getComponentType().equals(com.metamatrix.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host.TYPE))
+		// {
+		// executeHostOperation(operationResult,
+		// operationResult.getOperationName(), valueMap);
+		// } else if
+		// (operationResult.getComponentType().equals(com.metamatrix.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session.TYPE))
+		// {
+		// executeSessionOperation(operationResult,
+		// operationResult.getOperationName(), valueMap);
+		// } else if
+		// (operationResult.getComponentType().equals(com.metamatrix.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries.TYPE))
+		// {
+		// executeQueriesOperation(operationResult,
+		// operationResult.getOperationName(), valueMap);
+		// }
+	}
+
+	private void executePlatformOperation(ExecutedResult operationResult,
+			final String operationName, final Map<String, Object> valueMap) {
+		Collection<RequestMetadata> resultObject = new ArrayList<RequestMetadata>();
+
+		if (operationName.equals(Platform.Operations.GET_LONGRUNNINGQUERIES)) {
+			Integer longRunningValue = (Integer) valueMap
+					.get(Operation.Value.LONG_RUNNING_QUERY_LIMIT);
+			List<String> fieldNameList = operationResult.getFieldNameList();
+			resultObject = getLongRunningQueries(longRunningValue);
+			operationResult.setContent(createReportResultList(fieldNameList, resultObject.iterator()));
+		} 
+		
+//		else if (operationName.equals(ComponentType.Operation.KILL_REQUEST)) {
+//			String requestID = (String) valueMap
+//					.get(ConnectionConstants.ComponentType.Operation.Value.REQUEST_ID);
+//			cancelRequest(requestID);
+//		} else if (operationName.equals(ComponentType.Operation.GET_VDBS)) {
+//			List fieldNameList = operationResult.getFieldNameList();
+//			resultObject = getVDBs(fieldNameList);
+//			operationResult.setContent((List) resultObject);
+//		} else if (operationName.equals(ComponentType.Operation.GET_PROPERTIES)) {
+//			String identifier = (String) valueMap
+//					.get(ConnectionConstants.IDENTIFIER);
+//			Properties props = getProperties(
+//					ConnectionConstants.ComponentType.Runtime.System.TYPE,
+//					identifier);
+//			resultObject = createReportResultList(props);
+//			operationResult.setContent((List) resultObject);
+//		}
+
+	}
+
+	/*
+	 * Helper methods
+	 */
+
+	protected MetaValue getRequests(List<String> fieldNameList) {
+
+		MetaValue requestsCollection = null;
+		MetaValue args = null;
+
+		requestsCollection = executeManagedOperation(mc,
+				PluginConstants.Operation.GET_REQUESTS, args);
+
+		return requestsCollection;
+
+		// if (fieldNameList != null) {
+		// Collection reportResultCollection = createReportResultList(
+		// fieldNameList, requestsCollection.iterator());
+		// return reportResultCollection;
+		// } else {
+		// return requestsCollection;
+		// }
+	}
+
+	public MetaValue getSessions(List<String> fieldNameList) {
+
+		MetaValue sessionCollection = null;
+		MetaValue args = null;
+
+		sessionCollection = executeManagedOperation(mc,
+				PluginConstants.Operation.GET_SESSIONS, args);
+		return sessionCollection;
+
+		// if (fieldNameList != null) {
+		// Collection reportResultCollection = createReportResultList(
+		// fieldNameList, requestsCollection.iterator());
+		// return reportResultCollection;
+		// } else {
+		// return requestsCollection;
+		// }
+	}
+
+	public static MetaValue executeManagedOperation(ManagedComponent mc,
+			String operation, MetaValue... args) {
+
+		try {
+			mc = ProfileServiceUtil.getDQPManagementView();
+		} catch (NamingException e) {
+			LOG.error(e);
+		} catch (Exception e1) {
+			LOG.error(e1);
+		}
+
+		for (ManagedOperation mo : mc.getOperations()) {
+			String opName = mo.getName();
+			if (opName.equals(operation)) {
+				try {
+					if (args.length == 1 && args[0] == null) {
+						return mo.invoke();
+					} else {
+						return mo.invoke(args);
+					}
+				} catch (Exception e) {
+					final String msg = "Exception getting the AdminApi in " + operation; //$NON-NLS-1$
+					LOG.error(msg, e);
+				}
+			}
+		}
+		throw new MetaMatrixRuntimeException(
+				"No operation found with given name =" + operation);
+
+	}
+
+	private Integer getQueryCount() {
+
+		Integer count = new Integer(0);
+
+		MetaValue requests = null;
+		Collection<RequestMetadata> requestsCollection = new ArrayList();
+
+		requests = getRequests(null);
+
+		getRequestCollectionValue(requests, requestsCollection);
+
+		if (requestsCollection != null && !requestsCollection.isEmpty()) {
+			count = requestsCollection.size();
+		}
+
+		return count;
+	}
+
+	private Integer getSessionCount() {
+
+		Collection<SessionMetadata> activeSessionsCollection = new ArrayList<SessionMetadata>();
+		MetaValue sessionMetaValue = getSessions(null);
+		getSessionCollectionValue(sessionMetaValue, activeSessionsCollection);
+		return activeSessionsCollection.size();
+	}
+
+	protected Collection<RequestMetadata> getLongRunningQueries(
+			int longRunningValue) {
+
+		MetaValue requestsCollection = null;
+		Collection<RequestMetadata> list = new ArrayList<RequestMetadata>();
+
+		double longRunningQueryTimeDouble = new Double(longRunningValue);
+
+		requestsCollection = getRequests(null);
+
+		getRequestCollectionValue(requestsCollection, list);
+
+		Iterator<RequestMetadata> requestsIter = list.iterator();
+		while (requestsIter.hasNext()) {
+			RequestMetadata request = requestsIter.next();
+			long startTime = request.getProcessingTime();
+			// Get msec from each, and subtract.
+			long runningTime = Calendar.getInstance().getTimeInMillis()
+					- startTime;
+
+			if (runningTime < longRunningQueryTimeDouble) {
+				requestsIter.remove();
+			}
+		}
+		 
+		return list;
+	}
+	
+	public static <T> void getRequestCollectionValue(MetaValue pValue,
+			Collection<RequestMetadata> list) {
+		MetaType metaType = pValue.getMetaType();
+		if (metaType.isCollection()) {
+			for (MetaValue value : ((CollectionValueSupport) pValue)
+					.getElements()) {
+				if (value.getMetaType().isComposite()) {
+					RequestMetadataMapper requestMapper = new RequestMetadataMapper();
+					RequestMetadata requestMetaData = requestMapper
+							.unwrapMetaValue(value);
+					list.add(requestMetaData);
+				} else {
+					throw new IllegalStateException(pValue
+							+ " is not a Composite type");
+				}
+			}
+		}
+	}
+
+	public static <T> void getSessionCollectionValue(MetaValue pValue,
+			Collection<SessionMetadata> list) {
+		MetaType metaType = pValue.getMetaType();
+		if (metaType.isCollection()) {
+			for (MetaValue value : ((CollectionValueSupport) pValue)
+					.getElements()) {
+				if (value.getMetaType().isComposite()) {
+					SessionMetadataMapper sessionMapper = new SessionMetadataMapper();
+					SessionMetadata sessionMetaData = sessionMapper
+							.unwrapMetaValue(value);
+					list.add(sessionMetaData);
+				} else {
+					throw new IllegalStateException(pValue
+							+ " is not a Composite type");
+				}
+			}
+		}
+	}
+	
+	private Collection createReportResultList(List fieldNameList, Iterator objectIter) {
+		Collection reportResultList = new ArrayList();
+		
+		while (objectIter.hasNext()) {
+			Object object = objectIter.next();
+
+			Class cls = null;
+			try {
+				cls = object.getClass();
+				Iterator methodIter = fieldNameList.iterator();
+				Map reportValueMap = new HashMap<String, String>();
+				while (methodIter.hasNext()) {						
+					String fieldName = (String) methodIter.next();
+					String methodName = fieldName;
+					Method meth = cls.getMethod(methodName, (Class[]) null);  
+					Object retObj = meth.invoke(object, (Object[]) null);
+					reportValueMap.put(fieldName, retObj);
+				}
+				reportResultList.add(reportValueMap);
+			} catch (Throwable e) {
+				System.err.println(e);
+			}
+		}
+		return reportResultList;
+	}
+
+}

Deleted: trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java	2010-02-19 16:26:46 UTC (rev 1845)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java	2010-02-19 16:27:35 UTC (rev 1846)
@@ -1,145 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.rhq.admin.utils;
-
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
-import org.teiid.rhq.admin.ConnectionMgr;
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
-
-
-public class SingletonConnectionManager {
-
-	private static final Log log = LogFactory.getLog(SingletonConnectionManager.class);
-    
-    private static final String ENTERPRISE_CONNECTION_MGR="org.teiid.rhq.enterprise.EnterpriseConnectionMgr"; //$NON-NLS-1$
-    private static final String EMBEDDED_CONNECTION_MGR="org.teiid.rhq.embedded.EmbeddedConnectionMgr"; //$NON-NLS-1$
-
-	private static SingletonConnectionManager instance = null;
-	private ConnectionMgr connmgr;
-	private ClassLoader loader;
-	private boolean initialized = false;
-
-
-    private SingletonConnectionManager() {	
-         
-         
-	}
-
-	public synchronized static SingletonConnectionManager getInstance() {
-
-    		if (instance == null) {
-                   instance = new SingletonConnectionManager();
-                   instance.setupConnectionMgr();
-    		}
-            
-		return instance;
-	}	
-    
-	public Set getInstallationSystemKeys() {
-		return connmgr.getInstallationSystemKeys();
-	}
-
-	public Connection getConnection(String key) throws ConnectionException {
-    	return  connmgr.getConnection(key);
-    }
-	
-
-	public void initialize(Properties props) {
-		if (connmgr != null && initialized) {
-			// re-establish the connectionfactory and pool
-			shutdown();
-			setupConnectionMgr();
-		}
-		initializeConnectionMgr(props);
-		
-	}
-
-	public Map getServerInstallations() {
-		return connmgr.getServerInstallations();
-	}
-
-	public boolean hasServersDefined() {
-		return connmgr.hasServersDefined();
-	}
-
-	public void shutdown() {
-		connmgr.shutdown();
-		connmgr = null;
-	}
-
-	
-	
-	private void setupConnectionMgr() {
-		this.loader = this.getClass().getClassLoader();
-    	ConnectionMgr mgr = null;
-    	Class clzz = null;
-    	// first try enterprise version
-    	try { 
-    		clzz = Class.forName(ENTERPRISE_CONNECTION_MGR, true, this.loader); 
-    	} catch (ClassNotFoundException noent) {
-    		
-    		// no try the embedded connection pool version
-        	try { 
-        		clzz = Class.forName(EMBEDDED_CONNECTION_MGR, true, this.loader); 
-        	} catch (ClassNotFoundException noemb) {
-        		
-        	}
-    	}
-    	
-    	if (clzz == null) {
-    		throw new InvalidPluginConfigurationException("System Error: cannot load either enterprise or embedded connection mgr");
-    	}
-    	
-        try {
-			mgr = (ConnectionMgr) clzz.newInstance();
-		} catch (Exception e) {
-			throw new InvalidPluginConfigurationException(e);
-		}              
-
-    	this.connmgr = mgr;
-    	
-    }
-	
-	private void initializeConnectionMgr(Properties props) {
-            
-		connmgr.initialize(props, this.loader);
-		this.initialized = true;
-    	
-    }
-	
-	public boolean isEmbedded() {
-    	try { 
-    		Class.forName(EMBEDDED_CONNECTION_MGR);
-    		return true;
-    	} catch (ClassNotFoundException noent) {
-    		return false;    		
-    	}    	
-    }
-
-}



More information about the teiid-commits mailing list