[jboss-cvs] JBossAS SVN: r83395 - trunk/system/src/main/org/jboss/system/server/profileservice/repository.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 24 06:53:14 EST 2009


Author: emuckenhuber
Date: 2009-01-24 06:53:14 -0500 (Sat, 24 Jan 2009)
New Revision: 83395

Modified:
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java
Log:
validate activated profile only

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java	2009-01-24 11:09:21 UTC (rev 83394)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java	2009-01-24 11:53:14 UTC (rev 83395)
@@ -26,7 +26,6 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -272,18 +271,24 @@
       }
       
       // Check if the profile was activated successfully 
-      validate();
+      validate(context);
    }
    
    /**
     * Check if all dependencies are satisfied and the profile was installed successfully.
     * 
+    * @param context the context to validate
     * @throws Exception
     */
-   public void validate() throws Exception
+   public void validate(ControllerContext context) throws Exception
    {
-      // TODO - this should basically just validate the activated profile with it's dependencies
-      internalValidate(((AbstractController)controller).getAllContexts());
+      // 
+      Set<String> errors = new HashSet<String>();
+      Set<String> incomplete = new HashSet<String>();
+      // Validate the context, with it's dependencies
+      internalValidateContext(context, errors, incomplete);
+      // Create and throw the Exception
+      logErrors(errors, incomplete);
    }
    
    public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
@@ -373,108 +378,109 @@
       controller.uninstall(key);
    }
    
-   protected void internalValidate(Set<ControllerContext> notInstalled) throws Exception
+   /**
+    * Validate the context and create the error messages if needed.
+    * 
+    * TODO this only checks for NOT FOUND dependencies. 
+    * 
+    * @param ctx the context to validate
+    * @param errors a set of errors
+    * @param incomplete a set of incomplete contexts
+    */
+   protected void internalValidateContext(ControllerContext ctx, Set<String> errors, Set<String> incomplete)
    {
-      // Validate from AbstractKernelDeployer
-      if (notInstalled.isEmpty() == false)
+      if (ctx.getState().equals(ControllerState.ERROR))
       {
-         for (Iterator<ControllerContext> i = notInstalled.iterator(); i.hasNext();)
+         String error = ctx.getName() + " -> " + ctx.getError().toString(); 
+         errors.add(error);
+      }
+      else
+      {
+         Object name = ctx.getName();
+         DependencyInfo dependsInfo = ctx.getDependencyInfo();
+         Set<DependencyItem> depends = dependsInfo.getIDependOn(null);
+         for (DependencyItem item : depends)
          {
-            ControllerContext context = i.next();
-            if (context.getState().equals(context.getRequiredState()))
-               i.remove();
-         }
-         if (notInstalled.isEmpty() == false)
-         {
-            HashSet<ControllerContext> errors = new HashSet<ControllerContext>();
-            HashSet<ControllerContext> incomplete = new HashSet<ControllerContext>();
-            for (ControllerContext ctx : notInstalled)
+            ControllerState dependentState = item.getDependentState();
+            if (dependentState == null)
+               dependentState = ControllerState.INSTALLED;
+            
+            ControllerContext other = null; 
+            Object iDependOn = item.getIDependOn();
+            if (name.equals(iDependOn) == false)
             {
-               if (ctx.getState().equals(ControllerState.ERROR))
-                  errors.add(ctx);
-               else
-                  incomplete.add(ctx);
-            }
-            JBossStringBuilder buffer = new JBossStringBuilder();
-            buffer.append("Incompletely deployed:\n");
-            if (errors.size() != 0)
-            {
-               buffer.append("\n*** PROFILES IN ERROR: Name -> Error\n");
-               for (ControllerContext ctx : errors)
+               if (iDependOn != null)
                {
-                  buffer.append(ctx.getName()).append(" -> ").append(ctx.getError().toString()).append('\n');
+                  other = controller.getContext(iDependOn, null);
                }
-            }
-            if (incomplete.size() != 0)
-            {
-               buffer.append("\n*** PROFILES MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n");
-               for (ControllerContext ctx : incomplete)
+
+               if(other == null)
                {
-                  Object name = ctx.getName();
+                  JBossStringBuilder buffer = new JBossStringBuilder();
                   buffer.append(name).append(" -> ");
-                  DependencyInfo dependsInfo = ctx.getDependencyInfo();
-                  Set<DependencyItem> depends = dependsInfo.getIDependOn(null);
-                  boolean first = true;
-                  for (DependencyItem item : depends)
+                  
+                  buffer.append(iDependOn).append('{').append(dependentState.getStateString());
+                  buffer.append(':');
+                  if (iDependOn == null)
                   {
-                     ControllerState dependentState = item.getDependentState();
-                     if (dependentState == null)
-                        dependentState = ControllerState.INSTALLED;
-                     
-                     ControllerState otherState = null;
-                     ControllerContext other = null; 
-                     Object iDependOn = item.getIDependOn();
-
-                     if (name.equals(iDependOn) == false)
-                     {
-                        if (iDependOn != null)
-                        {
-                           other = controller.getContext(iDependOn, null);
-                           if (other != null)
-                              otherState = other.getState();
-                        }
-
-                        boolean print = true;
-                        if (otherState != null && otherState.equals(ControllerState.ERROR) == false)
-                        {
-                           ControllerStateModel states = controller.getStates();
-                           if (states.isBeforeState(otherState, dependentState) == false)
-                              print = false;
-                        }
-
-                        if (print)
-                        {
-                           if (first)
-                              first = false;
-                           else
-                              buffer.append(", ");
-
-                           buffer.append(iDependOn).append('{').append(dependentState.getStateString());
-                           buffer.append(':');
-                           if (iDependOn == null)
-                           {
-                              buffer.append("** UNRESOLVED " + item.toHumanReadableString() + " **");
-                           }
-                           else
-                           {
-                              if (other == null)
-                                 buffer.append("** NOT FOUND **");
-                              else
-                                 buffer.append(otherState.getStateString());
-                           }
-                           buffer.append('}');
-                        }
-                     }
+                     buffer.append("** UNRESOLVED " + item.toHumanReadableString() + " **");
                   }
-                  buffer.append('\n');
+                  else
+                  {
+                     buffer.append("** NOT FOUND **");
+                  }
+                  buffer.append('}');
+                  
+                  // Add to incomplete list
+                  incomplete.add(buffer.toString());                  
                }
+               else
+               {
+                  // If there is a known context, see why it's not working
+                  internalValidateContext(other, errors, incomplete);
+               }
             }
-            throw new IllegalStateException(buffer.toString());
          }
       }
    }
    
    /**
+    * This method just groups the errors and incomplete messages and throws an
+    * Exception if there are errors or missing dependencies.
+    * 
+    * @param errors a set of errors
+    * @param incomplete a set of missing dependencies
+    * @throws Exception in case there are errors or missing dependencies
+    */
+   protected void logErrors(Set<String> errors, Set<String> incomplete) throws Exception
+   {
+      if(errors.isEmpty() && incomplete.isEmpty())
+         return;
+
+      JBossStringBuilder buffer = new JBossStringBuilder();
+      buffer.append("Incompletely deployed:\n");
+      
+      // Append errors
+      if(errors.size() != 0)
+      {
+         buffer.append("\n*** PROFILES IN ERROR: Name -> Error\n");
+         for(String error : errors)
+            buffer.append(error).append('\n');
+      }
+      
+      // Append missing dependencies
+      if(incomplete.size() != 0)
+      {
+         buffer.append("\n*** PROFILES MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n");
+         for(String missing : incomplete)
+            buffer.append(missing).append('\n');
+      }
+      
+      // Fail
+      throw new IllegalStateException(buffer.toString());
+   }
+   
+   /**
     * A simple lifecycle action to add/remove a profile to the activeProfiles.  
     */
    private class ProfileInstallAction extends AbstractProfileLifeCycleAction
@@ -482,7 +488,7 @@
       public void install(Profile profile) throws Exception
       {
          // activate profile
-         activeProfiles.add(profile.getKey());
+         activeProfiles.add(0, profile.getKey());
          log.debug("profile activated: " + profile);
       }
       public void uninstall(Profile profile)




More information about the jboss-cvs-commits mailing list