Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 94541 invoked from network); 17 Jul 2008 08:42:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Jul 2008 08:42:40 -0000 Received: (qmail 95774 invoked by uid 500); 17 Jul 2008 08:42:40 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 95731 invoked by uid 500); 17 Jul 2008 08:42:40 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 95722 invoked by uid 99); 17 Jul 2008 08:42:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Jul 2008 01:42:40 -0700 X-ASF-Spam-Status: No, hits=-1999.3 required=10.0 tests=ALL_TRUSTED,FRT_LEVITRA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Jul 2008 08:41:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3644A23889F7; Thu, 17 Jul 2008 01:42:19 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r677535 - /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java Date: Thu, 17 Jul 2008 08:42:18 -0000 To: scm@geronimo.apache.org From: shivahr@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080717084219.3644A23889F7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: shivahr Date: Thu Jul 17 01:42:18 2008 New Revision: 677535 URL: http://svn.apache.org/viewvc?rev=677535&view=rev Log: GERONIMODEVTOOLS-434 Query Dynamic Information from Server using JMX. Thanks to Sainath for the patch. Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java (with props) Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java?rev=677535&view=auto ============================================================================== --- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java (added) +++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java Thu Jul 17 01:42:18 2008 @@ -0,0 +1,361 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.st.v21.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.management.MBeanServerConnection; + +import org.apache.geronimo.gbean.AbstractName; +import org.apache.geronimo.gbean.AbstractNameQuery; +import org.apache.geronimo.gbean.GAttributeInfo; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.jee.deployment.Dependency; +import org.apache.geronimo.jee.naming.Pattern; +import org.apache.geronimo.kernel.GBeanNotFoundException; +import org.apache.geronimo.kernel.InternalKernelException; +import org.apache.geronimo.kernel.Kernel; +import org.apache.geronimo.kernel.NoSuchAttributeException; +import org.apache.geronimo.kernel.NoSuchOperationException; +import org.apache.geronimo.kernel.repository.Artifact; +import org.apache.geronimo.st.core.GeronimoServerBehaviourDelegate; +import org.apache.geronimo.st.v21.core.internal.Trace; +import org.apache.geronimo.system.jmx.KernelDelegate; +import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.ServerCore; + +/** + * @version $Rev$ $Date$ + */ +public class GeronimoServerInfo { + static final long serialVersionUID = 1L; + + private ArrayList kernels; + + // singleton class + private GeronimoServerInfo() { + } + + private static GeronimoServerInfo instance = new GeronimoServerInfo(); + + public static GeronimoServerInfo getInstance() { + return instance; + } + + public List getDeployedEJBs() { + ArrayList statelessSessionBeans = getByType("StatelessSessionBean"); + ArrayList statefulSessionBeans = getByType("StatefulSessionBean"); + ArrayList messageDrivenBeans = getByType("MessageDrivenBean"); + ArrayList entityBeans = getByType("EntityBean"); + ArrayList deployedEJBs = new ArrayList(); + deployedEJBs.addAll(statelessSessionBeans); + deployedEJBs.addAll(statefulSessionBeans); + deployedEJBs.addAll(messageDrivenBeans); + deployedEJBs.addAll(entityBeans); + return deployedEJBs; + } + + public List getSecurityRealms() { + ArrayList securityRealms = new ArrayList(); + Map m = null; + m = Collections.singletonMap("j2eeType", "SecurityRealm"); + AbstractNameQuery query = new AbstractNameQuery(null, m, Collections.EMPTY_SET); + updateKernels(); + for (int i = 0; i < kernels.size(); i++) { + Set beans = kernels.get(i).listGBeans(query); + for (Iterator it = beans.iterator(); it.hasNext();) { + AbstractName abstractName = (AbstractName) it.next(); + String name = (String) abstractName.getName().get("name"); + if (!securityRealms.contains(name)) { + securityRealms.add(name); + } + } + } + return securityRealms; + } + + public List getJMSConnectionFactories() { + String[] requiredInterfaces = new String[] { "javax.jms.ConnectionFactory", + "javax.jms.QueueConnectionFactory", "javax.jms.TopicConnectionFactory", }; + String attribute = "implementedInterfaces"; + ArrayList jmsConnectionFactories = getByTypeAttributeValues( + "JCAManagedConnectionFactory", attribute, requiredInterfaces); + return jmsConnectionFactories; + } + + public List getJMSDestinations() { + String[] requiredInterfaces = new String[] { "javax.jms.Queue", "javax.jms.Topic" }; + String attribute = "adminObjectInterface"; + ArrayList jmsDestinations = getByTypeAttributeValues("JCAAdminObject", attribute, + requiredInterfaces); + return jmsDestinations; + } + + public List getJDBCConnectionPools() { + String[] acceptedValues = new String[] { "javax.sql.DataSource" }; + String attribute = "connectionFactoryInterface"; + ArrayList jdbcConnectionPools = getByTypeAttributeValues( + "JCAManagedConnectionFactory", attribute, acceptedValues); + return jdbcConnectionPools; + + } + + public List getJavaMailSessions() { + ArrayList javaMailResources = getByType("JavaMailResource"); + return javaMailResources; + } + + public List getDeployedCredentialStores() { + ArrayList credentialStores = new ArrayList(); + Map map = Collections.singletonMap("j2eeType", "GBean"); + AbstractNameQuery query = new AbstractNameQuery(null, map, Collections.EMPTY_SET); + updateKernels(); + for (int i = 0; i < kernels.size(); i++) { + Set beans = kernels.get(i).listGBeans(query); + for (Iterator it = beans.iterator(); it.hasNext();) { + AbstractName abstractName = (AbstractName) it.next(); + try { + GBeanInfo info = kernels.get(i).getGBeanInfo(abstractName); + GAttributeInfo attribInfo = info.getAttribute("credentialStore"); + if (attribInfo != null) { + Artifact artifact = abstractName.getArtifact(); + Object name = abstractName.getName().get("name"); + org.apache.geronimo.jee.deployment.Pattern pattern = new org.apache.geronimo.jee.deployment.Pattern(); + pattern.setArtifactId(artifact.getArtifactId()); + pattern.setGroupId(artifact.getGroupId()); + pattern.setType(artifact.getType()); + pattern.setVersion(artifact.getVersion().toString()); + pattern.setCustomFoo((String) name); + if (!credentialStores.contains(pattern)) { + credentialStores.add(pattern); + } + } + } catch (GBeanNotFoundException e) { + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return credentialStores; + } + + public List getCommonLibs() { + List artifacts = null; + ArrayList dependencies = new ArrayList(); + Map map = Collections.singletonMap("j2eeType", "Repository"); + AbstractNameQuery query = new AbstractNameQuery(null, map, Collections.EMPTY_SET); + updateKernels(); + for (int i = 0; i < kernels.size(); i++) { + Set beans = kernels.get(i).listGBeans(query); + for (Iterator it = beans.iterator(); it.hasNext();) { + AbstractName abstractName = (AbstractName) it.next(); + try { + GBeanInfo info = kernels.get(i).getGBeanInfo(abstractName); + Object value = kernels.get(i).invoke(abstractName, "list"); + if (value instanceof TreeSet) { + artifacts = Arrays.asList(((TreeSet) value).toArray()); + } + } catch (GBeanNotFoundException e) { + Trace.trace(Trace.WARNING, "GBean Not Found. " + e.getMessage()); + } catch (NoSuchOperationException e) { + Trace.trace(Trace.WARNING, "The operation cant invoked. " + e.getMessage()); + } catch (InternalKernelException e) { + throw e; + } catch (Exception e) { + Trace.trace(Trace.WARNING, "Kernel connection failed. " + e.getMessage()); + } + + } + } + if (artifacts != null) { + for (int i = 0; i < artifacts.size(); i++) { + Dependency dependency = new Dependency(); + dependency.setArtifactId(((Artifact) artifacts.get(i)).getArtifactId()); + dependency.setGroupId(((Artifact) artifacts.get(i)).getGroupId()); + dependency.setVersion(((Artifact) artifacts.get(i)).getVersion().toString()); + dependency.setType(((Artifact) artifacts.get(i)).getType()); + if (!dependencies.contains(dependency)) { + dependencies.add(dependency); + } + } + } + return dependencies; + } + + protected ArrayList getByTypeAttributeValues(String type, String attribute, + String[] acceptedValues) { + ArrayList result = new ArrayList(); + Map map = Collections.singletonMap("j2eeType", type); + AbstractNameQuery query = new AbstractNameQuery(null, map, Collections.EMPTY_SET); + updateKernels(); + for (int i = 0; i < kernels.size(); i++) { + Set beans = kernels.get(i).listGBeans(query); + for (Iterator it = beans.iterator(); it.hasNext();) { + AbstractName abstractName = (AbstractName) it.next(); + try { + Object value = kernels.get(i).getAttribute(abstractName, attribute); + if (value != null) { + if (value instanceof String[]) { + List interfaces = Arrays.asList((String[]) value); + for (int j = 0; j < acceptedValues.length; j++) { + if (interfaces.contains(acceptedValues[j])) { + Pattern pattern = new Pattern(); + Artifact artifact = abstractName.getArtifact(); + pattern.setArtifactId(artifact.getArtifactId()); + pattern.setGroupId(artifact.getGroupId()); + pattern.setVersion(artifact.getVersion().toString()); + pattern.setName((String) abstractName.getName().get("name")); + if (!result.contains(pattern)) { + result.add(pattern); + } + break; + } + } + } + if (value instanceof String) { + String interfaces = (String) value; + for (int j = 0; j < acceptedValues.length; j++) { + if (interfaces.contains(acceptedValues[j])) { + Pattern pattern = new Pattern(); + Artifact artifact = abstractName.getArtifact(); + pattern.setArtifactId(artifact.getArtifactId()); + pattern.setGroupId(artifact.getGroupId()); + pattern.setVersion(artifact.getVersion().toString()); + pattern.setName((String) abstractName.getName().get("name")); + if (!result.contains(pattern)) { + result.add(pattern); + } + break; + } + } + } + } + } catch (GBeanNotFoundException e) { + } catch (NoSuchAttributeException e) { + } catch (Exception e) { + Trace.trace(Trace.WARNING, "Kernel connection failed. " + e.getMessage()); + } + } + } + return result; + } + + protected ArrayList getByType(String type) { + ArrayList result = new ArrayList(); + Map map = Collections.singletonMap("j2eeType", type); + AbstractNameQuery query = new AbstractNameQuery(null, map, Collections.EMPTY_SET); + updateKernels(); + for (int i = 0; i < kernels.size(); i++) { + Set beans = kernels.get(i).listGBeans(query); + for (Iterator it = beans.iterator(); it.hasNext();) { + AbstractName abstractName = (AbstractName) it.next(); + Pattern pattern = new Pattern(); + Artifact artifact = abstractName.getArtifact(); + pattern.setArtifactId(artifact.getArtifactId()); + pattern.setGroupId(artifact.getGroupId()); + pattern.setVersion(artifact.getVersion().toString()); + pattern.setName((String) abstractName.getName().get("name")); + if (!result.contains(pattern)) { + result.add(pattern); + } + } + } + return result; + } + + protected void updateKernels() { + kernels = new ArrayList(); + IServer[] runningServers = ServerCore.getServers(); + for (int i = 0; i < runningServers.length; i++) { + try { + GeronimoServerBehaviourDelegate delegate = (GeronimoServerBehaviourDelegate) runningServers[i] + .getAdapter(GeronimoServerBehaviourDelegate.class); + if (delegate != null) { + MBeanServerConnection connection = delegate.getServerConnection(); + if (connection != null) { + kernels.add(new KernelDelegate(connection)); + } + } + } catch (SecurityException e) { + } catch (Exception e) { + Trace.trace(Trace.WARNING, "Kernel connection failed. " + e.getMessage()); + } + } + } + + protected void printNamingPatternList(List patternList) { + for (int i = 0; i < patternList.size(); i++) { + Pattern pattern = patternList.get(i); + System.out.println("ArtifactID:" + pattern.getArtifactId() + " GroupID:" + + pattern.getGroupId() + " Module:" + pattern.getModule() + " Version:" + + pattern.getVersion() + " Name:" + pattern.getName()); + } + } + + protected void printDeploymentPatternList(List patternList) { + for (int i = 0; i < patternList.size(); i++) { + org.apache.geronimo.jee.deployment.Pattern pattern = patternList.get(i); + System.out.println("ArtifactID:" + pattern.getArtifactId() + " GroupID:" + + pattern.getGroupId() + " Module:" + pattern.getVersion() + " Version:" + + pattern.getType() + " Name:" + pattern.getCustomFoo()); + } + } + + protected void printDependencies(List dependencyList) { + for (int i = 0; i < dependencyList.size(); i++) { + Dependency dependency = dependencyList.get(i); + System.out.println("ArtifactID:" + dependency.getArtifactId() + " GroupID:" + + dependency.getGroupId() + " Type:" + dependency.getType() + " Version:" + + dependency.getVersion()); + } + } + + public void testGeronimoServerInfo() { + System.out.println("EJB Modules: \n"); + List ejbModules = getDeployedEJBs(); + printNamingPatternList(ejbModules); + System.out.println("\n\nSecurity Realms: \n"); + List securityRealms = getSecurityRealms(); + System.out.println(securityRealms.toString()); + System.out.println("\n\nJMS Connection Factories: \n"); + List jmsConnectionFactories = getJMSConnectionFactories(); + printNamingPatternList(jmsConnectionFactories); + System.out.println("\n\nJMS Destinations: \n"); + List jmsDestinations = getJMSDestinations(); + printNamingPatternList(jmsDestinations); + System.out.println("\n\nJDBC Connection Pools: \n"); + List jdbcConnectionPools = getJDBCConnectionPools(); + printNamingPatternList(jdbcConnectionPools); + System.out.println("\n\nJava Mail Resources: \n"); + List javaMailResources = getJavaMailSessions(); + printNamingPatternList(javaMailResources); + System.out.println("\n\nCredential Stores: \n"); + List credentialStores = getDeployedCredentialStores(); + printDeploymentPatternList(credentialStores); + System.out.println("\n\nCommon Libs: \n"); + List dependencies = getCommonLibs(); + printDependencies(dependencies); + } + +} Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/GeronimoServerInfo.java ------------------------------------------------------------------------------ svn:mime-type = text/plain