[Jboss-cvs] JBossAS SVN: r57036 - in projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers: plugins/deployer plugins/deployment plugins/structure spi spi/deployment spi/structure
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 21 00:17:46 EDT 2006
Author: adrian at jboss.org
Date: 2006-09-21 00:17:36 -0400 (Thu, 21 Sep 2006)
New Revision: 57036
Added:
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentException.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeployments.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentsBuilder.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/MissingDependency.java
Modified:
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployment/MainDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java
Log:
Implement the IncompleteDeploymentException processing
with rudimentary support for "unprocessed" deployments.
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -73,6 +73,7 @@
ClassLoader cl = deploymentContext.getClassLoader();
if (cl == null)
throw new IllegalStateException("ClassLoader has not been set");
+ deploymentContext.deployed();
return cl;
}
@@ -128,11 +129,14 @@
if (parent != null)
result.putAll(parent.getPredeterminedManagedObjects().getAttachments());
result.putAll(deploymentContext.getPredeterminedManagedObjects().getAttachments());
+ if (result.isEmpty() == false)
+ deploymentContext.deployed();
return Collections.unmodifiableMap(result);
}
public Object addAttachment(String name, Object attachment)
{
+ deploymentContext.deployed();
return deploymentContext.getTransientAttachments().addAttachment(name, attachment);
}
@@ -143,30 +147,48 @@
parent = null;
Object result = deploymentContext.getPredeterminedManagedObjects().getAttachment(name);
if (result != null)
+ {
+ deploymentContext.deployed();
return result;
+ }
if (parent != null)
{
result = parent.getPredeterminedManagedObjects().getAttachment(name);
if (result != null)
+ {
+ deploymentContext.deployed();
return result;
+ }
}
result = deploymentContext.getTransientManagedObjects().getAttachment(name);
if (result != null)
+ {
+ deploymentContext.deployed();
return result;
+ }
if (parent != null)
{
result = parent.getTransientManagedObjects().getAttachment(name);
if (result != null)
+ {
+ deploymentContext.deployed();
return result;
+ }
}
result = deploymentContext.getTransientAttachments().getAttachment(name);
if (result != null)
+ {
+ deploymentContext.deployed();
return result;
+ }
if (parent != null)
{
result = parent.getTransientAttachments().getAttachment(name);
if (result != null)
+ {
+ deploymentContext.deployed();
return result;
+ }
}
return null;
}
@@ -177,17 +199,35 @@
if (deploymentContext.isComponent() == false)
parent = null;
if (deploymentContext.getPredeterminedManagedObjects().isAttachmentPresent(name))
+ {
+ deploymentContext.deployed();
return true;
+ }
if (parent != null && parent.getPredeterminedManagedObjects().isAttachmentPresent(name))
+ {
+ deploymentContext.deployed();
return true;
+ }
if (deploymentContext.getTransientManagedObjects().isAttachmentPresent(name))
+ {
+ deploymentContext.deployed();
return true;
+ }
if (parent != null && parent.getTransientAttachments().isAttachmentPresent(name))
+ {
+ deploymentContext.deployed();
return true;
+ }
if (deploymentContext.getTransientAttachments().isAttachmentPresent(name))
+ {
+ deploymentContext.deployed();
return true;
+ }
if (parent != null && parent.getTransientAttachments().isAttachmentPresent(name))
+ {
+ deploymentContext.deployed();
return true;
+ }
return false;
}
@@ -215,12 +255,15 @@
if (type.isInstance(object))
result.add((T) object);
}
+ if (result.isEmpty() == false)
+ deploymentContext.deployed();
return result;
}
@Deprecated
public DeploymentContext getDeploymentContext()
{
+ deploymentContext.deployed();
return deploymentContext;
}
}
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -31,6 +31,8 @@
import static org.jboss.deployers.spi.structure.StructureDetermined.YES;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -79,6 +81,12 @@
/** All deployments by name */
private Map<String, DeploymentContext> allDeployments = new ConcurrentHashMap<String, DeploymentContext>();
+
+ /** Deployments in error by name */
+ private Map<String, DeploymentContext> errorDeployments = new ConcurrentHashMap<String, DeploymentContext>();
+
+ /** Deployments missing deployers */
+ private Map<String, DeploymentContext> missingDeployers = new ConcurrentHashMap<String, DeploymentContext>();
/** The undeploy work */
private List<DeploymentContext> undeploy = new CopyOnWriteArrayList<DeploymentContext>();
@@ -261,6 +269,7 @@
log.error("Unable to determine structure of deployment: " + name, t);
context.setState(ERROR);
context.setProblem(t);
+ errorDeployments.put(name, context);
}
addContext(context);
@@ -285,6 +294,26 @@
return true;
}
+ public Collection<DeploymentContext> getAll()
+ {
+ return Collections.unmodifiableCollection(allDeployments.values());
+ }
+
+ public Collection<DeploymentContext> getErrors()
+ {
+ return Collections.unmodifiableCollection(errorDeployments.values());
+ }
+
+ public Collection<DeploymentContext> getMissingDeployer()
+ {
+ return Collections.unmodifiableCollection(missingDeployers.values());
+ }
+
+ public Collection<DeploymentContext> getTopLevel()
+ {
+ return Collections.unmodifiableCollection(topLevelDeployments.values());
+ }
+
public void process()
{
if (shutdown.get())
@@ -350,6 +379,7 @@
context.setState(ERROR);
context.setProblem(e);
errors.add(context);
+ errorDeployments.put(context.getName(), context);
// Unwind the deployment
for (int j = i-1; j >= 0; --j)
{
@@ -363,8 +393,12 @@
}
for (DeploymentContext context : deployContexts)
{
+ String name = context.getName();
+ // TODO Need some metadata that says we expect a deployment to only provide classes
+ if (context.isDeployed() == false && context.getRoot().getName().endsWith(".jar") == false)
+ missingDeployers.put(name, context);
context.setState(DEPLOYED);
- log.debug("Deployed: " + context.getName());
+ log.debug("Deployed: " + name);
}
}
}
@@ -556,14 +590,17 @@
*/
private void removeContext(DeploymentContext context)
{
- allDeployments.remove(context.getName());
+ String name = context.getName();
+ allDeployments.remove(name);
+ errorDeployments.remove(name);
+ missingDeployers.remove(name);
if (context.getState() == ERROR)
{
- log.debug("Not scheduling removal of context already in error: " + context.getName());
+ log.debug("Not scheduling removal of context already in error: " + name);
return;
}
context.setState(UNDEPLOYING);
- log.debug("Scheduling undeployment: " + context.getName());
+ log.debug("Scheduling undeployment: " + name);
undeploy.add(context);
// Remove all the children
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -82,6 +82,9 @@
/** Whether this is a candidate deployment */
private boolean candidate = false;
+ /** Whether this deployment was processed */
+ private boolean deployed = false;
+
/** The parent context */
private DeploymentContext parent;
@@ -319,7 +322,7 @@
{
if (factory == null)
throw new IllegalArgumentException("Null factory");
-
+
ClassLoader cl = getClassLoader();
if (cl != null)
return false;
@@ -431,6 +434,7 @@
{
if (component == null)
throw new IllegalArgumentException("Null component");
+ deployed();
components.add(component);
log.debug("Added component " + component.getName() + " to " + getName());
}
@@ -582,7 +586,10 @@
return null;
}
// Look in the meta data location
- return metaDataLocation.findChild(name);
+ VirtualFile result = metaDataLocation.findChild(name);
+ if (result != null)
+ deployed();
+ return result;
}
catch (Exception e)
{
@@ -615,7 +622,10 @@
return Collections.emptyList();
}
// Look in the meta data location
- return metaDataLocation.getChildren(new MetaDataMatchFilter(name, suffix));
+ List<VirtualFile> result = metaDataLocation.getChildren(new MetaDataMatchFilter(name, suffix));
+ if (result != null && result.isEmpty() == false)
+ deployed();
+ return result;
}
catch (Exception e)
{
@@ -624,6 +634,16 @@
}
}
+ public boolean isDeployed()
+ {
+ return deployed;
+ }
+
+ public void deployed()
+ {
+ deployed = true;
+ }
+
public void reset()
{
if (structureDetermined != StructureDetermined.PREDETERMINED)
@@ -634,6 +654,7 @@
child.reset();
}
components.clear();
+ deployed = false;
classLoader = null;
transientManagedObjects.clear();
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/ComponentDeploymentContext.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -366,6 +366,16 @@
return parent.getMetaDataFiles(name, suffix);
}
+ public void deployed()
+ {
+ parent.deployed();
+ }
+
+ public boolean isDeployed()
+ {
+ return parent.isDeployed();
+ }
+
public void reset()
{
components.clear();
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentException.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentException.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentException.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -0,0 +1,152 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.spi;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * IncompleteDeploymentException.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class IncompleteDeploymentException extends DeploymentException
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1433292979582684692L;
+
+ /** Incomplete deployments */
+ private IncompleteDeployments incompleteDeployments;
+
+ /**
+ * For serialization
+ */
+ public IncompleteDeploymentException()
+ {
+ }
+
+ /**
+ * Create a new IncompleteDeploymentException.
+ *
+ * @param incompleteDeployments the incomplete deployments
+ * @throws IllegalArgumentException for null incompleteDeployments
+ */
+ public IncompleteDeploymentException(IncompleteDeployments incompleteDeployments)
+ {
+ if (incompleteDeployments == null)
+ throw new IllegalArgumentException("Null incompleteDeployments");
+ this.incompleteDeployments = incompleteDeployments;
+ }
+
+ /**
+ * Get the incompleteDeployments.
+ *
+ * @return the incompleteDeployments.
+ */
+ public IncompleteDeployments getIncompleteDeployments()
+ {
+ return incompleteDeployments;
+ }
+
+ public String getMessage()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):\n");
+
+ // Display all the missing deployers
+ Collection<String> deploymentsMissingDeployers = incompleteDeployments.getDeploymentsMissingDeployer();
+ if (deploymentsMissingDeployers.isEmpty() == false)
+ {
+ buffer.append("\n*** DEPLOYMENTS MISSING DEPLOYERS: Name\n\n");
+ for (String name : deploymentsMissingDeployers)
+ buffer.append(name).append('\n');
+ }
+
+ // Display all the incomplete deployments
+ Map<String, Throwable> deploymentsInError = incompleteDeployments.getDeploymentsInError();
+ if (deploymentsInError.isEmpty() == false)
+ {
+ buffer.append("\n*** DEPLOYMENTS IN ERROR: Name -> Error\n\n");
+ for (Map.Entry<String, Throwable> entry : deploymentsInError.entrySet())
+ buffer.append(entry.getKey()).append(" -> ").append(entry.getValue().toString()).append("\n\n");
+ }
+
+ // Popluate the potential root causes
+ Map<String, String> rootCauses = new HashMap<String, String>();
+
+ // Errors are root causes
+ Map<String, Throwable> contextsInError = incompleteDeployments.getContextsInError();
+ if (contextsInError.isEmpty() == false)
+ {
+ for (Map.Entry<String, Throwable> entry : contextsInError.entrySet())
+ {
+ Throwable t = entry.getValue();
+ if (t == null)
+ rootCauses.put(entry.getKey(), "** UNKNOWN ERROR **");
+ else
+ rootCauses.put(entry.getKey(), t.toString());
+ }
+ }
+ // Missing dependencies are root causes
+ Map<String, Set<MissingDependency>> contextsMissingDependencies = incompleteDeployments.getContextsMissingDependencies();
+ if (contextsMissingDependencies.isEmpty() == false)
+ {
+ for (Map.Entry<String, Set<MissingDependency>> entry : contextsMissingDependencies.entrySet())
+ {
+ for (MissingDependency dependency : entry.getValue())
+ rootCauses.put(dependency.getDependency(), dependency.getActualState());
+ }
+ }
+
+ // Display all the missing dependencies
+ if (contextsMissingDependencies.isEmpty() == false)
+ {
+ buffer.append("\n*** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n\n");
+ for (Map.Entry<String, Set<MissingDependency>> entry : contextsMissingDependencies.entrySet())
+ {
+ String name = entry.getKey();
+ buffer.append(name).append("\n");
+ for (MissingDependency dependency : entry.getValue())
+ {
+ buffer.append(" -> ").append(dependency.getDependency());
+ buffer.append('{').append(dependency.getRequiredState());
+ buffer.append(':').append(dependency.getActualState()).append("}");
+ buffer.append("\n");
+ }
+ buffer.append('\n');
+
+ // It is not a root cause if it has missing dependencies
+ rootCauses.remove(name);
+ }
+ }
+ if (rootCauses.isEmpty() == false)
+ {
+ buffer.append("\n*** CONTEXTS IN ERROR: Name -> Error\n\n");
+ for (Map.Entry<String, String> entry : rootCauses.entrySet())
+ buffer.append(entry.getKey()).append(" -> ").append(entry.getValue()).append("\n\n");
+ }
+ return buffer.toString();
+ }
+}
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeployments.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeployments.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeployments.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -0,0 +1,155 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.spi;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+/**
+ * IncompleteDeployments.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class IncompleteDeployments
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1433292979582684692L;
+
+ /** Deployments in error */
+ private Map<String, Throwable> deploymentsInError;
+
+ /** Deployments missing deployer */
+ private Collection<String> deploymentsMissingDeployer;
+
+ /** Contexts in error */
+ private Map<String, Throwable> contextsInError;
+
+ /** Contexts missing dependencies */
+ private Map<String, Set<MissingDependency>> contextsMissingDependencies;
+
+ /**
+ * Create a new IncompleteDeploymentException.
+ *
+ * @param deploymentsInError
+ * @param deploymentsMissingDeployer
+ * @param contextsInError
+ * @param contextsMissingDependencies
+ */
+ public IncompleteDeployments(Map<String, Throwable> deploymentsInError, Collection<String> deploymentsMissingDeployer, Map<String, Throwable> contextsInError, Map<String, Set<MissingDependency>> contextsMissingDependencies)
+ {
+ if (deploymentsInError != null && deploymentsInError.isEmpty() == false)
+ {
+ this.deploymentsInError = new TreeMap<String, Throwable>();
+ this.deploymentsInError.putAll(deploymentsInError);
+ }
+ if (deploymentsMissingDeployer != null && deploymentsMissingDeployer.isEmpty() == false)
+ {
+ this.deploymentsMissingDeployer = new TreeSet<String>();
+ this.deploymentsMissingDeployer.addAll(deploymentsMissingDeployer);
+ }
+ if (contextsInError != null && contextsInError.isEmpty() == false)
+ {
+ this.contextsInError = new TreeMap<String, Throwable>();
+ this.contextsInError.putAll(contextsInError);
+ }
+ if (contextsMissingDependencies != null && contextsMissingDependencies.isEmpty() == false)
+ {
+ this.contextsMissingDependencies = new TreeMap<String, Set<MissingDependency>>();
+ this.contextsMissingDependencies.putAll(contextsMissingDependencies);
+ }
+ }
+
+ /**
+ * Whether it is incomplete
+ *
+ * @return true when incomplete
+ */
+ public boolean isIncomplete()
+ {
+ if (deploymentsInError != null)
+ return true;
+ if (deploymentsMissingDeployer != null )
+ return true;
+ if (contextsInError != null)
+ return true;
+ if (contextsMissingDependencies != null)
+ return true;
+ return false;
+ }
+
+ /**
+ * Get the contextsInError.
+ *
+ * @return the contextsInError.
+ */
+ public Map<String, Throwable> getContextsInError()
+ {
+ if (contextsInError == null)
+ return Collections.emptyMap();
+ else
+ return Collections.unmodifiableMap(contextsInError);
+ }
+
+ /**
+ * Get the contextsMissingDependencies.
+ *
+ * @return the contextsMissingDependencies.
+ */
+ public Map<String, Set<MissingDependency>> getContextsMissingDependencies()
+ {
+ if (contextsMissingDependencies == null)
+ return Collections.emptyMap();
+ else
+ return Collections.unmodifiableMap(contextsMissingDependencies);
+ }
+
+ /**
+ * Get the deploymentsInError.
+ *
+ * @return the deploymentsInError.
+ */
+ public Map<String, Throwable> getDeploymentsInError()
+ {
+ if (deploymentsInError == null)
+ return Collections.emptyMap();
+ else
+ return Collections.unmodifiableMap(deploymentsInError);
+ }
+
+ /**
+ * Get the deploymentsMissingDeployer.
+ *
+ * @return the deploymentsMissingDeployer.
+ */
+ public Collection<String> getDeploymentsMissingDeployer()
+ {
+ if (deploymentsMissingDeployer == null)
+ return Collections.emptySet();
+ else
+ return Collections.unmodifiableCollection(deploymentsMissingDeployer);
+ }
+}
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentsBuilder.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentsBuilder.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/IncompleteDeploymentsBuilder.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -0,0 +1,174 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.spi;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.spi.deployment.MainDeployer;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+
+/**
+ * IncompleteDeploymentBuilder.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class IncompleteDeploymentsBuilder
+{
+ /**
+ * Get the root cause of a throwable
+ *
+ * @param original the original
+ * @return the root
+ */
+ private static Throwable getCause(Throwable original)
+ {
+ if (original == null)
+ return null;
+ Throwable result = original;
+ Throwable cause = result.getCause();
+ while (cause != null)
+ {
+ result = cause;
+ cause = cause.getCause();
+ }
+ return result;
+ }
+
+ /**
+ * Build an incomplete deployment
+ *
+ * @param main the main deployer
+ * @param controller the controller
+ * @return the incomplte deployments
+ */
+ public static IncompleteDeployments build(MainDeployer main, Controller controller)
+ {
+ Map<String, Throwable> deploymentsInError = null;
+ Collection<String> deploymentsMissingDeployer = null;
+ Map<String, Throwable> contextsInError = null;
+ Map<String, Set<MissingDependency>> contextsMissingDependencies = null;
+
+ if (main != null)
+ {
+ Collection<DeploymentContext> errors = main.getErrors();
+ if (errors != null && errors.isEmpty() == false)
+ {
+ deploymentsInError = new HashMap<String, Throwable>();
+ for (DeploymentContext context : errors)
+ deploymentsInError.put(context.getName(), getCause(context.getProblem()));
+ }
+
+
+ Collection<DeploymentContext> missingDeployer = main.getMissingDeployer();
+ if (missingDeployer != null && missingDeployer.isEmpty() == false)
+ {
+ deploymentsMissingDeployer = new HashSet<String>();
+ for (DeploymentContext context : missingDeployer)
+ deploymentsMissingDeployer.add(context.getName());
+ }
+ }
+
+ if (controller != null)
+ {
+ List<ControllerState> states = controller.getStates();
+
+ Set<ControllerContext> notInstalled = controller.getNotInstalled();
+ if (notInstalled.isEmpty() == false)
+ {
+ for (Iterator<ControllerContext> i = notInstalled.iterator(); i.hasNext();)
+ {
+ ControllerContext context = i.next();
+ if (context.getState().equals(context.getRequiredState()))
+ i.remove();
+ }
+ if (notInstalled.isEmpty() == false)
+ {
+ contextsInError = new HashMap<String, Throwable>();
+ contextsMissingDependencies = new HashMap<String, Set<MissingDependency>>();
+ for (ControllerContext context : notInstalled)
+ {
+ if (context.getState().equals(ControllerState.ERROR))
+ contextsInError.put(context.getName().toString(), getCause(context.getError()));
+ else
+ {
+ String name = context.getName().toString();
+ Set<MissingDependency> dependencies = new HashSet<MissingDependency>();
+ DependencyInfo dependsInfo = context.getDependencyInfo();
+ for (DependencyItem item : dependsInfo.getIDependOn(null))
+ {
+ if (item.isResolved() == false)
+ {
+ String dependency = null;
+ ControllerState actualState = null;
+ String actualStateString = null;
+ Object iDependOn = item.getIDependOn();
+ if (iDependOn == null)
+ {
+ dependency = "<UNKNOWN>";
+ // TODO allow the item to better describe itself
+ actualStateString = "** UNRESOLVED " + item + " **";
+ }
+ else
+ {
+ dependency = iDependOn.toString();
+ ControllerContext other = controller.getContext(item.getIDependOn(), null);
+ if (other == null)
+ actualStateString = "** NOT FOUND **";
+ else
+ {
+ actualState = other.getState();
+ actualStateString = actualState.getStateString();
+ }
+ }
+ ControllerState requiredState = item.getWhenRequired();
+ String requiredStateString = requiredState.getStateString();
+ int required = states.indexOf(requiredState);
+ int actual = actualState == null ? -1 : states.indexOf(actualState);
+ if (required > actual)
+ {
+ MissingDependency missing = new MissingDependency(name, dependency, requiredStateString, actualStateString);
+ dependencies.add(missing);
+ }
+ }
+ }
+ contextsMissingDependencies.put(name, dependencies);
+ }
+ }
+ }
+ }
+ }
+
+ return new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies);
+ }
+}
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/MissingDependency.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/MissingDependency.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/MissingDependency.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -0,0 +1,111 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.spi;
+
+import java.io.Serializable;
+
+/**
+ * MissingDependency.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MissingDependency implements Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1159684023853245283L;
+
+ /** The name */
+ private String name;
+
+ /** The dependency */
+ private String dependency;
+
+ /** The required state */
+ private String requiredState;
+
+ /** The actual state */
+ private String actualState;
+
+ /**
+ * For serialization
+ */
+ public MissingDependency()
+ {
+ }
+
+ /**
+ * Create a new MissingDependency.
+ *
+ * @param name the name
+ * @param dependency the dependency
+ * @param requiredState the required state
+ * @param actualState the actual state
+ */
+ public MissingDependency(String name, String dependency, String requiredState, String actualState)
+ {
+ this.name = name;
+ this.dependency = dependency;
+ this.requiredState = requiredState;
+ this.actualState = actualState;
+ }
+
+ /**
+ * Get the actualState.
+ *
+ * @return the actualState.
+ */
+ public String getActualState()
+ {
+ return actualState;
+ }
+
+ /**
+ * Get the dependency.
+ *
+ * @return the dependency.
+ */
+ public String getDependency()
+ {
+ return dependency;
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the requiredState.
+ *
+ * @return the requiredState.
+ */
+ public String getRequiredState()
+ {
+ return requiredState;
+ }
+}
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployment/MainDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployment/MainDeployer.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployment/MainDeployer.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -21,6 +21,8 @@
*/
package org.jboss.deployers.spi.deployment;
+import java.util.Collection;
+
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.structure.DeploymentContext;
@@ -45,6 +47,34 @@
DeploymentContext getDeploymentContext(String name);
/**
+ * Get the top level deployments
+ *
+ * @return the top level deployments
+ */
+ Collection<DeploymentContext> getTopLevel();
+
+ /**
+ * Get all the deployments
+ *
+ * @return the deployments
+ */
+ Collection<DeploymentContext> getAll();
+
+ /**
+ * Get the deployments in error
+ *
+ * @return the deployments
+ */
+ Collection<DeploymentContext> getErrors();
+
+ /**
+ * Get the deployments missing a deployer
+ *
+ * @return the deployments
+ */
+ Collection<DeploymentContext> getMissingDeployer();
+
+ /**
* Add a deployment context
*
* @param context the deployment context
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java 2006-09-21 04:16:27 UTC (rev 57035)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java 2006-09-21 04:17:36 UTC (rev 57036)
@@ -293,6 +293,18 @@
Attachments getTransientAttachments();
/**
+ * Whether the deployment was processed
+ *
+ * @return true when processed
+ */
+ boolean isDeployed();
+
+ /**
+ * Touch the context to say it is deployed
+ */
+ void deployed();
+
+ /**
* Get the problem for this context
*
* @return the problem
More information about the jboss-cvs-commits
mailing list