You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2006/07/25 06:14:39 UTC

svn commit: r425270 - in /geronimo/branches/1.1: configs/client-corba/src/plan/ modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ modules/deployment/src/java/org/apache/geronimo/deployment/ modules/j2ee-builder/src/test/org/a...

Author: dain
Date: Mon Jul 24 21:14:39 2006
New Revision: 425270

URL: http://svn.apache.org/viewvc?rev=425270&view=rev
Log:
GERONIMO-1960 Bad GBean reference isn't caught during deployment

Modified:
    geronimo/branches/1.1/configs/client-corba/src/plan/plan.xml
    geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java
    geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/branches/1.1/modules/j2ee-builder/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/SingleElementCollection.java

Modified: geronimo/branches/1.1/configs/client-corba/src/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/configs/client-corba/src/plan/plan.xml?rev=425270&r1=425269&r2=425270&view=diff
==============================================================================
--- geronimo/branches/1.1/configs/client-corba/src/plan/plan.xml (original)
+++ geronimo/branches/1.1/configs/client-corba/src/plan/plan.xml Mon Jul 24 21:14:39 2006
@@ -55,9 +55,9 @@
         <attribute name="props">
             com.sun.CORBA.ORBServerHost=${PlanORBSSLHost}
         </attribute>
-        <dependency>
+        <!--dependency>
             <name>SecurityService</name>
-        </dependency>
+        </dependenc-->
         <dependency>
             <name>CORBASystemProperties</name>
         </dependency>

Modified: geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java?rev=425270&r1=425269&r2=425270&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java (original)
+++ geronimo/branches/1.1/modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ConnectorModuleBuilderTest.java Mon Jul 24 21:14:39 2006
@@ -151,7 +151,7 @@
     private Kernel kernel;
     private EditableConfigurationManager configurationManager;
     private static final Naming naming = new Jsr77Naming();
-    private static final Artifact bootId = new Artifact("test", "test", "", "car");
+    private static final Artifact bootId = new Artifact("test", "test", "42", "car");
 
     private static final AbstractNameQuery connectionTrackerName = new AbstractNameQuery(null, Collections.singletonMap("name", "ConnectionTracker"));
     private AbstractName serverName;
@@ -162,9 +162,22 @@
         JarFile rarFile = null;
         try {
             rarFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-ear-noger.ear"));
-            EARConfigBuilder configBuilder = new EARConfigBuilder(defaultEnvironment, transactionContextManagerName, connectionTrackerName, null, null, null, new AbstractNameQuery(serverName, J2EEServerImpl.GBEAN_INFO.getInterfaces()), null, null, ejbReferenceBuilder, null,
-                    new ConnectorModuleBuilder(defaultEnvironment, defaultMaxSize, defaultMinSize, defaultBlockingTimeoutMilliseconds, defaultidleTimeoutMinutes, defaultXATransactionCaching, defaultXAThreadCaching),
-                    resourceReferenceBuilder, null, serviceReferenceBuilder, kernel.getNaming());
+            EARConfigBuilder configBuilder = new EARConfigBuilder(defaultEnvironment,
+                    transactionContextManagerName,
+                    connectionTrackerName,
+                    null,
+                    null,
+                    null,
+                    new AbstractNameQuery(serverName, J2EEServerImpl.GBEAN_INFO.getInterfaces()),
+                    null,
+                    null,
+                    Collections.singleton(ejbReferenceBuilder),
+                    null,
+                    Collections.singleton(new ConnectorModuleBuilder(defaultEnvironment, defaultMaxSize, defaultMinSize, defaultBlockingTimeoutMilliseconds, defaultidleTimeoutMinutes, defaultXATransactionCaching, defaultXAThreadCaching)),
+                    Collections.singleton(resourceReferenceBuilder),
+                    null,
+                    Collections.singleton(serviceReferenceBuilder),
+                    kernel);
             ConfigurationData configData = null;
             DeploymentContext context = null;
             ArtifactManager artifactManager = new DefaultArtifactManager();

Modified: geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=425270&r1=425269&r2=425270&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java Mon Jul 24 21:14:39 2006
@@ -48,6 +48,8 @@
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.gbean.GReferenceInfo;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Naming;
@@ -57,7 +59,6 @@
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.ArtifactResolver;
 import org.apache.geronimo.kernel.repository.Environment;
 
 /**
@@ -363,7 +364,18 @@
         childConfigurationDatas.put(moduleName, configurationData);
     }
 
-    public ConfigurationData getConfigurationData() {
+    public ConfigurationData getConfigurationData() throws DeploymentException {
+        List failures = verify();
+        if (!failures.isEmpty()) {
+            StringBuffer message = new StringBuffer();
+            for (Iterator iterator = failures.iterator(); iterator.hasNext();) {
+                String failure = (String) iterator.next();
+                if (message.length() > 0) message.append("\n");
+                message.append(failure);
+            }
+            throw new DeploymentException(message.toString());
+        }
+
         ConfigurationData configurationData = new ConfigurationData(configuration.getModuleType(),
                 new LinkedHashSet(configuration.getClassPath()),
                 new ArrayList(configuration.getGBeans().values()),
@@ -377,7 +389,7 @@
             ConfigurationData ownedConfiguration = (ConfigurationData) iterator.next();
             configurationData.addOwnedConfigurations(ownedConfiguration.getId());
         }
-        
+
         return configurationData;
     }
 
@@ -387,5 +399,81 @@
 
     public List getAdditionalDeployment() {
         return additionalDeployment;
+    }
+
+    public List verify() throws DeploymentException {
+        List failures = new ArrayList();
+        for (Iterator iterator = configuration.getGBeans().entrySet().iterator(); iterator.hasNext();) {
+            Map.Entry entry = (Map.Entry) iterator.next();
+            AbstractName name = (AbstractName) entry.getKey();
+            GBeanData gbean = (GBeanData) entry.getValue();
+
+            for (Iterator iterator1 = gbean.getReferences().entrySet().iterator(); iterator1.hasNext();) {
+                Map.Entry referenceEntry = (Map.Entry) iterator1.next();
+                String referenceName = (String) referenceEntry.getKey();
+                ReferencePatterns referencePatterns = (ReferencePatterns) referenceEntry.getValue();
+
+                String failure = verifyReference(gbean, referenceName, referencePatterns);
+                if (failure != null) {
+                    failures.add(failure);
+                }
+            }
+
+            for (Iterator iterator1 = gbean.getDependencies().iterator(); iterator1.hasNext();) {
+                ReferencePatterns referencePatterns = (ReferencePatterns) iterator1.next();
+                String failure = verifyDependency(name, referencePatterns);
+                if (failure != null) {
+                    failures.add(failure);
+                }
+            }
+        }
+        return failures;
+    }
+
+    private String verifyReference(GBeanData gbean, String referenceName, ReferencePatterns referencePatterns) {
+        GReferenceInfo referenceInfo = gbean.getGBeanInfo().getReference(referenceName);
+
+        // if there is no reference info we can't verify
+        if (referenceInfo == null) return null;
+
+        // A collection valued reference doesn't need to be verified
+        if (referenceInfo.getProxyType().equals(Collection.class.getName())) return null;
+
+        if (!isVerifyReference(referencePatterns)) {
+            return "Unable to resolve reference \"" + referenceName + "\" in gbean " +
+                    gbean.getAbstractName() + " to a gbean matching the pattern " + referencePatterns.getPatterns();
+        }
+        return null;
+    }
+
+    private String verifyDependency(AbstractName name, ReferencePatterns referencePatterns) {
+        if (!isVerifyReference(referencePatterns)) {
+            return "Unable to resolve dependency in gbean " + name +
+                    " to a gbean matching the pattern " + referencePatterns.getPatterns();
+        }
+
+        return null;
+    }
+
+    private boolean isVerifyReference(ReferencePatterns referencePatterns) {
+        // we can't verify a resolved reference since it will have a specific artifact already set...
+        // hopefully the deployer won't generate bad resolved references
+        if (referencePatterns.isResolved()) return true;
+
+        // Do not verify the reference if it has an explicit depenency on another artifact, because it it likely
+        // that the other artifact is not in the "environment" (if it were you wouldn't use the long form)
+        Set patterns = referencePatterns.getPatterns();
+        for (Iterator iterator = patterns.iterator(); iterator.hasNext();) {
+            AbstractNameQuery query = (AbstractNameQuery) iterator.next();
+            if (query.getArtifact() != null) return true;
+        }
+
+        // attempt to find the bean
+        try {
+            findGBean(patterns);
+            return true;
+        } catch (GBeanNotFoundException e) {
+            return false;
+        }
     }
 }

Modified: geronimo/branches/1.1/modules/j2ee-builder/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/j2ee-builder/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java?rev=425270&r1=425269&r2=425270&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/j2ee-builder/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java (original)
+++ geronimo/branches/1.1/modules/j2ee-builder/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java Mon Jul 24 21:14:39 2006
@@ -42,6 +42,7 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl;
 import org.apache.geronimo.kernel.Jsr77Naming;
 import org.apache.geronimo.kernel.Naming;
 import org.apache.geronimo.kernel.config.ConfigurationData;
@@ -567,6 +568,7 @@
 
         public ConfigurationData loadConfiguration(Artifact configId) throws NoSuchConfigException, IOException, InvalidConfigException {
             ConfigurationData configurationData = new ConfigurationData(configId, naming);
+            configurationData.addGBean("GeronimoServer", J2EEServerImpl.GBEAN_INFO);
             configurationData.setConfigurationStore(this);
             return configurationData;
         }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/SingleElementCollection.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/SingleElementCollection.java?rev=425270&r1=425269&r2=425270&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/SingleElementCollection.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/SingleElementCollection.java Mon Jul 24 21:14:39 2006
@@ -38,7 +38,7 @@
 
     public SingleElementCollection(Collection collection) {
         if (collection == null) {
-            throw new IllegalArgumentException("No collection parameter supplied");
+            collection = Collections.EMPTY_SET;            
         }
 
         this.collection = collection;