[jboss-cvs] JBossAS SVN: r88259 - in branches/Branch_5_x: system/src/main/org/jboss/system/server/profileservice/repository and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 6 09:08:27 EDT 2009


Author: emuckenhuber
Date: 2009-05-06 09:08:26 -0400 (Wed, 06 May 2009)
New Revision: 88259

Added:
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ContextStateMapper.java
Modified:
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractRuntimeComponentDispatcher.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java
Log:
fix state mapping for stopped components.

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractRuntimeComponentDispatcher.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractRuntimeComponentDispatcher.java	2009-05-06 13:02:27 UTC (rev 88258)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractRuntimeComponentDispatcher.java	2009-05-06 13:08:26 UTC (rev 88259)
@@ -24,10 +24,8 @@
 import org.jboss.deployers.spi.management.RuntimeComponentDispatcher;
 import org.jboss.managed.api.ManagedOperation;
 import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.TransientAttachments;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.metatype.spi.values.MetaMapper;
 
 /**
  * Abstract component dispatcher.
@@ -74,6 +72,16 @@
     * @return state enum value
     */
    public abstract String getState(Object name);
+   
+   /**
+    * Map the state of the component.
+    * 
+    * @param <T> the state enum
+    * @param name the component name
+    * @param mapper the state mapper
+    * @return the mapped state
+    */
+   public abstract <T extends Enum<?>> T mapControllerState(Object name, ContextStateMapper<T> mapper);
 
    /**
     * Create meta value.

Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ContextStateMapper.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ContextStateMapper.java	                        (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ContextStateMapper.java	2009-05-06 13:08:26 UTC (rev 88259)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+package org.jboss.profileservice.management;
+
+import java.util.Map;
+
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Basic state mapper.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ContextStateMapper<T extends Enum<?>>
+{
+   
+   /** The state mappings. */
+   private Map<String, T> mappings;
+   
+   /** Installing state. */
+   private T installState;
+   
+   /** Uninstalling state. */
+   private T uninstallState;
+   
+   /** The unknown state. */
+   private T unknown;
+   
+   /** The error state. */
+   private T error;
+
+   public ContextStateMapper(Map<String, T> mappings,
+         T installState, T uninstallState, T error, T unknown)
+   {
+      this.mappings = mappings;
+      this.installState = installState;
+      this.uninstallState = uninstallState;
+      this.error = error;
+      this.unknown = unknown;
+   }
+   
+   public T getErrorState()
+   {
+      return this.error;
+   }
+   
+   public T map(String currentState, String toState)
+   {
+      if(currentState == null)
+         throw new IllegalArgumentException("null current controller state.");
+      // If the context is in the required state 
+      if(toState == null || currentState.equals(toState))
+      {
+         T state = mappings.get(currentState);
+         if(state == null)
+            state = unknown;
+         return state;
+      }
+      // installing state
+      if(ControllerState.INSTALLED.equals(toState))
+         return installState;
+      // uninstalling state
+      if(ControllerState.NOT_INSTALLED.equals(toState))
+         return uninstallState;
+      
+      T state = null;
+      state = mappings.get(currentState);
+      if(state == null)
+         state = unknown;
+      
+      return state;
+   }
+   
+}
+

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java	2009-05-06 13:02:27 UTC (rev 88258)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/KernelBusRuntimeComponentDispatcher.java	2009-05-06 13:08:26 UTC (rev 88259)
@@ -29,6 +29,7 @@
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.kernel.spi.registry.KernelBus;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
 import org.jboss.managed.api.ManagedOperation;
 import org.jboss.managed.api.ManagedParameter;
 import org.jboss.managed.api.ManagedProperty;
@@ -206,4 +207,24 @@
       ControllerState state = context.getState();
       return state.getStateString();
    }
+   
+   public <T extends Enum<?>> T mapControllerState(Object name, ContextStateMapper<T> mapper)
+   {
+      if(name == null)
+         throw new IllegalArgumentException("null name");
+      if(mapper == null)
+         throw new IllegalArgumentException("null mapper");
+
+      KernelController controller = kernel.getController();
+      ControllerContext context = controller.getContext(name, null);
+      if (context == null)
+         throw new IllegalStateException("Context not installed: " + name);
+      
+      ControllerState requiredState = null;
+      // FIXME
+      if(context instanceof KernelRegistryEntry == false)
+         requiredState = context.getRequiredState();
+      String requiredStateString = requiredState != null ? requiredState.getStateString() : null;
+      return mapper.map(context.getState().getStateString(), requiredStateString);
+   }
 }

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-05-06 13:02:27 UTC (rev 88258)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-05-06 13:08:26 UTC (rev 88259)
@@ -153,8 +153,8 @@
    private List<String> rootDeployments = new ArrayList<String>();
    
    /** The state mappings. */
-   private Map<String, String> stateMappings = new HashMap<String, String>();
-   private Map<String, String> deploymentStateMappings = new HashMap<String, String>();
+   private static final ContextStateMapper<RunState> runStateMapper;
+   private static final ContextStateMapper<DeploymentState> deploymentStateMapper;
    
    /** The dispatcher handles ManagedOperation dispatches */
    private RuntimeComponentDispatcher dispatcher;
@@ -171,26 +171,38 @@
    private MBeanServer mbeanServer;
    private MBeanManagedObjectFactory mbeanMOFactory = new MBeanManagedObjectFactory();
 
+   static
+   {
+      // Set default run state mappings for mc beans/mbeans
+      Map<String, RunState> runStateMappings = new HashMap<String, RunState>();
+      runStateMappings.put("**ERROR**", RunState.FAILED);
+      runStateMappings.put("Not Installed", RunState.STOPPED);
+      runStateMappings.put("PreInstall", RunState.STOPPED);
+      runStateMappings.put("Described", RunState.STOPPED);
+      runStateMappings.put("Instantiated", RunState.STOPPED);
+      runStateMappings.put("Configured", RunState.STOPPED);
+      runStateMappings.put("Create", RunState.STOPPED);
+      runStateMappings.put("Start", RunState.STOPPED);
+      runStateMappings.put("Installed", RunState.RUNNING);
+
+      runStateMapper = new ContextStateMapper<RunState>(runStateMappings,
+            RunState.STARTING, RunState.STOPPED, RunState.FAILED, RunState.UNKNOWN);
+
+      Map<String, DeploymentState> deploymentMappings = new HashMap<String, DeploymentState>();
+      deploymentMappings.put("**ERROR**", DeploymentState.FAILED);
+      deploymentMappings.put("Not Installed", DeploymentState.STOPPED);
+      deploymentMappings.put("Installed", DeploymentState.STARTED);
+
+      deploymentStateMapper = new ContextStateMapper<DeploymentState>(deploymentMappings,
+            DeploymentState.STARTING, DeploymentState.STOPPING, DeploymentState.FAILED, DeploymentState.UNKNOWN);   
+   }
+   
    public ManagementViewImpl() throws IOException
    {
       
       currentLocale = Locale.getDefault();
       formatter.setLocale(currentLocale);
       i18n = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
-      // Set default run state mappings for mc beans/mbeans
-      stateMappings.put("**ERROR**", RunState.FAILED.name());
-      stateMappings.put("Not Installed", RunState.STOPPED.name());
-      stateMappings.put("PreInstall", RunState.STARTING.name());
-      stateMappings.put("Described", RunState.STARTING.name());
-      stateMappings.put("Instantiated", RunState.STARTING.name());
-      stateMappings.put("Configured", RunState.STARTING.name());
-      stateMappings.put("Create", RunState.STARTING.name());
-      stateMappings.put("Start", RunState.STARTING.name());
-      stateMappings.put("Installed", RunState.RUNNING.name());
-      // Set default deployment state mappings for managed deployments
-      deploymentStateMappings.put("**ERROR**", DeploymentState.FAILED.name());
-      deploymentStateMappings.put("Not Installed", DeploymentState.STOPPED.name());
-      deploymentStateMappings.put("Installed", DeploymentState.STARTED.name());
    }
    
    public void start() throws Exception
@@ -376,49 +388,52 @@
             {
                try
                {
-                  ManagedDeployment md = getManagedDeployment(deployment);
-                  processRootManagedDeployment(md, key, trace);
-                  
-                  // TODO update profileservice-spi
-                  // Cache the deployment types
-                  ((AbstractProfileDeployment)deployment)
-                     .addTransientAttachment(KnownDeploymentTypes.class.getName(), md.getTypes());
-               }
-               catch(DeploymentException e)
-               {
-                  // FIXME Assume a undeployed (stopped) deployment
-                  String deploymentName = deployment.getName();
-                  ManagedDeployment md = new ManagedDeploymentImpl(deploymentName,
-                        deployment.getRoot().getName());
-                  
-                  // TODO update profileservice-spi
-                  // Try to get the cached deployment type 
-                  Collection<String> deploymentTypes = (Collection<String>) ((AbstractProfileDeployment)deployment)
-                        .getTransientAttachment(KnownDeploymentTypes.class.getName());
-                  
-                  if(deploymentTypes != null)
+                  try
                   {
-                     for(String deploymentType : deploymentTypes)
-                        md.addType(deploymentType);
+                     ManagedDeployment md = getManagedDeployment(deployment);
+                     processRootManagedDeployment(md, key, trace);
+                     
+                     // TODO update profileservice-spi
+                     // Cache the deployment types
+                     if(md.getTypes() != null && md.getTypes().isEmpty() == false)
+                        ((AbstractProfileDeployment)deployment)
+                           .addTransientAttachment(KnownDeploymentTypes.class.getName(), md.getTypes());
                   }
-                  else
+                  catch(DeploymentException e)
                   {
-                     int i = deploymentName.lastIndexOf(".");
-                     if(i != -1 && (i + 1) < deploymentName.length())
+                     // FIXME Assume a undeployed (stopped) deployment
+                     String deploymentName = deployment.getName();
+                     ManagedDeployment md = new ManagedDeploymentImpl(deploymentName,
+                           deployment.getRoot().getName());
+                     
+                     // TODO update profileservice-spi
+                     // Try to get the cached deployment type 
+                     Collection<String> deploymentTypes = (Collection<String>) ((AbstractProfileDeployment)deployment)
+                           .getTransientAttachment(KnownDeploymentTypes.class.getName());
+                     
+                     if(deploymentTypes != null)
                      {
-                        String guessedType = deploymentName.substring(i + 1, deploymentName.length());
-                        if(guessedType.endsWith("/"))
-                           guessedType = guessedType.substring(0, guessedType.length() -1 );
-                        md.setTypes(new HashSet<String>(1));
-                        md.addType(guessedType);
-                     }  
-                  }
-                  
-                  processManagedDeployment(md, key, DeploymentState.STOPPED, 0, trace);
+                        md.setTypes(new HashSet<String>(deploymentTypes));
+                     }
+                     else
+                     {
+                        int i = deploymentName.lastIndexOf(".");
+                        if(i != -1 && (i + 1) < deploymentName.length())
+                        {
+                           String guessedType = deploymentName.substring(i + 1, deploymentName.length());
+                           if(guessedType.endsWith("/"))
+                              guessedType = guessedType.substring(0, guessedType.length() -1 );
+                           md.setTypes(new HashSet<String>(1));
+                           md.addType(guessedType);
+                        }  
+                     }
+                     
+                     processManagedDeployment(md, key, DeploymentState.STOPPED, 0, trace);
+                  }  
                }
                catch(Exception e)
                {
-                  log.debug("Failed to create ManagedDeployment for: " + deployment.getName(), e);
+                  log.warn("Failed to create ManagedDeployment for: " + deployment.getName(), e);
                }
             }
          }
@@ -756,9 +771,7 @@
             name = runtimeMO.getComponentName();
          if (name != null)
          {
-            String stateString = getControllerState(name);
-            String runStateString = stateMappings.get(stateString);
-            state = RunState.valueOf(runStateString);
+            state = getMappedState(name, runStateMapper);
             if (comp instanceof MutableManagedComponent)
             {
                MutableManagedComponent mcomp = MutableManagedComponent.class.cast(comp);
@@ -776,34 +789,32 @@
       {
          Object name = md.getName();
          if(name != null)
-         {
-            String stateString = getControllerState(name);
-            String deploymenStateString = deploymentStateMappings.get(stateString); 
-            state = DeploymentState.valueOf(deploymenStateString);
+         { 
+            state = getMappedState(name, deploymentStateMapper);
          }
       }
       return state;
    }
-   
-   protected String getControllerState(Object name)
+
+   protected <T extends Enum<?>> T getMappedState(Object name, ContextStateMapper<T> mapper)
    {
-      String state = "**ERROR**";
+      T state = mapper.getErrorState();
       try
       {
          if(dispatcher != null)
          {
             //TODO, update RuntimeComponentDispatcher
             AbstractRuntimeComponentDispatcher xdispatcher = (AbstractRuntimeComponentDispatcher) dispatcher;
-            state = xdispatcher.getState(name);  
+            state = xdispatcher.mapControllerState(name, mapper);
          }
       }
       catch(Exception e)
       {
          log.debug("Failed to get controller state", e);
       }
-      return state;
+      return state;      
    }
-
+   
    /**
     * Process generic value.
     *

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java	2009-05-06 13:02:27 UTC (rev 88258)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileDeployment.java	2009-05-06 13:08:26 UTC (rev 88259)
@@ -208,7 +208,7 @@
       if(name == null)
          throw new IllegalArgumentException("Null attachment name.");
       
-      return transientAttachments;
+      return this.transientAttachments.get(name);
    }
    
    /**




More information about the jboss-cvs-commits mailing list