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

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Nov 30 10:24:24 EST 2009


Author: tejones
Date: 2009-11-30 10:24:24 -0500 (Mon, 30 Nov 2009)
New Revision: 1605

Modified:
   trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
Log:
TEIID-807: Added discovery of runtime engine

Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java	2009-11-29 14:39:39 UTC (rev 1604)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java	2009-11-30 15:24:24 UTC (rev 1605)
@@ -21,103 +21,156 @@
  */
 package org.teiid.rhq.plugin;
 
+import java.io.File;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import javax.naming.InitialContext;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
 import org.rhq.core.domain.configuration.Configuration;
 import org.rhq.core.domain.configuration.PropertySimple;
 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.ConnectionConstants;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
 
-
 /**
  * This is the parent node for a MetaMatrix system
  */
 public class PlatformDiscoveryComponent implements ResourceDiscoveryComponent {
-	private static SingletonConnectionManager connMgr  = SingletonConnectionManager.getInstance();
+	
 	private static final Log LOG = LogFactory
 			.getLog(PlatformDiscoveryComponent.class);
-	   
-	
-	Map environmentMap = new HashMap();
 
-    /**
+	private final Log log = LogFactory.getLog(this.getClass());
+
+	/**
 	 * Review the javadoc for both {@link ResourceDiscoveryComponent} and
 	 * {@link ResourceDiscoveryContext} to learn what you need to do in this
 	 * method.
 	 * 
 	 * @see ResourceDiscoveryComponent#discoverResources(ResourceDiscoveryContext)
 	 */
-	public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext discoveryContext) throws InvalidPluginConfigurationException,
-                                                                                                      Exception {
-        try {
-            
-            String name = discoveryContext.getResourceType().getName();
-            String desc = discoveryContext.getResourceType().getDescription();
-            String version = ConnectionConstants.VERSION;
-            
-            LOG.info("Discovering " + desc); //$NON-NLS-1$
-            
-            
-            // now perform your own discovery mechanism, if you have one. For each
-            // resource discovered, you need to
-            // create a details object that describe the resource that you
-            // discovered.
-            HashSet<DiscoveredResourceDetails> set = new HashSet<DiscoveredResourceDetails>();
+	public Set<DiscoveredResourceDetails> discoverResources(
+			ResourceDiscoveryContext discoveryContext)
+			throws InvalidPluginConfigurationException, Exception {
 
-            Set<String> systemkeys = null ;
+		Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>();
 
-            try {
-            	systemkeys = connMgr.getInstallationSystemKeys();
-            } catch (Exception e) {
-            	systemkeys = new HashSet(1);
-            	systemkeys.add("NotDefined");
+		InitialContext ic = new InitialContext();
+		ProfileService ps = (ProfileService) ic.lookup("ProfileService");
 
-            	// TODO
-                // - when the serverList cannot be obtained
-                
-                // DO NOT throw exception, still want to create the
-                // resource, but it will show not active / available
-            }
+		ManagementView vm = ps.getViewManager();
+		vm.load();
+		ComponentType type = new ComponentType("ConnectionFactory", "NoTx");
+		ManagedComponent mc = vm.getComponent("teiid-runtime-engine",
+				type);
 
+		/*
+		 * Currently this uses a hardcoded remote address for access to the
+		 * MBean server This needs to be switched to check if we e.g. run inside
+		 * a JBossAS to which we have a connection already that we can reuse.
+		 */
+		Configuration c = new Configuration(); // TODO get from
+												// defaultPluginConfig
 
+		String managerName = mc.getName();
+		c.put(new PropertySimple("objectName", managerName));
+		/**
+		 * 
+		 * A discovered resource must have a unique key, that must stay the same
+		 * when the resource is discovered the next time
+		 */
+		DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
+				discoveryContext.getResourceType(), // ResourceType
+				managerName, // Resource Key
+				"Data Service Runtime Engine", // Resource Name
+				null, // Version TODO can we get that from discovery ?
+				"The JBoss Enterprise Data Service Engine", // Description
+				c, // Plugin Config
+				null // Process info from a process scan
+		);
 
-            Iterator<String> serverIter = systemkeys.iterator();
-            int hostCount = -1;
-            while (serverIter.hasNext()) {
-                hostCount++;
-                String systemKey = serverIter.next();
-                    
-	                    DiscoveredResourceDetails resource = new DiscoveredResourceDetails(discoveryContext.getResourceType(),
-	                                                                                       systemKey, name,
-	                                                                                       version, desc, null, null);
-	
-	                    Configuration configuration = resource.getPluginConfiguration();
-	                    configuration.put(new PropertySimple(Component.NAME, name));
-	                    configuration.put(new PropertySimple(Component.IDENTIFIER, name));
-	                    configuration.put(new PropertySimple(Component.SYSTEM_KEY, systemKey));
-	                    
-	
-	                    set.add(resource); 
+		// Add to return values
+		discoveredResources.add(detail);
+		log.info("Discovered Teiid instance: " + managerName);
+		return discoveredResources;
 
-            }
-
-            return set;
-        } catch (InvalidPluginConfigurationException ipe) {
-            throw ipe;
-        } catch (Throwable t) {
-            throw new InvalidPluginConfigurationException(t);
-        }
-
-    }
+		// String name = discoveryContext.getResourceType().getName();
+		// String desc = discoveryContext.getResourceType().getDescription();
+		// String version = ConnectionConstants.VERSION;
+		//            
+		//            LOG.info("Discovering " + desc); //$NON-NLS-1$
+		//            
+		//            
+		// // now perform your own discovery mechanism, if you have one. For
+		// each
+		// // resource discovered, you need to
+		// // create a details object that describe the resource that you
+		// // discovered.
+		// HashSet<DiscoveredResourceDetails> set = new
+		// HashSet<DiscoveredResourceDetails>();
+		//
+		// Set<String> systemkeys = null ;
+		//
+		// try {
+		// systemkeys = connMgr.getInstallationSystemKeys();
+		// } catch (Exception e) {
+		// systemkeys = new HashSet(1);
+		// systemkeys.add("NotDefined");
+		//
+		// // TODO
+		// // - when the serverList cannot be obtained
+		//                
+		// // DO NOT throw exception, still want to create the
+		// // resource, but it will show not active / available
+		// }
+		//
+		//
+		//
+		// Iterator<String> serverIter = systemkeys.iterator();
+		// int hostCount = -1;
+		// while (serverIter.hasNext()) {
+		// hostCount++;
+		// String systemKey = serverIter.next();
+		//                    
+		// DiscoveredResourceDetails resource = new
+		// DiscoveredResourceDetails(discoveryContext.getResourceType(),
+		// systemKey, name,
+		// version, desc, null, null);
+		//	
+		// Configuration configuration = resource.getPluginConfiguration();
+		// configuration.put(new PropertySimple(Component.NAME, name));
+		// configuration.put(new PropertySimple(Component.IDENTIFIER, name));
+		// configuration.put(new PropertySimple(Component.SYSTEM_KEY,
+		// systemKey));
+		//	                    
+		//	
+		// set.add(resource);
+		//
+		// }
+		//
+		// return set;
+		// } catch (InvalidPluginConfigurationException ipe) {
+		// throw ipe;
+		// } catch (Throwable t) {
+		// throw new InvalidPluginConfigurationException(t);
+		// }
+		//
+	}
 }
\ No newline at end of file



More information about the teiid-commits mailing list