[teiid-commits] teiid SVN: r1850 - trunk/console/src/main/java/org/teiid/rhq/plugin.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Feb 19 11:48:56 EST 2010


Author: tejones
Date: 2010-02-19 11:48:56 -0500 (Fri, 19 Feb 2010)
New Revision: 1850

Removed:
   trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java
Modified:
   trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
   trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
Log:
TEIID-807: Cleaned up legacy code and added VDB deployment/un-deployment. Also added operation execution framework.

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -21,21 +21,13 @@
  */
 package org.teiid.rhq.plugin;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.deployers.spi.management.deploy.DeploymentManager;
@@ -45,8 +37,6 @@
 import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
 import org.rhq.core.domain.content.PackageDetailsKey;
 import org.rhq.core.domain.content.PackageType;
-import org.rhq.core.domain.content.transfer.ContentResponseResult;
-import org.rhq.core.domain.content.transfer.DeployIndividualPackageResponse;
 import org.rhq.core.domain.content.transfer.DeployPackageStep;
 import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
 import org.rhq.core.domain.content.transfer.RemovePackagesResponse;
@@ -55,12 +45,10 @@
 import org.rhq.core.domain.measurement.MeasurementReport;
 import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
 import org.rhq.core.domain.resource.CreateResourceStatus;
-import org.rhq.core.domain.resource.ResourceType;
 import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
 import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
 import org.rhq.core.pluginapi.content.ContentFacet;
 import org.rhq.core.pluginapi.content.ContentServices;
-import org.rhq.core.pluginapi.content.version.PackageVersions;
 import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
 import org.rhq.core.pluginapi.inventory.CreateResourceReport;
 import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
@@ -70,11 +58,7 @@
 import org.rhq.core.pluginapi.measurement.MeasurementFacet;
 import org.rhq.core.pluginapi.operation.OperationFacet;
 import org.rhq.core.pluginapi.operation.OperationResult;
-import org.rhq.core.util.ZipUtil;
-import org.rhq.core.util.exception.ThrowableUtil;
-import org.teiid.rhq.admin.utils.SingletonConnectionManager;
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.admin.DQPManagementView;
 import org.teiid.rhq.comm.ExecutedResult;
 import org.teiid.rhq.plugin.objects.ExecutedOperationResultImpl;
 import org.teiid.rhq.plugin.util.DeploymentUtils;
@@ -88,9 +72,6 @@
 		OperationFacet, ConfigurationFacet, ContentFacet, DeleteResourceFacet,
 		CreateChildResourceFacet {
 
-	protected static SingletonConnectionManager connMgr = SingletonConnectionManager
-			.getInstance();
-
 	protected final Log LOG = LogFactory.getLog(Facet.class);
 
 	/**
@@ -111,45 +92,21 @@
 
 	private String identifier;
 
+	protected String componentType;
+	
 	// may be null when the component is not a host or vm
 	private String port = null;
 
 	protected boolean isAvailable = false;
 
-	/**
-	 * Name of the backing package type that will be used when discovering
-	 * packages. This corresponds to the name of the package type defined in the
-	 * plugin descriptor.
-	 */
-	private static final String PKG_TYPE_FILE = "vdb";
-
-	/**
-	 * Architecture string used in describing discovered packages.
-	 */
-	private static final String ARCHITECTURE = "noarch";
-
-	private static final String BACKUP_FILE_EXTENSION = ".rej";
-
 	private final Log log = LogFactory.getLog(this.getClass());
 
-	private PackageVersions versions;
-
 	/**
 	 * The name of the ManagedDeployment (e.g.:
-	 * vfszip:/C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.vdb).
+	 * C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.vdb).
 	 */
 	protected String deploymentName;
 
-	/**
-	 * The type of the ManagedDeployment.
-	 */
-	// protected KnownDeploymentTypes deploymentType;
-	/**
-	 * The absolute path of the deployment file (e.g.:
-	 * C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.vdb).
-	 */
-	protected File deploymentFile;
-
 	abstract String getComponentType();
 
 	/**
@@ -161,6 +118,7 @@
 	 */
 	public void start(ResourceContext context) {
 		resourceContext = context;
+		deploymentName=context.getResourceKey();
 	}
 
 	/**
@@ -214,7 +172,7 @@
 	}
 
 	protected void setOperationArguments(String name,
-			Configuration configuration, Map argumentMap) {
+			Configuration configuration, Map<String, Object> argumentMap) {
 		// moved this logic up to the associated implemented class
 		throw new InvalidPluginConfigurationException(
 				"Not implemented on component type " + this.getComponentType()
@@ -223,44 +181,12 @@
 	}
 
 	protected void execute(final ExecutedResult result, final Map valueMap) {
-		Connection conn = null;
-		try {
-			conn = getConnection();
-
-			if (!conn.isValid()) {
-				return;
-			}
-			conn.executeOperation(result, valueMap);
-
-		} catch (Exception e) {
-			final String msg = "Error invoking operation [" + name + "]. Cause: " + e; //$NON-NLS-1$ //$NON-NLS-2$
-			LOG.error(msg);
-			throw new RuntimeException(msg);
-		} finally {
-			conn.close();
-		}
+		DQPManagementView dqp = new DQPManagementView();
+			
+		dqp.executeOperation(result, valueMap);
+		
 	}
-
-	/**
-	 * The connection will be returned when it is available. If it is not, then
-	 * null will be returned. Resource methods will not throw exceptions as a
-	 * MetaMatrix System goes up and down. That state will be indicated by it's
-	 * availability state.
-	 * 
-	 * @return
-	 */
-
-	public Connection getConnection() throws ConnectionException {
-		Connection conn = connMgr.getConnection(getSystemKey());
-		if (conn.isValid()) {
-			this.isAvailable = true;
-		} else {
-			this.isAvailable = false;
-		}
-
-		return conn;
-	}
-
+	
 	/*
 	 * (non-Javadoc) This method is called by JON to check the availability of
 	 * the inventoried component on a time scheduled basis
@@ -281,7 +207,7 @@
 	 * @return true if the resource is available
 	 */
 	protected boolean isAvailable() {
-		return this.isAvailable;
+		return true;
 	}
 
 	/**
@@ -306,8 +232,7 @@
 	public OperationResult invokeOperation(String name,
 			Configuration configuration) {
 		Map valueMap = new HashMap();
-		Connection conn = null;
-
+	
 		Set operationDefinitionSet = this.resourceContext.getResourceType()
 				.getOperationDefinitions();
 
@@ -366,7 +291,25 @@
 
 	@Override
 	public void deleteResource() throws Exception {
-		// TODO Auto-generated method stub
+		
+		DeploymentManager deploymentManager = ProfileServiceUtil.getDeploymentManager();
+		
+        log.debug("Stopping deployment [" + this.deploymentName + "]...");
+        DeploymentProgress progress = deploymentManager.stop(this.deploymentName);
+        DeploymentStatus stopStatus = DeploymentUtils.run(progress);
+        if (stopStatus.isFailed()) {
+            log.error("Failed to stop deployment '" + this.deploymentName + "'.", stopStatus.getFailure());
+            throw new Exception("Failed to stop deployment '" + this.deploymentName + "' - cause: "
+                    + stopStatus.getFailure());
+        }
+        log.debug("Removing deployment [" + this.deploymentName + "]...");
+        progress = deploymentManager.remove(this.deploymentName);
+        DeploymentStatus removeStatus = DeploymentUtils.run(progress);
+        if (removeStatus.isFailed()) {
+            log.error("Failed to remove deployment '" + this.deploymentName + "'.", removeStatus.getFailure());
+            throw new Exception("Failed to remove deployment '" + this.deploymentName + "' - cause: "
+                    + removeStatus.getFailure());
+        }
 
 	}
 
@@ -374,187 +317,12 @@
 	public DeployPackagesResponse deployPackages(
 			Set<ResourcePackageDetails> packages,
 			ContentServices contentServices) {
-		String resourceTypeName = this.resourceContext.getResourceType()
-				.getName();
-
-		// You can only update the one application file referenced by this
-		// resource, so punch out if multiple are
-		// specified.
-		if (packages.size() != 1) {
-			log.warn("Request to update " + resourceTypeName
-					+ " file contained multiple packages: " + packages);
-			DeployPackagesResponse response = new DeployPackagesResponse(
-					ContentResponseResult.FAILURE);
-			response.setOverallRequestErrorMessage("Only one "
-					+ resourceTypeName + " can be updated at a time.");
-			return response;
-		}
-
-		ResourcePackageDetails packageDetails = packages.iterator().next();
-
-		log.debug("Updating VDB file '" + this.deploymentFile + "' using ["
-				+ packageDetails + "]...");
-		// Find location of existing application.
-		if (!this.deploymentFile.exists()) {
-			return failApplicationDeployment(
-					"Could not find application to update at location: "
-							+ this.deploymentFile, packageDetails);
-		}
-
-		log.debug("Writing new EAR/WAR bits to temporary file...");
-		File tempFile;
-		try {
-			tempFile = writeNewAppBitsToTempFile(contentServices,
-					packageDetails);
-		} catch (Exception e) {
-			return failApplicationDeployment(
-					"Error writing new application bits to temporary file - cause: "
-							+ e, packageDetails);
-		}
-		log.debug("Wrote new EAR/WAR bits to temporary file '" + tempFile
-				+ "'.");
-
-		boolean deployExploded = this.deploymentFile.isDirectory();
-
-		// Backup the original app file/dir.
-		File tempDir = resourceContext.getTemporaryDirectory();
-		File backupDir = new File(tempDir, "deployBackup");
-		File backupOfOriginalFile = new File(backupDir, this.deploymentFile
-				.getName());
-		log.debug("Backing up existing EAR/WAR '" + this.deploymentFile
-				+ "' to '" + backupOfOriginalFile + "'...");
-		try {
-			if (backupOfOriginalFile.exists()) {
-				FileUtils.forceDelete(backupOfOriginalFile);
-			}
-			if (this.deploymentFile.isDirectory()) {
-				FileUtils.copyDirectory(this.deploymentFile,
-						backupOfOriginalFile, true);
-			} else {
-				FileUtils.copyFile(this.deploymentFile, backupOfOriginalFile,
-						true);
-			}
-		} catch (Exception e) {
-			throw new RuntimeException("Failed to backup existing "
-					+ resourceTypeName + "'" + this.deploymentFile + "' to '"
-					+ backupOfOriginalFile + "'.");
-		}
-
-		// Now stop the original app.
-		try {
-			DeploymentManager deploymentManager = ProfileServiceUtil
-					.getDeploymentManager();
-			DeploymentProgress progress = deploymentManager
-					.stop(this.deploymentName);
-			DeploymentUtils.run(progress);
-		} catch (Exception e) {
-			throw new RuntimeException("Failed to stop deployment ["
-					+ this.deploymentName + "].", e);
-		}
-
-		// And then remove it (this will delete the physical file/dir from the
-		// deploy dir).
-		try {
-			DeploymentManager deploymentManager = ProfileServiceUtil
-					.getDeploymentManager();
-			DeploymentProgress progress = deploymentManager
-					.remove(this.deploymentName);
-			DeploymentUtils.run(progress);
-		} catch (Exception e) {
-			throw new RuntimeException("Failed to remove deployment ["
-					+ this.deploymentName + "].", e);
-		}
-
-		// Deploy away!
-		log.debug("Deploying '" + tempFile + "'...");
-		DeploymentManager deploymentManager = null;
-		try {
-			deploymentManager = ProfileServiceUtil.getDeploymentManager();
-			DeploymentUtils.deployArchive(deploymentManager, tempFile,
-					deployExploded);
-		} catch (Exception e) {
-			// Deploy failed - rollback to the original app file...
-			log.debug("Redeploy failed - rolling back to original archive...",
-					e);
-			String errorMessage = ThrowableUtil.getAllMessages(e);
-			try {
-				// Try to delete the new app file, which failed to deploy, if it
-				// still exists.
-				if (this.deploymentFile.exists()) {
-					try {
-						FileUtils.forceDelete(this.deploymentFile);
-					} catch (IOException e1) {
-						log.debug("Failed to delete application file '"
-								+ this.deploymentFile
-								+ "' that failed to deploy.", e1);
-					}
-				}
-				// Now redeploy the original file - this generally should
-				// succeed.
-				DeploymentUtils.deployArchive(deploymentManager,
-						backupOfOriginalFile, deployExploded);
-				errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****";
-			} catch (Exception e1) {
-				log.debug("Rollback failed!", e1);
-				errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: "
-						+ ThrowableUtil.getAllMessages(e1);
-			}
-			log
-					.info("Failed to update " + resourceTypeName + " file '"
-							+ this.deploymentFile + "' using ["
-							+ packageDetails + "].");
-			return failApplicationDeployment(errorMessage, packageDetails);
-		}
-
-		// Deploy was successful!
-		deleteBackupOfOriginalFile(backupOfOriginalFile);
-		persistApplicationVersion(packageDetails, this.deploymentFile);
-
-		DeployPackagesResponse response = new DeployPackagesResponse(
-				ContentResponseResult.SUCCESS);
-		DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(
-				packageDetails.getKey(), ContentResponseResult.SUCCESS);
-		response.addPackageResponse(packageResponse);
-
-		log.debug("Updated " + resourceTypeName + " file '"
-				+ this.deploymentFile + "' successfully - returning response ["
-				+ response + "]...");
-
-		return response;
+		return null;
 	}
 
 	@Override
 	public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType arg0) {
-		if (!this.deploymentFile.exists())
-			throw new IllegalStateException("Deployment file '"
-					+ this.deploymentFile + "' for " + "VDB Archive"
-					+ " does not exist.");
-
-		String fileName = this.deploymentFile.getName();
-		PackageVersions packageVersions = loadPackageVersions();
-		String version = packageVersions.getVersion(fileName);
-		if (version == null) {
-			// This is either the first time we've discovered this VDB, or
-			// someone purged the PC's data dir.
-			version = "1.0";
-			packageVersions.putVersion(fileName, version);
-			packageVersions.saveToDisk();
-		}
-
-		// Package name is the deployment's file name (e.g. foo.ear).
-		PackageDetailsKey key = new PackageDetailsKey(fileName, version,
-				PKG_TYPE_FILE, ARCHITECTURE);
-		ResourcePackageDetails packageDetails = new ResourcePackageDetails(key);
-		packageDetails.setFileName(fileName);
-		packageDetails.setLocation(this.deploymentFile.getPath());
-		if (!this.deploymentFile.isDirectory())
-			packageDetails.setFileSize(this.deploymentFile.length());
-		packageDetails.setFileCreatedDate(null); // TODO: get created date via
-		// SIGAR
-		Set<ResourcePackageDetails> packages = new HashSet<ResourcePackageDetails>();
-		packages.add(packageDetails);
-
-		return packages;
+		return null;
 	}
 
 	@Override
@@ -563,159 +331,17 @@
 		return null;
 	}
 
+	@Override
 	public RemovePackagesResponse removePackages(
-			Set<ResourcePackageDetails> packages) {
-		throw new UnsupportedOperationException(
-				"Cannot remove the package backing an VDB resource.");
+			Set<ResourcePackageDetails> arg0) {
+		return null;
 	}
 
 	@Override
 	public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
-		File packageFile = new File(packageDetails.getName());
-		File fileToSend;
-		try {
-			if (packageFile.isDirectory()) {
-				fileToSend = File.createTempFile("rhq", ".zip");
-				ZipUtil.zipFileOrDirectory(packageFile, fileToSend);
-			} else
-				fileToSend = packageFile;
-			return new BufferedInputStream(new FileInputStream(fileToSend));
-		} catch (IOException e) {
-			throw new RuntimeException("Failed to retrieve package bits for "
-					+ packageDetails, e);
-		}
+		return null;
 	}
 
-	/**
-	 * Returns an instantiated and loaded versions store access point.
-	 * 
-	 * @return will not be <code>null</code>
-	 */
-	private PackageVersions loadPackageVersions() {
-		if (this.versions == null) {
-			ResourceType resourceType = this.resourceContext.getResourceType();
-			String pluginName = resourceType.getPlugin();
-			File dataDirectoryFile = this.resourceContext.getDataDirectory();
-			dataDirectoryFile.mkdirs();
-			String dataDirectory = dataDirectoryFile.getAbsolutePath();
-			log.trace("Creating application versions store with plugin name ["
-					+ pluginName + "] and data directory [" + dataDirectory
-					+ "]");
-			this.versions = new PackageVersions(pluginName, dataDirectory);
-			this.versions.loadFromDisk();
-		}
-
-		return this.versions;
-	}
-
-	/**
-	 * Creates the necessary transfer objects to report a failed application
-	 * deployment (update).
-	 * 
-	 * @param errorMessage
-	 *            reason the deploy failed
-	 * @param packageDetails
-	 *            describes the update being made
-	 * 
-	 * @return response populated to reflect a failure
-	 */
-	private DeployPackagesResponse failApplicationDeployment(
-			String errorMessage, ResourcePackageDetails packageDetails) {
-		DeployPackagesResponse response = new DeployPackagesResponse(
-				ContentResponseResult.FAILURE);
-
-		DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(
-				packageDetails.getKey(), ContentResponseResult.FAILURE);
-		packageResponse.setErrorMessage(errorMessage);
-
-		response.addPackageResponse(packageResponse);
-
-		return response;
-	}
-
-	private File writeNewAppBitsToTempFile(ContentServices contentServices,
-			ResourcePackageDetails packageDetails) throws Exception {
-		File tempDir = resourceContext.getTemporaryDirectory();
-		File tempFile = new File(tempDir, this.deploymentFile.getName());
-
-		OutputStream tempOutputStream = null;
-		try {
-			tempOutputStream = new BufferedOutputStream(new FileOutputStream(
-					tempFile));
-			long bytesWritten = contentServices.downloadPackageBits(
-					resourceContext.getContentContext(), packageDetails
-							.getKey(), tempOutputStream, true);
-			log
-					.debug("Wrote " + bytesWritten + " bytes to '" + tempFile
-							+ "'.");
-		} catch (IOException e) {
-			log.error(
-					"Error writing updated application bits to temporary location: "
-							+ tempFile, e);
-			throw e;
-		} finally {
-			if (tempOutputStream != null) {
-				try {
-					tempOutputStream.close();
-				} catch (IOException e) {
-					log.error("Error closing temporary output stream", e);
-				}
-			}
-		}
-		if (!tempFile.exists()) {
-			log.error("Temporary file for application update not written to: "
-					+ tempFile);
-			throw new Exception();
-		}
-		return tempFile;
-	}
-
-	private void persistApplicationVersion(
-			ResourcePackageDetails packageDetails, File appFile) {
-		String packageName = appFile.getName();
-		PackageVersions versions = loadApplicationVersions();
-		versions.putVersion(packageName, packageDetails.getVersion());
-	}
-
-	private void deleteBackupOfOriginalFile(File backupOfOriginalFile) {
-		try {
-			FileUtils.forceDelete(backupOfOriginalFile);
-		} catch (Exception e) {
-			// not critical.
-			log.warn("Failed to delete backup of original file: "
-					+ backupOfOriginalFile);
-		}
-	}
-
-	/**
-	 * Returns an instantiated and loaded versions store access point.
-	 * 
-	 * @return will not be <code>null</code>
-	 */
-	private PackageVersions loadApplicationVersions() {
-		if (versions == null) {
-			ResourceType resourceType = resourceContext.getResourceType();
-			String pluginName = resourceType.getPlugin();
-
-			File dataDirectoryFile = resourceContext.getDataDirectory();
-
-			if (!dataDirectoryFile.exists()) {
-				dataDirectoryFile.mkdir();
-			}
-
-			String dataDirectory = dataDirectoryFile.getAbsolutePath();
-
-			log.debug("Creating application versions store with plugin name ["
-					+ pluginName + "] and data directory [" + dataDirectory
-					+ "]");
-
-			versions = new PackageVersions(pluginName, dataDirectory);
-			versions.loadFromDisk();
-		}
-
-		return versions;
-	}
-
 	@Override
 	public CreateResourceReport createResource(CreateResourceReport createResourceReport) {
 		ResourcePackageDetails details = createResourceReport
@@ -736,15 +362,10 @@
 				return createResourceReport;
 			}
 
-			Configuration deployTimeConfig = details
-					.getDeploymentTimeConfiguration();
-			@SuppressWarnings( { "ConstantConditions" })
-		//	boolean deployExploded = deployTimeConfig.getSimple(
-		//			"deployExploded").getBooleanValue();
-
 			DeploymentManager deploymentManager = ProfileServiceUtil.getDeploymentManager();
 			DeploymentUtils.deployArchive(deploymentManager, archiveFile, false);
 
+			deploymentName = archivePath;
 			createResourceReport.setResourceName(archivePath);
 			createResourceReport.setResourceKey(archivePath);
 			createResourceReport.setStatus(CreateResourceStatus.SUCCESS);

Deleted: trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -1,122 +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.plugin;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-import org.teiid.rhq.comm.Component;
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
-
-
-/**
- * Discovery component used to discover the monitored connector bindings
- * 
- */
-public abstract class NodeChildrenDiscoveryComponent extends NodeDiscoveryComponent {
-
-
-	private final Log LOG = LogFactory.getLog(NodeChildrenDiscoveryComponent.class);
-
-	/**
-	 * @see ResourceDiscoveryComponent#discoverResources(ResourceDiscoveryContext)
-	 */
-
-	@Override
-	protected void addResources(Set<DiscoveredResourceDetails> found, ResourceType resourceType, Facet parent)
-		throws InvalidPluginConfigurationException {
-		Connection conn = null;
-		   try {
-		        conn = getConnection();
-		        if (!conn.isValid()) {
-		            return;
-		        }
-		        Collection<Component> components =  getComponents(conn, parent);
-		        
-		        if (components == null || components.size() == 0) {
-		            LOG.info("No components were found to be configured for parent "+ parent.getComponentIdentifier()); //$NON-NLS-1$
-		            return;
-		        }
-		         
-		        Iterator<Component> comIter = components.iterator();
-		        
-		        while (comIter.hasNext()) {
-		          Component comp =  comIter.next();           
-		          LOG.info("Processing component "+ comp.getName()); //$NON-NLS-1$
-		          
-		          DiscoveredResourceDetails resource = this.createResource(resourceType, comp);
-           
-		          found.add(resource);      
-		        }
-	       } catch (InvalidPluginConfigurationException ipe) {
-	            throw ipe;
-	        } catch (Throwable t) {
-	            throw new InvalidPluginConfigurationException(t);            
-	            
-	        } finally {
-	            if (conn != null) {
-	                conn.close();
-	            }
-	        } 
-
-		
-	}
-	
-	protected DiscoveredResourceDetails createResource(ResourceType resourceType, Component component)
-	throws InvalidPluginConfigurationException {
-		
-		DiscoveredResourceDetails resource = createResource(resourceType, 
-      		  systemkey + "|" + component.getIdentifier(), 
-      		component.getName(), 
-      		(component.getDescription()!=null?component.getDescription():""));
-
-  	                   
-	    Configuration configuration = resource.getPluginConfiguration();
-	    configuration.put(new PropertySimple(Component.NAME, component.getName()));
-	    configuration.put(new PropertySimple(Component.IDENTIFIER, component.getIdentifier()));
-	    configuration.put(new PropertySimple(Component.SYSTEM_KEY, systemkey));
-	    
-	    addAdditionalProperties(configuration, component);
-	    
-	    return resource;
-	
-	}
-	
-	protected void addAdditionalProperties(Configuration configuration, Component component) throws InvalidPluginConfigurationException {
-		
-	}
-	
-	abstract Collection<Component> getComponents(Connection conn, Facet parent) throws ConnectionException;
-	
-
-}
\ No newline at end of file

Deleted: trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -1,131 +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.plugin;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
-import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-import org.teiid.rhq.admin.utils.SingletonConnectionManager;
-import org.teiid.rhq.comm.Component;
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionConstants;
-
-
-/**
- * Discovery component used to discover the monitored services
- *
- */
-public class NodeDiscoveryComponent implements
-		ResourceDiscoveryComponent {
-	private static final Log LOG = LogFactory
-			.getLog(NodeDiscoveryComponent.class);
-    
-    private static SingletonConnectionManager connMgr  = SingletonConnectionManager.getInstance();
-
-    protected String systemkey = null;
-    
-
-	public Set<DiscoveredResourceDetails> discoverResources(
-			ResourceDiscoveryContext discoveryContext) throws InvalidPluginConfigurationException, Exception {
-		
-        
-        String name = discoveryContext.getResourceType().getName();
-  
-        LOG.info("Discovering " + name); //$NON-NLS-1$
-
-        // if no servers have been defined, do not discover resources
-        if (!connMgr.hasServersDefined()) {
-            LOG.info("Unable to discover " + name + ", no JBEDSP Platforms defined"); //$NON-NLS-1$
-            return Collections.EMPTY_SET;
-        }
-
-        Facet parent = (Facet) discoveryContext.getParentResourceComponent();
-         
-        String parentName = parent.getComponentName(); 
-        systemkey = parent.getSystemKey();
-        
-        LOG.info("Discovering JBEDSP " + name + " for " + (parentName!=null?parentName:"PARENTNAMENOTFOUND")); //$NON-NLS-1$ //$NON-NLS-2$
-        
-		Set<DiscoveredResourceDetails> found = new HashSet<DiscoveredResourceDetails>();           
-              
-        addResources(found, discoveryContext.getResourceType(), parent);
-        
-       return found;
-	}
-	
-	protected void addResources(Set<DiscoveredResourceDetails> found, ResourceType resourceType, Facet parent)
-		throws InvalidPluginConfigurationException {
-		 String identifier = parent.getComponentIdentifier()+ "|" + resourceType.getName();
-        DiscoveredResourceDetails resource = createResource(resourceType, identifier,  resourceType.getName(), resourceType.getDescription());
-           
-        found.add(resource);           	  
-		
-	}
-		
-	protected DiscoveredResourceDetails createResource(ResourceType resourceType, String identifier, String name, String description)
-		throws InvalidPluginConfigurationException {
-
-        DiscoveredResourceDetails resource = new DiscoveredResourceDetails(resourceType,
-      		  identifier, name,
-      		  ConnectionConstants.VERSION, 
-      		  (description!=null?description:""), 
-      		  null, 
-      		  null);
-      	                   
-        Configuration configuration = resource.getPluginConfiguration();
-        configuration.put(new PropertySimple(Component.NAME, name));
-        configuration.put(new PropertySimple(Component.IDENTIFIER, identifier));
-        configuration.put(new PropertySimple(Component.SYSTEM_KEY, systemkey));
-        
-        addAdditionalProperties(configuration);
-        
-        return resource;
-		
-	}
-	
-
-	
-	protected void addAdditionalProperties(Configuration configuration) throws InvalidPluginConfigurationException {
-		
-	}
-	
-	protected Connection getConnection() throws InvalidPluginConfigurationException{
-		try {
-			return connMgr.getConnection(this.systemkey);
-
-		} catch (Throwable t) {
-          throw new InvalidPluginConfigurationException(t);            
-          
-      } 
-	}
-	
-}
\ No newline at end of file

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -31,7 +31,6 @@
 
 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.RunState;
 import org.rhq.core.domain.configuration.Configuration;
@@ -41,70 +40,124 @@
 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.utils.SingletonConnectionManager;
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionConstants;
-//import org.teiid.rhq.comm.ConnectionConstants;
-//import org.teiid.rhq.comm.Connection;
-//import org.teiid.rhq.comm.ConnectionConstants;
-//import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.System.Metrics;
+import org.teiid.rhq.admin.DQPManagementView;
 import org.teiid.rhq.plugin.util.PluginConstants;
 import org.teiid.rhq.plugin.util.ProfileServiceUtil;
-import org.teiid.rhq.plugin.util.PluginConstants.Operation;
-import org.teiid.rhq.plugin.util.PluginConstants.ComponentType.Runtime.Metrics;
+import org.teiid.rhq.plugin.util.PluginConstants.ComponentType.Platform;
 
-
 /**
  * 
  */
-public class PlatformComponent extends Facet {
+public class PlatformComponent extends Facet implements PluginConstants {
 	private final Log LOG = LogFactory.getLog(PlatformComponent.class);
 
+	
 	/**
 	 * @see org.teiid.rhq.plugin.Facet#getComponentType()
 	 * @since 4.3
 	 */
 	@Override
 	String getComponentType() {
-		return null;
+		return PluginConstants.ComponentType.Platform.NAME;
 	}
-	
+
 	@Override
 	public AvailabilityType getAvailability() {
 		RunState runState = null;
 		ManagedComponent mc;
 		try {
-			mc = ProfileServiceUtil.getManagedComponent(
-					new ComponentType(PluginConstants.ComponentType.Runtime.TYPE,
-							PluginConstants.ComponentType.Runtime.SUBTYPE),
-					PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
+			mc =  ProfileServiceUtil.getManagedComponent(new org.jboss.managed.api.ComponentType(
+					ComponentType.Platform.TYPE,
+					ComponentType.Platform.SUBTYPE),
+					ComponentType.Platform.TEIID_RUNTIME_ENGINE);
 			runState = mc.getRunState();
 		} catch (NamingException e) {
-			LOG.error("Naming exception getting: " + PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
-	        return AvailabilityType.DOWN;
+			LOG
+					.error("Naming exception getting: "
+							+ PluginConstants.ComponentType.Platform.TEIID_RUNTIME_ENGINE);
+			return AvailabilityType.DOWN;
 		} catch (Exception e) {
-			LOG.error("Exception getting: " + PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
+			LOG
+					.error("Exception getting: "
+							+ 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;
+
 	}
 
-	
-	protected void setOperationArguments(String name, Configuration configuration,
-			Map valueMap) {
- 		
-	}	
+	@Override
+	protected void setOperationArguments(String name,
+			Configuration configuration, Map<String, Object> valueMap) {
+		// Parameter logic for System Operations
+		if (name.equals(Platform.Operations.GET_QUERIES) ||
+			name.equals(Platform.Operations.GET_LONGRUNNINGQUERIES)) {
+			Integer long_running_value = getResourceConfiguration().getSimple(Operation.Value.LONG_RUNNING_QUERY_LIMIT).getIntegerValue();
+			valueMap.put(Operation.Value.LONG_RUNNING_QUERY_LIMIT, long_running_value);				
+		} else if (name.equals(Platform.Operations.KILL_REQUEST)) {
+			String key = Operation.Value.REQUEST_ID;
+			valueMap.put(key, configuration.getSimple(key).getStringValue());
+		} 
+//		else if (name.equals(ConnectionConstants.ComponentType.Operation.GET_PROPERTIES) ) {
+//			String key = ConnectionConstants.IDENTIFIER;
+//			valueMap.put(key, getComponentIdentifier());
+//		}
 
+	}
 
 	@Override
 	public void getValues(MeasurementReport report,
 			Set<MeasurementScheduleRequest> requests) throws Exception {
+		
+		DQPManagementView view = new DQPManagementView();
+
+		Map<String, Object> valueMap = new HashMap<String, Object>();
+
+		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 {
+				if (request.getName().equals(PluginConstants.ComponentType.Platform.Metrics.QUERY_COUNT)) {
+					report.addData(new MeasurementDataNumeric(request,
+							(Double) metricReturnObject));
+				} else {
+					if (request.getName().equals(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);
+			}
+		}
+
 	}
-	
-	
-	
+
 	@Override
 	public void stop() {
 		// TODO Auto-generated method stub
@@ -113,19 +166,20 @@
 
 	@Override
 	public void updateResourceConfiguration(ConfigurationUpdateReport report) {
-		
+
 		Properties props = System.getProperties();
-		
-		Iterator<PropertySimple> pluginPropIter = report.getConfiguration().getSimpleProperties().values().iterator();
-		
-		while (pluginPropIter.hasNext()){
+
+		Iterator<PropertySimple> pluginPropIter = report.getConfiguration()
+				.getSimpleProperties().values().iterator();
+
+		while (pluginPropIter.hasNext()) {
 			PropertySimple pluginProp = pluginPropIter.next();
 			props.put(pluginProp.getName(), pluginProp.getStringValue());
 		}
-		
-		SingletonConnectionManager.getInstance().initialize(props);
+
+		//SingletonConnectionManager.getInstance().initialize(props);
 		super.updateResourceConfiguration(report);
-		
-	}	
 
+	}
+
 }
\ No newline at end of file

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -58,9 +58,9 @@
 		Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
 
 		ManagedComponent mc = ProfileServiceUtil.getManagedComponent(
-				new ComponentType(PluginConstants.ComponentType.Runtime.TYPE,
-						PluginConstants.ComponentType.Runtime.SUBTYPE),
-				PluginConstants.ComponentType.Runtime.TEIID_RUNTIME_ENGINE);
+				new ComponentType(PluginConstants.ComponentType.Platform.TYPE,
+						PluginConstants.ComponentType.Platform.SUBTYPE),
+				PluginConstants.ComponentType.Platform.TEIID_RUNTIME_ENGINE);
 
 		Configuration c = new Configuration(); 
 		String managerName = mc.getName();
@@ -74,9 +74,9 @@
 		DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
 				discoveryContext.getResourceType(), // ResourceType
 				managerName, // Resource Key
-				PluginConstants.ComponentType.Runtime.TEIID_ENGINE_RESOURCE_NAME, // Resource Name
+				PluginConstants.ComponentType.Platform.TEIID_ENGINE_RESOURCE_NAME, // Resource Name
 				null, // Version TODO can we get that from discovery ?
-				PluginConstants.ComponentType.Runtime.TEIID_ENGINE_RESOURCE_DESCRIPTION, // Description
+				PluginConstants.ComponentType.Platform.TEIID_ENGINE_RESOURCE_DESCRIPTION, // Description
 				c, // Plugin Config
 				null // Process info from a process scan
 		);

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -32,6 +32,7 @@
 import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
 import org.rhq.core.pluginapi.measurement.MeasurementFacet;
 import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.plugin.util.PluginConstants;
 
 
 /**
@@ -42,6 +43,15 @@
 	private final Log LOG = LogFactory
 			.getLog(VDBComponent.class);
 
+	
+	/* (non-Javadoc)
+	 * @see org.teiid.rhq.plugin.Facet#getComponentName()
+	 */
+	@Override
+	public String getComponentName() {
+		return PluginConstants.ComponentType.VDB.NAME;
+	}
+
 	/**
 	 * The plugin container will call this method when your resource component
 	 * has been scheduled to collect some measurements now. It is within this

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java	2010-02-19 16:29:33 UTC (rev 1849)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java	2010-02-19 16:48:56 UTC (rev 1850)
@@ -67,22 +67,9 @@
 
 		for (ManagedComponent mcVdb : vdbs) {
 
+			String vdbKey = mcVdb.getDeployment().getName();
 			String vdbName = ((SimpleValueSupport) mcVdb.getProperty("name")
 					.getValue()).getValue().toString();
-//			ManagementView managementView = ProfileServiceUtil
-//			.getManagementView(ProfileServiceUtil.getProfileService(),
-//					false);
-			//ManagedDeployment managedDeployment = managementView.getDeploymentNamesForType(arg0)(vdbName);
-			//Set deploymentNames = null;
-			
-//			try
-//	        {
-//	            deploymentNames = managementView.getDeploymentNames();
-//	        }
-//	        catch (Exception e)
-//	        {
-//	            log.error("Unable to get deployment for type " , e);
-//	        }
 			String vdbVersion = ((SimpleValueSupport) mcVdb.getProperty(
 					"version").getValue()).getValue().toString();
 			// TODO: Correct this after deploying proper VDB/Metadata
@@ -97,7 +84,7 @@
 			 */
 			DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
 					discoveryContext.getResourceType(), // ResourceType
-					vdbName, // Resource Key
+					vdbKey, // Resource Key
 					vdbName, // Resource Name
 					vdbVersion, // Version
 					PluginConstants.ComponentType.VDB.DESCRIPTION, // Description



More information about the teiid-commits mailing list