geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1096955 - in /geronimo/server/trunk/framework/modules/geronimo-kernel: ./ src/main/java/org/apache/geronimo/kernel/command/ src/main/java/org/apache/geronimo/kernel/config/ src/main/resources/OSGI-INF/ src/main/resources/OSGI-INF/blueprint/
Date Tue, 26 Apr 2011 23:20:08 GMT
Author: djencks
Date: Tue Apr 26 23:20:08 2011
New Revision: 1096955

URL: http://svn.apache.org/viewvc?rev=1096955&view=rev
Log:
Add a gbeans:list console command.  Don't stop gbeans that successfully started in a configuration

Added:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
  (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml?rev=1096955&r1=1096954&r2=1096955&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml Tue Apr 26 23:20:08 2011
@@ -80,6 +80,12 @@
             <groupId>org.apache.xbean</groupId>
             <artifactId>xbean-reflect</artifactId>
         </dependency>
+        <!-- commands -->
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+            <scope>provided</scope>
+        </dependency>
 
         <!--<dependency>-->
             <!--<groupId>org.apache.geronimo.specs</groupId>-->

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java?rev=1096955&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
Tue Apr 26 23:20:08 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.kernel.command;
+
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public abstract class KernelCommandSupport extends OsgiCommandSupport {
+
+    protected Object doExecute() throws Exception {
+        // Get repository admin service.
+        ServiceReference ref = getBundleContext().getServiceReference(Kernel.class.getName());
+        if (ref == null) {
+            System.out.println("FeaturesService service is unavailable.");
+            return null;
+        }
+        try {
+            Kernel admin = (Kernel) getBundleContext().getService(ref);
+            if (admin == null) {
+                System.out.println("FeaturesService service is unavailable.");
+                return null;
+            }
+
+            doExecute(admin);
+        }
+        finally {
+            getBundleContext().ungetService(ref);
+        }
+        return null;
+    }
+
+
+    protected abstract void doExecute(Kernel kernel) throws Exception;
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/KernelCommandSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java?rev=1096955&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
Tue Apr 26 23:20:08 2011
@@ -0,0 +1,116 @@
+/*
+ * 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.kernel.command;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GReferenceInfo;
+import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.management.State;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+@Command(scope = "gbeans", name = "list", description = "Lists all gbeans in the kernel.")
+public class ListGBeansCommand extends KernelCommandSupport {
+
+    @Option(name = "-q", aliases = {"--query"}, description = "Abstract name query URI",
required = false, multiValued = false)
+    String queryString = "";
+
+    @Option(name = "-v", aliases = {"--verbose"}, description = "Show the state reason for
non-running gbeans", required = false, multiValued = false)
+    boolean verbose;
+
+    @Override
+    protected void doExecute(Kernel kernel) throws Exception {
+        AbstractNameQuery query = new AbstractNameQuery(URI.create(queryString));
+        Collection<AbstractName> names = kernel.listGBeans(query);
+        if (names.isEmpty()) {
+            System.out.println("No gbeans found in kernel");
+            return;
+        }
+
+        LinkedHashMap<AbstractName, Integer> states = new LinkedHashMap<AbstractName,
Integer>();
+
+        for (AbstractName name: names) {
+            states.put(name, kernel.getGBeanState(name));
+        }
+        StringBuilder buf = new StringBuilder("State      Name:\n");
+        for (Map.Entry<AbstractName, Integer> entry: states.entrySet()) {
+            AbstractName name = entry.getKey();
+            int state = entry.getValue();
+            buf.append("[").append(State.fromInt(state)).append("]   ").append(name).append("\n");
+            if (verbose) {
+                if (state == State.FAILED_INDEX) {
+                    buf.append("  state reason: ").append(kernel.getStateReason(name)).append("\n\n");
+                } else if (state == State.STOPPED_INDEX) {
+                    GBeanData data = kernel.getGBeanData(name);
+                    if (!data.getDependencies().isEmpty()) {
+                        buf.append(" non-running dependendencies:\n");
+                        for (ReferencePatterns pattern : data.getDependencies()) {
+                            if (pattern.isResolved()) {
+                                AbstractName dependencyName = pattern.getAbstractName();
+                                if (states.get(dependencyName) != State.RUNNING_INDEX) {
+                                    buf.append("   state: ").append(states.get(dependencyName)).append("
resolved: ").append(dependencyName).append("\n");
+                                }
+                            } else {
+                                buf.append("  unresolved: ").append(pattern).append("\n");
+                            }
+                        }
+                    }
+                    if (!data.getReferences().isEmpty()) {
+                        GBeanInfo info = data.getGBeanInfo();
+                        buf.append("  non-running references:\n");
+                        for (Map.Entry<String, ReferencePatterns> refEntry : data.getReferences().entrySet())
{
+                            ReferencePatterns pattern = refEntry.getValue();
+                            GReferenceInfo refInfo = info.getReference(refEntry.getKey());
+                            boolean multivalued = refInfo.getProxyType().equals(Collection.class.getName());
+                            if (!multivalued) {
+                                if (pattern.isResolved()) {
+                                    AbstractName dependencyName = pattern.getAbstractName();
+                                    if (states.get(dependencyName) != State.RUNNING_INDEX)
{
+                                        buf.append("   state: [").append(State.fromInt(states.get(dependencyName))).append("]
resolved: ").append(dependencyName).append("\n");
+                                    }
+                                } else {
+                                    buf.append("  unresolved: ").append(pattern).append("\n");
+                                }
+                            }
+                        }
+
+                    }
+                }
+            }
+        }
+
+        System.out.println(buf.toString());
+
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/command/ListGBeansCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java?rev=1096955&r1=1096954&r2=1096955&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationUtil.java
Tue Apr 26 23:20:08 2011
@@ -528,15 +528,15 @@ public final class ConfigurationUtil {
                 ConfigurationUtil.startConfigurationGBeans(childConfiguration, kernel);
             }
         } catch (Throwable e) {
-            for (AbstractName gbeanName : started) {
-                try {
-                    kernel.stopGBean(gbeanName);
-                } catch (GBeanNotFoundException ignored) {
-                } catch (IllegalStateException ignored) {
-                } catch (InternalKernelException kernelException) {
-                    log.debug("Error cleaning up after failed start of configuration " +
configuration.getId() + " gbean " + gbeanName, kernelException);
-                }
-            }
+//            for (AbstractName gbeanName : started) {
+//                try {
+//                    kernel.stopGBean(gbeanName);
+//                } catch (GBeanNotFoundException ignored) {
+//                } catch (IllegalStateException ignored) {
+//                } catch (InternalKernelException kernelException) {
+//                    log.debug("Error cleaning up after failed start of configuration "
+ configuration.getId() + " gbean " + gbeanName, kernelException);
+//                }
+//            }
             if (e instanceof Error) {
                 throw (Error) e;
             }

Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml?rev=1096955&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
Tue Apr 26 23:20:08 2011
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+        <command name="gbean/list">
+            <action class="org.apache.geronimo.kernel.command.ListGBeansCommand"/>
+        </command>
+    </command-bundle>
+
+
+</blueprint>

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/resources/OSGI-INF/blueprint/kernel-command.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message